summaryrefslogtreecommitdiff
path: root/media/libstagefright/codecs/aacdec/sbr_get_header_data.cpp
blob: 42789aeee02005ffc5f6cbae557fd409d84306ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* ------------------------------------------------------------------
 * Copyright (C) 1998-2009 PacketVideo
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 * -------------------------------------------------------------------
 */
/*

 Filename: sbr_get_header_data.c

------------------------------------------------------------------------------
 REVISION HISTORY


 Who:                                   Date: MM/DD/YYYY
 Description:

------------------------------------------------------------------------------
 INPUT AND OUTPUT DEFINITIONS

 Arguments:     h_sbr_header - handle to struct SBR_HEADER_DATA
                hBitBuf      - handle to struct BIT_BUFFER
                id_sbr       - SBR_ELEMENT_ID

 Return:        error status - 0 if ok


------------------------------------------------------------------------------
 FUNCTION DESCRIPTION

    Reads header data from bitstream

------------------------------------------------------------------------------
 REQUIREMENTS


------------------------------------------------------------------------------
 REFERENCES

SC 29 Software Copyright Licencing Disclaimer:

This software module was originally developed by
  Coding Technologies

and edited by
  -

in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3
standards for reference purposes and its performance may not have been
optimized. This software module is an implementation of one or more tools as
specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards.
ISO/IEC gives users free license to this software module or modifications
thereof for use in products claiming conformance to audiovisual and
image-coding related ITU Recommendations and/or ISO/IEC International
Standards. ISO/IEC gives users the same free license to this software module or
modifications thereof for research purposes and further ISO/IEC standardisation.
Those intending to use this software module in products are advised that its
use may infringe existing patents. ISO/IEC have no liability for use of this
software module or modifications thereof. Copyright is not released for
products that do not conform to audiovisual and image-coding related ITU
Recommendations and/or ISO/IEC International Standards.
The original developer retains full right to modify and use the code for its
own purpose, assign or donate the code to a third party and to inhibit third
parties from using the code for products that do not conform to audiovisual and
image-coding related ITU Recommendations and/or ISO/IEC International Standards.
This copyright notice must be included in all copies or derivative works.
Copyright (c) ISO/IEC 2002.

------------------------------------------------------------------------------
 PSEUDO-CODE

------------------------------------------------------------------------------
*/


/*----------------------------------------------------------------------------
; INCLUDES
----------------------------------------------------------------------------*/

#ifdef AAC_PLUS


#include    "sbr_get_header_data.h"
#include    "sbr_constants.h"
#include    "buf_getbits.h"
#include    "aac_mem_funcs.h"

/*----------------------------------------------------------------------------
; MACROS
; Define module specific macros here
----------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------
; DEFINES
; Include all pre-processor statements here. Include conditional
; compile variables also.
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; LOCAL FUNCTION DEFINITIONS
; Function Prototype declaration
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
; Variable declaration - defined here and used outside this module
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; EXTERNAL FUNCTION REFERENCES
; Declare functions defined elsewhere and referenced in this module
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
; Declare variables used in this module but defined elsewhere
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; FUNCTION CODE
----------------------------------------------------------------------------*/

SBR_HEADER_STATUS sbr_get_header_data(SBR_HEADER_DATA   * h_sbr_header,
                                      BIT_BUFFER          * hBitBuf,
                                      SBR_SYNC_STATE     syncState)
{
    SBR_HEADER_DATA lastHeader;
    Int32 headerExtra1, headerExtra2;


    /* Copy header to temporary header */
    if (syncState == SBR_ACTIVE)
    {
        pv_memcpy(&lastHeader, h_sbr_header, sizeof(SBR_HEADER_DATA));
    }
    else
    {
        pv_memset((void *)&lastHeader, 0, sizeof(SBR_HEADER_DATA));
    }


    /* Read new header from bitstream */
    h_sbr_header->ampResolution   = buf_getbits(hBitBuf, SI_SBR_AMP_RES_BITS);
    h_sbr_header->startFreq       = buf_getbits(hBitBuf, SI_SBR_START_FREQ_BITS);
    h_sbr_header->stopFreq        = buf_getbits(hBitBuf, SI_SBR_STOP_FREQ_BITS);
    h_sbr_header->xover_band      = buf_getbits(hBitBuf, SI_SBR_XOVER_BAND_BITS);

    buf_getbits(hBitBuf, SI_SBR_RESERVED_BITS_HDR);

    headerExtra1    = buf_getbits(hBitBuf, SI_SBR_HEADER_EXTRA_1_BITS);
    headerExtra2    = buf_getbits(hBitBuf, SI_SBR_HEADER_EXTRA_2_BITS);

    /* handle extra header information */
    if (headerExtra1)
    {
        h_sbr_header->freqScale   = buf_getbits(hBitBuf, SI_SBR_FREQ_SCALE_BITS);
        h_sbr_header->alterScale  = buf_getbits(hBitBuf, SI_SBR_ALTER_SCALE_BITS);
        h_sbr_header->noise_bands = buf_getbits(hBitBuf, SI_SBR_NOISE_BANDS_BITS);
    }
    else
    { /* Set default values.*/
        h_sbr_header->freqScale   = SBR_FREQ_SCALE_DEFAULT;
        h_sbr_header->alterScale  = SBR_ALTER_SCALE_DEFAULT;
        h_sbr_header->noise_bands = SBR_NOISE_BANDS_DEFAULT;
    }


    if (headerExtra2)
    {
        h_sbr_header->limiterBands    = buf_getbits(hBitBuf, SI_SBR_LIMITER_BANDS_BITS);
        h_sbr_header->limiterGains    = buf_getbits(hBitBuf, SI_SBR_LIMITER_GAINS_BITS);
        h_sbr_header->interpolFreq    = buf_getbits(hBitBuf, SI_SBR_INTERPOL_FREQ_BITS);
        h_sbr_header->smoothingLength = buf_getbits(hBitBuf, SI_SBR_SMOOTHING_LENGTH_BITS);
    }
    else
    { /* Set default values.*/
        h_sbr_header->limiterBands    = SBR_LIMITER_BANDS_DEFAULT;
        h_sbr_header->limiterGains    = SBR_LIMITER_GAINS_DEFAULT;
        h_sbr_header->interpolFreq    = SBR_INTERPOL_FREQ_DEFAULT;
        h_sbr_header->smoothingLength = SBR_SMOOTHING_LENGTH_DEFAULT;
    }

    if (syncState == SBR_ACTIVE)
    {
        h_sbr_header->status = HEADER_OK;

        /* look for new settings */
        if (lastHeader.startFreq   != h_sbr_header->startFreq   ||
                lastHeader.stopFreq    != h_sbr_header->stopFreq    ||
                lastHeader.xover_band  != h_sbr_header->xover_band  ||
                lastHeader.freqScale   != h_sbr_header->freqScale   ||
                lastHeader.alterScale  != h_sbr_header->alterScale  ||
                lastHeader.noise_bands != h_sbr_header->noise_bands)
        {
            h_sbr_header->status = HEADER_RESET;
        }
    }
    else
    {
        h_sbr_header->status = HEADER_RESET;
    }

    return h_sbr_header->status;
}

#endif