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 "internal.h"
26 #include "pcm.h"
27 #include "libavutil/log.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/avassert.h"
30 
31 typedef struct DFPWMAudioDemuxerContext {
32  AVClass *class;
34 #if FF_API_OLD_CHANNEL_LAYOUT
35  int channels;
36 #endif
39 
41 {
42  DFPWMAudioDemuxerContext *s1 = s->priv_data;
43  AVCodecParameters *par;
44  AVStream *st;
45  int ret;
46 
47  st = avformat_new_stream(s, NULL);
48  if (!st)
49  return AVERROR(ENOMEM);
50  par = st->codecpar;
51 
53  par->codec_id = s->iformat->raw_codec_id;
54  par->sample_rate = s1->sample_rate;
55 #if FF_API_OLD_CHANNEL_LAYOUT
56  if (s1->ch_layout.nb_channels) {
57 #endif
58  ret = av_channel_layout_copy(&par->ch_layout, &s1->ch_layout);
59  if (ret < 0)
60  return ret;
61 #if FF_API_OLD_CHANNEL_LAYOUT
62  } else
63  par->ch_layout.nb_channels = s1->channels;
64 #endif
65  par->bits_per_coded_sample = 1;
66  par->block_align = 1;
67 
68  avpriv_set_pts_info(st, 64, 1, par->sample_rate);
69  return 0;
70 }
71 
72 static const AVOption dfpwm_options[] = {
73  { "sample_rate", "", offsetof(DFPWMAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
74 #if FF_API_OLD_CHANNEL_LAYOUT
75  { "channels", "", offsetof(DFPWMAudioDemuxerContext, channels), AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_DEPRECATED },
76  { "ch_layout", "", offsetof(DFPWMAudioDemuxerContext, ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
77 #else
78  { "ch_layout", "", offsetof(DFPWMAudioDemuxerContext, ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "mono"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
79 #endif
80  { NULL },
81 };
82 static const AVClass dfpwm_demuxer_class = {
83  .class_name = "dfpwm demuxer",
84  .item_name = av_default_item_name,
85  .option = dfpwm_options,
86  .version = LIBAVUTIL_VERSION_INT,
87 };
88 
90  .name = "dfpwm",
91  .long_name = NULL_IF_CONFIG_SMALL("raw DFPWM1a"),
92  .priv_data_size = sizeof(DFPWMAudioDemuxerContext),
97  .extensions = "dfpwm",
98  .raw_codec_id = AV_CODEC_ID_DFPWM,
99  .priv_class = &dfpwm_demuxer_class,
100 };
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
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: options.c:243
pcm.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:58
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:54
DFPWMAudioDemuxerContext::sample_rate
int sample_rate
Definition: dfpwmdec.c:33
AVOption
AVOption.
Definition: opt.h:251
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
sample_rate
sample_rate
Definition: ffmpeg_filter.c:156
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:771
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
AVInputFormat
Definition: avformat.h:546
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:256
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:551
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
s1
#define s1
Definition: regdef.h:38
channels
channels
Definition: aptx.h:31
AVFormatContext
Format I/O context.
Definition: avformat.h:1104
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:861
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:545
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:37
AV_OPT_TYPE_CHLAYOUT
@ AV_OPT_TYPE_CHLAYOUT
Definition: opt.h:245
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:213
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:178
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:115
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:301
dfpwm_read_header
static int dfpwm_read_header(AVFormatContext *s)
Definition: dfpwmdec.c:40
log.h
AVCodecParameters::block_align
int block_align
Audio only.
Definition: codec_par.h:185
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:282
DFPWMAudioDemuxerContext
Definition: dfpwmdec.c:31
ff_pcm_read_packet
int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: pcm.c:29
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:838
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:56
avformat.h
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
dfpwm_options
static const AVOption dfpwm_options[]
Definition: dfpwmdec.c:72
dfpwm_demuxer_class
static const AVClass dfpwm_demuxer_class
Definition: dfpwmdec.c:82
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:639
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:104
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:62
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AV_CODEC_ID_DFPWM
@ AV_CODEC_ID_DFPWM
Definition: codec_id.h:534
avstring.h
ff_dfpwm_demuxer
const AVInputFormat ff_dfpwm_demuxer
Definition: dfpwmdec.c:89
AV_OPT_FLAG_DEPRECATED
#define AV_OPT_FLAG_DEPRECATED
set if option is deprecated, users should refer to AVOption.help text for more information
Definition: opt.h:298