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_crc_check.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 
     33 ------------------------------------------------------------------------------
     34  FUNCTION DESCRIPTION
     35 
     36 
     37 ------------------------------------------------------------------------------
     38  REQUIREMENTS
     39 
     40 
     41 ------------------------------------------------------------------------------
     42  REFERENCES
     43 
     44 SC 29 Software Copyright Licencing Disclaimer:
     45 
     46 This software module was originally developed by
     47   Coding Technologies
     48 
     49 and edited by
     50   -
     51 
     52 in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3
     53 standards for reference purposes and its performance may not have been
     54 optimized. This software module is an implementation of one or more tools as
     55 specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards.
     56 ISO/IEC gives users free license to this software module or modifications
     57 thereof for use in products claiming conformance to audiovisual and
     58 image-coding related ITU Recommendations and/or ISO/IEC International
     59 Standards. ISO/IEC gives users the same free license to this software module or
     60 modifications thereof for research purposes and further ISO/IEC standardisation.
     61 Those intending to use this software module in products are advised that its
     62 use may infringe existing patents. ISO/IEC have no liability for use of this
     63 software module or modifications thereof. Copyright is not released for
     64 products that do not conform to audiovisual and image-coding related ITU
     65 Recommendations and/or ISO/IEC International Standards.
     66 The original developer retains full right to modify and use the code for its
     67 own purpose, assign or donate the code to a third party and to inhibit third
     68 parties from using the code for products that do not conform to audiovisual and
     69 image-coding related ITU Recommendations and/or ISO/IEC International Standards.
     70 This copyright notice must be included in all copies or derivative works.
     71 Copyright (c) ISO/IEC 2002.
     72 
     73 ------------------------------------------------------------------------------
     74  PSEUDO-CODE
     75 
     76 ------------------------------------------------------------------------------
     77 */
     78 
     79 
     80 /*----------------------------------------------------------------------------
     81 ; INCLUDES
     82 ----------------------------------------------------------------------------*/
     83 
     84 #ifdef AAC_PLUS
     85 
     86 
     87 #include "sbr_crc_check.h"
     88 #include "s_crc_buffer.h"
     89 #include "buf_getbits.h"
     90 #include "sbr_constants.h"
     91 #include "check_crc.h"
     92 
     93 
     94 
     95 
     96 /*----------------------------------------------------------------------------
     97 ; MACROS
     98 ; Define module specific macros here
     99 ----------------------------------------------------------------------------*/
    100 
    101 
    102 /*----------------------------------------------------------------------------
    103 ; DEFINES
    104 ; Include all pre-processor statements here. Include conditional
    105 ; compile variables also.
    106 ----------------------------------------------------------------------------*/
    107 
    108 /*----------------------------------------------------------------------------
    109 ; LOCAL FUNCTION DEFINITIONS
    110 ; Function Prototype declaration
    111 ----------------------------------------------------------------------------*/
    112 
    113 /*----------------------------------------------------------------------------
    114 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    115 ; Variable declaration - defined here and used outside this module
    116 ----------------------------------------------------------------------------*/
    117 
    118 const unsigned short MAXCRCSTEP = 16;
    119 
    120 /*----------------------------------------------------------------------------
    121 ; EXTERNAL FUNCTION REFERENCES
    122 ; Declare functions defined elsewhere and referenced in this module
    123 ----------------------------------------------------------------------------*/
    124 
    125 /*----------------------------------------------------------------------------
    126 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    127 ; Declare variables used in this module but defined elsewhere
    128 ----------------------------------------------------------------------------*/
    129 
    130 /*----------------------------------------------------------------------------
    131 ; FUNCTION CODE
    132 ----------------------------------------------------------------------------*/
    133 
    134 Int32 sbr_crc_check(BIT_BUFFER * hBitBuf, UInt32 NrBits)
    135 {
    136     Int32 crcResult = 1;
    137     BIT_BUFFER BitBufferCRC;
    138     UInt32 NrCrcBits;
    139 
    140     UInt32 crcCheckSum;
    141 
    142     Int32 i;
    143     CRC_BUFFER CrcBuf;
    144     UInt32 bValue;
    145     Int32 CrcStep;
    146     Int32 CrcNrBitsRest;
    147 
    148     crcCheckSum = buf_getbits(hBitBuf, SI_SBR_CRC_BITS);
    149 
    150 
    151     /*
    152      *    Copy Bit buffer State
    153      */
    154 
    155     BitBufferCRC.char_ptr       = hBitBuf->char_ptr;
    156     BitBufferCRC.buffer_word    = hBitBuf->buffer_word;
    157     BitBufferCRC.buffered_bits  = hBitBuf->buffered_bits;
    158     BitBufferCRC.nrBitsRead     = hBitBuf->nrBitsRead;
    159     BitBufferCRC.bufferLen      = hBitBuf->bufferLen;
    160 
    161 
    162     NrCrcBits = min(NrBits, BitBufferCRC.bufferLen - BitBufferCRC.nrBitsRead);
    163 
    164 
    165     CrcStep = NrCrcBits / MAXCRCSTEP;
    166     CrcNrBitsRest = (NrCrcBits - CrcStep * MAXCRCSTEP);
    167 
    168     CrcBuf.crcState = CRCSTART;
    169     CrcBuf.crcMask  = CRCMASK;
    170     CrcBuf.crcPoly  = CRCPOLY;
    171 
    172     for (i = 0; i < CrcStep; i++)
    173     {
    174         bValue = buf_getbits(&BitBufferCRC, MAXCRCSTEP);
    175         check_crc(&CrcBuf, bValue, MAXCRCSTEP);
    176     }
    177 
    178     bValue = buf_getbits(&BitBufferCRC, CrcNrBitsRest);
    179     check_crc(&CrcBuf, bValue, CrcNrBitsRest);
    180 
    181     if ((UInt32)(CrcBuf.crcState & CRCRANGE) != crcCheckSum)
    182     {
    183         crcResult = 0;
    184     }
    185 
    186     return (crcResult);
    187 }
    188 
    189 #endif
    190 
    191 
    192