Coverage Report

Created: 2026-05-16 07:49

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
971k
{
31
971k
    if (AV_RL32(p->buf) != MKTAG('O','S','Q',' '))
32
970k
        return 0;
33
602
    if (AV_RL32(p->buf + 4) != 48)
34
187
        return 0;
35
415
    if (AV_RL16(p->buf + 8) != 1)
36
88
        return 0;
37
327
    if (p->buf[10] == 0)
38
48
        return 0;
39
279
    if (p->buf[11] == 0)
40
61
        return 0;
41
218
    if (AV_RL32(p->buf + 12) == 0)
42
64
        return 0;
43
154
    if (AV_RL16(p->buf + 16) == 0)
44
61
        return 0;
45
46
93
    return AVPROBE_SCORE_MAX;
47
154
}
48
49
static int osq_read_header(AVFormatContext *s)
50
1.35k
{
51
1.35k
    uint32_t t, size;
52
1.35k
    AVStream *st;
53
1.35k
    int ret;
54
55
1.35k
    t = avio_rl32(s->pb);
56
1.35k
    if (t != MKTAG('O','S','Q',' '))
57
214
        return AVERROR_INVALIDDATA;
58
59
1.13k
    size = avio_rl32(s->pb);
60
1.13k
    if (size != 48)
61
56
        return AVERROR_INVALIDDATA;
62
63
1.08k
    st = avformat_new_stream(s, NULL);
64
1.08k
    if (!st)
65
0
        return AVERROR(ENOMEM);
66
1.08k
    if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0)
67
57
        return ret;
68
69
1.02k
    t = avio_rl32(s->pb);
70
1.02k
    if (t != MKTAG('R','I','F','F'))
71
71
        return AVERROR_INVALIDDATA;
72
954
    avio_skip(s->pb, 8);
73
74
954
    t = avio_rl32(s->pb);
75
954
    if (t != MKTAG('f','m','t',' '))
76
61
        return AVERROR_INVALIDDATA;
77
893
    size = avio_rl32(s->pb);
78
893
    avio_skip(s->pb, size);
79
80
893
    t = avio_rl32(s->pb);
81
893
    size = avio_rl32(s->pb);
82
403k
    while (t != MKTAG('d','a','t','a')) {
83
402k
        avio_skip(s->pb, size);
84
85
402k
        t = avio_rl32(s->pb);
86
402k
        size = avio_rl32(s->pb);
87
402k
        if (avio_feof(s->pb))
88
388
            return AVERROR_INVALIDDATA;
89
402k
    }
90
91
505
    st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
92
505
    st->codecpar->codec_id    = AV_CODEC_ID_OSQ;
93
505
    st->codecpar->sample_rate = AV_RL32(st->codecpar->extradata + 4);
94
505
    if (st->codecpar->sample_rate <= 0)
95
34
        return AVERROR_INVALIDDATA;
96
471
    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
97
471
    st->codecpar->ch_layout.nb_channels = st->codecpar->extradata[3];
98
471
    if (st->codecpar->ch_layout.nb_channels == 0)
99
2
        return AVERROR_INVALIDDATA;
100
469
    st->start_time = 0;
101
469
    st->duration = AV_RL32(st->codecpar->extradata + 16);
102
469
    avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
103
104
469
    return 0;
105
471
}
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
};