FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/lvfdec.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 3 87 3.4%
Functions: 1 3 33.3%
Branches: 1 35 2.9%

Line Branch Exec Source
1 /*
2 * LVF 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 "avformat.h"
24 #include "demux.h"
25 #include "riff.h"
26
27 7186 static int lvf_probe(const AVProbeData *p)
28 {
29
1/2
✓ Branch 0 taken 7186 times.
✗ Branch 1 not taken.
7186 if (AV_RL32(p->buf) != MKTAG('L', 'V', 'F', 'F'))
30 7186 return 0;
31
32 if (!AV_RL32(p->buf + 16) || AV_RL32(p->buf + 16) > 256)
33 return AVPROBE_SCORE_MAX / 8;
34
35 return AVPROBE_SCORE_EXTENSION;
36 }
37
38 static int lvf_read_header(AVFormatContext *s)
39 {
40 AVStream *st;
41 int64_t next_offset;
42 unsigned size, nb_streams, id;
43
44 avio_skip(s->pb, 16);
45 nb_streams = avio_rl32(s->pb);
46 if (!nb_streams)
47 return AVERROR_INVALIDDATA;
48 if (nb_streams > 2) {
49 avpriv_request_sample(s, "%d streams", nb_streams);
50 return AVERROR_PATCHWELCOME;
51 }
52
53 avio_skip(s->pb, 1012);
54
55 while (!avio_feof(s->pb)) {
56 id = avio_rl32(s->pb);
57 size = avio_rl32(s->pb);
58 next_offset = avio_tell(s->pb) + size;
59
60 switch (id) {
61 case MKTAG('0', '0', 'f', 'm'):
62 st = avformat_new_stream(s, 0);
63 if (!st)
64 return AVERROR(ENOMEM);
65
66 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
67 avio_skip(s->pb, 4);
68 st->codecpar->width = avio_rl32(s->pb);
69 st->codecpar->height = avio_rl32(s->pb);
70 avio_skip(s->pb, 4);
71 st->codecpar->codec_tag = avio_rl32(s->pb);
72 st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags,
73 st->codecpar->codec_tag);
74 avpriv_set_pts_info(st, 32, 1, 1000);
75 break;
76 case MKTAG('0', '1', 'f', 'm'):
77 st = avformat_new_stream(s, 0);
78 if (!st)
79 return AVERROR(ENOMEM);
80
81 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
82 st->codecpar->codec_tag = avio_rl16(s->pb);
83 st->codecpar->ch_layout.nb_channels = avio_rl16(s->pb);
84 st->codecpar->sample_rate = avio_rl16(s->pb);
85 avio_skip(s->pb, 8);
86 st->codecpar->bits_per_coded_sample = avio_r8(s->pb);
87 st->codecpar->codec_id = ff_codec_get_id(ff_codec_wav_tags,
88 st->codecpar->codec_tag);
89 avpriv_set_pts_info(st, 32, 1, 1000);
90 break;
91 case 0:
92 avio_seek(s->pb, 2048 + 8, SEEK_SET);
93 return 0;
94 default:
95 avpriv_request_sample(s, "id %d", id);
96 return AVERROR_PATCHWELCOME;
97 }
98
99 avio_seek(s->pb, next_offset, SEEK_SET);
100 }
101
102 return AVERROR_EOF;
103 }
104
105 static int lvf_read_packet(AVFormatContext *s, AVPacket *pkt)
106 {
107 unsigned size, flags, timestamp, id;
108 int64_t pos;
109 int ret, is_video = 0;
110 int stream_index;
111
112 pos = avio_tell(s->pb);
113 while (!avio_feof(s->pb)) {
114 id = avio_rl32(s->pb);
115 size = avio_rl32(s->pb);
116
117 if (size == 0xFFFFFFFFu)
118 return AVERROR_EOF;
119
120 switch (id) {
121 case MKTAG('0', '0', 'd', 'c'):
122 is_video = 1;
123 case MKTAG('0', '1', 'w', 'b'):
124 if (size < 8)
125 return AVERROR_INVALIDDATA;
126 stream_index = is_video ? 0 : 1;
127 if (stream_index >= s->nb_streams)
128 return AVERROR_INVALIDDATA;
129 timestamp = avio_rl32(s->pb);
130 flags = avio_rl32(s->pb);
131 ret = av_get_packet(s->pb, pkt, size - 8);
132 if (flags & (1 << 12))
133 pkt->flags |= AV_PKT_FLAG_KEY;
134 pkt->stream_index = stream_index;
135 pkt->pts = timestamp;
136 pkt->pos = pos;
137 return ret;
138 default:
139 ret = avio_skip(s->pb, size);
140 }
141
142 if (ret < 0)
143 return ret;
144 }
145
146 return AVERROR_EOF;
147 }
148
149 const FFInputFormat ff_lvf_demuxer = {
150 .p.name = "lvf",
151 .p.long_name = NULL_IF_CONFIG_SMALL("LVF"),
152 .p.extensions = "lvf",
153 .p.flags = AVFMT_GENERIC_INDEX,
154 .read_probe = lvf_probe,
155 .read_header = lvf_read_header,
156 .read_packet = lvf_read_packet,
157 };
158