FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/aptxdec.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 34 37 91.9%
Branches: 7 14 50.0%

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
28 #define APTX_BLOCK_SIZE 4
29 #define APTX_PACKET_SIZE (256*APTX_BLOCK_SIZE)
30
31 #define APTX_HD_BLOCK_SIZE 6
32 #define APTX_HD_PACKET_SIZE (256*APTX_HD_BLOCK_SIZE)
33
34 typedef struct AptXDemuxerContext {
35 AVClass *class;
36 int sample_rate;
37 } AptXDemuxerContext;
38
39 2 static AVStream *aptx_read_header_common(AVFormatContext *s)
40 {
41 2 AptXDemuxerContext *s1 = s->priv_data;
42 2 AVStream *st = avformat_new_stream(s, NULL);
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!st)
44 return NULL;
45 2 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
46 2 st->codecpar->format = AV_SAMPLE_FMT_S32P;
47 2 st->codecpar->ch_layout.nb_channels = 2;
48 2 st->codecpar->sample_rate = s1->sample_rate;
49 2 st->start_time = 0;
50 2 return st;
51 }
52
53 1 static int aptx_read_header(AVFormatContext *s)
54 {
55 1 AVStream *st = aptx_read_header_common(s);
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!st)
57 return AVERROR(ENOMEM);
58 1 st->codecpar->codec_id = AV_CODEC_ID_APTX;
59 1 st->codecpar->bits_per_coded_sample = 4;
60 1 st->codecpar->block_align = APTX_BLOCK_SIZE;
61 1 return 0;
62 }
63
64 1 static int aptx_hd_read_header(AVFormatContext *s)
65 {
66 1 AVStream *st = aptx_read_header_common(s);
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!st)
68 return AVERROR(ENOMEM);
69 1 st->codecpar->codec_id = AV_CODEC_ID_APTX_HD;
70 1 st->codecpar->bits_per_coded_sample = 6;
71 1 st->codecpar->block_align = APTX_HD_BLOCK_SIZE;
72 1 return 0;
73 }
74
75 50 static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt)
76 {
77 50 int ret = av_get_packet(s->pb, pkt, APTX_PACKET_SIZE);
78
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))
79 50 pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
80 50 return ret >= 0 ? 0 : ret;
81 }
82
83 50 static int aptx_hd_read_packet(AVFormatContext *s, AVPacket *pkt)
84 {
85 50 int ret = av_get_packet(s->pb, pkt, APTX_HD_PACKET_SIZE);
86
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))
87 50 pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
88 50 return ret >= 0 ? 0 : ret;
89 }
90
91 static const AVOption aptx_options[] = {
92 { "sample_rate", "", offsetof(AptXDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
93 { NULL },
94 };
95
96 static const AVClass aptx_demuxer_class = {
97 .class_name = "aptx (hd) demuxer",
98 .item_name = av_default_item_name,
99 .option = aptx_options,
100 .version = LIBAVUTIL_VERSION_INT,
101 };
102
103 #if CONFIG_APTX_DEMUXER
104 const AVInputFormat ff_aptx_demuxer = {
105 .name = "aptx",
106 .long_name = NULL_IF_CONFIG_SMALL("raw aptX"),
107 .extensions = "aptx",
108 .priv_data_size = sizeof(AptXDemuxerContext),
109 .read_header = aptx_read_header,
110 .read_packet = aptx_read_packet,
111 .flags = AVFMT_GENERIC_INDEX,
112 .priv_class = &aptx_demuxer_class,
113 };
114 #endif
115
116 #if CONFIG_APTX_HD_DEMUXER
117 const AVInputFormat ff_aptx_hd_demuxer = {
118 .name = "aptx_hd",
119 .long_name = NULL_IF_CONFIG_SMALL("raw aptX HD"),
120 .extensions = "aptxhd",
121 .priv_data_size = sizeof(AptXDemuxerContext),
122 .read_header = aptx_hd_read_header,
123 .read_packet = aptx_hd_read_packet,
124 .flags = AVFMT_GENERIC_INDEX,
125 .priv_class = &aptx_demuxer_class,
126 };
127 #endif
128