FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ac3dec_fixed.c
Date: 2025-01-20 09:27:23
Exec Total Coverage
Lines: 40 58 69.0%
Functions: 2 2 100.0%
Branches: 9 18 50.0%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2012
3 * MIPS Technologies, Inc., California.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * Author: Stanislav Ocovaj (socovaj@mips.com)
30 *
31 * AC3 fixed-point decoder for MIPS platforms
32 *
33 * This file is part of FFmpeg.
34 *
35 * FFmpeg is free software; you can redistribute it and/or
36 * modify it under the terms of the GNU Lesser General Public
37 * License as published by the Free Software Foundation; either
38 * version 2.1 of the License, or (at your option) any later version.
39 *
40 * FFmpeg is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43 * Lesser General Public License for more details.
44 *
45 * You should have received a copy of the GNU Lesser General Public
46 * License along with FFmpeg; if not, write to the Free Software
47 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
48 */
49
50 #include "config_components.h"
51 #define USE_FIXED 1
52 #include "ac3dec.h"
53 #include "codec_internal.h"
54 #define IMDCT_TYPE AV_TX_INT32_MDCT
55
56 #include "ac3dec.h"
57
58 static const int end_freq_inv_tab[8] =
59 {
60 50529027, 44278013, 39403370, 32292987, 27356480, 23729101, 20951060, 18755316
61 };
62
63 7008 static void scale_coefs (
64 int32_t *dst,
65 const int32_t *src,
66 int dynrng,
67 int len)
68 {
69 int i, shift;
70 unsigned mul, round;
71 int temp, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
72
73 7008 mul = (dynrng & 0x1f) + 0x20;
74 7008 shift = 4 - (sign_extend(dynrng, 9) >> 5);
75
1/2
✓ Branch 0 taken 7008 times.
✗ Branch 1 not taken.
7008 if (shift > 0 ) {
76 7008 round = 1 << (shift-1);
77
2/2
✓ Branch 0 taken 224256 times.
✓ Branch 1 taken 7008 times.
231264 for (i=0; i<len; i+=8) {
78
79 224256 temp = src[i] * mul;
80 224256 temp1 = src[i+1] * mul;
81 224256 temp = temp + round;
82 224256 temp2 = src[i+2] * mul;
83
84 224256 temp1 = temp1 + round;
85 224256 dst[i] = temp >> shift;
86 224256 temp3 = src[i+3] * mul;
87 224256 temp2 = temp2 + round;
88
89 224256 dst[i+1] = temp1 >> shift;
90 224256 temp4 = src[i + 4] * mul;
91 224256 temp3 = temp3 + round;
92 224256 dst[i+2] = temp2 >> shift;
93
94 224256 temp5 = src[i+5] * mul;
95 224256 temp4 = temp4 + round;
96 224256 dst[i+3] = temp3 >> shift;
97 224256 temp6 = src[i+6] * mul;
98
99 224256 dst[i+4] = temp4 >> shift;
100 224256 temp5 = temp5 + round;
101 224256 temp7 = src[i+7] * mul;
102 224256 temp6 = temp6 + round;
103
104 224256 dst[i+5] = temp5 >> shift;
105 224256 temp7 = temp7 + round;
106 224256 dst[i+6] = temp6 >> shift;
107 224256 dst[i+7] = temp7 >> shift;
108
109 }
110 } else {
111 shift = -shift;
112 mul <<= shift;
113 for (i=0; i<len; i+=8) {
114
115 dst[i] = src[i ] * mul;
116 dst[i+1] = src[i+1] * mul;
117 dst[i+2] = src[i+2] * mul;
118 dst[i+3] = src[i+3] * mul;
119 dst[i+4] = src[i+4] * mul;
120 dst[i+5] = src[i+5] * mul;
121 dst[i+6] = src[i+6] * mul;
122 dst[i+7] = src[i+7] * mul;
123 }
124 }
125 7008 }
126
127 /**
128 * Downmix samples from original signal to stereo or mono (this is for 16-bit samples
129 * and fixed point decoder - original (for 32-bit samples) is in ac3dsp.c).
130 */
131 1 static void ac3_downmix_c_fixed16(int16_t **samples, int16_t **matrix,
132 int out_ch, int in_ch, int len)
133 {
134 int i, j;
135 int v0, v1;
136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (out_ch == 2) {
137 for (i = 0; i < len; i++) {
138 v0 = v1 = 0;
139 for (j = 0; j < in_ch; j++) {
140 v0 += samples[j][i] * matrix[0][j];
141 v1 += samples[j][i] * matrix[1][j];
142 }
143 samples[0][i] = (v0+2048)>>12;
144 samples[1][i] = (v1+2048)>>12;
145 }
146
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 } else if (out_ch == 1) {
147
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 1 times.
257 for (i = 0; i < len; i++) {
148 256 v0 = 0;
149
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 256 times.
1280 for (j = 0; j < in_ch; j++)
150 1024 v0 += samples[j][i] * matrix[0][j];
151 256 samples[0][i] = (v0+2048)>>12;
152 }
153 }
154 1 }
155
156 #if CONFIG_EAC3_DECODER
157 #include "eac3dec.c"
158 #endif
159 #include "ac3dec.c"
160
161 static const AVOption options[] = {
162 { "cons_noisegen", "enable consistent noise generation", OFFSET(consistent_noise_generation), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR },
163 { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 6.0, PAR },
164 { "heavy_compr", "enable heavy dynamic range compression", OFFSET(heavy_compression), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR },
165 { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = PAR },
166 { NULL},
167 };
168
169 static const AVClass ac3_decoder_class = {
170 .class_name = "Fixed-Point AC-3 Decoder",
171 .item_name = av_default_item_name,
172 .option = options,
173 .version = LIBAVUTIL_VERSION_INT,
174 };
175
176 const FFCodec ff_ac3_fixed_decoder = {
177 .p.name = "ac3_fixed",
178 CODEC_LONG_NAME("ATSC A/52A (AC-3)"),
179 .p.type = AVMEDIA_TYPE_AUDIO,
180 .p.id = AV_CODEC_ID_AC3,
181 .p.priv_class = &ac3_decoder_class,
182 .priv_data_size = sizeof (AC3DecodeContext),
183 .init = ac3_decode_init,
184 .close = ac3_decode_end,
185 FF_CODEC_DECODE_CB(ac3_decode_frame),
186 .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
187 AV_CODEC_CAP_DR1,
188 .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
189 AV_SAMPLE_FMT_NONE },
190 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
191 };
192