FFmpeg
Loading...
Searching...
No Matches
wady.c
Go to the documentation of this file.
1/*
2 * WADY 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 "demux.h"
26#include "internal.h"
27#include "pcm.h"
28
29static int wady_probe(const AVProbeData *p)
30{
31 if (AV_RL32(p->buf) != MKTAG('W','A','D','Y'))
32 return 0;
33 if (p->buf[4] != 0 || p->buf[5] == 0 ||
34 AV_RL16(p->buf+6) == 0 ||
35 AV_RL16(p->buf+6) > 2 ||
36 (int32_t)AV_RL32(p->buf+8) <= 0)
37 return 0;
38
39 return AVPROBE_SCORE_MAX / 3 * 2;
40}
41
43{
44 AVIOContext *pb = s->pb;
46 int channels, ret;
47 AVStream *st;
48
49 avio_skip(pb, 4 + 1);
50
52 if (!st)
53 return AVERROR(ENOMEM);
54
55 par = st->codecpar;
59 if ((ret = ff_get_extradata(s, par, pb, 1)) < 0)
60 return ret;
61 channels = avio_rl16(pb);
62 if (channels == 0)
65 par->sample_rate = avio_rl32(pb);
66 if (par->sample_rate <= 0)
68 avio_skip(pb, 4);
69 st->duration = avio_rl32(pb);
70 par->block_align = channels;
71 avpriv_set_pts_info(st, 64, 1, par->sample_rate);
72
73 avio_seek(pb, 0x30, SEEK_SET);
74
75 return 0;
76}
77
79 .p.name = "wady",
80 .p.long_name = NULL_IF_CONFIG_SMALL("Marble WADY"),
81 .p.flags = AVFMT_GENERIC_INDEX,
82 .p.extensions = "way",
83 .read_probe = wady_probe,
84 .read_header = wady_read_header,
85 .read_packet = ff_pcm_read_packet,
86 .read_seek = ff_pcm_read_seek,
87};
const FFInputFormat ff_wady_demuxer
Definition wady.c:78
channels
Definition aptx.h:31
int32_t
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_GENERIC_INDEX
Use generic index building code.
Definition avformat.h:499
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
unsigned int avio_rl16(AVIOContext *s)
Definition aviobuf.c:717
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
#define s(width, name)
Definition cbs_vp9.c:198
Public libavutil channel layout APIs header.
#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_WADY_DPCM
Definition codec_id.h:449
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(e)
Definition error.h:45
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition samplefmt.h:58
#define AV_RL32(p)
#define AV_RL16(p)
int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition pcm.c:57
int ff_pcm_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition pcm.c:73
#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
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
int block_align
The number of bytes per coded audio frame, required by some formats.
Definition codec_par.h:221
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 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
static int wady_read_header(AVFormatContext *s)
Definition wady.c:42
static int wady_probe(const AVProbeData *p)
Definition wady.c:29