Coverage Report

Created: 2026-10-28 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/libfaad/decoder.c
Line
Count
Source
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
379
{
74
379
    static char *libfaadName = PACKAGE_VERSION;
75
379
    static char *libCopyright =
76
379
        " Copyright 2002-2004: Ahead Software AG\n"
77
379
  " http://www.audiocoding.com\n"
78
379
  " bug tracking: https://sourceforge.net/p/faac/bugs/\n";
79
80
379
    if (faad_id_string)
81
379
        *faad_id_string = libfaadName;
82
83
379
    if (faad_copyright_string)
84
379
        *faad_copyright_string = libCopyright;
85
86
379
    return 0;
87
379
}
88
89
char* NeAACDecGetErrorMessage(unsigned char errcode)
90
379
{
91
379
    if (errcode >= NUM_ERROR_MESSAGES)
92
274
        return NULL;
93
105
    return err_msg[errcode];
94
379
}
95
96
unsigned long NeAACDecGetCapabilities(void)
97
1.51k
{
98
1.51k
    uint32_t cap = 0;
99
100
    /* can't do without it */
101
1.51k
    cap += LC_DEC_CAP;
102
103
#ifdef MAIN_DEC
104
379
    cap += MAIN_DEC_CAP;
105
#endif
106
#ifdef LTP_DEC
107
758
    cap += LTP_DEC_CAP;
108
#endif
109
#ifdef LD_DEC
110
758
    cap += LD_DEC_CAP;
111
#endif
112
1.51k
#ifdef ERROR_RESILIENCE
113
1.51k
    cap += ERROR_RESILIENCE_CAP;
114
1.51k
#endif
115
#ifdef FIXED_POINT
116
758
    cap += FIXED_POINT_CAP;
117
#endif
118
119
1.51k
    return cap;
120
1.51k
}
NeAACDecGetCapabilities
Line
Count
Source
97
379
{
98
379
    uint32_t cap = 0;
99
100
    /* can't do without it */
101
379
    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
379
#ifdef ERROR_RESILIENCE
113
379
    cap += ERROR_RESILIENCE_CAP;
114
379
#endif
115
379
#ifdef FIXED_POINT
116
379
    cap += FIXED_POINT_CAP;
117
379
#endif
118
119
379
    return cap;
120
379
}
NeAACDecGetCapabilities
Line
Count
Source
97
379
{
98
379
    uint32_t cap = 0;
99
100
    /* can't do without it */
101
379
    cap += LC_DEC_CAP;
102
103
379
#ifdef MAIN_DEC
104
379
    cap += MAIN_DEC_CAP;
105
379
#endif
106
379
#ifdef LTP_DEC
107
379
    cap += LTP_DEC_CAP;
108
379
#endif
109
379
#ifdef LD_DEC
110
379
    cap += LD_DEC_CAP;
111
379
#endif
112
379
#ifdef ERROR_RESILIENCE
113
379
    cap += ERROR_RESILIENCE_CAP;
114
379
#endif
115
#ifdef FIXED_POINT
116
    cap += FIXED_POINT_CAP;
117
#endif
118
119
379
    return cap;
120
379
}
NeAACDecGetCapabilities
Line
Count
Source
97
379
{
98
379
    uint32_t cap = 0;
99
100
    /* can't do without it */
101
379
    cap += LC_DEC_CAP;
102
103
#ifdef MAIN_DEC
104
    cap += MAIN_DEC_CAP;
105
#endif
106
379
#ifdef LTP_DEC
107
379
    cap += LTP_DEC_CAP;
108
379
#endif
109
379
#ifdef LD_DEC
110
379
    cap += LD_DEC_CAP;
111
379
#endif
112
379
#ifdef ERROR_RESILIENCE
113
379
    cap += ERROR_RESILIENCE_CAP;
114
379
#endif
115
379
#ifdef FIXED_POINT
116
379
    cap += FIXED_POINT_CAP;
117
379
#endif
118
119
379
    return cap;
120
379
}
NeAACDecGetCapabilities
Line
Count
Source
97
379
{
98
379
    uint32_t cap = 0;
99
100
    /* can't do without it */
101
379
    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
379
#ifdef ERROR_RESILIENCE
113
379
    cap += ERROR_RESILIENCE_CAP;
114
379
#endif
115
#ifdef FIXED_POINT
116
    cap += FIXED_POINT_CAP;
117
#endif
118
119
379
    return cap;
120
379
}
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
69.8k
{
125
69.8k
    uint8_t i;
126
69.8k
    NeAACDecStruct *hDecoder = NULL;
127
128
69.8k
    if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL)
129
0
        return NULL;
130
131
69.8k
    memset(hDecoder, 0, sizeof(NeAACDecStruct));
132
133
69.8k
    hDecoder->cmes = mes;
134
69.8k
    hDecoder->config.outputFormat  = FAAD_FMT_16BIT;
135
69.8k
    hDecoder->config.defObjectType = MAIN;
136
69.8k
    hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */
137
69.8k
    hDecoder->config.downMatrix = 0;
138
69.8k
    hDecoder->adts_header_present = 0;
139
69.8k
    hDecoder->adif_header_present = 0;
140
69.8k
    hDecoder->latm_header_present = 0;
141
69.8k
#ifdef ERROR_RESILIENCE
142
69.8k
    hDecoder->aacSectionDataResilienceFlag = 0;
143
69.8k
    hDecoder->aacScalefactorDataResilienceFlag = 0;
144
69.8k
    hDecoder->aacSpectralDataResilienceFlag = 0;
145
69.8k
#endif
146
69.8k
    hDecoder->frameLength = 1024;
147
148
69.8k
    hDecoder->frame = 0;
149
69.8k
    hDecoder->sample_buffer = NULL;
150
151
    // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all.
152
69.8k
    hDecoder->__r1 = 0x2bb431ea;
153
69.8k
    hDecoder->__r2 = 0x206155b7;
154
155
4.53M
    for (i = 0; i < MAX_CHANNELS; i++)
156
4.46M
    {
157
4.46M
        hDecoder->element_id[i] = INVALID_ELEMENT_ID;
158
4.46M
        hDecoder->window_shape_prev[i] = 0;
159
4.46M
        hDecoder->time_out[i] = NULL;
160
4.46M
        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
4.46M
    }
173
174
69.8k
#ifdef SBR_DEC
175
3.42M
    for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
176
3.35M
    {
177
3.35M
        hDecoder->sbr[i] = NULL;
178
3.35M
    }
179
69.8k
#endif
180
181
69.8k
    hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0));
182
69.8k
#if (defined(PS_DEC) || defined(DRM_PS))
183
69.8k
    hDecoder->ps_present_flag = -1;
184
69.8k
#endif
185
186
69.8k
    return hDecoder;
187
69.8k
}
NeAACDecOpen
Line
Count
Source
124
17.2k
{
125
17.2k
    uint8_t i;
126
17.2k
    NeAACDecStruct *hDecoder = NULL;
127
128
17.2k
    if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL)
129
0
        return NULL;
130
131
17.2k
    memset(hDecoder, 0, sizeof(NeAACDecStruct));
132
133
17.2k
    hDecoder->cmes = mes;
134
17.2k
    hDecoder->config.outputFormat  = FAAD_FMT_16BIT;
135
17.2k
    hDecoder->config.defObjectType = MAIN;
136
17.2k
    hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */
137
17.2k
    hDecoder->config.downMatrix = 0;
138
17.2k
    hDecoder->adts_header_present = 0;
139
17.2k
    hDecoder->adif_header_present = 0;
140
17.2k
    hDecoder->latm_header_present = 0;
141
17.2k
#ifdef ERROR_RESILIENCE
142
17.2k
    hDecoder->aacSectionDataResilienceFlag = 0;
143
17.2k
    hDecoder->aacScalefactorDataResilienceFlag = 0;
144
17.2k
    hDecoder->aacSpectralDataResilienceFlag = 0;
145
17.2k
#endif
146
17.2k
    hDecoder->frameLength = 1024;
147
148
17.2k
    hDecoder->frame = 0;
149
17.2k
    hDecoder->sample_buffer = NULL;
150
151
    // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all.
152
17.2k
    hDecoder->__r1 = 0x2bb431ea;
153
17.2k
    hDecoder->__r2 = 0x206155b7;
154
155
1.12M
    for (i = 0; i < MAX_CHANNELS; i++)
156
1.10M
    {
157
1.10M
        hDecoder->element_id[i] = INVALID_ELEMENT_ID;
158
1.10M
        hDecoder->window_shape_prev[i] = 0;
159
1.10M
        hDecoder->time_out[i] = NULL;
160
1.10M
        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.10M
    }
173
174
17.2k
#ifdef SBR_DEC
175
844k
    for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
176
827k
    {
177
827k
        hDecoder->sbr[i] = NULL;
178
827k
    }
179
17.2k
#endif
180
181
17.2k
    hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0));
182
17.2k
#if (defined(PS_DEC) || defined(DRM_PS))
183
17.2k
    hDecoder->ps_present_flag = -1;
184
17.2k
#endif
185
186
17.2k
    return hDecoder;
187
17.2k
}
NeAACDecOpen
Line
Count
Source
124
17.6k
{
125
17.6k
    uint8_t i;
126
17.6k
    NeAACDecStruct *hDecoder = NULL;
127
128
17.6k
    if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL)
129
0
        return NULL;
130
131
17.6k
    memset(hDecoder, 0, sizeof(NeAACDecStruct));
132
133
17.6k
    hDecoder->cmes = mes;
134
17.6k
    hDecoder->config.outputFormat  = FAAD_FMT_16BIT;
135
17.6k
    hDecoder->config.defObjectType = MAIN;
136
17.6k
    hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */
137
17.6k
    hDecoder->config.downMatrix = 0;
138
17.6k
    hDecoder->adts_header_present = 0;
139
17.6k
    hDecoder->adif_header_present = 0;
140
17.6k
    hDecoder->latm_header_present = 0;
141
17.6k
#ifdef ERROR_RESILIENCE
142
17.6k
    hDecoder->aacSectionDataResilienceFlag = 0;
143
17.6k
    hDecoder->aacScalefactorDataResilienceFlag = 0;
144
17.6k
    hDecoder->aacSpectralDataResilienceFlag = 0;
145
17.6k
#endif
146
17.6k
    hDecoder->frameLength = 1024;
147
148
17.6k
    hDecoder->frame = 0;
149
17.6k
    hDecoder->sample_buffer = NULL;
150
151
    // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all.
152
17.6k
    hDecoder->__r1 = 0x2bb431ea;
153
17.6k
    hDecoder->__r2 = 0x206155b7;
154
155
1.14M
    for (i = 0; i < MAX_CHANNELS; i++)
156
1.13M
    {
157
1.13M
        hDecoder->element_id[i] = INVALID_ELEMENT_ID;
158
1.13M
        hDecoder->window_shape_prev[i] = 0;
159
1.13M
        hDecoder->time_out[i] = NULL;
160
1.13M
        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.13M
#ifdef MAIN_DEC
166
1.13M
        hDecoder->pred_stat[i] = NULL;
167
1.13M
#endif
168
1.13M
#ifdef LTP_DEC
169
1.13M
        hDecoder->ltp_lag[i] = 0;
170
1.13M
        hDecoder->lt_pred_stat[i] = NULL;
171
1.13M
#endif
172
1.13M
    }
173
174
17.6k
#ifdef SBR_DEC
175
866k
    for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
176
848k
    {
177
848k
        hDecoder->sbr[i] = NULL;
178
848k
    }
179
17.6k
#endif
180
181
17.6k
    hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0));
182
17.6k
#if (defined(PS_DEC) || defined(DRM_PS))
183
17.6k
    hDecoder->ps_present_flag = -1;
184
17.6k
#endif
185
186
17.6k
    return hDecoder;
187
17.6k
}
NeAACDecOpen
Line
Count
Source
124
17.2k
{
125
17.2k
    uint8_t i;
126
17.2k
    NeAACDecStruct *hDecoder = NULL;
127
128
17.2k
    if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL)
129
0
        return NULL;
130
131
17.2k
    memset(hDecoder, 0, sizeof(NeAACDecStruct));
132
133
17.2k
    hDecoder->cmes = mes;
134
17.2k
    hDecoder->config.outputFormat  = FAAD_FMT_16BIT;
135
17.2k
    hDecoder->config.defObjectType = MAIN;
136
17.2k
    hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */
137
17.2k
    hDecoder->config.downMatrix = 0;
138
17.2k
    hDecoder->adts_header_present = 0;
139
17.2k
    hDecoder->adif_header_present = 0;
140
17.2k
    hDecoder->latm_header_present = 0;
141
17.2k
#ifdef ERROR_RESILIENCE
142
17.2k
    hDecoder->aacSectionDataResilienceFlag = 0;
143
17.2k
    hDecoder->aacScalefactorDataResilienceFlag = 0;
144
17.2k
    hDecoder->aacSpectralDataResilienceFlag = 0;
145
17.2k
#endif
146
17.2k
    hDecoder->frameLength = 1024;
147
148
17.2k
    hDecoder->frame = 0;
149
17.2k
    hDecoder->sample_buffer = NULL;
150
151
    // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all.
152
17.2k
    hDecoder->__r1 = 0x2bb431ea;
153
17.2k
    hDecoder->__r2 = 0x206155b7;
154
155
1.12M
    for (i = 0; i < MAX_CHANNELS; i++)
156
1.10M
    {
157
1.10M
        hDecoder->element_id[i] = INVALID_ELEMENT_ID;
158
1.10M
        hDecoder->window_shape_prev[i] = 0;
159
1.10M
        hDecoder->time_out[i] = NULL;
160
1.10M
        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
1.10M
#ifdef LTP_DEC
169
1.10M
        hDecoder->ltp_lag[i] = 0;
170
1.10M
        hDecoder->lt_pred_stat[i] = NULL;
171
1.10M
#endif
172
1.10M
    }
173
174
17.2k
#ifdef SBR_DEC
175
844k
    for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
176
827k
    {
177
827k
        hDecoder->sbr[i] = NULL;
178
827k
    }
179
17.2k
#endif
180
181
17.2k
    hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0));
182
17.2k
#if (defined(PS_DEC) || defined(DRM_PS))
183
17.2k
    hDecoder->ps_present_flag = -1;
184
17.2k
#endif
185
186
17.2k
    return hDecoder;
187
17.2k
}
NeAACDecOpen
Line
Count
Source
124
17.6k
{
125
17.6k
    uint8_t i;
126
17.6k
    NeAACDecStruct *hDecoder = NULL;
127
128
17.6k
    if ((hDecoder = (NeAACDecStruct*)faad_malloc(sizeof(NeAACDecStruct))) == NULL)
129
0
        return NULL;
130
131
17.6k
    memset(hDecoder, 0, sizeof(NeAACDecStruct));
132
133
17.6k
    hDecoder->cmes = mes;
134
17.6k
    hDecoder->config.outputFormat  = FAAD_FMT_16BIT;
135
17.6k
    hDecoder->config.defObjectType = MAIN;
136
17.6k
    hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */
137
17.6k
    hDecoder->config.downMatrix = 0;
138
17.6k
    hDecoder->adts_header_present = 0;
139
17.6k
    hDecoder->adif_header_present = 0;
140
17.6k
    hDecoder->latm_header_present = 0;
141
17.6k
#ifdef ERROR_RESILIENCE
142
17.6k
    hDecoder->aacSectionDataResilienceFlag = 0;
143
17.6k
    hDecoder->aacScalefactorDataResilienceFlag = 0;
144
17.6k
    hDecoder->aacSpectralDataResilienceFlag = 0;
145
17.6k
#endif
146
17.6k
    hDecoder->frameLength = 1024;
147
148
17.6k
    hDecoder->frame = 0;
149
17.6k
    hDecoder->sample_buffer = NULL;
150
151
    // Same as (1, 1) after 1024 iterations; otherwise first values does not look random at all.
152
17.6k
    hDecoder->__r1 = 0x2bb431ea;
153
17.6k
    hDecoder->__r2 = 0x206155b7;
154
155
1.14M
    for (i = 0; i < MAX_CHANNELS; i++)
156
1.13M
    {
157
1.13M
        hDecoder->element_id[i] = INVALID_ELEMENT_ID;
158
1.13M
        hDecoder->window_shape_prev[i] = 0;
159
1.13M
        hDecoder->time_out[i] = NULL;
160
1.13M
        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.13M
    }
173
174
17.6k
#ifdef SBR_DEC
175
866k
    for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
176
848k
    {
177
848k
        hDecoder->sbr[i] = NULL;
178
848k
    }
179
17.6k
#endif
180
181
17.6k
    hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0));
182
17.6k
#if (defined(PS_DEC) || defined(DRM_PS))
183
17.6k
    hDecoder->ps_present_flag = -1;
184
17.6k
#endif
185
186
17.6k
    return hDecoder;
