| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | |||
| 35 | typedef struct AptXDemuxerContext { | ||
| 36 | AVClass *class; | ||
| 37 | int sample_rate; | ||
| 38 | } AptXDemuxerContext; | ||
| 39 | |||
| 40 | 2 | static AVStream *aptx_read_header_common(AVFormatContext *s) | |
| 41 | { | ||
| 42 | 2 | AptXDemuxerContext *s1 = s->priv_data; | |
| 43 | 2 | AVStream *st = avformat_new_stream(s, NULL); | |
| 44 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (!st) |
| 45 | ✗ | return NULL; | |
| 46 | 2 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
| 47 | 2 | st->codecpar->format = AV_SAMPLE_FMT_S32P; | |
| 48 | 2 | st->codecpar->ch_layout.nb_channels = 2; | |
| 49 | 2 | st->codecpar->sample_rate = s1->sample_rate; | |
| 50 | 2 | st->start_time = 0; | |
| 51 | 2 | return st; | |
| 52 | } | ||
| 53 | |||
| 54 | 1 | static int aptx_read_header(AVFormatContext *s) | |
| 55 | { | ||
| 56 | 1 | AVStream *st = aptx_read_header_common(s); | |
| 57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!st) |
| 58 | ✗ | return AVERROR(ENOMEM); | |
| 59 | 1 | st->codecpar->codec_id = AV_CODEC_ID_APTX; | |
| 60 | 1 | st->codecpar->bits_per_coded_sample = 4; | |
| 61 | 1 | st->codecpar->block_align = APTX_BLOCK_SIZE; | |
| 62 | 1 | return 0; | |
| 63 | } | ||
| 64 | |||
| 65 | 1 | static int aptx_hd_read_header(AVFormatContext *s) | |
| 66 | { | ||
| 67 | 1 | AVStream *st = aptx_read_header_common(s); | |
| 68 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!st) |
| 69 | ✗ | return AVERROR(ENOMEM); | |
| 70 | 1 | st->codecpar->codec_id = AV_CODEC_ID_APTX_HD; | |
| 71 | 1 | st->codecpar->bits_per_coded_sample = 6; | |
| 72 | 1 | st->codecpar->block_align = APTX_HD_BLOCK_SIZE; | |
| 73 | 1 | return 0; | |
| 74 | } | ||
| 75 | |||
| 76 | 50 | static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt) | |
| 77 | { | ||
| 78 | 50 | int ret = av_get_packet(s->pb, pkt, APTX_PACKET_SIZE); | |
| 79 |
2/4✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
|
50 | if (ret >= 0 && !(ret % APTX_BLOCK_SIZE)) |
| 80 | 50 | pkt->flags &= ~AV_PKT_FLAG_CORRUPT; | |
| 81 | 50 | return ret >= 0 ? 0 : ret; | |
| 82 | } | ||
| 83 | |||
| 84 | 50 | static int aptx_hd_read_packet(AVFormatContext *s, AVPacket *pkt) | |
| 85 | { | ||
| 86 | 50 | int ret = av_get_packet(s->pb, pkt, APTX_HD_PACKET_SIZE); | |
| 87 |
2/4✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
|
50 | if (ret >= 0 && !(ret % APTX_HD_BLOCK_SIZE)) |
| 88 | 50 | pkt->flags &= ~AV_PKT_FLAG_CORRUPT; | |
| 89 | 50 | return ret >= 0 ? 0 : ret; | |
| 90 | } | ||
| 91 | |||
| 92 | static 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 | |||
| 97 | static const AVClass aptx_demuxer_class = { | ||
| 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 | ||
| 105 | const FFInputFormat ff_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), | ||
| 112 | .read_header = aptx_read_header, | ||
| 113 | .read_packet = aptx_read_packet, | ||
| 114 | }; | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #if CONFIG_APTX_HD_DEMUXER | ||
| 118 | const FFInputFormat ff_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), | ||
| 125 | .read_header = aptx_hd_read_header, | ||
| 126 | .read_packet = aptx_hd_read_packet, | ||
| 127 | }; | ||
| 128 | #endif | ||
| 129 |