FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/movtextdec.c
Date: 2021-09-23 20:34:37
Exec Total Coverage
Lines: 130 278 46.8%
Branches: 43 165 26.1%

Line Branch Exec Source
1 /*
2 * 3GPP TS 26.245 Timed Text decoder
3 * Copyright (c) 2012 Philip Langdale <philipl@overt.org>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "avcodec.h"
23 #include "ass.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/avstring.h"
26 #include "libavutil/common.h"
27 #include "libavutil/bprint.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/mem.h"
30 #include "bytestream.h"
31 #include "internal.h"
32
33 #define STYLE_FLAG_BOLD (1<<0)
34 #define STYLE_FLAG_ITALIC (1<<1)
35 #define STYLE_FLAG_UNDERLINE (1<<2)
36
37 #define BOX_SIZE_INITIAL 40
38
39 #define STYL_BOX (1<<0)
40 #define HLIT_BOX (1<<1)
41 #define HCLR_BOX (1<<2)
42 #define TWRP_BOX (1<<3)
43
44 #define BOTTOM_LEFT 1
45 #define BOTTOM_CENTER 2
46 #define BOTTOM_RIGHT 3
47 #define MIDDLE_LEFT 4
48 #define MIDDLE_CENTER 5
49 #define MIDDLE_RIGHT 6
50 #define TOP_LEFT 7
51 #define TOP_CENTER 8
52 #define TOP_RIGHT 9
53
54 #define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff))
55
56 typedef struct {
57 uint16_t fontID;
58 const char *font;
59 uint8_t fontsize;
60 int color;
61 uint8_t alpha;
62 int back_color;
63 uint8_t back_alpha;
64 uint8_t bold;
65 uint8_t italic;
66 uint8_t underline;
67 int alignment;
68 } MovTextDefault;
69
70 typedef struct {
71 uint16_t fontID;
72 char *font;
73 } FontRecord;
74
75 typedef struct {
76 uint16_t style_start;
77 uint16_t style_end;
78 uint8_t style_flag;
79 uint8_t bold;
80 uint8_t italic;
81 uint8_t underline;
82 int color;
83 uint8_t alpha;
84 uint8_t fontsize;
85 uint16_t style_fontID;
86 } StyleBox;
87
88 typedef struct {
89 uint16_t hlit_start;
90 uint16_t hlit_end;
91 } HighlightBox;
92
93 typedef struct {
94 uint8_t hlit_color[4];
95 } HilightcolorBox;
96
97 typedef struct {
98 uint8_t wrap_flag;
99 } TextWrapBox;
100
101 typedef struct {
102 AVClass *class;
103 StyleBox *s;
104 HighlightBox h;
105 HilightcolorBox c;
106 FontRecord *ftab;
107 TextWrapBox w;
108 MovTextDefault d;
109 uint8_t box_flags;
110 uint16_t style_entries, ftab_entries;
111 uint64_t tracksize;
112 int size_var;
113 int readorder;
114 int frame_width;
115 int frame_height;
116 } MovTextContext;
117
118 typedef struct {
119 uint32_t type;
120 size_t base_size;
121 int (*decode)(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt);
122 } Box;
123
124 15 static void mov_text_cleanup(MovTextContext *m)
125 {
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (m->box_flags & STYL_BOX) {
127 av_freep(&m->s);
128 m->style_entries = 0;
129 }
130 15 }
131
132 6 static void mov_text_cleanup_ftab(MovTextContext *m)
133 {
134
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for (unsigned i = 0; i < m->ftab_entries; i++)
135 6 av_freep(&m->ftab[i].font);
136 6 av_freep(&m->ftab);
137 6 m->ftab_entries = 0;
138 6 }
139
140 6 static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
141 {
142 6 const uint8_t *tx3g_ptr = avctx->extradata;
143 6 int i, j = -1, font_length, remaining = avctx->extradata_size - BOX_SIZE_INITIAL;
144 int8_t v_align, h_align;
145 unsigned ftab_entries;
146 StyleBox s_default;
147
148 6 m->ftab_entries = 0;
149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (remaining < 0)
150 return -1;
151
152 // Display Flags
153 6 tx3g_ptr += 4;
154 // Alignment
155 6 h_align = bytestream_get_byte(&tx3g_ptr);
156 6 v_align = bytestream_get_byte(&tx3g_ptr);
157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (h_align == 0) {
158 if (v_align == 0)
159 m->d.alignment = TOP_LEFT;
160 if (v_align == 1)
161 m->d.alignment = MIDDLE_LEFT;
162 if (v_align == -1)
163 m->d.alignment = BOTTOM_LEFT;
164 }
165
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (h_align == 1) {
166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (v_align == 0)
167 m->d.alignment = TOP_CENTER;
168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (v_align == 1)
169 m->d.alignment = MIDDLE_CENTER;
170
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (v_align == -1)
171 6 m->d.alignment = BOTTOM_CENTER;
172 }
173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (h_align == -1) {
174 if (v_align == 0)
175 m->d.alignment = TOP_RIGHT;
176 if (v_align == 1)
177 m->d.alignment = MIDDLE_RIGHT;
178 if (v_align == -1)
179 m->d.alignment = BOTTOM_RIGHT;
180 }
181 // Background Color
182 6 m->d.back_color = bytestream_get_be24(&tx3g_ptr);
183 6 m->d.back_alpha = bytestream_get_byte(&tx3g_ptr);
184 // BoxRecord
185 6 tx3g_ptr += 8;
186 // StyleRecord
187 6 tx3g_ptr += 4;
188 // fontID
189 6 m->d.fontID = bytestream_get_be16(&tx3g_ptr);
190 // face-style-flags
191 6 s_default.style_flag = bytestream_get_byte(&tx3g_ptr);
192 6 m->d.bold = !!(s_default.style_flag & STYLE_FLAG_BOLD);
193 6 m->d.italic = !!(s_default.style_flag & STYLE_FLAG_ITALIC);
194 6 m->d.underline = !!(s_default.style_flag & STYLE_FLAG_UNDERLINE);
195 // fontsize
196 6 m->d.fontsize = bytestream_get_byte(&tx3g_ptr);
197 // Primary color
198 6 m->d.color = bytestream_get_be24(&tx3g_ptr);
199 6 m->d.alpha = bytestream_get_byte(&tx3g_ptr);
200 // FontRecord
201 // FontRecord Size
202 6 tx3g_ptr += 4;
203 // ftab
204 6 tx3g_ptr += 4;
205
206 // In case of broken header, init default font
207 6 m->d.font = ASS_DEFAULT_FONT;
208
209 6 ftab_entries = bytestream_get_be16(&tx3g_ptr);
210
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!ftab_entries)
211 return 0;
212 6 remaining -= 3 * ftab_entries;
213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (remaining < 0)
214 return AVERROR_INVALIDDATA;
215 6 m->ftab = av_calloc(ftab_entries, sizeof(*m->ftab));
216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!m->ftab)
217 return AVERROR(ENOMEM);
218 6 m->ftab_entries = ftab_entries;
219
220
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for (i = 0; i < m->ftab_entries; i++) {
221 6 m->ftab[i].fontID = bytestream_get_be16(&tx3g_ptr);
222
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (m->ftab[i].fontID == m->d.fontID)
223 6 j = i;
224 6 font_length = bytestream_get_byte(&tx3g_ptr);
225
226 6 remaining -= font_length;
227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (remaining < 0) {
228 mov_text_cleanup_ftab(m);
229 return -1;
230 }
231 6 m->ftab[i].font = av_malloc(font_length + 1);
232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!m->ftab[i].font) {
233 mov_text_cleanup_ftab(m);
234 return AVERROR(ENOMEM);
235 }
236 6 bytestream_get_buffer(&tx3g_ptr, m->ftab[i].font, font_length);
237 6 m->ftab[i].font[font_length] = '\0';
238 }
239
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (j >= 0)
240 6 m->d.font = m->ftab[j].font;
241 6 return 0;
242 }
243
244 static int decode_twrp(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
245 {
246 m->box_flags |= TWRP_BOX;
247 m->w.wrap_flag = bytestream_get_byte(&tsmb);
248 return 0;
249 }
250
251 static int decode_hlit(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
252 {
253 m->box_flags |= HLIT_BOX;
254 m->h.hlit_start = bytestream_get_be16(&tsmb);
255 m->h.hlit_end = bytestream_get_be16(&tsmb);
256 return 0;
257 }
258
259 static int decode_hclr(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
260 {
261 m->box_flags |= HCLR_BOX;
262 bytestream_get_buffer(&tsmb, m->c.hlit_color, 4);
263 return 0;
264 }
265
266 static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
267 {
268 int i;
269 int style_entries = bytestream_get_be16(&tsmb);
270 StyleBox *tmp;
271
272 // A single style record is of length 12 bytes.
273 if (m->tracksize + m->size_var + 2 + style_entries * 12 > avpkt->size)
274 return -1;
275
276 tmp = av_realloc_array(m->s, style_entries, sizeof(*m->s));
277 if (!tmp)
278 return AVERROR(ENOMEM);
279 m->s = tmp;
280 m->style_entries = style_entries;
281
282 m->box_flags |= STYL_BOX;
283 for(i = 0; i < m->style_entries; i++) {
284 StyleBox *style = &m->s[i];
285
286 style->style_start = bytestream_get_be16(&tsmb);
287 style->style_end = bytestream_get_be16(&tsmb);
288 if ( style->style_end < style->style_start
289 || (i && style->style_start < m->s[i - 1].style_end)) {
290 mov_text_cleanup(m);
291 return AVERROR(ENOMEM);
292 }
293 if (style->style_start == style->style_end) {
294 /* Skip this style as it applies to no character */
295 tsmb += 8;
296 m->style_entries--;
297 i--;
298 continue;
299 }
300
301 style->style_fontID = bytestream_get_be16(&tsmb);
302 style->style_flag = bytestream_get_byte(&tsmb);
303 style->bold = !!(style->style_flag & STYLE_FLAG_BOLD);
304 style->italic = !!(style->style_flag & STYLE_FLAG_ITALIC);
305 style->underline = !!(style->style_flag & STYLE_FLAG_UNDERLINE);
306 style->fontsize = bytestream_get_byte(&tsmb);
307 style->color = bytestream_get_be24(&tsmb);
308 style->alpha = bytestream_get_byte(&tsmb);
309 }
310 return 0;
311 }
312
313 static const Box box_types[] = {
314 { MKBETAG('s','t','y','l'), 2, decode_styl },
315 { MKBETAG('h','l','i','t'), 4, decode_hlit },
316 { MKBETAG('h','c','l','r'), 4, decode_hclr },
317 { MKBETAG('t','w','r','p'), 1, decode_twrp }
318 };
319
320 const static size_t box_count = FF_ARRAY_ELEMS(box_types);
321
322 // Return byte length of the UTF-8 sequence starting at text[0]. 0 on error.
323 135 static int get_utf8_length_at(const char *text, const char *text_end)
324 {
325 135 const char *start = text;
326 135 int err = 0;
327 uint32_t c;
328
4/12
✓ Branch 0 taken 135 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 135 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 135 times.
135 GET_UTF8(c, text < text_end ? (uint8_t)*text++ : (err = 1, 0), goto error;);
329
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 135 times.
135 if (err)
330 goto error;
331 135 return text - start;
332 error:
333 return 0;
334 }
335
336 9 static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
337 AVCodecContext *avctx)
338 {
339 9 MovTextContext *m = avctx->priv_data;
340 9 int i = 0;
341 9 int text_pos = 0;
342 9 int entry = 0;
343 9 int color = m->d.color;
344
345
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if (text < text_end && m->box_flags & TWRP_BOX) {
346 if (m->w.wrap_flag == 1) {
347 av_bprintf(buf, "{\\q1}"); /* End of line wrap */
348 } else {
349 av_bprintf(buf, "{\\q2}"); /* No wrap */
350 }
351 }
352
353
2/2
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 9 times.
144 while (text < text_end) {
354 int len;
355
356
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
135 if ((m->box_flags & STYL_BOX) && entry < m->style_entries) {
357 const StyleBox *style = &m->s[entry];
358 if (text_pos == style->style_end) {
359 av_bprintf(buf, "{\\r}");
360 color = m->d.color;
361 entry++;
362 style++;
363 }
364 if (entry < m->style_entries && text_pos == style->style_start) {
365 if (style->bold ^ m->d.bold)
366 av_bprintf(buf, "{\\b%d}", style->bold);
367 if (style->italic ^ m->d.italic)
368 av_bprintf(buf, "{\\i%d}", style->italic);
369 if (style->underline ^ m->d.underline)
370 av_bprintf(buf, "{\\u%d}", style->underline);
371 if (style->fontsize != m->d.fontsize)
372 av_bprintf(buf, "{\\fs%d}", style->fontsize);
373 if (style->style_fontID != m->d.fontID)
374 for (i = 0; i < m->ftab_entries; i++) {
375 if (style->style_fontID == m->ftab[i].fontID)
376 av_bprintf(buf, "{\\fn%s}", m->ftab[i].font);
377 }
378 if (m->d.color != style->color) {
379 color = style->color;
380 av_bprintf(buf, "{\\1c&H%X&}", RGB_TO_BGR(color));
381 }
382 if (m->d.alpha != style->alpha)
383 av_bprintf(buf, "{\\1a&H%02X&}", 255 - style->alpha);
384 }
385 }
386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 135 times.
135 if (m->box_flags & HLIT_BOX) {
387 if (text_pos == m->h.hlit_start) {
388 /* If hclr box is present, set the secondary color to the color
389 * specified. Otherwise, set primary color to white and secondary
390 * color to black. These colors will come from TextSampleModifier
391 * boxes in future and inverse video technique for highlight will
392 * be implemented.
393 */
394 if (m->box_flags & HCLR_BOX) {
395 av_bprintf(buf, "{\\2c&H%02x%02x%02x&}", m->c.hlit_color[2],
396 m->c.hlit_color[1], m->c.hlit_color[0]);
397 } else {
398 av_bprintf(buf, "{\\1c&H000000&}{\\2c&HFFFFFF&}");
399 }
400 }
401 if (text_pos == m->h.hlit_end) {
402 if (m->box_flags & HCLR_BOX) {
403 av_bprintf(buf, "{\\2c&H%X&}", RGB_TO_BGR(m->d.color));
404 } else {
405 av_bprintf(buf, "{\\1c&H%X&}{\\2c&H%X&}",
406 RGB_TO_BGR(color), RGB_TO_BGR(m->d.color));
407 }
408 }
409 }
410
411 135 len = get_utf8_length_at(text, text_end);
412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 135 times.
135 if (len < 1) {
413 av_log(avctx, AV_LOG_ERROR, "invalid UTF-8 byte in subtitle\n");
414 len = 1;
415 }
416
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 129 times.
135 switch (*text) {
417 case '\r':
418 break;
419 6 case '\n':
420 6 av_bprintf(buf, "\\N");
421 6 break;
422 129 default:
423 129 av_bprint_append_data(buf, text, len);
424 129 break;
425 }
426 135 text += len;
427 135 text_pos++;
428 }
429
430 9 return 0;
431 }
432
433 6 static int mov_text_init(AVCodecContext *avctx) {
434 /*
435 * TODO: Handle the default text style.
436 * NB: Most players ignore styles completely, with the result that
437 * it's very common to find files where the default style is broken
438 * and respecting it results in a worse experience than ignoring it.
439 */
440 int ret;
441 6 MovTextContext *m = avctx->priv_data;
442 6 ret = mov_text_tx3g(avctx, m);
443
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (ret == 0) {
444
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (!m->frame_width || !m->frame_height) {
445 6 m->frame_width = ASS_DEFAULT_PLAYRESX;
446 6 m->frame_height = ASS_DEFAULT_PLAYRESY;
447 }
448 6 return ff_ass_subtitle_header_full(avctx,
449 m->frame_width, m->frame_height,
450 6 m->d.font, m->d.fontsize,
451 6 (255U - m->d.alpha) << 24 | RGB_TO_BGR(m->d.color),
452 6 (255U - m->d.alpha) << 24 | RGB_TO_BGR(m->d.color),
453 6 (255U - m->d.back_alpha) << 24 | RGB_TO_BGR(m->d.back_color),
454 6 (255U - m->d.back_alpha) << 24 | RGB_TO_BGR(m->d.back_color),
455 6 m->d.bold, m->d.italic, m->d.underline,
456 ASS_DEFAULT_BORDERSTYLE, m->d.alignment);
457 } else
458 return ff_ass_subtitle_header_default(avctx);
459 }
460
461 18 static int mov_text_decode_frame(AVCodecContext *avctx,
462 void *data, int *got_sub_ptr, AVPacket *avpkt)
463 {
464 18 AVSubtitle *sub = data;
465 18 MovTextContext *m = avctx->priv_data;
466 int ret;
467 AVBPrint buf;
468 18 char *ptr = avpkt->data;
469 char *end;
470 int text_length, tsmb_type, ret_tsmb;
471 uint64_t tsmb_size;
472 const uint8_t *tsmb;
473 size_t i;
474
475
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 if (!ptr || avpkt->size < 2)
476 return AVERROR_INVALIDDATA;
477
478 /*
479 * A packet of size two with value zero is an empty subtitle
480 * used to mark the end of the previous non-empty subtitle.
481 * We can just drop them here as we have duration information
482 * already. If the value is non-zero, then it's technically a
483 * bad packet.
484 */
485
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if (avpkt->size == 2)
486
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 return AV_RB16(ptr) == 0 ? 0 : AVERROR_INVALIDDATA;
487
488 /*
489 * The first two bytes of the packet are the length of the text string
490 * In complex cases, there are style descriptors appended to the string
491 * so we can't just assume the packet size is the string size.
492 */
493 9 text_length = AV_RB16(ptr);
494
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 end = ptr + FFMIN(2 + text_length, avpkt->size);
495 9 ptr += 2;
496
497 9 mov_text_cleanup(m);
498
499 9 tsmb_size = 0;
500 9 m->tracksize = 2 + text_length;
501 9 m->style_entries = 0;
502 9 m->box_flags = 0;
503 // Note that the spec recommends lines be no longer than 2048 characters.
504 9 av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (text_length + 2 != avpkt->size) {
506 while (m->tracksize + 8 <= avpkt->size) {
507 // A box is a minimum of 8 bytes.
508 tsmb = ptr + m->tracksize - 2;
509 tsmb_size = AV_RB32(tsmb);
510 tsmb += 4;
511 tsmb_type = AV_RB32(tsmb);
512 tsmb += 4;
513
514 if (tsmb_size == 1) {
515 if (m->tracksize + 16 > avpkt->size)
516 break;
517 tsmb_size = AV_RB64(tsmb);
518 tsmb += 8;
519 m->size_var = 16;
520 } else
521 m->size_var = 8;
522 //size_var is equal to 8 or 16 depending on the size of box
523
524 if (tsmb_size == 0) {
525 av_log(avctx, AV_LOG_ERROR, "tsmb_size is 0\n");
526 return AVERROR_INVALIDDATA;
527 }
528
529 if (tsmb_size > avpkt->size - m->tracksize)
530 break;
531
532 for (i = 0; i < box_count; i++) {
533 if (tsmb_type == box_types[i].type) {
534 if (m->tracksize + m->size_var + box_types[i].base_size > avpkt->size)
535 break;
536 ret_tsmb = box_types[i].decode(tsmb, m, avpkt);
537 if (ret_tsmb == -1)
538 break;
539 }
540 }
541 m->tracksize = m->tracksize + tsmb_size;
542 }
543 text_to_ass(&buf, ptr, end, avctx);
544 mov_text_cleanup(m);
545 } else
546 9 text_to_ass(&buf, ptr, end, avctx);
547
548 9 ret = ff_ass_add_rect(sub, buf.str, m->readorder++, 0, NULL, NULL);
549 9 av_bprint_finalize(&buf, NULL);
550
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ret < 0)
551 return ret;
552 9 *got_sub_ptr = sub->num_rects > 0;
553 9 return avpkt->size;
554 }
555
556 6 static int mov_text_decode_close(AVCodecContext *avctx)
557 {
558 6 MovTextContext *m = avctx->priv_data;
559 6 mov_text_cleanup_ftab(m);
560 6 mov_text_cleanup(m);
561 6 return 0;
562 }
563
564 static void mov_text_flush(AVCodecContext *avctx)
565 {
566 MovTextContext *m = avctx->priv_data;
567 if (!(avctx->flags2 & AV_CODEC_FLAG2_RO_FLUSH_NOOP))
568 m->readorder = 0;
569 }
570
571 #define OFFSET(x) offsetof(MovTextContext, x)
572 #define FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
573 static const AVOption options[] = {
574 { "width", "Frame width, usually video width", OFFSET(frame_width), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
575 { "height", "Frame height, usually video height", OFFSET(frame_height), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
576 { NULL },
577 };
578
579 static const AVClass mov_text_decoder_class = {
580 .class_name = "MOV text decoder",
581 .item_name = av_default_item_name,
582 .option = options,
583 .version = LIBAVUTIL_VERSION_INT,
584 };
585
586 const AVCodec ff_movtext_decoder = {
587 .name = "mov_text",
588 .long_name = NULL_IF_CONFIG_SMALL("3GPP Timed Text subtitle"),
589 .type = AVMEDIA_TYPE_SUBTITLE,
590 .id = AV_CODEC_ID_MOV_TEXT,
591 .priv_data_size = sizeof(MovTextContext),
592 .priv_class = &mov_text_decoder_class,
593 .init = mov_text_init,
594 .decode = mov_text_decode_frame,
595 .close = mov_text_decode_close,
596 .flush = mov_text_flush,
597 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
598 };
599