187
17.6k
}
188
189
NeAACDecConfigurationPtr NeAACDecGetCurrentConfiguration(NeAACDecHandle hpDecoder)
190
33.3k
{
191
33.3k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
192
33.3k
    if (hDecoder)
193
33.3k
    {
194
33.3k
        NeAACDecConfigurationPtr config = &(hDecoder->config);
195
196
33.3k
        return config;
197
33.3k
    }
198
199
0
    return NULL;
200
33.3k
}
201
202
unsigned char NeAACDecSetConfiguration(NeAACDecHandle hpDecoder,
203
                                                   NeAACDecConfigurationPtr config)
204
33.6k
{
205
33.6k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
206
33.6k
    if (hDecoder && config)
207
33.6k
    {
208
        /* check if we can decode this object type */
209
33.6k
        if (can_decode_ot(config->defObjectType) < 0)
210
19
            return 0;
211
33.6k
        hDecoder->config.defObjectType = config->defObjectType;
212
213
        /* samplerate: anything but 0 should be possible */
214
33.6k
        if (config->defSampleRate == 0)
215
4
            return 0;
216
33.6k
        hDecoder->config.defSampleRate = config->defSampleRate;
217
218
        /* check output format */
219
33.6k
#ifdef FIXED_POINT
220
33.6k
        if ((config->outputFormat < 1) || (config->outputFormat > 4))
221
245
            return 0;
222
#else
223
        if ((config->outputFormat < 1) || (config->outputFormat > 5))
224
            return 0;
225
#endif
226
33.4k
        hDecoder->config.outputFormat = config->outputFormat;
227
228
33.4k
        if (config->downMatrix > 1)
229
36
            return 0;
230
33.3k
        hDecoder->config.downMatrix = config->downMatrix;
231
232
        /* OK */
233
33.3k
        return 1;
234
33.4k
    }
235
236
0
    return 0;
237
33.6k
}
238
239
240
#if 0
241
static int latmCheck(latm_header *latm, bitfile *ld)
242
{
243
    uint32_t good=0, bad=0, bits, m;
244
245
    while (ld->bytes_left)
246
    {
247
        bits = faad_latm_frame(latm, ld);
248
        if(bits==0xFFFFFFFF)
249
            bad++;
250
        else
251
        {
252
            good++;
253
            while(bits>0)
254
            {
255
                m = min(bits, 8);
256
                faad_getbits(ld, m);
257
                bits -= m;
258
            }
259
        }
260
    }
261
262
    return (good>0);
263
}
264
#endif
265
266
long NeAACDecInit(NeAACDecHandle hpDecoder,
267
                              unsigned char *buffer,
268
                              unsigned long buffer_size,
269
                              unsigned long *samplerate,
270
                              unsigned char *channels)
271
21.6k
{
272
21.6k
    uint32_t bits = 0;
273
21.6k
    bitfile ld;
274
21.6k
    adif_header adif;
275
21.6k
    adts_header adts;
276
21.6k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
277
278
279
21.6k
    if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL) || (buffer_size == 0))
280
60
        return -1;
281
282
21.5k
    adts.old_format = hDecoder->config.useOldADTSFormat;
283
21.5k
    hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate);
284
21.5k
    hDecoder->object_type = hDecoder->config.defObjectType;
285
21.5k
    *samplerate = get_sample_rate(hDecoder->sf_index);
286
21.5k
    *channels = 1;
287
288
21.5k
    if (buffer != NULL)
289
21.5k
    {
290
#if 0
291
        int is_latm;
292
        latm_header *l = &hDecoder->latm_config;
293
#endif
294
295
21.5k
        faad_initbits(&ld, buffer, buffer_size);
296
297
#if 0
298
        memset(l, 0, sizeof(latm_header));
299
        is_latm = latmCheck(l, &ld);
300
        l->inited = 0;
301
        l->frameLength = 0;
302
        faad_rewindbits(&ld);
303
        if(is_latm && l->ASCbits>0)
304
        {
305
            int32_t x;
306
            hDecoder->latm_header_present = 1;
307
            x = NeAACDecInit2(hDecoder, l->ASC, (l->ASCbits+7)/8, samplerate, channels);
308
            if(x!=0)
309
                hDecoder->latm_header_present = 0;
310
            return x;
311
        } else
312
#endif
313
        /* Check if an ADIF header is present */
314
21.5k
        if ((buffer_size >= 8) && (buffer[0] == 'A') && (buffer[1] == 'D') &&
315
476
            (buffer[2] == 'I') && (buffer[3] == 'F'))
316
420
        {
317
420
            hDecoder->adif_header_present = 1;
318
319
420
            get_adif_header(&adif, &ld);
320
420
            faad_byte_align(&ld);
321
322
420
            hDecoder->sf_index = adif.pce[0].sf_index;
323
420
            hDecoder->object_type = adif.pce[0].object_type + 1;
324
325
420
            *samplerate = get_sample_rate(hDecoder->sf_index);
326
420
            *channels = adif.pce[0].channels;
327
328
420
            memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config));
329
420
            hDecoder->pce_set = 1;
330
331
420
            bits = bit2byte(faad_get_processed_bits(&ld));
332
333
        /* Check if an ADTS header is present */
334
21.1k
        } else if (adts_frame(&adts, &ld) == 0) {
335
653
            hDecoder->adts_header_present = 1;
336
337
653
            hDecoder->sf_index = adts.sf_index;
338
653
            hDecoder->object_type = adts.profile + 1;
339
340
653
            *samplerate = get_sample_rate(hDecoder->sf_index);
341
653
            *channels = (adts.channel_configuration > 6) ?
342
593
                2 : adts.channel_configuration;
343
653
        }
344
345
21.5k
        if (ld.error)
346
0
        {
347
0
            faad_endbits(&ld);
348
0
            return -1;
349
0
        }
350
21.5k
        faad_endbits(&ld);
351
21.5k
    }
352
353
21.5k
    if (!*samplerate)
354
166
        return -1;
355
356
21.4k
    hDecoder->channelConfiguration = *channels;
357
358
21.4k
#ifdef SBR_DEC
359
    /* implicit signalling */
360
21.4k
    if (*samplerate <= 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0))
361
9.90k
    {
362
9.90k
        *samplerate *= 2;
363
9.90k
        hDecoder->forceUpSampling = 1;
364
11.5k
    } else if (*samplerate > 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) {
365
11.5k
        hDecoder->downSampledSBR = 1;
366
11.5k
    }
367
21.4k
#endif
368
369
21.4k
    if (can_decode_ot(hDecoder->object_type) < 0)
370
235
        return -1;
371
372
    /* must be done before frameLength is divided by 2 for LD */
373
#ifdef SSR_DEC
374
    if (hDecoder->object_type == SSR)
375
        hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS);
376
    else
377
#endif
378
21.1k
        hDecoder->fb = filter_bank_init(hDecoder->frameLength);
379
380
#ifdef LD_DEC
381
11.0k
    if (hDecoder->object_type == LD)
382
301
        hDecoder->frameLength >>= 1;
383
#endif
384
385
21.1k
    return bits;
386
21.4k
}
NeAACDecInit
Line
Count
Source
271
10.4k
{
272
10.4k
    uint32_t bits = 0;
273
10.4k
    bitfile ld;
274
10.4k
    adif_header adif;
275
10.4k
    adts_header adts;
276
10.4k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
277
278
279
10.4k
    if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL) || (buffer_size == 0))
280
35
        return -1;
281
282
10.4k
    adts.old_format = hDecoder->config.useOldADTSFormat;
283
10.4k
    hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate);
284
10.4k
    hDecoder->object_type = hDecoder->config.defObjectType;
285
10.4k
    *samplerate = get_sample_rate(hDecoder->sf_index);
286
10.4k
    *channels = 1;
287
288
10.4k
    if (buffer != NULL)
289
10.4k
    {
290
#if 0
291
        int is_latm;
292
        latm_header *l = &hDecoder->latm_config;
293
#endif
294
295
10.4k
        faad_initbits(&ld, buffer, buffer_size);
296
297
#if 0
298
        memset(l, 0, sizeof(latm_header));
299
        is_latm = latmCheck(l, &ld);
300
        l->inited = 0;
301
        l->frameLength = 0;
302
        faad_rewindbits(&ld);
303
        if(is_latm && l->ASCbits>0)
304
        {
305
            int32_t x;
306
            hDecoder->latm_header_present = 1;
307
            x = NeAACDecInit2(hDecoder, l->ASC, (l->ASCbits+7)/8, samplerate, channels);
308
            if(x!=0)
309
                hDecoder->latm_header_present = 0;
310
            return x;
311
        } else
312
#endif
313
        /* Check if an ADIF header is present */
314
10.4k
        if ((buffer_size >= 8) && (buffer[0] == 'A') && (buffer[1] == 'D') &&
315
226
            (buffer[2] == 'I') && (buffer[3] == 'F'))
316
198
        {
317
198
            hDecoder->adif_header_present = 1;
318
319
198
            get_adif_header(&adif, &ld);
320
198
            faad_byte_align(&ld);
321
322
198
            hDecoder->sf_index = adif.pce[0].sf_index;
323
198
            hDecoder->object_type = adif.pce[0].object_type + 1;
324
325
198
            *samplerate = get_sample_rate(hDecoder->sf_index);
326
198
            *channels = adif.pce[0].channels;
327
328
198
            memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config));
329
198
            hDecoder->pce_set = 1;
330
331
198
            bits = bit2byte(faad_get_processed_bits(&ld));
332
333
        /* Check if an ADTS header is present */
334
10.2k
        } else if (adts_frame(&adts, &ld) == 0) {
335
178
            hDecoder->adts_header_present = 1;
336
337
178
            hDecoder->sf_index = adts.sf_index;
338
178
            hDecoder->object_type = adts.profile + 1;
339
340
178
            *samplerate = get_sample_rate(hDecoder->sf_index);
341
178
            *channels = (adts.channel_configuration > 6) ?
342
158
                2 : adts.channel_configuration;
343
178
        }
344
345
10.4k
        if (ld.error)
346
0
        {
347
0
            faad_endbits(&ld);
348
0
            return -1;
349
0
        }
350
10.4k
        faad_endbits(&ld);
351
10.4k
    }
352
353
10.4k
    if (!*samplerate)
354
83
        return -1;
355
356
10.3k
    hDecoder->channelConfiguration = *channels;
357
358
10.3k
#ifdef SBR_DEC
359
    /* implicit signalling */
360
10.3k
    if (*samplerate <= 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0))
361
4.73k
    {
362
4.73k
        *samplerate *= 2;
363
4.73k
        hDecoder->forceUpSampling = 1;
364
5.58k
    } else if (*samplerate > 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) {
365
5.58k
        hDecoder->downSampledSBR = 1;
366
5.58k
    }
367
10.3k
#endif
368
369
10.3k
    if (can_decode_ot(hDecoder->object_type) < 0)
370
154
        return -1;
371
372
    /* must be done before frameLength is divided by 2 for LD */
373
#ifdef SSR_DEC
374
    if (hDecoder->object_type == SSR)
375
        hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS);
376
    else
377
#endif
378
10.1k
        hDecoder->fb = filter_bank_init(hDecoder->frameLength);
379
380
#ifdef LD_DEC
381
    if (hDecoder->object_type == LD)
382
        hDecoder->frameLength >>= 1;
383
#endif
384
385
10.1k
    return bits;
386
10.3k
}
NeAACDecInit
Line
Count
Source
271
11.2k
{
272
11.2k
    uint32_t bits = 0;
273
11.2k
    bitfile ld;
274
11.2k
    adif_header adif;
275
11.2k
    adts_header adts;
276
11.2k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
277
278
279
11.2k
    if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL) || (buffer_size == 0))
280
25
        return -1;
281
282
11.1k
    adts.old_format = hDecoder->config.useOldADTSFormat;
283
11.1k
    hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate);
284
11.1k
    hDecoder->object_type = hDecoder->config.defObjectType;
285
11.1k
    *samplerate = get_sample_rate(hDecoder->sf_index);
286
11.1k
    *channels = 1;
287
288
11.1k
    if (buffer != NULL)
289
11.1k
    {
290
#if 0
291
        int is_latm;
292
        latm_header *l = &hDecoder->latm_config;
293
#endif
294
295
11.1k
        faad_initbits(&ld, buffer, buffer_size);
296
297
#if 0
298
        memset(l, 0, sizeof(latm_header));
299
        is_latm = latmCheck(l, &ld);
300
        l->inited = 0;
301
        l->frameLength = 0;
302
        faad_rewindbits(&ld);
303
        if(is_latm && l->ASCbits>0)
304
        {
305
            int32_t x;
306
            hDecoder->latm_header_present = 1;
307
            x = NeAACDecInit2(hDecoder, l->ASC, (l->ASCbits+7)/8, samplerate, channels);
308
            if(x!=0)
309
                hDecoder->latm_header_present = 0;
310
            return x;
311
        } else
312
#endif
313
        /* Check if an ADIF header is present */
314
11.1k
        if ((buffer_size >= 8) && (buffer[0] == 'A') && (buffer[1] == 'D') &&
315
250
            (buffer[2] == 'I') && (buffer[3] == 'F'))
316
222
        {
317
222
            hDecoder->adif_header_present = 1;
318
319
222
            get_adif_header(&adif, &ld);
320
222
            faad_byte_align(&ld);
321
322
222
            hDecoder->sf_index = adif.pce[0].sf_index;
323
222
            hDecoder->object_type = adif.pce[0].object_type + 1;
324
325
222
            *samplerate = get_sample_rate(hDecoder->sf_index);
326
222
            *channels = adif.pce[0].channels;
327
328
222
            memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config));
329
222
            hDecoder->pce_set = 1;
330
331
222
            bits = bit2byte(faad_get_processed_bits(&ld));
332
333
        /* Check if an ADTS header is present */
334
10.9k
        } else if (adts_frame(&adts, &ld) == 0) {
335
475
            hDecoder->adts_header_present = 1;
336
337
475
            hDecoder->sf_index = adts.sf_index;
338
475
            hDecoder->object_type = adts.profile + 1;
339
340
475
            *samplerate = get_sample_rate(hDecoder->sf_index);
341
475
            *channels = (adts.channel_configuration > 6) ?
342
435
                2 : adts.channel_configuration;
343
475
        }
344
345
11.1k
        if (ld.error)
346
0
        {
347
0
            faad_endbits(&ld);
348
0
            return -1;
349
0
        }
350
11.1k
        faad_endbits(&ld);
351
11.1k
    }
352
353
11.1k
    if (!*samplerate)
354
83
        return -1;
355
356
11.1k
    hDecoder->channelConfiguration = *channels;
357
358
11.1k
#ifdef SBR_DEC
359
    /* implicit signalling */
360
11.1k
    if (*samplerate <= 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0))
361
5.17k
    {
362
5.17k
        *samplerate *= 2;
363
5.17k
        hDecoder->forceUpSampling = 1;
364
5.92k
    } else if (*samplerate > 24000 && (hDecoder->config.dontUpSampleImplicitSBR == 0)) {
365
5.92k
        hDecoder->downSampledSBR = 1;
366
5.92k
    }
367
11.1k
#endif
368
369
11.1k
    if (can_decode_ot(hDecoder->object_type) < 0)
370
81
        return -1;
371
372
    /* must be done before frameLength is divided by 2 for LD */
373
#ifdef SSR_DEC
374
    if (hDecoder->object_type == SSR)
375
        hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS);
376
    else
377
#endif
378
11.0k
        hDecoder->fb = filter_bank_init(hDecoder->frameLength);
379
380
11.0k
#ifdef LD_DEC
381
11.0k
    if (hDecoder->object_type == LD)
382
301
        hDecoder->frameLength >>= 1;
383
11.0k
#endif
384
385
11.0k
    return bits;
386
11.1k
}
387
388
/* Init the library using a DecoderSpecificInfo */
389
char NeAACDecInit2(NeAACDecHandle hpDecoder,
390
                               unsigned char *pBuffer,
391
                               unsigned long SizeOfDecoderSpecificInfo,
392
                               unsigned long *samplerate,
393
                               unsigned char *channels)
394
11.7k
{
395
11.7k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
396
11.7k
    int8_t rc;
397
11.7k
    mp4AudioSpecificConfig mp4ASC;
398
399
11.7k
    if((hDecoder == NULL)
400
11.7k
        || (pBuffer == NULL)
401
11.7k
        || (SizeOfDecoderSpecificInfo < 2)
402
11.6k
        || (samplerate == NULL)
403
11.6k
        || (channels == NULL))
404
32
    {
405
32
        return -1;
406
32
    }
407
408
11.6k
    hDecoder->adif_header_present = 0;
409
11.6k
    hDecoder->adts_header_present = 0;
410
411
    /* decode the audio specific config */
412
11.6k
    rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC,
413
11.6k
        &(hDecoder->pce), hDecoder->latm_header_present);
414
415
    /* copy the relevant info to the decoder handle */
416
11.6k
    *samplerate = mp4ASC.samplingFrequency;
