/proc/self/cwd/libfaad/decoder.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding |
3 | | ** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com |
4 | | ** |
5 | | ** This program is free software; you can redistribute it and/or modify |
6 | | ** it under the terms of the GNU General Public License as published by |
7 | | ** the Free Software Foundation; either version 2 of the License, or |
8 | | ** (at your option) any later version. |
9 | | ** |
10 | | ** This program is distributed in the hope that it will be useful, |
11 | | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | ** GNU General Public License for more details. |
14 | | ** |
15 | | ** You should have received a copy of the GNU General Public License |
16 | | ** along with this program; if not, write to the Free Software |
17 | | ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | | ** |
19 | | ** Any non-GPL usage of this software or parts of this software is strictly |
20 | | ** forbidden. |
21 | | ** |
22 | | ** The "appropriate copyright message" mentioned in section 2c of the GPLv2 |
23 | | ** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com" |
24 | | ** |
25 | | ** Commercial non-GPL licensing of this software is possible. |
26 | | ** For more info contact Nero AG through Mpeg4AAClicense@nero.com. |
27 | | ** |
28 | | ** $Id: decoder.c,v 1.119 2015/01/24 14:21:05 knik Exp $ |
29 | | **/ |
30 | | |
31 | | #include "common.h" |
32 | | #include "structs.h" |
33 | | |
34 | | #include <stdlib.h> |
35 | | #include <stdio.h> |
36 | | #include <string.h> |
37 | | |
38 | | #include "mp4.h" |
39 | | #include "syntax.h" |
40 | | #include "error.h" |
41 | | #include "output.h" |
42 | | #include "filtbank.h" |
43 | | #include "drc.h" |
44 | | #ifdef SBR_DEC |
45 | | #include "sbr_dec.h" |
46 | | #include "sbr_syntax.h" |
47 | | #endif |
48 | | #ifdef SSR_DEC |
49 | | #include "ssr.h" |
50 | | #endif |
51 | | |
52 | | #ifdef ANALYSIS |
53 | | uint16_t dbg_count; |
54 | | #endif |
55 | | |
56 | | #if !defined(PACKAGE_VERSION) |
57 | | #error "PACKAGE_VERSION must be defined" |
58 | | #endif |
59 | | |
60 | | /* static function declarations */ |
61 | | static void* aac_frame_decode(NeAACDecStruct *hDecoder, |
62 | | NeAACDecFrameInfo *hInfo, |
63 | | unsigned char *buffer, |
64 | | unsigned long buffer_size, |
65 | | void **sample_buffer2, |
66 | | unsigned long sample_buffer_size); |
67 | | static void create_channel_config(NeAACDecStruct *hDecoder, |
68 | | NeAACDecFrameInfo *hInfo); |
69 | | |
70 | | |
71 | | int NeAACDecGetVersion(char **faad_id_string, |
72 | | char **faad_copyright_string) |
73 | 333 | { |
74 | 333 | static char *libfaadName = PACKAGE_VERSION; |
75 | 333 | static char *libCopyright = |
76 | 333 | " Copyright 2002-2004: Ahead Software AG\n" |
77 | 333 | " http://www.audiocoding.com\n" |
78 | 333 | " bug tracking: https://sourceforge.net/p/faac/bugs/\n"; |
79 | | |
80 | 333 | if (faad_id_string) |
81 | 333 | *faad_id_string = libfaadName; |
82 | | |
83 | 333 | if (faad_copyright_string) |
84 | 333 | *faad_copyright_string = libCopyright; |
85 | | |
86 | 333 | return 0; |
87 | 333 | } |
88 | | |
89 | | char* NeAACDecGetErrorMessage(unsigned char errcode) |
90 | 333 | { |
91 | 333 | if (errcode >= NUM_ERROR_MESSAGES) |
92 | 215 | return NULL; |
93 | 118 | return err_msg[errcode]; |
94 | 333 | } |
95 | | |
96 | | unsigned long NeAACDecGetCapabilities(void) |
97 | 1.33k | { |
98 | 1.33k | uint32_t cap = 0; |
99 | | |
100 | | /* can't do without it */ |
101 | 1.33k | cap += LC_DEC_CAP; |
102 | | |
103 | | #ifdef MAIN_DEC |
104 | 333 | cap += MAIN_DEC_CAP; |
105 | | #endif |
106 | | #ifdef LTP_DEC |
107 | 666 | cap += LTP_DEC_CAP; |
108 | | #endif |
109 | | #ifdef LD_DEC |
110 | 666 | cap += LD_DEC_CAP; |
111 | | #endif |
112 | 1.33k | #ifdef ERROR_RESILIENCE |
113 | 1.33k | cap += ERROR_RESILIENCE_CAP; |
114 | 1.33k | #endif |
115 | | #ifdef FIXED_POINT |
116 | 666 | cap += FIXED_POINT_CAP; |
117 | | #endif |
118 | | |
119 | 1.33k | return cap; |
120 | 1.33k | } Line | Count | Source | 97 | 333 | { | 98 | 333 | uint32_t cap = 0; | 99 | | | 100 | | /* can't do without it */ | 101 | 333 | cap += LC_DEC_CAP; | 102 | | | 103 | | #ifdef MAIN_DEC | 104 | | cap += MAIN_DEC_CAP; | 105 | | #endif | 106 | | #ifdef LTP_DEC | 107 | | cap += LTP_DEC_CAP; | 108 | | #endif | 109 | | #ifdef LD_DEC | 110 | | cap += LD_DEC_CAP; | 111 | | #endif | 112 | 333 | #ifdef ERROR_RESILIENCE | 113 | 333 | cap += ERROR_RESILIENCE_CAP; | 114 | 333 | #endif | 115 | 333 | #ifdef FIXED_POINT | 116 | 333 | cap += FIXED_POINT_CAP; | 117 | 333 | #endif | 118 | | | 119 | 333 | return cap; | 120 | 333 | } |
Line | Count | Source | 97 | 333 | { | 98 | 333 | uint32_t cap = 0; | 99 | | | 100 | | /* can't do without it */ | 101 | 333 | cap += LC_DEC_CAP; | 102 | | | 103 | 333 | #ifdef MAIN_DEC | 104 | 333 | cap += MAIN_DEC_CAP; | 105 | 333 | #endif | 106 | 333 | #ifdef LTP_DEC | 107 | 333 | cap += LTP_DEC_CAP; | 108 | 333 | #endif | 109 | 333 | #ifdef LD_DEC | 110 | 333 | cap += LD_DEC_CAP; | 111 | 333 | #endif | 112 | 333 | #ifdef ERROR_RESILIENCE | 113 | 333 | cap += ERROR_RESILIENCE_CAP; | 114 | 333 | #endif | 115 | | #ifdef FIXED_POINT | 116 | | cap += FIXED_POINT_CAP; | 117 | | #endif | 118 | | | 119 | 333 | return cap; | 120 | 333 | } |
Line | Count | Source | 97 | 333 | { | 98 | 333 | uint32_t cap = 0; | 99 | | | 100 | | /* can't do without it */ | 101 | 333 | cap += LC_DEC_CAP; | 102 | | | 103 | | #ifdef MAIN_DEC | 104 | | cap += MAIN_DEC_CAP; | 105 | | #endif | 106 | 333 | #ifdef LTP_DEC | 107 | 333 | cap += LTP_DEC_CAP; | 108 | 333 | #endif | 109 | 333 | #ifdef LD_DEC | 110 | 333 | cap += LD_DEC_CAP; | 111 | 333 | #endif | 112 | 333 | #ifdef ERROR_RESILIENCE | 113 | 333 | cap += ERROR_RESILIENCE_CAP; | 114 | 333 | #endif | 115 | 333 | #ifdef FIXED_POINT | 116 | 333 | cap += FIXED_POINT_CAP; | 117 | 333 | #endif | 118 | | | 119 | 333 | return cap; | 120 | 333 | } |
Line | Count | Source | 97 | 333 | { | 98 | 333 | uint32_t cap = 0; | 99 | | | 100 | | /* can't do without it */ | 101 | 333 | cap += LC_DEC_CAP; | 102 | | | 103 | | #ifdef MAIN_DEC | 104 | | cap += MAIN_DEC_CAP; | 105 | | #endif | 106 | | #ifdef LTP_DEC | 107 | | cap += LTP_DEC_CAP; | 108 | | #endif | 109 | | #ifdef LD_DEC | 110 | | cap += LD_DEC_CAP; | 111 | | #endif | 112 | 333 | #ifdef ERROR_RESILIENCE | 113 | 333 | cap += ERROR_RESILIENCE_CAP; | 114 | 333 | #endif | 115 | | #ifdef FIXED_POINT | 116 | | cap += FIXED_POINT_CAP; | 117 | | #endif | 118 | | | 119 | 333 | return cap; | 120 | 333 | } |
|
121 | | |
122 | | const unsigned char mes[] = { 0x67,0x20,0x61,0x20,0x20,0x20,0x6f,0x20,0x72,0x20,0x65,0x20,0x6e,0x20,0x20,0x20,0x74,0x20,0x68,0x20,0x67,0x20,0x69,0x20,0x72,0x20,0x79,0x20,0x70,0x20,0x6f,0x20,0x63 }; |
123 | | NeAACDecHandle NeAACDecOpen(void) |
124 | 50.5k | { |
125 | 50.5k | uint8_t i; |
126 | 50.5k | NeAACDecStruct *hDecoder = NULL; |
127 | | |
128 | 50.5k | if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL) |
129 | 0 | return NULL; |
130 | | |
131 | 50.5k | memset(hDecoder, 0, sizeof(NeAACDecStruct)); |
132 | | |
133 | 50.5k | hDecoder->cmes = mes; |
134 | 50.5k | hDecoder->config.outputFormat = FAAD_FMT_16BIT; |
135 | 50.5k | hDecoder->config.defObjectType = MAIN; |
136 | 50.5k | hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ |
137 | 50.5k | hDecoder->config.downMatrix = 0; |
138 | 50.5k | hDecoder->adts_header_present = 0; |
139 | 50.5k | hDecoder->adif_header_present = 0; |
140 | 50.5k | hDecoder->latm_header_present = 0; |
141 | 50.5k | #ifdef ERROR_RESILIENCE |
142 | 50.5k | hDecoder->aacSectionDataResilienceFlag = 0; |
143 | 50.5k | hDecoder->aacScalefactorDataResilienceFlag = 0; |
144 | 50.5k | hDecoder->aacSpectralDataResilienceFlag = 0; |
145 | 50.5k | #endif |
146 | 50.5k | hDecoder->frameLength = 1024; |
147 | | |
148 | 50.5k | hDecoder->frame = 0; |
149 | 50.5k | hDecoder->sample_buffer = NULL; |
150 | | |
151 | | // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all. |
152 | 50.5k | hDecoder->__r1 = 0x2bb431ea; |
153 | 50.5k | hDecoder->__r2 = 0x206155b7; |
154 | | |
155 | 3.28M | for (i = 0; i < MAX_CHANNELS; i++) |
156 | 3.23M | { |
157 | 3.23M | hDecoder->element_id[i] = INVALID_ELEMENT_ID; |
158 | 3.23M | hDecoder->window_shape_prev[i] = 0; |
159 | 3.23M | hDecoder->time_out[i] = NULL; |
160 | 3.23M | hDecoder->fb_intermed[i] = NULL; |
161 | | #ifdef SSR_DEC |
162 | | hDecoder->ssr_overlap[i] = NULL; |
163 | | hDecoder->prev_fmd[i] = NULL; |
164 | | #endif |
165 | | #ifdef MAIN_DEC |
166 | | hDecoder->pred_stat[i] = NULL; |
167 | | #endif |
168 | | #ifdef LTP_DEC |
169 | | hDecoder->ltp_lag[i] = 0; |
170 | | hDecoder->lt_pred_stat[i] = NULL; |
171 | | #endif |
172 | 3.23M | } |
173 | | |
174 | 50.5k | #ifdef SBR_DEC |
175 | 2.47M | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) |
176 | 2.42M | { |
177 | 2.42M | hDecoder->sbr[i] = NULL; |
178 | 2.42M | } |
179 | 50.5k | #endif |
180 | | |
181 | 50.5k | hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0)); |
182 | | |
183 | 50.5k | return hDecoder; |
184 | 50.5k | } Line | Count | Source | 124 | 8.44k | { | 125 | 8.44k | uint8_t i; | 126 | 8.44k | NeAACDecStruct *hDecoder = NULL; | 127 | | | 128 | 8.44k | if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL) | 129 | 0 | return NULL; | 130 | | | 131 | 8.44k | memset(hDecoder, 0, sizeof(NeAACDecStruct)); | 132 | | | 133 | 8.44k | hDecoder->cmes = mes; | 134 | 8.44k | hDecoder->config.outputFormat = FAAD_FMT_16BIT; | 135 | 8.44k | hDecoder->config.defObjectType = MAIN; | 136 | 8.44k | hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ | 137 | 8.44k | hDecoder->config.downMatrix = 0; | 138 | 8.44k | hDecoder->adts_header_present = 0; | 139 | 8.44k | hDecoder->adif_header_present = 0; | 140 | 8.44k | hDecoder->latm_header_present = 0; | 141 | 8.44k | #ifdef ERROR_RESILIENCE | 142 | 8.44k | hDecoder->aacSectionDataResilienceFlag = 0; | 143 | 8.44k | hDecoder->aacScalefactorDataResilienceFlag = 0; | 144 | 8.44k | hDecoder->aacSpectralDataResilienceFlag = 0; | 145 | 8.44k | #endif | 146 | 8.44k | hDecoder->frameLength = 1024; | 147 | | | 148 | 8.44k | hDecoder->frame = 0; | 149 | 8.44k | hDecoder->sample_buffer = NULL; | 150 | | | 151 | | // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all. | 152 | 8.44k | hDecoder->__r1 = 0x2bb431ea; | 153 | 8.44k | hDecoder->__r2 = 0x206155b7; | 154 | | | 155 | 549k | for (i = 0; i < MAX_CHANNELS; i++) | 156 | 540k | { | 157 | 540k | hDecoder->element_id[i] = INVALID_ELEMENT_ID; | 158 | 540k | hDecoder->window_shape_prev[i] = 0; | 159 | 540k | hDecoder->time_out[i] = NULL; | 160 | 540k | hDecoder->fb_intermed[i] = NULL; | 161 | | #ifdef SSR_DEC | 162 | | hDecoder->ssr_overlap[i] = NULL; | 163 | | hDecoder->prev_fmd[i] = NULL; | 164 | | #endif | 165 | | #ifdef MAIN_DEC | 166 | | hDecoder->pred_stat[i] = NULL; | 167 | | #endif | 168 | | #ifdef LTP_DEC | 169 | | hDecoder->ltp_lag[i] = 0; | 170 | | hDecoder->lt_pred_stat[i] = NULL; | 171 | | #endif | 172 | 540k | } | 173 | | | 174 | 8.44k | #ifdef SBR_DEC | 175 | 413k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 176 | 405k | { | 177 | 405k | hDecoder->sbr[i] = NULL; | 178 | 405k | } | 179 | 8.44k | #endif | 180 | | | 181 | 8.44k | hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0)); | 182 | | | 183 | 8.44k | return hDecoder; | 184 | 8.44k | } |
Line | Count | Source | 124 | 16.8k | { | 125 | 16.8k | uint8_t i; | 126 | 16.8k | NeAACDecStruct *hDecoder = NULL; | 127 | | | 128 | 16.8k | if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL) | 129 | 0 | return NULL; | 130 | | | 131 | 16.8k | memset(hDecoder, 0, sizeof(NeAACDecStruct)); | 132 | | | 133 | 16.8k | hDecoder->cmes = mes; | 134 | 16.8k | hDecoder->config.outputFormat = FAAD_FMT_16BIT; | 135 | 16.8k | hDecoder->config.defObjectType = MAIN; | 136 | 16.8k | hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ | 137 | 16.8k | hDecoder->config.downMatrix = 0; | 138 | 16.8k | hDecoder->adts_header_present = 0; | 139 | 16.8k | hDecoder->adif_header_present = 0; | 140 | 16.8k | hDecoder->latm_header_present = 0; | 141 | 16.8k | #ifdef ERROR_RESILIENCE | 142 | 16.8k | hDecoder->aacSectionDataResilienceFlag = 0; | 143 | 16.8k | hDecoder->aacScalefactorDataResilienceFlag = 0; | 144 | 16.8k | hDecoder->aacSpectralDataResilienceFlag = 0; | 145 | 16.8k | #endif | 146 | 16.8k | hDecoder->frameLength = 1024; | 147 | | | 148 | 16.8k | hDecoder->frame = 0; | 149 | 16.8k | hDecoder->sample_buffer = NULL; | 150 | | | 151 | | // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all. | 152 | 16.8k | hDecoder->__r1 = 0x2bb431ea; | 153 | 16.8k | hDecoder->__r2 = 0x206155b7; | 154 | | | 155 | 1.09M | for (i = 0; i < MAX_CHANNELS; i++) | 156 | 1.07M | { | 157 | 1.07M | hDecoder->element_id[i] = INVALID_ELEMENT_ID; | 158 | 1.07M | hDecoder->window_shape_prev[i] = 0; | 159 | 1.07M | hDecoder->time_out[i] = NULL; | 160 | 1.07M | hDecoder->fb_intermed[i] = NULL; | 161 | | #ifdef SSR_DEC | 162 | | hDecoder->ssr_overlap[i] = NULL; | 163 | | hDecoder->prev_fmd[i] = NULL; | 164 | | #endif | 165 | 1.07M | #ifdef MAIN_DEC | 166 | 1.07M | hDecoder->pred_stat[i] = NULL; | 167 | 1.07M | #endif | 168 | 1.07M | #ifdef LTP_DEC | 169 | 1.07M | hDecoder->ltp_lag[i] = 0; | 170 | 1.07M | hDecoder->lt_pred_stat[i] = NULL; | 171 | 1.07M | #endif | 172 | 1.07M | } | 173 | | | 174 | 16.8k | #ifdef SBR_DEC | 175 | 824k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 176 | 807k | { | 177 | 807k | hDecoder->sbr[i] = NULL; | 178 | 807k | } | 179 | 16.8k | #endif | 180 | | | 181 | 16.8k | hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0)); | 182 | | | 183 | 16.8k | return hDecoder; | 184 | 16.8k | } |
Line | Count | Source | 124 | 8.44k | { | 125 | 8.44k | uint8_t i; | 126 | 8.44k | NeAACDecStruct *hDecoder = NULL; | 127 | | | 128 | 8.44k | if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL) | 129 | 0 | return NULL; | 130 | | | 131 | 8.44k | memset(hDecoder, 0, sizeof(NeAACDecStruct)); | 132 | | | 133 | 8.44k | hDecoder->cmes = mes; | 134 | 8.44k | hDecoder->config.outputFormat = FAAD_FMT_16BIT; | 135 | 8.44k | hDecoder->config.defObjectType = MAIN; | 136 | 8.44k | hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ | 137 | 8.44k | hDecoder->config.downMatrix = 0; | 138 | 8.44k | hDecoder->adts_header_present = 0; | 139 | 8.44k | hDecoder->adif_header_present = 0; | 140 | 8.44k | hDecoder->latm_header_present = 0; | 141 | 8.44k | #ifdef ERROR_RESILIENCE | 142 | 8.44k | hDecoder->aacSectionDataResilienceFlag = 0; | 143 | 8.44k | hDecoder->aacScalefactorDataResilienceFlag = 0; | 144 | 8.44k | hDecoder->aacSpectralDataResilienceFlag = 0; | 145 | 8.44k | #endif | 146 | 8.44k | hDecoder->frameLength = 1024; | 147 | | | 148 | 8.44k | hDecoder->frame = 0; | 149 | 8.44k | hDecoder->sample_buffer = NULL; | 150 | | | 151 | | // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all. | 152 | 8.44k | hDecoder->__r1 = 0x2bb431ea; | 153 | 8.44k | hDecoder->__r2 = 0x206155b7; | 154 | | | 155 | 549k | for (i = 0; i < MAX_CHANNELS; i++) | 156 | 540k | { | 157 | 540k | hDecoder->element_id[i] = INVALID_ELEMENT_ID; | 158 | 540k | hDecoder->window_shape_prev[i] = 0; | 159 | 540k | hDecoder->time_out[i] = NULL; | 160 | 540k | hDecoder->fb_intermed[i] = NULL; | 161 | | #ifdef SSR_DEC | 162 | | hDecoder->ssr_overlap[i] = NULL; | 163 | | hDecoder->prev_fmd[i] = NULL; | 164 | | #endif | 165 | | #ifdef MAIN_DEC | 166 | | hDecoder->pred_stat[i] = NULL; | 167 | | #endif | 168 | 540k | #ifdef LTP_DEC | 169 | 540k | hDecoder->ltp_lag[i] = 0; | 170 | 540k | hDecoder->lt_pred_stat[i] = NULL; | 171 | 540k | #endif | 172 | 540k | } | 173 | | | 174 | 8.44k | #ifdef SBR_DEC | 175 | 413k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 176 | 405k | { | 177 | 405k | hDecoder->sbr[i] = NULL; | 178 | 405k | } | 179 | 8.44k | #endif | 180 | | | 181 | 8.44k | hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0)); | 182 | | | 183 | 8.44k | return hDecoder; | 184 | 8.44k | } |
Line | Count | Source | 124 | 16.8k | { | 125 | 16.8k | uint8_t i; | 126 | 16.8k | NeAACDecStruct *hDecoder = NULL; | 127 | | | 128 | 16.8k | if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL) | 129 | 0 | return NULL; | 130 | | | 131 | 16.8k | memset(hDecoder, 0, sizeof(NeAACDecStruct)); | 132 | | | 133 | 16.8k | hDecoder->cmes = mes; | 134 | 16.8k | hDecoder->config.outputFormat = FAAD_FMT_16BIT; | 135 | 16.8k | hDecoder->config.defObjectType = MAIN; | 136 | 16.8k | hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ | 137 | 16.8k | hDecoder->config.downMatrix = 0; | 138 | 16.8k | hDecoder->adts_header_present = 0; | 139 | 16.8k | hDecoder->adif_header_present = 0; | 140 | 16.8k | hDecoder->latm_header_present = 0; | 141 | 16.8k | #ifdef ERROR_RESILIENCE | 142 | 16.8k | hDecoder->aacSectionDataResilienceFlag = 0; | 143 | 16.8k | hDecoder->aacScalefactorDataResilienceFlag = 0; | 144 | 16.8k | hDecoder->aacSpectralDataResilienceFlag = 0; | 145 | 16.8k | #endif | 146 | 16.8k | hDecoder->frameLength = 1024; | 147 | | | 148 | 16.8k | hDecoder->frame = 0; | 149 | 16.8k | hDecoder->sample_buffer = NULL; | 150 | | | 151 | | // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all. | 152 | 16.8k | hDecoder->__r1 = 0x2bb431ea; | 153 | 16.8k | hDecoder->__r2 = 0x206155b7; | 154 | | | 155 | 1.09M | for (i = 0; i < MAX_CHANNELS; i++) | 156 | 1.07M | { | 157 | 1.07M | hDecoder->element_id[i] = INVALID_ELEMENT_ID; | 158 | 1.07M | hDecoder->window_shape_prev[i] = 0; | 159 | 1.07M | hDecoder->time_out[i] = NULL; | 160 | 1.07M | hDecoder->fb_intermed[i] = NULL; | 161 | | #ifdef SSR_DEC | 162 | | hDecoder->ssr_overlap[i] = NULL; | 163 | | hDecoder->prev_fmd[i] = NULL; | 164 | | #endif | 165 | | #ifdef MAIN_DEC | 166 | | hDecoder->pred_stat[i] = NULL; | 167 | | #endif | 168 | | #ifdef LTP_DEC | 169 | | hDecoder->ltp_lag[i] = 0; | 170 | | hDecoder->lt_pred_stat[i] = NULL; | 171 | | #endif | 172 | 1.07M | } | 173 | | | 174 | 16.8k | #ifdef SBR_DEC | 175 | 824k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 176 | 807k | { | 177 | 807k | hDecoder->sbr[i] = NULL; | 178 | 807k | } | 179 | 16.8k | #endif | 180 | | | 181 | 16.8k | hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0)); | 182 | | | 183 | 16.8k | return hDecoder; | 184 | 16.8k | } |
|
185 | | |
186 | | NeAACDecConfigurationPtr NeAACDecGetCurrentConfiguration(NeAACDecHandle hpDecoder) |
187 | 24.2k | { |
188 | 24.2k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
189 | 24.2k | if (hDecoder) |
190 | 24.2k | { |
191 | 24.2k | NeAACDecConfigurationPtr config = &(hDecoder->config); |
192 | | |
193 | 24.2k | return config; |
194 | 24.2k | } |
195 | | |
196 | 0 | return NULL; |
197 | 24.2k | } |
198 | | |
199 | | unsigned char NeAACDecSetConfiguration(NeAACDecHandle hpDecoder, |
200 | | NeAACDecConfigurationPtr config) |
201 | 24.4k | { |
202 | 24.4k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
203 | 24.4k | if (hDecoder && config) |
204 | 24.4k | { |
205 | | /* check if we can decode this object type */ |
206 | 24.4k | if (can_decode_ot(config->defObjectType) < 0) |
207 | 28 | return 0; |
208 | 24.4k | hDecoder->config.defObjectType = config->defObjectType; |
209 | | |
210 | | /* samplerate: anything but 0 should be possible */ |
211 | 24.4k | if (config->defSampleRate == 0) |
212 | 4 | return 0; |
213 | 24.4k | hDecoder->config.defSampleRate = config->defSampleRate; |
214 | | |
215 | | /* check output format */ |
216 | 24.4k | #ifdef FIXED_POINT |
217 | 24.4k | if ((config->outputFormat < 1) || (config->outputFormat > 4)) |
218 | 214 | return 0; |
219 | | #else |
220 | | if ((config->outputFormat < 1) || (config->outputFormat > 5)) |
221 | | return 0; |
222 | | #endif |
223 | 24.2k | hDecoder->config.outputFormat = config->outputFormat; |
224 | | |
225 | 24.2k | if (config->downMatrix > 1) |
226 | 26 | return 0; |
227 | 24.2k | hDecoder->config.downMatrix = config->downMatrix; |
228 | | |
229 | | /* OK */ |
230 | 24.2k | return 1; |
231 | 24.2k | } |
232 | | |
233 | 0 | return 0; |
234 | 24.4k | } |
235 | | |
236 | | |
237 | | #if 0 |
238 | | static int latmCheck(latm_header *latm, bitfile *ld) |
239 | | { |
240 | | uint32_t good=0, bad=0, bits, m; |
241 | | |
242 | | while (ld->bytes_left) |
243 | | { |
244 | | bits = faad_latm_frame(latm, ld); |
245 | | if(bits==0xFFFFFFFF) |
246 | | bad++; |
247 | | else |
248 | | { |
249 | | good++; |
250 | | while(bits>0) |
251 | | { |
252 | | m = min(bits, 8); |
253 | | faad_getbits(ld, m); |
254 | | bits -= m; |
255 | | } |
256 | | } |
257 | | } |
258 | | |
259 | | return (good>0); |
260 | | } |
261 | | #endif |
262 | | |
263 | | long NeAACDecInit(NeAACDecHandle hpDecoder, |
264 | | unsigned char *buffer, |
265 | | unsigned long buffer_size, |
266 | | unsigned long *samplerate, |
267 | | unsigned char *channels) |
268 | 16.8k | { |
269 | 16.8k | uint32_t bits = 0; |
270 | 16.8k | bitfile ld; |
271 | 16.8k | adif_header adif; |
272 | 16.8k | adts_header adts; |
273 | 16.8k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
274 | | |
275 | | |
276 | 16.8k | if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL) || (buffer_size == 0)) |
277 | 32 | return -1; |
278 | | |
279 | 16.8k | adts.old_format = hDecoder->config.useOldADTSFormat; |
280 | 16.8k | hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate); |
281 | 16.8k | hDecoder->object_type = hDecoder->config.defObjectType; |
282 | 16.8k | *samplerate = get_sample_rate(hDecoder->sf_index); |
283 | 16.8k | *channels = 1; |
284 | | |
285 | 16.8k | if (buffer != NULL) |
286 | 16.8k | { |
287 | | #if 0 |
288 | | int is_latm; |
289 | | latm_header *l = &hDecoder->latm_config; |
290 | | #endif |
291 | | |
292 | 16.8k | faad_initbits(&ld, buffer, buffer_size); |
293 | | |
294 | | #if 0 |
295 | | memset(l, 0, sizeof(latm_header)); |
296 | | is_latm = latmCheck(l, &ld); |
297 | | l->inited = 0; |
298 | | l->frameLength = 0; |
299 | | faad_rewindbits(&ld); |
300 | | if(is_latm && l->ASCbits>0) |
301 | | { |
302 | | int32_t x; |
303 | | hDecoder->latm_header_present = 1; |
304 | | x = NeAACDecInit2(hDecoder, l->ASC, (l->ASCbits+7)/8, samplerate, channels); |
305 | | if(x!=0) |
306 | | hDecoder->latm_header_present = 0; |
307 | | return x; |
308 | | } else |
309 | | #endif |
310 | | /* Check if an ADIF header is present */ |
311 | 16.8k | if ((buffer_size >= 8) && (buffer[0] == 'A') && (buffer[1] == 'D') && |
312 | 16.8k | (buffer[2] == 'I') && (buffer[3] == 'F')) |
313 | 389 | { |
314 | 389 | hDecoder->adif_header_present = 1; |
315 | | |
316 | 389 | get_adif_header(&adif, &ld); |
317 | 389 | faad_byte_align(&ld); |
318 | | |
319 | 389 | hDecoder->sf_index = adif.pce[0].sf_index; |
320 | 389 | hDecoder->object_type = adif.pce[0].object_type + 1; |
321 | | |
322 | 389 | *samplerate = get_sample_rate(hDecoder->sf_index); |
323 | 389 | *channels = adif.pce[0].channels; |
324 | | |
325 | 389 | memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config)); |
326 | 389 | hDecoder->pce_set = 1; |
327 | | |
328 | 389 | bits = bit2byte(faad_get_processed_bits(&ld)); |
329 | | |
330 | | /* Check if an ADTS header is present */ |
331 | 16.4k | } else if (adts_frame(&adts, &ld) == 0) { |
332 | 573 | hDecoder->adts_header_present = 1; |
333 | | |
334 | 573 | hDecoder->sf_index = adts.sf_index; |
335 | 573 | hDecoder->object_type = adts.profile + 1; |
336 | | |
337 | 573 | *samplerate = get_sample_rate(hDecoder->sf_index); |
338 | 573 | *channels = (adts.channel_configuration > 6) ? |
339 | 507 | 2 : adts.channel_configuration; |
340 | 573 | } |
341 | | |
342 | 16.8k | if (ld.error) |
343 | 0 | { |
344 | 0 | faad_endbits(&ld); |
345 | 0 | return -1; |
346 | 0 | } |
347 | 16.8k | faad_endbits(&ld); |
348 | 16.8k | } |
349 | | |
350 | 16.8k | if (!*samplerate) |
351 | 153 | return -1; |
352 | | |
353 | 16.6k | #if (defined(PS_DEC) || defined(DRM_PS)) |
354 | | /* check if we have a mono file */ |
355 | 16.6k | if (*channels == 1) |
356 | 15.8k | { |
357 | | /* upMatrix to 2 channels for implicit signalling of PS */ |
358 | 15.8k | *channels = 2; |
359 | 15.8k | } |
360 | 16.6k | #endif |
361 | | |
362 | 16.6k | hDecoder->channelConfiguration = *channels; |
363 | | |
364 | 16.6k | #ifdef SBR_DEC |
365 | | /* implicit signalling */ |
366 | 16.6k | if (*samplerate <= 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) |
367 | 7.92k | { |
368 | 7.92k | *samplerate *= 2; |
369 | 7.92k | hDecoder->forceUpSampling = 1; |
370 | 8.73k | } else if (*samplerate > 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) { |
371 | 8.73k | hDecoder->downSampledSBR = 1; |
372 | 8.73k | } |
373 | 16.6k | #endif |
374 | | |
375 | | /* must be done before frameLength is divided by 2 for LD */ |
376 | | #ifdef SSR_DEC |
377 | | if (hDecoder->object_type == SSR) |
378 | | hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS); |
379 | | else |
380 | | #endif |
381 | 16.6k | hDecoder->fb = filter_bank_init(hDecoder->frameLength); |
382 | | |
383 | | #ifdef LD_DEC |
384 | 10.4k | if (hDecoder->object_type == LD) |
385 | 437 | hDecoder->frameLength >>= 1; |
386 | | #endif |
387 | | |
388 | 16.6k | if (can_decode_ot(hDecoder->object_type) < 0) |
389 | 203 | return -1; |
390 | | |
391 | 16.4k | return bits; |
392 | 16.6k | } Line | Count | Source | 268 | 6.24k | { | 269 | 6.24k | uint32_t bits = 0; | 270 | 6.24k | bitfile ld; | 271 | 6.24k | adif_header adif; | 272 | 6.24k | adts_header adts; | 273 | 6.24k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; | 274 | | | 275 | | | 276 | 6.24k | if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL) || (buffer_size == 0)) | 277 | 15 | return -1; | 278 | | | 279 | 6.23k | adts.old_format = hDecoder->config.useOldADTSFormat; | 280 | 6.23k | hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate); | 281 | 6.23k | hDecoder->object_type = hDecoder->config.defObjectType; | 282 | 6.23k | *samplerate = get_sample_rate(hDecoder->sf_index); | 283 | 6.23k | *channels = 1; | 284 | | | 285 | 6.23k | if (buffer != NULL) | 286 | 6.23k | { | 287 | | #if 0 | 288 | | int is_latm; | 289 | | latm_header *l = &hDecoder->latm_config; | 290 | | #endif | 291 | | | 292 | 6.23k | faad_initbits(&ld, buffer, buffer_size); | 293 | | | 294 | | #if 0 | 295 | | memset(l, 0, sizeof(latm_header)); | 296 | | is_latm = latmCheck(l, &ld); | 297 | | l->inited = 0; | 298 | | l->frameLength = 0; | 299 | | faad_rewindbits(&ld); | 300 | | if(is_latm && l->ASCbits>0) | 301 | | { | 302 | | int32_t x; | 303 | | hDecoder->latm_header_present = 1; | 304 | | x = NeAACDecInit2(hDecoder, l->ASC, (l->ASCbits+7)/8, samplerate, channels); | 305 | | if(x!=0) | 306 | | hDecoder->latm_header_present = 0; | 307 | | return x; | 308 | | } else | 309 | | #endif | 310 | | /* Check if an ADIF header is present */ | 311 | 6.23k | if ((buffer_size >= 8) && (buffer[0] == 'A') && (buffer[1] == 'D') && | 312 | 6.23k | (buffer[2] == 'I') && (buffer[3] == 'F')) | 313 | 173 | { | 314 | 173 | hDecoder->adif_header_present = 1; | 315 | | | 316 | 173 | get_adif_header(&adif, &ld); | 317 | 173 | faad_byte_align(&ld); | 318 | | | 319 | 173 | hDecoder->sf_index = adif.pce[0].sf_index; | 320 | 173 | hDecoder->object_type = adif.pce[0].object_type + 1; | 321 | | | 322 | 173 | *samplerate = get_sample_rate(hDecoder->sf_index); | 323 | 173 | *channels = adif.pce[0].channels; | 324 | | | 325 | 173 | memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config)); | 326 | 173 | hDecoder->pce_set = 1; | 327 | | | 328 | 173 | bits = bit2byte(faad_get_processed_bits(&ld)); | 329 | | | 330 | | /* Check if an ADTS header is present */ | 331 | 6.06k | } else if (adts_frame(&adts, &ld) == 0) { | 332 | 104 | hDecoder->adts_header_present = 1; | 333 | | | 334 | 104 | hDecoder->sf_index = adts.sf_index; | 335 | 104 | hDecoder->object_type = adts.profile + 1; | 336 | | | 337 | 104 | *samplerate = get_sample_rate(hDecoder->sf_index); | 338 | 104 | *channels = (adts.channel_configuration > 6) ? | 339 | 88 | 2 : adts.channel_configuration; | 340 | 104 | } | 341 | | | 342 | 6.23k | if (ld.error) | 343 | 0 | { | 344 | 0 | faad_endbits(&ld); | 345 | 0 | return -1; | 346 | 0 | } | 347 | 6.23k | faad_endbits(&ld); | 348 | 6.23k | } | 349 | | | 350 | 6.23k | if (!*samplerate) | 351 | 65 | return -1; | 352 | | | 353 | 6.16k | #if (defined(PS_DEC) || defined(DRM_PS)) | 354 | | /* check if we have a mono file */ | 355 | 6.16k | if (*channels == 1) | 356 | 5.96k | { | 357 | | /* upMatrix to 2 channels for implicit signalling of PS */ | 358 | 5.96k | *channels = 2; | 359 | 5.96k | } | 360 | 6.16k | #endif | 361 | | | 362 | 6.16k | hDecoder->channelConfiguration = *channels; | 363 | | | 364 | 6.16k | #ifdef SBR_DEC | 365 | | /* implicit signalling */ | 366 | 6.16k | if (*samplerate <= 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) | 367 | 3.01k | { | 368 | 3.01k | *samplerate *= 2; | 369 | 3.01k | hDecoder->forceUpSampling = 1; | 370 | 3.15k | } else if (*samplerate > 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) { | 371 | 3.15k | hDecoder->downSampledSBR = 1; | 372 | 3.15k | } | 373 | 6.16k | #endif | 374 | | | 375 | | /* must be done before frameLength is divided by 2 for LD */ | 376 | | #ifdef SSR_DEC | 377 | | if (hDecoder->object_type == SSR) | 378 | | hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS); | 379 | | else | 380 | | #endif | 381 | 6.16k | hDecoder->fb = filter_bank_init(hDecoder->frameLength); | 382 | | | 383 | | #ifdef LD_DEC | 384 | | if (hDecoder->object_type == LD) | 385 | | hDecoder->frameLength >>= 1; | 386 | | #endif | 387 | | | 388 | 6.16k | if (can_decode_ot(hDecoder->object_type) < 0) | 389 | 111 | return -1; | 390 | | | 391 | 6.05k | return bits; | 392 | 6.16k | } |
Line | Count | Source | 268 | 10.5k | { | 269 | 10.5k | uint32_t bits = 0; | 270 | 10.5k | bitfile ld; | 271 | 10.5k | adif_header adif; | 272 | 10.5k | adts_header adts; | 273 | 10.5k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; | 274 | | | 275 | | | 276 | 10.5k | if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL) || (buffer_size == 0)) | 277 | 17 | return -1; | 278 | | | 279 | 10.5k | adts.old_format = hDecoder->config.useOldADTSFormat; | 280 | 10.5k | hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate); | 281 | 10.5k | hDecoder->object_type = hDecoder->config.defObjectType; | 282 | 10.5k | *samplerate = get_sample_rate(hDecoder->sf_index); | 283 | 10.5k | *channels = 1; | 284 | | | 285 | 10.5k | if (buffer != NULL) | 286 | 10.5k | { | 287 | | #if 0 | 288 | | int is_latm; | 289 | | latm_header *l = &hDecoder->latm_config; | 290 | | #endif | 291 | | | 292 | 10.5k | faad_initbits(&ld, buffer, buffer_size); | 293 | | | 294 | | #if 0 | 295 | | memset(l, 0, sizeof(latm_header)); | 296 | | is_latm = latmCheck(l, &ld); | 297 | | l->inited = 0; | 298 | | l->frameLength = 0; | 299 | | faad_rewindbits(&ld); | 300 | | if(is_latm && l->ASCbits>0) | 301 | | { | 302 | | int32_t x; | 303 | | hDecoder->latm_header_present = 1; | 304 | | x = NeAACDecInit2(hDecoder, l->ASC, (l->ASCbits+7)/8, samplerate, channels); | 305 | | if(x!=0) | 306 | | hDecoder->latm_header_present = 0; | 307 | | return x; | 308 | | } else | 309 | | #endif | 310 | | /* Check if an ADIF header is present */ | 311 | 10.5k | if ((buffer_size >= 8) && (buffer[0] == 'A') && (buffer[1] == 'D') && | 312 | 10.5k | (buffer[2] == 'I') && (buffer[3] == 'F')) | 313 | 216 | { | 314 | 216 | hDecoder->adif_header_present = 1; | 315 | | | 316 | 216 | get_adif_header(&adif, &ld); | 317 | 216 | faad_byte_align(&ld); | 318 | | | 319 | 216 | hDecoder->sf_index = adif.pce[0].sf_index; | 320 | 216 | hDecoder->object_type = adif.pce[0].object_type + 1; | 321 | | | 322 | 216 | *samplerate = get_sample_rate(hDecoder->sf_index); | 323 | 216 | *channels = adif.pce[0].channels; | 324 | | | 325 | 216 | memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config)); | 326 | 216 | hDecoder->pce_set = 1; | 327 | | | 328 | 216 | bits = bit2byte(faad_get_processed_bits(&ld)); | 329 | | | 330 | | /* Check if an ADTS header is present */ | 331 | 10.3k | } else if (adts_frame(&adts, &ld) == 0) { | 332 | 469 | hDecoder->adts_header_present = 1; | 333 | | | 334 | 469 | hDecoder->sf_index = adts.sf_index; | 335 | 469 | hDecoder->object_type = adts.profile + 1; | 336 | | | 337 | 469 | *samplerate = get_sample_rate(hDecoder->sf_index); | 338 | 469 | *channels = (adts.channel_configuration > 6) ? | 339 | 419 | 2 : adts.channel_configuration; | 340 | 469 | } | 341 | | | 342 | 10.5k | if (ld.error) | 343 | 0 | { | 344 | 0 | faad_endbits(&ld); | 345 | 0 | return -1; | 346 | 0 | } | 347 | 10.5k | faad_endbits(&ld); | 348 | 10.5k | } | 349 | | | 350 | 10.5k | if (!*samplerate) | 351 | 88 | return -1; | 352 | | | 353 | 10.4k | #if (defined(PS_DEC) || defined(DRM_PS)) | 354 | | /* check if we have a mono file */ | 355 | 10.4k | if (*channels == 1) | 356 | 9.90k | { | 357 | | /* upMatrix to 2 channels for implicit signalling of PS */ | 358 | 9.90k | *channels = 2; | 359 | 9.90k | } | 360 | 10.4k | #endif | 361 | | | 362 | 10.4k | hDecoder->channelConfiguration = *channels; | 363 | | | 364 | 10.4k | #ifdef SBR_DEC | 365 | | /* implicit signalling */ | 366 | 10.4k | if (*samplerate <= 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) | 367 | 4.90k | { | 368 | 4.90k | *samplerate *= 2; | 369 | 4.90k | hDecoder->forceUpSampling = 1; | 370 | 5.58k | } else if (*samplerate > 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) { | 371 | 5.58k | hDecoder->downSampledSBR = 1; | 372 | 5.58k | } | 373 | 10.4k | #endif | 374 | | | 375 | | /* must be done before frameLength is divided by 2 for LD */ | 376 | | #ifdef SSR_DEC | 377 | | if (hDecoder->object_type == SSR) | 378 | | hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS); | 379 | | else | 380 | | #endif | 381 | 10.4k | hDecoder->fb = filter_bank_init(hDecoder->frameLength); | 382 | | | 383 | 10.4k | #ifdef LD_DEC | 384 | 10.4k | if (hDecoder->object_type == LD) | 385 | 437 | hDecoder->frameLength >>= 1; | 386 | 10.4k | #endif | 387 | | | 388 | 10.4k | if (can_decode_ot(hDecoder->object_type) < 0) | 389 | 92 | return -1; | 390 | | | 391 | 10.3k | return bits; | 392 | 10.4k | } |
|
393 | | |
394 | | /* Init the library using a DecoderSpecificInfo */ |
395 | | char NeAACDecInit2(NeAACDecHandle hpDecoder, |
396 | | unsigned char *pBuffer, |
397 | | unsigned long SizeOfDecoderSpecificInfo, |
398 | | unsigned long *samplerate, |
399 | | unsigned char *channels) |
400 | 7.38k | { |
401 | 7.38k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
402 | 7.38k | int8_t rc; |
403 | 7.38k | mp4AudioSpecificConfig mp4ASC; |
404 | | |
405 | 7.38k | if((hDecoder == NULL) |
406 | 7.38k | || (pBuffer == NULL) |
407 | 7.38k | || (SizeOfDecoderSpecificInfo < 2) |
408 | 7.38k | || (samplerate == NULL) |
409 | 7.38k | || (channels == NULL)) |
410 | 12 | { |
411 | 12 | return -1; |
412 | 12 | } |
413 | | |
414 | 7.37k | hDecoder->adif_header_present = 0; |
415 | 7.37k | hDecoder->adts_header_present = 0; |
416 | | |
417 | | /* decode the audio specific config */ |
418 | 7.37k | rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC, |
419 | 7.37k | &(hDecoder->pce), hDecoder->latm_header_present); |
420 | | |
421 | | /* copy the relevant info to the decoder handle */ |
422 | 7.37k | *samplerate = mp4ASC.samplingFrequency; |
423 | 7.37k | if (mp4ASC.channelsConfiguration) |
424 | 6.22k | { |
425 | 6.22k | *channels = mp4ASC.channelsConfiguration; |
426 | 6.22k | } else { |
427 | 1.14k | *channels = hDecoder->pce.channels; |
428 | 1.14k | hDecoder->pce_set = 1; |
429 | 1.14k | } |
430 | 7.37k | #if (defined(PS_DEC) || defined(DRM_PS)) |
431 | | /* check if we have a mono file */ |
432 | 7.37k | if (*channels == 1) |
433 | 54 | { |
434 | | /* upMatrix to 2 channels for implicit signalling of PS */ |
435 | 54 | *channels = 2; |
436 | 54 | } |
437 | 7.37k | #endif |
438 | 7.37k | hDecoder->sf_index = mp4ASC.samplingFrequencyIndex; |
439 | 7.37k | hDecoder->object_type = mp4ASC.objectTypeIndex; |
440 | 7.37k | #ifdef ERROR_RESILIENCE |
441 | 7.37k | hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag; |
442 | 7.37k | hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag; |
443 | 7.37k | hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag; |
444 | 7.37k | #endif |
445 | 7.37k | #ifdef SBR_DEC |
446 | 7.37k | hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag; |
447 | 7.37k | hDecoder->downSampledSBR = mp4ASC.downSampledSBR; |
448 | 7.37k | if (hDecoder->config.dontUpSampleImplicitSBR == 0) |
449 | 7.37k | hDecoder->forceUpSampling = mp4ASC.forceUpSampling; |
450 | 0 | else |
451 | 0 | hDecoder->forceUpSampling = 0; |
452 | | |
453 | | /* AAC core decoder samplerate is 2 times as low */ |
454 | 7.37k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1) |
455 | 4.70k | { |
456 | 4.70k | hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2); |
457 | 4.70k | } |
458 | 7.37k | #endif |
459 | | |
460 | 7.37k | if (rc != 0) |
461 | 80 | { |
462 | 80 | return rc; |
463 | 80 | } |
464 | 7.29k | hDecoder->channelConfiguration = mp4ASC.channelsConfiguration; |
465 | 7.29k | if (mp4ASC.frameLengthFlag) |
466 | 4.47k | #ifdef ALLOW_SMALL_FRAMELENGTH |
467 | 4.47k | hDecoder->frameLength = 960; |
468 | | #else |
469 | | return -1; |
470 | | #endif |
471 | | |
472 | | /* must be done before frameLength is divided by 2 for LD */ |
473 | | #ifdef SSR_DEC |
474 | | if (hDecoder->object_type == SSR) |
475 | | hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS); |
476 | | else |
477 | | #endif |
478 | 7.29k | hDecoder->fb = filter_bank_init(hDecoder->frameLength); |
479 | | |
480 | | #ifdef LD_DEC |
481 | 4.78k | if (hDecoder->object_type == LD) |
482 | 604 | hDecoder->frameLength >>= 1; |
483 | | #endif |
484 | | |
485 | 7.29k | return 0; |
486 | 7.37k | } Line | Count | Source | 400 | 2.55k | { | 401 | 2.55k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; | 402 | 2.55k | int8_t rc; | 403 | 2.55k | mp4AudioSpecificConfig mp4ASC; | 404 | | | 405 | 2.55k | if((hDecoder == NULL) | 406 | 2.55k | || (pBuffer == NULL) | 407 | 2.55k | || (SizeOfDecoderSpecificInfo < 2) | 408 | 2.55k | || (samplerate == NULL) | 409 | 2.55k | || (channels == NULL)) | 410 | 7 | { | 411 | 7 | return -1; | 412 | 7 | } | 413 | | | 414 | 2.54k | hDecoder->adif_header_present = 0; | 415 | 2.54k | hDecoder->adts_header_present = 0; | 416 | | | 417 | | /* decode the audio specific config */ | 418 | 2.54k | rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC, | 419 | 2.54k | &(hDecoder->pce), hDecoder->latm_header_present); | 420 | | | 421 | | /* copy the relevant info to the decoder handle */ | 422 | 2.54k | *samplerate = mp4ASC.samplingFrequency; | 423 | 2.54k | if (mp4ASC.channelsConfiguration) | 424 | 2.03k | { | 425 | 2.03k | *channels = mp4ASC.channelsConfiguration; | 426 | 2.03k | } else { | 427 | 506 | *channels = hDecoder->pce.channels; | 428 | 506 | hDecoder->pce_set = 1; | 429 | 506 | } | 430 | 2.54k | #if (defined(PS_DEC) || defined(DRM_PS)) | 431 | | /* check if we have a mono file */ | 432 | 2.54k | if (*channels == 1) | 433 | 37 | { | 434 | | /* upMatrix to 2 channels for implicit signalling of PS */ | 435 | 37 | *channels = 2; | 436 | 37 | } | 437 | 2.54k | #endif | 438 | 2.54k | hDecoder->sf_index = mp4ASC.samplingFrequencyIndex; | 439 | 2.54k | hDecoder->object_type = mp4ASC.objectTypeIndex; | 440 | 2.54k | #ifdef ERROR_RESILIENCE | 441 | 2.54k | hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag; | 442 | 2.54k | hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag; | 443 | 2.54k | hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag; | 444 | 2.54k | #endif | 445 | 2.54k | #ifdef SBR_DEC | 446 | 2.54k | hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag; | 447 | 2.54k | hDecoder->downSampledSBR = mp4ASC.downSampledSBR; | 448 | 2.54k | if (hDecoder->config.dontUpSampleImplicitSBR == 0) | 449 | 2.54k | hDecoder->forceUpSampling = mp4ASC.forceUpSampling; | 450 | 0 | else | 451 | 0 | hDecoder->forceUpSampling = 0; | 452 | | | 453 | | /* AAC core decoder samplerate is 2 times as low */ | 454 | 2.54k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1) | 455 | 1.57k | { | 456 | 1.57k | hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2); | 457 | 1.57k | } | 458 | 2.54k | #endif | 459 | | | 460 | 2.54k | if (rc != 0) | 461 | 36 | { | 462 | 36 | return rc; | 463 | 36 | } | 464 | 2.50k | hDecoder->channelConfiguration = mp4ASC.channelsConfiguration; | 465 | 2.50k | if (mp4ASC.frameLengthFlag) | 466 | 1.61k | #ifdef ALLOW_SMALL_FRAMELENGTH | 467 | 1.61k | hDecoder->frameLength = 960; | 468 | | #else | 469 | | return -1; | 470 | | #endif | 471 | | | 472 | | /* must be done before frameLength is divided by 2 for LD */ | 473 | | #ifdef SSR_DEC | 474 | | if (hDecoder->object_type == SSR) | 475 | | hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS); | 476 | | else | 477 | | #endif | 478 | 2.50k | hDecoder->fb = filter_bank_init(hDecoder->frameLength); | 479 | | | 480 | | #ifdef LD_DEC | 481 | | if (hDecoder->object_type == LD) | 482 | | hDecoder->frameLength >>= 1; | 483 | | #endif | 484 | | | 485 | 2.50k | return 0; | 486 | 2.54k | } |
Line | Count | Source | 400 | 4.83k | { | 401 | 4.83k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; | 402 | 4.83k | int8_t rc; | 403 | 4.83k | mp4AudioSpecificConfig mp4ASC; | 404 | | | 405 | 4.83k | if((hDecoder == NULL) | 406 | 4.83k | || (pBuffer == NULL) | 407 | 4.83k | || (SizeOfDecoderSpecificInfo < 2) | 408 | 4.83k | || (samplerate == NULL) | 409 | 4.83k | || (channels == NULL)) | 410 | 5 | { | 411 | 5 | return -1; | 412 | 5 | } | 413 | | | 414 | 4.82k | hDecoder->adif_header_present = 0; | 415 | 4.82k | hDecoder->adts_header_present = 0; | 416 | | | 417 | | /* decode the audio specific config */ | 418 | 4.82k | rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC, | 419 | 4.82k | &(hDecoder->pce), hDecoder->latm_header_present); | 420 | | | 421 | | /* copy the relevant info to the decoder handle */ | 422 | 4.82k | *samplerate = mp4ASC.samplingFrequency; | 423 | 4.82k | if (mp4ASC.channelsConfiguration) | 424 | 4.19k | { | 425 | 4.19k | *channels = mp4ASC.channelsConfiguration; | 426 | 4.19k | } else { | 427 | 638 | *channels = hDecoder->pce.channels; | 428 | 638 | hDecoder->pce_set = 1; | 429 | 638 | } | 430 | 4.82k | #if (defined(PS_DEC) || defined(DRM_PS)) | 431 | | /* check if we have a mono file */ | 432 | 4.82k | if (*channels == 1) | 433 | 17 | { | 434 | | /* upMatrix to 2 channels for implicit signalling of PS */ | 435 | 17 | *channels = 2; | 436 | 17 | } | 437 | 4.82k | #endif | 438 | 4.82k | hDecoder->sf_index = mp4ASC.samplingFrequencyIndex; | 439 | 4.82k | hDecoder->object_type = mp4ASC.objectTypeIndex; | 440 | 4.82k | #ifdef ERROR_RESILIENCE | 441 | 4.82k | hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag; | 442 | 4.82k | hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag; | 443 | 4.82k | hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag; | 444 | 4.82k | #endif | 445 | 4.82k | #ifdef SBR_DEC | 446 | 4.82k | hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag; | 447 | 4.82k | hDecoder->downSampledSBR = mp4ASC.downSampledSBR; | 448 | 4.82k | if (hDecoder->config.dontUpSampleImplicitSBR == 0) | 449 | 4.82k | hDecoder->forceUpSampling = mp4ASC.forceUpSampling; | 450 | 0 | else | 451 | 0 | hDecoder->forceUpSampling = 0; | 452 | | | 453 | | /* AAC core decoder samplerate is 2 times as low */ | 454 | 4.82k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1) | 455 | 3.12k | { | 456 | 3.12k | hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2); | 457 | 3.12k | } | 458 | 4.82k | #endif | 459 | | | 460 | 4.82k | if (rc != 0) | 461 | 44 | { | 462 | 44 | return rc; | 463 | 44 | } | 464 | 4.78k | hDecoder->channelConfiguration = mp4ASC.channelsConfiguration; | 465 | 4.78k | if (mp4ASC.frameLengthFlag) | 466 | 2.86k | #ifdef ALLOW_SMALL_FRAMELENGTH | 467 | 2.86k | hDecoder->frameLength = 960; | 468 | | #else | 469 | | return -1; | 470 | | #endif | 471 | | | 472 | | /* must be done before frameLength is divided by 2 for LD */ | 473 | | #ifdef SSR_DEC | 474 | | if (hDecoder->object_type == SSR) | 475 | | hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS); | 476 | | else | 477 | | #endif | 478 | 4.78k | hDecoder->fb = filter_bank_init(hDecoder->frameLength); | 479 | | | 480 | 4.78k | #ifdef LD_DEC | 481 | 4.78k | if (hDecoder->object_type == LD) | 482 | 604 | hDecoder->frameLength >>= 1; | 483 | 4.78k | #endif | 484 | | | 485 | 4.78k | return 0; | 486 | 4.82k | } |
|
487 | | |
488 | | #ifdef DRM |
489 | | char NeAACDecInitDRM(NeAACDecHandle *hpDecoder, |
490 | | unsigned long samplerate, |
491 | | unsigned char channels) |
492 | 768 | { |
493 | 768 | NeAACDecStruct** hDecoder = (NeAACDecStruct**)hpDecoder; |
494 | 768 | if (hDecoder == NULL) |
495 | 0 | return 1; /* error */ |
496 | | |
497 | 768 | NeAACDecClose(*hDecoder); |
498 | | |
499 | 768 | *hDecoder = NeAACDecOpen(); |
500 | | |
501 | | /* Special object type defined for DRM */ |
502 | 768 | (*hDecoder)->config.defObjectType = DRM_ER_LC; |
503 | | |
504 | 768 | (*hDecoder)->config.defSampleRate = samplerate; |
505 | 768 | #ifdef ERROR_RESILIENCE // This shoudl always be defined for DRM |
506 | 768 | (*hDecoder)->aacSectionDataResilienceFlag = 1; /* VCB11 */ |
507 | 768 | (*hDecoder)->aacScalefactorDataResilienceFlag = 0; /* no RVLC */ |
508 | 768 | (*hDecoder)->aacSpectralDataResilienceFlag = 1; /* HCR */ |
509 | 768 | #endif |
510 | 768 | (*hDecoder)->frameLength = 960; |
511 | 768 | (*hDecoder)->sf_index = get_sr_index((*hDecoder)->config.defSampleRate); |
512 | 768 | (*hDecoder)->object_type = (*hDecoder)->config.defObjectType; |
513 | | |
514 | 768 | if ((channels == DRMCH_STEREO) || (channels == DRMCH_SBR_STEREO)) |
515 | 129 | (*hDecoder)->channelConfiguration = 2; |
516 | 639 | else |
517 | 639 | (*hDecoder)->channelConfiguration = 1; |
518 | | |
519 | 768 | #ifdef SBR_DEC |
520 | 768 | if ((channels == DRMCH_MONO) || (channels == DRMCH_STEREO)) |
521 | 106 | (*hDecoder)->sbr_present_flag = 0; |
522 | 662 | else |
523 | 662 | (*hDecoder)->sbr_present_flag = 1; |
524 | 768 | #endif |
525 | | |
526 | 768 | (*hDecoder)->fb = filter_bank_init((*hDecoder)->frameLength); |
527 | | |
528 | 768 | return 0; |
529 | 768 | } |
530 | | #endif |
531 | | |
532 | | void NeAACDecClose(NeAACDecHandle hpDecoder) |
533 | 9.65k | { |
534 | 9.65k | uint8_t i; |
535 | 9.65k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
536 | | |
537 | 9.65k | if (hDecoder == NULL) |
538 | 0 | return; |
539 | | |
540 | | #ifdef PROFILE |
541 | | printf("AAC decoder total: %I64d cycles\n", hDecoder->cycles); |
542 | | printf("requant: %I64d cycles\n", hDecoder->requant_cycles); |
543 | | printf("spectral_data: %I64d cycles\n", hDecoder->spectral_cycles); |
544 | | printf("scalefactors: %I64d cycles\n", hDecoder->scalefac_cycles); |
545 | | printf("output: %I64d cycles\n", hDecoder->output_cycles); |
546 | | #endif |
547 | | |
548 | 627k | for (i = 0; i < MAX_CHANNELS; i++) |
549 | 617k | { |
550 | 617k | if (hDecoder->time_out[i]) faad_free(hDecoder->time_out[i]); |
551 | 617k | if (hDecoder->fb_intermed[i]) faad_free(hDecoder->fb_intermed[i]); |
552 | | #ifdef SSR_DEC |
553 | | if (hDecoder->ssr_overlap[i]) faad_free(hDecoder->ssr_overlap[i]); |
554 | | if (hDecoder->prev_fmd[i]) faad_free(hDecoder->prev_fmd[i]); |
555 | | #endif |
556 | | #ifdef MAIN_DEC |
557 | | if (hDecoder->pred_stat[i]) faad_free(hDecoder->pred_stat[i]); |
558 | | #endif |
559 | | #ifdef LTP_DEC |
560 | | if (hDecoder->lt_pred_stat[i]) faad_free(hDecoder->lt_pred_stat[i]); |
561 | | #endif |
562 | 617k | } |
563 | | |
564 | | #ifdef SSR_DEC |
565 | | if (hDecoder->object_type == SSR) |
566 | | ssr_filter_bank_end(hDecoder->fb); |
567 | | else |
568 | | #endif |
569 | 9.65k | filter_bank_end(hDecoder->fb); |
570 | | |
571 | 9.65k | drc_end(hDecoder->drc); |
572 | | |
573 | 9.65k | if (hDecoder->sample_buffer) faad_free(hDecoder->sample_buffer); |
574 | | |
575 | 9.65k | #ifdef SBR_DEC |
576 | 473k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) |
577 | 463k | { |
578 | 463k | if (hDecoder->sbr[i]) |
579 | 110k | sbrDecodeEnd(hDecoder->sbr[i]); |
580 | 463k | } |
581 | 9.65k | #endif |
582 | | |
583 | 9.65k | if (hDecoder) faad_free(hDecoder); |
584 | 9.65k | } |
585 | | |
586 | | void NeAACDecPostSeekReset(NeAACDecHandle hpDecoder, long frame) |
587 | 16.4k | { |
588 | 16.4k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
589 | 16.4k | if (hDecoder) |
590 | 16.4k | { |
591 | 16.4k | hDecoder->postSeekResetFlag = 1; |
592 | | |
593 | 16.4k | if (frame != -1) |
594 | 16.4k | hDecoder->frame = frame; |
595 | 16.4k | } |
596 | 16.4k | } |
597 | | |
598 | | static void create_channel_config(NeAACDecStruct *hDecoder, NeAACDecFrameInfo *hInfo) |
599 | 36.9k | { |
600 | 36.9k | hInfo->num_front_channels = 0; |
601 | 36.9k | hInfo->num_side_channels = 0; |
602 | 36.9k | hInfo->num_back_channels = 0; |
603 | 36.9k | hInfo->num_lfe_channels = 0; |
604 | 36.9k | memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); |
605 | | |
606 | 36.9k | if (hDecoder->downMatrix) |
607 | 3.65k | { |
608 | 3.65k | hInfo->num_front_channels = 2; |
609 | 3.65k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; |
610 | 3.65k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; |
611 | 3.65k | return; |
612 | 3.65k | } |
613 | | |
614 | | /* check if there is a PCE */ |
615 | | /* TODO: why CPE flag is ignored? */ |
616 | 33.2k | if (hDecoder->pce_set) |
617 | 1.25k | { |
618 | 1.25k | uint8_t i, chpos = 0; |
619 | 1.25k | uint8_t chdir, back_center = 0; |
620 | | |
621 | 1.25k | hInfo->num_front_channels = hDecoder->pce.num_front_channels; |
622 | 1.25k | hInfo->num_side_channels = hDecoder->pce.num_side_channels; |
623 | 1.25k | hInfo->num_back_channels = hDecoder->pce.num_back_channels; |
624 | 1.25k | hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; |
625 | 1.25k | chdir = hInfo->num_front_channels; |
626 | 1.25k | if (chdir & 1) |
627 | 576 | { |
628 | 576 | #if (defined(PS_DEC) || defined(DRM_PS)) |
629 | 576 | if (hInfo->num_front_channels == 1 && |
630 | 576 | hInfo->num_side_channels == 0 && |
631 | 576 | hInfo->num_back_channels == 0 && |
632 | 576 | hInfo->num_lfe_channels == 0) |
633 | 104 | { |
634 | | /* When PS is enabled output is always stereo */ |
635 | 104 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; |
636 | 104 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; |
637 | 104 | } else |
638 | 472 | #endif |
639 | 472 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; |
640 | 576 | chdir--; |
641 | 576 | } |
642 | 6.84k | for (i = 0; i < chdir; i++) |
643 | 5.58k | { |
644 | 5.58k | hInfo->channel_position[chpos++] = |
645 | 5.58k | (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT; |
646 | 5.58k | } |
647 | | |
648 | 6.30k | for (i = 0; i < hInfo->num_side_channels; i++) |
649 | 5.04k | { |
650 | 5.04k | hInfo->channel_position[chpos++] = |
651 | 5.04k | (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT; |
652 | 5.04k | } |
653 | | |
654 | 1.25k | chdir = hInfo->num_back_channels; |
655 | 1.25k | if (chdir & 1) |
656 | 264 | { |
657 | 264 | back_center = 1; |
658 | 264 | chdir--; |
659 | 264 | } |
660 | 5.36k | for (i = 0; i < chdir; i++) |
661 | 4.11k | { |
662 | 4.11k | hInfo->channel_position[chpos++] = |
663 | 4.11k | (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT; |
664 | 4.11k | } |
665 | 1.25k | if (back_center) |
666 | 264 | { |
667 | 264 | hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; |
668 | 264 | } |
669 | | |
670 | 2.22k | for (i = 0; i < hInfo->num_lfe_channels; i++) |
671 | 964 | { |
672 | 964 | hInfo->channel_position[chpos++] = LFE_CHANNEL; |
673 | 964 | } |
674 | | |
675 | 32.0k | } else { |
676 | 32.0k | switch (hDecoder->channelConfiguration) |
677 | 32.0k | { |
678 | 1.71k | case 1: |
679 | 1.71k | #if (defined(PS_DEC) || defined(DRM_PS)) |
680 | | /* When PS is enabled output is always stereo */ |
681 | 1.71k | hInfo->num_front_channels = 2; |
682 | 1.71k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; |
683 | 1.71k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; |
684 | | #else |
685 | | hInfo->num_front_channels = 1; |
686 | | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
687 | | #endif |
688 | 1.71k | break; |
689 | 14.9k | case 2: |
690 | 14.9k | hInfo->num_front_channels = 2; |
691 | 14.9k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; |
692 | 14.9k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; |
693 | 14.9k | break; |
694 | 2.02k | case 3: |
695 | 2.02k | hInfo->num_front_channels = 3; |
696 | 2.02k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
697 | 2.02k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; |
698 | 2.02k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; |
699 | 2.02k | break; |
700 | 3.04k | case 4: |
701 | 3.04k | hInfo->num_front_channels = 3; |
702 | 3.04k | hInfo->num_back_channels = 1; |
703 | 3.04k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
704 | 3.04k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; |
705 | 3.04k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; |
706 | 3.04k | hInfo->channel_position[3] = BACK_CHANNEL_CENTER; |
707 | 3.04k | break; |
708 | 2.30k | case 5: |
709 | 2.30k | hInfo->num_front_channels = 3; |
710 | 2.30k | hInfo->num_back_channels = 2; |
711 | 2.30k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
712 | 2.30k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; |
713 | 2.30k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; |
714 | 2.30k | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; |
715 | 2.30k | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; |
716 | 2.30k | break; |
717 | 1.51k | case 6: |
718 | 1.51k | hInfo->num_front_channels = 3; |
719 | 1.51k | hInfo->num_back_channels = 2; |
720 | 1.51k | hInfo->num_lfe_channels = 1; |
721 | 1.51k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
722 | 1.51k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; |
723 | 1.51k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; |
724 | 1.51k | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; |
725 | 1.51k | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; |
726 | 1.51k | hInfo->channel_position[5] = LFE_CHANNEL; |
727 | 1.51k | break; |
728 | 5.58k | case 7: |
729 | 5.58k | hInfo->num_front_channels = 3; |
730 | 5.58k | hInfo->num_side_channels = 2; |
731 | 5.58k | hInfo->num_back_channels = 2; |
732 | 5.58k | hInfo->num_lfe_channels = 1; |
733 | 5.58k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
734 | 5.58k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; |
735 | 5.58k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; |
736 | 5.58k | hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; |
737 | 5.58k | hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; |
738 | 5.58k | hInfo->channel_position[5] = BACK_CHANNEL_LEFT; |
739 | 5.58k | hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; |
740 | 5.58k | hInfo->channel_position[7] = LFE_CHANNEL; |
741 | 5.58k | break; |
742 | 860 | default: /* channelConfiguration == 0 || channelConfiguration > 7 */ |
743 | 860 | { |
744 | 860 | uint8_t i; |
745 | 860 | uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; |
746 | 860 | if (ch & 1) /* there's either a center front or a center back channel */ |
747 | 316 | { |
748 | 316 | uint8_t ch1 = (ch-1)/2; |
749 | 316 | if (hDecoder->first_syn_ele == ID_SCE) |
750 | 200 | { |
751 | 200 | hInfo->num_front_channels = ch1 + 1; |
752 | 200 | hInfo->num_back_channels = ch1; |
753 | 200 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
754 | 852 | for (i = 1; i <= ch1; i+=2) |
755 | 652 | { |
756 | 652 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; |
757 | 652 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; |
758 | 652 | } |
759 | 852 | for (i = ch1+1; i < ch; i+=2) |
760 | 652 | { |
761 | 652 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; |
762 | 652 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; |
763 | 652 | } |
764 | 200 | } else { |
765 | 116 | hInfo->num_front_channels = ch1; |
766 | 116 | hInfo->num_back_channels = ch1 + 1; |
767 | 628 | for (i = 0; i < ch1; i+=2) |
768 | 512 | { |
769 | 512 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; |
770 | 512 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; |
771 | 512 | } |
772 | 628 | for (i = ch1; i < ch-1; i+=2) |
773 | 512 | { |
774 | 512 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; |
775 | 512 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; |
776 | 512 | } |
777 | 116 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; |
778 | 116 | } |
779 | 544 | } else { |
780 | 544 | uint8_t ch1 = (ch)/2; |
781 | 544 | hInfo->num_front_channels = ch1; |
782 | 544 | hInfo->num_back_channels = ch1; |
783 | 544 | if (ch1 & 1) |
784 | 248 | { |
785 | 248 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
786 | 1.47k | for (i = 1; i <= ch1; i+=2) |
787 | 1.22k | { |
788 | 1.22k | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; |
789 | 1.22k | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; |
790 | 1.22k | } |
791 | 1.22k | for (i = ch1+1; i < ch-1; i+=2) |
792 | 980 | { |
793 | 980 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; |
794 | 980 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; |
795 | 980 | } |
796 | 248 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; |
797 | 296 | } else { |
798 | 1.38k | for (i = 0; i < ch1; i+=2) |
799 | 1.08k | { |
800 | 1.08k | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; |
801 | 1.08k | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; |
802 | 1.08k | } |
803 | 1.38k | for (i = ch1; i < ch; i+=2) |
804 | 1.08k | { |
805 | 1.08k | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; |
806 | 1.08k | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; |
807 | 1.08k | } |
808 | 296 | } |
809 | 544 | } |
810 | 860 | hInfo->num_lfe_channels = hDecoder->has_lfe; |
811 | 1.68k | for (i = ch; i < hDecoder->fr_channels; i++) |
812 | 824 | { |
813 | 824 | hInfo->channel_position[i] = LFE_CHANNEL; |
814 | 824 | } |
815 | 860 | } |
816 | 860 | break; |
817 | 32.0k | } |
818 | 32.0k | } |
819 | 33.2k | } decoder.c:create_channel_config Line | Count | Source | 599 | 9.23k | { | 600 | 9.23k | hInfo->num_front_channels = 0; | 601 | 9.23k | hInfo->num_side_channels = 0; | 602 | 9.23k | hInfo->num_back_channels = 0; | 603 | 9.23k | hInfo->num_lfe_channels = 0; | 604 | 9.23k | memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); | 605 | | | 606 | 9.23k | if (hDecoder->downMatrix) | 607 | 913 | { | 608 | 913 | hInfo->num_front_channels = 2; | 609 | 913 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 610 | 913 | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 611 | 913 | return; | 612 | 913 | } | 613 | | | 614 | | /* check if there is a PCE */ | 615 | | /* TODO: why CPE flag is ignored? */ | 616 | 8.32k | if (hDecoder->pce_set) | 617 | 314 | { | 618 | 314 | uint8_t i, chpos = 0; | 619 | 314 | uint8_t chdir, back_center = 0; | 620 | | | 621 | 314 | hInfo->num_front_channels = hDecoder->pce.num_front_channels; | 622 | 314 | hInfo->num_side_channels = hDecoder->pce.num_side_channels; | 623 | 314 | hInfo->num_back_channels = hDecoder->pce.num_back_channels; | 624 | 314 | hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; | 625 | 314 | chdir = hInfo->num_front_channels; | 626 | 314 | if (chdir & 1) | 627 | 144 | { | 628 | 144 | #if (defined(PS_DEC) || defined(DRM_PS)) | 629 | 144 | if (hInfo->num_front_channels == 1 && | 630 | 144 | hInfo->num_side_channels == 0 && | 631 | 144 | hInfo->num_back_channels == 0 && | 632 | 144 | hInfo->num_lfe_channels == 0) | 633 | 26 | { | 634 | | /* When PS is enabled output is always stereo */ | 635 | 26 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; | 636 | 26 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; | 637 | 26 | } else | 638 | 118 | #endif | 639 | 118 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; | 640 | 144 | chdir--; | 641 | 144 | } | 642 | 1.71k | for (i = 0; i < chdir; i++) | 643 | 1.39k | { | 644 | 1.39k | hInfo->channel_position[chpos++] = | 645 | 1.39k | (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT; | 646 | 1.39k | } | 647 | | | 648 | 1.57k | for (i = 0; i < hInfo->num_side_channels; i++) | 649 | 1.26k | { | 650 | 1.26k | hInfo->channel_position[chpos++] = | 651 | 1.26k | (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT; | 652 | 1.26k | } | 653 | | | 654 | 314 | chdir = hInfo->num_back_channels; | 655 | 314 | if (chdir & 1) | 656 | 66 | { | 657 | 66 | back_center = 1; | 658 | 66 | chdir--; | 659 | 66 | } | 660 | 1.34k | for (i = 0; i < chdir; i++) | 661 | 1.02k | { | 662 | 1.02k | hInfo->channel_position[chpos++] = | 663 | 1.02k | (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT; | 664 | 1.02k | } | 665 | 314 | if (back_center) | 666 | 66 | { | 667 | 66 | hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; | 668 | 66 | } | 669 | | | 670 | 555 | for (i = 0; i < hInfo->num_lfe_channels; i++) | 671 | 241 | { | 672 | 241 | hInfo->channel_position[chpos++] = LFE_CHANNEL; | 673 | 241 | } | 674 | | | 675 | 8.00k | } else { | 676 | 8.00k | switch (hDecoder->channelConfiguration) | 677 | 8.00k | { | 678 | 428 | case 1: | 679 | 428 | #if (defined(PS_DEC) || defined(DRM_PS)) | 680 | | /* When PS is enabled output is always stereo */ | 681 | 428 | hInfo->num_front_channels = 2; | 682 | 428 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 683 | 428 | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 684 | | #else | 685 | | hInfo->num_front_channels = 1; | 686 | | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 687 | | #endif | 688 | 428 | break; | 689 | 3.74k | case 2: | 690 | 3.74k | hInfo->num_front_channels = 2; | 691 | 3.74k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 692 | 3.74k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 693 | 3.74k | break; | 694 | 505 | case 3: | 695 | 505 | hInfo->num_front_channels = 3; | 696 | 505 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 697 | 505 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 698 | 505 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 699 | 505 | break; | 700 | 762 | case 4: | 701 | 762 | hInfo->num_front_channels = 3; | 702 | 762 | hInfo->num_back_channels = 1; | 703 | 762 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 704 | 762 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 705 | 762 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 706 | 762 | hInfo->channel_position[3] = BACK_CHANNEL_CENTER; | 707 | 762 | break; | 708 | 576 | case 5: | 709 | 576 | hInfo->num_front_channels = 3; | 710 | 576 | hInfo->num_back_channels = 2; | 711 | 576 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 712 | 576 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 713 | 576 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 714 | 576 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 715 | 576 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 716 | 576 | break; | 717 | 378 | case 6: | 718 | 378 | hInfo->num_front_channels = 3; | 719 | 378 | hInfo->num_back_channels = 2; | 720 | 378 | hInfo->num_lfe_channels = 1; | 721 | 378 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 722 | 378 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 723 | 378 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 724 | 378 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 725 | 378 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 726 | 378 | hInfo->channel_position[5] = LFE_CHANNEL; | 727 | 378 | break; | 728 | 1.39k | case 7: | 729 | 1.39k | hInfo->num_front_channels = 3; | 730 | 1.39k | hInfo->num_side_channels = 2; | 731 | 1.39k | hInfo->num_back_channels = 2; | 732 | 1.39k | hInfo->num_lfe_channels = 1; | 733 | 1.39k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 734 | 1.39k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 735 | 1.39k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 736 | 1.39k | hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; | 737 | 1.39k | hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; | 738 | 1.39k | hInfo->channel_position[5] = BACK_CHANNEL_LEFT; | 739 | 1.39k | hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; | 740 | 1.39k | hInfo->channel_position[7] = LFE_CHANNEL; | 741 | 1.39k | break; | 742 | 215 | default: /* channelConfiguration == 0 || channelConfiguration > 7 */ | 743 | 215 | { | 744 | 215 | uint8_t i; | 745 | 215 | uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; | 746 | 215 | if (ch & 1) /* there's either a center front or a center back channel */ | 747 | 79 | { | 748 | 79 | uint8_t ch1 = (ch-1)/2; | 749 | 79 | if (hDecoder->first_syn_ele == ID_SCE) | 750 | 50 | { | 751 | 50 | hInfo->num_front_channels = ch1 + 1; | 752 | 50 | hInfo->num_back_channels = ch1; | 753 | 50 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 754 | 213 | for (i = 1; i <= ch1; i+=2) | 755 | 163 | { | 756 | 163 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 757 | 163 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 758 | 163 | } | 759 | 213 | for (i = ch1+1; i < ch; i+=2) | 760 | 163 | { | 761 | 163 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 762 | 163 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 763 | 163 | } | 764 | 50 | } else { | 765 | 29 | hInfo->num_front_channels = ch1; | 766 | 29 | hInfo->num_back_channels = ch1 + 1; | 767 | 157 | for (i = 0; i < ch1; i+=2) | 768 | 128 | { | 769 | 128 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 770 | 128 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 771 | 128 | } | 772 | 157 | for (i = ch1; i < ch-1; i+=2) | 773 | 128 | { | 774 | 128 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 775 | 128 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 776 | 128 | } | 777 | 29 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 778 | 29 | } | 779 | 136 | } else { | 780 | 136 | uint8_t ch1 = (ch)/2; | 781 | 136 | hInfo->num_front_channels = ch1; | 782 | 136 | hInfo->num_back_channels = ch1; | 783 | 136 | if (ch1 & 1) | 784 | 62 | { | 785 | 62 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 786 | 369 | for (i = 1; i <= ch1; i+=2) | 787 | 307 | { | 788 | 307 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 789 | 307 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 790 | 307 | } | 791 | 307 | for (i = ch1+1; i < ch-1; i+=2) | 792 | 245 | { | 793 | 245 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 794 | 245 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 795 | 245 | } | 796 | 62 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 797 | 74 | } else { | 798 | 345 | for (i = 0; i < ch1; i+=2) | 799 | 271 | { | 800 | 271 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 801 | 271 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 802 | 271 | } | 803 | 345 | for (i = ch1; i < ch; i+=2) | 804 | 271 | { | 805 | 271 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 806 | 271 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 807 | 271 | } | 808 | 74 | } | 809 | 136 | } | 810 | 215 | hInfo->num_lfe_channels = hDecoder->has_lfe; | 811 | 421 | for (i = ch; i < hDecoder->fr_channels; i++) | 812 | 206 | { | 813 | 206 | hInfo->channel_position[i] = LFE_CHANNEL; | 814 | 206 | } | 815 | 215 | } | 816 | 215 | break; | 817 | 8.00k | } | 818 | 8.00k | } | 819 | 8.32k | } |
decoder.c:create_channel_config Line | Count | Source | 599 | 9.23k | { | 600 | 9.23k | hInfo->num_front_channels = 0; | 601 | 9.23k | hInfo->num_side_channels = 0; | 602 | 9.23k | hInfo->num_back_channels = 0; | 603 | 9.23k | hInfo->num_lfe_channels = 0; | 604 | 9.23k | memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); | 605 | | | 606 | 9.23k | if (hDecoder->downMatrix) | 607 | 913 | { | 608 | 913 | hInfo->num_front_channels = 2; | 609 | 913 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 610 | 913 | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 611 | 913 | return; | 612 | 913 | } | 613 | | | 614 | | /* check if there is a PCE */ | 615 | | /* TODO: why CPE flag is ignored? */ | 616 | 8.32k | if (hDecoder->pce_set) | 617 | 314 | { | 618 | 314 | uint8_t i, chpos = 0; | 619 | 314 | uint8_t chdir, back_center = 0; | 620 | | | 621 | 314 | hInfo->num_front_channels = hDecoder->pce.num_front_channels; | 622 | 314 | hInfo->num_side_channels = hDecoder->pce.num_side_channels; | 623 | 314 | hInfo->num_back_channels = hDecoder->pce.num_back_channels; | 624 | 314 | hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; | 625 | 314 | chdir = hInfo->num_front_channels; | 626 | 314 | if (chdir & 1) | 627 | 144 | { | 628 | 144 | #if (defined(PS_DEC) || defined(DRM_PS)) | 629 | 144 | if (hInfo->num_front_channels == 1 && | 630 | 144 | hInfo->num_side_channels == 0 && | 631 | 144 | hInfo->num_back_channels == 0 && | 632 | 144 | hInfo->num_lfe_channels == 0) | 633 | 26 | { | 634 | | /* When PS is enabled output is always stereo */ | 635 | 26 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; | 636 | 26 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; | 637 | 26 | } else | 638 | 118 | #endif | 639 | 118 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; | 640 | 144 | chdir--; | 641 | 144 | } | 642 | 1.71k | for (i = 0; i < chdir; i++) | 643 | 1.39k | { | 644 | 1.39k | hInfo->channel_position[chpos++] = | 645 | 1.39k | (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT; | 646 | 1.39k | } | 647 | | | 648 | 1.57k | for (i = 0; i < hInfo->num_side_channels; i++) | 649 | 1.26k | { | 650 | 1.26k | hInfo->channel_position[chpos++] = | 651 | 1.26k | (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT; | 652 | 1.26k | } | 653 | | | 654 | 314 | chdir = hInfo->num_back_channels; | 655 | 314 | if (chdir & 1) | 656 | 66 | { | 657 | 66 | back_center = 1; | 658 | 66 | chdir--; | 659 | 66 | } | 660 | 1.34k | for (i = 0; i < chdir; i++) | 661 | 1.02k | { | 662 | 1.02k | hInfo->channel_position[chpos++] = | 663 | 1.02k | (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT; | 664 | 1.02k | } | 665 | 314 | if (back_center) | 666 | 66 | { | 667 | 66 | hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; | 668 | 66 | } | 669 | | | 670 | 555 | for (i = 0; i < hInfo->num_lfe_channels; i++) | 671 | 241 | { | 672 | 241 | hInfo->channel_position[chpos++] = LFE_CHANNEL; | 673 | 241 | } | 674 | | | 675 | 8.00k | } else { | 676 | 8.00k | switch (hDecoder->channelConfiguration) | 677 | 8.00k | { | 678 | 428 | case 1: | 679 | 428 | #if (defined(PS_DEC) || defined(DRM_PS)) | 680 | | /* When PS is enabled output is always stereo */ | 681 | 428 | hInfo->num_front_channels = 2; | 682 | 428 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 683 | 428 | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 684 | | #else | 685 | | hInfo->num_front_channels = 1; | 686 | | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 687 | | #endif | 688 | 428 | break; | 689 | 3.74k | case 2: | 690 | 3.74k | hInfo->num_front_channels = 2; | 691 | 3.74k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 692 | 3.74k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 693 | 3.74k | break; | 694 | 505 | case 3: | 695 | 505 | hInfo->num_front_channels = 3; | 696 | 505 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 697 | 505 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 698 | 505 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 699 | 505 | break; | 700 | 762 | case 4: | 701 | 762 | hInfo->num_front_channels = 3; | 702 | 762 | hInfo->num_back_channels = 1; | 703 | 762 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 704 | 762 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 705 | 762 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 706 | 762 | hInfo->channel_position[3] = BACK_CHANNEL_CENTER; | 707 | 762 | break; | 708 | 576 | case 5: | 709 | 576 | hInfo->num_front_channels = 3; | 710 | 576 | hInfo->num_back_channels = 2; | 711 | 576 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 712 | 576 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 713 | 576 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 714 | 576 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 715 | 576 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 716 | 576 | break; | 717 | 378 | case 6: | 718 | 378 | hInfo->num_front_channels = 3; | 719 | 378 | hInfo->num_back_channels = 2; | 720 | 378 | hInfo->num_lfe_channels = 1; | 721 | 378 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 722 | 378 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 723 | 378 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 724 | 378 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 725 | 378 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 726 | 378 | hInfo->channel_position[5] = LFE_CHANNEL; | 727 | 378 | break; | 728 | 1.39k | case 7: | 729 | 1.39k | hInfo->num_front_channels = 3; | 730 | 1.39k | hInfo->num_side_channels = 2; | 731 | 1.39k | hInfo->num_back_channels = 2; | 732 | 1.39k | hInfo->num_lfe_channels = 1; | 733 | 1.39k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 734 | 1.39k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 735 | 1.39k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 736 | 1.39k | hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; | 737 | 1.39k | hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; | 738 | 1.39k | hInfo->channel_position[5] = BACK_CHANNEL_LEFT; | 739 | 1.39k | hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; | 740 | 1.39k | hInfo->channel_position[7] = LFE_CHANNEL; | 741 | 1.39k | break; | 742 | 215 | default: /* channelConfiguration == 0 || channelConfiguration > 7 */ | 743 | 215 | { | 744 | 215 | uint8_t i; | 745 | 215 | uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; | 746 | 215 | if (ch & 1) /* there's either a center front or a center back channel */ | 747 | 79 | { | 748 | 79 | uint8_t ch1 = (ch-1)/2; | 749 | 79 | if (hDecoder->first_syn_ele == ID_SCE) | 750 | 50 | { | 751 | 50 | hInfo->num_front_channels = ch1 + 1; | 752 | 50 | hInfo->num_back_channels = ch1; | 753 | 50 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 754 | 213 | for (i = 1; i <= ch1; i+=2) | 755 | 163 | { | 756 | 163 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 757 | 163 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 758 | 163 | } | 759 | 213 | for (i = ch1+1; i < ch; i+=2) | 760 | 163 | { | 761 | 163 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 762 | 163 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 763 | 163 | } | 764 | 50 | } else { | 765 | 29 | hInfo->num_front_channels = ch1; | 766 | 29 | hInfo->num_back_channels = ch1 + 1; | 767 | 157 | for (i = 0; i < ch1; i+=2) | 768 | 128 | { | 769 | 128 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 770 | 128 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 771 | 128 | } | 772 | 157 | for (i = ch1; i < ch-1; i+=2) | 773 | 128 | { | 774 | 128 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 775 | 128 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 776 | 128 | } | 777 | 29 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 778 | 29 | } | 779 | 136 | } else { | 780 | 136 | uint8_t ch1 = (ch)/2; | 781 | 136 | hInfo->num_front_channels = ch1; | 782 | 136 | hInfo->num_back_channels = ch1; | 783 | 136 | if (ch1 & 1) | 784 | 62 | { | 785 | 62 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 786 | 369 | for (i = 1; i <= ch1; i+=2) | 787 | 307 | { | 788 | 307 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 789 | 307 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 790 | 307 | } | 791 | 307 | for (i = ch1+1; i < ch-1; i+=2) | 792 | 245 | { | 793 | 245 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 794 | 245 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 795 | 245 | } | 796 | 62 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 797 | 74 | } else { | 798 | 345 | for (i = 0; i < ch1; i+=2) | 799 | 271 | { | 800 | 271 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 801 | 271 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 802 | 271 | } | 803 | 345 | for (i = ch1; i < ch; i+=2) | 804 | 271 | { | 805 | 271 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 806 | 271 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 807 | 271 | } | 808 | 74 | } | 809 | 136 | } | 810 | 215 | hInfo->num_lfe_channels = hDecoder->has_lfe; | 811 | 421 | for (i = ch; i < hDecoder->fr_channels; i++) | 812 | 206 | { | 813 | 206 | hInfo->channel_position[i] = LFE_CHANNEL; | 814 | 206 | } | 815 | 215 | } | 816 | 215 | break; | 817 | 8.00k | } | 818 | 8.00k | } | 819 | 8.32k | } |
decoder.c:create_channel_config Line | Count | Source | 599 | 9.23k | { | 600 | 9.23k | hInfo->num_front_channels = 0; | 601 | 9.23k | hInfo->num_side_channels = 0; | 602 | 9.23k | hInfo->num_back_channels = 0; | 603 | 9.23k | hInfo->num_lfe_channels = 0; | 604 | 9.23k | memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); | 605 | | | 606 | 9.23k | if (hDecoder->downMatrix) | 607 | 913 | { | 608 | 913 | hInfo->num_front_channels = 2; | 609 | 913 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 610 | 913 | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 611 | 913 | return; | 612 | 913 | } | 613 | | | 614 | | /* check if there is a PCE */ | 615 | | /* TODO: why CPE flag is ignored? */ | 616 | 8.32k | if (hDecoder->pce_set) | 617 | 314 | { | 618 | 314 | uint8_t i, chpos = 0; | 619 | 314 | uint8_t chdir, back_center = 0; | 620 | | | 621 | 314 | hInfo->num_front_channels = hDecoder->pce.num_front_channels; | 622 | 314 | hInfo->num_side_channels = hDecoder->pce.num_side_channels; | 623 | 314 | hInfo->num_back_channels = hDecoder->pce.num_back_channels; | 624 | 314 | hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; | 625 | 314 | chdir = hInfo->num_front_channels; | 626 | 314 | if (chdir & 1) | 627 | 144 | { | 628 | 144 | #if (defined(PS_DEC) || defined(DRM_PS)) | 629 | 144 | if (hInfo->num_front_channels == 1 && | 630 | 144 | hInfo->num_side_channels == 0 && | 631 | 144 | hInfo->num_back_channels == 0 && | 632 | 144 | hInfo->num_lfe_channels == 0) | 633 | 26 | { | 634 | | /* When PS is enabled output is always stereo */ | 635 | 26 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; | 636 | 26 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; | 637 | 26 | } else | 638 | 118 | #endif | 639 | 118 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; | 640 | 144 | chdir--; | 641 | 144 | } | 642 | 1.71k | for (i = 0; i < chdir; i++) | 643 | 1.39k | { | 644 | 1.39k | hInfo->channel_position[chpos++] = | 645 | 1.39k | (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT; | 646 | 1.39k | } | 647 | | | 648 | 1.57k | for (i = 0; i < hInfo->num_side_channels; i++) | 649 | 1.26k | { | 650 | 1.26k | hInfo->channel_position[chpos++] = | 651 | 1.26k | (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT; | 652 | 1.26k | } | 653 | | | 654 | 314 | chdir = hInfo->num_back_channels; | 655 | 314 | if (chdir & 1) | 656 | 66 | { | 657 | 66 | back_center = 1; | 658 | 66 | chdir--; | 659 | 66 | } | 660 | 1.34k | for (i = 0; i < chdir; i++) | 661 | 1.02k | { | 662 | 1.02k | hInfo->channel_position[chpos++] = | 663 | 1.02k | (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT; | 664 | 1.02k | } | 665 | 314 | if (back_center) | 666 | 66 | { | 667 | 66 | hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; | 668 | 66 | } | 669 | | | 670 | 555 | for (i = 0; i < hInfo->num_lfe_channels; i++) | 671 | 241 | { | 672 | 241 | hInfo->channel_position[chpos++] = LFE_CHANNEL; | 673 | 241 | } | 674 | | | 675 | 8.00k | } else { | 676 | 8.00k | switch (hDecoder->channelConfiguration) | 677 | 8.00k | { | 678 | 428 | case 1: | 679 | 428 | #if (defined(PS_DEC) || defined(DRM_PS)) | 680 | | /* When PS is enabled output is always stereo */ | 681 | 428 | hInfo->num_front_channels = 2; | 682 | 428 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 683 | 428 | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 684 | | #else | 685 | | hInfo->num_front_channels = 1; | 686 | | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 687 | | #endif | 688 | 428 | break; | 689 | 3.74k | case 2: | 690 | 3.74k | hInfo->num_front_channels = 2; | 691 | 3.74k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 692 | 3.74k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 693 | 3.74k | break; | 694 | 505 | case 3: | 695 | 505 | hInfo->num_front_channels = 3; | 696 | 505 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 697 | 505 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 698 | 505 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 699 | 505 | break; | 700 | 762 | case 4: | 701 | 762 | hInfo->num_front_channels = 3; | 702 | 762 | hInfo->num_back_channels = 1; | 703 | 762 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 704 | 762 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 705 | 762 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 706 | 762 | hInfo->channel_position[3] = BACK_CHANNEL_CENTER; | 707 | 762 | break; | 708 | 576 | case 5: | 709 | 576 | hInfo->num_front_channels = 3; | 710 | 576 | hInfo->num_back_channels = 2; | 711 | 576 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 712 | 576 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 713 | 576 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 714 | 576 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 715 | 576 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 716 | 576 | break; | 717 | 378 | case 6: | 718 | 378 | hInfo->num_front_channels = 3; | 719 | 378 | hInfo->num_back_channels = 2; | 720 | 378 | hInfo->num_lfe_channels = 1; | 721 | 378 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 722 | 378 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 723 | 378 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 724 | 378 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 725 | 378 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 726 | 378 | hInfo->channel_position[5] = LFE_CHANNEL; | 727 | 378 | break; | 728 | 1.39k | case 7: | 729 | 1.39k | hInfo->num_front_channels = 3; | 730 | 1.39k | hInfo->num_side_channels = 2; | 731 | 1.39k | hInfo->num_back_channels = 2; | 732 | 1.39k | hInfo->num_lfe_channels = 1; | 733 | 1.39k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 734 | 1.39k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 735 | 1.39k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 736 | 1.39k | hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; | 737 | 1.39k | hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; | 738 | 1.39k | hInfo->channel_position[5] = BACK_CHANNEL_LEFT; | 739 | 1.39k | hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; | 740 | 1.39k | hInfo->channel_position[7] = LFE_CHANNEL; | 741 | 1.39k | break; | 742 | 215 | default: /* channelConfiguration == 0 || channelConfiguration > 7 */ | 743 | 215 | { | 744 | 215 | uint8_t i; | 745 | 215 | uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; | 746 | 215 | if (ch & 1) /* there's either a center front or a center back channel */ | 747 | 79 | { | 748 | 79 | uint8_t ch1 = (ch-1)/2; | 749 | 79 | if (hDecoder->first_syn_ele == ID_SCE) | 750 | 50 | { | 751 | 50 | hInfo->num_front_channels = ch1 + 1; | 752 | 50 | hInfo->num_back_channels = ch1; | 753 | 50 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 754 | 213 | for (i = 1; i <= ch1; i+=2) | 755 | 163 | { | 756 | 163 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 757 | 163 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 758 | 163 | } | 759 | 213 | for (i = ch1+1; i < ch; i+=2) | 760 | 163 | { | 761 | 163 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 762 | 163 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 763 | 163 | } | 764 | 50 | } else { | 765 | 29 | hInfo->num_front_channels = ch1; | 766 | 29 | hInfo->num_back_channels = ch1 + 1; | 767 | 157 | for (i = 0; i < ch1; i+=2) | 768 | 128 | { | 769 | 128 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 770 | 128 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 771 | 128 | } | 772 | 157 | for (i = ch1; i < ch-1; i+=2) | 773 | 128 | { | 774 | 128 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 775 | 128 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 776 | 128 | } | 777 | 29 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 778 | 29 | } | 779 | 136 | } else { | 780 | 136 | uint8_t ch1 = (ch)/2; | 781 | 136 | hInfo->num_front_channels = ch1; | 782 | 136 | hInfo->num_back_channels = ch1; | 783 | 136 | if (ch1 & 1) | 784 | 62 | { | 785 | 62 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 786 | 369 | for (i = 1; i <= ch1; i+=2) | 787 | 307 | { | 788 | 307 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 789 | 307 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 790 | 307 | } | 791 | 307 | for (i = ch1+1; i < ch-1; i+=2) | 792 | 245 | { | 793 | 245 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 794 | 245 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 795 | 245 | } | 796 | 62 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 797 | 74 | } else { | 798 | 345 | for (i = 0; i < ch1; i+=2) | 799 | 271 | { | 800 | 271 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 801 | 271 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 802 | 271 | } | 803 | 345 | for (i = ch1; i < ch; i+=2) | 804 | 271 | { | 805 | 271 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 806 | 271 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 807 | 271 | } | 808 | 74 | } | 809 | 136 | } | 810 | 215 | hInfo->num_lfe_channels = hDecoder->has_lfe; | 811 | 421 | for (i = ch; i < hDecoder->fr_channels; i++) | 812 | 206 | { | 813 | 206 | hInfo->channel_position[i] = LFE_CHANNEL; | 814 | 206 | } | 815 | 215 | } | 816 | 215 | break; | 817 | 8.00k | } | 818 | 8.00k | } | 819 | 8.32k | } |
decoder.c:create_channel_config Line | Count | Source | 599 | 9.23k | { | 600 | 9.23k | hInfo->num_front_channels = 0; | 601 | 9.23k | hInfo->num_side_channels = 0; | 602 | 9.23k | hInfo->num_back_channels = 0; | 603 | 9.23k | hInfo->num_lfe_channels = 0; | 604 | 9.23k | memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); | 605 | | | 606 | 9.23k | if (hDecoder->downMatrix) | 607 | 913 | { | 608 | 913 | hInfo->num_front_channels = 2; | 609 | 913 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 610 | 913 | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 611 | 913 | return; | 612 | 913 | } | 613 | | | 614 | | /* check if there is a PCE */ | 615 | | /* TODO: why CPE flag is ignored? */ | 616 | 8.32k | if (hDecoder->pce_set) | 617 | 314 | { | 618 | 314 | uint8_t i, chpos = 0; | 619 | 314 | uint8_t chdir, back_center = 0; | 620 | | | 621 | 314 | hInfo->num_front_channels = hDecoder->pce.num_front_channels; | 622 | 314 | hInfo->num_side_channels = hDecoder->pce.num_side_channels; | 623 | 314 | hInfo->num_back_channels = hDecoder->pce.num_back_channels; | 624 | 314 | hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; | 625 | 314 | chdir = hInfo->num_front_channels; | 626 | 314 | if (chdir & 1) | 627 | 144 | { | 628 | 144 | #if (defined(PS_DEC) || defined(DRM_PS)) | 629 | 144 | if (hInfo->num_front_channels == 1 && | 630 | 144 | hInfo->num_side_channels == 0 && | 631 | 144 | hInfo->num_back_channels == 0 && | 632 | 144 | hInfo->num_lfe_channels == 0) | 633 | 26 | { | 634 | | /* When PS is enabled output is always stereo */ | 635 | 26 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; | 636 | 26 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; | 637 | 26 | } else | 638 | 118 | #endif | 639 | 118 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; | 640 | 144 | chdir--; | 641 | 144 | } | 642 | 1.71k | for (i = 0; i < chdir; i++) | 643 | 1.39k | { | 644 | 1.39k | hInfo->channel_position[chpos++] = | 645 | 1.39k | (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT; | 646 | 1.39k | } | 647 | | | 648 | 1.57k | for (i = 0; i < hInfo->num_side_channels; i++) | 649 | 1.26k | { | 650 | 1.26k | hInfo->channel_position[chpos++] = | 651 | 1.26k | (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT; | 652 | 1.26k | } | 653 | | | 654 | 314 | chdir = hInfo->num_back_channels; | 655 | 314 | if (chdir & 1) | 656 | 66 | { | 657 | 66 | back_center = 1; | 658 | 66 | chdir--; | 659 | 66 | } | 660 | 1.34k | for (i = 0; i < chdir; i++) | 661 | 1.02k | { | 662 | 1.02k | hInfo->channel_position[chpos++] = | 663 | 1.02k | (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT; | 664 | 1.02k | } | 665 | 314 | if (back_center) | 666 | 66 | { | 667 | 66 | hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; | 668 | 66 | } | 669 | | | 670 | 555 | for (i = 0; i < hInfo->num_lfe_channels; i++) | 671 | 241 | { | 672 | 241 | hInfo->channel_position[chpos++] = LFE_CHANNEL; | 673 | 241 | } | 674 | | | 675 | 8.00k | } else { | 676 | 8.00k | switch (hDecoder->channelConfiguration) | 677 | 8.00k | { | 678 | 428 | case 1: | 679 | 428 | #if (defined(PS_DEC) || defined(DRM_PS)) | 680 | | /* When PS is enabled output is always stereo */ | 681 | 428 | hInfo->num_front_channels = 2; | 682 | 428 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 683 | 428 | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 684 | | #else | 685 | | hInfo->num_front_channels = 1; | 686 | | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 687 | | #endif | 688 | 428 | break; | 689 | 3.74k | case 2: | 690 | 3.74k | hInfo->num_front_channels = 2; | 691 | 3.74k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 692 | 3.74k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 693 | 3.74k | break; | 694 | 505 | case 3: | 695 | 505 | hInfo->num_front_channels = 3; | 696 | 505 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 697 | 505 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 698 | 505 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 699 | 505 | break; | 700 | 762 | case 4: | 701 | 762 | hInfo->num_front_channels = 3; | 702 | 762 | hInfo->num_back_channels = 1; | 703 | 762 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 704 | 762 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 705 | 762 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 706 | 762 | hInfo->channel_position[3] = BACK_CHANNEL_CENTER; | 707 | 762 | break; | 708 | 576 | case 5: | 709 | 576 | hInfo->num_front_channels = 3; | 710 | 576 | hInfo->num_back_channels = 2; | 711 | 576 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 712 | 576 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 713 | 576 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 714 | 576 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 715 | 576 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 716 | 576 | break; | 717 | 378 | case 6: | 718 | 378 | hInfo->num_front_channels = 3; | 719 | 378 | hInfo->num_back_channels = 2; | 720 | 378 | hInfo->num_lfe_channels = 1; | 721 | 378 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 722 | 378 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 723 | 378 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 724 | 378 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 725 | 378 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 726 | 378 | hInfo->channel_position[5] = LFE_CHANNEL; | 727 | 378 | break; | 728 | 1.39k | case 7: | 729 | 1.39k | hInfo->num_front_channels = 3; | 730 | 1.39k | hInfo->num_side_channels = 2; | 731 | 1.39k | hInfo->num_back_channels = 2; | 732 | 1.39k | hInfo->num_lfe_channels = 1; | 733 | 1.39k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 734 | 1.39k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 735 | 1.39k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 736 | 1.39k | hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; | 737 | 1.39k | hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; | 738 | 1.39k | hInfo->channel_position[5] = BACK_CHANNEL_LEFT; | 739 | 1.39k | hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; | 740 | 1.39k | hInfo->channel_position[7] = LFE_CHANNEL; | 741 | 1.39k | break; | 742 | 215 | default: /* channelConfiguration == 0 || channelConfiguration > 7 */ | 743 | 215 | { | 744 | 215 | uint8_t i; | 745 | 215 | uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; | 746 | 215 | if (ch & 1) /* there's either a center front or a center back channel */ | 747 | 79 | { | 748 | 79 | uint8_t ch1 = (ch-1)/2; | 749 | 79 | if (hDecoder->first_syn_ele == ID_SCE) | 750 | 50 | { | 751 | 50 | hInfo->num_front_channels = ch1 + 1; | 752 | 50 | hInfo->num_back_channels = ch1; | 753 | 50 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 754 | 213 | for (i = 1; i <= ch1; i+=2) | 755 | 163 | { | 756 | 163 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 757 | 163 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 758 | 163 | } | 759 | 213 | for (i = ch1+1; i < ch; i+=2) | 760 | 163 | { | 761 | 163 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 762 | 163 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 763 | 163 | } | 764 | 50 | } else { | 765 | 29 | hInfo->num_front_channels = ch1; | 766 | 29 | hInfo->num_back_channels = ch1 + 1; | 767 | 157 | for (i = 0; i < ch1; i+=2) | 768 | 128 | { | 769 | 128 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 770 | 128 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 771 | 128 | } | 772 | 157 | for (i = ch1; i < ch-1; i+=2) | 773 | 128 | { | 774 | 128 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 775 | 128 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 776 | 128 | } | 777 | 29 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 778 | 29 | } | 779 | 136 | } else { | 780 | 136 | uint8_t ch1 = (ch)/2; | 781 | 136 | hInfo->num_front_channels = ch1; | 782 | 136 | hInfo->num_back_channels = ch1; | 783 | 136 | if (ch1 & 1) | 784 | 62 | { | 785 | 62 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 786 | 369 | for (i = 1; i <= ch1; i+=2) | 787 | 307 | { | 788 | 307 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 789 | 307 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 790 | 307 | } | 791 | 307 | for (i = ch1+1; i < ch-1; i+=2) | 792 | 245 | { | 793 | 245 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 794 | 245 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 795 | 245 | } | 796 | 62 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 797 | 74 | } else { | 798 | 345 | for (i = 0; i < ch1; i+=2) | 799 | 271 | { | 800 | 271 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 801 | 271 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 802 | 271 | } | 803 | 345 | for (i = ch1; i < ch; i+=2) | 804 | 271 | { | 805 | 271 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 806 | 271 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 807 | 271 | } | 808 | 74 | } | 809 | 136 | } | 810 | 215 | hInfo->num_lfe_channels = hDecoder->has_lfe; | 811 | 421 | for (i = ch; i < hDecoder->fr_channels; i++) | 812 | 206 | { | 813 | 206 | hInfo->channel_position[i] = LFE_CHANNEL; | 814 | 206 | } | 815 | 215 | } | 816 | 215 | break; | 817 | 8.00k | } | 818 | 8.00k | } | 819 | 8.32k | } |
|
820 | | |
821 | | void* NeAACDecDecode(NeAACDecHandle hpDecoder, |
822 | | NeAACDecFrameInfo *hInfo, |
823 | | unsigned char *buffer, |
824 | | unsigned long buffer_size) |
825 | 36.3k | { |
826 | 36.3k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
827 | 36.3k | return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, NULL, 0); |
828 | 36.3k | } |
829 | | |
830 | | void* NeAACDecDecode2(NeAACDecHandle hpDecoder, |
831 | | NeAACDecFrameInfo *hInfo, |
832 | | unsigned char *buffer, |
833 | | unsigned long buffer_size, |
834 | | void **sample_buffer, |
835 | | unsigned long sample_buffer_size) |
836 | 10.9k | { |
837 | 10.9k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
838 | 10.9k | if ((sample_buffer_size == 0) || (sample_buffer == NULL) || (*sample_buffer == NULL)) |
839 | 103 | { |
840 | 103 | hInfo->error = 27; |
841 | 103 | return NULL; |
842 | 103 | } |
843 | | |
844 | 10.8k | return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, |
845 | 10.8k | sample_buffer, sample_buffer_size); |
846 | 10.9k | } |
847 | | |
848 | | static void* aac_frame_decode(NeAACDecStruct *hDecoder, |
849 | | NeAACDecFrameInfo *hInfo, |
850 | | unsigned char *buffer, |
851 | | unsigned long buffer_size, |
852 | | void **sample_buffer2, |
853 | | unsigned long sample_buffer_size) |
854 | 47.1k | { |
855 | 47.1k | uint16_t i; |
856 | 47.1k | uint8_t channels = 0; |
857 | 47.1k | uint8_t output_channels = 0; |
858 | 47.1k | bitfile ld; |
859 | 47.1k | uint32_t bitsconsumed; |
860 | 47.1k | uint16_t frame_len; |
861 | 47.1k | void *sample_buffer; |
862 | | #if 0 |
863 | | uint32_t startbit=0, endbit=0, payload_bits=0; |
864 | | #endif |
865 | 47.1k | uint32_t required_buffer_size=0; |
866 | | |
867 | | #ifdef PROFILE |
868 | | int64_t count = faad_get_ts(); |
869 | | #endif |
870 | | |
871 | | /* safety checks */ |
872 | 47.1k | if ((hDecoder == NULL) || (hInfo == NULL) || (buffer == NULL)) |
873 | 0 | { |
874 | 0 | return NULL; |
875 | 0 | } |
876 | | |
877 | | #if 0 |
878 | | printf("%d\n", buffer_size*8); |
879 | | #endif |
880 | | |
881 | 47.1k | frame_len = hDecoder->frameLength; |
882 | | |
883 | | |
884 | 47.1k | memset(hInfo, 0, sizeof(NeAACDecFrameInfo)); |
885 | 47.1k | memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0])); |
886 | | |
887 | | #ifdef USE_TIME_LIMIT |
888 | | if ((TIME_LIMIT * get_sample_rate(hDecoder->sf_index)) > hDecoder->TL_count) |
889 | | { |
890 | | hDecoder->TL_count += 1024; |
891 | | } else { |
892 | | hInfo->error = (NUM_ERROR_MESSAGES-1); |
893 | | goto error; |
894 | | } |
895 | | #endif |
896 | | |
897 | | |
898 | | /* check for some common metadata tag types in the bitstream |
899 | | * No need to return an error |
900 | | */ |
901 | | /* ID3 */ |
902 | 47.1k | if (buffer_size >= 128) |
903 | 5.56k | { |
904 | 5.56k | if (memcmp(buffer, "TAG", 3) == 0) |
905 | 12 | { |
906 | | /* found it */ |
907 | 12 | hInfo->bytesconsumed = 128; /* 128 bytes fixed size */ |
908 | | /* no error, but no output either */ |
909 | 12 | return NULL; |
910 | 12 | } |
911 | 5.56k | } |
912 | | |
913 | | |
914 | | /* initialize the bitstream */ |
915 | 47.1k | faad_initbits(&ld, buffer, buffer_size); |
916 | 47.1k | if (ld.error != 0) |
917 | 18.4k | return NULL; |
918 | | |
919 | | #if 0 |
920 | | { |
921 | | int i; |
922 | | for (i = 0; i < ((buffer_size+3)>>2); i++) |
923 | | { |
924 | | uint8_t *buf; |
925 | | uint32_t temp = 0; |
926 | | buf = faad_getbitbuffer(&ld, 32); |
927 | | //temp = getdword((void*)buf); |
928 | | temp = *((uint32_t*)buf); |
929 | | printf("0x%.8X\n", temp); |
930 | | free(buf); |
931 | | } |
932 | | faad_endbits(&ld); |
933 | | faad_initbits(&ld, buffer, buffer_size); |
934 | | } |
935 | | #endif |
936 | | |
937 | | #if 0 |
938 | | if(hDecoder->latm_header_present) |
939 | | { |
940 | | payload_bits = faad_latm_frame(&hDecoder->latm_config, &ld); |
941 | | startbit = faad_get_processed_bits(&ld); |
942 | | if(payload_bits == -1U) |
943 | | { |
944 | | hInfo->error = 1; |
945 | | goto error; |
946 | | } |
947 | | } |
948 | | #endif |
949 | | |
950 | | #ifdef DRM |
951 | 10.2k | if (hDecoder->object_type == DRM_ER_LC) |
952 | 989 | { |
953 | | /* We do not support stereo right now */ |
954 | 989 | if (0) //(hDecoder->channelConfiguration == 2) |
955 | 0 | { |
956 | 0 | hInfo->error = 28; // Throw CRC error |
957 | 0 | goto error; |
958 | 0 | } |
959 | | |
960 | 989 | faad_getbits(&ld, 8 |
961 | 989 | DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC")); |
962 | 989 | } |
963 | 10.2k | #endif |
964 | | |
965 | 28.7k | if (hDecoder->adts_header_present) |
966 | 814 | { |
967 | 814 | adts_header adts; |
968 | | |
969 | 814 | adts.old_format = hDecoder->config.useOldADTSFormat; |
970 | 814 | if ((hInfo->error = adts_frame(&adts, &ld)) > 0) |
971 | 103 | goto error; |
972 | | |
973 | | /* MPEG2 does byte_alignment() here, |
974 | | * but ADTS header is always multiple of 8 bits in MPEG2 |
975 | | * so not needed to actually do it. |
976 | | */ |
977 | 814 | } |
978 | | |
979 | | #ifdef ANALYSIS |
980 | | dbg_count = 0; |
981 | | #endif |
982 | | |
983 | | /* decode the complete bitstream */ |
984 | | #ifdef DRM |
985 | 10.2k | if (/*(hDecoder->object_type == 6) ||*/ hDecoder->object_type == DRM_ER_LC) |
986 | 989 | { |
987 | 989 | DRM_aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); |
988 | 9.28k | } else { |
989 | 9.28k | #endif |
990 | 18.3k | raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); |
991 | | #ifdef DRM |
992 | | } |
993 | | #endif |
994 | | |
995 | | #if 0 |
996 | | if(hDecoder->latm_header_present) |
997 | | { |
998 | | endbit = faad_get_processed_bits(&ld); |
999 | | if(endbit-startbit > payload_bits) |
1000 | | fprintf(stderr, "\r\nERROR, too many payload bits read: %u > %d. Please. report with a link to a sample\n", |
1001 | | endbit-startbit, payload_bits); |
1002 | | if(hDecoder->latm_config.otherDataLenBits > 0) |
1003 | | faad_getbits(&ld, hDecoder->latm_config.otherDataLenBits); |
1004 | | faad_byte_align(&ld); |
1005 | | } |
1006 | | #endif |
1007 | | |
1008 | 18.3k | channels = hDecoder->fr_channels; |
1009 | | |
1010 | 28.6k | if (hInfo->error > 0) |
1011 | 19.2k | goto error; |
1012 | | |
1013 | | /* safety check */ |
1014 | 9.34k | if (channels == 0 || channels > MAX_CHANNELS) |
1015 | 101 | { |
1016 | | /* invalid number of channels */ |
1017 | 101 | hInfo->error = 12; |
1018 | 101 | goto error; |
1019 | 101 | } |
1020 | | |
1021 | | /* no more bit reading after this */ |
1022 | 9.24k | bitsconsumed = faad_get_processed_bits(&ld); |
1023 | 9.24k | hInfo->bytesconsumed = bit2byte(bitsconsumed); |
1024 | 9.24k | if (ld.error) |
1025 | 0 | { |
1026 | 0 | hInfo->error = 14; |
1027 | 0 | goto error; |
1028 | 0 | } |
1029 | 9.24k | faad_endbits(&ld); |
1030 | | |
1031 | | |
1032 | 9.24k | if (!hDecoder->adts_header_present && !hDecoder->adif_header_present |
1033 | | #if 0 |
1034 | | && !hDecoder->latm_header_present |
1035 | | #endif |
1036 | 9.24k | ) |
1037 | 9.03k | { |
1038 | 9.03k | if (hDecoder->channelConfiguration == 0) |
1039 | 275 | hDecoder->channelConfiguration = channels; |
1040 | | |
1041 | 9.03k | if (channels == 8) /* 7.1 */ |
1042 | 1.05k | hDecoder->channelConfiguration = 7; |
1043 | 9.03k | if (channels == 7) /* not a standard channelConfiguration */ |
1044 | 53 | hDecoder->channelConfiguration = 0; |
1045 | 9.03k | } |
1046 | | |
1047 | 9.24k | if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix) |
1048 | 905 | { |
1049 | 905 | hDecoder->downMatrix = 1; |
1050 | 905 | output_channels = 2; |
1051 | 8.33k | } else { |
1052 | 8.33k | output_channels = channels; |
1053 | 8.33k | } |
1054 | | |
1055 | 9.24k | #if (defined(PS_DEC) || defined(DRM_PS)) |
1056 | 9.24k | hDecoder->upMatrix = 0; |
1057 | | /* check if we have a mono file */ |
1058 | 9.24k | if (output_channels == 1) |
1059 | 245 | { |
1060 | | /* upMatrix to 2 channels for implicit signalling of PS */ |
1061 | 245 | hDecoder->upMatrix = 1; |
1062 | 245 | output_channels = 2; |
1063 | 245 | } |
1064 | 9.24k | #endif |
1065 | | |
1066 | | /* Make a channel configuration based on either a PCE or a channelConfiguration */ |
1067 | 9.24k | if (!hDecoder->downMatrix && hDecoder->pce_set) |
1068 | 323 | { |
1069 | | /* In some codepath program_config_element result is ignored. */ |
1070 | 323 | if (hDecoder->pce.channels > MAX_CHANNELS) |
1071 | 9 | { |
1072 | 9 | hInfo->error = 22; |
1073 | 9 | return NULL; |
1074 | 9 | } |
1075 | 323 | } |
1076 | 9.23k | create_channel_config(hDecoder, hInfo); |
1077 | | |
1078 | | /* number of samples in this frame */ |
1079 | 9.23k | hInfo->samples = frame_len*output_channels; |
1080 | | /* number of channels in this frame */ |
1081 | 9.23k | hInfo->channels = output_channels; |
1082 | | /* samplerate */ |
1083 | 9.23k | hInfo->samplerate = get_sample_rate(hDecoder->sf_index); |
1084 | | /* object type */ |
1085 | 9.23k | hInfo->object_type = hDecoder->object_type; |
1086 | | /* sbr */ |
1087 | 9.23k | hInfo->sbr = NO_SBR; |
1088 | | /* header type */ |
1089 | 9.23k | hInfo->header_type = RAW; |
1090 | 9.23k | if (hDecoder->adif_header_present) |
1091 | 0 | hInfo->header_type = ADIF; |
1092 | 9.23k | if (hDecoder->adts_header_present) |
1093 | 213 | hInfo->header_type = ADTS; |
1094 | | #if 0 |
1095 | | if (hDecoder->latm_header_present) |
1096 | | hInfo->header_type = LATM; |
1097 | | #endif |
1098 | 9.23k | #if (defined(PS_DEC) || defined(DRM_PS)) |
1099 | 9.23k | hInfo->ps = hDecoder->ps_used_global; |
1100 | 9.23k | #endif |
1101 | | |
1102 | | /* check if frame has channel elements */ |
1103 | 9.23k | if (channels == 0) |
1104 | 0 | { |
1105 | 0 | hDecoder->frame++; |
1106 | 0 | return NULL; |
1107 | 0 | } |
1108 | | |
1109 | 9.23k | { |
1110 | 9.23k | static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t), |
1111 | 9.23k | sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t), |
1112 | 9.23k | sizeof(int16_t), sizeof(int16_t), 0, 0, 0 |
1113 | 9.23k | }; |
1114 | 9.23k | uint8_t stride = str[hDecoder->config.outputFormat-1]; |
1115 | 9.23k | #ifdef SBR_DEC |
1116 | 9.23k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1)) |
1117 | 5.25k | { |
1118 | 5.25k | stride = 2 * stride; |
1119 | 5.25k | } |
1120 | 9.23k | #endif |
1121 | 9.23k | required_buffer_size = frame_len*output_channels*stride; |
1122 | 9.23k | } |
1123 | | |
1124 | | /* check if we want to use internal sample_buffer */ |
1125 | 9.23k | if (sample_buffer_size == 0) |
1126 | 6.32k | { |
1127 | | /* allocate the buffer for the final samples */ |
1128 | 6.32k | if (hDecoder->sample_buffer_size != required_buffer_size) |
1129 | 5.53k | { |
1130 | 5.53k | if (hDecoder->sample_buffer) |
1131 | 91 | faad_free(hDecoder->sample_buffer); |
1132 | 5.53k | hDecoder->sample_buffer = NULL; |
1133 | 5.53k | hDecoder->sample_buffer = faad_malloc(required_buffer_size); |
1134 | 5.53k | hDecoder->sample_buffer_size = required_buffer_size; |
1135 | 5.53k | } |
1136 | 6.32k | } else if (sample_buffer_size < required_buffer_size) { |
1137 | | /* provided sample buffer is not big enough */ |
1138 | 1.30k | hInfo->error = 27; |
1139 | 1.30k | return NULL; |
1140 | 1.30k | } |
1141 | | |
1142 | 7.93k | if (sample_buffer_size == 0) |
1143 | 6.32k | { |
1144 | 6.32k | sample_buffer = hDecoder->sample_buffer; |
1145 | 6.32k | } else { |
1146 | 1.61k | sample_buffer = *sample_buffer2; |
1147 | 1.61k | } |
1148 | | |
1149 | 7.93k | #ifdef SBR_DEC |
1150 | 7.93k | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) |
1151 | 5.52k | { |
1152 | 5.52k | uint8_t ele; |
1153 | | |
1154 | | /* this data is different when SBR is used or when the data is upsampled */ |
1155 | 5.52k | if (!hDecoder->downSampledSBR) |
1156 | 4.32k | { |
1157 | 4.32k | frame_len *= 2; |
1158 | 4.32k | hInfo->samples *= 2; |
1159 | 4.32k | hInfo->samplerate *= 2; |
1160 | 4.32k | } |
1161 | | |
1162 | | /* check if every element was provided with SBR data */ |
1163 | 28.6k | for (ele = 0; ele < hDecoder->fr_ch_ele; ele++) |
1164 | 23.1k | { |
1165 | 23.1k | if (hDecoder->sbr[ele] == NULL) |
1166 | 8 | { |
1167 | 8 | hInfo->error = 25; |
1168 | 8 | goto error; |
1169 | 8 | } |
1170 | 23.1k | } |
1171 | | |
1172 | | /* sbr */ |
1173 | 5.51k | if (hDecoder->sbr_present_flag == 1) |
1174 | 3.58k | { |
1175 | 3.58k | hInfo->object_type = HE_AAC; |
1176 | 3.58k | hInfo->sbr = SBR_UPSAMPLED; |
1177 | 3.58k | } else { |
1178 | 1.93k | hInfo->sbr = NO_SBR_UPSAMPLED; |
1179 | 1.93k | } |
1180 | 5.51k | if (hDecoder->downSampledSBR) |
1181 | 1.19k | { |
1182 | 1.19k | hInfo->sbr = SBR_DOWNSAMPLED; |
1183 | 1.19k | } |
1184 | 5.51k | } |
1185 | 7.92k | #endif |
1186 | | |
1187 | | |
1188 | 7.92k | sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer, |
1189 | 7.92k | output_channels, frame_len, hDecoder->config.outputFormat); |
1190 | | |
1191 | | |
1192 | | #ifdef DRM |
1193 | | //conceal_output(hDecoder, frame_len, output_channels, sample_buffer); |
1194 | | #endif |
1195 | | |
1196 | | |
1197 | 7.92k | hDecoder->postSeekResetFlag = 0; |
1198 | | |
1199 | 7.92k | hDecoder->frame++; |
1200 | | #ifdef LD_DEC |
1201 | 5.21k | if (hDecoder->object_type != LD) |
1202 | 4.56k | { |
1203 | 4.56k | #endif |
1204 | 7.28k | if (hDecoder->frame <= 1) |
1205 | 2.96k | hInfo->samples = 0; |
1206 | | #ifdef LD_DEC |
1207 | 642 | } else { |
1208 | | /* LD encoders will give lower delay */ |
1209 | 642 | if (hDecoder->frame <= 0) |
1210 | 0 | hInfo->samples = 0; |
1211 | 642 | } |
1212 | | #endif |
1213 | | |
1214 | | /* cleanup */ |
1215 | | #ifdef ANALYSIS |
1216 | | fflush(stdout); |
1217 | | #endif |
1218 | | |
1219 | | #ifdef PROFILE |
1220 | | count = faad_get_ts() - count; |
1221 | | hDecoder->cycles += count; |
1222 | | #endif |
1223 | | |
1224 | 7.92k | return sample_buffer; |
1225 | | |
1226 | 19.4k | error: |
1227 | | |
1228 | | /* reset filterbank state */ |
1229 | 1.26M | for (i = 0; i < MAX_CHANNELS; i++) |
1230 | 1.24M | { |
1231 | 1.24M | if (hDecoder->fb_intermed[i] != NULL) |
1232 | 600k | { |
1233 | 600k | memset(hDecoder->fb_intermed[i], 0, hDecoder->frameLength*sizeof(real_t)); |
1234 | 600k | } |
1235 | 1.24M | } |
1236 | 19.4k | #ifdef SBR_DEC |
1237 | 954k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) |
1238 | 935k | { |
1239 | 935k | if (hDecoder->sbr[i] != NULL) |
1240 | 430k | { |
1241 | 430k | sbrReset(hDecoder->sbr[i]); |
1242 | 430k | } |
1243 | 935k | } |
1244 | 19.4k | #endif |
1245 | | |
1246 | | |
1247 | 19.4k | faad_endbits(&ld); |
1248 | | |
1249 | | /* cleanup */ |
1250 | | #ifdef ANALYSIS |
1251 | | fflush(stdout); |
1252 | | #endif |
1253 | | |
1254 | 19.4k | return NULL; |
1255 | 7.93k | } decoder.c:aac_frame_decode Line | Count | Source | 854 | 17.0k | { | 855 | 17.0k | uint16_t i; | 856 | 17.0k | uint8_t channels = 0; | 857 | 17.0k | uint8_t output_channels = 0; | 858 | 17.0k | bitfile ld; | 859 | 17.0k | uint32_t bitsconsumed; | 860 | 17.0k | uint16_t frame_len; | 861 | 17.0k | void *sample_buffer; | 862 | | #if 0 | 863 | | uint32_t startbit=0, endbit=0, payload_bits=0; | 864 | | #endif | 865 | 17.0k | uint32_t required_buffer_size=0; | 866 | | | 867 | | #ifdef PROFILE | 868 | | int64_t count = faad_get_ts(); | 869 | | #endif | 870 | | | 871 | | /* safety checks */ | 872 | 17.0k | if ((hDecoder == NULL) || (hInfo == NULL) || (buffer == NULL)) | 873 | 0 | { | 874 | 0 | return NULL; | 875 | 0 | } | 876 | | | 877 | | #if 0 | 878 | | printf("%d\n", buffer_size*8); | 879 | | #endif | 880 | | | 881 | 17.0k | frame_len = hDecoder->frameLength; | 882 | | | 883 | | | 884 | 17.0k | memset(hInfo, 0, sizeof(NeAACDecFrameInfo)); | 885 | 17.0k | memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0])); | 886 | | | 887 | | #ifdef USE_TIME_LIMIT | 888 | | if ((TIME_LIMIT * get_sample_rate(hDecoder->sf_index)) > hDecoder->TL_count) | 889 | | { | 890 | | hDecoder->TL_count += 1024; | 891 | | } else { | 892 | | hInfo->error = (NUM_ERROR_MESSAGES-1); | 893 | | goto error; | 894 | | } | 895 | | #endif | 896 | | | 897 | | | 898 | | /* check for some common metadata tag types in the bitstream | 899 | | * No need to return an error | 900 | | */ | 901 | | /* ID3 */ | 902 | 17.0k | if (buffer_size >= 128) | 903 | 2.51k | { | 904 | 2.51k | if (memcmp(buffer, "TAG", 3) == 0) | 905 | 6 | { | 906 | | /* found it */ | 907 | 6 | hInfo->bytesconsumed = 128; /* 128 bytes fixed size */ | 908 | | /* no error, but no output either */ | 909 | 6 | return NULL; | 910 | 6 | } | 911 | 2.51k | } | 912 | | | 913 | | | 914 | | /* initialize the bitstream */ | 915 | 17.0k | faad_initbits(&ld, buffer, buffer_size); | 916 | 17.0k | if (ld.error != 0) | 917 | 6.73k | return NULL; | 918 | | | 919 | | #if 0 | 920 | | { | 921 | | int i; | 922 | | for (i = 0; i < ((buffer_size+3)>>2); i++) | 923 | | { | 924 | | uint8_t *buf; | 925 | | uint32_t temp = 0; | 926 | | buf = faad_getbitbuffer(&ld, 32); | 927 | | //temp = getdword((void*)buf); | 928 | | temp = *((uint32_t*)buf); | 929 | | printf("0x%.8X\n", temp); | 930 | | free(buf); | 931 | | } | 932 | | faad_endbits(&ld); | 933 | | faad_initbits(&ld, buffer, buffer_size); | 934 | | } | 935 | | #endif | 936 | | | 937 | | #if 0 | 938 | | if(hDecoder->latm_header_present) | 939 | | { | 940 | | payload_bits = faad_latm_frame(&hDecoder->latm_config, &ld); | 941 | | startbit = faad_get_processed_bits(&ld); | 942 | | if(payload_bits == -1U) | 943 | | { | 944 | | hInfo->error = 1; | 945 | | goto error; | 946 | | } | 947 | | } | 948 | | #endif | 949 | | | 950 | 10.2k | #ifdef DRM | 951 | 10.2k | if (hDecoder->object_type == DRM_ER_LC) | 952 | 989 | { | 953 | | /* We do not support stereo right now */ | 954 | 989 | if (0) //(hDecoder->channelConfiguration == 2) | 955 | 0 | { | 956 | 0 | hInfo->error = 28; // Throw CRC error | 957 | 0 | goto error; | 958 | 0 | } | 959 | | | 960 | 989 | faad_getbits(&ld, 8 | 961 | 989 | DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC")); | 962 | 989 | } | 963 | 10.2k | #endif | 964 | | | 965 | 10.2k | if (hDecoder->adts_header_present) | 966 | 105 | { | 967 | 105 | adts_header adts; | 968 | | | 969 | 105 | adts.old_format = hDecoder->config.useOldADTSFormat; | 970 | 105 | if ((hInfo->error = adts_frame(&adts, &ld)) > 0) | 971 | 5 | goto error; | 972 | | | 973 | | /* MPEG2 does byte_alignment() here, | 974 | | * but ADTS header is always multiple of 8 bits in MPEG2 | 975 | | * so not needed to actually do it. | 976 | | */ | 977 | 105 | } | 978 | | | 979 | | #ifdef ANALYSIS | 980 | | dbg_count = 0; | 981 | | #endif | 982 | | | 983 | | /* decode the complete bitstream */ | 984 | 10.2k | #ifdef DRM | 985 | 10.2k | if (/*(hDecoder->object_type == 6) ||*/ hDecoder->object_type == DRM_ER_LC) | 986 | 989 | { | 987 | 989 | DRM_aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); | 988 | 9.28k | } else { | 989 | 9.28k | #endif | 990 | 9.28k | raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); | 991 | 9.28k | #ifdef DRM | 992 | 9.28k | } | 993 | 10.2k | #endif | 994 | | | 995 | | #if 0 | 996 | | if(hDecoder->latm_header_present) | 997 | | { | 998 | | endbit = faad_get_processed_bits(&ld); | 999 | | if(endbit-startbit > payload_bits) | 1000 | | fprintf(stderr, "\r\nERROR, too many payload bits read: %u > %d. Please. report with a link to a sample\n", | 1001 | | endbit-startbit, payload_bits); | 1002 | | if(hDecoder->latm_config.otherDataLenBits > 0) | 1003 | | faad_getbits(&ld, hDecoder->latm_config.otherDataLenBits); | 1004 | | faad_byte_align(&ld); | 1005 | | } | 1006 | | #endif | 1007 | | | 1008 | 10.2k | channels = hDecoder->fr_channels; | 1009 | | | 1010 | 10.2k | if (hInfo->error > 0) | 1011 | 6.87k | goto error; | 1012 | | | 1013 | | /* safety check */ | 1014 | 3.40k | if (channels == 0 || channels > MAX_CHANNELS) | 1015 | 31 | { | 1016 | | /* invalid number of channels */ | 1017 | 31 | hInfo->error = 12; | 1018 | 31 | goto error; | 1019 | 31 | } | 1020 | | | 1021 | | /* no more bit reading after this */ | 1022 | 3.37k | bitsconsumed = faad_get_processed_bits(&ld); | 1023 | 3.37k | hInfo->bytesconsumed = bit2byte(bitsconsumed); | 1024 | 3.37k | if (ld.error) | 1025 | 0 | { | 1026 | 0 | hInfo->error = 14; | 1027 | 0 | goto error; | 1028 | 0 | } | 1029 | 3.37k | faad_endbits(&ld); | 1030 | | | 1031 | | | 1032 | 3.37k | if (!hDecoder->adts_header_present && !hDecoder->adif_header_present | 1033 | | #if 0 | 1034 | | && !hDecoder->latm_header_present | 1035 | | #endif | 1036 | 3.37k | ) | 1037 | 3.32k | { | 1038 | 3.32k | if (hDecoder->channelConfiguration == 0) | 1039 | 135 | hDecoder->channelConfiguration = channels; | 1040 | | | 1041 | 3.32k | if (channels == 8) /* 7.1 */ | 1042 | 186 | hDecoder->channelConfiguration = 7; | 1043 | 3.32k | if (channels == 7) /* not a standard channelConfiguration */ | 1044 | 0 | hDecoder->channelConfiguration = 0; | 1045 | 3.32k | } | 1046 | | | 1047 | 3.37k | if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix) | 1048 | 470 | { | 1049 | 470 | hDecoder->downMatrix = 1; | 1050 | 470 | output_channels = 2; | 1051 | 2.90k | } else { | 1052 | 2.90k | output_channels = channels; | 1053 | 2.90k | } | 1054 | | | 1055 | 3.37k | #if (defined(PS_DEC) || defined(DRM_PS)) | 1056 | 3.37k | hDecoder->upMatrix = 0; | 1057 | | /* check if we have a mono file */ | 1058 | 3.37k | if (output_channels == 1) | 1059 | 0 | { | 1060 | | /* upMatrix to 2 channels for implicit signalling of PS */ | 1061 | 0 | hDecoder->upMatrix = 1; | 1062 | 0 | output_channels = 2; | 1063 | 0 | } | 1064 | 3.37k | #endif | 1065 | | | 1066 | | /* Make a channel configuration based on either a PCE or a channelConfiguration */ | 1067 | 3.37k | if (!hDecoder->downMatrix && hDecoder->pce_set) | 1068 | 159 | { | 1069 | | /* In some codepath program_config_element result is ignored. */ | 1070 | 159 | if (hDecoder->pce.channels > MAX_CHANNELS) | 1071 | 3 | { | 1072 | 3 | hInfo->error = 22; | 1073 | 3 | return NULL; | 1074 | 3 | } | 1075 | 159 | } | 1076 | 3.36k | create_channel_config(hDecoder, hInfo); | 1077 | | | 1078 | | /* number of samples in this frame */ | 1079 | 3.36k | hInfo->samples = frame_len*output_channels; | 1080 | | /* number of channels in this frame */ | 1081 | 3.36k | hInfo->channels = output_channels; | 1082 | | /* samplerate */ | 1083 | 3.36k | hInfo->samplerate = get_sample_rate(hDecoder->sf_index); | 1084 | | /* object type */ | 1085 | 3.36k | hInfo->object_type = hDecoder->object_type; | 1086 | | /* sbr */ | 1087 | 3.36k | hInfo->sbr = NO_SBR; | 1088 | | /* header type */ | 1089 | 3.36k | hInfo->header_type = RAW; | 1090 | 3.36k | if (hDecoder->adif_header_present) | 1091 | 0 | hInfo->header_type = ADIF; | 1092 | 3.36k | if (hDecoder->adts_header_present) | 1093 | 41 | hInfo->header_type = ADTS; | 1094 | | #if 0 | 1095 | | if (hDecoder->latm_header_present) | 1096 | | hInfo->header_type = LATM; | 1097 | | #endif | 1098 | 3.36k | #if (defined(PS_DEC) || defined(DRM_PS)) | 1099 | 3.36k | hInfo->ps = hDecoder->ps_used_global; | 1100 | 3.36k | #endif | 1101 | | | 1102 | | /* check if frame has channel elements */ | 1103 | 3.36k | if (channels == 0) | 1104 | 0 | { | 1105 | 0 | hDecoder->frame++; | 1106 | 0 | return NULL; | 1107 | 0 | } | 1108 | | | 1109 | 3.36k | { | 1110 | 3.36k | static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t), | 1111 | 3.36k | sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t), | 1112 | 3.36k | sizeof(int16_t), sizeof(int16_t), 0, 0, 0 | 1113 | 3.36k | }; | 1114 | 3.36k | uint8_t stride = str[hDecoder->config.outputFormat-1]; | 1115 | 3.36k | #ifdef SBR_DEC | 1116 | 3.36k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1)) | 1117 | 1.90k | { | 1118 | 1.90k | stride = 2 * stride; | 1119 | 1.90k | } | 1120 | 3.36k | #endif | 1121 | 3.36k | required_buffer_size = frame_len*output_channels*stride; | 1122 | 3.36k | } | 1123 | | | 1124 | | /* check if we want to use internal sample_buffer */ | 1125 | 3.36k | if (sample_buffer_size == 0) | 1126 | 1.78k | { | 1127 | | /* allocate the buffer for the final samples */ | 1128 | 1.78k | if (hDecoder->sample_buffer_size != required_buffer_size) | 1129 | 1.58k | { | 1130 | 1.58k | if (hDecoder->sample_buffer) | 1131 | 46 | faad_free(hDecoder->sample_buffer); | 1132 | 1.58k | hDecoder->sample_buffer = NULL; | 1133 | 1.58k | hDecoder->sample_buffer = faad_malloc(required_buffer_size); | 1134 | 1.58k | hDecoder->sample_buffer_size = required_buffer_size; | 1135 | 1.58k | } | 1136 | 1.78k | } else if (sample_buffer_size < required_buffer_size) { | 1137 | | /* provided sample buffer is not big enough */ | 1138 | 654 | hInfo->error = 27; | 1139 | 654 | return NULL; | 1140 | 654 | } | 1141 | | | 1142 | 2.71k | if (sample_buffer_size == 0) | 1143 | 1.78k | { | 1144 | 1.78k | sample_buffer = hDecoder->sample_buffer; | 1145 | 1.78k | } else { | 1146 | 933 | sample_buffer = *sample_buffer2; | 1147 | 933 | } | 1148 | | | 1149 | 2.71k | #ifdef SBR_DEC | 1150 | 2.71k | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | 1151 | 1.98k | { | 1152 | 1.98k | uint8_t ele; | 1153 | | | 1154 | | /* this data is different when SBR is used or when the data is upsampled */ | 1155 | 1.98k | if (!hDecoder->downSampledSBR) | 1156 | 1.42k | { | 1157 | 1.42k | frame_len *= 2; | 1158 | 1.42k | hInfo->samples *= 2; | 1159 | 1.42k | hInfo->samplerate *= 2; | 1160 | 1.42k | } | 1161 | | | 1162 | | /* check if every element was provided with SBR data */ | 1163 | 10.3k | for (ele = 0; ele < hDecoder->fr_ch_ele; ele++) | 1164 | 8.36k | { | 1165 | 8.36k | if (hDecoder->sbr[ele] == NULL) | 1166 | 1 | { | 1167 | 1 | hInfo->error = 25; | 1168 | 1 | goto error; | 1169 | 1 | } | 1170 | 8.36k | } | 1171 | | | 1172 | | /* sbr */ | 1173 | 1.98k | if (hDecoder->sbr_present_flag == 1) | 1174 | 1.54k | { | 1175 | 1.54k | hInfo->object_type = HE_AAC; | 1176 | 1.54k | hInfo->sbr = SBR_UPSAMPLED; | 1177 | 1.54k | } else { | 1178 | 444 | hInfo->sbr = NO_SBR_UPSAMPLED; | 1179 | 444 | } | 1180 | 1.98k | if (hDecoder->downSampledSBR) | 1181 | 562 | { | 1182 | 562 | hInfo->sbr = SBR_DOWNSAMPLED; | 1183 | 562 | } | 1184 | 1.98k | } | 1185 | 2.71k | #endif | 1186 | | | 1187 | | | 1188 | 2.71k | sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer, | 1189 | 2.71k | output_channels, frame_len, hDecoder->config.outputFormat); | 1190 | | | 1191 | | | 1192 | 2.71k | #ifdef DRM | 1193 | | //conceal_output(hDecoder, frame_len, output_channels, sample_buffer); | 1194 | 2.71k | #endif | 1195 | | | 1196 | | | 1197 | 2.71k | hDecoder->postSeekResetFlag = 0; | 1198 | | | 1199 | 2.71k | hDecoder->frame++; | 1200 | | #ifdef LD_DEC | 1201 | | if (hDecoder->object_type != LD) | 1202 | | { | 1203 | | #endif | 1204 | 2.71k | if (hDecoder->frame <= 1) | 1205 | 1.07k | hInfo->samples = 0; | 1206 | | #ifdef LD_DEC | 1207 | | } else { | 1208 | | /* LD encoders will give lower delay */ | 1209 | | if (hDecoder->frame <= 0) | 1210 | | hInfo->samples = 0; | 1211 | | } | 1212 | | #endif | 1213 | | | 1214 | | /* cleanup */ | 1215 | | #ifdef ANALYSIS | 1216 | | fflush(stdout); | 1217 | | #endif | 1218 | | | 1219 | | #ifdef PROFILE | 1220 | | count = faad_get_ts() - count; | 1221 | | hDecoder->cycles += count; | 1222 | | #endif | 1223 | | | 1224 | 2.71k | return sample_buffer; | 1225 | | | 1226 | 6.90k | error: | 1227 | | | 1228 | | /* reset filterbank state */ | 1229 | 448k | for (i = 0; i < MAX_CHANNELS; i++) | 1230 | 442k | { | 1231 | 442k | if (hDecoder->fb_intermed[i] != NULL) | 1232 | 164k | { | 1233 | 164k | memset(hDecoder->fb_intermed[i], 0, hDecoder->frameLength*sizeof(real_t)); | 1234 | 164k | } | 1235 | 442k | } | 1236 | 6.90k | #ifdef SBR_DEC | 1237 | 338k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 1238 | 331k | { | 1239 | 331k | if (hDecoder->sbr[i] != NULL) | 1240 | 123k | { | 1241 | 123k | sbrReset(hDecoder->sbr[i]); | 1242 | 123k | } | 1243 | 331k | } | 1244 | 6.90k | #endif | 1245 | | | 1246 | | | 1247 | 6.90k | faad_endbits(&ld); | 1248 | | | 1249 | | /* cleanup */ | 1250 | | #ifdef ANALYSIS | 1251 | | fflush(stdout); | 1252 | | #endif | 1253 | | | 1254 | 6.90k | return NULL; | 1255 | 2.71k | } |
decoder.c:aac_frame_decode Line | Count | Source | 854 | 30.1k | { | 855 | 30.1k | uint16_t i; | 856 | 30.1k | uint8_t channels = 0; | 857 | 30.1k | uint8_t output_channels = 0; | 858 | 30.1k | bitfile ld; | 859 | 30.1k | uint32_t bitsconsumed; | 860 | 30.1k | uint16_t frame_len; | 861 | 30.1k | void *sample_buffer; | 862 | | #if 0 | 863 | | uint32_t startbit=0, endbit=0, payload_bits=0; | 864 | | #endif | 865 | 30.1k | uint32_t required_buffer_size=0; | 866 | | | 867 | | #ifdef PROFILE | 868 | | int64_t count = faad_get_ts(); | 869 | | #endif | 870 | | | 871 | | /* safety checks */ | 872 | 30.1k | if ((hDecoder == NULL) || (hInfo == NULL) || (buffer == NULL)) | 873 | 0 | { | 874 | 0 | return NULL; | 875 | 0 | } | 876 | | | 877 | | #if 0 | 878 | | printf("%d\n", buffer_size*8); | 879 | | #endif | 880 | | | 881 | 30.1k | frame_len = hDecoder->frameLength; | 882 | | | 883 | | | 884 | 30.1k | memset(hInfo, 0, sizeof(NeAACDecFrameInfo)); | 885 | 30.1k | memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0])); | 886 | | | 887 | | #ifdef USE_TIME_LIMIT | 888 | | if ((TIME_LIMIT * get_sample_rate(hDecoder->sf_index)) > hDecoder->TL_count) | 889 | | { | 890 | | hDecoder->TL_count += 1024; | 891 | | } else { | 892 | | hInfo->error = (NUM_ERROR_MESSAGES-1); | 893 | | goto error; | 894 | | } | 895 | | #endif | 896 | | | 897 | | | 898 | | /* check for some common metadata tag types in the bitstream | 899 | | * No need to return an error | 900 | | */ | 901 | | /* ID3 */ | 902 | 30.1k | if (buffer_size >= 128) | 903 | 3.04k | { | 904 | 3.04k | if (memcmp(buffer, "TAG", 3) == 0) | 905 | 6 | { | 906 | | /* found it */ | 907 | 6 | hInfo->bytesconsumed = 128; /* 128 bytes fixed size */ | 908 | | /* no error, but no output either */ | 909 | 6 | return NULL; | 910 | 6 | } | 911 | 3.04k | } | 912 | | | 913 | | | 914 | | /* initialize the bitstream */ | 915 | 30.1k | faad_initbits(&ld, buffer, buffer_size); | 916 | 30.1k | if (ld.error != 0) | 917 | 11.7k | return NULL; | 918 | | | 919 | | #if 0 | 920 | | { | 921 | | int i; | 922 | | for (i = 0; i < ((buffer_size+3)>>2); i++) | 923 | | { | 924 | | uint8_t *buf; | 925 | | uint32_t temp = 0; | 926 | | buf = faad_getbitbuffer(&ld, 32); | 927 | | //temp = getdword((void*)buf); | 928 | | temp = *((uint32_t*)buf); | 929 | | printf("0x%.8X\n", temp); | 930 | | free(buf); | 931 | | } | 932 | | faad_endbits(&ld); | 933 | | faad_initbits(&ld, buffer, buffer_size); | 934 | | } | 935 | | #endif | 936 | | | 937 | | #if 0 | 938 | | if(hDecoder->latm_header_present) | 939 | | { | 940 | | payload_bits = faad_latm_frame(&hDecoder->latm_config, &ld); | 941 | | startbit = faad_get_processed_bits(&ld); | 942 | | if(payload_bits == -1U) | 943 | | { | 944 | | hInfo->error = 1; | 945 | | goto error; | 946 | | } | 947 | | } | 948 | | #endif | 949 | | | 950 | | #ifdef DRM | 951 | | if (hDecoder->object_type == DRM_ER_LC) | 952 | | { | 953 | | /* We do not support stereo right now */ | 954 | | if (0) //(hDecoder->channelConfiguration == 2) | 955 | | { | 956 | | hInfo->error = 28; // Throw CRC error | 957 | | goto error; | 958 | | } | 959 | | | 960 | | faad_getbits(&ld, 8 | 961 | | DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC")); | 962 | | } | 963 | | #endif | 964 | | | 965 | 18.4k | if (hDecoder->adts_header_present) | 966 | 709 | { | 967 | 709 | adts_header adts; | 968 | | | 969 | 709 | adts.old_format = hDecoder->config.useOldADTSFormat; | 970 | 709 | if ((hInfo->error = adts_frame(&adts, &ld)) > 0) | 971 | 98 | goto error; | 972 | | | 973 | | /* MPEG2 does byte_alignment() here, | 974 | | * but ADTS header is always multiple of 8 bits in MPEG2 | 975 | | * so not needed to actually do it. | 976 | | */ | 977 | 709 | } | 978 | | | 979 | | #ifdef ANALYSIS | 980 | | dbg_count = 0; | 981 | | #endif | 982 | | | 983 | | /* decode the complete bitstream */ | 984 | | #ifdef DRM | 985 | | if (/*(hDecoder->object_type == 6) ||*/ hDecoder->object_type == DRM_ER_LC) | 986 | | { | 987 | | DRM_aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); | 988 | | } else { | 989 | | #endif | 990 | 18.3k | raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); | 991 | | #ifdef DRM | 992 | | } | 993 | | #endif | 994 | | | 995 | | #if 0 | 996 | | if(hDecoder->latm_header_present) | 997 | | { | 998 | | endbit = faad_get_processed_bits(&ld); | 999 | | if(endbit-startbit > payload_bits) | 1000 | | fprintf(stderr, "\r\nERROR, too many payload bits read: %u > %d. Please. report with a link to a sample\n", | 1001 | | endbit-startbit, payload_bits); | 1002 | | if(hDecoder->latm_config.otherDataLenBits > 0) | 1003 | | faad_getbits(&ld, hDecoder->latm_config.otherDataLenBits); | 1004 | | faad_byte_align(&ld); | 1005 | | } | 1006 | | #endif | 1007 | | | 1008 | 18.3k | channels = hDecoder->fr_channels; | 1009 | | | 1010 | 18.3k | if (hInfo->error > 0) | 1011 | 12.3k | goto error; | 1012 | | | 1013 | | /* safety check */ | 1014 | 5.94k | if (channels == 0 || channels > MAX_CHANNELS) | 1015 | 70 | { | 1016 | | /* invalid number of channels */ | 1017 | 70 | hInfo->error = 12; | 1018 | 70 | goto error; | 1019 | 70 | } | 1020 | | | 1021 | | /* no more bit reading after this */ | 1022 | 5.87k | bitsconsumed = faad_get_processed_bits(&ld); | 1023 | 5.87k | hInfo->bytesconsumed = bit2byte(bitsconsumed); | 1024 | 5.87k | if (ld.error) | 1025 | 0 | { | 1026 | 0 | hInfo->error = 14; | 1027 | 0 | goto error; | 1028 | 0 | } | 1029 | 5.87k | faad_endbits(&ld); | 1030 | | | 1031 | | | 1032 | 5.87k | if (!hDecoder->adts_header_present && !hDecoder->adif_header_present | 1033 | | #if 0 | 1034 | | && !hDecoder->latm_header_present | 1035 | | #endif | 1036 | 5.87k | ) | 1037 | 5.70k | { | 1038 | 5.70k | if (hDecoder->channelConfiguration == 0) | 1039 | 140 | hDecoder->channelConfiguration = channels; | 1040 | | | 1041 | 5.70k | if (channels == 8) /* 7.1 */ | 1042 | 867 | hDecoder->channelConfiguration = 7; | 1043 | 5.70k | if (channels == 7) /* not a standard channelConfiguration */ | 1044 | 53 | hDecoder->channelConfiguration = 0; | 1045 | 5.70k | } | 1046 | | | 1047 | 5.87k | if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix) | 1048 | 435 | { | 1049 | 435 | hDecoder->downMatrix = 1; | 1050 | 435 | output_channels = 2; | 1051 | 5.43k | } else { | 1052 | 5.43k | output_channels = channels; | 1053 | 5.43k | } | 1054 | | | 1055 | 5.87k | #if (defined(PS_DEC) || defined(DRM_PS)) | 1056 | 5.87k | hDecoder->upMatrix = 0; | 1057 | | /* check if we have a mono file */ | 1058 | 5.87k | if (output_channels == 1) | 1059 | 245 | { | 1060 | | /* upMatrix to 2 channels for implicit signalling of PS */ | 1061 | 245 | hDecoder->upMatrix = 1; | 1062 | 245 | output_channels = 2; | 1063 | 245 | } | 1064 | 5.87k | #endif | 1065 | | | 1066 | | /* Make a channel configuration based on either a PCE or a channelConfiguration */ | 1067 | 5.87k | if (!hDecoder->downMatrix && hDecoder->pce_set) | 1068 | 164 | { | 1069 | | /* In some codepath program_config_element result is ignored. */ | 1070 | 164 | if (hDecoder->pce.channels > MAX_CHANNELS) | 1071 | 6 | { | 1072 | 6 | hInfo->error = 22; | 1073 | 6 | return NULL; | 1074 | 6 | } | 1075 | 164 | } | 1076 | 5.86k | create_channel_config(hDecoder, hInfo); | 1077 | | | 1078 | | /* number of samples in this frame */ | 1079 | 5.86k | hInfo->samples = frame_len*output_channels; | 1080 | | /* number of channels in this frame */ | 1081 | 5.86k | hInfo->channels = output_channels; | 1082 | | /* samplerate */ | 1083 | 5.86k | hInfo->samplerate = get_sample_rate(hDecoder->sf_index); | 1084 | | /* object type */ | 1085 | 5.86k | hInfo->object_type = hDecoder->object_type; | 1086 | | /* sbr */ | 1087 | 5.86k | hInfo->sbr = NO_SBR; | 1088 | | /* header type */ | 1089 | 5.86k | hInfo->header_type = RAW; | 1090 | 5.86k | if (hDecoder->adif_header_present) | 1091 | 0 | hInfo->header_type = ADIF; | 1092 | 5.86k | if (hDecoder->adts_header_present) | 1093 | 172 | hInfo->header_type = ADTS; | 1094 | | #if 0 | 1095 | | if (hDecoder->latm_header_present) | 1096 | | hInfo->header_type = LATM; | 1097 | | #endif | 1098 | 5.86k | #if (defined(PS_DEC) || defined(DRM_PS)) | 1099 | 5.86k | hInfo->ps = hDecoder->ps_used_global; | 1100 | 5.86k | #endif | 1101 | | | 1102 | | /* check if frame has channel elements */ | 1103 | 5.86k | if (channels == 0) | 1104 | 0 | { | 1105 | 0 | hDecoder->frame++; | 1106 | 0 | return NULL; | 1107 | 0 | } | 1108 | | | 1109 | 5.86k | { | 1110 | 5.86k | static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t), | 1111 | 5.86k | sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t), | 1112 | 5.86k | sizeof(int16_t), sizeof(int16_t), 0, 0, 0 | 1113 | 5.86k | }; | 1114 | 5.86k | uint8_t stride = str[hDecoder->config.outputFormat-1]; | 1115 | 5.86k | #ifdef SBR_DEC | 1116 | 5.86k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1)) | 1117 | 3.34k | { | 1118 | 3.34k | stride = 2 * stride; | 1119 | 3.34k | } | 1120 | 5.86k | #endif | 1121 | 5.86k | required_buffer_size = frame_len*output_channels*stride; | 1122 | 5.86k | } | 1123 | | | 1124 | | /* check if we want to use internal sample_buffer */ | 1125 | 5.86k | if (sample_buffer_size == 0) | 1126 | 4.54k | { | 1127 | | /* allocate the buffer for the final samples */ | 1128 | 4.54k | if (hDecoder->sample_buffer_size != required_buffer_size) | 1129 | 3.95k | { | 1130 | 3.95k | if (hDecoder->sample_buffer) | 1131 | 45 | faad_free(hDecoder->sample_buffer); | 1132 | 3.95k | hDecoder->sample_buffer = NULL; | 1133 | 3.95k | hDecoder->sample_buffer = faad_malloc(required_buffer_size); | 1134 | 3.95k | hDecoder->sample_buffer_size = required_buffer_size; | 1135 | 3.95k | } | 1136 | 4.54k | } else if (sample_buffer_size < required_buffer_size) { | 1137 | | /* provided sample buffer is not big enough */ | 1138 | 650 | hInfo->error = 27; | 1139 | 650 | return NULL; | 1140 | 650 | } | 1141 | | | 1142 | 5.21k | if (sample_buffer_size == 0) | 1143 | 4.54k | { | 1144 | 4.54k | sample_buffer = hDecoder->sample_buffer; | 1145 | 4.54k | } else { | 1146 | 677 | sample_buffer = *sample_buffer2; | 1147 | 677 | } | 1148 | | | 1149 | 5.21k | #ifdef SBR_DEC | 1150 | 5.21k | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | 1151 | 3.54k | { | 1152 | 3.54k | uint8_t ele; | 1153 | | | 1154 | | /* this data is different when SBR is used or when the data is upsampled */ | 1155 | 3.54k | if (!hDecoder->downSampledSBR) | 1156 | 2.89k | { | 1157 | 2.89k | frame_len *= 2; | 1158 | 2.89k | hInfo->samples *= 2; | 1159 | 2.89k | hInfo->samplerate *= 2; | 1160 | 2.89k | } | 1161 | | | 1162 | | /* check if every element was provided with SBR data */ | 1163 | 18.2k | for (ele = 0; ele < hDecoder->fr_ch_ele; ele++) | 1164 | 14.7k | { | 1165 | 14.7k | if (hDecoder->sbr[ele] == NULL) | 1166 | 7 | { | 1167 | 7 | hInfo->error = 25; | 1168 | 7 | goto error; | 1169 | 7 | } | 1170 | 14.7k | } | 1171 | | | 1172 | | /* sbr */ | 1173 | 3.53k | if (hDecoder->sbr_present_flag == 1) | 1174 | 2.04k | { | 1175 | 2.04k | hInfo->object_type = HE_AAC; | 1176 | 2.04k | hInfo->sbr = SBR_UPSAMPLED; | 1177 | 2.04k | } else { | 1178 | 1.49k | hInfo->sbr = NO_SBR_UPSAMPLED; | 1179 | 1.49k | } | 1180 | 3.53k | if (hDecoder->downSampledSBR) | 1181 | 636 | { | 1182 | 636 | hInfo->sbr = SBR_DOWNSAMPLED; | 1183 | 636 | } | 1184 | 3.53k | } | 1185 | 5.21k | #endif | 1186 | | | 1187 | | | 1188 | 5.21k | sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer, | 1189 | 5.21k | output_channels, frame_len, hDecoder->config.outputFormat); | 1190 | | | 1191 | | | 1192 | | #ifdef DRM | 1193 | | //conceal_output(hDecoder, frame_len, output_channels, sample_buffer); | 1194 | | #endif | 1195 | | | 1196 | | | 1197 | 5.21k | hDecoder->postSeekResetFlag = 0; | 1198 | | | 1199 | 5.21k | hDecoder->frame++; | 1200 | 5.21k | #ifdef LD_DEC | 1201 | 5.21k | if (hDecoder->object_type != LD) | 1202 | 4.56k | { | 1203 | 4.56k | #endif | 1204 | 4.56k | if (hDecoder->frame <= 1) | 1205 | 1.89k | hInfo->samples = 0; | 1206 | 4.56k | #ifdef LD_DEC | 1207 | 4.56k | } else { | 1208 | | /* LD encoders will give lower delay */ | 1209 | 642 | if (hDecoder->frame <= 0) | 1210 | 0 | hInfo->samples = 0; | 1211 | 642 | } | 1212 | 5.21k | #endif | 1213 | | | 1214 | | /* cleanup */ | 1215 | | #ifdef ANALYSIS | 1216 | | fflush(stdout); | 1217 | | #endif | 1218 | | | 1219 | | #ifdef PROFILE | 1220 | | count = faad_get_ts() - count; | 1221 | | hDecoder->cycles += count; | 1222 | | #endif | 1223 | | | 1224 | 5.21k | return sample_buffer; | 1225 | | | 1226 | 12.5k | error: | 1227 | | | 1228 | | /* reset filterbank state */ | 1229 | 817k | for (i = 0; i < MAX_CHANNELS; i++) | 1230 | 804k | { | 1231 | 804k | if (hDecoder->fb_intermed[i] != NULL) | 1232 | 435k | { | 1233 | 435k | memset(hDecoder->fb_intermed[i], 0, hDecoder->frameLength*sizeof(real_t)); | 1234 | 435k | } | 1235 | 804k | } | 1236 | 12.5k | #ifdef SBR_DEC | 1237 | 616k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 1238 | 603k | { | 1239 | 603k | if (hDecoder->sbr[i] != NULL) | 1240 | 306k | { | 1241 | 306k | sbrReset(hDecoder->sbr[i]); | 1242 | 306k | } | 1243 | 603k | } | 1244 | 12.5k | #endif | 1245 | | | 1246 | | | 1247 | 12.5k | faad_endbits(&ld); | 1248 | | | 1249 | | /* cleanup */ | 1250 | | #ifdef ANALYSIS | 1251 | | fflush(stdout); | 1252 | | #endif | 1253 | | | 1254 | 12.5k | return NULL; | 1255 | 5.21k | } |
|