annotate libass/ass_render_api.c @ 34185:05306b88b675

Fix wrong runtime and average bitrate for VBR (variable bitrate) MP3. Do so by determining the number of frames from the Xing/Info/VBRI headers and by calculation a correct duration which leads to an reasonable average bytes per seconds.
author ib
date Thu, 27 Oct 2011 20:09:09 +0000
parents 88eebbbbd6a0
children 6e7f60f6f9d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
1 /*
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
3 * Copyright (C) 2010 Grigori Goronzy <greg@geekmind.org>
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
4 *
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
5 * This file is part of libass.
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
6 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
7 * Permission to use, copy, modify, and distribute this software for any
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
8 * purpose with or without fee is hereby granted, provided that the above
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
9 * copyright notice and this permission notice appear in all copies.
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
10 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31853
diff changeset
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
18 */
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
19
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
20 #include "config.h"
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
21 #include "ass_render.h"
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
22
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
23 static void ass_reconfigure(ASS_Renderer *priv)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
24 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
25 ASS_Settings *settings = &priv->settings;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
26
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
27 priv->render_id++;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
28 priv->cache.glyph_cache =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
29 ass_glyph_cache_reset(priv->cache.glyph_cache);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
30 priv->cache.bitmap_cache =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
31 ass_bitmap_cache_reset(priv->cache.bitmap_cache);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
32 priv->cache.composite_cache =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
33 ass_composite_cache_reset(priv->cache.composite_cache);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
34 ass_free_images(priv->prev_images_root);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
35 priv->prev_images_root = 0;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
36
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
37 priv->width = settings->frame_width;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
38 priv->height = settings->frame_height;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
39 priv->orig_width = settings->frame_width - settings->left_margin -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
40 settings->right_margin;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
41 priv->orig_height = settings->frame_height - settings->top_margin -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
42 settings->bottom_margin;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
43 priv->orig_width_nocrop =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
44 settings->frame_width - FFMAX(settings->left_margin, 0) -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
45 FFMAX(settings->right_margin, 0);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
46 priv->orig_height_nocrop =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
47 settings->frame_height - FFMAX(settings->top_margin, 0) -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
48 FFMAX(settings->bottom_margin, 0);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
49 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
50
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
51 void ass_set_frame_size(ASS_Renderer *priv, int w, int h)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
52 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
53 if (priv->settings.frame_width != w || priv->settings.frame_height != h) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
54 priv->settings.frame_width = w;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
55 priv->settings.frame_height = h;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
56 if (priv->settings.aspect == 0.) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
57 priv->settings.aspect = ((double) w) / h;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
58 priv->settings.storage_aspect = ((double) w) / h;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
59 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
60 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
61 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
62 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
63
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
64 void ass_set_margins(ASS_Renderer *priv, int t, int b, int l, int r)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
65 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
66 if (priv->settings.left_margin != l || priv->settings.right_margin != r ||
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
67 priv->settings.top_margin != t || priv->settings.bottom_margin != b) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
68 priv->settings.left_margin = l;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
69 priv->settings.right_margin = r;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
70 priv->settings.top_margin = t;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
71 priv->settings.bottom_margin = b;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
72 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
73 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
74 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
75
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
76 void ass_set_use_margins(ASS_Renderer *priv, int use)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
77 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
78 priv->settings.use_margins = use;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
79 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
80
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
81 void ass_set_aspect_ratio(ASS_Renderer *priv, double dar, double sar)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
82 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
83 if (priv->settings.aspect != dar || priv->settings.storage_aspect != sar) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
84 priv->settings.aspect = dar;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
85 priv->settings.storage_aspect = sar;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
86 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
87 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
88 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
89
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
90 void ass_set_font_scale(ASS_Renderer *priv, double font_scale)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
91 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
92 if (priv->settings.font_size_coeff != font_scale) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
93 priv->settings.font_size_coeff = font_scale;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
94 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
95 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
96 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
97
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
98 void ass_set_hinting(ASS_Renderer *priv, ASS_Hinting ht)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
99 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
100 if (priv->settings.hinting != ht) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
101 priv->settings.hinting = ht;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
102 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
103 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
104 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
105
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
106 void ass_set_line_spacing(ASS_Renderer *priv, double line_spacing)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
107 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
108 priv->settings.line_spacing = line_spacing;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
109 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
110
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
111 void ass_set_fonts(ASS_Renderer *priv, const char *default_font,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
112 const char *default_family, int fc, const char *config,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
113 int update)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
114 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
115 free(priv->settings.default_font);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
116 free(priv->settings.default_family);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
117 priv->settings.default_font = default_font ? strdup(default_font) : 0;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
118 priv->settings.default_family =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
119 default_family ? strdup(default_family) : 0;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
120
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
121 if (priv->fontconfig_priv)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
122 fontconfig_done(priv->fontconfig_priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
123 priv->fontconfig_priv =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
124 fontconfig_init(priv->library, priv->ftlibrary, default_family,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
125 default_font, fc, config, update);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
126 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
127
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
128 int ass_fonts_update(ASS_Renderer *render_priv)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
129 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
130 return fontconfig_update(render_priv->fontconfig_priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
131 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
132
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
133 void ass_set_cache_limits(ASS_Renderer *render_priv, int glyph_max,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
134 int bitmap_max)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
135 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
136 render_priv->cache.glyph_max = glyph_max ? glyph_max : GLYPH_CACHE_MAX;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
137 render_priv->cache.bitmap_max_size = bitmap_max ? 1048576 * bitmap_max :
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
138 BITMAP_CACHE_MAX_SIZE;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
139 }