417
11.6k
    if (mp4ASC.channelsConfiguration)
418
10.1k
    {
419
10.1k
        *channels = mp4ASC.channelsConfiguration;
420
10.1k
    } else {
421
1.58k
        *channels = hDecoder->pce.channels;
422
1.58k
        hDecoder->pce_set = 1;
423
1.58k
    }
424
11.6k
#if (defined(PS_DEC) || defined(DRM_PS))
425
11.6k
    hDecoder->ps_present_flag = mp4ASC.ps_present_flag;
426
11.6k
#endif
427
11.6k
    hDecoder->sf_index = mp4ASC.samplingFrequencyIndex;
428
11.6k
    hDecoder->object_type = mp4ASC.objectTypeIndex;
429
11.6k
#ifdef ERROR_RESILIENCE
430
11.6k
    hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag;
431
11.6k
    hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag;
432
11.6k
    hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag;
433
11.6k
#endif
434
11.6k
#ifdef SBR_DEC
435
11.6k
    hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag;
436
11.6k
    hDecoder->downSampledSBR = mp4ASC.downSampledSBR;
437
11.6k
    if (hDecoder->config.dontUpSampleImplicitSBR == 0)
438
11.6k
        hDecoder->forceUpSampling = mp4ASC.forceUpSampling;
439
0
    else
440
0
        hDecoder->forceUpSampling = 0;
441
442
    /* AAC core decoder samplerate is 2 times as low */
443
11.6k
    if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1)
444
6.90k
    {
445
6.90k
        hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2);
446
6.90k
    }
447
11.6k
#endif
448
449
11.6k
    if (rc != 0)
450
128
    {
451
128
        return rc;
452
128
    }
453
11.5k
    hDecoder->channelConfiguration = mp4ASC.channelsConfiguration;
454
11.5k
    if (mp4ASC.frameLengthFlag)
455
7.11k
#ifdef ALLOW_SMALL_FRAMELENGTH
456
7.11k
        hDecoder->frameLength = 960;
457
#else
458
        return -1;
459
#endif
460
461
    /* must be done before frameLength is divided by 2 for LD */
462
#ifdef SSR_DEC
463
    if (hDecoder->object_type == SSR)
464
        hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS);
465
    else
466
#endif
467
11.5k
        hDecoder->fb = filter_bank_init(hDecoder->frameLength);
468
469
#ifdef LD_DEC
470
6.31k
    if (hDecoder->object_type == LD)
471
972
        hDecoder->frameLength >>= 1;
472
#endif
473
474
11.5k
    return 0;
475
11.6k
}
NeAACDecInit2
Line
Count
Source
394
5.32k
{
395
5.32k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
396
5.32k
    int8_t rc;
397
5.32k
    mp4AudioSpecificConfig mp4ASC;
398
399
5.32k
    if((hDecoder == NULL)
400
5.32k
        || (pBuffer == NULL)
401
5.32k
        || (SizeOfDecoderSpecificInfo < 2)
402
5.30k
        || (samplerate == NULL)
403
5.30k
        || (channels == NULL))
404
24
    {
405
24
        return -1;
406
24
    }
407
408
5.30k
    hDecoder->adif_header_present = 0;
409
5.30k
    hDecoder->adts_header_present = 0;
410
411
    /* decode the audio specific config */
412
5.30k
    rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC,
413
5.30k
        &(hDecoder->pce), hDecoder->latm_header_present);
414
415
    /* copy the relevant info to the decoder handle */
416
5.30k
    *samplerate = mp4ASC.samplingFrequency;
417
5.30k
    if (mp4ASC.channelsConfiguration)
418
4.53k
    {
419
4.53k
        *channels = mp4ASC.channelsConfiguration;
420
4.53k
    } else {
421
772
        *channels = hDecoder->pce.channels;
422
772
        hDecoder->pce_set = 1;
423
772
    }
424
5.30k
#if (defined(PS_DEC) || defined(DRM_PS))
425
5.30k
    hDecoder->ps_present_flag = mp4ASC.ps_present_flag;
426
5.30k
#endif
427
5.30k
    hDecoder->sf_index = mp4ASC.samplingFrequencyIndex;
428
5.30k
    hDecoder->object_type = mp4ASC.objectTypeIndex;
429
5.30k
#ifdef ERROR_RESILIENCE
430
5.30k
    hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag;
431
5.30k
    hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag;
432
5.30k
    hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag;
433
5.30k
#endif
434
5.30k
#ifdef SBR_DEC
435
5.30k
    hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag;
436
5.30k
    hDecoder->downSampledSBR = mp4ASC.downSampledSBR;
437
5.30k
    if (hDecoder->config.dontUpSampleImplicitSBR == 0)
438
5.30k
        hDecoder->forceUpSampling = mp4ASC.forceUpSampling;
439
0
    else
440
0
        hDecoder->forceUpSampling = 0;
441
442
    /* AAC core decoder samplerate is 2 times as low */
443
5.30k
    if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1)
444
3.06k
    {
445
3.06k
        hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2);
446
3.06k
    }
447
5.30k
#endif
448
449
5.30k
    if (rc != 0)
450
60
    {
451
60
        return rc;
452
60
    }
453
5.24k
    hDecoder->channelConfiguration = mp4ASC.channelsConfiguration;
454
5.24k
    if (mp4ASC.frameLengthFlag)
455
3.31k
#ifdef ALLOW_SMALL_FRAMELENGTH
456
3.31k
        hDecoder->frameLength = 960;
457
#else
458
        return -1;
459
#endif
460
461
    /* must be done before frameLength is divided by 2 for LD */
462
#ifdef SSR_DEC
463
    if (hDecoder->object_type == SSR)
464
        hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS);
465
    else
466
#endif
467
5.24k
        hDecoder->fb = filter_bank_init(hDecoder->frameLength);
468
469
#ifdef LD_DEC
470
    if (hDecoder->object_type == LD)
471
        hDecoder->frameLength >>= 1;
472
#endif
473
474
5.24k
    return 0;
475
5.30k
}
NeAACDecInit2
Line
Count
Source
394
6.39k
{
395
6.39k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
396
6.39k
    int8_t rc;
397
6.39k
    mp4AudioSpecificConfig mp4ASC;
398
399
6.39k
    if((hDecoder == NULL)
400
6.39k
        || (pBuffer == NULL)
401
6.39k
        || (SizeOfDecoderSpecificInfo < 2)
402
6.38k
        || (samplerate == NULL)
403
6.38k
        || (channels == NULL))
404
8
    {
405
8
        return -1;
406
8
    }
407
408
6.38k
    hDecoder->adif_header_present = 0;
409
6.38k
    hDecoder->adts_header_present = 0;
410
411
    /* decode the audio specific config */
412
6.38k
    rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC,
413
6.38k
        &(hDecoder->pce), hDecoder->latm_header_present);
414
415
    /* copy the relevant info to the decoder handle */
416
6.38k
    *samplerate = mp4ASC.samplingFrequency;
417
6.38k
    if (mp4ASC.channelsConfiguration)
418
5.57k
    {
419
5.57k
        *channels = mp4ASC.channelsConfiguration;
420
5.57k
    } else {
421
816
        *channels = hDecoder->pce.channels;
422
816
        hDecoder->pce_set = 1;
423
816
    }
424
6.38k
#if (defined(PS_DEC) || defined(DRM_PS))
425
6.38k
    hDecoder->ps_present_flag = mp4ASC.ps_present_flag;
426
6.38k
#endif
427
6.38k
    hDecoder->sf_index = mp4ASC.samplingFrequencyIndex;
428
6.38k
    hDecoder->object_type = mp4ASC.objectTypeIndex;
429
6.38k
#ifdef ERROR_RESILIENCE
430
6.38k
    hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag;
431
6.38k
    hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag;
432
6.38k
    hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag;
433
6.38k
#endif
434
6.38k
#ifdef SBR_DEC
435
6.38k
    hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag;
436
6.38k
    hDecoder->downSampledSBR = mp4ASC.downSampledSBR;
437
6.38k
    if (hDecoder->config.dontUpSampleImplicitSBR == 0)
438
6.38k
        hDecoder->forceUpSampling = mp4ASC.forceUpSampling;
439
0
    else
440
0
        hDecoder->forceUpSampling = 0;
441
442
    /* AAC core decoder samplerate is 2 times as low */
443
6.38k
    if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || hDecoder->forceUpSampling == 1)
444
3.83k
    {
445
3.83k
        hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2);
446
3.83k
    }
447
6.38k
#endif
448
449
6.38k
    if (rc != 0)
450
68
    {
451
68
        return rc;
452
68
    }
453
6.31k
    hDecoder->channelConfiguration = mp4ASC.channelsConfiguration;
454
6.31k
    if (mp4ASC.frameLengthFlag)
455
3.79k
#ifdef ALLOW_SMALL_FRAMELENGTH
456
3.79k
        hDecoder->frameLength = 960;
457
#else
458
        return -1;
459
#endif
460
461
    /* must be done before frameLength is divided by 2 for LD */
462
#ifdef SSR_DEC
463
    if (hDecoder->object_type == SSR)
464
        hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS);
465
    else
466
#endif
467
6.31k
        hDecoder->fb = filter_bank_init(hDecoder->frameLength);
468
469
6.31k
#ifdef LD_DEC
470
6.31k
    if (hDecoder->object_type == LD)
471
972
        hDecoder->frameLength >>= 1;
472
6.31k
#endif
473
474
6.31k
    return 0;
475
6.38k
}
476
477
#ifdef DRM
478
char NeAACDecInitDRM(NeAACDecHandle *hpDecoder,
479
                                 unsigned long samplerate,
480
                                 unsigned char channels)
481
1.23k
{
482
1.23k
    NeAACDecStruct** hDecoder = (NeAACDecStruct**)hpDecoder;
483
1.23k
    if (hDecoder == NULL)
484
0
        return 1; /* error */
485
486
1.23k
    NeAACDecClose(*hDecoder);
487
488
1.23k
    *hDecoder = NeAACDecOpen();
489
490
    /* Special object type defined for DRM */
491
1.23k
    (*hDecoder)->config.defObjectType = DRM_ER_LC;
492
493
1.23k
    (*hDecoder)->config.defSampleRate = samplerate;
494
1.23k
#ifdef ERROR_RESILIENCE // This shoudl always be defined for DRM
495
1.23k
    (*hDecoder)->aacSectionDataResilienceFlag = 1; /* VCB11 */
496
1.23k
    (*hDecoder)->aacScalefactorDataResilienceFlag = 0; /* no RVLC */
497
1.23k
    (*hDecoder)->aacSpectralDataResilienceFlag = 1; /* HCR */
498
1.23k
#endif
499
1.23k
    (*hDecoder)->frameLength = 960;
500
1.23k
    (*hDecoder)->sf_index = get_sr_index((*hDecoder)->config.defSampleRate);
501
1.23k
    (*hDecoder)->object_type = (*hDecoder)->config.defObjectType;
502
503
1.23k
    if ((channels == DRMCH_STEREO) || (channels == DRMCH_SBR_STEREO))
504
242
        (*hDecoder)->channelConfiguration = 2;
505
996
    else
506
996
        (*hDecoder)->channelConfiguration = 1;
507
508
1.23k
#ifdef SBR_DEC
509
1.23k
    if ((channels == DRMCH_MONO) || (channels == DRMCH_STEREO))
510
215
        (*hDecoder)->sbr_present_flag = 0;
511
1.02k
    else
512
1.02k
        (*hDecoder)->sbr_present_flag = 1;
513
1.23k
#endif
514
515
1.23k
    (*hDecoder)->fb = filter_bank_init((*hDecoder)->frameLength);
516
517
1.23k
    return 0;
518
1.23k
}
519
#endif
520
521
void NeAACDecClose(NeAACDecHandle hpDecoder)
522
17.1k
{
523
17.1k
    uint8_t i;
524
17.1k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
525
526
17.1k
    if (hDecoder == NULL)
527
0
        return;
528
529
#ifdef PROFILE
530
    printf("AAC decoder total:  %I64d cycles\n", hDecoder->cycles);
531
    printf("requant:            %I64d cycles\n", hDecoder->requant_cycles);
532
    printf("spectral_data:      %I64d cycles\n", hDecoder->spectral_cycles);
533
    printf("scalefactors:       %I64d cycles\n", hDecoder->scalefac_cycles);
534
    printf("output:             %I64d cycles\n", hDecoder->output_cycles);
535
#endif
536
537
1.11M
    for (i = 0; i < MAX_CHANNELS; i++)
538
1.09M
    {
539
1.09M
        if (hDecoder->time_out[i]) faad_free(hDecoder->time_out[i]);
540
1.09M
        if (hDecoder->fb_intermed[i]) faad_free(hDecoder->fb_intermed[i]);
541
#ifdef SSR_DEC
542
        if (hDecoder->ssr_overlap[i]) faad_free(hDecoder->ssr_overlap[i]);
543
        if (hDecoder->prev_fmd[i]) faad_free(hDecoder->prev_fmd[i]);
544
#endif
545
#ifdef MAIN_DEC
546
        if (hDecoder->pred_stat[i]) faad_free(hDecoder->pred_stat[i]);
547
#endif
548
#ifdef LTP_DEC
549
        if (hDecoder->lt_pred_stat[i]) faad_free(hDecoder->lt_pred_stat[i]);
550
#endif
551
1.09M
    }
552
553
#ifdef SSR_DEC
554
    if (hDecoder->object_type == SSR)
555
        ssr_filter_bank_end(hDecoder->fb);
556
    else
557
#endif
558
17.1k
        filter_bank_end(hDecoder->fb);
559
560
17.1k
    drc_end(hDecoder->drc);
561
562
17.1k
    if (hDecoder->sample_buffer) faad_free(hDecoder->sample_buffer);
563
564
17.1k
#ifdef SBR_DEC
565
840k
    for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
566
823k
    {
567
823k
        if (hDecoder->sbr[i])
568
203k
            sbrDecodeEnd(hDecoder->sbr[i]);
569
823k
    }
570
17.1k
#endif
571
572
17.1k
    if (hDecoder) faad_free(hDecoder);
573
17.1k
}
574
575
void NeAACDecPostSeekReset(NeAACDecHandle hpDecoder, long frame)
576
24.9k
{
577
24.9k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
578
24.9k
    if (hDecoder)
579
24.9k
    {
580
24.9k
        hDecoder->postSeekResetFlag = 1;
581
582
24.9k
        if (frame != -1)
583
24.9k
            hDecoder->frame = frame;
584
24.9k
    }
585
24.9k
}
586
587
static void create_channel_config(NeAACDecStruct *hDecoder, NeAACDecFrameInfo *hInfo)
588
45.4k
{
589
45.4k
    hInfo->num_front_channels = 0;
590
45.4k
    hInfo->num_side_channels = 0;
591
45.4k
    hInfo->num_back_channels = 0;
592
45.4k
    hInfo->num_lfe_channels = 0;
593
45.4k
    memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t));
594
595
45.4k
    if (hDecoder->downMatrix)
596
6.53k
    {
597
6.53k
        hInfo->num_front_channels = 2;
598
6.53k
        hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
599
6.53k
        hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
600
6.53k
        return;
601
6.53k
    }
602
603
    /* check if there is a PCE */
604
    /* TODO: why CPE flag is ignored? */
605
38.9k
    if (hDecoder->pce_set)
