]> git.sesse.net Git - ffmpeg/blob - libavformat/aptxdec.c
avformat: Constify all muxer/demuxers
[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 #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;
34     int sample_rate;
35 } AptXDemuxerContext;
36
37 static AVStream *aptx_read_header_common(AVFormatContext *s)
38 {
39     AptXDemuxerContext *s1 = s->priv_data;
40     AVStream *st = avformat_new_stream(s, NULL);
41     if (!st)
42         return NULL;
43     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
44     st->codecpar->format = AV_SAMPLE_FMT_S32P;
45     st->codecpar->channels = 2;
46     st->codecpar->sample_rate = s1->sample_rate;
47     st->start_time = 0;
48     return st;
49 }
50
51 static int aptx_read_header(AVFormatContext *s)
52 {
53     AVStream *st = aptx_read_header_common(s);
54     if (!st)
55         return AVERROR(ENOMEM);
56     st->codecpar->codec_id = AV_CODEC_ID_APTX;
57     st->codecpar->bits_per_coded_sample = 4;
58     st->codecpar->block_align = APTX_BLOCK_SIZE;
59     st->codecpar->frame_size = APTX_PACKET_SIZE;
60     return 0;
61 }
62
63 static int aptx_hd_read_header(AVFormatContext *s)
64 {
65     AVStream *st = aptx_read_header_common(s);
66     if (!st)
67         return AVERROR(ENOMEM);
68     st->codecpar->codec_id = AV_CODEC_ID_APTX_HD;
69     st->codecpar->bits_per_coded_sample = 6;
70     st->codecpar->block_align = APTX_HD_BLOCK_SIZE;
71     st->codecpar->frame_size = APTX_HD_PACKET_SIZE;
72     return 0;
73 }
74
75 static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt)
76 {
77     return av_get_packet(s->pb, pkt, APTX_PACKET_SIZE);
78 }
79
80 static int aptx_hd_read_packet(AVFormatContext *s, AVPacket *pkt)
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
98 const AVInputFormat ff_aptx_demuxer = {
99     .name           = "aptx",
100     .long_name      = NULL_IF_CONFIG_SMALL("raw aptX"),
101     .extensions     = "aptx",
102     .priv_data_size = sizeof(AptXDemuxerContext),
103     .read_header    = aptx_read_header,
104     .read_packet    = aptx_read_packet,
105     .flags          = AVFMT_GENERIC_INDEX,
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
118 const AVInputFormat ff_aptx_hd_demuxer = {
119     .name           = "aptx_hd",
120     .long_name      = NULL_IF_CONFIG_SMALL("raw aptX HD"),
121     .extensions     = "aptxhd",
122     .priv_data_size = sizeof(AptXDemuxerContext),
123     .read_header    = aptx_hd_read_header,
124     .read_packet    = aptx_hd_read_packet,
125     .flags          = AVFMT_GENERIC_INDEX,
126     .priv_class     = &aptx_hd_demuxer_class,
127 };
128 #endif