Showing the changes to codec/decoder/core/src/bit_stream.cpp (1 of 308 files). Show all
Unified · Split
| @@ -0,0 +1,123 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2009-2013, Cisco Systems | |
| 4 | + * All rights reserved. | |
| 5 | + * | |
| 6 | + * Redistribution and use in source and binary forms, with or without | |
| 7 | + * modification, are permitted provided that the following conditions | |
| 8 | + * are met: | |
| 9 | + * | |
| 10 | + * * Redistributions of source code must retain the above copyright | |
| 11 | + * notice, this list of conditions and the following disclaimer. | |
| 12 | + * | |
| 13 | + * * Redistributions in binary form must reproduce the above copyright | |
| 14 | + * notice, this list of conditions and the following disclaimer in | |
| 15 | + * the documentation and/or other materials provided with the | |
| 16 | + * distribution. | |
| 17 | + * | |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | + * | |
| 31 | + * | |
| 32 | + * \file bit_stream.cpp | |
| 33 | + * | |
| 34 | + * \brief Reading / writing bit-stream | |
| 35 | + * | |
| 36 | + * \date 03/10/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | +#include "bit_stream.h" | |
| 41 | +#include "macros.h" | |
| 42 | + | |
| 43 | +namespace WelsDec { | |
| 44 | + | |
| 45 | +#ifdef WORDS_BIGENDIAN | |
| 46 | +inline uint32_t EndianFix(uint32_t uiX) | |
| 47 | +{ | |
| 48 | + return uiX; | |
| 49 | +} | |
| 50 | +#else //WORDS_BIGENDIAN | |
| 51 | + | |
| 52 | +#ifdef _MSC_VER | |
| 53 | +inline uint32_t EndianFix(uint32_t uiX) | |
| 54 | +{ | |
| 55 | + __asm | |
| 56 | + { | |
| 57 | + mov eax, uiX | |
| 58 | + bswap eax | |
| 59 | + mov uiX, eax | |
| 60 | + } | |
| 61 | + return uiX; | |
| 62 | +} | |
| 63 | +#else //_MSC_VER | |
| 64 | + | |
| 65 | +inline uint32_t EndianFix(uint32_t uiX) | |
| 66 | +{ | |
| 67 | +#ifdef ARM_ARCHv7 | |
| 68 | + __asm__ __volatile__("rev %0, %0":"+r"(uiX)); //Just for the ARMv7 | |
| 69 | +#elif defined (X86_ARCH) | |
| 70 | + __asm__ __volatile__("bswap %0":"+r"(uiX)); | |
| 71 | +#else | |
| 72 | + uiX = ((uiX & 0xff000000)>> 24) | ((uiX & 0xff0000) >> 8) | | |
| 73 | + ((uiX & 0xff00) << 8) | ((uiX&0xff) << 24); | |
| 74 | +#endif | |
| 75 | + return uiX; | |
| 76 | +} | |
| 77 | +#endif //_MSC_VER | |
| 78 | + | |
| 79 | +#endif //WORDS_BIGENDIAN | |
| 80 | + | |
| 81 | +inline uint32_t GetValue4Bytes( uint8_t* pDstNal ) | |
| 82 | +{ | |
| 83 | + uint32_t uiValue = 0; | |
| 84 | + uiValue = (pDstNal[0]<<24) | (pDstNal[1]<<16) | (pDstNal[2]<<8) | (pDstNal[3]); | |
| 85 | + return uiValue; | |
| 86 | +} | |
| 87 | + | |
| 88 | +void_t InitReadBits( PBitStringAux pBitString ) | |
| 89 | +{ | |
| 90 | + pBitString->uiCurBits = GetValue4Bytes( pBitString->pCurBuf ); | |
| 91 | + pBitString->pCurBuf += 4; | |
| 92 | + pBitString->iLeftBits = -16; | |
| 93 | +} | |
| 94 | + | |
| 95 | +/*! | |
| 96 | + * \brief input bits for decoder or initialize bitstream writing in encoder | |
| 97 | + * | |
| 98 | + * \param pBitString Bit string auxiliary pointer | |
| 99 | + * \param kpBuf bit-stream buffer | |
| 100 | + * \param kiSize size in bits for decoder; size in bytes for encoder | |
| 101 | + * | |
| 102 | + * \return size of buffer data in byte; failed in -1 return | |
| 103 | + */ | |
| 104 | +int32_t InitBits( PBitStringAux pBitString, const uint8_t *kpBuf, const int32_t kiSize ) | |
| 105 | +{ | |
| 106 | + const int32_t kiSizeBuf = (kiSize + 7) >> 3; | |
| 107 | + uint8_t *pTmp = (uint8_t *)kpBuf; | |
| 108 | + | |
| 109 | + if ( NULL == pTmp ) | |
| 110 | + return -1; | |
| 111 | + | |
| 112 | + pBitString->pStartBuf = pTmp; // buffer to start position | |
| 113 | + pBitString->pEndBuf = pTmp + kiSizeBuf; // buffer + length | |
| 114 | + pBitString->iBits = kiSize; // count bits of overall bitstreaming inputindex; | |
| 115 | + | |
| 116 | + pBitString->pCurBuf = pBitString->pStartBuf; | |
| 117 | + InitReadBits( pBitString ); | |
| 118 | + | |
| 119 | + return kiSizeBuf; | |
| 120 | +} | |
| 121 | + | |
| 122 | +} // namespace WelsDec | |
| 123 | + | |