606
1.73k
    {
607
1.73k
        uint8_t i, chpos = 0;
608
1.73k
        uint8_t chdir, back_center = 0;
609
610
1.73k
        hInfo->num_front_channels = hDecoder->pce.num_front_channels;
611
1.73k
        hInfo->num_side_channels = hDecoder->pce.num_side_channels;
612
1.73k
        hInfo->num_back_channels = hDecoder->pce.num_back_channels;
613
1.73k
        hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels;
614
1.73k
        chdir = hInfo->num_front_channels;
615
1.73k
        if (chdir & 1)
616
776
        {
617
776
#if (defined(PS_DEC) || defined(DRM_PS))
618
776
            if (hInfo->num_front_channels == 1 &&
619
412
                hInfo->num_side_channels == 0 &&
620
268
                hInfo->num_back_channels == 0 &&
621
212
                hInfo->num_lfe_channels == 0 &&
622
164
                hDecoder->ps_used_global)
623
48
            {
624
                /* When PS is enabled output is always stereo */
625
48
                hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT;
626
48
                hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT;
627
48
            } else
628
728
#endif
629
728
            hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER;
630
776
            chdir--;
631
776
        }
632
8.82k
        for (i = 0; i < chdir; i++)
633
7.08k
        {
634
7.08k
            hInfo->channel_position[chpos++] =
635
7.08k
                (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT;
636
7.08k
        }
637
638
8.15k
        for (i = 0; i < hInfo->num_side_channels; i++)
639
6.42k
        {
640
6.42k
            hInfo->channel_position[chpos++] =
641
6.42k
                (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT;
642
6.42k
        }
643
644
1.73k
        chdir = hInfo->num_back_channels;
645
1.73k
        if (chdir & 1)
646
256
        {
647
256
            back_center = 1;
648
256
            chdir--;
649
256
        }
650
5.74k
        for (i = 0; i < chdir; i++)
651
4.01k
        {
652
4.01k
            hInfo->channel_position[chpos++] =
653
4.01k
                (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT;
654
4.01k
        }
655
1.73k
        if (back_center)
656
256
        {
657
256
            hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER;
658
256
        }
659
660
2.83k
        for (i = 0; i < hInfo->num_lfe_channels; i++)
661
1.10k
        {
662
1.10k
            hInfo->channel_position[chpos++] = LFE_CHANNEL;
663
1.10k
        }
664
665
37.1k
    } else {
666
37.1k
        switch (hDecoder->channelConfiguration)
667
37.1k
        {
668
10.3k
        case 1:
669
10.3k
#if (defined(PS_DEC) || defined(DRM_PS))
670
10.3k
            if (hDecoder->ps_used_global)
671
2.45k
            {
672
                /* When PS is enabled output is always stereo */
673
2.45k
                hInfo->num_front_channels = 2;
674
2.45k
                hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
675
2.45k
                hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
676
7.89k
            } else {
677
7.89k
                hInfo->num_front_channels = 1;
678
7.89k
                hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
679
7.89k
            }
680
#else
681
            hInfo->num_front_channels = 1;
682
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
683
#endif
684
10.3k
            break;
685
2.28k
        case 2:
686
2.28k
            hInfo->num_front_channels = 2;
687
2.28k
            hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
688
2.28k
            hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
689
2.28k
            break;
690
4.14k
        case 3:
691
4.14k
            hInfo->num_front_channels = 3;
692
4.14k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
693
4.14k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
694
4.14k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
695
4.14k
            break;
696
5.48k
        case 4:
697
5.48k
            hInfo->num_front_channels = 3;
698
5.48k
            hInfo->num_back_channels = 1;
699
5.48k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
700
5.48k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
701
5.48k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
702
5.48k
            hInfo->channel_position[3] = BACK_CHANNEL_CENTER;
703
5.48k
            break;
704
3.89k
        case 5:
705
3.89k
            hInfo->num_front_channels = 3;
706
3.89k
            hInfo->num_back_channels = 2;
707
3.89k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
708
3.89k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
709
3.89k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
710
3.89k
            hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
711
3.89k
            hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
712
3.89k
            break;
713
1.45k
        case 6:
714
1.45k
            hInfo->num_front_channels = 3;
715
1.45k
            hInfo->num_back_channels = 2;
716
1.45k
            hInfo->num_lfe_channels = 1;
717
1.45k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
718
1.45k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
719
1.45k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
720
1.45k
            hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
721
1.45k
            hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
722
1.45k
            hInfo->channel_position[5] = LFE_CHANNEL;
723
1.45k
            break;
724
8.65k
        case 7:
725
8.65k
            hInfo->num_front_channels = 3;
726
8.65k
            hInfo->num_side_channels = 2;
727
8.65k
            hInfo->num_back_channels = 2;
728
8.65k
            hInfo->num_lfe_channels = 1;
729
8.65k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
730
8.65k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
731
8.65k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
732
8.65k
            hInfo->channel_position[3] = SIDE_CHANNEL_LEFT;
733
8.65k
            hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT;
734
8.65k
            hInfo->channel_position[5] = BACK_CHANNEL_LEFT;
735
8.65k
            hInfo->channel_position[6] = BACK_CHANNEL_RIGHT;
736
8.65k
            hInfo->channel_position[7] = LFE_CHANNEL;
737
8.65k
            break;
738
912
        default: /* channelConfiguration == 0 || channelConfiguration > 7 */
739
912
            {
740
912
                uint8_t i;
741
912
                uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe;
742
912
                if (ch & 1) /* there's either a center front or a center back channel */
743
280
                {
744
280
                    uint8_t ch1 = (ch-1)/2;
745
280
                    if (hDecoder->first_syn_ele == ID_SCE)
746
180
                    {
747
180
                        hInfo->num_front_channels = ch1 + 1;
748
180
                        hInfo->num_back_channels = ch1;
749
180
                        hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
750
844
                        for (i = 1; i <= ch1; i+=2)
751
664
                        {
752
664
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
753
664
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
754
664
                        }
755
844
                        for (i = ch1+1; i < ch; i+=2)
756
664
                        {
757
664
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
758
664
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
759
664
                        }
760
180
                    } else {
761
100
                        hInfo->num_front_channels = ch1;
762
100
                        hInfo->num_back_channels = ch1 + 1;
763
572
                        for (i = 0; i < ch1; i+=2)
764
472
                        {
765
472
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
766
472
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
767
472
                        }
768
572
                        for (i = ch1; i < ch-1; i+=2)
769
472
                        {
770
472
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
771
472
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
772
472
                        }
773
100
                        hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
774
100
                    }
775
632
                } else {
776
632
                    uint8_t ch1 = (ch)/2;
777
632
                    hInfo->num_front_channels = ch1;
778
632
                    hInfo->num_back_channels = ch1;
779
632
                    if (ch1 & 1)
780
292
                    {
781
292
                        hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
782
1.61k
                        for (i = 1; i <= ch1; i+=2)
783
1.32k
                        {
784
1.32k
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
785
1.32k
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
786
1.32k
                        }
787
1.32k
                        for (i = ch1+1; i < ch-1; i+=2)
788
1.02k
                        {
789
1.02k
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
790
1.02k
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
791
1.02k
                        }
792
292
                        hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
793
340
                    } else {
794
2.59k
                        for (i = 0; i < ch1; i+=2)
795
2.25k
                        {
796
2.25k
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
797
2.25k
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
798
2.25k
                        }
799
2.59k
                        for (i = ch1; i < ch; i+=2)
800
2.25k
                        {
801
2.25k
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
802
2.25k
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
803
2.25k
                        }
804
340
                    }
805
632
                }
806
912
                hInfo->num_lfe_channels = hDecoder->has_lfe;
807
2.45k
                for (i = ch; i < hDecoder->fr_channels; i++)
808
1.54k
                {
809
1.54k
                    hInfo->channel_position[i] = LFE_CHANNEL;
810
1.54k
                }
811
912
            }
812
912
            break;
813
37.1k
        }
814
37.1k
    }
815
38.9k
}
decoder.c:create_channel_config
Line
Count
Source
588
11.3k
{
589
11.3k
    hInfo->num_front_channels = 0;
590
11.3k
    hInfo->num_side_channels = 0;
591
11.3k
    hInfo->num_back_channels = 0;
592
11.3k
    hInfo->num_lfe_channels = 0;
593
11.3k
    memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t));
594
595
11.3k
    if (hDecoder->downMatrix)
596
1.63k
    {
597
1.63k
        hInfo->num_front_channels = 2;
598
1.63k
        hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
599
1.63k
        hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
600
1.63k
        return;
601
1.63k
    }
602
603
    /* check if there is a PCE */
604
    /* TODO: why CPE flag is ignored? */
605
9.72k
    if (hDecoder->pce_set)
606
433
    {
607
433
        uint8_t i, chpos = 0;
608
433
        uint8_t chdir, back_center = 0;
609
610
433
        hInfo->num_front_channels = hDecoder->pce.num_front_channels;
611
433
        hInfo->num_side_channels = hDecoder->pce.num_side_channels;
612
433
        hInfo->num_back_channels = hDecoder->pce.num_back_channels;
613
433
        hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels;
614
433
        chdir = hInfo->num_front_channels;
615
433
        if (chdir & 1)
616
194
        {
617
194
#if (defined(PS_DEC) || defined(DRM_PS))
618
194
            if (hInfo->num_front_channels == 1 &&
619
103
                hInfo->num_side_channels == 0 &&
620
67
                hInfo->num_back_channels == 0 &&
621
53
                hInfo->num_lfe_channels == 0 &&
622
41
                hDecoder->ps_used_global)
623
12
            {
624
                /* When PS is enabled output is always stereo */
625
12
                hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT;
626
12
                hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT;
627
12
            } else
628
182
#endif
629
182
            hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER;
630
194
            chdir--;
631
194
        }
632
2.20k
        for (i = 0; i < chdir; i++)
633
1.77k
        {
634
1.77k
            hInfo->channel_position[chpos++] =
635
1.77k
                (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT;
636
1.77k
        }
637
638
2.03k
        for (i = 0; i < hInfo->num_side_channels; i++)
639
1.60k
        {
640
1.60k
            hInfo->channel_position[chpos++] =
641
1.60k
                (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT;
642
1.60k
        }
643
644
433
        chdir = hInfo->num_back_channels;
645
433
        if (chdir & 1)
646
64
        {
647
64
            back_center = 1;
648
64
            chdir--;
649
64
        }
650
1.43k
        for (i = 0; i < chdir; i++)
651
1.00k
        {
652
1.00k
            hInfo->channel_position[chpos++] =
653
1.00k
                (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT;
654
1.00k
        }
655
433
        if (back_center)
656
64
        {
657
64
            hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER;
658
64
        }
659
660
708
        for (i = 0; i < hInfo->num_lfe_channels; i++)
661
275
        {
662
275
            hInfo->channel_position[chpos++] = LFE_CHANNEL;
663
275
        }
664
665
9.29k
    } else {
666
9.29k
        switch (hDecoder->channelConfiguration)
667
9.29k
        {
668
2.58k
        case 1:
669
2.58k
#if (defined(PS_DEC) || defined(DRM_PS))
670
2.58k
            if (hDecoder->ps_used_global)
671
613
            {
672
                /* When PS is enabled output is always stereo */
673
613
                hInfo->num_front_channels = 2;
674
613
                hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
675
613
                hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
676
1.97k
            } else {
677
1.97k
                hInfo->num_front_channels = 1;
678
1.97k
                hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
679
1.97k
            }
680
#else
681
            hInfo->num_front_channels = 1;
682
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
683
#endif
684
2.58k
            break;
685
571
        case 2:
686
571
            hInfo->num_front_channels = 2;
687
571
            hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
688
571
            hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
689
571
            break;
690
1.03k
        case 3:
691
1.03k
            hInfo->num_front_channels = 3;
692
1.03k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
693
1.03k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
694
1.03k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
695
1.03k
            break;
696
1.37k
        case 4:
697
1.37k
            hInfo->num_front_channels = 3;
698
1.37k
            hInfo->num_back_channels = 1;
699
1.37k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
700
1.37k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
701
1.37k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
702
1.37k
            hInfo->channel_position[3] = BACK_CHANNEL_CENTER;
703
1.37k
            break;
704
973
        case 5:
705
973
            hInfo->num_front_channels = 3;
706
973
            hInfo->num_back_channels = 2;
707
973
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
708
973
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
709
973
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
710
973
            hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
711
973
            hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
712
973
            break;
713
363
        case 6:
714
363
            hInfo->num_front_channels = 3;
715
363
            hInfo->num_back_channels = 2;
716
363
            hInfo->num_lfe_channels = 1;
717
363
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
718
363
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
719
363
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
720
363
            hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
721
363
            hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
722
363
            hInfo->channel_position[5] = LFE_CHANNEL;
723
363
            break;
724
2.16k
        case 7:
725
2.16k
            hInfo->num_front_channels = 3;
726
2.16k
            hInfo->num_side_channels = 2;
727
2.16k
            hInfo->num_back_channels = 2;
728
2.16k
            hInfo->num_lfe_channels = 1;
729
2.16k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
730
2.16k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
731
2.16k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
732
2.16k
            hInfo->channel_position[3] = SIDE_CHANNEL_LEFT;
733
2.16k
            hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT;
734
2.16k
            hInfo->channel_position[5] = BACK_CHANNEL_LEFT;
735
2.16k
            hInfo->channel_position[6] = BACK_CHANNEL_RIGHT;
736
2.16k
            hInfo->channel_position[7] = LFE_CHANNEL;
737
2.16k
            break;
738
228
        default: /* channelConfiguration == 0 || channelConfiguration > 7 */
739
228
            {
740
228
                uint8_t i;
741
228
                uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe;
742
228
                if (ch & 1) /* there's either a center front or a center back channel */
743
70
                {
744
70
                    uint8_t ch1 = (ch-1)/2;
745
70
                    if (hDecoder->first_syn_ele == ID_SCE)
746
45
                    {
747
45
                        hInfo->num_front_channels = ch1 + 1;
748
45
                        hInfo->num_back_channels = ch1;
749
45
                        hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
750
211
                        for (i = 1; i <= ch1; i+=2)
751
166
                        {
752
166
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
753
166
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
754
166
                        }
755
211
                        for (i = ch1+1; i < ch; i+=2)
756
166
                        {
757
166
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
758
166
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
759
166
                        }
760
45
                    } else {
761
25
                        hInfo->num_front_channels = ch1;
762
25
                        hInfo->num_back_channels = ch1 + 1;
763
143
                        for (i = 0; i < ch1; i+=2)
764
118
                        {
765
118
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
766
118
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
767
118
                        }
768
143
                        for (i = ch1; i < ch-1; i+=2)
769
118
                        {
770
118
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
771
118
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
772
118
                        }
773
25
                        hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
774
25
                    }
775
158
                } else {
776
158
                    uint8_t ch1 = (ch)/2;
777
158
                    hInfo->num_front_channels = ch1;
778
158
                    hInfo->num_back_channels = ch1;
779
158
                    if (ch1 & 1)
780
73
                    {
781
73
                        hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
782
403
                        for (i = 1; i <= ch1; i+=2)
783
330
                        {
784
330
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
785
330
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
786
330
                        }
787
330
                        for (i = ch1+1; i < ch-1; i+=2)
788
257
                        {
789
257
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
790
257
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
791
257
                        }
792
73
                        hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
793
85
                    } else {
794
649
                        for (i = 0; i < ch1; i+=2)
795
564
                        {
796
564
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
797
564
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
798
564
                        }
799
649
                        for (i = ch1; i < ch; i+=2)
800
564
                        {
801
564
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
802
564
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
803
564
                        }
804
85
                    }
805
158
                }
806
228
                hInfo->num_lfe_channels = hDecoder->has_lfe;
807
614
                for (i = ch; i < hDecoder->fr_channels; i++)
808
386
                {
809
386
                    hInfo->channel_position[i] = LFE_CHANNEL;
810
386
                }
811
228
            }
812
228
            break;
813
9.29k
        }
814
9.29k
    }
815
9.72k
}
decoder.c:create_channel_config
Line
Count
Source
588
11.3k
{
589
11.3k
    hInfo->num_front_channels = 0;
590
11.3k
    hInfo->num_side_channels = 0;
591
11.3k
    hInfo->num_back_channels = 0;
592
11.3k
    hInfo->num_lfe_channels = 0;
593
11.3k
    memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t));
594
595
11.3k
    if (hDecoder->downMatrix)
596
1.63k
    {
597
1.63k
        hInfo->num_front_channels = 2;
598
1.63k
        hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
599
1.63k
        hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
600
1.63k
        return;
601
1.63k
    }
602
603
    /* check if there is a PCE */
604
    /* TODO: why CPE flag is ignored? */
605
9.72k
    if (hDecoder->pce_set)
606
433
    {
607
433
        uint8_t i, chpos = 0;
608
433
        uint8_t chdir, back_center = 0;
609
610
433
        hInfo->num_front_channels = hDecoder->pce.num_front_channels;
611
433
        hInfo->num_side_channels = hDecoder->pce.num_side_channels;
612
433
        hInfo->num_back_channels = hDecoder->pce.num_back_channels;
613
433
        hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels;
614
433
        chdir = hInfo->num_front_channels;
615
433
        if (chdir & 1)
616
194
        {
617
194
#if (defined(PS_DEC) || defined(DRM_PS))
618
194
            if (hInfo->num_front_channels == 1 &&
619
103
                hInfo->num_side_channels == 0 &&
620
67
                hInfo->num_back_channels == 0 &&
621
53
                hInfo->num_lfe_channels == 0 &&
622
41
                hDecoder->ps_used_global)
623
12
            {
624
                /* When PS is enabled output is always stereo */
625
12
                hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT;
626
12
                hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT;
627
12
            } else
628
182
#endif
629
182
            hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER;
630
194
            chdir--;
631
194
        }
632
2.20k
        for (i = 0; i < chdir; i++)
633
1.77k
        {
634
1.77k
            hInfo->channel_position[chpos++] =
635
1.77k
                (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT;
636
1.77k
        }
637
638
2.03k
        for (i = 0; i < hInfo->num_side_channels; i++)
639
1.60k
        {
640
1.60k
            hInfo->channel_position[chpos++] =
641
1.60k
                (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT;
642
1.60k
        }
643
644
433
        chdir = hInfo->num_back_channels;
645
433
        if (chdir & 1)
646
64
        {
647
64
            back_center = 1;
648
64
            chdir--;
649
64
        }
650
1.43k
        for (i = 0; i < chdir; i++)
651
1.00k
        {
652
1.00k
            hInfo->channel_position[chpos++] =
653
1.00k
                (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT;
654
1.00k
        }
655
433
        if (back_center)
656
64
        {
657
64
            hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER;
658
64
        }
659
660
708
        for (i = 0; i < hInfo->num_lfe_channels; i++)
661
275
        {
662
275
            hInfo->channel_position[chpos++] = LFE_CHANNEL;
663
275
        }
664
665
9.29k
    } else {
666
9.29k
        switch (hDecoder->channelConfiguration)
667
9.29k
        {
668
2.58k
        case 1:
669
2.58k
#if (defined(PS_DEC) || defined(DRM_PS))
670
2.58k
            if (hDecoder->ps_used_global)
671
613
            {
672
                /* When PS is enabled output is always stereo */
673
613
                hInfo->num_front_channels = 2;
674
613
                hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
675
613
                hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
676
1.97k
            } else {
677
1.97k
                hInfo->num_front_channels = 1;
678
1.97k
                hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
679
1.97k
            }
680
#else
681
            hInfo->num_front_channels = 1;
682
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
683
#endif
684
2.58k
            break;
685
571
        case 2:
686
571
            hInfo->num_front_channels = 2;
687
571
            hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
688
571
            hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
689
571
            break;
690
1.03k
        case 3:
691
1.03k
            hInfo->num_front_channels = 3;
692
1.03k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
693
1.03k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
694
1.03k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
695
1.03k
            break;
696
1.37k
        case 4:
697
1.37k
            hInfo->num_front_channels = 3;
698
1.37k
            hInfo->num_back_channels = 1;
699
1.37k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
700
1.37k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
701
1.37k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
702
1.37k
            hInfo->channel_position[3] = BACK_CHANNEL_CENTER;
703
1.37k
            break;
704
973
        case 5:
705
973
            hInfo->num_front_channels = 3;
706
973
            hInfo->num_back_channels = 2;
707
973
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
708
973
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
709
973
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
710
973
            hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
711
973
            hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
712
973
            break;
713
363
        case 6:
714
363
            hInfo->num_front_channels = 3;
715
363
            hInfo->num_back_channels = 2;
716
363
            hInfo->num_lfe_channels = 1;
717
363
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
718
363
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
719
363
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
720
363
            hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
721
363
            hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
722
363
            hInfo->channel_position[5] = LFE_CHANNEL;
723
363
            break;
724
2.16k
        case 7:
725
2.16k
            hInfo->num_front_channels = 3;
726
2.16k
            hInfo->num_side_channels = 2;
727
2.16k
            hInfo->num_back_channels = 2;
728
2.16k
            hInfo->num_lfe_channels = 1;
729
2.16k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
730
2.16k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
731
2.16k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
732
2.16k
            hInfo->channel_position[3] = SIDE_CHANNEL_LEFT;
733
2.16k
            hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT;
734
2.16k
            hInfo->channel_position[5] = BACK_CHANNEL_LEFT;
735
2.16k
            hInfo->channel_position[6] = BACK_CHANNEL_RIGHT;
736
2.16k
            hInfo->channel_position[7] = LFE_CHANNEL;
737
2.16k
            break;
738
228
        default: /* channelConfiguration == 0 || channelConfiguration > 7 */
739
228
            {
740
228
                uint8_t i;
741
228
                uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe;
742
228
                if (ch & 1) /* there's either a center front or a center back channel */
743
70
                {
744
70
                    uint8_t ch1 = (ch-1)/2;
745
70
                    if (hDecoder->first_syn_ele == ID_SCE)
746
45
                    {
747
45
                        hInfo->num_front_channels = ch1 + 1;
748
45
                        hInfo->num_back_channels = ch1;
749
45
                        hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
750
211
                        for (i = 1; i <= ch1; i+=2)
751
166
                        {
752
166
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
753
166
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
754
166
                        }
755
211
                        for (i = ch1+1; i < ch; i+=2)
756
166
                        {
757
166
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
758
166
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
759
166
                        }
760
45
                    } else {
761
25
                        hInfo->num_front_channels = ch1;
762
25
                        hInfo->num_back_channels = ch1 + 1;
763
143
                        for (i = 0; i < ch1; i+=2)
764
118
                        {
765
118
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
766
118
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
767
118
                        }
768
143
                        for (i = ch1; i < ch-1; i+=2)
769
118
                        {
770
118
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
771
118
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
772
118
                        }
773
25
                        hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
774
25
                    }
775
158
                } else {
776
158
                    uint8_t ch1 = (ch)/2;
777
158
                    hInfo->num_front_channels = ch1;
778
158
                    hInfo->num_back_channels = ch1;
779
158
                    if (ch1 & 1)
780
73
                    {
781
73
                        hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
782
403
                        for (i = 1; i <= ch1; i+=2)
783
330
                        {
784
330
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
785
330
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
786
330
                        }
787
330
                        for (i = ch1+1; i < ch-1; i+=2)
788
257
                        {
789
257
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
790
257
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
791
257
                        }
792
73
                        hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
793
85
                    } else {
794
649
                        for (i = 0; i < ch1; i+=2)
795
564
                        {
796
564
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
797
564
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
798
564
                        }
799
649
                        for (i = ch1; i < ch; i+=2)
800
564
                        {
801
564
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
802
564
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
803
564
                        }
804
85
                    }
805
158
                }
806
228
                hInfo->num_lfe_channels = hDecoder->has_lfe;
807
614
                for (i = ch; i < hDecoder->fr_channels; i++)
808
386
                {
809
386
                    hInfo->channel_position[i] = LFE_CHANNEL;
810
386
                }
811
228
            }
812
228
            break;
813
9.29k
        }
814
9.29k
    }
815
9.72k
}
decoder.c:create_channel_config
Line
Count
Source
588
11.3k
{
589
11.3k
    hInfo->num_front_channels = 0;
590
11.3k
    hInfo->num_side_channels = 0;
591
11.3k
    hInfo->num_back_channels = 0;
592
11.3k
    hInfo->num_lfe_channels = 0;
593
11.3k
    memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t));
594
595
11.3k
    if (hDecoder->downMatrix)
596
1.63k
    {
597
1.63k
        hInfo->num_front_channels = 2;
598
1.63k
        hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
599
1.63k
        hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
600
1.63k
        return;
601
1.63k
    }
602
603
    /* check if there is a PCE */
604
    /* TODO: why CPE flag is ignored? */
605
9.72k
    if (hDecoder->pce_set)
606
433
    {
607
433
        uint8_t i, chpos = 0;
608
433
        uint8_t chdir, back_center = 0;
609
610
433
        hInfo->num_front_channels = hDecoder->pce.num_front_channels;
611
433
        hInfo->num_side_channels = hDecoder->pce.num_side_channels;
612
433
        hInfo->num_back_channels = hDecoder->pce.num_back_channels;
613
433
        hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels;
614
433
        chdir = hInfo->num_front_channels;
615
433
        if (chdir & 1)
616
194
        {
617
194
#if (defined(PS_DEC) || defined(DRM_PS))
618
194
            if (hInfo->num_front_channels == 1 &&
619
103
                hInfo->num_side_channels == 0 &&
620
67
                hInfo->num_back_channels == 0 &&
621
53
                hInfo->num_lfe_channels == 0 &&
622
41
                hDecoder->ps_used_global)
623
12
            {
624
                /* When PS is enabled output is always stereo */
625
12
                hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT;
626
12
                hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT;
627
12
            } else
628
182
#endif
629
182
            hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER;
630
194
            chdir--;
631
194
        }
632
2.20k
        for (i = 0; i < chdir; i++)
633
1.77k
        {
634
1.77k
            hInfo->channel_position[chpos++] =
635
1.77k
                (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT;
636
1.77k
        }
637
638
2.03k
        for (i = 0; i < hInfo->num_side_channels; i++)
639
1.60k
        {
640
1.60k
            hInfo->channel_position[chpos++] =
641
1.60k
                (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT;
642
1.60k
        }
643
644
433
        chdir = hInfo->num_back_channels;
645
433
        if (chdir & 1)
646
64
        {
647
64
            back_center = 1;
648
64
            chdir--;
649
64
        }
650
1.43k
        for (i = 0; i < chdir; i++)
651
1.00k
        {
652
1.00k
            hInfo->channel_position[chpos++] =
653
1.00k
                (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT;
654
1.00k
        }
655
433
        if (back_center)
656
64
        {
657
64
            hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER;
658
64
        }
659
660
708
        for (i = 0; i < hInfo->num_lfe_channels; i++)
661
275
        {
662
275
            hInfo->channel_position[chpos++] = LFE_CHANNEL;
663
275
        }
664
665
9.29k
    } else {
666
9.29k
        switch (hDecoder->channelConfiguration)
667
9.29k
        {
668
2.58k
        case 1:
669
2.58k
#if (defined(PS_DEC) || defined(DRM_PS))
670
2.58k
            if (hDecoder->ps_used_global)
671
613
            {
672
                /* When PS is enabled output is always stereo */
673
613
                hInfo->num_front_channels = 2;
674
613
                hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
675
613
                hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
676
1.97k
            } else {
677
1.97k
                hInfo->num_front_channels = 1;
678
1.97k
                hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
679
1.97k
            }
680
#else
681
            hInfo->num_front_channels = 1;
682
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
683
#endif
684
2.58k
            break;
685
571
        case 2:
686
571
            hInfo->num_front_channels = 2;
687
571
            hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
688
571
            hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
689
571
            break;
690
1.03k
        case 3:
691
1.03k
            hInfo->num_front_channels = 3;
692
1.03k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
693
1.03k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
694
1.03k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
695
1.03k
            break;
696
1.37k
        case 4:
697
1.37k
            hInfo->num_front_channels = 3;
698
1.37k
            hInfo->num_back_channels = 1;
699
1.37k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
700
1.37k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
701
1.37k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
702
1.37k
            hInfo->channel_position[3] = BACK_CHANNEL_CENTER;
703
1.37k
            break;
704
973
        case 5:
705
973
            hInfo->num_front_channels = 3;
706
973
            hInfo->num_back_channels = 2;
707
973
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
708
973
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
709
973
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
710
973
            hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
711
973
            hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
712
973
            break;
713
363
        case 6:
714
363
            hInfo->num_front_channels = 3;
715
363
            hInfo->num_back_channels = 2;
716
363
            hInfo->num_lfe_channels = 1;
717
363
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
718
363
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
719
363
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
720
363
            hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
721
363
            hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
722
363
            hInfo->channel_position[5] = LFE_CHANNEL;
723
363
            break;
724
2.16k
        case 7:
725
2.16k
            hInfo->num_front_channels = 3;
726
2.16k
            hInfo->num_side_channels = 2;
727
2.16k
            hInfo->num_back_channels = 2;
728
2.16k
            hInfo->num_lfe_channels = 1;
729
2.16k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
730
2.16k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
731
2.16k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
732
2.16k
            hInfo->channel_position[3] = SIDE_CHANNEL_LEFT;
733
2.16k
            hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT;
734
2.16k
            hInfo->channel_position[5] = BACK_CHANNEL_LEFT;
735
2.16k
            hInfo->channel_position[6] = BACK_CHANNEL_RIGHT;
736
2.16k
            hInfo->channel_position[7] = LFE_CHANNEL;
737
2.16k
            break;
738
228
        default: /* channelConfiguration == 0 || channelConfiguration > 7 */
739
228
            {
740
228
                uint8_t i;
741
228
                uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe;
742
228
                if (ch & 1) /* there's either a center front or a center back channel */
743
70
                {
744
70
                    uint8_t ch1 = (ch-1)/2;
745
70
                    if (hDecoder->first_syn_ele == ID_SCE)
746
45
                    {
747
45
                        hInfo->num_front_channels = ch1 + 1;
748
45
                        hInfo->num_back_channels = ch1;
749
45
                        hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
750
211
                        for (i = 1; i <= ch1; i+=2)
751
166
                        {
752
166
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
753
166
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
754
166
                        }
755
211
                        for (i = ch1+1; i < ch; i+=2)
756
166
                        {
757
166
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
758
166
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
759
166
                        }
760
45
                    } else {
761
25
                        hInfo->num_front_channels = ch1;
762
25
                        hInfo->num_back_channels = ch1 + 1;
763
143
                        for (i = 0; i < ch1; i+=2)
764
118
                        {
765
118
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
766
118
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
767
118
                        }
768
143
                        for (i = ch1; i < ch-1; i+=2)
769
118
                        {
770
118
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
771
118
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
772
118
                        }
773
25
                        hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
774
25
                    }
775
158
                } else {
776
158
                    uint8_t ch1 = (ch)/2;
777
158
                    hInfo->num_front_channels = ch1;
778
158
                    hInfo->num_back_channels = ch1;
779
158
                    if (ch1 & 1)
780
73
                    {
781
73
                        hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
782
403
                        for (i = 1; i <= ch1; i+=2)
783
330
                        {
784
330
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
785
330
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
786
330
                        }
787
330
                        for (i = ch1+1; i < ch-1; i+=2)
788
257
                        {
789
257
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
790
257
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
791
257
                        }
792
73
                        hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
793
85
                    } else {
794
649
                        for (i = 0; i < ch1; i+=2)
795
564
                        {
796
564
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
797
564
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
798
564
                        }
799
649
                        for (i = ch1; i < ch; i+=2)
800
564
                        {
801
564
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
802
564
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
803
564
                        }
804
85
                    }
805
158
                }
806
228
                hInfo->num_lfe_channels = hDecoder->has_lfe;
807
614
                for (i = ch; i < hDecoder->fr_channels; i++)
808
386
                {
809
386
                    hInfo->channel_position[i] = LFE_CHANNEL;
810
386
                }
811
228
            }
812
228
            break;
813
9.29k
        }
814
9.29k
    }
815
9.72k
}
decoder.c:create_channel_config
Line
Count
Source
588
11.3k
{
589
11.3k
    hInfo->num_front_channels = 0;
590
11.3k
    hInfo->num_side_channels = 0;
591
11.3k
    hInfo->num_back_channels = 0;
592
11.3k
    hInfo->num_lfe_channels = 0;
593
11.3k
    memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t));
594
595
11.3k
    if (hDecoder->downMatrix)
596
1.63k
    {
597
1.63k
        hInfo->num_front_channels = 2;
598
1.63k
        hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
599
1.63k
        hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
600
1.63k
        return;
601
1.63k
    }
602
603
    /* check if there is a PCE */
604
    /* TODO: why CPE flag is ignored? */
605
9.72k
    if (hDecoder->pce_set)
606
433
    {
607
433
        uint8_t i, chpos = 0;
608
433
        uint8_t chdir, back_center = 0;
609
610
433
        hInfo->num_front_channels = hDecoder->pce.num_front_channels;
611
433
        hInfo->num_side_channels = hDecoder->pce.num_side_channels;
612
433
        hInfo->num_back_channels = hDecoder->pce.num_back_channels;
613
433
        hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels;
614
433
        chdir = hInfo->num_front_channels;
615
433
        if (chdir & 1)
616
194
        {
617
194
#if (defined(PS_DEC) || defined(DRM_PS))
618
194
            if (hInfo->num_front_channels == 1 &&
619
103
                hInfo->num_side_channels == 0 &&
620
67
                hInfo->num_back_channels == 0 &&
621
53
                hInfo->num_lfe_channels == 0 &&
622
41
                hDecoder->ps_used_global)
623
12
            {
624
                /* When PS is enabled output is always stereo */
625
12
                hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT;
626
12
                hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT;
627
12
            } else
628
182
#endif
629
182
            hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER;
630
194
            chdir--;
631
194
        }
632
2.20k
        for (i = 0; i < chdir; i++)
633
1.77k
        {
634
1.77k
            hInfo->channel_position[chpos++] =
635
1.77k
                (i & 1) ? FRONT_CHANNEL_RIGHT : FRONT_CHANNEL_LEFT;
636
1.77k
        }
637
638
2.03k
        for (i = 0; i < hInfo->num_side_channels; i++)
639
1.60k
        {
640
1.60k
            hInfo->channel_position[chpos++] =
641
1.60k
                (i & 1) ? SIDE_CHANNEL_RIGHT : SIDE_CHANNEL_LEFT;
642
1.60k
        }
643
644
433
        chdir = hInfo->num_back_channels;
645
433
        if (chdir & 1)
646
64
        {
647
64
            back_center = 1;
648
64
            chdir--;
649
64
        }
650
1.43k
        for (i = 0; i < chdir; i++)
651
1.00k
        {
652
1.00k
            hInfo->channel_position[chpos++] =
653
1.00k
                (i & 1) ? BACK_CHANNEL_RIGHT : BACK_CHANNEL_LEFT;
654
1.00k
        }
655
433
        if (back_center)
656
64
        {
657
64
            hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER;
658
64
        }
659
660
708
        for (i = 0; i < hInfo->num_lfe_channels; i++)
661
275
        {
662
275
            hInfo->channel_position[chpos++] = LFE_CHANNEL;
663
275
        }
664
665
9.29k
    } else {
666
9.29k
        switch (hDecoder->channelConfiguration)
667
9.29k
        {
668
2.58k
        case 1:
669
2.58k
#if (defined(PS_DEC) || defined(DRM_PS))
670
2.58k
            if (hDecoder->ps_used_global)
671
613
            {
672
                /* When PS is enabled output is always stereo */
673
613
                hInfo->num_front_channels = 2;
674
613
                hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
675
613
                hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
676
1.97k
            } else {
677
1.97k
                hInfo->num_front_channels = 1;
678
1.97k
                hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
679
1.97k
            }
680
#else
681
            hInfo->num_front_channels = 1;
682
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
683
#endif
684
2.58k
            break;
685
571
        case 2:
686
571
            hInfo->num_front_channels = 2;
687
571
            hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
688
571
            hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
689
571
            break;
690
1.03k
        case 3:
691
1.03k
            hInfo->num_front_channels = 3;
692
1.03k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
693
1.03k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
694
1.03k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
695
1.03k
            break;
696
1.37k
        case 4:
697
1.37k
            hInfo->num_front_channels = 3;
698
1.37k
            hInfo->num_back_channels = 1;
699
1.37k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
700
1.37k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
701
1.37k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
702
1.37k
            hInfo->channel_position[3] = BACK_CHANNEL_CENTER;
703
1.37k
            break;
704
973
        case 5:
705
973
            hInfo->num_front_channels = 3;
706
973
            hInfo->num_back_channels = 2;
707
973
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
708
973
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
709
973
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
710
973
            hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
711
973
            hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
712
973
            break;
713
363
        case 6:
714
363
            hInfo->num_front_channels = 3;
715
363
            hInfo->num_back_channels = 2;
716
363
            hInfo->num_lfe_channels = 1;
717
363
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
718
363
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
719
363
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
720
363
            hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
721
363
            hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
722
363
            hInfo->channel_position[5] = LFE_CHANNEL;
723
363
            break;
724
2.16k
        case 7:
725
2.16k
            hInfo->num_front_channels = 3;
726
2.16k
            hInfo->num_side_channels = 2;
727
2.16k
            hInfo->num_back_channels = 2;
728
2.16k
            hInfo->num_lfe_channels = 1;
729
2.16k
            hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
730
2.16k
            hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
731
2.16k
            hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
732
2.16k
            hInfo->channel_position[3] = SIDE_CHANNEL_LEFT;
733
2.16k
            hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT;
734
2.16k
            hInfo->channel_position[5] = BACK_CHANNEL_LEFT;
735
2.16k
            hInfo->channel_position[6] = BACK_CHANNEL_RIGHT;
736
2.16k
            hInfo->channel_position[7] = LFE_CHANNEL;
737
2.16k
            break;
738
228
        default: /* channelConfiguration == 0 || channelConfiguration > 7 */
739
228
            {
740
228
                uint8_t i;
741
228
                uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe;
742
228
                if (ch & 1) /* there's either a center front or a center back channel */
743
70
                {
744
70
                    uint8_t ch1 = (ch-1)/2;
745
70
                    if (hDecoder->first_syn_ele == ID_SCE)
746
45
                    {
747
45
                        hInfo->num_front_channels = ch1 + 1;
748
45
                        hInfo->num_back_channels = ch1;
749
45
                        hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
750
211
                        for (i = 1; i <= ch1; i+=2)
751
166
                        {
752
166
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
753
166
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
754
166
                        }
755
211
                        for (i = ch1+1; i < ch; i+=2)
756
166
                        {
757
166
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
758
166
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
759
166
                        }
760
45
                    } else {
761
25
                        hInfo->num_front_channels = ch1;
762
25
                        hInfo->num_back_channels = ch1 + 1;
763
143
                        for (i = 0; i < ch1; i+=2)
764
118
                        {
765
118
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
766
118
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
767
118
                        }
768
143
                        for (i = ch1; i < ch-1; i+=2)
769
118
                        {
770
118
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
771
118
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
772
118
                        }
773
25
                        hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
774
25
                    }
775
158
                } else {
776
158
                    uint8_t ch1 = (ch)/2;
777
158
                    hInfo->num_front_channels = ch1;
778
158
                    hInfo->num_back_channels = ch1;
779
158
                    if (ch1 & 1)
780
73
                    {
781
73
                        hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
782
403
                        for (i = 1; i <= ch1; i+=2)
783
330
                        {
784
330
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
785
330
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
786
330
                        }
787
330
                        for (i = ch1+1; i < ch-1; i+=2)
788
257
                        {
789
257
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
790
257
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
791
257
                        }
792
73
                        hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
793
85
                    } else {
794
649
                        for (i = 0; i < ch1; i+=2)
795
564
                        {
796
564
                            hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
797
564
                            hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
798
564
                        }
799
649
                        for (i = ch1; i < ch; i+=2)
800
564
                        {
801
564
                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
802
564
                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
803
564
                        }
804
85
                    }
805
158
                }
806
228
                hInfo->num_lfe_channels = hDecoder->has_lfe;
807
614
                for (i = ch; i < hDecoder->fr_channels; i++)
808
386
                {
809
386
                    hInfo->channel_position[i] = LFE_CHANNEL;
810
386
                }
811
228
            }
812
228
            break;
813
9.29k
        }
814
9.29k
    }
815
9.72k
}
816
817
void* NeAACDecDecode(NeAACDecHandle hpDecoder,
818
                                 NeAACDecFrameInfo *hInfo,
819
                                 unsigned char *buffer,
820
                                 unsigned long buffer_size)
821
51.2k
{
822
51.2k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
823
51.2k
    return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, NULL, 0);
824
51.2k
}
825
826
void* NeAACDecDecode2(NeAACDecHandle hpDecoder,
827
                                  NeAACDecFrameInfo *hInfo,
828
                                  unsigned char *buffer,
829
                                  unsigned long buffer_size,
830
                                  void **sample_buffer,
831
                                  unsigned long sample_buffer_size)
832
14.0k
{
833
14.0k
    NeAACDecStruct* hDecoder = (NeAACDecStruct*)hpDecoder;
834
14.0k
    if ((sample_buffer_size == 0) || (sample_buffer == NULL) || (*sample_buffer == NULL))
835
127
    {
836
127
        hInfo->error = 27;
837
127
        return NULL;
838
127
    }
839
840
13.8k
    return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size,
841
13.8k
        sample_buffer, sample_buffer_size);
842
14.0k
}
843
844
static void* aac_frame_decode(NeAACDecStruct *hDecoder,
845
                              NeAACDecFrameInfo *hInfo,
846
                              unsigned char *buffer,
847
                              unsigned long buffer_size,
848
                              void **sample_buffer2,
849
                              unsigned long sample_buffer_size)
850
65.1k
{
851
65.1k
    uint16_t i;
852
65.1k
    uint8_t channels = 0;
853
65.1k
    uint8_t output_channels = 0;
854
65.1k
    bitfile ld;
855
65.1k
    uint32_t bitsconsumed;
856
65.1k
    uint16_t frame_len;
857
65.1k
    void *sample_buffer;
858
#if 0
859
    uint32_t startbit=0, endbit=0, payload_bits=0;
860
#endif
861
65.1k
    uint32_t required_buffer_size=0;
862
863
#ifdef PROFILE
864
    int64_t count = faad_get_ts();
865
#endif
866
867
    /* safety checks */
868
65.1k
    if ((hDecoder == NULL) || (hInfo == NULL) || (buffer == NULL))
869
0
    {
870
0
        return NULL;
871
0
    }
872
873
#if 0
874
    printf("%d\n", buffer_size*8);
875
#endif
876
877
65.1k
    frame_len = hDecoder->frameLength;
878
879
880
65.1k
    memset(hInfo, 0, sizeof(NeAACDecFrameInfo));
881
65.1k
    memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0]));
