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