FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/bonk.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 6 42 14.3%
Branches: 7 38 18.4%

Line Branch Exec Source
1 /*
2 * Bonk demuxer
3 * Copyright (c) 2016 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 "internal.h"
26 #include "rawdec.h"
27
28 6780 static int bonk_probe(const AVProbeData *p)
29 {
30
2/2
✓ Branch 0 taken 292028 times.
✓ Branch 1 taken 91 times.
292119 for (int i = 0; i < p->buf_size - 22; i++) {
31
3/4
✓ Branch 0 taken 6689 times.
✓ Branch 1 taken 285339 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6689 times.
292028 if (!p->buf[i] && AV_RL32(p->buf + i + 1) == MKTAG('B','O','N','K')) {
32 if (p->buf[i + 5])
33 return 0;
34 if (AV_RL32(p->buf + i + 6) == 0)
35 return 0;
36 if (AV_RL32(p->buf + i + 10) == 0)
37 return 0;
38 if (p->buf[i + 14] == 0)
39 return 0;
40 if (AV_RL16(p->buf + i + 17) == 0 ||
41 AV_RL16(p->buf + i + 17) > 2048)
42 return 0;
43 if (p->buf[i + 19] == 0)
44 return 0;
45 if (AV_RL16(p->buf + i + 20) == 0)
46 return 0;
47 return AVPROBE_SCORE_MAX;
48
2/2
✓ Branch 0 taken 6689 times.
✓ Branch 1 taken 285339 times.
292028 } else if (!p->buf[i]) {
49 6689 break;
50 }
51 }
52
53 6780 return 0;
54 }
55
56 static int bonk_read_header(AVFormatContext *s)
57 {
58 AVStream *st;
59 int ret;
60
61 for (int i = 0; !avio_feof(s->pb); i++) {
62 int b = avio_r8(s->pb);
63 if (!b && avio_rl32(s->pb) == MKTAG('B','O','N','K'))
64 break;
65 else if (!b)
66 return AVERROR_INVALIDDATA;
67 }
68
69 st = avformat_new_stream(s, NULL);
70 if (!st)
71 return AVERROR(ENOMEM);
72 if ((ret = ff_get_extradata(s, st->codecpar, s->pb, 17)) < 0)
73 return ret;
74 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
75 st->codecpar->codec_id = AV_CODEC_ID_BONK;
76 st->codecpar->sample_rate = AV_RL32(st->codecpar->extradata + 5);
77 st->codecpar->ch_layout.nb_channels = st->codecpar->extradata[9];
78 if (st->codecpar->ch_layout.nb_channels == 0)
79 return AVERROR_INVALIDDATA;
80 st->duration = AV_RL32(st->codecpar->extradata + 1) / st->codecpar->ch_layout.nb_channels;
81 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
82
83 return 0;
84 }
85
86 const AVInputFormat ff_bonk_demuxer = {
87 .name = "bonk",
88 .long_name = NULL_IF_CONFIG_SMALL("raw Bonk"),
89 .read_probe = bonk_probe,
90 .read_header = bonk_read_header,
91 .read_packet = ff_raw_read_partial_packet,
92 .extensions = "bonk",
93 .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK | AVFMT_NOTIMESTAMPS,
94 .raw_codec_id = AV_CODEC_ID_BONK,
95 .priv_data_size = sizeof(FFRawDemuxerContext),
96 .priv_class = &ff_raw_demuxer_class,
97 };
98