882
883
#ifdef USE_TIME_LIMIT
884
    if ((TIME_LIMIT * get_sample_rate(hDecoder->sf_index)) > hDecoder->TL_count)
885
    {
886
        hDecoder->TL_count += 1024;
887
    } else {
888
        hInfo->error = (NUM_ERROR_MESSAGES-1);
889
        goto error;
890
    }
891
#endif
892
893
894
    /* check for some common metadata tag types in the bitstream
895
     * No need to return an error
896
     */
897
    /* ID3 */
898
65.1k
    if (buffer_size >= 128)
899
6.36k
    {
900
6.36k
        if (memcmp(buffer, "TAG", 3) == 0)
901
12
        {
902
            /* found it */
903
12
            hInfo->bytesconsumed = 128; /* 128 bytes fixed size */
904
            /* no error, but no output either */
905
12
            return NULL;
906
12
        }
907
6.36k
    }
908
909
910
    /* initialize the bitstream */
911
65.1k
    faad_initbits(&ld, buffer, buffer_size);
912
65.1k
    if (ld.error != 0)
913
26.1k
        return NULL;
914
915
#if 0
916
    {
917
        int i;
918
        for (i = 0; i < ((buffer_size+3)>>2); i++)
919
        {
920
            uint8_t *buf;
921
            uint32_t temp = 0;
922
            buf = faad_getbitbuffer(&ld, 32);
923
            //temp = getdword((void*)buf);
924
            temp = *((uint32_t*)buf);
925
            printf("0x%.8X\n", temp);
926
            free(buf);
927
        }
928
        faad_endbits(&ld);
929
        faad_initbits(&ld, buffer, buffer_size);
930
    }
