FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/qoadec.c
Date: 2024-05-04 02:01:39
Exec Total Coverage
Lines: 45 50 90.0%
Functions: 3 3 100.0%
Branches: 17 28 60.7%

Line Branch Exec Source
1 /*
2 * QOA demuxer
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "avformat.h"
22 #include "avio_internal.h"
23 #include "demux.h"
24 #include "internal.h"
25 #include "libavutil/intreadwrite.h"
26
27 7128 static int qoa_probe(const AVProbeData *p)
28 {
29
1/2
✓ Branch 0 taken 7128 times.
✗ Branch 1 not taken.
7128 if ((p->buf_size < 16) ||
30
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7125 times.
7128 (AV_RB32(p->buf) != MKBETAG('q','o','a','f')) ||
31
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 (AV_RB32(p->buf + 4) == 0) ||
32
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 (p->buf[8] == 0) ||
33
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 (AV_RB24(p->buf + 9) == 0) ||
34
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 (AV_RB16(p->buf + 12) == 0) ||
35
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 (AV_RB16(p->buf + 14) == 0))
36 7125 return 0;
37 3 return AVPROBE_SCORE_MAX;
38 }
39
40 3 static int qoa_read_header(AVFormatContext *s)
41 {
42 3 AVIOContext *pb = s->pb;
43 AVStream *st;
44
45 3 st = avformat_new_stream(s, NULL);
46
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!st)
47 return AVERROR(ENOMEM);
48
49 3 avio_skip(pb, 4);
50 3 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
51 3 st->codecpar->codec_id = AV_CODEC_ID_QOA;
52 3 st->duration = avio_rb32(pb);
53 3 st->start_time = 0;
54
55 3 ffio_ensure_seekback(pb, 4);
56 3 st->codecpar->ch_layout.nb_channels = avio_r8(pb);
57
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (st->codecpar->ch_layout.nb_channels == 0)
58 return AVERROR_INVALIDDATA;
59
60 3 st->codecpar->sample_rate = avio_rb24(pb);
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (st->codecpar->sample_rate == 0)
62 return AVERROR_INVALIDDATA;
63
64 3 avio_seek(pb, -4, SEEK_CUR);
65
66 3 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
67
68 3 return 0;
69 }
70
71 173 static int qoa_read_packet(AVFormatContext *s, AVPacket *pkt)
72 {
73 173 AVIOContext *pb = s->pb;
74 uint16_t size, duration;
75 uint8_t hdr[8];
76 int64_t pos;
77 int ret;
78
79
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 171 times.
173 if (avio_feof(pb))
80 2 return AVERROR_EOF;
81
82 171 pos = avio_tell(pb);
83 171 ret = avio_read(pb, hdr, sizeof(hdr));
84
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 168 times.
171 if (ret != sizeof(hdr))
85 3 return AVERROR_EOF;
86
87 168 duration = AV_RB16(hdr + 4);
88 168 size = AV_RB16(hdr + 6);
89
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 168 times.
168 if ((ret = av_new_packet(pkt, size)) < 0)
90 return ret;
91
92 168 memcpy(pkt->data, hdr, sizeof(hdr));
93 168 ret = avio_read(pb, pkt->data + sizeof(hdr), size - sizeof(hdr));
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if (ret != size - sizeof(hdr))
95 return AVERROR(EIO);
96 168 pkt->stream_index = 0;
97 168 pkt->pos = pos;
98 168 pkt->duration = duration;
99
100 168 return 0;
101 }
102
103 const FFInputFormat ff_qoa_demuxer = {
104 .p.name = "qoa",
105 .p.long_name = NULL_IF_CONFIG_SMALL("QOA"),
106 .p.flags = AVFMT_GENERIC_INDEX,
107 .p.extensions = "qoa",
108 .read_probe = qoa_probe,
109 .read_header = qoa_read_header,
110 .read_packet = qoa_read_packet,
111 };
112