bitstream-decode.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2014 The Android Open Source Project
  4. * Copyright 2003 - 2004 Open Interface North America, Inc. All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at:
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. ******************************************************************************/
  19. /**********************************************************************************
  20. $Revision: #1 $
  21. ***********************************************************************************/
  22. /**
  23. @file
  24. Functions for manipulating input bitstreams.
  25. @ingroup codec_internal
  26. */
  27. /**
  28. @addtogroup codec_internal
  29. @{
  30. */
  31. #include "common/bt_target.h"
  32. #include "oi_stddefs.h"
  33. #include "oi_bitstream.h"
  34. #include "oi_assert.h"
  35. #if (defined(SBC_DEC_INCLUDED) && SBC_DEC_INCLUDED == TRUE)
  36. PRIVATE void OI_BITSTREAM_ReadInit(OI_BITSTREAM *bs,
  37. const OI_BYTE *buffer)
  38. {
  39. bs->value = ((OI_INT32)buffer[0] << 16) | ((OI_INT32)buffer[1] << 8) | (buffer[2]);
  40. bs->ptr.r = buffer + 3;
  41. bs->bitPtr = 8;
  42. }
  43. PRIVATE OI_UINT32 OI_BITSTREAM_ReadUINT(OI_BITSTREAM *bs, OI_UINT bits)
  44. {
  45. OI_UINT32 result;
  46. OI_BITSTREAM_READUINT(result, bits, bs->ptr.r, bs->value, bs->bitPtr);
  47. return result;
  48. }
  49. PRIVATE OI_UINT8 OI_BITSTREAM_ReadUINT4Aligned(OI_BITSTREAM *bs)
  50. {
  51. OI_UINT32 result;
  52. OI_ASSERT(bs->bitPtr < 16);
  53. OI_ASSERT(bs->bitPtr % 4 == 0);
  54. if (bs->bitPtr == 8) {
  55. result = bs->value << 8;
  56. bs->bitPtr = 12;
  57. } else {
  58. result = bs->value << 12;
  59. bs->value = (bs->value << 8) | *bs->ptr.r++;
  60. bs->bitPtr = 8;
  61. }
  62. result >>= 28;
  63. OI_ASSERT(result < (1u << 4));
  64. return (OI_UINT8)result;
  65. }
  66. PRIVATE OI_UINT8 OI_BITSTREAM_ReadUINT8Aligned(OI_BITSTREAM *bs)
  67. {
  68. OI_UINT32 result;
  69. OI_ASSERT(bs->bitPtr == 8);
  70. result = bs->value >> 16;
  71. bs->value = (bs->value << 8) | *bs->ptr.r++;
  72. return (OI_UINT8)result;
  73. }
  74. /**
  75. @}
  76. */
  77. #endif /* #if (defined(SBC_DEC_INCLUDED) && SBC_DEC_INCLUDED == TRUE) */