931
#endif
932
933
#if 0
934
    if(hDecoder->latm_header_present)
935
    {
936
        payload_bits = faad_latm_frame(&hDecoder->latm_config, &ld);
937
        startbit = faad_get_processed_bits(&ld);
938
        if(payload_bits == -1U)
939
        {
940
            hInfo->error = 1;
941
            goto error;
942
        }
943
    }
944
#endif
945
946
#ifdef DRM
947
18.3k
    if (hDecoder->object_type == DRM_ER_LC)
948
1.55k
    {
949
        /* We do not support stereo right now */
950
1.55k
        if (0) //(hDecoder->channelConfiguration == 2)
951
0
        {
952
0
            hInfo->error = 28; // Throw CRC error
953
0
            goto error;
954
0
        }
955
956
1.55k
        faad_getbits(&ld, 8
957
1.55k
            DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC"));
958
1.55k
    }
959
18.3k
#endif
960
961
38.9k
    if (hDecoder->adts_header_present)
962
914
    {
963
914
        adts_header adts;
964
965
914
        adts.old_format = hDecoder->config.useOldADTSFormat;
966
914
        if ((hInfo->error = adts_frame(&adts, &ld)) > 0)
967
110
            goto error;
968
969
        /* MPEG2 does byte_alignment() here,
970
         * but ADTS header is always multiple of 8 bits in MPEG2
971
         * so not needed to actually do it.
972
         */
973
914
    }
974
975
#ifdef ANALYSIS
976
    dbg_count = 0;
977
#endif
978
979
    /* decode the complete bitstream */
980
#ifdef DRM
981
18.3k
    if (/*(hDecoder->object_type == 6) ||*/ hDecoder->object_type == DRM_ER_LC)
982
1.55k
    {
983
1.55k
        DRM_aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);
984
16.7k
    } else {
985
16.7k
#endif
986
20.4k
        raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);
987
#ifdef DRM
988
    }
989
#endif
990
991
#if 0
992
    if(hDecoder->latm_header_present)
993
    {
994
        endbit = faad_get_processed_bits(&ld);
995
        if(endbit-startbit > payload_bits)
996
            fprintf(stderr, "\r\nERROR, too many payload bits read: %u > %d. Please. report with a link to a sample\n",
997
                endbit-startbit, payload_bits);
998
        if(hDecoder->latm_config.otherDataLenBits > 0)
999
            faad_getbits(&ld, hDecoder->latm_config.otherDataLenBits);
1000
        faad_byte_align(&ld);
1001
    }
1002
#endif
1003
1004
20.4k
    channels = hDecoder->fr_channels;
1005
1006
38.8k
    if (hInfo->error > 0)
1007
27.2k
        goto error;
1008
1009
    /* safety check */
1010
11.5k
    if (channels == 0 || channels > MAX_CHANNELS)
1011
164
    {
1012
        /* invalid number of channels */
1013
164
        hInfo->error = 12;
1014
164
        goto error;
1015
164
    }
1016
1017
    /* no more bit reading after this */
1018
11.3k
    bitsconsumed = faad_get_processed_bits(&ld);
1019
11.3k
    hInfo->bytesconsumed = bit2byte(bitsconsumed);
1020
11.3k
    if (ld.error)
1021
0
    {
1022
0
        hInfo->error = 14;
1023
0
        goto error;
1024
0
    }
1025
11.3k
    faad_endbits(&ld);
1026
1027
1028
11.3k
    if (!hDecoder->adts_header_present && !hDecoder->adif_header_present
1029
#if 0
1030
        && !hDecoder->latm_header_present
1031
#endif
1032
11.3k
        )
1033
11.1k
    {
1034
11.1k
        if (hDecoder->channelConfiguration == 0)
1035
354
            hDecoder->channelConfiguration = channels;
1036
1037
11.1k
        if (channels == 8) /* 7.1 */
1038
1.29k
            hDecoder->channelConfiguration = 7;
1039
11.1k
        if (channels == 7) /* not a standard channelConfiguration */
1040
41
            hDecoder->channelConfiguration = 0;
1041
11.1k
    }
1042
1043
11.3k
    if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix)
1044
1.61k
    {
1045
1.61k
        hDecoder->downMatrix = 1;
1046
1.61k
        output_channels = 2;
1047
9.75k
    } else {
1048
9.75k
        output_channels = channels;
1049
9.75k
    }
1050
1051
11.3k
#if (defined(PS_DEC) || defined(DRM_PS))
1052
11.3k
    hDecoder->upMatrix = 0;
1053
11.3k
#endif
1054
1055
    /* Make a channel configuration based on either a PCE or a channelConfiguration */
1056
11.3k
    if (!hDecoder->downMatrix && hDecoder->pce_set)
1057
445
    {
1058
        /* In some codepath program_config_element result is ignored. */
1059
445
        if (hDecoder->pce.channels > MAX_CHANNELS)
1060
12
        {
1061
12
            hInfo->error = 22;
1062
12
            return NULL;
1063
12
        }
1064
445
    }
1065
11.3k
    create_channel_config(hDecoder, hInfo);
1066
1067
    /* number of samples in this frame */
1068
11.3k
    hInfo->samples = frame_len*output_channels;
1069
    /* number of channels in this frame */
1070
11.3k
    hInfo->channels = output_channels;
1071
    /* samplerate */
1072
11.3k
    hInfo->samplerate = get_sample_rate(hDecoder->sf_index);
1073
    /* object type */
1074
11.3k
    hInfo->object_type = hDecoder->object_type;
1075
    /* sbr */
1076
11.3k
    hInfo->sbr = NO_SBR;
1077
    /* header type */
1078
11.3k
    hInfo->header_type = RAW;
1079
11.3k
    if (hDecoder->adif_header_present)
1080
0
        hInfo->header_type = ADIF;
1081
11.3k
    if (hDecoder->adts_header_present)
1082
245
        hInfo->header_type = ADTS;
1083
#if 0
1084
    if (hDecoder->latm_header_present)
1085
        hInfo->header_type = LATM;
1086
#endif
1087
11.3k
#if (defined(PS_DEC) || defined(DRM_PS))
1088
11.3k
    hInfo->ps = hDecoder->ps_used_global;
1089
11.3k
#endif
1090
1091
    /* check if frame has channel elements */
1092
11.3k
    if (channels == 0)
1093
0
    {
1094
0
        hDecoder->frame++;
1095
0
        return NULL;
1096
0
    }
1097
1098
11.3k
    {
1099
11.3k
        static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t),
1100
11.3k
            sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t),
1101
11.3k
            sizeof(int16_t), sizeof(int16_t), 0, 0, 0
1102
11.3k
        };
1103
11.3k
        uint8_t stride = str[hDecoder->config.outputFormat-1];
1104
11.3k
#ifdef SBR_DEC
1105
11.3k
        if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1))
1106
6.44k
        {
1107
6.44k
            stride = 2 * stride;
1108
6.44k
        }
1109
11.3k
#endif
1110
11.3k
        required_buffer_size = frame_len*output_channels*stride;
1111
11.3k
    }
1112
1113
    /* check if we want to use internal sample_buffer */
1114
11.3k
    if (sample_buffer_size == 0)
1115
7.96k
    {
1116
        /* allocate the buffer for the final samples */
1117
7.96k
        if (hDecoder->sample_buffer_size != required_buffer_size) 
1118
6.79k
        {
1119
6.79k
            if (hDecoder->sample_buffer)
1120
122
                faad_free(hDecoder->sample_buffer);
1121
6.79k
            hDecoder->sample_buffer = NULL;
1122
6.79k
            hDecoder->sample_buffer = faad_malloc(required_buffer_size);
1123
6.79k
            hDecoder->sample_buffer_size = required_buffer_size;
1124
6.79k
        }
1125
7.96k
    } else if (sample_buffer_size < required_buffer_size) {
1126
        /* provided sample buffer is not big enough */
1127
1.46k
        hInfo->error = 27;
1128
1.46k
        return NULL;
1129
1.46k
    }
