FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "avformat.h"
24 #include "rawdec.h"
25 
26 #define APTX_BLOCK_SIZE 4
27 #define APTX_PACKET_SIZE (256*APTX_BLOCK_SIZE)
28 
29 #define APTX_HD_BLOCK_SIZE 6
30 #define APTX_HD_PACKET_SIZE (256*APTX_HD_BLOCK_SIZE)
31 
32 typedef struct AptXDemuxerContext {
33  AVClass *class;
36 
38 {
41  if (!st)
42  return NULL;
45  st->codecpar->channels = 2;
46  st->codecpar->sample_rate = s1->sample_rate;
47  st->start_time = 0;
48  return st;
49 }
50 
52 {
54  if (!st)
55  return AVERROR(ENOMEM);
60  return 0;
61 }
62 
64 {
66  if (!st)
67  return AVERROR(ENOMEM);
72  return 0;
73 }
74 
76 {
77  return av_get_packet(s->pb, pkt, APTX_PACKET_SIZE);
78 }
79 
81 {
82  return av_get_packet(s->pb, pkt, APTX_HD_PACKET_SIZE);
83 }
84 
85 static const AVOption aptx_options[] = {
86  { "sample_rate", "", offsetof(AptXDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
87  { NULL },
88 };
89 
90 #if CONFIG_APTX_DEMUXER
91 static const AVClass aptx_demuxer_class = {
92  .class_name = "aptx demuxer",
93  .item_name = av_default_item_name,
94  .option = aptx_options,
95  .version = LIBAVUTIL_VERSION_INT,
96 };
97 
99  .name = "aptx",
100  .long_name = NULL_IF_CONFIG_SMALL("raw aptX"),
101  .extensions = "aptx",
102  .priv_data_size = sizeof(AptXDemuxerContext),
106  .priv_class = &aptx_demuxer_class,
107 };
108 #endif
109 
110 #if CONFIG_APTX_HD_DEMUXER
111 static const AVClass aptx_hd_demuxer_class = {
112  .class_name = "aptx hd demuxer",
113  .item_name = av_default_item_name,
114  .option = aptx_options,
115  .version = LIBAVUTIL_VERSION_INT,
116 };
117 
119  .name = "aptx_hd",
120  .long_name = NULL_IF_CONFIG_SMALL("raw aptX HD"),
121  .extensions = "aptxhd",
122  .priv_data_size = sizeof(AptXDemuxerContext),
126  .priv_class = &aptx_hd_demuxer_class,
127 };
128 #endif
#define NULL
Definition: coverity.c:32
AVOption.
Definition: opt.h:246
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3900
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
static const AVOption aptx_options[]
Definition: aptxdec.c:85
#define APTX_HD_BLOCK_SIZE
Definition: aptxdec.c:29
static AVStream * aptx_read_header_common(AVFormatContext *s)
Definition: aptxdec.c:37
static AVPacket pkt
int frame_size
Audio only.
Definition: avcodec.h:4021
#define APTX_HD_PACKET_SIZE
Definition: aptxdec.c:30
Format I/O context.
Definition: avformat.h:1351
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:72
#define APTX_BLOCK_SIZE
Definition: aptxdec.c:26
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4455
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:310
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3896
#define APTX_PACKET_SIZE
Definition: aptxdec.c:27
int block_align
Audio only.
Definition: avcodec.h:4017
signed 32 bits, planar
Definition: samplefmt.h:68
static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: aptxdec.c:75
static int aptx_hd_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: aptxdec.c:80
AVInputFormat ff_aptx_demuxer
#define s(width, name)
Definition: cbs_vp9.c:257
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
Stream structure.
Definition: avformat.h:874
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
sample_rate
AVIOContext * pb
I/O context.
Definition: avformat.h:1393
Describe the class of an AVClass context structure.
Definition: log.h:67
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:470
AVInputFormat ff_aptx_hd_demuxer
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:277
#define s1
Definition: regdef.h:38
static int aptx_read_header(AVFormatContext *s)
Definition: aptxdec.c:51
#define flags(name, subs,...)
Definition: cbs_av1.c:596
int sample_rate
Audio only.
Definition: avcodec.h:4010
Main libavformat public API header.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:913
static int aptx_hd_read_header(AVFormatContext *s)
Definition: aptxdec.c:63
void * priv_data
Format private data.
Definition: avformat.h:1379
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: avcodec.h:3942
int channels
Audio only.
Definition: avcodec.h:4006
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:647
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1021
This structure stores compressed data.
Definition: avcodec.h:1422