annotate sub/ass_mp.c @ 35115:24c022e9d700

Update FFmpeg git URL to the current official one (they point at the same place though).
author reimar
date Sat, 22 Sep 2012 18:04:17 +0000
parents fede902a408c
children ccf5f4e1e87c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
1 /*
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
3 *
32210
f6ff1c427ff3 Adapt license header from libass to MPlayer boilerplate.
diego
parents: 32209
diff changeset
4 * This file is part of MPlayer.
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
5 *
32210
f6ff1c427ff3 Adapt license header from libass to MPlayer boilerplate.
diego
parents: 32209
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
9 * (at your option) any later version.
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
10 *
32210
f6ff1c427ff3 Adapt license header from libass to MPlayer boilerplate.
diego
parents: 32209
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
14 * GNU General Public License for more details.
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
15 *
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License along
32210
f6ff1c427ff3 Adapt license header from libass to MPlayer boilerplate.
diego
parents: 32209
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
19 */
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
20
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
21 #include <inttypes.h>
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
22 #include <string.h>
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
23 #include <stdlib.h>
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
24
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
25 #include "mp_msg.h"
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
26 #include "mpcommon.h"
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
27 #include "path.h"
32464
22888a8cb312 Do not use a path for including files in the same directory.
reimar
parents: 32461
diff changeset
28 #include "subreader.h"
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
29
32464
22888a8cb312 Do not use a path for including files in the same directory.
reimar
parents: 32461
diff changeset
30 #include "ass_mp.h"
22888a8cb312 Do not use a path for including files in the same directory.
reimar
parents: 32461
diff changeset
31 #include "eosd.h"
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
32 #include "mpcommon.h"
32467
fbe5c829c69b Move libvo/sub.[ch] from libvo to sub.
cigaes
parents: 32466
diff changeset
33 #include "sub.h"
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
34 #include "help_mp.h"
32466
9e627a1793b1 Move font_load.[ch], font_load_ft.c and osd_font.h from libvo to sub.
cigaes
parents: 32464
diff changeset
35 #include "font_load.h"
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
36 #include "stream/stream.h"
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
37
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
38 #ifdef CONFIG_FONTCONFIG
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
39 #include <fontconfig/fontconfig.h>
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
40 #endif
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
41
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
42 // libass-related command line options
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
43 ASS_Library* ass_library;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
44 int ass_enabled = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
45 float ass_font_scale = 1.;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
46 float ass_line_spacing = 0.;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
47 int ass_top_margin = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
48 int ass_bottom_margin = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
49 int extract_embedded_fonts = 1;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
50 char **ass_force_style_list = NULL;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
51 int ass_use_margins = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
52 char* ass_color = NULL;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
53 char* ass_border_color = NULL;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
54 char* ass_styles_file = NULL;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
55 int ass_hinting = ASS_HINTING_NATIVE + 4; // native hinting for unscaled osd
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
56
34475
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
57 static void init_style(ASS_Style *style, const char *name, double playres)
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
58 {
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
59 double fs;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
60 uint32_t c1, c2;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
61 style->Name = strdup(name);
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
62 style->FontName = (font_fontconfig >= 0 && sub_font_name) ? strdup(sub_font_name) : (font_fontconfig >= 0 && font_name) ? strdup(font_name) : strdup("Sans");
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
63 style->treat_fontname_as_pattern = 1;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
64
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
65 fs = playres * text_font_scale_factor / 100.;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
66 // approximate autoscale coefficients
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
67 if (subtitle_autoscale == 2)
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
68 fs *= 1.3;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
69 else if (subtitle_autoscale == 3)
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
70 fs *= 1.4;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
71 style->FontSize = fs;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
72
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
73 if (ass_color) c1 = strtoll(ass_color, NULL, 16);
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
74 else c1 = 0xFFFF0000;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
75 if (ass_border_color) c2 = strtoll(ass_border_color, NULL, 16);
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
76 else c2 = 0x00000000;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
77
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
78 style->PrimaryColour = c1;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
79 style->SecondaryColour = c1;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
80 style->OutlineColour = c2;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
81 style->BackColour = 0x00000000;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
82 style->BorderStyle = 1;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
83 style->Alignment = 2;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
84 style->Outline = 2;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
85 style->MarginL = 10;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
86 style->MarginR = 10;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
87 style->MarginV = 5;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
88 style->ScaleX = 1.;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
89 style->ScaleY = 1.;
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
90 }
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
91
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
92 ASS_Track* ass_default_track(ASS_Library* library) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
93 ASS_Track* track = ass_new_track(library);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
94
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
95 track->track_type = TRACK_TYPE_ASS;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
96 track->Timer = 100.;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
97 track->PlayResY = 288;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
98 track->WrapStyle = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
99
34476
fd5512f5bfe9 Fix -ass-styles with SRT subs and more.
reimar
parents: 34475
diff changeset
100 if (track->n_styles == 0) {
fd5512f5bfe9 Fix -ass-styles with SRT subs and more.
reimar
parents: 34475
diff changeset
101 // stupid hack to stop libass to add a default track
fd5512f5bfe9 Fix -ass-styles with SRT subs and more.
reimar
parents: 34475
diff changeset
102 // in front in ass_read_styles - this makes it impossible
fd5512f5bfe9 Fix -ass-styles with SRT subs and more.
reimar
parents: 34475
diff changeset
103 // to completely override the "Default" track.
fd5512f5bfe9 Fix -ass-styles with SRT subs and more.
reimar
parents: 34475
diff changeset
104 int sid = ass_alloc_style(track);
fd5512f5bfe9 Fix -ass-styles with SRT subs and more.
reimar
parents: 34475
diff changeset
105 init_style(track->styles + sid, "MPlayerDummy", track->PlayResY);
fd5512f5bfe9 Fix -ass-styles with SRT subs and more.
reimar
parents: 34475
diff changeset
106 }
fd5512f5bfe9 Fix -ass-styles with SRT subs and more.
reimar
parents: 34475
diff changeset
107
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
108 if (ass_styles_file)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
109 ass_read_styles(track, ass_styles_file, sub_cp);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
110
34476
fd5512f5bfe9 Fix -ass-styles with SRT subs and more.
reimar
parents: 34475
diff changeset
111 if (track->default_style <= 0) {
34475
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
112 int sid = ass_alloc_style(track);
45e9c10b2f5b Extract setting up default ASS style to a separate function.
reimar
parents: 32467
diff changeset
113 init_style(track->styles + sid, "Default", track->PlayResY);
34476
fd5512f5bfe9 Fix -ass-styles with SRT subs and more.
reimar
parents: 34475
diff changeset
114 track->default_style = sid;
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
115 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
116
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
117 ass_process_force_style(track);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
118 return track;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
119 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
120
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
121 static int check_duplicate_plaintext_event(ASS_Track* track)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
122 {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
123 int i;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
124 ASS_Event* evt = track->events + track->n_events - 1;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
125
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
126 for (i = 0; i<track->n_events - 1; ++i) // ignoring last event, it is the one we are comparing with
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
127 if (track->events[i].Start == evt->Start &&
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
128 track->events[i].Duration == evt->Duration &&
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
129 strcmp(track->events[i].Text, evt->Text) == 0)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
130 return 1;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
131 return 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
132 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
133
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
134 /**
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
135 * \brief Convert subtitle to ASS_Event for the given track
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
136 * \param track ASS_Track
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
137 * \param sub subtitle to convert
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
138 * \return event id
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
139 * note: assumes that subtitle is _not_ fps-based; caller must manually correct
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
140 * Start and Duration in other case.
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
141 **/
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
142 int ass_process_subtitle(ASS_Track* track, subtitle* sub)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
143 {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
144 int eid;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
145 ASS_Event* event;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
146 int len = 0, j;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
147 char* p;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
148 char* end;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
149
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
150 eid = ass_alloc_event(track);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
151 event = track->events + eid;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
152
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
153 event->Start = sub->start * 10;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
154 event->Duration = (sub->end - sub->start) * 10;
34476
fd5512f5bfe9 Fix -ass-styles with SRT subs and more.
reimar
parents: 34475
diff changeset
155 event->Style = track->default_style;
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
156
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
157 for (j = 0; j < sub->lines; ++j)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
158 len += sub->text[j] ? strlen(sub->text[j]) : 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
159
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
160 len += 2 * sub->lines; // '\N', including the one after the last line
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
161 len += 6; // {\anX}
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
162 len += 1; // '\0'
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
163
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
164 event->Text = malloc(len);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
165 end = event->Text + len;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
166 p = event->Text;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
167
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
168 if (sub->alignment)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
169 p += snprintf(p, end - p, "{\\an%d}", sub->alignment);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
170
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
171 for (j = 0; j < sub->lines; ++j)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
172 p += snprintf(p, end - p, "%s\\N", sub->text[j]);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
173
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
174 if (sub->lines > 0) p-=2; // remove last "\N"
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
175 *p = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
176
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
177 if (check_duplicate_plaintext_event(track)) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
178 ass_free_event(track, eid);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
179 track->n_events--;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
180 return -1;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
181 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
182
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
183 mp_msg(MSGT_ASS, MSGL_V, "plaintext event at %" PRId64 ", +%" PRId64 ": %s \n",
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
184 (int64_t)event->Start, (int64_t)event->Duration, event->Text);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
185
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
186 return eid;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
187 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
188
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
189
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
190 /**
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
191 * \brief Convert subdata to ASS_Track
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
192 * \param subdata subtitles struct from subreader
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
193 * \param fps video framerate
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
194 * \return newly allocated ASS_Track, filled with subtitles from subdata
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
195 */
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
196 ASS_Track* ass_read_subdata(ASS_Library* library, sub_data* subdata, double fps) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
197 ASS_Track* track;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
198 int i;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
199
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
200 track = ass_default_track(library);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
201 track->name = subdata->filename ? strdup(subdata->filename) : 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
202
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
203 for (i = 0; i < subdata->sub_num; ++i) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
204 int eid = ass_process_subtitle(track, subdata->subtitles + i);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
205 if (eid < 0)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
206 continue;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
207 if (!subdata->sub_uses_time) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
208 track->events[eid].Start *= 100. / fps;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
209 track->events[eid].Duration *= 100. / fps;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
210 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
211 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
212 return track;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
213 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
214
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
215 ASS_Track* ass_read_stream(ASS_Library* library, const char *fname, char *charset) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
216 char *buf = NULL;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
217 ASS_Track *track;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
218 size_t sz = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
219 size_t buf_alloc = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
220 stream_t *fd;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
221
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
222 fd = open_stream(fname, NULL, NULL);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
223 if (!fd) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
224 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_FopenFailed, fname);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
225 return NULL;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
226 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
227 if (fd->end_pos > STREAM_BUFFER_SIZE)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
228 /* read entire file if size is known */
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
229 buf_alloc = fd->end_pos;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
230 for (;;) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
231 int i;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
232 if (buf_alloc >= 100*1024*1024) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
233 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M, fname);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
234 sz = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
235 break;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
236 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
237 if (buf_alloc < sz + STREAM_BUFFER_SIZE)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
238 buf_alloc += STREAM_BUFFER_SIZE;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
239 buf = realloc(buf, buf_alloc + 1);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
240 i = stream_read(fd, buf + sz, buf_alloc - sz);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
241 if (i <= 0) break;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
242 sz += i;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
243 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
244 free_stream(fd);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
245 if (!sz) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
246 free(buf);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
247 return NULL;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
248 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
249 buf[sz] = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
250 buf = realloc(buf, sz + 1);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
251 track = ass_read_memory(library, buf, sz, charset);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
252 if (track) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
253 free(track->name);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
254 track->name = strdup(fname);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
255 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
256 free(buf);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
257 return track;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
258 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
259
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
260 void ass_configure(ASS_Renderer* priv, int w, int h, int unscaled) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
261 int hinting;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
262 ass_set_frame_size(priv, w, h);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
263 ass_set_margins(priv, ass_top_margin, ass_bottom_margin, 0, 0);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
264 ass_set_use_margins(priv, ass_use_margins);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
265 ass_set_font_scale(priv, ass_font_scale);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
266 if (!unscaled && (ass_hinting & 4))
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
267 hinting = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
268 else
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
269 hinting = ass_hinting & 3;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
270 ass_set_hinting(priv, hinting);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
271 ass_set_line_spacing(priv, ass_line_spacing);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
272 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
273
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
274 void ass_configure_fonts(ASS_Renderer* priv) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
275 char *dir, *path, *family;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
276 dir = get_path("fonts");
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
277 if (font_fontconfig < 0 && sub_font_name) path = strdup(sub_font_name);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
278 else if (font_fontconfig < 0 && font_name) path = strdup(font_name);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
279 else path = get_path("subfont.ttf");
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
280 if (font_fontconfig >= 0 && sub_font_name) family = strdup(sub_font_name);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
281 else if (font_fontconfig >= 0 && font_name) family = strdup(font_name);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
282 else family = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
283
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
284 ass_set_fonts(priv, path, family, font_fontconfig, NULL, 1);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
285
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
286 free(dir);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
287 free(path);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
288 free(family);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
289 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
290
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
291 static void message_callback(int level, const char *format, va_list va, void *ctx)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
292 {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
293 int n;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
294 char *str;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
295 va_list dst;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
296
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
297 va_copy(dst, va);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
298 n = vsnprintf(NULL, 0, format, va);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
299 if (n > 0 && (str = malloc(n + 1))) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
300 vsnprintf(str, n + 1, format, dst);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
301 mp_msg(MSGT_ASS, level, "[ass] %s\n", str);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
302 free(str);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
303 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
304 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
305
34494
fede902a408c Fix per-file ASS options like -ass-force-style.
reimar
parents: 34476
diff changeset
306 /**
fede902a408c Fix per-file ASS options like -ass-force-style.
reimar
parents: 34476
diff changeset
307 * Reset all per-file settings for next file.
fede902a408c Fix per-file ASS options like -ass-force-style.
reimar
parents: 34476
diff changeset
308 */
fede902a408c Fix per-file ASS options like -ass-force-style.
reimar
parents: 34476
diff changeset
309 void ass_mp_reset_config(ASS_Library *l) {
fede902a408c Fix per-file ASS options like -ass-force-style.
reimar
parents: 34476
diff changeset
310 ass_set_extract_fonts(l, extract_embedded_fonts);
fede902a408c Fix per-file ASS options like -ass-force-style.
reimar
parents: 34476
diff changeset
311 ass_set_style_overrides(l, ass_force_style_list);
fede902a408c Fix per-file ASS options like -ass-force-style.
reimar
parents: 34476
diff changeset
312 ass_force_reload = 1;
fede902a408c Fix per-file ASS options like -ass-force-style.
reimar
parents: 34476
diff changeset
313 }
fede902a408c Fix per-file ASS options like -ass-force-style.
reimar
parents: 34476
diff changeset
314
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
315 ASS_Library* ass_init(void) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
316 ASS_Library* priv;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
317 char* path = get_path("fonts");
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
318 priv = ass_library_init();
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
319 ass_set_message_cb(priv, message_callback, NULL);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
320 ass_set_fonts_dir(priv, path);
34494
fede902a408c Fix per-file ASS options like -ass-force-style.
reimar
parents: 34476
diff changeset
321 ass_mp_reset_config(priv);
32209
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
322 free(path);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
323 return priv;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
324 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
325
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
326 int ass_force_reload = 0; // flag set if global ass-related settings were changed
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
327
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
328 ASS_Image* ass_mp_render_frame(ASS_Renderer *priv, ASS_Track* track, long long now, int* detect_change) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
329 if (ass_force_reload) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
330 ass_set_margins(priv, ass_top_margin, ass_bottom_margin, 0, 0);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
331 ass_set_use_margins(priv, ass_use_margins);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
332 ass_set_font_scale(priv, ass_font_scale);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
333 ass_force_reload = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
334 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
335 return ass_render_frame(priv, track, now, detect_change);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
336 }
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
337
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
338 /* EOSD source for ASS subtitles. */
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
339
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
340 static ASS_Renderer *ass_renderer;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
341 static int prev_visibility;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
342
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
343 static void eosd_ass_update(struct mp_eosd_source *src, const struct mp_eosd_settings *res, double ts)
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
344 {
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
345 long long ts_ms = (ts + sub_delay) * 1000 + .5;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
346 ASS_Image *aimg;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
347 struct mp_eosd_image *img;
32426
fbee56276c87 Add a flag "initialized" to the mp_eosd_source structure.
cigaes
parents: 32397
diff changeset
348 if (res->changed || !src->initialized) {
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
349 double dar = (double) (res->w - res->ml - res->mr) / (res->h - res->mt - res->mb);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
350 ass_configure(ass_renderer, res->w, res->h, res->unscaled);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
351 ass_set_margins(ass_renderer, res->mt, res->mb, res->ml, res->mr);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
352 ass_set_aspect_ratio(ass_renderer, dar, (double)res->srcw / res->srch);
32426
fbee56276c87 Add a flag "initialized" to the mp_eosd_source structure.
cigaes
parents: 32397
diff changeset
353 src->initialized = 1;
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
354 }
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
355 aimg = sub_visibility && ass_track && ts != MP_NOPTS_VALUE ?
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
356 ass_mp_render_frame(ass_renderer, ass_track, ts_ms, &src->changed) :
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
357 NULL;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
358 if (!aimg != !src->images)
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
359 src->changed = 2;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
360 if (src->changed) {
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
361 eosd_image_remove_all(src);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
362 while (aimg) {
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
363 img = eosd_image_alloc();
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
364 img->w = aimg->w;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
365 img->h = aimg->h;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
366 img->bitmap = aimg->bitmap;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
367 img->stride = aimg->stride;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
368 img->color = aimg->color;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
369 img->dst_x = aimg->dst_x;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
370 img->dst_y = aimg->dst_y;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
371 eosd_image_append(src, img);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
372 aimg = aimg->next;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
373 }
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
374 }
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
375 prev_visibility = sub_visibility;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
376 }
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
377
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
378 static void eosd_ass_uninit(struct mp_eosd_source *src)
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
379 {
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
380 eosd_image_remove_all(src);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
381 ass_renderer_done(ass_renderer);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
382 }
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
383
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
384 static struct mp_eosd_source eosd_ass = {
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
385 .uninit = eosd_ass_uninit,
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
386 .update = eosd_ass_update,
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
387 .z_index = 10,
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
388 };
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
389
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
390 void eosd_ass_init(ASS_Library *ass_library)
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
391 {
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
392 ass_renderer = ass_renderer_init(ass_library);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
393 if (!ass_renderer)
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
394 return;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
395 ass_configure_fonts(ass_renderer);
32397
b3110e526e19 EOSD: add a function to test if a source has already been registered.
cigaes
parents: 32391
diff changeset
396 if (!eosd_registered(&eosd_ass))
b3110e526e19 EOSD: add a function to test if a source has already been registered.
cigaes
parents: 32391
diff changeset
397 eosd_register(&eosd_ass);
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
398 }