FFmpeg
aptxdec.c
Go to the documentation of this file.
1 /*
2  * RAW aptX demuxer
3  *
4  * Copyright (C) 2017 Aurelien Jacobs <aurel@gnuage.org>
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 "config_components.h"
24 
25 #include "libavutil/opt.h"
26 #include "avformat.h"
27 
28 #define APTX_BLOCK_SIZE 4
29 #define APTX_PACKET_SIZE (256*APTX_BLOCK_SIZE)
30 
31 #define APTX_HD_BLOCK_SIZE 6
32 #define APTX_HD_PACKET_SIZE (256*APTX_HD_BLOCK_SIZE)
33 
34 typedef struct AptXDemuxerContext {
35  AVClass *class;
38 
40 {
41  AptXDemuxerContext *s1 = s->priv_data;
43  if (!st)
44  return NULL;
48  st->codecpar->sample_rate = s1->sample_rate;
49  st->start_time = 0;
50  return st;
51 }
52 
54 {
56  if (!st)
57  return AVERROR(ENOMEM);
62  return 0;
63 }
64 
66 {
68  if (!st)
69  return AVERROR(ENOMEM);
74  return 0;
75 }
76 
78 {
79  return av_get_packet(s->pb, pkt, APTX_PACKET_SIZE);
80 }
81 
83 {
84  return av_get_packet(s->pb, pkt, APTX_HD_PACKET_SIZE);
85 }
86 
87 static const AVOption aptx_options[] = {
88  { "sample_rate", "", offsetof(AptXDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
89  { NULL },
90 };
91 
92 static const AVClass aptx_demuxer_class = {
93  .class_name = "aptx (hd) demuxer",
94  .item_name = av_default_item_name,
95  .option = aptx_options,
96  .version = LIBAVUTIL_VERSION_INT,
97 };
98 
99 #if CONFIG_APTX_DEMUXER
101  .name = "aptx",
102  .long_name = NULL_IF_CONFIG_SMALL("raw aptX"),
103  .extensions = "aptx",
104  .priv_data_size = sizeof(AptXDemuxerContext),
108  .priv_class = &aptx_demuxer_class,
109 };
110 #endif
111 
112 #if CONFIG_APTX_HD_DEMUXER
114  .name = "aptx_hd",
115  .long_name = NULL_IF_CONFIG_SMALL("raw aptX HD"),
116  .extensions = "aptxhd",
117  .priv_data_size = sizeof(AptXDemuxerContext),
121  .priv_class = &aptx_demuxer_class,
122 };
123 #endif
aptx_hd_read_header
static int aptx_hd_read_header(AVFormatContext *s)
Definition: aptxdec.c:65
APTX_HD_BLOCK_SIZE
#define APTX_HD_BLOCK_SIZE
Definition: aptxdec.c:31
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:237
AptXDemuxerContext
Definition: aptxdec.c:34
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:57
aptx_options
static const AVOption aptx_options[]
Definition: aptxdec.c:87
aptx_demuxer_class
static const AVClass aptx_demuxer_class
Definition: aptxdec.c:92
AVOption
AVOption.
Definition: opt.h:251
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:300
sample_rate
sample_rate
Definition: ffmpeg_filter.c:153
AVFMT_GENERIC_INDEX
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:482
aptx_hd_read_packet
static int aptx_hd_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: aptxdec.c:82
pkt
AVPacket * pkt
Definition: movenc.c:59
AVInputFormat
Definition: avformat.h:656
AVCodecParameters::frame_size
int frame_size
Audio only.
Definition: codec_par.h:188
s
#define s(width, name)
Definition: cbs_vp9.c:256
APTX_PACKET_SIZE
#define APTX_PACKET_SIZE
Definition: aptxdec.c:29
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:661
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
s1
#define s1
Definition: regdef.h:38
aptx_read_header
static int aptx_read_header(AVFormatContext *s)
Definition: aptxdec.c:53
aptx_read_header_common
static AVStream * aptx_read_header_common(AVFormatContext *s)
Definition: aptxdec.c:39
AVFormatContext
Format I/O context.
Definition: avformat.h:1213
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1108
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:532
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
AptXDemuxerContext::sample_rate
int sample_rate
Definition: aptxdec.c:36
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:212
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:177
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:117
ff_aptx_demuxer
const AVInputFormat ff_aptx_demuxer
AVCodecParameters::block_align
int block_align
Audio only.
Definition: codec_par.h:184
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
av_get_packet
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:102
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVStream
Stream structure.
Definition: avformat.h:948
aptx_read_packet
static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: aptxdec.c:77
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
avformat.h
APTX_HD_PACKET_SIZE
#define APTX_HD_PACKET_SIZE
Definition: aptxdec.c:32
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
APTX_BLOCK_SIZE
#define APTX_BLOCK_SIZE
Definition: aptxdec.c:28
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:103
AVCodecParameters::format
int format
Definition: codec_par.h:85
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:61
AVPacket
This structure stores compressed data.
Definition: packet.h:351
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
ff_aptx_hd_demuxer
const AVInputFormat ff_aptx_hd_demuxer
AVStream::start_time
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition: avformat.h:988
AV_CODEC_ID_APTX
@ AV_CODEC_ID_APTX
Definition: codec_id.h:512
AV_CODEC_ID_APTX_HD
@ AV_CODEC_ID_APTX_HD
Definition: codec_id.h:513