1130
1131
9.89k
    if (sample_buffer_size == 0)
1132
7.96k
    {
1133
7.96k
        sample_buffer = hDecoder->sample_buffer;
1134
7.96k
    } else {
1135
1.93k
        sample_buffer = *sample_buffer2;
1136
1.93k
    }
1137
1138
9.89k
#ifdef SBR_DEC
1139
9.89k
    if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
1140
6.42k
    {
1141
6.42k
        uint8_t ele;
1142
1143
        /* this data is different when SBR is used or when the data is upsampled */
1144
6.42k
        if (!hDecoder->downSampledSBR)
1145
5.34k
        {
1146
5.34k
            frame_len *= 2;
1147
5.34k
            hInfo->samples *= 2;
1148
5.34k
            hInfo->samplerate *= 2;
1149
5.34k
        }
1150
1151
        /* check if every element was provided with SBR data */
1152
35.1k
        for (ele = 0; ele < hDecoder->fr_ch_ele; ele++)
1153
28.7k
        {
1154
28.7k
            if (hDecoder->sbr[ele] == NULL)
1155
9
            {
1156
9
                hInfo->error = 25;
1157
9
                goto error;
1158
9
            }
1159
28.7k
        }
1160
1161
        /* sbr */
1162
6.41k
        if (hDecoder->sbr_present_flag == 1)
1163
3.94k
        {
1164
3.94k
            hInfo->object_type = HE_AAC;
1165
3.94k
            hInfo->sbr = SBR_UPSAMPLED;
1166
3.94k
        } else {
1167
2.47k
            hInfo->sbr = NO_SBR_UPSAMPLED;
1168
2.47k
        }
1169
6.41k
        if (hDecoder->downSampledSBR)
1170
1.07k
        {
1171
1.07k
            hInfo->sbr = SBR_DOWNSAMPLED;
1172
1.07k
        }
1173
6.41k
    }
1174
9.88k
#endif
1175
1176
1177
9.88k
    sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer,
1178
9.88k
        output_channels, frame_len, hDecoder->config.outputFormat);
1179
1180
1181
#ifdef DRM
1182
    //conceal_output(hDecoder, frame_len, output_channels, sample_buffer);
1183
#endif
1184
1185
1186
9.88k
    hDecoder->postSeekResetFlag = 0;
1187
1188
9.88k
    hDecoder->frame++;
1189
#ifdef LD_DEC
1190
5.37k
    if (hDecoder->object_type != LD)
1191
4.43k
    {
1192
4.43k
#endif
1193
8.95k
        if (hDecoder->frame <= 1)
1194
2.89k
            hInfo->samples = 0;
1195
#ifdef LD_DEC
1196
936
    } else {
1197
        /* LD encoders will give lower delay */
1198
936
        if (hDecoder->frame <= 0)
1199
0
            hInfo->samples = 0;
1200
936
    }
1201
#endif
1202
1203
    /* cleanup */
1204
#ifdef ANALYSIS
1205
    fflush(stdout);
1206
#endif
1207
1208
#ifdef PROFILE
1209
    count = faad_get_ts() - count;
1210
    hDecoder->cycles += count;
1211
#endif
1212
1213
9.88k
    return sample_buffer;
1214
1215
27.5k
error:
1216
1217
    /* reset filterbank state */
1218
1.79M
    for (i = 0; i < MAX_CHANNELS; i++)
1219
1.76M
    {
1220
1.76M
        if (hDecoder->fb_intermed[i] != NULL)
1221
815k
        {
1222
815k
            memset(hDecoder->fb_intermed[i], 0, hDecoder->frameLength*sizeof(real_t));
1223
815k
        }
1224
1.76M
    }
1225
27.5k
#ifdef SBR_DEC
1226
1.35M
    for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
1227
1.32M
    {
1228
1.32M
        if (hDecoder->sbr[i] != NULL)
1229
584k
        {
1230
584k
            sbrReset(hDecoder->sbr[i]);
1231
584k
        }
1232
1.32M
    }
1233
27.5k
#endif
1234
1235
1236
27.5k
    faad_endbits(&ld);
1237
1238
    /* cleanup */
1239
#ifdef ANALYSIS
1240
    fflush(stdout);
1241
#endif
1242
1243
    return NULL;
1244
9.89k
}
decoder.c:aac_frame_decode
Line
Count
Source
850
30.6k
{
851
30.6k
    uint16_t i;
852
30.6k
    uint8_t channels = 0;
853
30.6k
    uint8_t output_channels = 0;
854
30.6k
    bitfile ld;
855
30.6k
    uint32_t bitsconsumed;
856
30.6k
    uint16_t frame_len;
857
30.6k
    void *sample_buffer;
858
#if 0
859
    uint32_t startbit=0, endbit=0, payload_bits=0;
860
#endif
861
30.6k
    uint32_t required_buffer_size=0;
862
863
#ifdef PROFILE
864
    int64_t count = faad_get_ts();
865
#endif
866
867
    /* safety checks */
868
30.6k
    if ((hDecoder == NULL) || (hInfo == NULL) || (buffer == NULL))
869
0
    {
870
0
        return NULL;
871
0
    }
872
873
#if 0
874
    printf("%d\n", buffer_size*8);
875
#endif
876
877
30.6k
    frame_len = hDecoder->frameLength;
878
879
880
30.6k
    memset(hInfo, 0, sizeof(NeAACDecFrameInfo));
881
30.6k
    memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0]));
882
883
#ifdef USE_TIME_LIMIT
884
    if ((TIME_LIMIT * get_sample_rate(hDecoder->sf_index)) > hDecoder->TL_count)
885
    {
886
        hDecoder->TL_count += 1024;
887
    } else {
888
        hInfo->error = (NUM_ERROR_MESSAGES-1);
889
        goto error;
890
    }
891
#endif
892
893
894
    /* check for some common metadata tag types in the bitstream
895
     * No need to return an error
896
     */
897
    /* ID3 */
898
30.6k
    if (buffer_size >= 128)
899
2.87k
    {
900
2.87k
        if (memcmp(buffer, "TAG", 3) == 0)
901
6
        {
902
            /* found it */
903
6
            hInfo->bytesconsumed = 128; /* 128 bytes fixed size */
904
            /* no error, but no output either */
905
6
            return NULL;
906
6
        }
907
2.87k
    }
908
909
910
    /* initialize the bitstream */
911
30.6k
    faad_initbits(&ld, buffer, buffer_size);
912
30.6k
    if (ld.error != 0)
913
12.3k
        return NULL;
914
915
#if 0
916
    {
917
        int i;
918
        for (i = 0; i < ((buffer_size+3)>>2); i++)
919
        {
920
            uint8_t *buf;
921
            uint32_t temp = 0;
922
            buf = faad_getbitbuffer(&ld, 32);
923
            //temp = getdword((void*)buf);
924
            temp = *((uint32_t*)buf);
925
            printf("0x%.8X\n", temp);
926
            free(buf);
927
        }
928
        faad_endbits(&ld);
929
        faad_initbits(&ld, buffer, buffer_size);
930
    }
931
#endif
932
933
#if 0
934
    if(hDecoder->latm_header_present)
935
    {
936
        payload_bits = faad_latm_frame(&hDecoder->latm_config, &ld);
937
        startbit = faad_get_processed_bits(&ld);
938
        if(payload_bits == -1U)
939
        {
940
            hInfo->error = 1;
941
            goto error;
942
        }
943
    }
944
#endif
945
946
18.3k
#ifdef DRM
947
18.3k
    if (hDecoder->object_type == DRM_ER_LC)
948
1.55k
    {
949
        /* We do not support stereo right now */
950
1.55k
        if (0) //(hDecoder->channelConfiguration == 2)
951
0
        {
952
0
            hInfo->error = 28; // Throw CRC error
953
0
            goto error;
954
0
        }
955
956
1.55k
        faad_getbits(&ld, 8
957
1.55k
            DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC"));
958
1.55k
    }
959
18.3k
#endif
960
961
18.3k
    if (hDecoder->adts_header_present)
962
164
    {
963
164
        adts_header adts;
964
965
164
        adts.old_format = hDecoder->config.useOldADTSFormat;
966
164
        if ((hInfo->error = adts_frame(&adts, &ld)) > 0)
967
9
            goto error;
968
969
        /* MPEG2 does byte_alignment() here,
970
         * but ADTS header is always multiple of 8 bits in MPEG2
971
         * so not needed to actually do it.
972
         */
973
164
    }
974
975
#ifdef ANALYSIS
976
    dbg_count = 0;
977
#endif
978
979
    /* decode the complete bitstream */
980
18.3k
#ifdef DRM
981
18.3k
    if (/*(hDecoder->object_type == 6) ||*/ hDecoder->object_type == DRM_ER_LC)
982
1.55k
    {
983
1.55k
        DRM_aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);
984
16.7k
    } else {
985
16.7k
#endif
986
16.7k
        raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);
987
16.7k
#ifdef DRM
988
16.7k
    }
989
18.3k
#endif
990
991
#if 0
992
    if(hDecoder->latm_header_present)
993
    {
994
        endbit = faad_get_processed_bits(&ld);
995
        if(endbit-startbit > payload_bits)
996
            fprintf(stderr, "\r\nERROR, too many payload bits read: %u > %d. Please. report with a link to a sample\n",
997
                endbit-startbit, payload_bits);
998
        if(hDecoder->latm_config.otherDataLenBits > 0)
999
            faad_getbits(&ld, hDecoder->latm_config.otherDataLenBits);
1000
        faad_byte_align(&ld);
1001
    }
1002
#endif
1003
1004
18.3k
    channels = hDecoder->fr_channels;
1005
1006
18.3k
    if (hInfo->error > 0)
1007
12.9k
        goto error;
1008
1009
    /* safety check */
1010
5.39k
    if (channels == 0 || channels > MAX_CHANNELS)
1011
62
    {
1012
        /* invalid number of channels */
1013
62
        hInfo->error = 12;
1014
62
        goto error;
1015
62
    }
1016
1017
    /* no more bit reading after this */
1018
5.32k
    bitsconsumed = faad_get_processed_bits(&ld);
1019
5.32k
    hInfo->bytesconsumed = bit2byte(bitsconsumed);
1020
5.32k
    if (ld.error)
1021
0
    {
1022
0
        hInfo->error = 14;
1023
0
        goto error;
1024
0
    }
1025
5.32k
    faad_endbits(&ld);
1026
1027
1028
5.32k
    if (!hDecoder->adts_header_present && !hDecoder->adif_header_present
1029
#if 0
1030
        && !hDecoder->latm_header_present
1031
#endif
1032
5.32k
        )
1033
5.27k
    {
1034
5.27k
        if (hDecoder->channelConfiguration == 0)
1035
202
            hDecoder->channelConfiguration = channels;
1036
1037
5.27k
        if (channels == 8) /* 7.1 */
1038
271
            hDecoder->channelConfiguration = 7;
1039
5.27k
        if (channels == 7) /* not a standard channelConfiguration */
1040
0
            hDecoder->channelConfiguration = 0;
1041
5.27k
    }
1042
1043
5.32k
    if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix)
1044
873
    {
1045
873
        hDecoder->downMatrix = 1;
1046
873
        output_channels = 2;
1047
4.45k
    } else {
1048
4.45k
        output_channels = channels;
1049
4.45k
    }
1050
1051
5.32k
#if (defined(PS_DEC) || defined(DRM_PS))
1052
5.32k
    hDecoder->upMatrix = 0;
1053
5.32k
#endif
1054
1055
    /* Make a channel configuration based on either a PCE or a channelConfiguration */
1056
5.32k
    if (!hDecoder->downMatrix && hDecoder->pce_set)
1057
258
    {
1058
        /* In some codepath program_config_element result is ignored. */
1059
258
        if (hDecoder->pce.channels > MAX_CHANNELS)
1060
6
        {
1061
6
            hInfo->error = 22;
1062
6
            return NULL;
1063
6
        }
1064
258
    }
1065
5.32k
    create_channel_config(hDecoder, hInfo);
1066
1067
    /* number of samples in this frame */
1068
5.32k
    hInfo->samples = frame_len*output_channels;
1069
    /* number of channels in this frame */
1070
5.32k
    hInfo->channels = output_channels;
1071
    /* samplerate */
1072
5.32k
    hInfo->samplerate = get_sample_rate(hDecoder->sf_index);
1073
    /* object type */
1074
5.32k
    hInfo->object_type = hDecoder->object_type;
1075
    /* sbr */
1076
5.32k
    hInfo->sbr = NO_SBR;
1077
    /* header type */
1078
5.32k
    hInfo->header_type = RAW;
1079
5.32k
    if (hDecoder->adif_header_present)
1080
0
        hInfo->header_type = ADIF;
1081
5.32k
    if (hDecoder->adts_header_present)
1082
58
        hInfo->header_type = ADTS;
1083
#if 0
1084
    if (hDecoder->latm_header_present)
1085
        hInfo->header_type = LATM;
1086
#endif
1087
5.32k
#if (defined(PS_DEC) || defined(DRM_PS))
1088
5.32k
    hInfo->ps = hDecoder->ps_used_global;
1089
5.32k
#endif
1090
1091
    /* check if frame has channel elements */
1092
5.32k
    if (channels == 0)
1093
0
    {
1094
0
        hDecoder->frame++;
1095
0
        return NULL;
1096
0
    }
1097
1098
5.32k
    {
1099
5.32k
        static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t),
1100
5.32k
            sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t),
1101
5.32k
            sizeof(int16_t), sizeof(int16_t), 0, 0, 0
1102
5.32k
        };
1103
5.32k
        uint8_t stride = str[hDecoder->config.outputFormat-1];
1104
5.32k
#ifdef SBR_DEC
1105
5.32k
        if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1))
1106
3.03k
        {
1107
3.03k
            stride = 2 * stride;
1108
3.03k
        }
1109
5.32k
#endif
1110
5.32k
        required_buffer_size = frame_len*output_channels*stride;
1111
5.32k
    }
1112
1113
    /* check if we want to use internal sample_buffer */
1114
5.32k
    if (sample_buffer_size == 0)
1115
3.28k
    {
1116
        /* allocate the buffer for the final samples */
1117
3.28k
        if (hDecoder->sample_buffer_size != required_buffer_size) 
1118
2.79k
        {
1119
2.79k
            if (hDecoder->sample_buffer)
1120
59
                faad_free(hDecoder->sample_buffer);
1121
2.79k
            hDecoder->sample_buffer = NULL;
1122
2.79k
            hDecoder->sample_buffer = faad_malloc(required_buffer_size);
1123
2.79k
            hDecoder->sample_buffer_size = required_buffer_size;
1124
2.79k
        }
1125
3.28k
    } else if (sample_buffer_size < required_buffer_size) {
1126
        /* provided sample buffer is not big enough */
1127
801
        hInfo->error = 27;
1128
801
        return NULL;
1129
801
    }
1130
1131
4.52k
    if (sample_buffer_size == 0)
1132
3.28k
    {
1133
3.28k
        sample_buffer = hDecoder->sample_buffer;
1134
3.28k
    } else {
1135
1.23k
        sample_buffer = *sample_buffer2;
1136
1.23k
    }
1137
1138
4.52k
#ifdef SBR_DEC
1139
4.52k
    if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
1140
2.98k
    {
1141
2.98k
        uint8_t ele;
1142
1143
        /* this data is different when SBR is used or when the data is upsampled */
1144
2.98k
        if (!hDecoder->downSampledSBR)
1145
2.44k
        {
1146
2.44k
            frame_len *= 2;
1147
2.44k
            hInfo->samples *= 2;
1148
2.44k
            hInfo->samplerate *= 2;
1149
2.44k
        }
1150
1151
        /* check if every element was provided with SBR data */
1152
15.6k
        for (ele = 0; ele < hDecoder->fr_ch_ele; ele++)
1153
12.6k
        {
1154
12.6k
            if (hDecoder->sbr[ele] == NULL)
1155
4
            {
1156
4
                hInfo->error = 25;
1157
4
                goto error;
1158
4
            }
1159
12.6k
        }
1160
1161
        /* sbr */
1162
2.97k
        if (hDecoder->sbr_present_flag == 1)
1163
2.15k
        {
1164
2.15k
            hInfo->object_type = HE_AAC;
1165
2.15k
            hInfo->sbr = SBR_UPSAMPLED;
1166
2.15k
        } else {
1167
824
            hInfo->sbr = NO_SBR_UPSAMPLED;
1168
824
        }
1169
2.97k
        if (hDecoder->downSampledSBR)
1170
537
        {
1171
537
            hInfo->sbr = SBR_DOWNSAMPLED;
1172
537
        }
1173
2.97k
    }
