/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 | 324 | { |
74 | 324 | static char *libfaadName = PACKAGE_VERSION; |
75 | 324 | static char *libCopyright = |
76 | 324 | " Copyright 2002-2004: Ahead Software AG\n" |
77 | 324 | " http://www.audiocoding.com\n" |
78 | 324 | " bug tracking: https://sourceforge.net/p/faac/bugs/\n"; |
79 | | |
80 | 324 | if (faad_id_string) |
81 | 324 | *faad_id_string = libfaadName; |
82 | | |
83 | 324 | if (faad_copyright_string) |
84 | 324 | *faad_copyright_string = libCopyright; |
85 | | |
86 | 324 | return 0; |
87 | 324 | } |
88 | | |
89 | | char* NeAACDecGetErrorMessage(unsigned char errcode) |
90 | 324 | { |
91 | 324 | if (errcode >= NUM_ERROR_MESSAGES) |
92 | 249 | return NULL; |
93 | 75 | return err_msg[errcode]; |
94 | 324 | } |
95 | | |
96 | | unsigned long NeAACDecGetCapabilities(void) |
97 | 1.29k | { |
98 | 1.29k | uint32_t cap = 0; |
99 | | |
100 | | /* can't do without it */ |
101 | 1.29k | cap += LC_DEC_CAP; |
102 | | |
103 | | #ifdef MAIN_DEC |
104 | 324 | cap += MAIN_DEC_CAP; |
105 | | #endif |
106 | | #ifdef LTP_DEC |
107 | 648 | cap += LTP_DEC_CAP; |
108 | | #endif |
109 | | #ifdef LD_DEC |
110 | 648 | cap += LD_DEC_CAP; |
111 | | #endif |
112 | 1.29k | #ifdef ERROR_RESILIENCE |
113 | 1.29k | cap += ERROR_RESILIENCE_CAP; |
114 | 1.29k | #endif |
115 | | #ifdef FIXED_POINT |
116 | 648 | cap += FIXED_POINT_CAP; |
117 | | #endif |
118 | | |
119 | 1.29k | return cap; |
120 | 1.29k | } Line | Count | Source | 97 | 324 | { | 98 | 324 | uint32_t cap = 0; | 99 | | | 100 | | /* can't do without it */ | 101 | 324 | 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 | 324 | #ifdef ERROR_RESILIENCE | 113 | 324 | cap += ERROR_RESILIENCE_CAP; | 114 | 324 | #endif | 115 | 324 | #ifdef FIXED_POINT | 116 | 324 | cap += FIXED_POINT_CAP; | 117 | 324 | #endif | 118 | | | 119 | 324 | return cap; | 120 | 324 | } |
Line | Count | Source | 97 | 324 | { | 98 | 324 | uint32_t cap = 0; | 99 | | | 100 | | /* can't do without it */ | 101 | 324 | cap += LC_DEC_CAP; | 102 | | | 103 | 324 | #ifdef MAIN_DEC | 104 | 324 | cap += MAIN_DEC_CAP; | 105 | 324 | #endif | 106 | 324 | #ifdef LTP_DEC | 107 | 324 | cap += LTP_DEC_CAP; | 108 | 324 | #endif | 109 | 324 | #ifdef LD_DEC | 110 | 324 | cap += LD_DEC_CAP; | 111 | 324 | #endif | 112 | 324 | #ifdef ERROR_RESILIENCE | 113 | 324 | cap += ERROR_RESILIENCE_CAP; | 114 | 324 | #endif | 115 | | #ifdef FIXED_POINT | 116 | | cap += FIXED_POINT_CAP; | 117 | | #endif | 118 | | | 119 | 324 | return cap; | 120 | 324 | } |
Line | Count | Source | 97 | 324 | { | 98 | 324 | uint32_t cap = 0; | 99 | | | 100 | | /* can't do without it */ | 101 | 324 | cap += LC_DEC_CAP; | 102 | | | 103 | | #ifdef MAIN_DEC | 104 | | cap += MAIN_DEC_CAP; | 105 | | #endif | 106 | 324 | #ifdef LTP_DEC | 107 | 324 | cap += LTP_DEC_CAP; | 108 | 324 | #endif | 109 | 324 | #ifdef LD_DEC | 110 | 324 | cap += LD_DEC_CAP; | 111 | 324 | #endif | 112 | 324 | #ifdef ERROR_RESILIENCE | 113 | 324 | cap += ERROR_RESILIENCE_CAP; | 114 | 324 | #endif | 115 | 324 | #ifdef FIXED_POINT | 116 | 324 | cap += FIXED_POINT_CAP; | 117 | 324 | #endif | 118 | | | 119 | 324 | return cap; | 120 | 324 | } |
Line | Count | Source | 97 | 324 | { | 98 | 324 | uint32_t cap = 0; | 99 | | | 100 | | /* can't do without it */ | 101 | 324 | 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 | 324 | #ifdef ERROR_RESILIENCE | 113 | 324 | cap += ERROR_RESILIENCE_CAP; | 114 | 324 | #endif | 115 | | #ifdef FIXED_POINT | 116 | | cap += FIXED_POINT_CAP; | 117 | | #endif | 118 | | | 119 | 324 | return cap; | 120 | 324 | } |
|
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 | 58.4k | { |
125 | 58.4k | uint8_t i; |
126 | 58.4k | NeAACDecStruct *hDecoder = NULL; |
127 | | |
128 | 58.4k | if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL) |
129 | 0 | return NULL; |
130 | | |
131 | 58.4k | memset(hDecoder, 0, sizeof(NeAACDecStruct)); |
132 | | |
133 | 58.4k | hDecoder->cmes = mes; |
134 | 58.4k | hDecoder->config.outputFormat = FAAD_FMT_16BIT; |
135 | 58.4k | hDecoder->config.defObjectType = MAIN; |
136 | 58.4k | hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ |
137 | 58.4k | hDecoder->config.downMatrix = 0; |
138 | 58.4k | hDecoder->adts_header_present = 0; |
139 | 58.4k | hDecoder->adif_header_present = 0; |
140 | 58.4k | hDecoder->latm_header_present = 0; |
141 | 58.4k | #ifdef ERROR_RESILIENCE |
142 | 58.4k | hDecoder->aacSectionDataResilienceFlag = 0; |
143 | 58.4k | hDecoder->aacScalefactorDataResilienceFlag = 0; |
144 | 58.4k | hDecoder->aacSpectralDataResilienceFlag = 0; |
145 | 58.4k | #endif |
146 | 58.4k | hDecoder->frameLength = 1024; |
147 | | |
148 | 58.4k | hDecoder->frame = 0; |
149 | 58.4k | hDecoder->sample_buffer = NULL; |
150 | | |
151 | | // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all. |
152 | 58.4k | hDecoder->__r1 = 0x2bb431ea; |
153 | 58.4k | hDecoder->__r2 = 0x206155b7; |
154 | | |
155 | 3.80M | for (i = 0; i < MAX_CHANNELS; i++) |
156 | 3.74M | { |
157 | 3.74M | hDecoder->element_id[i] = INVALID_ELEMENT_ID; |
158 | 3.74M | hDecoder->window_shape_prev[i] = 0; |
159 | 3.74M | hDecoder->time_out[i] = NULL; |
160 | 3.74M | 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.74M | } |
173 | | |
174 | 58.4k | #ifdef SBR_DEC |
175 | 2.86M | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) |
176 | 2.80M | { |
177 | 2.80M | hDecoder->sbr[i] = NULL; |
178 | 2.80M | } |
179 | 58.4k | #endif |
180 | | |
181 | 58.4k | hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0)); |
182 | | |
183 | 58.4k | return hDecoder; |
184 | 58.4k | } Line | Count | Source | 124 | 11.2k | { | 125 | 11.2k | uint8_t i; | 126 | 11.2k | NeAACDecStruct *hDecoder = NULL; | 127 | | | 128 | 11.2k | if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL) | 129 | 0 | return NULL; | 130 | | | 131 | 11.2k | memset(hDecoder, 0, sizeof(NeAACDecStruct)); | 132 | | | 133 | 11.2k | hDecoder->cmes = mes; | 134 | 11.2k | hDecoder->config.outputFormat = FAAD_FMT_16BIT; | 135 | 11.2k | hDecoder->config.defObjectType = MAIN; | 136 | 11.2k | hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ | 137 | 11.2k | hDecoder->config.downMatrix = 0; | 138 | 11.2k | hDecoder->adts_header_present = 0; | 139 | 11.2k | hDecoder->adif_header_present = 0; | 140 | 11.2k | hDecoder->latm_header_present = 0; | 141 | 11.2k | #ifdef ERROR_RESILIENCE | 142 | 11.2k | hDecoder->aacSectionDataResilienceFlag = 0; | 143 | 11.2k | hDecoder->aacScalefactorDataResilienceFlag = 0; | 144 | 11.2k | hDecoder->aacSpectralDataResilienceFlag = 0; | 145 | 11.2k | #endif | 146 | 11.2k | hDecoder->frameLength = 1024; | 147 | | | 148 | 11.2k | hDecoder->frame = 0; | 149 | 11.2k | hDecoder->sample_buffer = NULL; | 150 | | | 151 | | // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all. | 152 | 11.2k | hDecoder->__r1 = 0x2bb431ea; | 153 | 11.2k | hDecoder->__r2 = 0x206155b7; | 154 | | | 155 | 728k | for (i = 0; i < MAX_CHANNELS; i++) | 156 | 717k | { | 157 | 717k | hDecoder->element_id[i] = INVALID_ELEMENT_ID; | 158 | 717k | hDecoder->window_shape_prev[i] = 0; | 159 | 717k | hDecoder->time_out[i] = NULL; | 160 | 717k | 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 | 717k | } | 173 | | | 174 | 11.2k | #ifdef SBR_DEC | 175 | 549k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 176 | 538k | { | 177 | 538k | hDecoder->sbr[i] = NULL; | 178 | 538k | } | 179 | 11.2k | #endif | 180 | | | 181 | 11.2k | hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0)); | 182 | | | 183 | 11.2k | return hDecoder; | 184 | 11.2k | } |
Line | Count | Source | 124 | 18.0k | { | 125 | 18.0k | uint8_t i; | 126 | 18.0k | NeAACDecStruct *hDecoder = NULL; | 127 | | | 128 | 18.0k | if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL) | 129 | 0 | return NULL; | 130 | | | 131 | 18.0k | memset(hDecoder, 0, sizeof(NeAACDecStruct)); | 132 | | | 133 | 18.0k | hDecoder->cmes = mes; | 134 | 18.0k | hDecoder->config.outputFormat = FAAD_FMT_16BIT; | 135 | 18.0k | hDecoder->config.defObjectType = MAIN; | 136 | 18.0k | hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ | 137 | 18.0k | hDecoder->config.downMatrix = 0; | 138 | 18.0k | hDecoder->adts_header_present = 0; | 139 | 18.0k | hDecoder->adif_header_present = 0; | 140 | 18.0k | hDecoder->latm_header_present = 0; | 141 | 18.0k | #ifdef ERROR_RESILIENCE | 142 | 18.0k | hDecoder->aacSectionDataResilienceFlag = 0; | 143 | 18.0k | hDecoder->aacScalefactorDataResilienceFlag = 0; | 144 | 18.0k | hDecoder->aacSpectralDataResilienceFlag = 0; | 145 | 18.0k | #endif | 146 | 18.0k | hDecoder->frameLength = 1024; | 147 | | | 148 | 18.0k | hDecoder->frame = 0; | 149 | 18.0k | hDecoder->sample_buffer = NULL; | 150 | | | 151 | | // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all. | 152 | 18.0k | hDecoder->__r1 = 0x2bb431ea; | 153 | 18.0k | hDecoder->__r2 = 0x206155b7; | 154 | | | 155 | 1.17M | for (i = 0; i < MAX_CHANNELS; i++) | 156 | 1.15M | { | 157 | 1.15M | hDecoder->element_id[i] = INVALID_ELEMENT_ID; | 158 | 1.15M | hDecoder->window_shape_prev[i] = 0; | 159 | 1.15M | hDecoder->time_out[i] = NULL; | 160 | 1.15M | 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.15M | #ifdef MAIN_DEC | 166 | 1.15M | hDecoder->pred_stat[i] = NULL; | 167 | 1.15M | #endif | 168 | 1.15M | #ifdef LTP_DEC | 169 | 1.15M | hDecoder->ltp_lag[i] = 0; | 170 | 1.15M | hDecoder->lt_pred_stat[i] = NULL; | 171 | 1.15M | #endif | 172 | 1.15M | } | 173 | | | 174 | 18.0k | #ifdef SBR_DEC | 175 | 883k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 176 | 865k | { | 177 | 865k | hDecoder->sbr[i] = NULL; | 178 | 865k | } | 179 | 18.0k | #endif | 180 | | | 181 | 18.0k | hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0)); | 182 | | | 183 | 18.0k | return hDecoder; | 184 | 18.0k | } |
Line | Count | Source | 124 | 11.2k | { | 125 | 11.2k | uint8_t i; | 126 | 11.2k | NeAACDecStruct *hDecoder = NULL; | 127 | | | 128 | 11.2k | if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL) | 129 | 0 | return NULL; | 130 | | | 131 | 11.2k | memset(hDecoder, 0, sizeof(NeAACDecStruct)); | 132 | | | 133 | 11.2k | hDecoder->cmes = mes; | 134 | 11.2k | hDecoder->config.outputFormat = FAAD_FMT_16BIT; | 135 | 11.2k | hDecoder->config.defObjectType = MAIN; | 136 | 11.2k | hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ | 137 | 11.2k | hDecoder->config.downMatrix = 0; | 138 | 11.2k | hDecoder->adts_header_present = 0; | 139 | 11.2k | hDecoder->adif_header_present = 0; | 140 | 11.2k | hDecoder->latm_header_present = 0; | 141 | 11.2k | #ifdef ERROR_RESILIENCE | 142 | 11.2k | hDecoder->aacSectionDataResilienceFlag = 0; | 143 | 11.2k | hDecoder->aacScalefactorDataResilienceFlag = 0; | 144 | 11.2k | hDecoder->aacSpectralDataResilienceFlag = 0; | 145 | 11.2k | #endif | 146 | 11.2k | hDecoder->frameLength = 1024; | 147 | | | 148 | 11.2k | hDecoder->frame = 0; | 149 | 11.2k | hDecoder->sample_buffer = NULL; | 150 | | | 151 | | // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all. | 152 | 11.2k | hDecoder->__r1 = 0x2bb431ea; | 153 | 11.2k | hDecoder->__r2 = 0x206155b7; | 154 | | | 155 | 728k | for (i = 0; i < MAX_CHANNELS; i++) | 156 | 717k | { | 157 | 717k | hDecoder->element_id[i] = INVALID_ELEMENT_ID; | 158 | 717k | hDecoder->window_shape_prev[i] = 0; | 159 | 717k | hDecoder->time_out[i] = NULL; | 160 | 717k | 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 | 717k | #ifdef LTP_DEC | 169 | 717k | hDecoder->ltp_lag[i] = 0; | 170 | 717k | hDecoder->lt_pred_stat[i] = NULL; | 171 | 717k | #endif | 172 | 717k | } | 173 | | | 174 | 11.2k | #ifdef SBR_DEC | 175 | 549k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 176 | 538k | { | 177 | 538k | hDecoder->sbr[i] = NULL; | 178 | 538k | } | 179 | 11.2k | #endif | 180 | | | 181 | 11.2k | hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0)); | 182 | | | 183 | 11.2k | return hDecoder; | 184 | 11.2k | } |
Line | Count | Source | 124 | 18.0k | { | 125 | 18.0k | uint8_t i; | 126 | 18.0k | NeAACDecStruct *hDecoder = NULL; | 127 | | | 128 | 18.0k | if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL) | 129 | 0 | return NULL; | 130 | | | 131 | 18.0k | memset(hDecoder, 0, sizeof(NeAACDecStruct)); | 132 | | | 133 | 18.0k | hDecoder->cmes = mes; | 134 | 18.0k | hDecoder->config.outputFormat = FAAD_FMT_16BIT; | 135 | 18.0k | hDecoder->config.defObjectType = MAIN; | 136 | 18.0k | hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */ | 137 | 18.0k | hDecoder->config.downMatrix = 0; | 138 | 18.0k | hDecoder->adts_header_present = 0; | 139 | 18.0k | hDecoder->adif_header_present = 0; | 140 | 18.0k | hDecoder->latm_header_present = 0; | 141 | 18.0k | #ifdef ERROR_RESILIENCE | 142 | 18.0k | hDecoder->aacSectionDataResilienceFlag = 0; | 143 | 18.0k | hDecoder->aacScalefactorDataResilienceFlag = 0; | 144 | 18.0k | hDecoder->aacSpectralDataResilienceFlag = 0; | 145 | 18.0k | #endif | 146 | 18.0k | hDecoder->frameLength = 1024; | 147 | | | 148 | 18.0k | hDecoder->frame = 0; | 149 | 18.0k | hDecoder->sample_buffer = NULL; | 150 | | | 151 | | // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all. | 152 | 18.0k | hDecoder->__r1 = 0x2bb431ea; | 153 | 18.0k | hDecoder->__r2 = 0x206155b7; | 154 | | | 155 | 1.17M | for (i = 0; i < MAX_CHANNELS; i++) | 156 | 1.15M | { | 157 | 1.15M | hDecoder->element_id[i] = INVALID_ELEMENT_ID; | 158 | 1.15M | hDecoder->window_shape_prev[i] = 0; | 159 | 1.15M | hDecoder->time_out[i] = NULL; | 160 | 1.15M | 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.15M | } | 173 | | | 174 | 18.0k | #ifdef SBR_DEC | 175 | 883k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 176 | 865k | { | 177 | 865k | hDecoder->sbr[i] = NULL; | 178 | 865k | } | 179 | 18.0k | #endif | 180 | | | 181 | 18.0k | hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0)); | 182 | | | 183 | 18.0k | return hDecoder; | 184 | 18.0k | } |
|
185 | | |
186 | | NeAACDecConfigurationPtr NeAACDecGetCurrentConfiguration(NeAACDecHandle hpDecoder) |
187 | 28.1k | { |
188 | 28.1k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
189 | 28.1k | if (hDecoder) |
190 | 28.1k | { |
191 | 28.1k | NeAACDecConfigurationPtr config = &(hDecoder->config); |
192 | | |
193 | 28.1k | return config; |
194 | 28.1k | } |
195 | | |
196 | 0 | return NULL; |
197 | 28.1k | } |
198 | | |
199 | | unsigned char NeAACDecSetConfiguration(NeAACDecHandle hpDecoder, |
200 | | NeAACDecConfigurationPtr config) |
201 | 28.4k | { |
202 | 28.4k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
203 | 28.4k | if (hDecoder && config) |
204 | 28.4k | { |
205 | | /* check if we can decode this object type */ |
206 | 28.4k | if (can_decode_ot(config->defObjectType) < 0) |
207 | 26 | return 0; |
208 | 28.4k | hDecoder->config.defObjectType = config->defObjectType; |
209 | | |
210 | | /* samplerate: anything but 0 should be possible */ |
211 | 28.4k | if (config->defSampleRate == 0) |
212 | 4 | return 0; |
213 | 28.4k | hDecoder->config.defSampleRate = config->defSampleRate; |
214 | | |
215 | | /* check output format */ |
216 | 28.4k | #ifdef FIXED_POINT |
217 | 28.4k | if ((config->outputFormat < 1) || (config->outputFormat > 4)) |
218 | 197 | return 0; |
219 | | #else |
220 | | if ((config->outputFormat < 1) || (config->outputFormat > 5)) |
221 | | return 0; |
222 | | #endif |
223 | 28.2k | hDecoder->config.outputFormat = config->outputFormat; |
224 | | |
225 | 28.2k | if (config->downMatrix > 1) |
226 | 29 | return 0; |
227 | 28.1k | hDecoder->config.downMatrix = config->downMatrix; |
228 | | |
229 | | /* OK */ |
230 | 28.1k | return 1; |
231 | 28.2k | } |
232 | | |
233 | 0 | return 0; |
234 | 28.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 | 19.8k | { |
269 | 19.8k | uint32_t bits = 0; |
270 | 19.8k | bitfile ld; |
271 | 19.8k | adif_header adif; |
272 | 19.8k | adts_header adts; |
273 | 19.8k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
274 | | |
275 | | |
276 | 19.8k | if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL) || (buffer_size == 0)) |
277 | 45 | return -1; |
278 | | |
279 | 19.8k | adts.old_format = hDecoder->config.useOldADTSFormat; |
280 | 19.8k | hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate); |
281 | 19.8k | hDecoder->object_type = hDecoder->config.defObjectType; |
282 | 19.8k | *samplerate = get_sample_rate(hDecoder->sf_index); |
283 | 19.8k | *channels = 1; |
284 | | |
285 | 19.8k | if (buffer != NULL) |
286 | 19.8k | { |
287 | | #if 0 |
288 | | int is_latm; |
289 | | latm_header *l = &hDecoder->latm_config; |
290 | | #endif |
291 | | |
292 | 19.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 | 19.8k | if ((buffer_size >= 8) && (buffer[0] == 'A') && (buffer[1] == 'D') && |
312 | 19.8k | (buffer[2] == 'I') && (buffer[3] == 'F')) |
313 | 408 | { |
314 | 408 | hDecoder->adif_header_present = 1; |
315 | | |
316 | 408 | get_adif_header(&adif, &ld); |
317 | 408 | faad_byte_align(&ld); |
318 | | |
319 | 408 | hDecoder->sf_index = adif.pce[0].sf_index; |
320 | 408 | hDecoder->object_type = adif.pce[0].object_type + 1; |
321 | | |
322 | 408 | *samplerate = get_sample_rate(hDecoder->sf_index); |
323 | 408 | *channels = adif.pce[0].channels; |
324 | | |
325 | 408 | memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config)); |
326 | 408 | hDecoder->pce_set = 1; |
327 | | |
328 | 408 | bits = bit2byte(faad_get_processed_bits(&ld)); |
329 | | |
330 | | /* Check if an ADTS header is present */ |
331 | 19.4k | } else if (adts_frame(&adts, &ld) == 0) { |
332 | 582 | hDecoder->adts_header_present = 1; |
333 | | |
334 | 582 | hDecoder->sf_index = adts.sf_index; |
335 | 582 | hDecoder->object_type = adts.profile + 1; |
336 | | |
337 | 582 | *samplerate = get_sample_rate(hDecoder->sf_index); |
338 | 582 | *channels = (adts.channel_configuration > 6) ? |
339 | 525 | 2 : adts.channel_configuration; |
340 | 582 | } |
341 | | |
342 | 19.8k | if (ld.error) |
343 | 0 | { |
344 | 0 | faad_endbits(&ld); |
345 | 0 | return -1; |
346 | 0 | } |
347 | 19.8k | faad_endbits(&ld); |
348 | 19.8k | } |
349 | | |
350 | 19.8k | if (!*samplerate) |
351 | 160 | return -1; |
352 | | |
353 | 19.6k | #if (defined(PS_DEC) || defined(DRM_PS)) |
354 | | /* check if we have a mono file */ |
355 | 19.6k | if (*channels == 1) |
356 | 18.8k | { |
357 | | /* upMatrix to 2 channels for implicit signalling of PS */ |
358 | 18.8k | *channels = 2; |
359 | 18.8k | } |
360 | 19.6k | #endif |
361 | | |
362 | 19.6k | hDecoder->channelConfiguration = *channels; |
363 | | |
364 | 19.6k | #ifdef SBR_DEC |
365 | | /* implicit signalling */ |
366 | 19.6k | if (*samplerate <= 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) |
367 | 9.13k | { |
368 | 9.13k | *samplerate *= 2; |
369 | 9.13k | hDecoder->forceUpSampling = 1; |
370 | 10.5k | } else if (*samplerate > 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) { |
371 | 10.5k | hDecoder->downSampledSBR = 1; |
372 | 10.5k | } |
373 | 19.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 | 19.6k | hDecoder->fb = filter_bank_init(hDecoder->frameLength); |
382 | | |
383 | | #ifdef LD_DEC |
384 | 12.7k | if (hDecoder->object_type == LD) |
385 | 538 | hDecoder->frameLength >>= 1; |
386 | | #endif |
387 | | |
388 | 19.6k | if (can_decode_ot(hDecoder->object_type) < 0) |
389 | 229 | return -1; |
390 | | |
391 | 19.4k | return bits; |
392 | 19.6k | } Line | Count | Source | 268 | 7.00k | { | 269 | 7.00k | uint32_t bits = 0; | 270 | 7.00k | bitfile ld; | 271 | 7.00k | adif_header adif; | 272 | 7.00k | adts_header adts; | 273 | 7.00k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; | 274 | | | 275 | | | 276 | 7.00k | if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL) || (buffer_size == 0)) | 277 | 26 | return -1; | 278 | | | 279 | 6.98k | adts.old_format = hDecoder->config.useOldADTSFormat; | 280 | 6.98k | hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate); | 281 | 6.98k | hDecoder->object_type = hDecoder->config.defObjectType; | 282 | 6.98k | *samplerate = get_sample_rate(hDecoder->sf_index); | 283 | 6.98k | *channels = 1; | 284 | | | 285 | 6.98k | if (buffer != NULL) | 286 | 6.98k | { | 287 | | #if 0 | 288 | | int is_latm; | 289 | | latm_header *l = &hDecoder->latm_config; | 290 | | #endif | 291 | | | 292 | 6.98k | 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.98k | if ((buffer_size >= 8) && (buffer[0] == 'A') && (buffer[1] == 'D') && | 312 | 6.98k | (buffer[2] == 'I') && (buffer[3] == 'F')) | 313 | 168 | { | 314 | 168 | hDecoder->adif_header_present = 1; | 315 | | | 316 | 168 | get_adif_header(&adif, &ld); | 317 | 168 | faad_byte_align(&ld); | 318 | | | 319 | 168 | hDecoder->sf_index = adif.pce[0].sf_index; | 320 | 168 | hDecoder->object_type = adif.pce[0].object_type + 1; | 321 | | | 322 | 168 | *samplerate = get_sample_rate(hDecoder->sf_index); | 323 | 168 | *channels = adif.pce[0].channels; | 324 | | | 325 | 168 | memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config)); | 326 | 168 | hDecoder->pce_set = 1; | 327 | | | 328 | 168 | bits = bit2byte(faad_get_processed_bits(&ld)); | 329 | | | 330 | | /* Check if an ADTS header is present */ | 331 | 6.81k | } else if (adts_frame(&adts, &ld) == 0) { | 332 | 108 | hDecoder->adts_header_present = 1; | 333 | | | 334 | 108 | hDecoder->sf_index = adts.sf_index; | 335 | 108 | hDecoder->object_type = adts.profile + 1; | 336 | | | 337 | 108 | *samplerate = get_sample_rate(hDecoder->sf_index); | 338 | 108 | *channels = (adts.channel_configuration > 6) ? | 339 | 95 | 2 : adts.channel_configuration; | 340 | 108 | } | 341 | | | 342 | 6.98k | if (ld.error) | 343 | 0 | { | 344 | 0 | faad_endbits(&ld); | 345 | 0 | return -1; | 346 | 0 | } | 347 | 6.98k | faad_endbits(&ld); | 348 | 6.98k | } | 349 | | | 350 | 6.98k | if (!*samplerate) | 351 | 65 | return -1; | 352 | | | 353 | 6.91k | #if (defined(PS_DEC) || defined(DRM_PS)) | 354 | | /* check if we have a mono file */ | 355 | 6.91k | if (*channels == 1) | 356 | 6.71k | { | 357 | | /* upMatrix to 2 channels for implicit signalling of PS */ | 358 | 6.71k | *channels = 2; | 359 | 6.71k | } | 360 | 6.91k | #endif | 361 | | | 362 | 6.91k | hDecoder->channelConfiguration = *channels; | 363 | | | 364 | 6.91k | #ifdef SBR_DEC | 365 | | /* implicit signalling */ | 366 | 6.91k | if (*samplerate <= 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) | 367 | 3.30k | { | 368 | 3.30k | *samplerate *= 2; | 369 | 3.30k | hDecoder->forceUpSampling = 1; | 370 | 3.61k | } else if (*samplerate > 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) { | 371 | 3.61k | hDecoder->downSampledSBR = 1; | 372 | 3.61k | } | 373 | 6.91k | #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.91k | 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.91k | if (can_decode_ot(hDecoder->object_type) < 0) | 389 | 117 | return -1; | 390 | | | 391 | 6.79k | return bits; | 392 | 6.91k | } |
Line | Count | Source | 268 | 12.8k | { | 269 | 12.8k | uint32_t bits = 0; | 270 | 12.8k | bitfile ld; | 271 | 12.8k | adif_header adif; | 272 | 12.8k | adts_header adts; | 273 | 12.8k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; | 274 | | | 275 | | | 276 | 12.8k | if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL) || (buffer_size == 0)) | 277 | 19 | return -1; | 278 | | | 279 | 12.8k | adts.old_format = hDecoder->config.useOldADTSFormat; | 280 | 12.8k | hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate); | 281 | 12.8k | hDecoder->object_type = hDecoder->config.defObjectType; | 282 | 12.8k | *samplerate = get_sample_rate(hDecoder->sf_index); | 283 | 12.8k | *channels = 1; | 284 | | | 285 | 12.8k | if (buffer != NULL) | 286 | 12.8k | { | 287 | | #if 0 | 288 | | int is_latm; | 289 | | latm_header *l = &hDecoder->latm_config; | 290 | | #endif | 291 | | | 292 | 12.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 | 12.8k | if ((buffer_size >= 8) && (buffer[0] == 'A') && (buffer[1] == 'D') && | 312 | 12.8k | (buffer[2] == 'I') && (buffer[3] == 'F')) | 313 | 240 | { | 314 | 240 | hDecoder->adif_header_present = 1; | 315 | | | 316 | 240 | get_adif_header(&adif, &ld); | 317 | 240 | faad_byte_align(&ld); | 318 | | | 319 | 240 | hDecoder->sf_index = adif.pce[0].sf_index; | 320 | 240 | hDecoder->object_type = adif.pce[0].object_type + 1; | 321 | | | 322 | 240 | *samplerate = get_sample_rate(hDecoder->sf_index); | 323 | 240 | *channels = adif.pce[0].channels; | 324 | | | 325 | 240 | memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config)); | 326 | 240 | hDecoder->pce_set = 1; | 327 | | | 328 | 240 | bits = bit2byte(faad_get_processed_bits(&ld)); | 329 | | | 330 | | /* Check if an ADTS header is present */ | 331 | 12.5k | } else if (adts_frame(&adts, &ld) == 0) { | 332 | 474 | hDecoder->adts_header_present = 1; | 333 | | | 334 | 474 | hDecoder->sf_index = adts.sf_index; | 335 | 474 | hDecoder->object_type = adts.profile + 1; | 336 | | | 337 | 474 | *samplerate = get_sample_rate(hDecoder->sf_index); | 338 | 474 | *channels = (adts.channel_configuration > 6) ? | 339 | 430 | 2 : adts.channel_configuration; | 340 | 474 | } | 341 | | | 342 | 12.8k | if (ld.error) | 343 | 0 | { | 344 | 0 | faad_endbits(&ld); | 345 | 0 | return -1; | 346 | 0 | } | 347 | 12.8k | faad_endbits(&ld); | 348 | 12.8k | } | 349 | | | 350 | 12.8k | if (!*samplerate) | 351 | 95 | return -1; | 352 | | | 353 | 12.7k | #if (defined(PS_DEC) || defined(DRM_PS)) | 354 | | /* check if we have a mono file */ | 355 | 12.7k | if (*channels == 1) | 356 | 12.1k | { | 357 | | /* upMatrix to 2 channels for implicit signalling of PS */ | 358 | 12.1k | *channels = 2; | 359 | 12.1k | } | 360 | 12.7k | #endif | 361 | | | 362 | 12.7k | hDecoder->channelConfiguration = *channels; | 363 | | | 364 | 12.7k | #ifdef SBR_DEC | 365 | | /* implicit signalling */ | 366 | 12.7k | if (*samplerate <= 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) | 367 | 5.83k | { | 368 | 5.83k | *samplerate *= 2; | 369 | 5.83k | hDecoder->forceUpSampling = 1; | 370 | 6.90k | } else if (*samplerate > 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) { | 371 | 6.90k | hDecoder->downSampledSBR = 1; | 372 | 6.90k | } | 373 | 12.7k | #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 | 12.7k | hDecoder->fb = filter_bank_init(hDecoder->frameLength); | 382 | | | 383 | 12.7k | #ifdef LD_DEC | 384 | 12.7k | if (hDecoder->object_type == LD) | 385 | 538 | hDecoder->frameLength >>= 1; | 386 | 12.7k | #endif | 387 | | | 388 | 12.7k | if (can_decode_ot(hDecoder->object_type) < 0) | 389 | 112 | return -1; | 390 | | | 391 | 12.6k | return bits; | 392 | 12.7k | } |
|
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 | 8.32k | { |
401 | 8.32k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
402 | 8.32k | int8_t rc; |
403 | 8.32k | mp4AudioSpecificConfig mp4ASC; |
404 | | |
405 | 8.32k | if((hDecoder == NULL) |
406 | 8.32k | || (pBuffer == NULL) |
407 | 8.32k | || (SizeOfDecoderSpecificInfo < 2) |
408 | 8.32k | || (samplerate == NULL) |
409 | 8.32k | || (channels == NULL)) |
410 | 21 | { |
411 | 21 | return -1; |
412 | 21 | } |
413 | | |
414 | 8.30k | hDecoder->adif_header_present = 0; |
415 | 8.30k | hDecoder->adts_header_present = 0; |
416 | | |
417 | | /* decode the audio specific config */ |
418 | 8.30k | rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC, |
419 | 8.30k | &(hDecoder->pce), hDecoder->latm_header_present); |
420 | | |
421 | | /* copy the relevant info to the decoder handle */ |
422 | 8.30k | *samplerate = mp4ASC.samplingFrequency; |
423 | 8.30k | if (mp4ASC.channelsConfiguration) |
424 | 6.96k | { |
425 | 6.96k | *channels = mp4ASC.channelsConfiguration; |
426 | 6.96k | } else { |
427 | 1.34k | *channels = hDecoder->pce.channels; |
428 | 1.34k | hDecoder->pce_set = 1; |
429 | 1.34k | } |
430 | 8.30k | #if (defined(PS_DEC) || defined(DRM_PS)) |
431 | | /* check if we have a mono file */ |
432 | 8.30k | if (*channels == 1) |
433 | 62 | { |
434 | | /* upMatrix to 2 channels for implicit signalling of PS */ |
435 | 62 | *channels = 2; |
436 | 62 | } |
437 | 8.30k | #endif |
438 | 8.30k | hDecoder->sf_index = mp4ASC.samplingFrequencyIndex; |
439 | 8.30k | hDecoder->object_type = mp4ASC.objectTypeIndex; |
440 | 8.30k | #ifdef ERROR_RESILIENCE |
441 | 8.30k | hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag; |
442 | 8.30k | hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag; |
443 | 8.30k | hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag; |
444 | 8.30k | #endif |
445 | 8.30k | #ifdef SBR_DEC |
446 | 8.30k | hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag; |
447 | 8.30k | hDecoder->downSampledSBR = mp4ASC.downSampledSBR; |
448 | 8.30k | if (hDecoder->config.dontUpSampleImplicitSBR == 0) |
449 | 8.30k | hDecoder->forceUpSampling = mp4ASC.forceUpSampling; |
450 | 0 | else |
451 | 0 | hDecoder->forceUpSampling = 0; |
452 | | |
453 | | /* AAC core decoder samplerate is 2 times as low */ |
454 | 8.30k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1) |
455 | 5.37k | { |
456 | 5.37k | hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2); |
457 | 5.37k | } |
458 | 8.30k | #endif |
459 | | |
460 | 8.30k | if (rc != 0) |
461 | 100 | { |
462 | 100 | return rc; |
463 | 100 | } |
464 | 8.20k | hDecoder->channelConfiguration = mp4ASC.channelsConfiguration; |
465 | 8.20k | if (mp4ASC.frameLengthFlag) |
466 | 5.12k | #ifdef ALLOW_SMALL_FRAMELENGTH |
467 | 5.12k | 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 | 8.20k | hDecoder->fb = filter_bank_init(hDecoder->frameLength); |
479 | | |
480 | | #ifdef LD_DEC |
481 | 5.46k | if (hDecoder->object_type == LD) |
482 | 630 | hDecoder->frameLength >>= 1; |
483 | | #endif |
484 | | |
485 | 8.20k | return 0; |
486 | 8.30k | } Line | Count | Source | 400 | 2.79k | { | 401 | 2.79k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; | 402 | 2.79k | int8_t rc; | 403 | 2.79k | mp4AudioSpecificConfig mp4ASC; | 404 | | | 405 | 2.79k | if((hDecoder == NULL) | 406 | 2.79k | || (pBuffer == NULL) | 407 | 2.79k | || (SizeOfDecoderSpecificInfo < 2) | 408 | 2.79k | || (samplerate == NULL) | 409 | 2.79k | || (channels == NULL)) | 410 | 12 | { | 411 | 12 | return -1; | 412 | 12 | } | 413 | | | 414 | 2.78k | hDecoder->adif_header_present = 0; | 415 | 2.78k | hDecoder->adts_header_present = 0; | 416 | | | 417 | | /* decode the audio specific config */ | 418 | 2.78k | rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC, | 419 | 2.78k | &(hDecoder->pce), hDecoder->latm_header_present); | 420 | | | 421 | | /* copy the relevant info to the decoder handle */ | 422 | 2.78k | *samplerate = mp4ASC.samplingFrequency; | 423 | 2.78k | if (mp4ASC.channelsConfiguration) | 424 | 2.23k | { | 425 | 2.23k | *channels = mp4ASC.channelsConfiguration; | 426 | 2.23k | } else { | 427 | 550 | *channels = hDecoder->pce.channels; | 428 | 550 | hDecoder->pce_set = 1; | 429 | 550 | } | 430 | 2.78k | #if (defined(PS_DEC) || defined(DRM_PS)) | 431 | | /* check if we have a mono file */ | 432 | 2.78k | if (*channels == 1) | 433 | 43 | { | 434 | | /* upMatrix to 2 channels for implicit signalling of PS */ | 435 | 43 | *channels = 2; | 436 | 43 | } | 437 | 2.78k | #endif | 438 | 2.78k | hDecoder->sf_index = mp4ASC.samplingFrequencyIndex; | 439 | 2.78k | hDecoder->object_type = mp4ASC.objectTypeIndex; | 440 | 2.78k | #ifdef ERROR_RESILIENCE | 441 | 2.78k | hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag; | 442 | 2.78k | hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag; | 443 | 2.78k | hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag; | 444 | 2.78k | #endif | 445 | 2.78k | #ifdef SBR_DEC | 446 | 2.78k | hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag; | 447 | 2.78k | hDecoder->downSampledSBR = mp4ASC.downSampledSBR; | 448 | 2.78k | if (hDecoder->config.dontUpSampleImplicitSBR == 0) | 449 | 2.78k | 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.78k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1) | 455 | 1.70k | { | 456 | 1.70k | hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2); | 457 | 1.70k | } | 458 | 2.78k | #endif | 459 | | | 460 | 2.78k | if (rc != 0) | 461 | 42 | { | 462 | 42 | return rc; | 463 | 42 | } | 464 | 2.73k | hDecoder->channelConfiguration = mp4ASC.channelsConfiguration; | 465 | 2.73k | if (mp4ASC.frameLengthFlag) | 466 | 1.81k | #ifdef ALLOW_SMALL_FRAMELENGTH | 467 | 1.81k | 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.73k | 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.73k | return 0; | 486 | 2.78k | } |
Line | Count | Source | 400 | 5.53k | { | 401 | 5.53k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; | 402 | 5.53k | int8_t rc; | 403 | 5.53k | mp4AudioSpecificConfig mp4ASC; | 404 | | | 405 | 5.53k | if((hDecoder == NULL) | 406 | 5.53k | || (pBuffer == NULL) | 407 | 5.53k | || (SizeOfDecoderSpecificInfo < 2) | 408 | 5.53k | || (samplerate == NULL) | 409 | 5.53k | || (channels == NULL)) | 410 | 9 | { | 411 | 9 | return -1; | 412 | 9 | } | 413 | | | 414 | 5.52k | hDecoder->adif_header_present = 0; | 415 | 5.52k | hDecoder->adts_header_present = 0; | 416 | | | 417 | | /* decode the audio specific config */ | 418 | 5.52k | rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC, | 419 | 5.52k | &(hDecoder->pce), hDecoder->latm_header_present); | 420 | | | 421 | | /* copy the relevant info to the decoder handle */ | 422 | 5.52k | *samplerate = mp4ASC.samplingFrequency; | 423 | 5.52k | if (mp4ASC.channelsConfiguration) | 424 | 4.72k | { | 425 | 4.72k | *channels = mp4ASC.channelsConfiguration; | 426 | 4.72k | } else { | 427 | 792 | *channels = hDecoder->pce.channels; | 428 | 792 | hDecoder->pce_set = 1; | 429 | 792 | } | 430 | 5.52k | #if (defined(PS_DEC) || defined(DRM_PS)) | 431 | | /* check if we have a mono file */ | 432 | 5.52k | if (*channels == 1) | 433 | 19 | { | 434 | | /* upMatrix to 2 channels for implicit signalling of PS */ | 435 | 19 | *channels = 2; | 436 | 19 | } | 437 | 5.52k | #endif | 438 | 5.52k | hDecoder->sf_index = mp4ASC.samplingFrequencyIndex; | 439 | 5.52k | hDecoder->object_type = mp4ASC.objectTypeIndex; | 440 | 5.52k | #ifdef ERROR_RESILIENCE | 441 | 5.52k | hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag; | 442 | 5.52k | hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag; | 443 | 5.52k | hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag; | 444 | 5.52k | #endif | 445 | 5.52k | #ifdef SBR_DEC | 446 | 5.52k | hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag; | 447 | 5.52k | hDecoder->downSampledSBR = mp4ASC.downSampledSBR; | 448 | 5.52k | if (hDecoder->config.dontUpSampleImplicitSBR == 0) | 449 | 5.52k | hDecoder->forceUpSampling = mp4ASC.forceUpSampling; | 450 | 0 | else | 451 | 0 | hDecoder->forceUpSampling = 0; | 452 | | | 453 | | /* AAC core decoder samplerate is 2 times as low */ | 454 | 5.52k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1) | 455 | 3.67k | { | 456 | 3.67k | hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2); | 457 | 3.67k | } | 458 | 5.52k | #endif | 459 | | | 460 | 5.52k | if (rc != 0) | 461 | 58 | { | 462 | 58 | return rc; | 463 | 58 | } | 464 | 5.46k | hDecoder->channelConfiguration = mp4ASC.channelsConfiguration; | 465 | 5.46k | if (mp4ASC.frameLengthFlag) | 466 | 3.30k | #ifdef ALLOW_SMALL_FRAMELENGTH | 467 | 3.30k | 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 | 5.46k | hDecoder->fb = filter_bank_init(hDecoder->frameLength); | 479 | | | 480 | 5.46k | #ifdef LD_DEC | 481 | 5.46k | if (hDecoder->object_type == LD) | 482 | 630 | hDecoder->frameLength >>= 1; | 483 | 5.46k | #endif | 484 | | | 485 | 5.46k | return 0; | 486 | 5.52k | } |
|
487 | | |
488 | | #ifdef DRM |
489 | | char NeAACDecInitDRM(NeAACDecHandle *hpDecoder, |
490 | | unsigned long samplerate, |
491 | | unsigned char channels) |
492 | 810 | { |
493 | 810 | NeAACDecStruct** hDecoder = (NeAACDecStruct**)hpDecoder; |
494 | 810 | if (hDecoder == NULL) |
495 | 0 | return 1; /* error */ |
496 | | |
497 | 810 | NeAACDecClose(*hDecoder); |
498 | | |
499 | 810 | *hDecoder = NeAACDecOpen(); |
500 | | |
501 | | /* Special object type defined for DRM */ |
502 | 810 | (*hDecoder)->config.defObjectType = DRM_ER_LC; |
503 | | |
504 | 810 | (*hDecoder)->config.defSampleRate = samplerate; |
505 | 810 | #ifdef ERROR_RESILIENCE // This shoudl always be defined for DRM |
506 | 810 | (*hDecoder)->aacSectionDataResilienceFlag = 1; /* VCB11 */ |
507 | 810 | (*hDecoder)->aacScalefactorDataResilienceFlag = 0; /* no RVLC */ |
508 | 810 | (*hDecoder)->aacSpectralDataResilienceFlag = 1; /* HCR */ |
509 | 810 | #endif |
510 | 810 | (*hDecoder)->frameLength = 960; |
511 | 810 | (*hDecoder)->sf_index = get_sr_index((*hDecoder)->config.defSampleRate); |
512 | 810 | (*hDecoder)->object_type = (*hDecoder)->config.defObjectType; |
513 | | |
514 | 810 | if ((channels == DRMCH_STEREO) || (channels == DRMCH_SBR_STEREO)) |
515 | 123 | (*hDecoder)->channelConfiguration = 2; |
516 | 687 | else |
517 | 687 | (*hDecoder)->channelConfiguration = 1; |
518 | | |
519 | 810 | #ifdef SBR_DEC |
520 | 810 | if ((channels == DRMCH_MONO) || (channels == DRMCH_STEREO)) |
521 | 121 | (*hDecoder)->sbr_present_flag = 0; |
522 | 689 | else |
523 | 689 | (*hDecoder)->sbr_present_flag = 1; |
524 | 810 | #endif |
525 | | |
526 | 810 | (*hDecoder)->fb = filter_bank_init((*hDecoder)->frameLength); |
527 | | |
528 | 810 | return 0; |
529 | 810 | } |
530 | | #endif |
531 | | |
532 | | void NeAACDecClose(NeAACDecHandle hpDecoder) |
533 | 10.6k | { |
534 | 10.6k | uint8_t i; |
535 | 10.6k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
536 | | |
537 | 10.6k | 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 | 694k | for (i = 0; i < MAX_CHANNELS; i++) |
549 | 684k | { |
550 | 684k | if (hDecoder->time_out[i]) faad_free(hDecoder->time_out[i]); |
551 | 684k | 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 | 684k | } |
563 | | |
564 | | #ifdef SSR_DEC |
565 | | if (hDecoder->object_type == SSR) |
566 | | ssr_filter_bank_end(hDecoder->fb); |
567 | | else |
568 | | #endif |
569 | 10.6k | filter_bank_end(hDecoder->fb); |
570 | | |
571 | 10.6k | drc_end(hDecoder->drc); |
572 | | |
573 | 10.6k | if (hDecoder->sample_buffer) faad_free(hDecoder->sample_buffer); |
574 | | |
575 | 10.6k | #ifdef SBR_DEC |
576 | 523k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) |
577 | 513k | { |
578 | 513k | if (hDecoder->sbr[i]) |
579 | 125k | sbrDecodeEnd(hDecoder->sbr[i]); |
580 | 513k | } |
581 | 10.6k | #endif |
582 | | |
583 | 10.6k | if (hDecoder) faad_free(hDecoder); |
584 | 10.6k | } |
585 | | |
586 | | void NeAACDecPostSeekReset(NeAACDecHandle hpDecoder, long frame) |
587 | 20.5k | { |
588 | 20.5k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
589 | 20.5k | if (hDecoder) |
590 | 20.5k | { |
591 | 20.5k | hDecoder->postSeekResetFlag = 1; |
592 | | |
593 | 20.5k | if (frame != -1) |
594 | 20.5k | hDecoder->frame = frame; |
595 | 20.5k | } |
596 | 20.5k | } |
597 | | |
598 | | static void create_channel_config(NeAACDecStruct *hDecoder, NeAACDecFrameInfo *hInfo) |
599 | 41.8k | { |
600 | 41.8k | hInfo->num_front_channels = 0; |
601 | 41.8k | hInfo->num_side_channels = 0; |
602 | 41.8k | hInfo->num_back_channels = 0; |
603 | 41.8k | hInfo->num_lfe_channels = 0; |
604 | 41.8k | memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); |
605 | | |
606 | 41.8k | if (hDecoder->downMatrix) |
607 | 4.47k | { |
608 | 4.47k | hInfo->num_front_channels = 2; |
609 | 4.47k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; |
610 | 4.47k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; |
611 | 4.47k | return; |
612 | 4.47k | } |
613 | | |
614 | | /* check if there is a PCE */ |
615 | | /* TODO: why CPE flag is ignored? */ |
616 | 37.3k | if (hDecoder->pce_set) |
617 | 1.42k | { |
618 | 1.42k | uint8_t i, chpos = 0; |
619 | 1.42k | uint8_t chdir, back_center = 0; |
620 | | |
621 | 1.42k | hInfo->num_front_channels = hDecoder->pce.num_front_channels; |
622 | 1.42k | hInfo->num_side_channels = hDecoder->pce.num_side_channels; |
623 | 1.42k | hInfo->num_back_channels = hDecoder->pce.num_back_channels; |
624 | 1.42k | hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; |
625 | 1.42k | chdir = hInfo->num_front_channels; |
626 | 1.42k | if (chdir & 1) |
627 | 632 | { |
628 | 632 | #if (defined(PS_DEC) || defined(DRM_PS)) |
629 | 632 | if (hInfo->num_front_channels == 1 && |
630 | 632 | hInfo->num_side_channels == 0 && |
631 | 632 | hInfo->num_back_channels == 0 && |
632 | 632 | hInfo->num_lfe_channels == 0) |
633 | 156 | { |
634 | | /* When PS is enabled output is always stereo */ |
635 | 156 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; |
636 | 156 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; |
637 | 156 | } else |
638 | 476 | #endif |
639 | 476 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; |
640 | 632 | chdir--; |
641 | 632 | } |
642 | 7.34k | for (i = 0; i < chdir; i++) |
643 | 5.92k | { |
644 | 5.92k | hInfo->channel_position[chpos++] = |
645 | 5.92k | (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT; |
646 | 5.92k | } |
647 | | |
648 | 6.90k | for (i = 0; i < hInfo->num_side_channels; i++) |
649 | 5.48k | { |
650 | 5.48k | hInfo->channel_position[chpos++] = |
651 | 5.48k | (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT; |
652 | 5.48k | } |
653 | | |
654 | 1.42k | chdir = hInfo->num_back_channels; |
655 | 1.42k | if (chdir & 1) |
656 | 264 | { |
657 | 264 | back_center = 1; |
658 | 264 | chdir--; |
659 | 264 | } |
660 | 5.15k | for (i = 0; i < chdir; i++) |
661 | 3.73k | { |
662 | 3.73k | hInfo->channel_position[chpos++] = |
663 | 3.73k | (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT; |
664 | 3.73k | } |
665 | 1.42k | if (back_center) |
666 | 264 | { |
667 | 264 | hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; |
668 | 264 | } |
669 | | |
670 | 2.32k | for (i = 0; i < hInfo->num_lfe_channels; i++) |
671 | 904 | { |
672 | 904 | hInfo->channel_position[chpos++] = LFE_CHANNEL; |
673 | 904 | } |
674 | | |
675 | 35.9k | } else { |
676 | 35.9k | switch (hDecoder->channelConfiguration) |
677 | 35.9k | { |
678 | 1.74k | case 1: |
679 | 1.74k | #if (defined(PS_DEC) || defined(DRM_PS)) |
680 | | /* When PS is enabled output is always stereo */ |
681 | 1.74k | hInfo->num_front_channels = 2; |
682 | 1.74k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; |
683 | 1.74k | 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.74k | break; |
689 | 16.9k | case 2: |
690 | 16.9k | hInfo->num_front_channels = 2; |
691 | 16.9k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; |
692 | 16.9k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; |
693 | 16.9k | break; |
694 | 2.52k | case 3: |
695 | 2.52k | hInfo->num_front_channels = 3; |
696 | 2.52k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
697 | 2.52k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; |
698 | 2.52k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; |
699 | 2.52k | break; |
700 | 4.14k | case 4: |
701 | 4.14k | hInfo->num_front_channels = 3; |
702 | 4.14k | hInfo->num_back_channels = 1; |
703 | 4.14k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
704 | 4.14k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; |
705 | 4.14k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; |
706 | 4.14k | hInfo->channel_position[3] = BACK_CHANNEL_CENTER; |
707 | 4.14k | break; |
708 | 2.96k | case 5: |
709 | 2.96k | hInfo->num_front_channels = 3; |
710 | 2.96k | hInfo->num_back_channels = 2; |
711 | 2.96k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
712 | 2.96k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; |
713 | 2.96k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; |
714 | 2.96k | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; |
715 | 2.96k | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; |
716 | 2.96k | 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.18k | case 7: |
729 | 5.18k | hInfo->num_front_channels = 3; |
730 | 5.18k | hInfo->num_side_channels = 2; |
731 | 5.18k | hInfo->num_back_channels = 2; |
732 | 5.18k | hInfo->num_lfe_channels = 1; |
733 | 5.18k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
734 | 5.18k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; |
735 | 5.18k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; |
736 | 5.18k | hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; |
737 | 5.18k | hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; |
738 | 5.18k | hInfo->channel_position[5] = BACK_CHANNEL_LEFT; |
739 | 5.18k | hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; |
740 | 5.18k | hInfo->channel_position[7] = LFE_CHANNEL; |
741 | 5.18k | break; |
742 | 868 | default: /* channelConfiguration == 0 || channelConfiguration > 7 */ |
743 | 868 | { |
744 | 868 | uint8_t i; |
745 | 868 | uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; |
746 | 868 | if (ch & 1) /* there's either a center front or a center back channel */ |
747 | 336 | { |
748 | 336 | uint8_t ch1 = (ch-1)/2; |
749 | 336 | if (hDecoder->first_syn_ele == ID_SCE) |
750 | 220 | { |
751 | 220 | hInfo->num_front_channels = ch1 + 1; |
752 | 220 | hInfo->num_back_channels = ch1; |
753 | 220 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
754 | 848 | for (i = 1; i <= ch1; i+=2) |
755 | 628 | { |
756 | 628 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; |
757 | 628 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; |
758 | 628 | } |
759 | 848 | for (i = ch1+1; i < ch; i+=2) |
760 | 628 | { |
761 | 628 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; |
762 | 628 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; |
763 | 628 | } |
764 | 220 | } else { |
765 | 116 | hInfo->num_front_channels = ch1; |
766 | 116 | hInfo->num_back_channels = ch1 + 1; |
767 | 676 | for (i = 0; i < ch1; i+=2) |
768 | 560 | { |
769 | 560 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; |
770 | 560 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; |
771 | 560 | } |
772 | 676 | for (i = ch1; i < ch-1; i+=2) |
773 | 560 | { |
774 | 560 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; |
775 | 560 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; |
776 | 560 | } |
777 | 116 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; |
778 | 116 | } |
779 | 532 | } else { |
780 | 532 | uint8_t ch1 = (ch)/2; |
781 | 532 | hInfo->num_front_channels = ch1; |
782 | 532 | hInfo->num_back_channels = ch1; |
783 | 532 | if (ch1 & 1) |
784 | 244 | { |
785 | 244 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; |
786 | 1.66k | for (i = 1; i <= ch1; i+=2) |
787 | 1.42k | { |
788 | 1.42k | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; |
789 | 1.42k | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; |
790 | 1.42k | } |
791 | 1.42k | for (i = ch1+1; i < ch-1; i+=2) |
792 | 1.18k | { |
793 | 1.18k | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; |
794 | 1.18k | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; |
795 | 1.18k | } |
796 | 244 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; |
797 | 288 | } else { |
798 | 1.42k | for (i = 0; i < ch1; i+=2) |
799 | 1.13k | { |
800 | 1.13k | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; |
801 | 1.13k | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; |
802 | 1.13k | } |
803 | 1.42k | for (i = ch1; i < ch; i+=2) |
804 | 1.13k | { |
805 | 1.13k | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; |
806 | 1.13k | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; |
807 | 1.13k | } |
808 | 288 | } |
809 | 532 | } |
810 | 868 | hInfo->num_lfe_channels = hDecoder->has_lfe; |
811 | 1.92k | for (i = ch; i < hDecoder->fr_channels; i++) |
812 | 1.05k | { |
813 | 1.05k | hInfo->channel_position[i] = LFE_CHANNEL; |
814 | 1.05k | } |
815 | 868 | } |
816 | 868 | break; |
817 | 35.9k | } |
818 | 35.9k | } |
819 | 37.3k | } decoder.c:create_channel_config Line | Count | Source | 599 | 10.4k | { | 600 | 10.4k | hInfo->num_front_channels = 0; | 601 | 10.4k | hInfo->num_side_channels = 0; | 602 | 10.4k | hInfo->num_back_channels = 0; | 603 | 10.4k | hInfo->num_lfe_channels = 0; | 604 | 10.4k | memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); | 605 | | | 606 | 10.4k | if (hDecoder->downMatrix) | 607 | 1.11k | { | 608 | 1.11k | hInfo->num_front_channels = 2; | 609 | 1.11k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 610 | 1.11k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 611 | 1.11k | return; | 612 | 1.11k | } | 613 | | | 614 | | /* check if there is a PCE */ | 615 | | /* TODO: why CPE flag is ignored? */ | 616 | 9.33k | if (hDecoder->pce_set) | 617 | 355 | { | 618 | 355 | uint8_t i, chpos = 0; | 619 | 355 | uint8_t chdir, back_center = 0; | 620 | | | 621 | 355 | hInfo->num_front_channels = hDecoder->pce.num_front_channels; | 622 | 355 | hInfo->num_side_channels = hDecoder->pce.num_side_channels; | 623 | 355 | hInfo->num_back_channels = hDecoder->pce.num_back_channels; | 624 | 355 | hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; | 625 | 355 | chdir = hInfo->num_front_channels; | 626 | 355 | if (chdir & 1) | 627 | 158 | { | 628 | 158 | #if (defined(PS_DEC) || defined(DRM_PS)) | 629 | 158 | if (hInfo->num_front_channels == 1 && | 630 | 158 | hInfo->num_side_channels == 0 && | 631 | 158 | hInfo->num_back_channels == 0 && | 632 | 158 | hInfo->num_lfe_channels == 0) | 633 | 39 | { | 634 | | /* When PS is enabled output is always stereo */ | 635 | 39 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; | 636 | 39 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; | 637 | 39 | } else | 638 | 119 | #endif | 639 | 119 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; | 640 | 158 | chdir--; | 641 | 158 | } | 642 | 1.83k | for (i = 0; i < chdir; i++) | 643 | 1.48k | { | 644 | 1.48k | hInfo->channel_position[chpos++] = | 645 | 1.48k | (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT; | 646 | 1.48k | } | 647 | | | 648 | 1.72k | for (i = 0; i < hInfo->num_side_channels; i++) | 649 | 1.37k | { | 650 | 1.37k | hInfo->channel_position[chpos++] = | 651 | 1.37k | (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT; | 652 | 1.37k | } | 653 | | | 654 | 355 | chdir = hInfo->num_back_channels; | 655 | 355 | if (chdir & 1) | 656 | 66 | { | 657 | 66 | back_center = 1; | 658 | 66 | chdir--; | 659 | 66 | } | 660 | 1.28k | for (i = 0; i < chdir; i++) | 661 | 934 | { | 662 | 934 | hInfo->channel_position[chpos++] = | 663 | 934 | (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT; | 664 | 934 | } | 665 | 355 | if (back_center) | 666 | 66 | { | 667 | 66 | hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; | 668 | 66 | } | 669 | | | 670 | 581 | for (i = 0; i < hInfo->num_lfe_channels; i++) | 671 | 226 | { | 672 | 226 | hInfo->channel_position[chpos++] = LFE_CHANNEL; | 673 | 226 | } | 674 | | | 675 | 8.98k | } else { | 676 | 8.98k | switch (hDecoder->channelConfiguration) | 677 | 8.98k | { | 678 | 436 | case 1: | 679 | 436 | #if (defined(PS_DEC) || defined(DRM_PS)) | 680 | | /* When PS is enabled output is always stereo */ | 681 | 436 | hInfo->num_front_channels = 2; | 682 | 436 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 683 | 436 | 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 | 436 | break; | 689 | 4.24k | case 2: | 690 | 4.24k | hInfo->num_front_channels = 2; | 691 | 4.24k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 692 | 4.24k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 693 | 4.24k | break; | 694 | 630 | case 3: | 695 | 630 | hInfo->num_front_channels = 3; | 696 | 630 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 697 | 630 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 698 | 630 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 699 | 630 | break; | 700 | 1.03k | case 4: | 701 | 1.03k | hInfo->num_front_channels = 3; | 702 | 1.03k | hInfo->num_back_channels = 1; | 703 | 1.03k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 704 | 1.03k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 705 | 1.03k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 706 | 1.03k | hInfo->channel_position[3] = BACK_CHANNEL_CENTER; | 707 | 1.03k | break; | 708 | 742 | case 5: | 709 | 742 | hInfo->num_front_channels = 3; | 710 | 742 | hInfo->num_back_channels = 2; | 711 | 742 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 712 | 742 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 713 | 742 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 714 | 742 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 715 | 742 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 716 | 742 | break; | 717 | 379 | case 6: | 718 | 379 | hInfo->num_front_channels = 3; | 719 | 379 | hInfo->num_back_channels = 2; | 720 | 379 | hInfo->num_lfe_channels = 1; | 721 | 379 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 722 | 379 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 723 | 379 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 724 | 379 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 725 | 379 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 726 | 379 | hInfo->channel_position[5] = LFE_CHANNEL; | 727 | 379 | break; | 728 | 1.29k | case 7: | 729 | 1.29k | hInfo->num_front_channels = 3; | 730 | 1.29k | hInfo->num_side_channels = 2; | 731 | 1.29k | hInfo->num_back_channels = 2; | 732 | 1.29k | hInfo->num_lfe_channels = 1; | 733 | 1.29k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 734 | 1.29k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 735 | 1.29k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 736 | 1.29k | hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; | 737 | 1.29k | hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; | 738 | 1.29k | hInfo->channel_position[5] = BACK_CHANNEL_LEFT; | 739 | 1.29k | hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; | 740 | 1.29k | hInfo->channel_position[7] = LFE_CHANNEL; | 741 | 1.29k | break; | 742 | 217 | default: /* channelConfiguration == 0 || channelConfiguration > 7 */ | 743 | 217 | { | 744 | 217 | uint8_t i; | 745 | 217 | uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; | 746 | 217 | if (ch & 1) /* there's either a center front or a center back channel */ | 747 | 84 | { | 748 | 84 | uint8_t ch1 = (ch-1)/2; | 749 | 84 | if (hDecoder->first_syn_ele == ID_SCE) | 750 | 55 | { | 751 | 55 | hInfo->num_front_channels = ch1 + 1; | 752 | 55 | hInfo->num_back_channels = ch1; | 753 | 55 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 754 | 212 | for (i = 1; i <= ch1; i+=2) | 755 | 157 | { | 756 | 157 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 757 | 157 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 758 | 157 | } | 759 | 212 | for (i = ch1+1; i < ch; i+=2) | 760 | 157 | { | 761 | 157 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 762 | 157 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 763 | 157 | } | 764 | 55 | } else { | 765 | 29 | hInfo->num_front_channels = ch1; | 766 | 29 | hInfo->num_back_channels = ch1 + 1; | 767 | 169 | for (i = 0; i < ch1; i+=2) | 768 | 140 | { | 769 | 140 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 770 | 140 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 771 | 140 | } | 772 | 169 | for (i = ch1; i < ch-1; i+=2) | 773 | 140 | { | 774 | 140 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 775 | 140 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 776 | 140 | } | 777 | 29 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 778 | 29 | } | 779 | 133 | } else { | 780 | 133 | uint8_t ch1 = (ch)/2; | 781 | 133 | hInfo->num_front_channels = ch1; | 782 | 133 | hInfo->num_back_channels = ch1; | 783 | 133 | if (ch1 & 1) | 784 | 61 | { | 785 | 61 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 786 | 417 | for (i = 1; i <= ch1; i+=2) | 787 | 356 | { | 788 | 356 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 789 | 356 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 790 | 356 | } | 791 | 356 | for (i = ch1+1; i < ch-1; i+=2) | 792 | 295 | { | 793 | 295 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 794 | 295 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 795 | 295 | } | 796 | 61 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 797 | 72 | } else { | 798 | 356 | for (i = 0; i < ch1; i+=2) | 799 | 284 | { | 800 | 284 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 801 | 284 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 802 | 284 | } | 803 | 356 | for (i = ch1; i < ch; i+=2) | 804 | 284 | { | 805 | 284 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 806 | 284 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 807 | 284 | } | 808 | 72 | } | 809 | 133 | } | 810 | 217 | hInfo->num_lfe_channels = hDecoder->has_lfe; | 811 | 480 | for (i = ch; i < hDecoder->fr_channels; i++) | 812 | 263 | { | 813 | 263 | hInfo->channel_position[i] = LFE_CHANNEL; | 814 | 263 | } | 815 | 217 | } | 816 | 217 | break; | 817 | 8.98k | } | 818 | 8.98k | } | 819 | 9.33k | } |
decoder.c:create_channel_config Line | Count | Source | 599 | 10.4k | { | 600 | 10.4k | hInfo->num_front_channels = 0; | 601 | 10.4k | hInfo->num_side_channels = 0; | 602 | 10.4k | hInfo->num_back_channels = 0; | 603 | 10.4k | hInfo->num_lfe_channels = 0; | 604 | 10.4k | memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); | 605 | | | 606 | 10.4k | if (hDecoder->downMatrix) | 607 | 1.11k | { | 608 | 1.11k | hInfo->num_front_channels = 2; | 609 | 1.11k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 610 | 1.11k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 611 | 1.11k | return; | 612 | 1.11k | } | 613 | | | 614 | | /* check if there is a PCE */ | 615 | | /* TODO: why CPE flag is ignored? */ | 616 | 9.33k | if (hDecoder->pce_set) | 617 | 355 | { | 618 | 355 | uint8_t i, chpos = 0; | 619 | 355 | uint8_t chdir, back_center = 0; | 620 | | | 621 | 355 | hInfo->num_front_channels = hDecoder->pce.num_front_channels; | 622 | 355 | hInfo->num_side_channels = hDecoder->pce.num_side_channels; | 623 | 355 | hInfo->num_back_channels = hDecoder->pce.num_back_channels; | 624 | 355 | hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; | 625 | 355 | chdir = hInfo->num_front_channels; | 626 | 355 | if (chdir & 1) | 627 | 158 | { | 628 | 158 | #if (defined(PS_DEC) || defined(DRM_PS)) | 629 | 158 | if (hInfo->num_front_channels == 1 && | 630 | 158 | hInfo->num_side_channels == 0 && | 631 | 158 | hInfo->num_back_channels == 0 && | 632 | 158 | hInfo->num_lfe_channels == 0) | 633 | 39 | { | 634 | | /* When PS is enabled output is always stereo */ | 635 | 39 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; | 636 | 39 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; | 637 | 39 | } else | 638 | 119 | #endif | 639 | 119 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; | 640 | 158 | chdir--; | 641 | 158 | } | 642 | 1.83k | for (i = 0; i < chdir; i++) | 643 | 1.48k | { | 644 | 1.48k | hInfo->channel_position[chpos++] = | 645 | 1.48k | (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT; | 646 | 1.48k | } | 647 | | | 648 | 1.72k | for (i = 0; i < hInfo->num_side_channels; i++) | 649 | 1.37k | { | 650 | 1.37k | hInfo->channel_position[chpos++] = | 651 | 1.37k | (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT; | 652 | 1.37k | } | 653 | | | 654 | 355 | chdir = hInfo->num_back_channels; | 655 | 355 | if (chdir & 1) | 656 | 66 | { | 657 | 66 | back_center = 1; | 658 | 66 | chdir--; | 659 | 66 | } | 660 | 1.28k | for (i = 0; i < chdir; i++) | 661 | 934 | { | 662 | 934 | hInfo->channel_position[chpos++] = | 663 | 934 | (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT; | 664 | 934 | } | 665 | 355 | if (back_center) | 666 | 66 | { | 667 | 66 | hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; | 668 | 66 | } | 669 | | | 670 | 581 | for (i = 0; i < hInfo->num_lfe_channels; i++) | 671 | 226 | { | 672 | 226 | hInfo->channel_position[chpos++] = LFE_CHANNEL; | 673 | 226 | } | 674 | | | 675 | 8.98k | } else { | 676 | 8.98k | switch (hDecoder->channelConfiguration) | 677 | 8.98k | { | 678 | 436 | case 1: | 679 | 436 | #if (defined(PS_DEC) || defined(DRM_PS)) | 680 | | /* When PS is enabled output is always stereo */ | 681 | 436 | hInfo->num_front_channels = 2; | 682 | 436 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 683 | 436 | 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 | 436 | break; | 689 | 4.24k | case 2: | 690 | 4.24k | hInfo->num_front_channels = 2; | 691 | 4.24k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 692 | 4.24k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 693 | 4.24k | break; | 694 | 630 | case 3: | 695 | 630 | hInfo->num_front_channels = 3; | 696 | 630 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 697 | 630 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 698 | 630 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 699 | 630 | break; | 700 | 1.03k | case 4: | 701 | 1.03k | hInfo->num_front_channels = 3; | 702 | 1.03k | hInfo->num_back_channels = 1; | 703 | 1.03k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 704 | 1.03k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 705 | 1.03k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 706 | 1.03k | hInfo->channel_position[3] = BACK_CHANNEL_CENTER; | 707 | 1.03k | break; | 708 | 742 | case 5: | 709 | 742 | hInfo->num_front_channels = 3; | 710 | 742 | hInfo->num_back_channels = 2; | 711 | 742 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 712 | 742 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 713 | 742 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 714 | 742 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 715 | 742 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 716 | 742 | break; | 717 | 379 | case 6: | 718 | 379 | hInfo->num_front_channels = 3; | 719 | 379 | hInfo->num_back_channels = 2; | 720 | 379 | hInfo->num_lfe_channels = 1; | 721 | 379 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 722 | 379 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 723 | 379 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 724 | 379 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 725 | 379 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 726 | 379 | hInfo->channel_position[5] = LFE_CHANNEL; | 727 | 379 | break; | 728 | 1.29k | case 7: | 729 | 1.29k | hInfo->num_front_channels = 3; | 730 | 1.29k | hInfo->num_side_channels = 2; | 731 | 1.29k | hInfo->num_back_channels = 2; | 732 | 1.29k | hInfo->num_lfe_channels = 1; | 733 | 1.29k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 734 | 1.29k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 735 | 1.29k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 736 | 1.29k | hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; | 737 | 1.29k | hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; | 738 | 1.29k | hInfo->channel_position[5] = BACK_CHANNEL_LEFT; | 739 | 1.29k | hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; | 740 | 1.29k | hInfo->channel_position[7] = LFE_CHANNEL; | 741 | 1.29k | break; | 742 | 217 | default: /* channelConfiguration == 0 || channelConfiguration > 7 */ | 743 | 217 | { | 744 | 217 | uint8_t i; | 745 | 217 | uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; | 746 | 217 | if (ch & 1) /* there's either a center front or a center back channel */ | 747 | 84 | { | 748 | 84 | uint8_t ch1 = (ch-1)/2; | 749 | 84 | if (hDecoder->first_syn_ele == ID_SCE) | 750 | 55 | { | 751 | 55 | hInfo->num_front_channels = ch1 + 1; | 752 | 55 | hInfo->num_back_channels = ch1; | 753 | 55 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 754 | 212 | for (i = 1; i <= ch1; i+=2) | 755 | 157 | { | 756 | 157 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 757 | 157 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 758 | 157 | } | 759 | 212 | for (i = ch1+1; i < ch; i+=2) | 760 | 157 | { | 761 | 157 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 762 | 157 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 763 | 157 | } | 764 | 55 | } else { | 765 | 29 | hInfo->num_front_channels = ch1; | 766 | 29 | hInfo->num_back_channels = ch1 + 1; | 767 | 169 | for (i = 0; i < ch1; i+=2) | 768 | 140 | { | 769 | 140 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 770 | 140 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 771 | 140 | } | 772 | 169 | for (i = ch1; i < ch-1; i+=2) | 773 | 140 | { | 774 | 140 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 775 | 140 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 776 | 140 | } | 777 | 29 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 778 | 29 | } | 779 | 133 | } else { | 780 | 133 | uint8_t ch1 = (ch)/2; | 781 | 133 | hInfo->num_front_channels = ch1; | 782 | 133 | hInfo->num_back_channels = ch1; | 783 | 133 | if (ch1 & 1) | 784 | 61 | { | 785 | 61 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 786 | 417 | for (i = 1; i <= ch1; i+=2) | 787 | 356 | { | 788 | 356 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 789 | 356 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 790 | 356 | } | 791 | 356 | for (i = ch1+1; i < ch-1; i+=2) | 792 | 295 | { | 793 | 295 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 794 | 295 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 795 | 295 | } | 796 | 61 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 797 | 72 | } else { | 798 | 356 | for (i = 0; i < ch1; i+=2) | 799 | 284 | { | 800 | 284 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 801 | 284 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 802 | 284 | } | 803 | 356 | for (i = ch1; i < ch; i+=2) | 804 | 284 | { | 805 | 284 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 806 | 284 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 807 | 284 | } | 808 | 72 | } | 809 | 133 | } | 810 | 217 | hInfo->num_lfe_channels = hDecoder->has_lfe; | 811 | 480 | for (i = ch; i < hDecoder->fr_channels; i++) | 812 | 263 | { | 813 | 263 | hInfo->channel_position[i] = LFE_CHANNEL; | 814 | 263 | } | 815 | 217 | } | 816 | 217 | break; | 817 | 8.98k | } | 818 | 8.98k | } | 819 | 9.33k | } |
decoder.c:create_channel_config Line | Count | Source | 599 | 10.4k | { | 600 | 10.4k | hInfo->num_front_channels = 0; | 601 | 10.4k | hInfo->num_side_channels = 0; | 602 | 10.4k | hInfo->num_back_channels = 0; | 603 | 10.4k | hInfo->num_lfe_channels = 0; | 604 | 10.4k | memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); | 605 | | | 606 | 10.4k | if (hDecoder->downMatrix) | 607 | 1.11k | { | 608 | 1.11k | hInfo->num_front_channels = 2; | 609 | 1.11k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 610 | 1.11k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 611 | 1.11k | return; | 612 | 1.11k | } | 613 | | | 614 | | /* check if there is a PCE */ | 615 | | /* TODO: why CPE flag is ignored? */ | 616 | 9.33k | if (hDecoder->pce_set) | 617 | 355 | { | 618 | 355 | uint8_t i, chpos = 0; | 619 | 355 | uint8_t chdir, back_center = 0; | 620 | | | 621 | 355 | hInfo->num_front_channels = hDecoder->pce.num_front_channels; | 622 | 355 | hInfo->num_side_channels = hDecoder->pce.num_side_channels; | 623 | 355 | hInfo->num_back_channels = hDecoder->pce.num_back_channels; | 624 | 355 | hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; | 625 | 355 | chdir = hInfo->num_front_channels; | 626 | 355 | if (chdir & 1) | 627 | 158 | { | 628 | 158 | #if (defined(PS_DEC) || defined(DRM_PS)) | 629 | 158 | if (hInfo->num_front_channels == 1 && | 630 | 158 | hInfo->num_side_channels == 0 && | 631 | 158 | hInfo->num_back_channels == 0 && | 632 | 158 | hInfo->num_lfe_channels == 0) | 633 | 39 | { | 634 | | /* When PS is enabled output is always stereo */ | 635 | 39 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; | 636 | 39 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; | 637 | 39 | } else | 638 | 119 | #endif | 639 | 119 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; | 640 | 158 | chdir--; | 641 | 158 | } | 642 | 1.83k | for (i = 0; i < chdir; i++) | 643 | 1.48k | { | 644 | 1.48k | hInfo->channel_position[chpos++] = | 645 | 1.48k | (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT; | 646 | 1.48k | } | 647 | | | 648 | 1.72k | for (i = 0; i < hInfo->num_side_channels; i++) | 649 | 1.37k | { | 650 | 1.37k | hInfo->channel_position[chpos++] = | 651 | 1.37k | (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT; | 652 | 1.37k | } | 653 | | | 654 | 355 | chdir = hInfo->num_back_channels; | 655 | 355 | if (chdir & 1) | 656 | 66 | { | 657 | 66 | back_center = 1; | 658 | 66 | chdir--; | 659 | 66 | } | 660 | 1.28k | for (i = 0; i < chdir; i++) | 661 | 934 | { | 662 | 934 | hInfo->channel_position[chpos++] = | 663 | 934 | (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT; | 664 | 934 | } | 665 | 355 | if (back_center) | 666 | 66 | { | 667 | 66 | hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; | 668 | 66 | } | 669 | | | 670 | 581 | for (i = 0; i < hInfo->num_lfe_channels; i++) | 671 | 226 | { | 672 | 226 | hInfo->channel_position[chpos++] = LFE_CHANNEL; | 673 | 226 | } | 674 | | | 675 | 8.98k | } else { | 676 | 8.98k | switch (hDecoder->channelConfiguration) | 677 | 8.98k | { | 678 | 436 | case 1: | 679 | 436 | #if (defined(PS_DEC) || defined(DRM_PS)) | 680 | | /* When PS is enabled output is always stereo */ | 681 | 436 | hInfo->num_front_channels = 2; | 682 | 436 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 683 | 436 | 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 | 436 | break; | 689 | 4.24k | case 2: | 690 | 4.24k | hInfo->num_front_channels = 2; | 691 | 4.24k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 692 | 4.24k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 693 | 4.24k | break; | 694 | 630 | case 3: | 695 | 630 | hInfo->num_front_channels = 3; | 696 | 630 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 697 | 630 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 698 | 630 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 699 | 630 | break; | 700 | 1.03k | case 4: | 701 | 1.03k | hInfo->num_front_channels = 3; | 702 | 1.03k | hInfo->num_back_channels = 1; | 703 | 1.03k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 704 | 1.03k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 705 | 1.03k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 706 | 1.03k | hInfo->channel_position[3] = BACK_CHANNEL_CENTER; | 707 | 1.03k | break; | 708 | 742 | case 5: | 709 | 742 | hInfo->num_front_channels = 3; | 710 | 742 | hInfo->num_back_channels = 2; | 711 | 742 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 712 | 742 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 713 | 742 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 714 | 742 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 715 | 742 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 716 | 742 | break; | 717 | 379 | case 6: | 718 | 379 | hInfo->num_front_channels = 3; | 719 | 379 | hInfo->num_back_channels = 2; | 720 | 379 | hInfo->num_lfe_channels = 1; | 721 | 379 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 722 | 379 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 723 | 379 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 724 | 379 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 725 | 379 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 726 | 379 | hInfo->channel_position[5] = LFE_CHANNEL; | 727 | 379 | break; | 728 | 1.29k | case 7: | 729 | 1.29k | hInfo->num_front_channels = 3; | 730 | 1.29k | hInfo->num_side_channels = 2; | 731 | 1.29k | hInfo->num_back_channels = 2; | 732 | 1.29k | hInfo->num_lfe_channels = 1; | 733 | 1.29k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 734 | 1.29k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 735 | 1.29k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 736 | 1.29k | hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; | 737 | 1.29k | hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; | 738 | 1.29k | hInfo->channel_position[5] = BACK_CHANNEL_LEFT; | 739 | 1.29k | hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; | 740 | 1.29k | hInfo->channel_position[7] = LFE_CHANNEL; | 741 | 1.29k | break; | 742 | 217 | default: /* channelConfiguration == 0 || channelConfiguration > 7 */ | 743 | 217 | { | 744 | 217 | uint8_t i; | 745 | 217 | uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; | 746 | 217 | if (ch & 1) /* there's either a center front or a center back channel */ | 747 | 84 | { | 748 | 84 | uint8_t ch1 = (ch-1)/2; | 749 | 84 | if (hDecoder->first_syn_ele == ID_SCE) | 750 | 55 | { | 751 | 55 | hInfo->num_front_channels = ch1 + 1; | 752 | 55 | hInfo->num_back_channels = ch1; | 753 | 55 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 754 | 212 | for (i = 1; i <= ch1; i+=2) | 755 | 157 | { | 756 | 157 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 757 | 157 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 758 | 157 | } | 759 | 212 | for (i = ch1+1; i < ch; i+=2) | 760 | 157 | { | 761 | 157 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 762 | 157 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 763 | 157 | } | 764 | 55 | } else { | 765 | 29 | hInfo->num_front_channels = ch1; | 766 | 29 | hInfo->num_back_channels = ch1 + 1; | 767 | 169 | for (i = 0; i < ch1; i+=2) | 768 | 140 | { | 769 | 140 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 770 | 140 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 771 | 140 | } | 772 | 169 | for (i = ch1; i < ch-1; i+=2) | 773 | 140 | { | 774 | 140 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 775 | 140 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 776 | 140 | } | 777 | 29 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 778 | 29 | } | 779 | 133 | } else { | 780 | 133 | uint8_t ch1 = (ch)/2; | 781 | 133 | hInfo->num_front_channels = ch1; | 782 | 133 | hInfo->num_back_channels = ch1; | 783 | 133 | if (ch1 & 1) | 784 | 61 | { | 785 | 61 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 786 | 417 | for (i = 1; i <= ch1; i+=2) | 787 | 356 | { | 788 | 356 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 789 | 356 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 790 | 356 | } | 791 | 356 | for (i = ch1+1; i < ch-1; i+=2) | 792 | 295 | { | 793 | 295 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 794 | 295 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 795 | 295 | } | 796 | 61 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 797 | 72 | } else { | 798 | 356 | for (i = 0; i < ch1; i+=2) | 799 | 284 | { | 800 | 284 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 801 | 284 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 802 | 284 | } | 803 | 356 | for (i = ch1; i < ch; i+=2) | 804 | 284 | { | 805 | 284 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 806 | 284 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 807 | 284 | } | 808 | 72 | } | 809 | 133 | } | 810 | 217 | hInfo->num_lfe_channels = hDecoder->has_lfe; | 811 | 480 | for (i = ch; i < hDecoder->fr_channels; i++) | 812 | 263 | { | 813 | 263 | hInfo->channel_position[i] = LFE_CHANNEL; | 814 | 263 | } | 815 | 217 | } | 816 | 217 | break; | 817 | 8.98k | } | 818 | 8.98k | } | 819 | 9.33k | } |
decoder.c:create_channel_config Line | Count | Source | 599 | 10.4k | { | 600 | 10.4k | hInfo->num_front_channels = 0; | 601 | 10.4k | hInfo->num_side_channels = 0; | 602 | 10.4k | hInfo->num_back_channels = 0; | 603 | 10.4k | hInfo->num_lfe_channels = 0; | 604 | 10.4k | memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t)); | 605 | | | 606 | 10.4k | if (hDecoder->downMatrix) | 607 | 1.11k | { | 608 | 1.11k | hInfo->num_front_channels = 2; | 609 | 1.11k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 610 | 1.11k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 611 | 1.11k | return; | 612 | 1.11k | } | 613 | | | 614 | | /* check if there is a PCE */ | 615 | | /* TODO: why CPE flag is ignored? */ | 616 | 9.33k | if (hDecoder->pce_set) | 617 | 355 | { | 618 | 355 | uint8_t i, chpos = 0; | 619 | 355 | uint8_t chdir, back_center = 0; | 620 | | | 621 | 355 | hInfo->num_front_channels = hDecoder->pce.num_front_channels; | 622 | 355 | hInfo->num_side_channels = hDecoder->pce.num_side_channels; | 623 | 355 | hInfo->num_back_channels = hDecoder->pce.num_back_channels; | 624 | 355 | hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels; | 625 | 355 | chdir = hInfo->num_front_channels; | 626 | 355 | if (chdir & 1) | 627 | 158 | { | 628 | 158 | #if (defined(PS_DEC) || defined(DRM_PS)) | 629 | 158 | if (hInfo->num_front_channels == 1 && | 630 | 158 | hInfo->num_side_channels == 0 && | 631 | 158 | hInfo->num_back_channels == 0 && | 632 | 158 | hInfo->num_lfe_channels == 0) | 633 | 39 | { | 634 | | /* When PS is enabled output is always stereo */ | 635 | 39 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT; | 636 | 39 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT; | 637 | 39 | } else | 638 | 119 | #endif | 639 | 119 | hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER; | 640 | 158 | chdir--; | 641 | 158 | } | 642 | 1.83k | for (i = 0; i < chdir; i++) | 643 | 1.48k | { | 644 | 1.48k | hInfo->channel_position[chpos++] = | 645 | 1.48k | (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT; | 646 | 1.48k | } | 647 | | | 648 | 1.72k | for (i = 0; i < hInfo->num_side_channels; i++) | 649 | 1.37k | { | 650 | 1.37k | hInfo->channel_position[chpos++] = | 651 | 1.37k | (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT; | 652 | 1.37k | } | 653 | | | 654 | 355 | chdir = hInfo->num_back_channels; | 655 | 355 | if (chdir & 1) | 656 | 66 | { | 657 | 66 | back_center = 1; | 658 | 66 | chdir--; | 659 | 66 | } | 660 | 1.28k | for (i = 0; i < chdir; i++) | 661 | 934 | { | 662 | 934 | hInfo->channel_position[chpos++] = | 663 | 934 | (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT; | 664 | 934 | } | 665 | 355 | if (back_center) | 666 | 66 | { | 667 | 66 | hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER; | 668 | 66 | } | 669 | | | 670 | 581 | for (i = 0; i < hInfo->num_lfe_channels; i++) | 671 | 226 | { | 672 | 226 | hInfo->channel_position[chpos++] = LFE_CHANNEL; | 673 | 226 | } | 674 | | | 675 | 8.98k | } else { | 676 | 8.98k | switch (hDecoder->channelConfiguration) | 677 | 8.98k | { | 678 | 436 | case 1: | 679 | 436 | #if (defined(PS_DEC) || defined(DRM_PS)) | 680 | | /* When PS is enabled output is always stereo */ | 681 | 436 | hInfo->num_front_channels = 2; | 682 | 436 | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 683 | 436 | 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 | 436 | break; | 689 | 4.24k | case 2: | 690 | 4.24k | hInfo->num_front_channels = 2; | 691 | 4.24k | hInfo->channel_position[0] = FRONT_CHANNEL_LEFT; | 692 | 4.24k | hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT; | 693 | 4.24k | break; | 694 | 630 | case 3: | 695 | 630 | hInfo->num_front_channels = 3; | 696 | 630 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 697 | 630 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 698 | 630 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 699 | 630 | break; | 700 | 1.03k | case 4: | 701 | 1.03k | hInfo->num_front_channels = 3; | 702 | 1.03k | hInfo->num_back_channels = 1; | 703 | 1.03k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 704 | 1.03k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 705 | 1.03k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 706 | 1.03k | hInfo->channel_position[3] = BACK_CHANNEL_CENTER; | 707 | 1.03k | break; | 708 | 742 | case 5: | 709 | 742 | hInfo->num_front_channels = 3; | 710 | 742 | hInfo->num_back_channels = 2; | 711 | 742 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 712 | 742 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 713 | 742 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 714 | 742 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 715 | 742 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 716 | 742 | break; | 717 | 379 | case 6: | 718 | 379 | hInfo->num_front_channels = 3; | 719 | 379 | hInfo->num_back_channels = 2; | 720 | 379 | hInfo->num_lfe_channels = 1; | 721 | 379 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 722 | 379 | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 723 | 379 | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 724 | 379 | hInfo->channel_position[3] = BACK_CHANNEL_LEFT; | 725 | 379 | hInfo->channel_position[4] = BACK_CHANNEL_RIGHT; | 726 | 379 | hInfo->channel_position[5] = LFE_CHANNEL; | 727 | 379 | break; | 728 | 1.29k | case 7: | 729 | 1.29k | hInfo->num_front_channels = 3; | 730 | 1.29k | hInfo->num_side_channels = 2; | 731 | 1.29k | hInfo->num_back_channels = 2; | 732 | 1.29k | hInfo->num_lfe_channels = 1; | 733 | 1.29k | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 734 | 1.29k | hInfo->channel_position[1] = FRONT_CHANNEL_LEFT; | 735 | 1.29k | hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT; | 736 | 1.29k | hInfo->channel_position[3] = SIDE_CHANNEL_LEFT; | 737 | 1.29k | hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT; | 738 | 1.29k | hInfo->channel_position[5] = BACK_CHANNEL_LEFT; | 739 | 1.29k | hInfo->channel_position[6] = BACK_CHANNEL_RIGHT; | 740 | 1.29k | hInfo->channel_position[7] = LFE_CHANNEL; | 741 | 1.29k | break; | 742 | 217 | default: /* channelConfiguration == 0 || channelConfiguration > 7 */ | 743 | 217 | { | 744 | 217 | uint8_t i; | 745 | 217 | uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe; | 746 | 217 | if (ch & 1) /* there's either a center front or a center back channel */ | 747 | 84 | { | 748 | 84 | uint8_t ch1 = (ch-1)/2; | 749 | 84 | if (hDecoder->first_syn_ele == ID_SCE) | 750 | 55 | { | 751 | 55 | hInfo->num_front_channels = ch1 + 1; | 752 | 55 | hInfo->num_back_channels = ch1; | 753 | 55 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 754 | 212 | for (i = 1; i <= ch1; i+=2) | 755 | 157 | { | 756 | 157 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 757 | 157 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 758 | 157 | } | 759 | 212 | for (i = ch1+1; i < ch; i+=2) | 760 | 157 | { | 761 | 157 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 762 | 157 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 763 | 157 | } | 764 | 55 | } else { | 765 | 29 | hInfo->num_front_channels = ch1; | 766 | 29 | hInfo->num_back_channels = ch1 + 1; | 767 | 169 | for (i = 0; i < ch1; i+=2) | 768 | 140 | { | 769 | 140 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 770 | 140 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 771 | 140 | } | 772 | 169 | for (i = ch1; i < ch-1; i+=2) | 773 | 140 | { | 774 | 140 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 775 | 140 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 776 | 140 | } | 777 | 29 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 778 | 29 | } | 779 | 133 | } else { | 780 | 133 | uint8_t ch1 = (ch)/2; | 781 | 133 | hInfo->num_front_channels = ch1; | 782 | 133 | hInfo->num_back_channels = ch1; | 783 | 133 | if (ch1 & 1) | 784 | 61 | { | 785 | 61 | hInfo->channel_position[0] = FRONT_CHANNEL_CENTER; | 786 | 417 | for (i = 1; i <= ch1; i+=2) | 787 | 356 | { | 788 | 356 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 789 | 356 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 790 | 356 | } | 791 | 356 | for (i = ch1+1; i < ch-1; i+=2) | 792 | 295 | { | 793 | 295 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 794 | 295 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 795 | 295 | } | 796 | 61 | hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER; | 797 | 72 | } else { | 798 | 356 | for (i = 0; i < ch1; i+=2) | 799 | 284 | { | 800 | 284 | hInfo->channel_position[i] = FRONT_CHANNEL_LEFT; | 801 | 284 | hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT; | 802 | 284 | } | 803 | 356 | for (i = ch1; i < ch; i+=2) | 804 | 284 | { | 805 | 284 | hInfo->channel_position[i] = BACK_CHANNEL_LEFT; | 806 | 284 | hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT; | 807 | 284 | } | 808 | 72 | } | 809 | 133 | } | 810 | 217 | hInfo->num_lfe_channels = hDecoder->has_lfe; | 811 | 480 | for (i = ch; i < hDecoder->fr_channels; i++) | 812 | 263 | { | 813 | 263 | hInfo->channel_position[i] = LFE_CHANNEL; | 814 | 263 | } | 815 | 217 | } | 816 | 217 | break; | 817 | 8.98k | } | 818 | 8.98k | } | 819 | 9.33k | } |
|
820 | | |
821 | | void* NeAACDecDecode(NeAACDecHandle hpDecoder, |
822 | | NeAACDecFrameInfo *hInfo, |
823 | | unsigned char *buffer, |
824 | | unsigned long buffer_size) |
825 | 42.4k | { |
826 | 42.4k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
827 | 42.4k | return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, NULL, 0); |
828 | 42.4k | } |
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 | 12.5k | { |
837 | 12.5k | NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder; |
838 | 12.5k | if ((sample_buffer_size == 0) || (sample_buffer == NULL) || (*sample_buffer == NULL)) |
839 | 113 | { |
840 | 113 | hInfo->error = 27; |
841 | 113 | return NULL; |
842 | 113 | } |
843 | | |
844 | 12.4k | return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, |
845 | 12.4k | sample_buffer, sample_buffer_size); |
846 | 12.5k | } |
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 | 54.8k | { |
855 | 54.8k | uint16_t i; |
856 | 54.8k | uint8_t channels = 0; |
857 | 54.8k | uint8_t output_channels = 0; |
858 | 54.8k | bitfile ld; |
859 | 54.8k | uint32_t bitsconsumed; |
860 | 54.8k | uint16_t frame_len; |
861 | 54.8k | void *sample_buffer; |
862 | | #if 0 |
863 | | uint32_t startbit=0, endbit=0, payload_bits=0; |
864 | | #endif |
865 | 54.8k | uint32_t required_buffer_size=0; |
866 | | |
867 | | #ifdef PROFILE |
868 | | int64_t count = faad_get_ts(); |
869 | | #endif |
870 | | |
871 | | /* safety checks */ |
872 | 54.8k | 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 | 54.8k | frame_len = hDecoder->frameLength; |
882 | | |
883 | | |
884 | 54.8k | memset(hInfo, 0, sizeof(NeAACDecFrameInfo)); |
885 | 54.8k | 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 | 54.8k | if (buffer_size >= 128) |
903 | 6.13k | { |
904 | 6.13k | 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 | 6.13k | } |
912 | | |
913 | | |
914 | | /* initialize the bitstream */ |
915 | 54.8k | faad_initbits(&ld, buffer, buffer_size); |
916 | 54.8k | if (ld.error != 0) |
917 | 22.1k | 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 | 11.3k | if (hDecoder->object_type == DRM_ER_LC) |
952 | 1.00k | { |
953 | | /* We do not support stereo right now */ |
954 | 1.00k | if (0) //(hDecoder->channelConfiguration == 2) |
955 | 0 | { |
956 | 0 | hInfo->error = 28; // Throw CRC error |
957 | 0 | goto error; |
958 | 0 | } |
959 | | |
960 | 1.00k | faad_getbits(&ld, 8 |
961 | 1.00k | DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC")); |
962 | 1.00k | } |
963 | 11.3k | #endif |
964 | | |
965 | 32.7k | if (hDecoder->adts_header_present) |
966 | 781 | { |
967 | 781 | adts_header adts; |
968 | | |
969 | 781 | adts.old_format = hDecoder->config.useOldADTSFormat; |
970 | 781 | if ((hInfo->error = adts_frame(&adts, &ld)) > 0) |
971 | 107 | 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 | 781 | } |
978 | | |
979 | | #ifdef ANALYSIS |
980 | | dbg_count = 0; |
981 | | #endif |
982 | | |
983 | | /* decode the complete bitstream */ |
984 | | #ifdef DRM |
985 | 11.3k | if (/*(hDecoder->object_type == 6) ||*/ hDecoder->object_type == DRM_ER_LC) |
986 | 1.00k | { |
987 | 1.00k | DRM_aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); |
988 | 10.3k | } else { |
989 | 10.3k | #endif |
990 | 21.2k | 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 | 21.2k | channels = hDecoder->fr_channels; |
1009 | | |
1010 | 32.6k | if (hInfo->error > 0) |
1011 | 22.0k | goto error; |
1012 | | |
1013 | | /* safety check */ |
1014 | 10.5k | if (channels == 0 || channels > MAX_CHANNELS) |
1015 | 94 | { |
1016 | | /* invalid number of channels */ |
1017 | 94 | hInfo->error = 12; |
1018 | 94 | goto error; |
1019 | 94 | } |
1020 | | |
1021 | | /* no more bit reading after this */ |
1022 | 10.4k | bitsconsumed = faad_get_processed_bits(&ld); |
1023 | 10.4k | hInfo->bytesconsumed = bit2byte(bitsconsumed); |
1024 | 10.4k | if (ld.error) |
1025 | 0 | { |
1026 | 0 | hInfo->error = 14; |
1027 | 0 | goto error; |
1028 | 0 | } |
1029 | 10.4k | faad_endbits(&ld); |
1030 | | |
1031 | | |
1032 | 10.4k | if (!hDecoder->adts_header_present && !hDecoder->adif_header_present |
1033 | | #if 0 |
1034 | | && !hDecoder->latm_header_present |
1035 | | #endif |
1036 | 10.4k | ) |
1037 | 10.2k | { |
1038 | 10.2k | if (hDecoder->channelConfiguration == 0) |
1039 | 319 | hDecoder->channelConfiguration = channels; |
1040 | | |
1041 | 10.2k | if (channels == 8) /* 7.1 */ |
1042 | 916 | hDecoder->channelConfiguration = 7; |
1043 | 10.2k | if (channels == 7) /* not a standard channelConfiguration */ |
1044 | 57 | hDecoder->channelConfiguration = 0; |
1045 | 10.2k | } |
1046 | | |
1047 | 10.4k | if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix) |
1048 | 1.11k | { |
1049 | 1.11k | hDecoder->downMatrix = 1; |
1050 | 1.11k | output_channels = 2; |
1051 | 9.35k | } else { |
1052 | 9.35k | output_channels = channels; |
1053 | 9.35k | } |
1054 | | |
1055 | 10.4k | #if (defined(PS_DEC) || defined(DRM_PS)) |
1056 | 10.4k | hDecoder->upMatrix = 0; |
1057 | | /* check if we have a mono file */ |
1058 | 10.4k | if (output_channels == 1) |
1059 | 297 | { |
1060 | | /* upMatrix to 2 channels for implicit signalling of PS */ |
1061 | 297 | hDecoder->upMatrix = 1; |
1062 | 297 | output_channels = 2; |
1063 | 297 | } |
1064 | 10.4k | #endif |
1065 | | |
1066 | | /* Make a channel configuration based on either a PCE or a channelConfiguration */ |
1067 | 10.4k | if (!hDecoder->downMatrix && hDecoder->pce_set) |
1068 | 364 | { |
1069 | | /* In some codepath program_config_element result is ignored. */ |
1070 | 364 | if (hDecoder->pce.channels > MAX_CHANNELS) |
1071 | 9 | { |
1072 | 9 | hInfo->error = 22; |
1073 | 9 | return NULL; |
1074 | 9 | } |
1075 | 364 | } |
1076 | 10.4k | create_channel_config(hDecoder, hInfo); |
1077 | | |
1078 | | /* number of samples in this frame */ |
1079 | 10.4k | hInfo->samples = frame_len*output_channels; |
1080 | | /* number of channels in this frame */ |
1081 | 10.4k | hInfo->channels = output_channels; |
1082 | | /* samplerate */ |
1083 | 10.4k | hInfo->samplerate = get_sample_rate(hDecoder->sf_index); |
1084 | | /* object type */ |
1085 | 10.4k | hInfo->object_type = hDecoder->object_type; |
1086 | | /* sbr */ |
1087 | 10.4k | hInfo->sbr = NO_SBR; |
1088 | | /* header type */ |
1089 | 10.4k | hInfo->header_type = RAW; |
1090 | 10.4k | if (hDecoder->adif_header_present) |
1091 | 0 | hInfo->header_type = ADIF; |
1092 | 10.4k | if (hDecoder->adts_header_present) |
1093 | 208 | hInfo->header_type = ADTS; |
1094 | | #if 0 |
1095 | | if (hDecoder->latm_header_present) |
1096 | | hInfo->header_type = LATM; |
1097 | | #endif |
1098 | 10.4k | #if (defined(PS_DEC) || defined(DRM_PS)) |
1099 | 10.4k | hInfo->ps = hDecoder->ps_used_global; |
1100 | 10.4k | #endif |
1101 | | |
1102 | | /* check if frame has channel elements */ |
1103 | 10.4k | if (channels == 0) |
1104 | 0 | { |
1105 | 0 | hDecoder->frame++; |
1106 | 0 | return NULL; |
1107 | 0 | } |
1108 | | |
1109 | 10.4k | { |
1110 | 10.4k | static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t), |
1111 | 10.4k | sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t), |
1112 | 10.4k | sizeof(int16_t), sizeof(int16_t), 0, 0, 0 |
1113 | 10.4k | }; |
1114 | 10.4k | uint8_t stride = str[hDecoder->config.outputFormat-1]; |
1115 | 10.4k | #ifdef SBR_DEC |
1116 | 10.4k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1)) |
1117 | 5.96k | { |
1118 | 5.96k | stride = 2 * stride; |
1119 | 5.96k | } |
1120 | 10.4k | #endif |
1121 | 10.4k | required_buffer_size = frame_len*output_channels*stride; |
1122 | 10.4k | } |
1123 | | |
1124 | | /* check if we want to use internal sample_buffer */ |
1125 | 10.4k | if (sample_buffer_size == 0) |
1126 | 7.16k | { |
1127 | | /* allocate the buffer for the final samples */ |
1128 | 7.16k | if (hDecoder->sample_buffer_size != required_buffer_size) |
1129 | 6.22k | { |
1130 | 6.22k | if (hDecoder->sample_buffer) |
1131 | 101 | faad_free(hDecoder->sample_buffer); |
1132 | 6.22k | hDecoder->sample_buffer = NULL; |
1133 | 6.22k | hDecoder->sample_buffer = faad_malloc(required_buffer_size); |
1134 | 6.22k | hDecoder->sample_buffer_size = required_buffer_size; |
1135 | 6.22k | } |
1136 | 7.16k | } else if (sample_buffer_size < required_buffer_size) { |
1137 | | /* provided sample buffer is not big enough */ |
1138 | 1.34k | hInfo->error = 27; |
1139 | 1.34k | return NULL; |
1140 | 1.34k | } |
1141 | | |
1142 | 9.11k | if (sample_buffer_size == 0) |
1143 | 7.16k | { |
1144 | 7.16k | sample_buffer = hDecoder->sample_buffer; |
1145 | 7.16k | } else { |
1146 | 1.95k | sample_buffer = *sample_buffer2; |
1147 | 1.95k | } |
1148 | | |
1149 | 9.11k | #ifdef SBR_DEC |
1150 | 9.11k | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) |
1151 | 6.32k | { |
1152 | 6.32k | uint8_t ele; |
1153 | | |
1154 | | /* this data is different when SBR is used or when the data is upsampled */ |
1155 | 6.32k | if (!hDecoder->downSampledSBR) |
1156 | 5.00k | { |
1157 | 5.00k | frame_len *= 2; |
1158 | 5.00k | hInfo->samples *= 2; |
1159 | 5.00k | hInfo->samplerate *= 2; |
1160 | 5.00k | } |
1161 | | |
1162 | | /* check if every element was provided with SBR data */ |
1163 | 32.0k | for (ele = 0; ele < hDecoder->fr_ch_ele; ele++) |
1164 | 25.7k | { |
1165 | 25.7k | if (hDecoder->sbr[ele] == NULL) |
1166 | 8 | { |
1167 | 8 | hInfo->error = 25; |
1168 | 8 | goto error; |
1169 | 8 | } |
1170 | 25.7k | } |
1171 | | |
1172 | | /* sbr */ |
1173 | 6.31k | if (hDecoder->sbr_present_flag == 1) |
1174 | 4.05k | { |
1175 | 4.05k | hInfo->object_type = HE_AAC; |
1176 | 4.05k | hInfo->sbr = SBR_UPSAMPLED; |
1177 | 4.05k | } else { |
1178 | 2.26k | hInfo->sbr = NO_SBR_UPSAMPLED; |
1179 | 2.26k | } |
1180 | 6.31k | if (hDecoder->downSampledSBR) |
1181 | 1.31k | { |
1182 | 1.31k | hInfo->sbr = SBR_DOWNSAMPLED; |
1183 | 1.31k | } |
1184 | 6.31k | } |
1185 | 9.10k | #endif |
1186 | | |
1187 | | |
1188 | 9.10k | sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer, |
1189 | 9.10k | 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 | 9.10k | hDecoder->postSeekResetFlag = 0; |
1198 | | |
1199 | 9.10k | hDecoder->frame++; |
1200 | | #ifdef LD_DEC |
1201 | 6.06k | if (hDecoder->object_type != LD) |
1202 | 5.31k | { |
1203 | 5.31k | #endif |
1204 | 8.35k | if (hDecoder->frame <= 1) |
1205 | 3.11k | hInfo->samples = 0; |
1206 | | #ifdef LD_DEC |
1207 | 755 | } else { |
1208 | | /* LD encoders will give lower delay */ |
1209 | 755 | if (hDecoder->frame <= 0) |
1210 | 0 | hInfo->samples = 0; |
1211 | 755 | } |
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 | 9.10k | return sample_buffer; |
1225 | | |
1226 | 22.2k | error: |
1227 | | |
1228 | | /* reset filterbank state */ |
1229 | 1.44M | for (i = 0; i < MAX_CHANNELS; i++) |
1230 | 1.42M | { |
1231 | 1.42M | if (hDecoder->fb_intermed[i] != NULL) |
1232 | 712k | { |
1233 | 712k | memset(hDecoder->fb_intermed[i], 0, hDecoder->frameLength*sizeof(real_t)); |
1234 | 712k | } |
1235 | 1.42M | } |
1236 | 22.2k | #ifdef SBR_DEC |
1237 | 1.09M | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) |
1238 | 1.06M | { |
1239 | 1.06M | if (hDecoder->sbr[i] != NULL) |
1240 | 510k | { |
1241 | 510k | sbrReset(hDecoder->sbr[i]); |
1242 | 510k | } |
1243 | 1.06M | } |
1244 | 22.2k | #endif |
1245 | | |
1246 | | |
1247 | 22.2k | faad_endbits(&ld); |
1248 | | |
1249 | | /* cleanup */ |
1250 | | #ifdef ANALYSIS |
1251 | | fflush(stdout); |
1252 | | #endif |
1253 | | |
1254 | 22.2k | return NULL; |
1255 | 9.11k | } decoder.c:aac_frame_decode Line | Count | Source | 854 | 18.9k | { | 855 | 18.9k | uint16_t i; | 856 | 18.9k | uint8_t channels = 0; | 857 | 18.9k | uint8_t output_channels = 0; | 858 | 18.9k | bitfile ld; | 859 | 18.9k | uint32_t bitsconsumed; | 860 | 18.9k | uint16_t frame_len; | 861 | 18.9k | void *sample_buffer; | 862 | | #if 0 | 863 | | uint32_t startbit=0, endbit=0, payload_bits=0; | 864 | | #endif | 865 | 18.9k | uint32_t required_buffer_size=0; | 866 | | | 867 | | #ifdef PROFILE | 868 | | int64_t count = faad_get_ts(); | 869 | | #endif | 870 | | | 871 | | /* safety checks */ | 872 | 18.9k | 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 | 18.9k | frame_len = hDecoder->frameLength; | 882 | | | 883 | | | 884 | 18.9k | memset(hInfo, 0, sizeof(NeAACDecFrameInfo)); | 885 | 18.9k | 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 | 18.9k | if (buffer_size >= 128) | 903 | 2.80k | { | 904 | 2.80k | 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.80k | } | 912 | | | 913 | | | 914 | | /* initialize the bitstream */ | 915 | 18.9k | faad_initbits(&ld, buffer, buffer_size); | 916 | 18.9k | if (ld.error != 0) | 917 | 7.60k | 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 | 11.3k | #ifdef DRM | 951 | 11.3k | if (hDecoder->object_type == DRM_ER_LC) | 952 | 1.00k | { | 953 | | /* We do not support stereo right now */ | 954 | 1.00k | if (0) //(hDecoder->channelConfiguration == 2) | 955 | 0 | { | 956 | 0 | hInfo->error = 28; // Throw CRC error | 957 | 0 | goto error; | 958 | 0 | } | 959 | | | 960 | 1.00k | faad_getbits(&ld, 8 | 961 | 1.00k | DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC")); | 962 | 1.00k | } | 963 | 11.3k | #endif | 964 | | | 965 | 11.3k | if (hDecoder->adts_header_present) | 966 | 88 | { | 967 | 88 | adts_header adts; | 968 | | | 969 | 88 | adts.old_format = hDecoder->config.useOldADTSFormat; | 970 | 88 | 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 | 88 | } | 978 | | | 979 | | #ifdef ANALYSIS | 980 | | dbg_count = 0; | 981 | | #endif | 982 | | | 983 | | /* decode the complete bitstream */ | 984 | 11.3k | #ifdef DRM | 985 | 11.3k | if (/*(hDecoder->object_type == 6) ||*/ hDecoder->object_type == DRM_ER_LC) | 986 | 1.00k | { | 987 | 1.00k | DRM_aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); | 988 | 10.3k | } else { | 989 | 10.3k | #endif | 990 | 10.3k | raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); | 991 | 10.3k | #ifdef DRM | 992 | 10.3k | } | 993 | 11.3k | #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 | 11.3k | channels = hDecoder->fr_channels; | 1009 | | | 1010 | 11.3k | if (hInfo->error > 0) | 1011 | 7.57k | goto error; | 1012 | | | 1013 | | /* safety check */ | 1014 | 3.76k | if (channels == 0 || channels > MAX_CHANNELS) | 1015 | 34 | { | 1016 | | /* invalid number of channels */ | 1017 | 34 | hInfo->error = 12; | 1018 | 34 | goto error; | 1019 | 34 | } | 1020 | | | 1021 | | /* no more bit reading after this */ | 1022 | 3.73k | bitsconsumed = faad_get_processed_bits(&ld); | 1023 | 3.73k | hInfo->bytesconsumed = bit2byte(bitsconsumed); | 1024 | 3.73k | if (ld.error) | 1025 | 0 | { | 1026 | 0 | hInfo->error = 14; | 1027 | 0 | goto error; | 1028 | 0 | } | 1029 | 3.73k | faad_endbits(&ld); | 1030 | | | 1031 | | | 1032 | 3.73k | if (!hDecoder->adts_header_present && !hDecoder->adif_header_present | 1033 | | #if 0 | 1034 | | && !hDecoder->latm_header_present | 1035 | | #endif | 1036 | 3.73k | ) | 1037 | 3.69k | { | 1038 | 3.69k | if (hDecoder->channelConfiguration == 0) | 1039 | 156 | hDecoder->channelConfiguration = channels; | 1040 | | | 1041 | 3.69k | if (channels == 8) /* 7.1 */ | 1042 | 172 | hDecoder->channelConfiguration = 7; | 1043 | 3.69k | if (channels == 7) /* not a standard channelConfiguration */ | 1044 | 0 | hDecoder->channelConfiguration = 0; | 1045 | 3.69k | } | 1046 | | | 1047 | 3.73k | if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix) | 1048 | 513 | { | 1049 | 513 | hDecoder->downMatrix = 1; | 1050 | 513 | output_channels = 2; | 1051 | 3.21k | } else { | 1052 | 3.21k | output_channels = channels; | 1053 | 3.21k | } | 1054 | | | 1055 | 3.73k | #if (defined(PS_DEC) || defined(DRM_PS)) | 1056 | 3.73k | hDecoder->upMatrix = 0; | 1057 | | /* check if we have a mono file */ | 1058 | 3.73k | 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.73k | #endif | 1065 | | | 1066 | | /* Make a channel configuration based on either a PCE or a channelConfiguration */ | 1067 | 3.73k | if (!hDecoder->downMatrix && hDecoder->pce_set) | 1068 | 175 | { | 1069 | | /* In some codepath program_config_element result is ignored. */ | 1070 | 175 | if (hDecoder->pce.channels > MAX_CHANNELS) | 1071 | 3 | { | 1072 | 3 | hInfo->error = 22; | 1073 | 3 | return NULL; | 1074 | 3 | } | 1075 | 175 | } | 1076 | 3.72k | create_channel_config(hDecoder, hInfo); | 1077 | | | 1078 | | /* number of samples in this frame */ | 1079 | 3.72k | hInfo->samples = frame_len*output_channels; | 1080 | | /* number of channels in this frame */ | 1081 | 3.72k | hInfo->channels = output_channels; | 1082 | | /* samplerate */ | 1083 | 3.72k | hInfo->samplerate = get_sample_rate(hDecoder->sf_index); | 1084 | | /* object type */ | 1085 | 3.72k | hInfo->object_type = hDecoder->object_type; | 1086 | | /* sbr */ | 1087 | 3.72k | hInfo->sbr = NO_SBR; | 1088 | | /* header type */ | 1089 | 3.72k | hInfo->header_type = RAW; | 1090 | 3.72k | if (hDecoder->adif_header_present) | 1091 | 0 | hInfo->header_type = ADIF; | 1092 | 3.72k | if (hDecoder->adts_header_present) | 1093 | 40 | hInfo->header_type = ADTS; | 1094 | | #if 0 | 1095 | | if (hDecoder->latm_header_present) | 1096 | | hInfo->header_type = LATM; | 1097 | | #endif | 1098 | 3.72k | #if (defined(PS_DEC) || defined(DRM_PS)) | 1099 | 3.72k | hInfo->ps = hDecoder->ps_used_global; | 1100 | 3.72k | #endif | 1101 | | | 1102 | | /* check if frame has channel elements */ | 1103 | 3.72k | if (channels == 0) | 1104 | 0 | { | 1105 | 0 | hDecoder->frame++; | 1106 | 0 | return NULL; | 1107 | 0 | } | 1108 | | | 1109 | 3.72k | { | 1110 | 3.72k | static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t), | 1111 | 3.72k | sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t), | 1112 | 3.72k | sizeof(int16_t), sizeof(int16_t), 0, 0, 0 | 1113 | 3.72k | }; | 1114 | 3.72k | uint8_t stride = str[hDecoder->config.outputFormat-1]; | 1115 | 3.72k | #ifdef SBR_DEC | 1116 | 3.72k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1)) | 1117 | 2.07k | { | 1118 | 2.07k | stride = 2 * stride; | 1119 | 2.07k | } | 1120 | 3.72k | #endif | 1121 | 3.72k | required_buffer_size = frame_len*output_channels*stride; | 1122 | 3.72k | } | 1123 | | | 1124 | | /* check if we want to use internal sample_buffer */ | 1125 | 3.72k | if (sample_buffer_size == 0) | 1126 | 1.96k | { | 1127 | | /* allocate the buffer for the final samples */ | 1128 | 1.96k | if (hDecoder->sample_buffer_size != required_buffer_size) | 1129 | 1.73k | { | 1130 | 1.73k | if (hDecoder->sample_buffer) | 1131 | 50 | faad_free(hDecoder->sample_buffer); | 1132 | 1.73k | hDecoder->sample_buffer = NULL; | 1133 | 1.73k | hDecoder->sample_buffer = faad_malloc(required_buffer_size); | 1134 | 1.73k | hDecoder->sample_buffer_size = required_buffer_size; | 1135 | 1.73k | } | 1136 | 1.96k | } else if (sample_buffer_size < required_buffer_size) { | 1137 | | /* provided sample buffer is not big enough */ | 1138 | 687 | hInfo->error = 27; | 1139 | 687 | return NULL; | 1140 | 687 | } | 1141 | | | 1142 | 3.04k | if (sample_buffer_size == 0) | 1143 | 1.96k | { | 1144 | 1.96k | sample_buffer = hDecoder->sample_buffer; | 1145 | 1.96k | } else { | 1146 | 1.07k | sample_buffer = *sample_buffer2; | 1147 | 1.07k | } | 1148 | | | 1149 | 3.04k | #ifdef SBR_DEC | 1150 | 3.04k | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | 1151 | 2.22k | { | 1152 | 2.22k | uint8_t ele; | 1153 | | | 1154 | | /* this data is different when SBR is used or when the data is upsampled */ | 1155 | 2.22k | if (!hDecoder->downSampledSBR) | 1156 | 1.55k | { | 1157 | 1.55k | frame_len *= 2; | 1158 | 1.55k | hInfo->samples *= 2; | 1159 | 1.55k | hInfo->samplerate *= 2; | 1160 | 1.55k | } | 1161 | | | 1162 | | /* check if every element was provided with SBR data */ | 1163 | 11.6k | for (ele = 0; ele < hDecoder->fr_ch_ele; ele++) | 1164 | 9.45k | { | 1165 | 9.45k | if (hDecoder->sbr[ele] == NULL) | 1166 | 1 | { | 1167 | 1 | hInfo->error = 25; | 1168 | 1 | goto error; | 1169 | 1 | } | 1170 | 9.45k | } | 1171 | | | 1172 | | /* sbr */ | 1173 | 2.22k | if (hDecoder->sbr_present_flag == 1) | 1174 | 1.74k | { | 1175 | 1.74k | hInfo->object_type = HE_AAC; | 1176 | 1.74k | hInfo->sbr = SBR_UPSAMPLED; | 1177 | 1.74k | } else { | 1178 | 481 | hInfo->sbr = NO_SBR_UPSAMPLED; | 1179 | 481 | } | 1180 | 2.22k | if (hDecoder->downSampledSBR) | 1181 | 663 | { | 1182 | 663 | hInfo->sbr = SBR_DOWNSAMPLED; | 1183 | 663 | } | 1184 | 2.22k | } | 1185 | 3.04k | #endif | 1186 | | | 1187 | | | 1188 | 3.04k | sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer, | 1189 | 3.04k | output_channels, frame_len, hDecoder->config.outputFormat); | 1190 | | | 1191 | | | 1192 | 3.04k | #ifdef DRM | 1193 | | //conceal_output(hDecoder, frame_len, output_channels, sample_buffer); | 1194 | 3.04k | #endif | 1195 | | | 1196 | | | 1197 | 3.04k | hDecoder->postSeekResetFlag = 0; | 1198 | | | 1199 | 3.04k | hDecoder->frame++; | 1200 | | #ifdef LD_DEC | 1201 | | if (hDecoder->object_type != LD) | 1202 | | { | 1203 | | #endif | 1204 | 3.04k | if (hDecoder->frame <= 1) | 1205 | 1.17k | 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 | 3.04k | return sample_buffer; | 1225 | | | 1226 | 7.61k | error: | 1227 | | | 1228 | | /* reset filterbank state */ | 1229 | 495k | for (i = 0; i < MAX_CHANNELS; i++) | 1230 | 487k | { | 1231 | 487k | if (hDecoder->fb_intermed[i] != NULL) | 1232 | 186k | { | 1233 | 186k | memset(hDecoder->fb_intermed[i], 0, hDecoder->frameLength*sizeof(real_t)); | 1234 | 186k | } | 1235 | 487k | } | 1236 | 7.61k | #ifdef SBR_DEC | 1237 | 373k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 1238 | 365k | { | 1239 | 365k | if (hDecoder->sbr[i] != NULL) | 1240 | 140k | { | 1241 | 140k | sbrReset(hDecoder->sbr[i]); | 1242 | 140k | } | 1243 | 365k | } | 1244 | 7.61k | #endif | 1245 | | | 1246 | | | 1247 | 7.61k | faad_endbits(&ld); | 1248 | | | 1249 | | /* cleanup */ | 1250 | | #ifdef ANALYSIS | 1251 | | fflush(stdout); | 1252 | | #endif | 1253 | | | 1254 | 7.61k | return NULL; | 1255 | 3.04k | } |
decoder.c:aac_frame_decode Line | Count | Source | 854 | 35.9k | { | 855 | 35.9k | uint16_t i; | 856 | 35.9k | uint8_t channels = 0; | 857 | 35.9k | uint8_t output_channels = 0; | 858 | 35.9k | bitfile ld; | 859 | 35.9k | uint32_t bitsconsumed; | 860 | 35.9k | uint16_t frame_len; | 861 | 35.9k | void *sample_buffer; | 862 | | #if 0 | 863 | | uint32_t startbit=0, endbit=0, payload_bits=0; | 864 | | #endif | 865 | 35.9k | uint32_t required_buffer_size=0; | 866 | | | 867 | | #ifdef PROFILE | 868 | | int64_t count = faad_get_ts(); | 869 | | #endif | 870 | | | 871 | | /* safety checks */ | 872 | 35.9k | 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 | 35.9k | frame_len = hDecoder->frameLength; | 882 | | | 883 | | | 884 | 35.9k | memset(hInfo, 0, sizeof(NeAACDecFrameInfo)); | 885 | 35.9k | 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 | 35.9k | if (buffer_size >= 128) | 903 | 3.32k | { | 904 | 3.32k | 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.32k | } | 912 | | | 913 | | | 914 | | /* initialize the bitstream */ | 915 | 35.9k | faad_initbits(&ld, buffer, buffer_size); | 916 | 35.9k | if (ld.error != 0) | 917 | 14.5k | 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 | 21.3k | if (hDecoder->adts_header_present) | 966 | 693 | { | 967 | 693 | adts_header adts; | 968 | | | 969 | 693 | adts.old_format = hDecoder->config.useOldADTSFormat; | 970 | 693 | if ((hInfo->error = adts_frame(&adts, &ld)) > 0) | 971 | 102 | 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 | 693 | } | 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 | 21.2k | 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 | 21.2k | channels = hDecoder->fr_channels; | 1009 | | | 1010 | 21.2k | if (hInfo->error > 0) | 1011 | 14.4k | goto error; | 1012 | | | 1013 | | /* safety check */ | 1014 | 6.79k | if (channels == 0 || channels > MAX_CHANNELS) | 1015 | 60 | { | 1016 | | /* invalid number of channels */ | 1017 | 60 | hInfo->error = 12; | 1018 | 60 | goto error; | 1019 | 60 | } | 1020 | | | 1021 | | /* no more bit reading after this */ | 1022 | 6.73k | bitsconsumed = faad_get_processed_bits(&ld); | 1023 | 6.73k | hInfo->bytesconsumed = bit2byte(bitsconsumed); | 1024 | 6.73k | if (ld.error) | 1025 | 0 | { | 1026 | 0 | hInfo->error = 14; | 1027 | 0 | goto error; | 1028 | 0 | } | 1029 | 6.73k | faad_endbits(&ld); | 1030 | | | 1031 | | | 1032 | 6.73k | if (!hDecoder->adts_header_present && !hDecoder->adif_header_present | 1033 | | #if 0 | 1034 | | && !hDecoder->latm_header_present | 1035 | | #endif | 1036 | 6.73k | ) | 1037 | 6.56k | { | 1038 | 6.56k | if (hDecoder->channelConfiguration == 0) | 1039 | 163 | hDecoder->channelConfiguration = channels; | 1040 | | | 1041 | 6.56k | if (channels == 8) /* 7.1 */ | 1042 | 744 | hDecoder->channelConfiguration = 7; | 1043 | 6.56k | if (channels == 7) /* not a standard channelConfiguration */ | 1044 | 57 | hDecoder->channelConfiguration = 0; | 1045 | 6.56k | } | 1046 | | | 1047 | 6.73k | if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix) | 1048 | 597 | { | 1049 | 597 | hDecoder->downMatrix = 1; | 1050 | 597 | output_channels = 2; | 1051 | 6.13k | } else { | 1052 | 6.13k | output_channels = channels; | 1053 | 6.13k | } | 1054 | | | 1055 | 6.73k | #if (defined(PS_DEC) || defined(DRM_PS)) | 1056 | 6.73k | hDecoder->upMatrix = 0; | 1057 | | /* check if we have a mono file */ | 1058 | 6.73k | if (output_channels == 1) | 1059 | 297 | { | 1060 | | /* upMatrix to 2 channels for implicit signalling of PS */ | 1061 | 297 | hDecoder->upMatrix = 1; | 1062 | 297 | output_channels = 2; | 1063 | 297 | } | 1064 | 6.73k | #endif | 1065 | | | 1066 | | /* Make a channel configuration based on either a PCE or a channelConfiguration */ | 1067 | 6.73k | if (!hDecoder->downMatrix && hDecoder->pce_set) | 1068 | 189 | { | 1069 | | /* In some codepath program_config_element result is ignored. */ | 1070 | 189 | if (hDecoder->pce.channels > MAX_CHANNELS) | 1071 | 6 | { | 1072 | 6 | hInfo->error = 22; | 1073 | 6 | return NULL; | 1074 | 6 | } | 1075 | 189 | } | 1076 | 6.72k | create_channel_config(hDecoder, hInfo); | 1077 | | | 1078 | | /* number of samples in this frame */ | 1079 | 6.72k | hInfo->samples = frame_len*output_channels; | 1080 | | /* number of channels in this frame */ | 1081 | 6.72k | hInfo->channels = output_channels; | 1082 | | /* samplerate */ | 1083 | 6.72k | hInfo->samplerate = get_sample_rate(hDecoder->sf_index); | 1084 | | /* object type */ | 1085 | 6.72k | hInfo->object_type = hDecoder->object_type; | 1086 | | /* sbr */ | 1087 | 6.72k | hInfo->sbr = NO_SBR; | 1088 | | /* header type */ | 1089 | 6.72k | hInfo->header_type = RAW; | 1090 | 6.72k | if (hDecoder->adif_header_present) | 1091 | 0 | hInfo->header_type = ADIF; | 1092 | 6.72k | if (hDecoder->adts_header_present) | 1093 | 168 | hInfo->header_type = ADTS; | 1094 | | #if 0 | 1095 | | if (hDecoder->latm_header_present) | 1096 | | hInfo->header_type = LATM; | 1097 | | #endif | 1098 | 6.72k | #if (defined(PS_DEC) || defined(DRM_PS)) | 1099 | 6.72k | hInfo->ps = hDecoder->ps_used_global; | 1100 | 6.72k | #endif | 1101 | | | 1102 | | /* check if frame has channel elements */ | 1103 | 6.72k | if (channels == 0) | 1104 | 0 | { | 1105 | 0 | hDecoder->frame++; | 1106 | 0 | return NULL; | 1107 | 0 | } | 1108 | | | 1109 | 6.72k | { | 1110 | 6.72k | static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t), | 1111 | 6.72k | sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t), | 1112 | 6.72k | sizeof(int16_t), sizeof(int16_t), 0, 0, 0 | 1113 | 6.72k | }; | 1114 | 6.72k | uint8_t stride = str[hDecoder->config.outputFormat-1]; | 1115 | 6.72k | #ifdef SBR_DEC | 1116 | 6.72k | if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1)) | 1117 | 3.88k | { | 1118 | 3.88k | stride = 2 * stride; | 1119 | 3.88k | } | 1120 | 6.72k | #endif | 1121 | 6.72k | required_buffer_size = frame_len*output_channels*stride; | 1122 | 6.72k | } | 1123 | | | 1124 | | /* check if we want to use internal sample_buffer */ | 1125 | 6.72k | if (sample_buffer_size == 0) | 1126 | 5.19k | { | 1127 | | /* allocate the buffer for the final samples */ | 1128 | 5.19k | if (hDecoder->sample_buffer_size != required_buffer_size) | 1129 | 4.48k | { | 1130 | 4.48k | if (hDecoder->sample_buffer) | 1131 | 51 | faad_free(hDecoder->sample_buffer); | 1132 | 4.48k | hDecoder->sample_buffer = NULL; | 1133 | 4.48k | hDecoder->sample_buffer = faad_malloc(required_buffer_size); | 1134 | 4.48k | hDecoder->sample_buffer_size = required_buffer_size; | 1135 | 4.48k | } | 1136 | 5.19k | } else if (sample_buffer_size < required_buffer_size) { | 1137 | | /* provided sample buffer is not big enough */ | 1138 | 655 | hInfo->error = 27; | 1139 | 655 | return NULL; | 1140 | 655 | } | 1141 | | | 1142 | 6.07k | if (sample_buffer_size == 0) | 1143 | 5.19k | { | 1144 | 5.19k | sample_buffer = hDecoder->sample_buffer; | 1145 | 5.19k | } else { | 1146 | 878 | sample_buffer = *sample_buffer2; | 1147 | 878 | } | 1148 | | | 1149 | 6.07k | #ifdef SBR_DEC | 1150 | 6.07k | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | 1151 | 4.10k | { | 1152 | 4.10k | uint8_t ele; | 1153 | | | 1154 | | /* this data is different when SBR is used or when the data is upsampled */ | 1155 | 4.10k | if (!hDecoder->downSampledSBR) | 1156 | 3.44k | { | 1157 | 3.44k | frame_len *= 2; | 1158 | 3.44k | hInfo->samples *= 2; | 1159 | 3.44k | hInfo->samplerate *= 2; | 1160 | 3.44k | } | 1161 | | | 1162 | | /* check if every element was provided with SBR data */ | 1163 | 20.3k | for (ele = 0; ele < hDecoder->fr_ch_ele; ele++) | 1164 | 16.2k | { | 1165 | 16.2k | if (hDecoder->sbr[ele] == NULL) | 1166 | 7 | { | 1167 | 7 | hInfo->error = 25; | 1168 | 7 | goto error; | 1169 | 7 | } | 1170 | 16.2k | } | 1171 | | | 1172 | | /* sbr */ | 1173 | 4.09k | if (hDecoder->sbr_present_flag == 1) | 1174 | 2.31k | { | 1175 | 2.31k | hInfo->object_type = HE_AAC; | 1176 | 2.31k | hInfo->sbr = SBR_UPSAMPLED; | 1177 | 2.31k | } else { | 1178 | 1.78k | hInfo->sbr = NO_SBR_UPSAMPLED; | 1179 | 1.78k | } | 1180 | 4.09k | if (hDecoder->downSampledSBR) | 1181 | 651 | { | 1182 | 651 | hInfo->sbr = SBR_DOWNSAMPLED; | 1183 | 651 | } | 1184 | 4.09k | } | 1185 | 6.06k | #endif | 1186 | | | 1187 | | | 1188 | 6.06k | sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer, | 1189 | 6.06k | 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 | 6.06k | hDecoder->postSeekResetFlag = 0; | 1198 | | | 1199 | 6.06k | hDecoder->frame++; | 1200 | 6.06k | #ifdef LD_DEC | 1201 | 6.06k | if (hDecoder->object_type != LD) | 1202 | 5.31k | { | 1203 | 5.31k | #endif | 1204 | 5.31k | if (hDecoder->frame <= 1) | 1205 | 1.93k | hInfo->samples = 0; | 1206 | 5.31k | #ifdef LD_DEC | 1207 | 5.31k | } else { | 1208 | | /* LD encoders will give lower delay */ | 1209 | 755 | if (hDecoder->frame <= 0) | 1210 | 0 | hInfo->samples = 0; | 1211 | 755 | } | 1212 | 6.06k | #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 | 6.06k | return sample_buffer; | 1225 | | | 1226 | 14.6k | error: | 1227 | | | 1228 | | /* reset filterbank state */ | 1229 | 951k | for (i = 0; i < MAX_CHANNELS; i++) | 1230 | 936k | { | 1231 | 936k | if (hDecoder->fb_intermed[i] != NULL) | 1232 | 525k | { | 1233 | 525k | memset(hDecoder->fb_intermed[i], 0, hDecoder->frameLength*sizeof(real_t)); | 1234 | 525k | } | 1235 | 936k | } | 1236 | 14.6k | #ifdef SBR_DEC | 1237 | 717k | for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | 1238 | 702k | { | 1239 | 702k | if (hDecoder->sbr[i] != NULL) | 1240 | 369k | { | 1241 | 369k | sbrReset(hDecoder->sbr[i]); | 1242 | 369k | } | 1243 | 702k | } | 1244 | 14.6k | #endif | 1245 | | | 1246 | | | 1247 | 14.6k | faad_endbits(&ld); | 1248 | | | 1249 | | /* cleanup */ | 1250 | | #ifdef ANALYSIS | 1251 | | fflush(stdout); | 1252 | | #endif | 1253 | | | 1254 | 14.6k | return NULL; | 1255 | 6.07k | } |
|