1/* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18/*
19
20 Filename: get_sbr_bitstream.c
21
22------------------------------------------------------------------------------
23 REVISION HISTORY
24
25
26 Who:                                   Date: MM/DD/YYYY
27 Description:
28
29------------------------------------------------------------------------------
30 INPUT AND OUTPUT DEFINITIONS
31
32    INPUT
33
34    SBRDECODER self,
35    SBRBITSTREAM * stream,
36    float *timeData,
37    int numChannels
38
39    OUTPUT
40
41    errorCode, noError if successful
42
43------------------------------------------------------------------------------
44 FUNCTION DESCRIPTION
45
46        sbr decoder processing, set up SBR decoder phase 2 in case of
47        different cotrol data
48
49------------------------------------------------------------------------------
50 REQUIREMENTS
51
52
53------------------------------------------------------------------------------
54 REFERENCES
55
56SC 29 Software Copyright Licencing Disclaimer:
57
58This software module was originally developed by
59  Coding Technologies
60
61and edited by
62  -
63
64in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3
65standards for reference purposes and its performance may not have been
66optimized. This software module is an implementation of one or more tools as
67specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards.
68ISO/IEC gives users free license to this software module or modifications
69thereof for use in products claiming conformance to audiovisual and
70image-coding related ITU Recommendations and/or ISO/IEC International
71Standards. ISO/IEC gives users the same free license to this software module or
72modifications thereof for research purposes and further ISO/IEC standardisation.
73Those intending to use this software module in products are advised that its
74use may infringe existing patents. ISO/IEC have no liability for use of this
75software module or modifications thereof. Copyright is not released for
76products that do not conform to audiovisual and image-coding related ITU
77Recommendations and/or ISO/IEC International Standards.
78The original developer retains full right to modify and use the code for its
79own purpose, assign or donate the code to a third party and to inhibit third
80parties from using the code for products that do not conform to audiovisual and
81image-coding related ITU Recommendations and/or ISO/IEC International Standards.
82This copyright notice must be included in all copies or derivative works.
83Copyright (c) ISO/IEC 2002.
84
85------------------------------------------------------------------------------
86 PSEUDO-CODE
87
88------------------------------------------------------------------------------
89*/
90
91
92/*----------------------------------------------------------------------------
93; INCLUDES
94----------------------------------------------------------------------------*/
95#ifdef AAC_PLUS
96
97#include "get_sbr_bitstream.h"
98#include "pv_audio_type_defs.h"
99#include    "sbr_crc_check.h"
100
101/*----------------------------------------------------------------------------
102; MACROS
103; Define module specific macros here
104----------------------------------------------------------------------------*/
105
106
107/*----------------------------------------------------------------------------
108; DEFINES
109; Include all pre-processor statements here. Include conditional
110; compile variables also.
111----------------------------------------------------------------------------*/
112
113/*----------------------------------------------------------------------------
114; LOCAL FUNCTION DEFINITIONS
115; Function Prototype declaration
116----------------------------------------------------------------------------*/
117
118/*----------------------------------------------------------------------------
119; LOCAL STORE/BUFFER/POINTER DEFINITIONS
120; Variable declaration - defined here and used outside this module
121----------------------------------------------------------------------------*/
122
123/*----------------------------------------------------------------------------
124; EXTERNAL FUNCTION REFERENCES
125; Declare functions defined elsewhere and referenced in this module
126----------------------------------------------------------------------------*/
127
128/*----------------------------------------------------------------------------
129; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
130; Declare variables used in this module but defined elsewhere
131----------------------------------------------------------------------------*/
132
133/*----------------------------------------------------------------------------
134; FUNCTION CODE
135----------------------------------------------------------------------------*/
136
137void get_sbr_bitstream(SBRBITSTREAM *sbrBitStream, BITS *pInputStream)
138{
139    /*----------------------------------------------------------------------------
140    ; Define all local variables
141    ----------------------------------------------------------------------------*/
142
143    Int32 count;
144    Int32 esc_count;
145    Int32 Extention_Type;
146    Int32 i;
147
148    count = get9_n_lessbits(LEN_F_CNT, pInputStream);
149    if (count == 15)
150    {
151        esc_count = get9_n_lessbits(LEN_F_ESC, pInputStream);
152        count = esc_count + 14;
153    }
154
155
156
157    Extention_Type = get9_n_lessbits(LEN_F_CNT, pInputStream);
158
159
160    if (((Extention_Type == SBR_EXTENSION) || (Extention_Type == SBR_EXTENSION_CRC))
161            && (count < MAXSBRBYTES) && (count) && (sbrBitStream->NrElements < MAXNRELEMENTS))
162    {
163
164        sbrBitStream->sbrElement[sbrBitStream->NrElements].ExtensionType = Extention_Type;
165        sbrBitStream->sbrElement[sbrBitStream->NrElements].Payload       = count;
166        sbrBitStream->sbrElement[sbrBitStream->NrElements].Data[0]       = (UChar) get9_n_lessbits(LEN_F_CNT, pInputStream);
167        for (i = 1 ; i < count ; i++)
168        {
169            sbrBitStream->sbrElement[sbrBitStream->NrElements].Data[i] = (UChar) get9_n_lessbits(8, pInputStream);
170        }
171
172        sbrBitStream->NrElements += 1;
173
174    }
175    else
176    {
177        pInputStream->usedBits += (count - 1) * LEN_BYTE;
178        pInputStream->usedBits += 4;        /* compenste for LEN_F_CNT (=4) bits read for Extention_Type */
179
180    }
181}
182
183#endif
184