annotate sub/ass_mp.c @ 32635:b05c02525cb1

Simplify video format condition in get_metadata.
author cboesch
date Sun, 19 Dec 2010 14:15:44 +0000
parents fbe5c829c69b
children 45e9c10b2f5b
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
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
57 ASS_Track* ass_default_track(ASS_Library* library) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
58 ASS_Track* track = ass_new_track(library);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
59
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
60 track->track_type = TRACK_TYPE_ASS;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
61 track->Timer = 100.;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
62 track->PlayResY = 288;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
63 track->WrapStyle = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
64
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
65 if (ass_styles_file)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
66 ass_read_styles(track, ass_styles_file, sub_cp);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
67
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
68 if (track->n_styles == 0) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
69 ASS_Style* style;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
70 int sid;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
71 double fs;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
72 uint32_t c1, c2;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
73
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
74 sid = ass_alloc_style(track);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
75 style = track->styles + sid;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
76 style->Name = strdup("Default");
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
77 style->FontName = (font_fontconfig >= 0 && sub_font_name) ? strdup(sub_font_name) : (font_fontconfig >= 0 && font_name) ? strdup(font_name) : strdup("Sans");
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
78 style->treat_fontname_as_pattern = 1;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
79
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
80 fs = track->PlayResY * text_font_scale_factor / 100.;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
81 // approximate autoscale coefficients
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
82 if (subtitle_autoscale == 2)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
83 fs *= 1.3;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
84 else if (subtitle_autoscale == 3)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
85 fs *= 1.4;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
86 style->FontSize = fs;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
87
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
88 if (ass_color) c1 = strtoll(ass_color, NULL, 16);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
89 else c1 = 0xFFFF0000;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
90 if (ass_border_color) c2 = strtoll(ass_border_color, NULL, 16);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
91 else c2 = 0x00000000;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
92
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
93 style->PrimaryColour = c1;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
94 style->SecondaryColour = c1;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
95 style->OutlineColour = c2;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
96 style->BackColour = 0x00000000;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
97 style->BorderStyle = 1;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
98 style->Alignment = 2;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
99 style->Outline = 2;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
100 style->MarginL = 10;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
101 style->MarginR = 10;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
102 style->MarginV = 5;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
103 style->ScaleX = 1.;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
104 style->ScaleY = 1.;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
105 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
106
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
107 ass_process_force_style(track);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
108 return track;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
109 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
110
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
111 static int check_duplicate_plaintext_event(ASS_Track* track)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
112 {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
113 int i;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
114 ASS_Event* evt = track->events + track->n_events - 1;
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 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
117 if (track->events[i].Start == evt->Start &&
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
118 track->events[i].Duration == evt->Duration &&
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
119 strcmp(track->events[i].Text, evt->Text) == 0)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
120 return 1;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
121 return 0;
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
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
124 /**
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
125 * \brief Convert subtitle to ASS_Event for the given track
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
126 * \param track ASS_Track
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
127 * \param sub subtitle to convert
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
128 * \return event id
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
129 * 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
130 * Start and Duration in other case.
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
131 **/
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
132 int ass_process_subtitle(ASS_Track* track, subtitle* sub)
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 int eid;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
135 ASS_Event* event;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
136 int len = 0, j;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
137 char* p;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
138 char* end;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
139
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
140 eid = ass_alloc_event(track);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
141 event = track->events + eid;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
142
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
143 event->Start = sub->start * 10;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
144 event->Duration = (sub->end - sub->start) * 10;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
145 event->Style = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
146
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
147 for (j = 0; j < sub->lines; ++j)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
148 len += sub->text[j] ? strlen(sub->text[j]) : 0;
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 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
151 len += 6; // {\anX}
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
152 len += 1; // '\0'
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
153
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
154 event->Text = malloc(len);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
155 end = event->Text + len;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
156 p = event->Text;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
157
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
158 if (sub->alignment)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
159 p += snprintf(p, end - p, "{\\an%d}", sub->alignment);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
160
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
161 for (j = 0; j < sub->lines; ++j)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
162 p += snprintf(p, end - p, "%s\\N", sub->text[j]);
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 if (sub->lines > 0) p-=2; // remove last "\N"
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
165 *p = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
166
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
167 if (check_duplicate_plaintext_event(track)) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
168 ass_free_event(track, eid);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
169 track->n_events--;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
170 return -1;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
171 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
172
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
173 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
174 (int64_t)event->Start, (int64_t)event->Duration, event->Text);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
175
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
176 return eid;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
177 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
178
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
179
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
180 /**
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
181 * \brief Convert subdata to ASS_Track
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
182 * \param subdata subtitles struct from subreader
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
183 * \param fps video framerate
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
184 * \return newly allocated ASS_Track, filled with subtitles from subdata
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 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
187 ASS_Track* track;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
188 int i;
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 track = ass_default_track(library);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
191 track->name = subdata->filename ? strdup(subdata->filename) : 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
192
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
193 for (i = 0; i < subdata->sub_num; ++i) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
194 int eid = ass_process_subtitle(track, subdata->subtitles + i);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
195 if (eid < 0)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
196 continue;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
197 if (!subdata->sub_uses_time) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
198 track->events[eid].Start *= 100. / fps;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
199 track->events[eid].Duration *= 100. / fps;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
200 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
201 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
202 return track;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
203 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
204
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
205 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
206 char *buf = NULL;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
207 ASS_Track *track;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
208 size_t sz = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
209 size_t buf_alloc = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
210 stream_t *fd;
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 fd = open_stream(fname, NULL, NULL);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
213 if (!fd) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
214 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_FopenFailed, fname);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
215 return NULL;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
216 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
217 if (fd->end_pos > STREAM_BUFFER_SIZE)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
218 /* read entire file if size is known */
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
219 buf_alloc = fd->end_pos;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
220 for (;;) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
221 int i;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
222 if (buf_alloc >= 100*1024*1024) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
223 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M, fname);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
224 sz = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
225 break;
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 (buf_alloc < sz + STREAM_BUFFER_SIZE)
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
228 buf_alloc += STREAM_BUFFER_SIZE;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
229 buf = realloc(buf, buf_alloc + 1);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
230 i = stream_read(fd, buf + sz, buf_alloc - sz);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
231 if (i <= 0) break;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
232 sz += i;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
233 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
234 free_stream(fd);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
235 if (!sz) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
236 free(buf);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
237 return NULL;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
238 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
239 buf[sz] = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
240 buf = realloc(buf, sz + 1);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
241 track = ass_read_memory(library, buf, sz, charset);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
242 if (track) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
243 free(track->name);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
244 track->name = strdup(fname);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
245 }
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 track;
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
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
250 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
251 int hinting;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
252 ass_set_frame_size(priv, w, h);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
253 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
254 ass_set_use_margins(priv, ass_use_margins);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
255 ass_set_font_scale(priv, ass_font_scale);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
256 if (!unscaled && (ass_hinting & 4))
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
257 hinting = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
258 else
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
259 hinting = ass_hinting & 3;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
260 ass_set_hinting(priv, hinting);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
261 ass_set_line_spacing(priv, ass_line_spacing);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
262 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
263
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
264 void ass_configure_fonts(ASS_Renderer* priv) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
265 char *dir, *path, *family;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
266 dir = get_path("fonts");
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
267 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
268 else if (font_fontconfig < 0 && font_name) path = strdup(font_name);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
269 else path = get_path("subfont.ttf");
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
270 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
271 else if (font_fontconfig >= 0 && font_name) family = strdup(font_name);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
272 else family = 0;
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 ass_set_fonts(priv, path, family, font_fontconfig, NULL, 1);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
275
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
276 free(dir);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
277 free(path);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
278 free(family);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
279 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
280
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
281 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
282 {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
283 int n;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
284 char *str;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
285 va_list dst;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
286
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
287 va_copy(dst, va);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
288 n = vsnprintf(NULL, 0, format, va);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
289 if (n > 0 && (str = malloc(n + 1))) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
290 vsnprintf(str, n + 1, format, dst);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
291 mp_msg(MSGT_ASS, level, "[ass] %s\n", str);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
292 free(str);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
293 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
294 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
295
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
296 ASS_Library* ass_init(void) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
297 ASS_Library* priv;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
298 char* path = get_path("fonts");
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
299 priv = ass_library_init();
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
300 ass_set_message_cb(priv, message_callback, NULL);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
301 ass_set_fonts_dir(priv, path);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
302 ass_set_extract_fonts(priv, extract_embedded_fonts);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
303 ass_set_style_overrides(priv, ass_force_style_list);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
304 free(path);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
305 return priv;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
306 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
307
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
308 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
309
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
310 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
311 if (ass_force_reload) {
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
312 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
313 ass_set_use_margins(priv, ass_use_margins);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
314 ass_set_font_scale(priv, ass_font_scale);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
315 ass_force_reload = 0;
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
316 }
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
317 return ass_render_frame(priv, track, now, detect_change);
ef21cbba62ee Move libass/ass_mp.[ch] ---> ass_mp.[ch].
diego
parents:
diff changeset
318 }
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
319
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
320 /* EOSD source for ASS subtitles. */
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
321
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
322 static ASS_Renderer *ass_renderer;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
323 static int prev_visibility;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
324
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
325 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
326 {
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
327 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
328 ASS_Image *aimg;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
329 struct mp_eosd_image *img;
32426
fbee56276c87 Add a flag "initialized" to the mp_eosd_source structure.
cigaes
parents: 32397
diff changeset
330 if (res->changed || !src->initialized) {
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
331 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
332 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
333 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
334 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
335 src->initialized = 1;
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
336 }
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
337 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
338 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
339 NULL;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
340 if (!aimg != !src->images)
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
341 src->changed = 2;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
342 if (src->changed) {
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
343 eosd_image_remove_all(src);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
344 while (aimg) {
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
345 img = eosd_image_alloc();
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
346 img->w = aimg->w;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
347 img->h = aimg->h;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
348 img->bitmap = aimg->bitmap;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
349 img->stride = aimg->stride;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
350 img->color = aimg->color;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
351 img->dst_x = aimg->dst_x;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
352 img->dst_y = aimg->dst_y;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
353 eosd_image_append(src, img);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
354 aimg = aimg->next;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
355 }
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
356 }
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
357 prev_visibility = sub_visibility;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
358 }
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
359
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
360 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
361 {
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
362 eosd_image_remove_all(src);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
363 ass_renderer_done(ass_renderer);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
364 }
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
365
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
366 static struct mp_eosd_source eosd_ass = {
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
367 .uninit = eosd_ass_uninit,
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
368 .update = eosd_ass_update,
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
369 .z_index = 10,
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
370 };
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
371
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
372 void eosd_ass_init(ASS_Library *ass_library)
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 ass_renderer = ass_renderer_init(ass_library);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
375 if (!ass_renderer)
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
376 return;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
377 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
378 if (!eosd_registered(&eosd_ass))
b3110e526e19 EOSD: add a function to test if a source has already been registered.
cigaes
parents: 32391
diff changeset
379 eosd_register(&eosd_ass);
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32210
diff changeset
380 }