FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/assdec.c
Date: 2021-09-24 20:55:06
Exec Total Coverage
Lines: 21 26 80.8%
Branches: 6 12 50.0%

Line Branch Exec Source
1 /*
2 * SSA/ASS decoder
3 * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.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 <string.h>
23
24 #include "avcodec.h"
25 #include "ass.h"
26 #include "internal.h"
27 #include "libavutil/internal.h"
28 #include "libavutil/mem.h"
29
30 4 static av_cold int ass_decode_init(AVCodecContext *avctx)
31 {
32 4 avctx->subtitle_header = av_malloc(avctx->extradata_size + 1);
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!avctx->subtitle_header)
34 return AVERROR(ENOMEM);
35
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (avctx->extradata_size)
36 4 memcpy(avctx->subtitle_header, avctx->extradata, avctx->extradata_size);
37 4 avctx->subtitle_header[avctx->extradata_size] = 0;
38 4 avctx->subtitle_header_size = avctx->extradata_size;
39 4 return 0;
40 }
41
42 8 static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
43 AVPacket *avpkt)
44 {
45 8 AVSubtitle *sub = data;
46
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (avpkt->size <= 0)
48 return avpkt->size;
49
50 8 sub->rects = av_malloc(sizeof(*sub->rects));
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!sub->rects)
52 return AVERROR(ENOMEM);
53 8 sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!sub->rects[0])
55 return AVERROR(ENOMEM);
56 8 sub->num_rects = 1;
57 8 sub->rects[0]->type = SUBTITLE_ASS;
58 8 sub->rects[0]->ass = av_strdup(avpkt->data);
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!sub->rects[0]->ass)
60 return AVERROR(ENOMEM);
61 8 *got_sub_ptr = 1;
62 8 return avpkt->size;
63 }
64
65 #if CONFIG_SSA_DECODER
66 const AVCodec ff_ssa_decoder = {
67 .name = "ssa",
68 .long_name = NULL_IF_CONFIG_SMALL("ASS (Advanced SubStation Alpha) subtitle"),
69 .type = AVMEDIA_TYPE_SUBTITLE,
70 .id = AV_CODEC_ID_ASS,
71 .init = ass_decode_init,
72 .decode = ass_decode_frame,
73 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
74 };
75 #endif
76
77 #if CONFIG_ASS_DECODER
78 const AVCodec ff_ass_decoder = {
79 .name = "ass",
80 .long_name = NULL_IF_CONFIG_SMALL("ASS (Advanced SubStation Alpha) subtitle"),
81 .type = AVMEDIA_TYPE_SUBTITLE,
82 .id = AV_CODEC_ID_ASS,
83 .init = ass_decode_init,
84 .decode = ass_decode_frame,
85 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
86 };
87 #endif
88