FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/supenc.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 22 26 84.6%
Functions: 2 2 100.0%
Branches: 6 10 60.0%

Line Branch Exec Source
1 /*
2 * SUP muxer
3 * Copyright (c) 2014 Petri Hintukainen <phintuka@users.sourceforge.net>
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 "avformat.h"
23 #include "internal.h"
24 #include "mux.h"
25 #include "libavutil/intreadwrite.h"
26
27 #define SUP_PGS_MAGIC 0x5047 /* "PG", big endian */
28
29 10 static int sup_write_packet(AVFormatContext *s, AVPacket *pkt)
30 {
31 10 const uint8_t *data = pkt->data;
32 10 size_t size = pkt->size;
33 10 uint32_t pts = 0, dts = 0;
34
35
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (pkt->pts != AV_NOPTS_VALUE) {
36 10 pts = pkt->pts;
37 }
38
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (pkt->dts != AV_NOPTS_VALUE) {
39 10 dts = pkt->dts;
40 }
41
42 /*
43 Split frame to segments.
44 mkvmerge stores multiple segments in one frame.
45 */
46
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 while (size > 2) {
47 10 size_t len = AV_RB16(data + 1) + 3;
48
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (len > size) {
50 av_log(s, AV_LOG_ERROR, "Not enough data, skipping %"SIZE_SPECIFIER" bytes\n",
51 size);
52 return AVERROR_INVALIDDATA;
53 }
54
55 /* header */
56 10 avio_wb16(s->pb, SUP_PGS_MAGIC);
57 10 avio_wb32(s->pb, pts);
58 10 avio_wb32(s->pb, dts);
59
60 10 avio_write(s->pb, data, len);
61
62 10 data += len;
63 10 size -= len;
64 }
65
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (size > 0) {
67 av_log(s, AV_LOG_ERROR, "Skipping %"SIZE_SPECIFIER" bytes after last segment in frame\n",
68 size);
69 return AVERROR_INVALIDDATA;
70 }
71
72 10 return 0;
73 }
74
75 1 static av_cold int sup_init(AVFormatContext *s)
76 {
77 1 avpriv_set_pts_info(s->streams[0], 32, 1, 90000);
78
79 1 return 0;
80 }
81
82 const FFOutputFormat ff_sup_muxer = {
83 .p.name = "sup",
84 .p.long_name = NULL_IF_CONFIG_SMALL("raw HDMV Presentation Graphic Stream subtitles"),
85 .p.extensions = "sup",
86 .p.mime_type = "application/x-pgs",
87 .p.video_codec = AV_CODEC_ID_NONE,
88 .p.audio_codec = AV_CODEC_ID_NONE,
89 .p.subtitle_codec = AV_CODEC_ID_HDMV_PGS_SUBTITLE,
90 .p.flags = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,
91 .flags_internal = FF_OFMT_FLAG_MAX_ONE_OF_EACH,
92 .init = sup_init,
93 .write_packet = sup_write_packet,
94 };
95