1174
4.51k
#endif
1175
1176
1177
4.51k
    sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer,
1178
4.51k
        output_channels, frame_len, hDecoder->config.outputFormat);
1179
1180
1181
4.51k
#ifdef DRM
1182
    //conceal_output(hDecoder, frame_len, output_channels, sample_buffer);
1183
4.51k
#endif
1184
1185
1186
4.51k
    hDecoder->postSeekResetFlag = 0;
1187
1188
4.51k
    hDecoder->frame++;
1189
#ifdef LD_DEC
1190
    if (hDecoder->object_type != LD)
1191
    {
1192
#endif
1193
4.51k
        if (hDecoder->frame <= 1)
1194
1.49k
            hInfo->samples = 0;
1195
#ifdef LD_DEC
1196
    } else {
1197
        /* LD encoders will give lower delay */
1198
        if (hDecoder->frame <= 0)
1199
            hInfo->samples = 0;
1200
    }
1201
#endif
1202
1203
    /* cleanup */
1204
#ifdef ANALYSIS
1205
    fflush(stdout);
1206
#endif
1207
1208
#ifdef PROFILE
1209
    count = faad_get_ts() - count;
1210
    hDecoder->cycles += count;
1211
#endif
1212
1213
4.51k
    return sample_buffer;
1214
1215
13.0k
error:
1216
1217
    /* reset filterbank state */
1218
847k
    for (i = 0; i < MAX_CHANNELS; i++)
1219
834k
    {
1220
834k
        if (hDecoder->fb_intermed[i] != NULL)
1221
300k
        {
1222
300k
            memset(hDecoder->fb_intermed[i], 0, hDecoder->frameLength*sizeof(real_t));
1223
300k
        }
1224
834k
    }
1225
13.0k
#ifdef SBR_DEC
1226
638k
    for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
1227
625k
    {
1228
625k
        if (hDecoder->sbr[i] != NULL)
1229
227k
        {
1230
227k
            sbrReset(hDecoder->sbr[i]);
1231
227k
        }
1232
625k
    }
1233
13.0k
#endif
1234
1235
1236
13.0k
    faad_endbits(&ld);
1237
1238
    /* cleanup */
1239
#ifdef ANALYSIS
1240
    fflush(stdout);
1241
#endif
1242
1243
    return NULL;
1244
4.52k
}
decoder.c:aac_frame_decode
Line
Count
Source
850
34.4k
{
851
34.4k
    uint16_t i;
852
34.4k
    uint8_t channels = 0;
853
34.4k
    uint8_t output_channels = 0;
854
34.4k
    bitfile ld;
855
34.4k
    uint32_t bitsconsumed;
856
34.4k
    uint16_t frame_len;
857
34.4k
    void *sample_buffer;
858
#if 0
859
    uint32_t startbit=0, endbit=0, payload_bits=0;
860
#endif
861
34.4k
    uint32_t required_buffer_size=0;
862
863
#ifdef PROFILE
864
    int64_t count = faad_get_ts();
865
#endif
866
867
    /* safety checks */
868
34.4k
    if ((hDecoder == NULL) || (hInfo == NULL) || (buffer == NULL))
869
0
    {
870
0
        return NULL;
871
0
    }
872
873
#if 0
874
    printf("%d\n", buffer_size*8);
875
#endif
876
877
34.4k
    frame_len = hDecoder->frameLength;
878
879
880
34.4k
    memset(hInfo, 0, sizeof(NeAACDecFrameInfo));
881
34.4k
    memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0]));
882
883
#ifdef USE_TIME_LIMIT
884
    if ((TIME_LIMIT * get_sample_rate(hDecoder->sf_index)) > hDecoder->TL_count)
885
    {
886
        hDecoder->TL_count += 1024;
887
    } else {
888
        hInfo->error = (NUM_ERROR_MESSAGES-1);
889
        goto error;
890
    }
891
#endif
892
893
894
    /* check for some common metadata tag types in the bitstream
895
     * No need to return an error
896
     */
897
    /* ID3 */
898
34.4k
    if (buffer_size >= 128)
899
3.49k
    {
900
3.49k
        if (memcmp(buffer, "TAG", 3) == 0)
901
6
        {
902
            /* found it */
903
6
            hInfo->bytesconsumed = 128; /* 128 bytes fixed size */
904
            /* no error, but no output either */
905
6
            return NULL;
906
6
        }
907
3.49k
    }
908
909
910
    /* initialize the bitstream */
911
34.4k
    faad_initbits(&ld, buffer, buffer_size);
912
34.4k
    if (ld.error != 0)
913
13.8k
        return NULL;
914
915
#if 0
916
    {
917
        int i;
918
        for (i = 0; i < ((buffer_size+3)>>2); i++)
919
        {
920
            uint8_t *buf;
921
            uint32_t temp = 0;
922
            buf = faad_getbitbuffer(&ld, 32);
923
            //temp = getdword((void*)buf);
924
            temp = *((uint32_t*)buf);
925
            printf("0x%.8X\n", temp);
926
            free(buf);
927
        }
928
        faad_endbits(&ld);
929
        faad_initbits(&ld, buffer, buffer_size);
930
    }
931
#endif
932
933
#if 0
934
    if(hDecoder->latm_header_present)
935
    {
936
        payload_bits = faad_latm_frame(&hDecoder->latm_config, &ld);
937
        startbit = faad_get_processed_bits(&ld);
938
        if(payload_bits == -1U)
939
        {
940
            hInfo->error = 1;
941
            goto error;
942
        }
943
    }
944
#endif
945
946
#ifdef DRM
947
    if (hDecoder->object_type == DRM_ER_LC)
948
    {
949
        /* We do not support stereo right now */
950
        if (0) //(hDecoder->channelConfiguration == 2)
951
        {
952
            hInfo->error = 28; // Throw CRC error
953
            goto error;
954
        }
955
956
        faad_getbits(&ld, 8
957
            DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC"));
958
    }
959
#endif
960
961
20.5k
    if (hDecoder->adts_header_present)
962
750
    {
963
750
        adts_header adts;
964
965
750
        adts.old_format = hDecoder->config.useOldADTSFormat;
966
750
        if ((hInfo->error = adts_frame(&adts, &ld)) > 0)
967
101
            goto error;
968
969
        /* MPEG2 does byte_alignment() here,
970
         * but ADTS header is always multiple of 8 bits in MPEG2
971
         * so not needed to actually do it.
972
         */
973
750
    }
974
975
#ifdef ANALYSIS
976
    dbg_count = 0;
977
#endif
978
979
    /* decode the complete bitstream */
980
#ifdef DRM
981
    if (/*(hDecoder->object_type == 6) ||*/ hDecoder->object_type == DRM_ER_LC)
982
    {
983
        DRM_aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);
984
    } else {
985
#endif
986
20.4k
        raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);
987
#ifdef DRM
988
    }
989
#endif
990
991
#if 0
992
    if(hDecoder->latm_header_present)
993
    {
994
        endbit = faad_get_processed_bits(&ld);
995
        if(endbit-startbit > payload_bits)
996
            fprintf(stderr, "\r\nERROR, too many payload bits read: %u > %d. Please. report with a link to a sample\n",
997
                endbit-startbit, payload_bits);
998
        if(hDecoder->latm_config.otherDataLenBits > 0)
999
            faad_getbits(&ld, hDecoder->latm_config.otherDataLenBits);
1000
        faad_byte_align(&ld);
1001
    }
1002
#endif
1003
1004
20.4k
    channels = hDecoder->fr_channels;
1005
1006
20.4k
    if (hInfo->error > 0)
1007
14.3k
        goto error;
1008
1009
    /* safety check */
1010
6.14k
    if (channels == 0 || channels > MAX_CHANNELS)
1011
102
    {
1012
        /* invalid number of channels */
1013
102
        hInfo->error = 12;
1014
102
        goto error;
1015
102
    }
1016
1017
    /* no more bit reading after this */
1018
6.04k
    bitsconsumed = faad_get_processed_bits(&ld);
1019
6.04k
    hInfo->bytesconsumed = bit2byte(bitsconsumed);
1020
6.04k
    if (ld.error)
1021
0
    {
1022
0
        hInfo->error = 14;
1023
0
        goto error;
1024
0
    }
1025
6.04k
    faad_endbits(&ld);
1026
1027
1028
6.04k
    if (!hDecoder->adts_header_present && !hDecoder->adif_header_present
1029
#if 0
1030
        && !hDecoder->latm_header_present
1031
#endif
1032
6.04k
        )
1033
5.85k
    {
1034
5.85k
        if (hDecoder->channelConfiguration == 0)
1035
152
            hDecoder->channelConfiguration = channels;
1036
1037
5.85k
        if (channels == 8) /* 7.1 */
1038
1.02k
            hDecoder->channelConfiguration = 7;
1039
5.85k
        if (channels == 7) /* not a standard channelConfiguration */
1040
41
            hDecoder->channelConfiguration = 0;
1041
5.85k
    }
1042
1043
6.04k
    if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix)
1044
745
    {
1045
745
        hDecoder->downMatrix = 1;
1046
745
        output_channels = 2;
1047
5.29k
    } else {
1048
5.29k
        output_channels = channels;
1049
5.29k
    }
1050
1051
6.04k
#if (defined(PS_DEC) || defined(DRM_PS))
1052
6.04k
    hDecoder->upMatrix = 0;
1053
6.04k
#endif
1054
1055
    /* Make a channel configuration based on either a PCE or a channelConfiguration */
1056
6.04k
    if (!hDecoder->downMatrix && hDecoder->pce_set)
1057
187
    {
1058
        /* In some codepath program_config_element result is ignored. */
1059
187
        if (hDecoder->pce.channels > MAX_CHANNELS)
1060
6
        {
1061
6
            hInfo->error = 22;
1062
6
            return NULL;
1063
6
        }
1064
187
    }
1065
6.03k
    create_channel_config(hDecoder, hInfo);
1066
1067
    /* number of samples in this frame */
1068
6.03k
    hInfo->samples = frame_len*output_channels;
1069
    /* number of channels in this frame */
1070
6.03k
    hInfo->channels = output_channels;
1071
    /* samplerate */
1072
6.03k
    hInfo->samplerate = get_sample_rate(hDecoder->sf_index);
1073
    /* object type */
1074
6.03k
    hInfo->object_type = hDecoder->object_type;
1075
    /* sbr */
1076
6.03k
    hInfo->sbr = NO_SBR;
1077
    /* header type */
1078
6.03k
    hInfo->header_type = RAW;
1079
6.03k
    if (hDecoder->adif_header_present)
1080
0
        hInfo->header_type = ADIF;
1081
6.03k
    if (hDecoder->adts_header_present)
1082
187
        hInfo->header_type = ADTS;
1083
#if 0
1084
    if (hDecoder->latm_header_present)
1085
        hInfo->header_type = LATM;
1086
#endif
1087
6.03k
#if (defined(PS_DEC) || defined(DRM_PS))
1088
6.03k
    hInfo->ps = hDecoder->ps_used_global;
1089
6.03k
#endif
1090
1091
    /* check if frame has channel elements */
1092
6.03k
    if (channels == 0)
1093
0
    {
1094
0
        hDecoder->frame++;
1095
0
        return NULL;
1096
0
    }
1097
1098
6.03k
    {
1099
6.03k
        static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t),
1100
6.03k
            sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t),
1101
6.03k
            sizeof(int16_t), sizeof(int16_t), 0, 0, 0
1102
6.03k
        };
1103
6.03k
        uint8_t stride = str[hDecoder->config.outputFormat-1];
1104
6.03k
#ifdef SBR_DEC
1105
6.03k
        if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1))
1106
3.41k
        {
1107
3.41k
            stride = 2 * stride;
1108
3.41k
        }
1109
6.03k
#endif
1110
6.03k
        required_buffer_size = frame_len*output_channels*stride;
1111
6.03k
    }
1112
1113
    /* check if we want to use internal sample_buffer */
1114
6.03k
    if (sample_buffer_size == 0)
1115
4.67k
    {
1116
        /* allocate the buffer for the final samples */
1117
4.67k
        if (hDecoder->sample_buffer_size != required_buffer_size) 
1118
4.00k
        {
1119
4.00k
            if (hDecoder->sample_buffer)
1120
63
                faad_free(hDecoder->sample_buffer);
1121
4.00k
            hDecoder->sample_buffer = NULL;
1122
4.00k
            hDecoder->sample_buffer = faad_malloc(required_buffer_size);
1123
4.00k
            hDecoder->sample_buffer_size = required_buffer_size;
1124
4.00k
        }
1125
4.67k
    } else if (sample_buffer_size < required_buffer_size) {
1126
        /* provided sample buffer is not big enough */
1127
661
        hInfo->error = 27;
1128
661
        return NULL;
1129
661
    }
1130
1131
5.37k
    if (sample_buffer_size == 0)
1132
4.67k
    {
1133
4.67k
        sample_buffer = hDecoder->sample_buffer;
1134
4.67k
    } else {
1135
702
        sample_buffer = *sample_buffer2;
1136
702
    }
1137
1138
5.37k
#ifdef SBR_DEC
1139
5.37k
    if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
1140
3.44k
    {
1141
3.44k
        uint8_t ele;
1142
1143
        /* this data is different when SBR is used or when the data is upsampled */
1144
3.44k
        if (!hDecoder->downSampledSBR)
1145
2.89k
        {
1146
2.89k
            frame_len *= 2;
1147
2.89k
            hInfo->samples *= 2;
1148
2.89k
            hInfo->samplerate *= 2;
1149
2.89k
        }
1150
1151
        /* check if every element was provided with SBR data */
1152
19.5k
        for (ele = 0; ele < hDecoder->fr_ch_ele; ele++)
1153
16.0k
        {
1154
16.0k
            if (hDecoder->sbr[ele] == NULL)
1155
5
            {
1156
5
                hInfo->error = 25;
1157
5
                goto error;
1158
5
            }
1159
16.0k
        }
1160
1161
        /* sbr */
1162
3.43k
        if (hDecoder->sbr_present_flag == 1)
1163
1.78k
        {
1164
1.78k
            hInfo->object_type = HE_AAC;
1165
1.78k
            hInfo->sbr = SBR_UPSAMPLED;
1166
1.78k
        } else {
1167
1.64k
            hInfo->sbr = NO_SBR_UPSAMPLED;
1168
1.64k
        }
1169
3.43k
        if (hDecoder->downSampledSBR)
1170
536
        {
1171
536
            hInfo->sbr = SBR_DOWNSAMPLED;
1172
536
        }
1173
3.43k
    }
1174
5.37k
#endif
1175
1176
1177
5.37k
    sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer,
1178
5.37k
        output_channels, frame_len, hDecoder->config.outputFormat);
1179
1180
1181
#ifdef DRM
1182
    //conceal_output(hDecoder, frame_len, output_channels, sample_buffer);
1183
#endif
1184
1185
1186
5.37k
    hDecoder->postSeekResetFlag = 0;
1187
1188
5.37k
    hDecoder->frame++;
1189
5.37k
#ifdef LD_DEC
1190
5.37k
    if (hDecoder->object_type != LD)
1191
4.43k
    {
1192
4.43k
#endif
1193
4.43k
        if (hDecoder->frame <= 1)
1194
1.40k
            hInfo->samples = 0;
1195
4.43k
#ifdef LD_DEC
1196
4.43k
    } else {
1197
        /* LD encoders will give lower delay */
1198
936
        if (hDecoder->frame <= 0)
1199
0
            hInfo->samples = 0;
1200
936
    }
1201
5.37k
#endif
1202
1203
    /* cleanup */
1204
#ifdef ANALYSIS
1205
    fflush(stdout);
1206
#endif
1207
1208
#ifdef PROFILE
1209
    count = faad_get_ts() - count;
1210
    hDecoder->cycles += count;
1211
#endif
1212
1213
5.37k
    return sample_buffer;
1214
1215
14.5k
error:
1216
1217
    /* reset filterbank state */
1218
944k
    for (i = 0; i < MAX_CHANNELS; i++)
1219
929k
    {
1220
929k
        if (hDecoder->fb_intermed[i] != NULL)
1221
515k
        {
1222
515k
            memset(hDecoder->fb_intermed[i], 0, hDecoder->frameLength*sizeof(real_t));
1223
515k
        }
1224
929k
    }
1225
14.5k
#ifdef SBR_DEC
1226
712k
    for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
1227
697k
    {
1228
697k
        if (hDecoder->sbr[i] != NULL)
1229
356k
        {
1230
356k
            sbrReset(hDecoder->sbr[i]);
1231
356k
        }
1232
697k
    }
1233
14.5k
#endif
1234
1235
1236
14.5k
    faad_endbits(&ld);
1237
1238
    /* cleanup */
1239
#ifdef ANALYSIS
1240
    fflush(stdout);
1241
#endif
1242
1243
    return NULL;
1244
5.37k
}