FFmpeg
Loading...
Searching...
No Matches
bonk.c
Go to the documentation of this file.
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
23#include "avio_internal.h"
24#include "avformat.h"
25#include "demux.h"
26#include "internal.h"
27#include "id3v2.h"
28#include "rawdec.h"
29
30static int bonk_probe(const AVProbeData *p)
31{
32 for (int i = 0; i < p->buf_size - 22; i++) {
33 if (!p->buf[i] && AV_RL32(p->buf + i + 1) == MKTAG('B','O','N','K')) {
34 if (p->buf[i + 5])
35 return 0;
36 if (AV_RL32(p->buf + i + 6) == 0)
37 return 0;
38 if (AV_RL32(p->buf + i + 10) == 0)
39 return 0;
40 if (p->buf[i + 14] == 0)
41 return 0;
42 if (AV_RL16(p->buf + i + 17) == 0 ||
43 AV_RL16(p->buf + i + 17) > 2048)
44 return 0;
45 if (p->buf[i + 19] == 0)
46 return 0;
47 if (AV_RL16(p->buf + i + 20) == 0)
48 return 0;
49 return AVPROBE_SCORE_MAX;
50 }
51 }
52
53 return 0;
54}
55
57{
58 ID3v2ExtraMeta *extra_meta;
59 AVStream *st;
60 int ret;
61
62 while (!avio_feof(s->pb)) {
63 const int b = avio_r8(s->pb);
64 if (!b) {
65 uint32_t t;
66 ret = ffio_ensure_seekback(s->pb, 3);
67 if (ret < 0)
68 return ret;
69
70 t = avio_rl32(s->pb);
71 if (t == MKTAG('B','O','N','K')) {
72 break;
73 } else if (t == MKTAG(' ','I','D','3')) {
74 avio_seek(s->pb, -3, SEEK_CUR);
75 ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &extra_meta, 0);
76 if (extra_meta) {
77 ff_id3v2_parse_apic(s, extra_meta);
78 ff_id3v2_parse_priv(s, extra_meta);
79 ff_id3v2_free_extra_meta(&extra_meta);
80 }
81 avio_skip(s->pb, 8);
82 } else {
84 }
85 }
86 }
87
89 if (!st)
90 return AVERROR(ENOMEM);
91 if ((ret = ff_get_extradata(s, st->codecpar, s->pb, 17)) < 0)
92 return ret;
97 if (st->codecpar->ch_layout.nb_channels == 0)
101
102 return 0;
103}
104
106 .p.name = "bonk",
107 .p.long_name = NULL_IF_CONFIG_SMALL("raw Bonk"),
108 .p.extensions = "bonk",
110 .p.priv_class = &ff_raw_demuxer_class,
111 .read_probe = bonk_probe,
112 .read_header = bonk_read_header,
113 .read_packet = ff_raw_read_partial_packet,
114 .raw_codec_id = AV_CODEC_ID_BONK,
115 .priv_data_size = sizeof(FFRawDemuxerContext),
116};
const FFInputFormat ff_bonk_demuxer
Definition bonk.c:105
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition avformat.h:506
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition avformat.h:505
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition avformat.h:504
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition avformat.h:498
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
unsigned int avio_rl32(AVIOContext *s)
Definition aviobuf.c:733
int avio_r8(AVIOContext *s)
Definition aviobuf.c:606
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
Definition aviobuf.c:1026
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
int ff_get_extradata(void *logctx, AVCodecParameters *par, AVIOContext *pb, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and f...
@ AV_CODEC_ID_BONK
Definition codec_id.h:550
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta, unsigned int max_search_size)
Read an ID3v2 tag, including supported extra metadata.
Definition id3v2.c:1180
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
Definition id3v2.c:1186
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header.
Definition id3v2.c:1202
int ff_id3v2_parse_priv(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Add metadata for all PRIV tags in the ID3v2 header.
Definition id3v2.c:1298
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
Definition id3v2.h:35
#define b
Definition input.c:43
#define AV_RL32(p)
#define AV_RL16(p)
static int bonk_read_header(AVFormatContext *s)
Definition bonk.c:56
static int bonk_probe(const AVProbeData *p)
Definition bonk.c:30
const AVClass ff_raw_demuxer_class
Definition rawdec.c:141
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
Definition rawdec.c:33
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#define MKTAG(a, b, c, d)
Definition macros.h:55
int nb_channels
Number of channels in this layout.
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1333
This structure contains the data a format has to probe a file.
Definition avformat.h:471
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition avformat.h:825