FFmpeg
Loading...
Searching...
No Matches
wavarc.c
Go to the documentation of this file.
1/*
2 * WavArc 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
24#include "avformat.h"
25#include "avio_internal.h"
26#include "demux.h"
27#include "internal.h"
28
29typedef struct WavArcContext {
32
33static int wavarc_probe(const AVProbeData *p)
34{
35 int len = p->buf[0];
36 uint32_t id;
37
38 if (len == 0 || len + 6 >= p->buf_size)
39 return 0;
40
41 if (p->buf[len + 1] != 0)
42 return 0;
43
44 id = AV_RL32(p->buf + len + 2);
45 if (id != MKTAG('0','C','P','Y') &&
46 id != MKTAG('1','D','I','F') &&
47 id != MKTAG('2','S','L','P') &&
48 id != MKTAG('3','N','L','P') &&
49 id != MKTAG('4','A','L','P') &&
50 id != MKTAG('5','E','L','P'))
51 return 0;
52
53 return AVPROBE_SCORE_MAX / 3 * 2;
54}
55
57{
58 WavArcContext *w = s->priv_data;
59 AVIOContext *pb = s->pb;
61 int filename_len, fmt_len, ret;
62 uint8_t data[36];
63 AVStream *st;
64 uint32_t id;
65
66 filename_len = avio_r8(pb);
67 if (filename_len == 0)
69 avio_skip(pb, filename_len);
70 if (avio_r8(pb))
72 id = avio_rl32(pb);
73 w->data_end = avio_tell(pb);
74 if ((ret = ffio_read_size(pb, data, sizeof(data))) < 0)
75 return ret;
76 w->data_end += 16LL + AV_RL32(data + 4);
77 fmt_len = AV_RL32(data + 32);
78 if (fmt_len < 12)
80
82 if (!st)
83 return AVERROR(ENOMEM);
84 par = st->codecpar;
85
86 ret = ff_alloc_extradata(par, fmt_len + sizeof(data));
87 if (ret < 0)
88 return ret;
89 memcpy(par->extradata, data, sizeof(data));
90 ret = ffio_read_size(pb, par->extradata + sizeof(data), fmt_len);
91 if (ret < 0)
92 return ret;
93
96 par->codec_tag = id;
97
98 do {
99 id = avio_rl32(pb);
100 if (id != MKTAG('d','a','t','a'))
101 avio_skip(pb, avio_rl32(pb));
102 } while (id != MKTAG('d','a','t','a') && !avio_feof(pb));
103 avio_skip(pb, 4);
104
105 if (AV_RL32(par->extradata + 16) != MKTAG('R','I','F','F'))
106 return AVERROR_INVALIDDATA;
107 if (AV_RL32(par->extradata + 24) != MKTAG('W','A','V','E'))
108 return AVERROR_INVALIDDATA;
109 if (AV_RL32(par->extradata + 28) != MKTAG('f','m','t',' '))
110 return AVERROR_INVALIDDATA;
111
113 par->sample_rate = AV_RL32(par->extradata + 40);
114 avpriv_set_pts_info(st, 64, 1, par->sample_rate);
115 st->start_time = 0;
116
117 return 0;
118}
119
121{
122 WavArcContext *w = s->priv_data;
123 AVIOContext *pb = s->pb;
124 int64_t size, left = w->data_end - avio_tell(pb);
125 int ret;
126
127 size = FFMIN(left, 1024);
128 if (size <= 0)
129 return AVERROR_EOF;
130
131 ret = av_get_packet(pb, pkt, size);
132 pkt->stream_index = 0;
133 return ret;
134}
135
137 .p.name = "wavarc",
138 .p.long_name = NULL_IF_CONFIG_SMALL("Waveform Archiver"),
140 .p.extensions = "wa",
141 .priv_data_size = sizeof(WavArcContext),
145 .raw_codec_id = AV_CODEC_ID_WAVARC,
146};
const FFInputFormat ff_wavarc_demuxer
Definition wavarc.c:136
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
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition utils.c:98
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition avformat.h:498
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
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_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:665
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
Public libavutil channel layout APIs header.
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
enum AVCodecID id
Definition dts2pts.c:607
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
@ AV_CODEC_ID_WAVARC
Definition codec_id.h:554
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
#define AV_RL32(p)
#define AV_RL16(p)
int ff_alloc_extradata(AVCodecParameters *par, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0.
Definition utils.c:237
static int wavarc_probe(const AVProbeData *p)
Definition wavarc.c:33
static int wavarc_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition wavarc.c:120
static int wavarc_read_header(AVFormatContext *s)
Definition wavarc.c:56
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
uint8_t w
Definition llvidencdsp.c:39
#define FFMIN(a, b)
Definition macros.h:49
#define MKTAG(a, b, c, d)
Definition macros.h:55
const char data[16]
Definition mxf.c:149
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
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
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
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
Bytestream IO Context.
Definition avio.h:160
This structure stores compressed data.
Definition packet.h:580
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 start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition avformat.h:815
int64_t data_end
Definition wavarc.c:30
int size
int len