Home | History | Annotate | Download | only in aacdec
      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: sbr_extract_extended_data.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     SBR_FRAME_DATA *hFrameData,     Destination for extracted data of left channel
     33     SBR_FRAME_DATA *hFrameDataRight Destination for extracted data of right channel
     34     BIT_BUFFER hBitBuf              pointer to bit buffer
     35 
     36 
     37 ------------------------------------------------------------------------------
     38  FUNCTION DESCRIPTION
     39 
     40   Reads extension data from the bitstream
     41 
     42   The bitstream format allows up to 4 kinds of extended data element.
     43   Extended data may contain several elements, each identified by a 2-bit-ID.
     44 
     45 ------------------------------------------------------------------------------
     46  REQUIREMENTS
     47 
     48 
     49 ------------------------------------------------------------------------------
     50  REFERENCES
     51 
     52 SC 29 Software Copyright Licencing Disclaimer:
     53 
     54 This software module was originally developed by
     55   Coding Technologies
     56 
     57 and edited by
     58   -
     59 
     60 in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3
     61 standards for reference purposes and its performance may not have been
     62 optimized. This software module is an implementation of one or more tools as
     63 specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards.
     64 ISO/IEC gives users free license to this software module or modifications
     65 thereof for use in products claiming conformance to audiovisual and
     66 image-coding related ITU Recommendations and/or ISO/IEC International
     67 Standards. ISO/IEC gives users the same free license to this software module or
     68 modifications thereof for research purposes and further ISO/IEC standardisation.
     69 Those intending to use this software module in products are advised that its
     70 use may infringe existing patents. ISO/IEC have no liability for use of this
     71 software module or modifications thereof. Copyright is not released for
     72 products that do not conform to audiovisual and image-coding related ITU
     73 Recommendations and/or ISO/IEC International Standards.
     74 The original developer retains full right to modify and use the code for its
     75 own purpose, assign or donate the code to a third party and to inhibit third
     76 parties from using the code for products that do not conform to audiovisual and
     77 image-coding related ITU Recommendations and/or ISO/IEC International Standards.
     78 This copyright notice must be included in all copies or derivative works.
     79 Copyright (c) ISO/IEC 2002.
     80 
     81 ------------------------------------------------------------------------------
     82  PSEUDO-CODE
     83 
     84 ------------------------------------------------------------------------------
     85 */
     86 
     87 
     88 /*----------------------------------------------------------------------------
     89 ; INCLUDES
     90 ----------------------------------------------------------------------------*/
     91 
     92 #ifdef AAC_PLUS
     93 
     94 
     95 #include    "sbr_extract_extended_data.h"
     96 #include    "buf_getbits.h"
     97 
     98 #ifdef PARAMETRICSTEREO
     99 #include    "ps_read_data.h"
    100 #endif
    101 
    102 /*----------------------------------------------------------------------------
    103 ; MACROS
    104 ; Define module specific macros here
    105 ----------------------------------------------------------------------------*/
    106 
    107 
    108 /*----------------------------------------------------------------------------
    109 ; DEFINES
    110 ; Include all pre-processor statements here. Include conditional
    111 ; compile variables also.
    112 ----------------------------------------------------------------------------*/
    113 
    114 /*----------------------------------------------------------------------------
    115 ; LOCAL FUNCTION DEFINITIONS
    116 ; Function Prototype declaration
    117 ----------------------------------------------------------------------------*/
    118 
    119 /*----------------------------------------------------------------------------
    120 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    121 ; Variable declaration - defined here and used outside this module
    122 ----------------------------------------------------------------------------*/
    123 
    124 /*----------------------------------------------------------------------------
    125 ; EXTERNAL FUNCTION REFERENCES
    126 ; Declare functions defined elsewhere and referenced in this module
    127 ----------------------------------------------------------------------------*/
    128 
    129 /*----------------------------------------------------------------------------
    130 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    131 ; Declare variables used in this module but defined elsewhere
    132 ----------------------------------------------------------------------------*/
    133 
    134 /*----------------------------------------------------------------------------
    135 ; FUNCTION CODE
    136 ----------------------------------------------------------------------------*/
    137 
    138 void sbr_extract_extended_data(BIT_BUFFER * hBitBuf
    139 #ifdef PARAMETRICSTEREO         /* Parametric Stereo Decoder */
    140                                , HANDLE_PS_DEC hParametricStereoDec
    141 #endif
    142                               )
    143 {
    144     Int32 extended_data;
    145     Int32 i;
    146     Int32 nBitsLeft;
    147     Int32 extension_id;
    148 
    149     extended_data = buf_get_1bit(hBitBuf);    /*  SI_SBR_EXTENDED_DATA_BITS  */
    150 
    151     if (extended_data)
    152     {
    153         Int32 cnt;
    154 
    155         cnt = buf_getbits(hBitBuf, SI_SBR_EXTENSION_SIZE_BITS);
    156         if (cnt == (1 << SI_SBR_EXTENSION_SIZE_BITS) - 1)
    157         {
    158             cnt += buf_getbits(hBitBuf, SI_SBR_EXTENSION_ESC_COUNT_BITS);
    159         }
    160 
    161         nBitsLeft = (cnt << 3);
    162         while (nBitsLeft > 7)
    163         {
    164             extension_id = buf_getbits(hBitBuf, SI_SBR_EXTENSION_ID_BITS);
    165             nBitsLeft -= SI_SBR_EXTENSION_ID_BITS;
    166 
    167             switch (extension_id)
    168             {
    169 #ifdef HQ_SBR
    170 #ifdef PARAMETRICSTEREO
    171 
    172                     /*
    173                      *  Parametric Coding supports the Transient, Sinusoidal, Noise, and
    174                      *  Parametric Stereo tools (MPEG4).
    175                      *  3GPP use aac+ hq along with ps for enhanced aac+
    176                      *  The PS tool uses complex-value QMF data, therefore can not be used
    177                      *  with low power version of aac+
    178                      */
    179                 case EXTENSION_ID_PS_CODING:
    180 
    181                     if (hParametricStereoDec != NULL)
    182                     {
    183                         if (!hParametricStereoDec->psDetected)
    184                         {
    185                             /* parametric stereo detected */
    186                             hParametricStereoDec->psDetected = 1;
    187                         }
    188 
    189                         nBitsLeft -= ps_read_data(hParametricStereoDec,
    190                                                   hBitBuf,
    191                                                   nBitsLeft);
    192 
    193                     }
    194 
    195                     break;
    196 #endif
    197 #endif
    198                 case 0:
    199 
    200                 default:
    201                     /*   An unknown extension id causes the remaining extension data
    202                      *   to be skipped
    203                      */
    204                     cnt = nBitsLeft >> 3; /* number of remaining bytes */
    205 
    206                     for (i = 0; i < cnt; i++)
    207                     {
    208                         buf_getbits(hBitBuf, 8);
    209                     }
    210 
    211                     nBitsLeft -= (cnt << 3);
    212             }
    213         }
    214         /* read fill bits for byte alignment */
    215         buf_getbits(hBitBuf, nBitsLeft);
    216     }
    217 }
    218 
    219 
    220 #endif
    221 
    222 
    223 
    224