2017-11-10 21:09:24 +00:00
|
|
|
/*
|
|
|
|
* RAW aptX demuxer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Aurelien Jacobs <aurel@gnuage.org>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2022-02-23 12:56:49 +00:00
|
|
|
#include "config_components.h"
|
|
|
|
|
2021-06-07 19:08:59 +00:00
|
|
|
#include "libavutil/opt.h"
|
2017-11-10 21:09:24 +00:00
|
|
|
#include "avformat.h"
|
|
|
|
|
|
|
|
#define APTX_BLOCK_SIZE 4
|
|
|
|
#define APTX_PACKET_SIZE (256*APTX_BLOCK_SIZE)
|
|
|
|
|
2018-01-06 16:33:01 +00:00
|
|
|
#define APTX_HD_BLOCK_SIZE 6
|
|
|
|
#define APTX_HD_PACKET_SIZE (256*APTX_HD_BLOCK_SIZE)
|
|
|
|
|
2017-11-10 21:09:24 +00:00
|
|
|
typedef struct AptXDemuxerContext {
|
|
|
|
AVClass *class;
|
|
|
|
int sample_rate;
|
|
|
|
} AptXDemuxerContext;
|
|
|
|
|
2018-01-06 16:33:01 +00:00
|
|
|
static AVStream *aptx_read_header_common(AVFormatContext *s)
|
2017-11-10 21:09:24 +00:00
|
|
|
{
|
|
|
|
AptXDemuxerContext *s1 = s->priv_data;
|
|
|
|
AVStream *st = avformat_new_stream(s, NULL);
|
|
|
|
if (!st)
|
2018-01-06 16:33:01 +00:00
|
|
|
return NULL;
|
2017-11-10 21:09:24 +00:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
|
|
|
st->codecpar->format = AV_SAMPLE_FMT_S32P;
|
2019-05-13 09:11:26 +00:00
|
|
|
st->codecpar->ch_layout.nb_channels = 2;
|
2017-11-10 21:09:24 +00:00
|
|
|
st->codecpar->sample_rate = s1->sample_rate;
|
2018-01-06 16:33:01 +00:00
|
|
|
st->start_time = 0;
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aptx_read_header(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
AVStream *st = aptx_read_header_common(s);
|
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_APTX;
|
2017-11-10 21:09:24 +00:00
|
|
|
st->codecpar->bits_per_coded_sample = 4;
|
|
|
|
st->codecpar->block_align = APTX_BLOCK_SIZE;
|
2018-01-06 16:33:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aptx_hd_read_header(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
AVStream *st = aptx_read_header_common(s);
|
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_APTX_HD;
|
|
|
|
st->codecpar->bits_per_coded_sample = 6;
|
|
|
|
st->codecpar->block_align = APTX_HD_BLOCK_SIZE;
|
2017-11-10 21:09:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
2021-08-29 20:01:16 +00:00
|
|
|
int ret = av_get_packet(s->pb, pkt, APTX_PACKET_SIZE);
|
|
|
|
if (ret >= 0 && !(ret % APTX_BLOCK_SIZE))
|
|
|
|
pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
|
|
|
|
return ret >= 0 ? 0 : ret;
|
2017-11-10 21:09:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 16:33:01 +00:00
|
|
|
static int aptx_hd_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
2021-08-29 20:01:16 +00:00
|
|
|
int ret = av_get_packet(s->pb, pkt, APTX_HD_PACKET_SIZE);
|
|
|
|
if (ret >= 0 && !(ret % APTX_HD_BLOCK_SIZE))
|
|
|
|
pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
|
|
|
|
return ret >= 0 ? 0 : ret;
|
2018-01-06 16:33:01 +00:00
|
|
|
}
|
|
|
|
|
2017-11-10 21:09:24 +00:00
|
|
|
static const AVOption aptx_options[] = {
|
|
|
|
{ "sample_rate", "", offsetof(AptXDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass aptx_demuxer_class = {
|
2021-06-07 14:13:33 +00:00
|
|
|
.class_name = "aptx (hd) demuxer",
|
2017-11-10 21:09:24 +00:00
|
|
|
.item_name = av_default_item_name,
|
|
|
|
.option = aptx_options,
|
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
|
|
|
};
|
|
|
|
|
2021-06-07 14:13:33 +00:00
|
|
|
#if CONFIG_APTX_DEMUXER
|
2021-04-19 17:45:24 +00:00
|
|
|
const AVInputFormat ff_aptx_demuxer = {
|
2017-11-10 21:09:24 +00:00
|
|
|
.name = "aptx",
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("raw aptX"),
|
|
|
|
.extensions = "aptx",
|
|
|
|
.priv_data_size = sizeof(AptXDemuxerContext),
|
|
|
|
.read_header = aptx_read_header,
|
|
|
|
.read_packet = aptx_read_packet,
|
|
|
|
.flags = AVFMT_GENERIC_INDEX,
|
|
|
|
.priv_class = &aptx_demuxer_class,
|
|
|
|
};
|
2018-01-06 16:33:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_APTX_HD_DEMUXER
|
2021-04-19 17:45:24 +00:00
|
|
|
const AVInputFormat ff_aptx_hd_demuxer = {
|
2018-01-06 16:33:01 +00:00
|
|
|
.name = "aptx_hd",
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("raw aptX HD"),
|
|
|
|
.extensions = "aptxhd",
|
|
|
|
.priv_data_size = sizeof(AptXDemuxerContext),
|
|
|
|
.read_header = aptx_hd_read_header,
|
|
|
|
.read_packet = aptx_hd_read_packet,
|
|
|
|
.flags = AVFMT_GENERIC_INDEX,
|
2021-06-07 14:13:33 +00:00
|
|
|
.priv_class = &aptx_demuxer_class,
|
2018-01-06 16:33:01 +00:00
|
|
|
};
|
|
|
|
#endif
|