Coverage Report

Created: 2026-01-16 07:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavformat/osq.c
Line
Count
Source
1
/*
2
 * OSQ demuxer
3
 * Copyright (c) 2023 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 "avio_internal.h"
24
#include "avformat.h"
25
#include "demux.h"
26
#include "internal.h"
27
#include "rawdec.h"
28
29
static int osq_probe(const AVProbeData *p)
30
958k
{
31
958k
    if (AV_RL32(p->buf) != MKTAG('O','S','Q',' '))
32
957k
        return 0;
33
487
    if (AV_RL32(p->buf + 4) != 48)
34
161
        return 0;
35
326
    if (AV_RL16(p->buf + 8) != 1)
36
78
        return 0;
37
248
    if (p->buf[10] == 0)
38
39
        return 0;
39
209
    if (p->buf[11] == 0)
40
50
        return 0;
41
159
    if (AV_RL32(p->buf + 12) == 0)
42
53
        return 0;
43
106
    if (AV_RL16(p->buf + 16) == 0)
44
36
        return 0;
45
46
70
    return AVPROBE_SCORE_MAX;
47
106
}
48
49
static int osq_read_header(AVFormatContext *s)
50
1.31k
{
51
1.31k
    uint32_t t, size;
52
1.31k
    AVStream *st;
53
1.31k
    int ret;
54
55
1.31k
    t = avio_rl32(s->pb);
56
1.31k
    if (t != MKTAG('O','S','Q',' '))
57
214
        return AVERROR_INVALIDDATA;
58
59
1.09k
    size = avio_rl32(s->pb);
60
1.09k
    if (size != 48)
61
55
        return AVERROR_INVALIDDATA;
62
63
1.04k
    st = avformat_new_stream(s, NULL);
64
1.04k
    if (!st)
65
0
        return AVERROR(ENOMEM);
66
1.04k
    if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0)
67
55
        return ret;
68
69
986
    t = avio_rl32(s->pb);
70
986
    if (t != MKTAG('R','I','F','F'))
71
66
        return AVERROR_INVALIDDATA;
72
920
    avio_skip(s->pb, 8);
73
74
920
    t = avio_rl32(s->pb);
75
920
    if (t != MKTAG('f','m','t',' '))
76
65
        return AVERROR_INVALIDDATA;
77
855
    size = avio_rl32(s->pb);
78
855
    avio_skip(s->pb, size);
79
80
855
    t = avio_rl32(s->pb);
81
855
    size = avio_rl32(s->pb);
82
376k
    while (t != MKTAG('d','a','t','a')) {
83
375k
        avio_skip(s->pb, size);
84
85
375k
        t = avio_rl32(s->pb);
86
375k
        size = avio_rl32(s->pb);
87
375k
        if (avio_feof(s->pb))
88
392
            return AVERROR_INVALIDDATA;
89
375k
    }
90
91
463
    st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
92
463
    st->codecpar->codec_id    = AV_CODEC_ID_OSQ;
93
463
    st->codecpar->sample_rate = AV_RL32(st->codecpar->extradata + 4);
94
463
    if (st->codecpar->sample_rate <= 0)
95
31
        return AVERROR_INVALIDDATA;
96
432
    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
97
432
    st->codecpar->ch_layout.nb_channels = st->codecpar->extradata[3];
98
432
    if (st->codecpar->ch_layout.nb_channels == 0)
99
1
        return AVERROR_INVALIDDATA;
100
431
    st->start_time = 0;
101
431
    st->duration = AV_RL32(st->codecpar->extradata + 16);
102
431
    avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
103
104
431
    return 0;
105
432
}
106
107
const FFInputFormat ff_osq_demuxer = {
108
    .p.name         = "osq",
109
    .p.long_name    = NULL_IF_CONFIG_SMALL("raw OSQ"),
110
    .p.extensions   = "osq",
111
    .p.flags        = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK | AVFMT_NOTIMESTAMPS,
112
    .p.priv_class   = &ff_raw_demuxer_class,
113
    .read_probe     = osq_probe,
114
    .read_header    = osq_read_header,
115
    .read_packet    = ff_raw_read_partial_packet,
116
    .raw_codec_id   = AV_CODEC_ID_OSQ,
117
    .priv_data_size = sizeof(FFRawDemuxerContext),
118
};