FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/assenc.c
Date: 2021-09-26 18:22:30
Exec Total Coverage
Lines: 16 21 76.2%
Branches: 5 8 62.5%

Line Branch Exec Source
1 /*
2 * SSA/ASS encoder
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/avstring.h"
28 #include "libavutil/internal.h"
29 #include "libavutil/mem.h"
30
31 25 static av_cold int ass_encode_init(AVCodecContext *avctx)
32 {
33 25 avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if (!avctx->extradata)
35 return AVERROR(ENOMEM);
36 25 memcpy(avctx->extradata, avctx->subtitle_header, avctx->subtitle_header_size);
37 25 avctx->extradata_size = avctx->subtitle_header_size;
38 25 avctx->extradata[avctx->extradata_size] = 0;
39 25 return 0;
40 }
41
42 450 static int ass_encode_frame(AVCodecContext *avctx,
43 unsigned char *buf, int bufsize,
44 const AVSubtitle *sub)
45 {
46 450 int i, len, total_len = 0;
47
48
2/2
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 450 times.
900 for (i=0; i<sub->num_rects; i++) {
49 450 const char *ass = sub->rects[i]->ass;
50
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (sub->rects[i]->type != SUBTITLE_ASS) {
52 av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
53 return AVERROR(EINVAL);
54 }
55
56 450 len = av_strlcpy(buf+total_len, ass, bufsize-total_len);
57
58
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (len > bufsize-total_len-1) {
59 av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
60 return AVERROR_BUFFER_TOO_SMALL;
61 }
62
63 450 total_len += len;
64 }
65
66 450 return total_len;
67 }
68
69 #if CONFIG_SSA_ENCODER
70 const AVCodec ff_ssa_encoder = {
71 .name = "ssa",
72 .long_name = NULL_IF_CONFIG_SMALL("ASS (Advanced SubStation Alpha) subtitle"),
73 .type = AVMEDIA_TYPE_SUBTITLE,
74 .id = AV_CODEC_ID_ASS,
75 .init = ass_encode_init,
76 .encode_sub = ass_encode_frame,
77 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
78 };
79 #endif
80
81 #if CONFIG_ASS_ENCODER
82 const AVCodec ff_ass_encoder = {
83 .name = "ass",
84 .long_name = NULL_IF_CONFIG_SMALL("ASS (Advanced SubStation Alpha) subtitle"),
85 .type = AVMEDIA_TYPE_SUBTITLE,
86 .id = AV_CODEC_ID_ASS,
87 .init = ass_encode_init,
88 .encode_sub = ass_encode_frame,
89 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
90 };
91 #endif
92