FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/mgsts.c
Date: 2026-09-26 20:14:34
Exec Total Coverage
Lines: 3 48 6.2%
Functions: 1 3 33.3%
Branches: 1 16 6.2%

Line Branch Exec Source
1 /*
2 * Metar Gear Solid: The Twin Snakes demuxer
3 * Copyright (c) 2012 Paul B Mahol
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 "libavutil/intreadwrite.h"
23 #include "libavutil/intfloat.h"
24 #include "avformat.h"
25 #include "demux.h"
26 #include "riff.h"
27
28 8071 static int read_probe(const AVProbeData *p)
29 {
30
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8071 times.
8071 if (AV_RB32(p->buf ) != 0x000E ||
31 ✗ AV_RB32(p->buf + 4) != 0x0050 ||
32 ✗ AV_RB32(p->buf + 12) != 0x0034)
33 8071 return 0;
34 ✗ return AVPROBE_SCORE_MAX;
35 }
36
37 ✗ static int read_header(AVFormatContext *s)
38 {
39 ✗ AVIOContext *pb = s->pb;
40 AVStream *st;
41 AVRational fps;
42 uint32_t chunk_size;
43
44 ✗ avio_skip(pb, 4);
45 ✗ chunk_size = avio_rb32(pb);
46 ✗ if (chunk_size != 80)
47 ✗ return AVERROR_INVALIDDATA;
48 ✗ avio_skip(pb, 20);
49
50 ✗ st = avformat_new_stream(s, 0);
51 ✗ if (!st)
52 ✗ return AVERROR(ENOMEM);
53
54 ✗ ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS;
55 ✗ st->start_time = 0;
56 ✗ st->nb_frames =
57 ✗ st->duration = avio_rb32(pb);
58 ✗ fps = av_d2q(av_int2float(avio_rb32(pb)), INT_MAX);
59 ✗ st->codecpar->width = avio_rb32(pb);
60 ✗ st->codecpar->height = avio_rb32(pb);
61 ✗ avio_skip(pb, 12);
62 ✗ st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
63 ✗ st->codecpar->codec_tag = avio_rb32(pb);
64 ✗ st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags,
65 ✗ st->codecpar->codec_tag);
66 ✗ avpriv_set_pts_info(st, 64, fps.den, fps.num);
67 ✗ avio_skip(pb, 20);
68
69 ✗ return 0;
70 }
71
72 ✗ static int read_packet(AVFormatContext *s, AVPacket *pkt)
73 {
74 ✗ AVIOContext *pb = s->pb;
75 uint32_t chunk_size, payload_size;
76 int ret;
77
78 ✗ if (avio_feof(pb))
79 ✗ return AVERROR_EOF;
80
81 ✗ avio_skip(pb, 4);
82 ✗ chunk_size = avio_rb32(pb);
83 ✗ avio_skip(pb, 4);
84 ✗ payload_size = avio_rb32(pb);
85
86 ✗ if (chunk_size < payload_size + 16)
87 ✗ return AVERROR_INVALIDDATA;
88
89 ✗ ret = av_get_packet(pb, pkt, payload_size);
90 ✗ if (ret < 0)
91 ✗ return ret;
92
93 ✗ pkt->pos -= 16;
94 ✗ pkt->duration = 1;
95 ✗ avio_skip(pb, chunk_size - (ret + 16));
96
97 ✗ return ret;
98 }
99
100 const FFInputFormat ff_mgsts_demuxer = {
101 .p.name = "mgsts",
102 .p.long_name = NULL_IF_CONFIG_SMALL("Metal Gear Solid: The Twin Snakes"),
103 .p.flags = AVFMT_GENERIC_INDEX,
104 .read_probe = read_probe,
105 .read_header = read_header,
106 .read_packet = read_packet,
107 };
108