Coverage Report

Created: 2026-02-14 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavformat/lvfdec.c
Line
Count
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
static int lvf_probe(const AVProbeData *p)
28
936k
{
29
936k
    if (AV_RL32(p->buf) != MKTAG('L', 'V', 'F', 'F'))
30
936k
        return 0;
31
32
549
    if (!AV_RL32(p->buf + 16) || AV_RL32(p->buf + 16) > 256)
33
391
        return AVPROBE_SCORE_MAX / 8;
34
35
158
    return AVPROBE_SCORE_EXTENSION;
36
549
}
37
38
static int lvf_read_header(AVFormatContext *s)
39
3.66k
{
40
3.66k
    AVStream *st;
41
3.66k
    int64_t next_offset;
42
3.66k
    unsigned size, nb_streams, id;
43
44
3.66k
    avio_skip(s->pb, 16);
45
3.66k
    nb_streams = avio_rl32(s->pb);
46
3.66k
    if (!nb_streams)
47
16
        return AVERROR_INVALIDDATA;
48
3.65k
    if (nb_streams > 2) {
49
205
        avpriv_request_sample(s, "%d streams", nb_streams);
50
205
        return AVERROR_PATCHWELCOME;
51
205
    }
52
53
3.44k
    avio_skip(s->pb, 1012);
54
55
35.6k
    while (!avio_feof(s->pb)) {
56
35.3k
        id          = avio_rl32(s->pb);
57
35.3k
        size        = avio_rl32(s->pb);
58
35.3k
        next_offset = avio_tell(s->pb) + size;
59
60
35.3k
        switch (id) {
61
20.1k
        case MKTAG('0', '0', 'f', 'm'):
62
20.1k
            st = avformat_new_stream(s, 0);
63
20.1k
            if (!st)
64
1
                return AVERROR(ENOMEM);
65
66
20.1k
            st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
67
20.1k
            avio_skip(s->pb, 4);
68
20.1k
            st->codecpar->width      = avio_rl32(s->pb);
69
20.1k
            st->codecpar->height     = avio_rl32(s->pb);
70
20.1k
            avio_skip(s->pb, 4);
71
20.1k
            st->codecpar->codec_tag  = avio_rl32(s->pb);
72
20.1k
            st->codecpar->codec_id   = ff_codec_get_id(ff_codec_bmp_tags,
73
20.1k
                                                       st->codecpar->codec_tag);
74
20.1k
            avpriv_set_pts_info(st, 32, 1, 1000);
75
20.1k
            break;
76
12.0k
        case MKTAG('0', '1', 'f', 'm'):
77
12.0k
            st = avformat_new_stream(s, 0);
78
12.0k
            if (!st)
79
1
                return AVERROR(ENOMEM);
80
81
12.0k
            st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
82
12.0k
            st->codecpar->codec_tag   = avio_rl16(s->pb);
83
12.0k
            st->codecpar->ch_layout.nb_channels = avio_rl16(s->pb);
84
12.0k
            st->codecpar->sample_rate = avio_rl16(s->pb);
85
12.0k
            avio_skip(s->pb, 8);
86
12.0k
            st->codecpar->bits_per_coded_sample = avio_r8(s->pb);
87
12.0k
            st->codecpar->codec_id    = ff_codec_get_id(ff_codec_wav_tags,
88
12.0k
                                                        st->codecpar->codec_tag);
89
12.0k
            avpriv_set_pts_info(st, 32, 1, 1000);
90
12.0k
            break;
91
2.95k
        case 0:
92
2.95k
            avio_seek(s->pb, 2048 + 8, SEEK_SET);
93
2.95k
            return 0;
94
236
        default:
95
236
            avpriv_request_sample(s, "id %d", id);
96
236
            return AVERROR_PATCHWELCOME;
97
35.3k
        }
98
99
32.2k
        avio_seek(s->pb, next_offset, SEEK_SET);
100
32.2k
    }
101
102
255
    return AVERROR_EOF;
103
3.44k
}
104
105
static int lvf_read_packet(AVFormatContext *s, AVPacket *pkt)
106
58.4k
{
107
58.4k
    unsigned size, flags, timestamp, id;
108
58.4k
    int64_t pos;
109
58.4k
    int ret, is_video = 0;
110
58.4k
    int stream_index;
111
112
58.4k
    pos = avio_tell(s->pb);
113
130k
    while (!avio_feof(s->pb)) {
114
126k
        id    = avio_rl32(s->pb);
115
126k
        size  = avio_rl32(s->pb);
116
117
126k
        if (size == 0xFFFFFFFFu)
118
88
            return AVERROR_EOF;
119
120
125k
        switch (id) {
121
52.9k
        case MKTAG('0', '0', 'd', 'c'):
122
52.9k
            is_video = 1;
123
53.2k
        case MKTAG('0', '1', 'w', 'b'):
124
53.2k
            if (size < 8)
125
9
                return AVERROR_INVALIDDATA;
126
53.2k
            stream_index = is_video ? 0 : 1;
127
53.2k
            if (stream_index >= s->nb_streams)
128
4
                return AVERROR_INVALIDDATA;
129
53.2k
            timestamp = avio_rl32(s->pb);
130
53.2k
            flags = avio_rl32(s->pb);
131
53.2k
            ret = av_get_packet(s->pb, pkt, size - 8);
132
53.2k
            if (flags & (1 << 12))
133
26.7k
                pkt->flags |= AV_PKT_FLAG_KEY;
134
53.2k
            pkt->stream_index = stream_index;
135
53.2k
            pkt->pts          = timestamp;
136
53.2k
            pkt->pos          = pos;
137
53.2k
            return ret;
138
72.6k
        default:
139
72.6k
            ret = avio_skip(s->pb, size);
140
125k
        }
141
142
72.6k
        if (ret < 0)
143
854
            return ret;
144
72.6k
    }
145
146
4.23k
    return AVERROR_EOF;
147
58.4k
}
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
};