Coverage Report

Created: 2026-04-01 07:42

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
959k
{
29
959k
    if (AV_RL32(p->buf) != MKTAG('L', 'V', 'F', 'F'))
30
958k
        return 0;
31
32
621
    if (!AV_RL32(p->buf + 16) || AV_RL32(p->buf + 16) > 256)
33
453
        return AVPROBE_SCORE_MAX / 8;
34
35
168
    return AVPROBE_SCORE_EXTENSION;
36
621
}
37
38
static int lvf_read_header(AVFormatContext *s)
39
3.85k
{
40
3.85k
    AVStream *st;
41
3.85k
    int64_t next_offset;
42
3.85k
    unsigned size, nb_streams, id;
43
44
3.85k
    avio_skip(s->pb, 16);
45
3.85k
    nb_streams = avio_rl32(s->pb);
46
3.85k
    if (!nb_streams)
47
13
        return AVERROR_INVALIDDATA;
48
3.84k
    if (nb_streams > 2) {
49
193
        avpriv_request_sample(s, "%d streams", nb_streams);
50
193
        return AVERROR_PATCHWELCOME;
51
193
    }
52
53
3.64k
    avio_skip(s->pb, 1012);
54
55
38.2k
    while (!avio_feof(s->pb)) {
56
37.9k
        id          = avio_rl32(s->pb);
57
37.9k
        size        = avio_rl32(s->pb);
58
37.9k
        next_offset = avio_tell(s->pb) + size;
59
60
37.9k
        switch (id) {
61
20.3k
        case MKTAG('0', '0', 'f', 'm'):
62
20.3k
            st = avformat_new_stream(s, 0);
63
20.3k
            if (!st)
64
1
                return AVERROR(ENOMEM);
65
66
20.3k
            st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
67
20.3k
            avio_skip(s->pb, 4);
68
20.3k
            st->codecpar->width      = avio_rl32(s->pb);
69
20.3k
            st->codecpar->height     = avio_rl32(s->pb);
70
20.3k
            avio_skip(s->pb, 4);
71
20.3k
            st->codecpar->codec_tag  = avio_rl32(s->pb);
72
20.3k
            st->codecpar->codec_id   = ff_codec_get_id(ff_codec_bmp_tags,
73
20.3k
                                                       st->codecpar->codec_tag);
74
20.3k
            avpriv_set_pts_info(st, 32, 1, 1000);
75
20.3k
            break;
76
14.2k
        case MKTAG('0', '1', 'f', 'm'):
77
14.2k
            st = avformat_new_stream(s, 0);
78
14.2k
            if (!st)
79
1
                return AVERROR(ENOMEM);
80
81
14.2k
            st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
82
14.2k
            st->codecpar->codec_tag   = avio_rl16(s->pb);
83
14.2k
            st->codecpar->ch_layout.nb_channels = avio_rl16(s->pb);
84
14.2k
            st->codecpar->sample_rate = avio_rl16(s->pb);
85
14.2k
            avio_skip(s->pb, 8);
86
14.2k
            st->codecpar->bits_per_coded_sample = avio_r8(s->pb);
87
14.2k
            st->codecpar->codec_id    = ff_codec_get_id(ff_codec_wav_tags,
88
14.2k
                                                        st->codecpar->codec_tag);
89
14.2k
            avpriv_set_pts_info(st, 32, 1, 1000);
90
14.2k
            break;
91
3.12k
        case 0:
92
3.12k
            avio_seek(s->pb, 2048 + 8, SEEK_SET);
93
3.12k
            return 0;
94
244
        default:
95
244
            avpriv_request_sample(s, "id %d", id);
96
244
            return AVERROR_PATCHWELCOME;
97
37.9k
        }
98
99
34.5k
        avio_seek(s->pb, next_offset, SEEK_SET);
100
34.5k
    }
101
102
279
    return AVERROR_EOF;
103
3.64k
}
104
105
static int lvf_read_packet(AVFormatContext *s, AVPacket *pkt)
106
59.8k
{
107
59.8k
    unsigned size, flags, timestamp, id;
108
59.8k
    int64_t pos;
109
59.8k
    int ret, is_video = 0;
110
59.8k
    int stream_index;
111
112
59.8k
    pos = avio_tell(s->pb);
113
132k
    while (!avio_feof(s->pb)) {
114
128k
        id    = avio_rl32(s->pb);
115
128k
        size  = avio_rl32(s->pb);
116
117
128k
        if (size == 0xFFFFFFFFu)
118
100
            return AVERROR_EOF;
119
120
127k
        switch (id) {
121
54.0k
        case MKTAG('0', '0', 'd', 'c'):
122
54.0k
            is_video = 1;
123
54.4k
        case MKTAG('0', '1', 'w', 'b'):
124
54.4k
            if (size < 8)
125
12
                return AVERROR_INVALIDDATA;
126
54.3k
            stream_index = is_video ? 0 : 1;
127
54.3k
            if (stream_index >= s->nb_streams)
128
4
                return AVERROR_INVALIDDATA;
129
54.3k
            timestamp = avio_rl32(s->pb);
130
54.3k
            flags = avio_rl32(s->pb);
131
54.3k
            ret = av_get_packet(s->pb, pkt, size - 8);
132
54.3k
            if (flags & (1 << 12))
133
26.8k
                pkt->flags |= AV_PKT_FLAG_KEY;
134
54.3k
            pkt->stream_index = stream_index;
135
54.3k
            pkt->pts          = timestamp;
136
54.3k
            pkt->pos          = pos;
137
54.3k
            return ret;
138
73.5k
        default:
139
73.5k
            ret = avio_skip(s->pb, size);
140
127k
        }
141
142
73.5k
        if (ret < 0)
143
922
            return ret;
144
73.5k
    }
145
146
4.39k
    return AVERROR_EOF;
147
59.8k
}
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
};