FFmpeg
Loading...
Searching...
No Matches
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#include "demux.h"
28
29#define APTX_BLOCK_SIZE 4
30#define APTX_PACKET_SIZE (256*APTX_BLOCK_SIZE)
31
32#define APTX_HD_BLOCK_SIZE 6
33#define APTX_HD_PACKET_SIZE (256*APTX_HD_BLOCK_SIZE)
34
39
41{
42 AptXDemuxerContext *s1 = s->priv_data;
44 if (!st)
45 return NULL;
50 st->start_time = 0;
51 return st;
52}
53
55{
57 if (!st)
58 return AVERROR(ENOMEM);
62 return 0;
63}
64
66{
68 if (!st)
69 return AVERROR(ENOMEM);
73 return 0;
74}
75
77{
78 int ret = av_get_packet(s->pb, pkt, APTX_PACKET_SIZE);
79 if (ret >= 0 && !(ret % APTX_BLOCK_SIZE))
80 pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
81 return ret >= 0 ? 0 : ret;
82}
83
85{
86 int ret = av_get_packet(s->pb, pkt, APTX_HD_PACKET_SIZE);
87 if (ret >= 0 && !(ret % APTX_HD_BLOCK_SIZE))
88 pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
89 return ret >= 0 ? 0 : ret;
90}
91
92static const AVOption aptx_options[] = {
93 { "sample_rate", "", offsetof(AptXDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
94 { NULL },
95};
96
98 .class_name = "aptx (hd) demuxer",
99 .item_name = av_default_item_name,
100 .option = aptx_options,
101 .version = LIBAVUTIL_VERSION_INT,
102};
103
104#if CONFIG_APTX_DEMUXER
106 .p.name = "aptx",
107 .p.long_name = NULL_IF_CONFIG_SMALL("raw aptX"),
108 .p.extensions = "aptx",
109 .p.flags = AVFMT_GENERIC_INDEX,
110 .p.priv_class = &aptx_demuxer_class,
111 .priv_data_size = sizeof(AptXDemuxerContext),
114};
115#endif
116
117#if CONFIG_APTX_HD_DEMUXER
119 .p.name = "aptx_hd",
120 .p.long_name = NULL_IF_CONFIG_SMALL("raw aptX HD"),
121 .p.extensions = "aptxhd",
122 .p.flags = AVFMT_GENERIC_INDEX,
123 .p.priv_class = &aptx_demuxer_class,
124 .priv_data_size = sizeof(AptXDemuxerContext),
127};
128#endif
const FFInputFormat ff_aptx_demuxer
const FFInputFormat ff_aptx_hd_demuxer
Main libavformat public API header.
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:98
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition avformat.h:499
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
static AVPacket * pkt
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition opt.h:355
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_CODEC_ID_APTX
Definition codec_id.h:538
@ AV_CODEC_ID_APTX_HD
Definition codec_id.h:539
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition packet.h:651
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR(e)
Definition error.h:45
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition samplefmt.h:65
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static AVStream * aptx_read_header_common(AVFormatContext *s)
Definition aptxdec.c:40
#define APTX_HD_BLOCK_SIZE
Definition aptxdec.c:32
#define APTX_BLOCK_SIZE
Definition aptxdec.c:29
static const AVOption aptx_options[]
Definition aptxdec.c:92
static const AVClass aptx_demuxer_class
Definition aptxdec.c:97
static int aptx_hd_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition aptxdec.c:84
#define APTX_PACKET_SIZE
Definition aptxdec.c:30
static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition aptxdec.c:76
static int aptx_hd_read_header(AVFormatContext *s)
Definition aptxdec.c:65
#define APTX_HD_PACKET_SIZE
Definition aptxdec.c:33
static int aptx_read_header(AVFormatContext *s)
Definition aptxdec.c:54
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
AVOptions.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition codec_par.h:113
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
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition avformat.h:815