FFmpeg
dfpwmdec.c
Go to the documentation of this file.
1 /*
2  * RAW PCM demuxers
3  * Copyright (c) 2002 Fabrice Bellard
4  * Copyright (c) 2022 Jack Bruienne
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/avstring.h"
24 #include "avformat.h"
25 #include "demux.h"
26 #include "internal.h"
27 #include "pcm.h"
28 #include "libavutil/log.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/avassert.h"
31 
32 typedef struct DFPWMAudioDemuxerContext {
33  AVClass *class;
37 
39 {
40  DFPWMAudioDemuxerContext *s1 = s->priv_data;
41  AVCodecParameters *par;
42  AVStream *st;
43  int ret;
44 
45  st = avformat_new_stream(s, NULL);
46  if (!st)
47  return AVERROR(ENOMEM);
48  par = st->codecpar;
49 
52  par->sample_rate = s1->sample_rate;
53  ret = av_channel_layout_copy(&par->ch_layout, &s1->ch_layout);
54  if (ret < 0)
55  return ret;
56  par->bits_per_coded_sample = 1;
57  par->block_align = 1;
58 
59  avpriv_set_pts_info(st, 64, 1, par->sample_rate);
60  return 0;
61 }
62 
63 static const AVOption dfpwm_options[] = {
64  { "sample_rate", "", offsetof(DFPWMAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
65  { "ch_layout", "", offsetof(DFPWMAudioDemuxerContext, ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "mono"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
66 { NULL },
67 };
68 static const AVClass dfpwm_demuxer_class = {
69  .class_name = "dfpwm demuxer",
70  .item_name = av_default_item_name,
71  .option = dfpwm_options,
72  .version = LIBAVUTIL_VERSION_INT,
73 };
74 
76  .p.name = "dfpwm",
77  .p.long_name = NULL_IF_CONFIG_SMALL("raw DFPWM1a"),
78  .p.flags = AVFMT_GENERIC_INDEX,
79  .p.extensions = "dfpwm",
80  .p.priv_class = &dfpwm_demuxer_class,
81  .priv_data_size = sizeof(DFPWMAudioDemuxerContext),
85  .raw_codec_id = AV_CODEC_ID_DFPWM,
86 };
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
pcm.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
DFPWMAudioDemuxerContext::sample_rate
int sample_rate
Definition: dfpwmdec.c:34
AVOption
AVOption.
Definition: opt.h:346
sample_rate
sample_rate
Definition: ffmpeg_filter.c:409
avpriv_set_pts_info
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:853
read_seek
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:151
AVFMT_GENERIC_INDEX
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:480
avassert.h
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_read_callback.c:41
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
s1
#define s1
Definition: regdef.h:38
AVFormatContext
Format I/O context.
Definition: avformat.h:1255
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:766
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:550
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
DFPWMAudioDemuxerContext::ch_layout
AVChannelLayout ch_layout
Definition: dfpwmdec.c:35
AV_OPT_TYPE_CHLAYOUT
@ AV_OPT_TYPE_CHLAYOUT
Definition: opt.h:252
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:303
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:41
dfpwm_read_header
static int dfpwm_read_header(AVFormatContext *s)
Definition: dfpwmdec.c:38
log.h
AVCodecParameters::block_align
int block_align
Audio only.
Definition: codec_par.h:191
demux.h
DFPWMAudioDemuxerContext
Definition: dfpwmdec.c:32
ff_pcm_read_packet
int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: pcm.c:57
ff_dfpwm_demuxer
const FFInputFormat ff_dfpwm_demuxer
Definition: dfpwmdec.c:75
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:743
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
ff_pcm_read_seek
int ff_pcm_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: pcm.c:73
avformat.h
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
dfpwm_options
static const AVOption dfpwm_options[]
Definition: dfpwmdec.c:63
dfpwm_demuxer_class
static const AVClass dfpwm_demuxer_class
Definition: dfpwmdec.c:68
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:439
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition: opt.h:273
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:110
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
FFInputFormat
Definition: demux.h:37
AV_CODEC_ID_DFPWM
@ AV_CODEC_ID_DFPWM
Definition: codec_id.h:536
avstring.h