]> git.sesse.net Git - ffmpeg/blob - libavformat/aptxdec.c
Merge commit '34c113335b53d83ed343de49741f0823aa1f8cc6'
[ffmpeg] / libavformat / aptxdec.c
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 typedef struct AptXDemuxerContext {
30     AVClass *class;
31     int sample_rate;
32 } AptXDemuxerContext;
33
34 static int aptx_read_header(AVFormatContext *s)
35 {
36     AptXDemuxerContext *s1 = s->priv_data;
37     AVStream *st = avformat_new_stream(s, NULL);
38     if (!st)
39         return AVERROR(ENOMEM);
40     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
41     st->codecpar->codec_id = AV_CODEC_ID_APTX;
42     st->codecpar->format = AV_SAMPLE_FMT_S32P;
43     st->codecpar->channels = 2;
44     st->codecpar->sample_rate = s1->sample_rate;
45     st->codecpar->bits_per_coded_sample = 4;
46     st->codecpar->block_align = APTX_BLOCK_SIZE;
47     st->codecpar->frame_size = APTX_PACKET_SIZE;
48     st->start_time = 0;
49     return 0;
50 }
51
52 static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt)
53 {
54     return av_get_packet(s->pb, pkt, APTX_PACKET_SIZE);
55 }
56
57 static const AVOption aptx_options[] = {
58     { "sample_rate", "", offsetof(AptXDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
59     { NULL },
60 };
61
62 static const AVClass aptx_demuxer_class = {
63     .class_name = "aptx demuxer",
64     .item_name  = av_default_item_name,
65     .option     = aptx_options,
66     .version    = LIBAVUTIL_VERSION_INT,
67 };
68
69 AVInputFormat ff_aptx_demuxer = {
70     .name           = "aptx",
71     .long_name      = NULL_IF_CONFIG_SMALL("raw aptX"),
72     .extensions     = "aptx",
73     .priv_data_size = sizeof(AptXDemuxerContext),
74     .read_header    = aptx_read_header,
75     .read_packet    = aptx_read_packet,
76     .flags          = AVFMT_GENERIC_INDEX,
77     .priv_class     = &aptx_demuxer_class,
78 };