|
|
@ -26,26 +26,49 @@ |
|
|
|
#define APTX_BLOCK_SIZE 4 |
|
|
|
#define APTX_BLOCK_SIZE 4 |
|
|
|
#define APTX_PACKET_SIZE (256*APTX_BLOCK_SIZE) |
|
|
|
#define APTX_PACKET_SIZE (256*APTX_BLOCK_SIZE) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define APTX_HD_BLOCK_SIZE 6 |
|
|
|
|
|
|
|
#define APTX_HD_PACKET_SIZE (256*APTX_HD_BLOCK_SIZE) |
|
|
|
|
|
|
|
|
|
|
|
typedef struct AptXDemuxerContext { |
|
|
|
typedef struct AptXDemuxerContext { |
|
|
|
AVClass *class; |
|
|
|
AVClass *class; |
|
|
|
int sample_rate; |
|
|
|
int sample_rate; |
|
|
|
} AptXDemuxerContext; |
|
|
|
} AptXDemuxerContext; |
|
|
|
|
|
|
|
|
|
|
|
static int aptx_read_header(AVFormatContext *s) |
|
|
|
static AVStream *aptx_read_header_common(AVFormatContext *s) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AptXDemuxerContext *s1 = s->priv_data; |
|
|
|
AptXDemuxerContext *s1 = s->priv_data; |
|
|
|
AVStream *st = avformat_new_stream(s, NULL); |
|
|
|
AVStream *st = avformat_new_stream(s, NULL); |
|
|
|
if (!st) |
|
|
|
if (!st) |
|
|
|
return AVERROR(ENOMEM); |
|
|
|
return NULL; |
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; |
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; |
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_APTX; |
|
|
|
|
|
|
|
st->codecpar->format = AV_SAMPLE_FMT_S32P; |
|
|
|
st->codecpar->format = AV_SAMPLE_FMT_S32P; |
|
|
|
st->codecpar->channels = 2; |
|
|
|
st->codecpar->channels = 2; |
|
|
|
st->codecpar->sample_rate = s1->sample_rate; |
|
|
|
st->codecpar->sample_rate = s1->sample_rate; |
|
|
|
|
|
|
|
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; |
|
|
|
st->codecpar->bits_per_coded_sample = 4; |
|
|
|
st->codecpar->bits_per_coded_sample = 4; |
|
|
|
st->codecpar->block_align = APTX_BLOCK_SIZE; |
|
|
|
st->codecpar->block_align = APTX_BLOCK_SIZE; |
|
|
|
st->codecpar->frame_size = APTX_PACKET_SIZE; |
|
|
|
st->codecpar->frame_size = APTX_PACKET_SIZE; |
|
|
|
st->start_time = 0; |
|
|
|
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; |
|
|
|
|
|
|
|
st->codecpar->frame_size = APTX_HD_PACKET_SIZE; |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -54,11 +77,17 @@ static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt) |
|
|
|
return av_get_packet(s->pb, pkt, APTX_PACKET_SIZE); |
|
|
|
return av_get_packet(s->pb, pkt, APTX_PACKET_SIZE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int aptx_hd_read_packet(AVFormatContext *s, AVPacket *pkt) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return av_get_packet(s->pb, pkt, APTX_HD_PACKET_SIZE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static const AVOption aptx_options[] = { |
|
|
|
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 }, |
|
|
|
{ "sample_rate", "", offsetof(AptXDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, |
|
|
|
{ NULL }, |
|
|
|
{ NULL }, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if CONFIG_APTX_MUXER |
|
|
|
static const AVClass aptx_demuxer_class = { |
|
|
|
static const AVClass aptx_demuxer_class = { |
|
|
|
.class_name = "aptx demuxer", |
|
|
|
.class_name = "aptx demuxer", |
|
|
|
.item_name = av_default_item_name, |
|
|
|
.item_name = av_default_item_name, |
|
|
@ -76,3 +105,24 @@ AVInputFormat ff_aptx_demuxer = { |
|
|
|
.flags = AVFMT_GENERIC_INDEX, |
|
|
|
.flags = AVFMT_GENERIC_INDEX, |
|
|
|
.priv_class = &aptx_demuxer_class, |
|
|
|
.priv_class = &aptx_demuxer_class, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if CONFIG_APTX_HD_DEMUXER |
|
|
|
|
|
|
|
static const AVClass aptx_hd_demuxer_class = { |
|
|
|
|
|
|
|
.class_name = "aptx hd demuxer", |
|
|
|
|
|
|
|
.item_name = av_default_item_name, |
|
|
|
|
|
|
|
.option = aptx_options, |
|
|
|
|
|
|
|
.version = LIBAVUTIL_VERSION_INT, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AVInputFormat ff_aptx_hd_demuxer = { |
|
|
|
|
|
|
|
.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, |
|
|
|
|
|
|
|
.priv_class = &aptx_hd_demuxer_class, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
#endif |
|
|
|