FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/osq.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 43 58 74.1%
Functions: 2 2 100.0%
Branches: 19 34 55.9%

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