summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/aacdec/get_ga_specific_config.cpp
blob: 65c00ea0142ed831c295612c9112678ee146d15f (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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
/* ------------------------------------------------------------------
 * 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.
 * -------------------------------------------------------------------
 */
/*

 Pathname: get_GA_specific_config.c

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

 Description: Modified per review comments

 Description: Change getbits.h to ibstream.h

 Description: (1) use enum type for audioObjectType (2) update revision history

 Description: Updated the SW template to include the full pathname to the
 source file and a slightly modified copyright header.

 Description: Updated to use scratch memory for the temporary prog config.

 Description: Replace some instances of getbits to get1bits
              when only 1 bit is read.

 Who:                               Date:
 Description:

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

 Inputs:
        pVars   = pointer to the structure that holds all information for
                  this instance of the library. pVars->prog_config
                  pVars->mc_info, pVars->pWinSeqInfo, pVars->SFBWidth128
                  are needed for calling set_mc_info.
                  Data type pointer to tDec_Int_File

        channel_config = variable that indicates the channel configuration
                         information, in this decoder library, only values
                         0, 1, and 2 are allowed.
                         Data type UInt

        audioObjectType = variable that indicates the Audio Object Type.
                          Data type UInt.

        pInputStream = pointer to a BITS structure that holds information
                       regarding the input stream.

 Local Stores/Buffers/Pointers Needed:
    None

 Global Stores/Buffers/Pointers Needed:
    None

 Outputs:
    status = 0 if success
             1 otherwise

 Pointers and Buffers Modified:
    pVars->mc_info contents are updated with channel information.
    if infoinit is called within set_mc_info, then
    pVars->pWinSeqInfo contents are updated with window information.
    pVars->SFBWidth128 contents are updated with scale factor band width data.

 Local Stores Modified:
    None

 Global Stores Modified:
    None

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

 This function takes the sampling_rate_idx, channel_config, and
 audioObjectType from AudioSpecificConfig() and set the decoder configuration
 necessary for the decoder to decode properly.
 It also reads the bitstream for frame length, scalable bitstream information
 and extension information to General Audio defined in MPEG-4 phase 1

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

  This function shall not use global variables

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

 (1) ISO/IEC 14496-3: 1999(E)
 Part 3
 Subpart 1  p18     1.6 Interface to MPEG-4 Systems
 Subpart 4  p13     4.4.1 GA Specific Configuration
 Amendment  p10     6.2.1 AudioSpecificInfo
 Amendment  p78     8.2 Decoder configuration (GASpecificConfig)

 (2) AAC DecoderSpecificInfo Information
   PacketVideo descriptions - San Diego

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

    frameLenFlag = CALL getbits(
                            neededBits = LEN_FRAME_LEN_FLAG,
                            pInputStream = pInputStream);
                        MODIFYING (pInputStream)
                        RETURNING (frameLenFlag)

    dependsOnCoreCoder = CALL getbits(
                               neededBits = LEN_DEPEND_ON_CORE,
                               pInputStream = pInputStream);
                        MODIFYING (pInputStream)
                        RETURNING (dependsOnCoreCoder)

    IF (dependsOnCoreCoder != FALSE)
    THEN
        coreCoderDelay = CALL getbits(
                                neededBits = LEN_CORE_DELAY,
                                pInputStream = pInputStream);
                            MODIFYING (pInputStream)
                            RETURNING (coreCoderDelay)
    ENDIF

    extFlag = CALL getbits(
                      neededBits = LEN_EXT_FLAG,
                      pInputStream = pInputStream);
                   MODIFYING (pInputStream)
                   RETURNING (extFlag)

    IF (channel_config == 0)
    THEN
        status = CALL get_prog_config(
                        pVars = pVars,
                        pScratchPCE = &pVars->scratch_prog_config);
                   MODIFYING (pVars, pScratchPCE)
                   RETURNING (status)

    ELSE
        channel_config--;
        pVars->prog_config.front.ele_is_cpe[0] = channel_config;
        pVars->prog_config.front.ele_tag[0] = 0;

        status = CALL set_mc_info(
                        pMC_Info =  &(pVars->mc_info),
                        audioObjectType = audioObjectType,
                        sampling_rate_idx = pVars->prog_config.sampling_rate_idx,
                        tag = pVars->prog_config.front.ele_tag[0],
                        is_cpe = pVars->prog_config.front.ele_is_cpe[0],
                        pWinSeqInfo = pVars->pWinSeqInfo,
                        sfbwidth128 = pVars->SFBWidth128);
                    MODIFYING (pMC_Info, pWinSeqInfo, sfbwidth128)
                    RETURNING (SUCCESS)
    ENDIF

    IF ((audioObjectType == MP4AUDIO_AAC_SCALABLE) OR
        (audioObjectType == MP4AUDIO_ER_AAC_SCALABLE))
    THEN
        layer_num = CALL getbits(
                            neededBits = LEN_LAYER_NUM,
                            pInputStream = pInputStream);
                        MODIFYING (pInputStream)
                        RETURNING (layer_num)

        status = 1;
    ENDIF

    IF (extFlag != FALSE)
    THEN
         IF (audioObjectType == MP4AUDIO_ER_BSAC)
         THEN
              numOfSubFrame = CALL getbits(
                                     neededBits = LEN_SUB_FRAME,
                                     pInputStream = pInputStream);
                                MODIFYING (pInputStream)
                                RETURNING (numOfSubFrame)

              layer_len = CALL getbits(
                                neededBits = LEN_LAYER_LEN,
                                pInputStream = pInputStream);
                               MODIFYING (pInputStream)
                               RETURNING (layer_len)

         ENDIF

         IF (((audioObjectType > 16) AND (audioObjectType < 22)) OR
             (audioObjectType == 23))
         THEN
             aacSectionDataResilienceFlag =
                            CALL getbits(
                                    neededBits = LEN_SECT_RES_FLAG,
                                    pInputStream = pInputStream);
                                MODIFYING (pInputStream)
                                RETURNING (aacSectionDataResilienceFlag)

             aacScalefactorDataResilienceFlag =
                            CALL getbits(
                                    neededBits = LEN_SFB_RES_FLAG,
                                    pInputStream = pInputStream);
                                MODIFYING (pInputStream)
                                RETURNING (aacScalefactorDataResilienceFlag)

             aacSpectralDataResilienceFlag =
                            CALL getbits(
                                    neededBits = LEN_SPEC_RES_FLAG,
                                    pInputStream = pInputStream);
                                MODIFYING (pInputStream)
                                RETURNING (aacSpectralDataResilienceFlag)
         ENDIF

        status = 1;

    ENDIF

    RETURN status;

------------------------------------------------------------------------------
 RESOURCES USED
   When the code is written for a specific target processor the
     the resources used should be documented below.

 STACK USAGE: [stack count for this module] + [variable to represent
          stack usage for each subroutine called]

     where: [stack usage variable] = stack usage for [subroutine
         name] (see [filename].ext)

 DATA MEMORY USED: x words

 PROGRAM MEMORY USED: x words

 CLOCK CYCLES: [cycle count equation for this module] + [variable
           used to represent cycle count for each subroutine
           called]

     where: [cycle count variable] = cycle count for [subroutine
        name] (see [filename].ext)

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


/*----------------------------------------------------------------------------
; INCLUDES
----------------------------------------------------------------------------*/
#include    "pv_audio_type_defs.h"
#include    "e_mp4ff_const.h"
#include    "e_tmp4audioobjecttype.h"
#include    "s_tdec_int_file.h"
#include    "get_ga_specific_config.h"
#include    "set_mc_info.h"
#include    "get_prog_config.h"
#include    "ibstream.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
----------------------------------------------------------------------------*/
Int get_GA_specific_config(
    tDec_Int_File * const pVars,
    BITS    *pInputStream,
    UInt     channel_config,
    const tMP4AudioObjectType audioObjectType
)
{

    Int status = SUCCESS;
    UInt dependsOnCoreCoder;
    /* Int coreCoderDelay; */
    UInt extFlag;

    /* These variables are left for future implementation */
    /* UInt layer_num; */
    /* UInt numOfSubFrame; */
    /* UInt layer_len; */
    /* UInt aacSectionDataResilienceFlag; */
    /* UInt aacScalefactorDataResilienceFlag; */
    /* UInt aacSpectralDataResilienceFlag; */
    Int  extFlag3;

    /*
     * frame length flag == 0, 1024 samples/frame
     * frame length flag == 1,  960 samples/frame
     */
    get1bits(/*            LEN_FRAME_LEN_FLAG,*/
        pInputStream);

    /*
     * dependsOnCoreCoder == 1, core coder has different sampling rate
     * in a scalable bitstream
     */
    dependsOnCoreCoder =
        get1bits(/*            LEN_DEPEND_ON_CORE,*/
            pInputStream);

    if (dependsOnCoreCoder != FALSE)
    {
        /*coreCoderDelay =
         *    getbits(
         *        LEN_CORE_DELAY,
         *        pInputStream);
         */

        status = 1; /* do not support scalable coding in this release */
    }

    /*
     * extension flag indicates if Amendment 1 objects are used or not
     * extension flag == 0 objects = 1, 2, 3, 4, 6, 7
     * extension flag == 1 objects = 17, 19, 20, 21, 22, 23
     */
    extFlag = get1bits(pInputStream);       /*  LEN_EXT_FLAG,*/


    /* Force checks for implicit channel configuration */
    pVars->mc_info.implicit_channeling = 1;

    if (status == SUCCESS)
    {

        if (channel_config == 0)
        {
            status = get_prog_config(pVars,
                                     &pVars->scratch.scratch_prog_config);

            if (status != SUCCESS)
            {
                pVars->prog_config.front.ele_is_cpe[0] = 0; /* default to mono  */
                pVars->mc_info.nch = 1;
                pVars->prog_config.front.ele_tag[0] = 0;

                status = SUCCESS;
            }
        }
        else
        {
            /*
             * dummy tag = 0 and
             * set up decoding configurations
             */
            channel_config--;
            pVars->prog_config.front.ele_is_cpe[0] = channel_config;
            pVars->prog_config.front.ele_tag[0] = 0;

            status =
                set_mc_info(
                    &(pVars->mc_info),
                    audioObjectType, /* previously profile */
                    pVars->prog_config.sampling_rate_idx,
                    pVars->prog_config.front.ele_tag[0],
                    pVars->prog_config.front.ele_is_cpe[0],
                    pVars->winmap, /*pVars->pWinSeqInfo,*/
                    pVars->SFBWidth128);

        } /* if (channel_config) */

    } /* if(status) */

    /*
     * This layer_num is not found in ISO/IEC specs,
     * but it is defined in San Diego spec for scalable bitstream
     */
    if ((audioObjectType == MP4AUDIO_AAC_SCALABLE) ||
            (audioObjectType == MP4AUDIO_ER_AAC_SCALABLE))
    {
        /*layer_num =
         *    getbits(
         *        LEN_LAYER_NUM,
         *        pInputStream);
         */

        status = 1; /* for this release only */
    }

    if (extFlag)
    {
        /*
         * currently do not implement these functionalities
         * defined in Amendment 1
         * keep it here for future release
         */
        if (audioObjectType == MP4AUDIO_ER_BSAC)
        {
            status = 1;     /* NOT SUPPORTED */
            /*
            numOfSubFrame = getbits( LEN_SUB_FRAME, pInputStream);

            layer_len = getbits( LEN_LAYER_LEN, pInputStream);
            */
        }

        /*
         * The following code is equivalent to
         * if ((audioObjectType == 17) || (audioObjectType == 18) ||
         *     (audioObjectType == 19) || (audioObjectType == 20) ||
         *     (audioObjectType == 21) || (audioObjectType == 23))
         */

        if (((audioObjectType > 16) && (audioObjectType < 22)) ||
                (audioObjectType == 23))
        {
            status = 1;     /* NOT SUPPORTED */
            /*
            aacSectionDataResilienceFlag = getbits( LEN_SECT_RES_FLAG,
                                                    pInputStream);

            aacScalefactorDataResilienceFlag = getbits( LEN_SCF_RES_FLAG,
                                                        pInputStream);

            aacSpectralDataResilienceFlag = getbits( LEN_SPEC_RES_FLAG,
                                                     pInputStream);
            */
        }
        /*
         * this flag is tbd in version 3 of ISO/IEC spec
         * if the encoder generates this bit, then it has to be read
         * current adif2mp4ff does not write this bit. If this bit is to
         * be read, it can be done by the following code:
         */

        extFlag3 = get1bits(pInputStream);       /*  LEN_EXT_FLAG3 */

        if (extFlag3)
        {
            status = 1;     /* NOT SUPPORTED */
        }

    }

    return status;
}