yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2005 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /***************************************************************************** |
| 37 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * bitstream.h |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * Maui_Software |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * BitStream allows sequential reading and writing of bit fields. |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | *============================================================================ |
| 55 | * HISTORY |
| 56 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 57 | *------------------------------------------------------------------------------ |
| 58 | * removed! |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * |
| 62 | * removed! |
| 63 | * removed! |
| 64 | * removed! |
| 65 | * |
| 66 | * removed! |
| 67 | * removed! |
| 68 | * removed! |
| 69 | * |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * removed! |
| 73 | * removed! |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * removed! |
| 77 | * removed! |
| 78 | * removed! |
| 79 | * removed! |
| 80 | *------------------------------------------------------------------------------ |
| 81 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 82 | *============================================================================ |
| 83 | ****************************************************************************/ |
| 84 | |
| 85 | /********************************************************************* |
| 86 | (C) _____ (year of first publication) Sasken communication |
| 87 | Technologies Limited, All rights reserved. |
| 88 | * This file provides a template for .c files. This space |
| 89 | * should be used to describe the file contents |
| 90 | * Component-specific prefix : xxxx |
| 91 | *********************************************************************/ |
| 92 | |
| 93 | #ifndef _BITSTREAM_H |
| 94 | #define _BITSTREAM_H |
| 95 | /*RHR*/ |
| 96 | #include "kal_general_types.h" |
| 97 | /*RHR*/ |
| 98 | /* BitStream |
| 99 | * |
| 100 | * A bit stream allows bit fields to be read and written to, |
| 101 | * just like an byte stream allows byte to be read and written |
| 102 | * to. Reading and writing of bit fields is done to an underlying |
| 103 | * byte stream, in network byte order. |
| 104 | * |
| 105 | * bit_stream_init sets the underlying byte stream and the |
| 106 | * current read/write position within the byte stream. Can also |
| 107 | * be called when a seek to a new position is desired. |
| 108 | |
| 109 | * The values which are read by bit_stream_read are returned as |
| 110 | * native unsigned integers. |
| 111 | * |
| 112 | * Similarly the values which are passed to bit_stream_write for |
| 113 | * writing should be passed as native unsigned integers. |
| 114 | * |
| 115 | * Both bit_stream_read and bit_stream_write, increment the |
| 116 | * current position,to facilitate sequential operation. |
| 117 | * bit_stream_cur_pos returns the number of bytes, the underlying |
| 118 | * byte pointer has been moved since bit_stream_init. |
| 119 | * |
| 120 | */ |
| 121 | |
| 122 | typedef struct bit_stream { |
| 123 | kal_uint8 *byte_stream; /* Pointer to underlying byte stream. */ |
| 124 | kal_uint8 *byte_stream_start; |
| 125 | kal_uint8 offset; /* Offset in bits from MSB of byte_stream */ |
| 126 | } bit_stream; |
| 127 | |
| 128 | /* Initialise Bit stream operations |
| 129 | * |
| 130 | * offset |
| 131 | * | |
| 132 | * V |
| 133 | * /-------------------------------\ |
| 134 | * byte_stream-->| | | | | | | | | |
| 135 | * |---|---|---|---|---|---|---|---| |
| 136 | * | | | | | | | | | |
| 137 | * |---|---|---|---|---|---|---|---| |
| 138 | * | | | | | | | | | |
| 139 | * |---|---|---|---|---|---|---|---| |
| 140 | * | . | . | . | . | . | . | . | . | |
| 141 | * . . . . . . . . |
| 142 | * . . . . . . . . |
| 143 | * |
| 144 | * If offset is more than eight then, byte_stream is incremented by |
| 145 | * offset/8 and offset is taken to be offset modulo 8. |
| 146 | */ |
| 147 | extern void bit_stream_init( |
| 148 | bit_stream *bs, |
| 149 | kal_uint8 *byte_stream, |
| 150 | unsigned int offset); |
| 151 | |
| 152 | /* Read specified number of bits from current position and return it as |
| 153 | * an unsigned integer. |
| 154 | * |
| 155 | * offset (before) |
| 156 | * | |
| 157 | * V |
| 158 | * /-------------------------------\ |
| 159 | * byte_stream (before)->| | | | | 1 | 0 | 0 | 0 | |
| 160 | * |---|---|---|---|---|---|---|---| |
| 161 | * byte_stream (after) ->| 1 | 0 | | | | | | | |
| 162 | * |---|---|---|---|---|---|---|---| |
| 163 | * | . | . | ^ | . | . | . | . | . | |
| 164 | * | |
| 165 | * offset (after) |
| 166 | * |
| 167 | * On the above stream bit_stream_read(bs, 6) will return 34 |
| 168 | */ |
| 169 | extern unsigned int bit_stream_read( |
| 170 | bit_stream *bs, |
| 171 | unsigned int width); |
| 172 | |
| 173 | |
| 174 | /* Write specified number of bits from current position into the |
| 175 | * underlying byte stream. |
| 176 | * |
| 177 | * bit_stream_write(bs, 6) |
| 178 | * |
| 179 | * offset (before) |
| 180 | * | |
| 181 | * V |
| 182 | * /-------------------------------\ |
| 183 | * byte_stream (before)->| | | | | 1 | 0 | 0 | 0 | |
| 184 | * |---|---|---|---|---|---|---|---| |
| 185 | * byte_stream (after) ->| 1 | 0 | | | | | | | |
| 186 | * |---|---|---|---|---|---|---|---| |
| 187 | * | . | . | ^ | . | . | . | . | . | |
| 188 | * | |
| 189 | * offset (after) |
| 190 | * |
| 191 | */ |
| 192 | extern void bit_stream_write( |
| 193 | bit_stream *bs, |
| 194 | unsigned int width, |
| 195 | unsigned int value ); |
| 196 | |
| 197 | /* Return the number of bits the internal pointer has moved since |
| 198 | * bit_stream_init */ |
| 199 | extern unsigned int bit_stream_cur_pos(bit_stream *bs); |
| 200 | |
| 201 | /* Move pointer back by given number of bits */ |
| 202 | extern void bit_stream_move_back( |
| 203 | bit_stream *bs, |
| 204 | unsigned int bits); |
| 205 | |
| 206 | /* Copy bits from one byte stream to another. |
| 207 | * Byte stream is incremented as read operation |
| 208 | * is done */ |
| 209 | |
| 210 | extern void byte_stream_bit_copy( |
| 211 | kal_uint8 *s, |
| 212 | unsigned int s_offset, |
| 213 | unsigned int length, |
| 214 | kal_uint8 *d, |
| 215 | unsigned int d_offset); |
| 216 | |
| 217 | |
| 218 | /* Read specified number of bits from the bitstream, starting |
| 219 | * from a position, width bits before the current position. |
| 220 | |
| 221 | * |
| 222 | * offset (after) |
| 223 | * | |
| 224 | * V |
| 225 | * /-------------------------------\ |
| 226 | * byte_stream (after)-> | | | | | 1 | 0 | 0 | 0 | |
| 227 | * |---|---|---|---|---|---|---|---| |
| 228 | * byte_stream (before)->| 1 | 0 | | | | | | | |
| 229 | * |---|---|---|---|---|---|---|---| |
| 230 | * | . | . | ^ | . | . | . | . | . | |
| 231 | * | |
| 232 | * offset (before) |
| 233 | * |
| 234 | * On the above stream , |
| 235 | * bit_stream_read_back(bs, 6) will return 34 |
| 236 | */ |
| 237 | |
| 238 | extern unsigned int bit_stream_read_back( |
| 239 | bit_stream *bs, |
| 240 | unsigned int width); |
| 241 | |
| 242 | |
| 243 | |
| 244 | /* Write specified number of bits to the bitstream starting |
| 245 | * from a position width bits before the current position. |
| 246 | * |
| 247 | * bit_stream_write_back(bs, 6, 34) will return |
| 248 | * |
| 249 | * |
| 250 | * offset (after) |
| 251 | * | |
| 252 | * V |
| 253 | * /-------------------------------\ |
| 254 | * byte_stream (after) ->| | | | | 1 | 0 | 0 | 0 | |
| 255 | * |---|---|---|---|---|---|---|---| |
| 256 | * byte_stream (before)->| 1 | 0 | | | | | | | |
| 257 | * |---|---|---|---|---|---|---|---| |
| 258 | * | . | . | ^ | . | . | . | . | . | |
| 259 | * | |
| 260 | * offset (before) |
| 261 | * |
| 262 | */ |
| 263 | extern void bit_stream_write_back( |
| 264 | bit_stream *bs, |
| 265 | unsigned int width, |
| 266 | unsigned int value ); |
| 267 | #endif /* _BITSTREAM_H */ |
| 268 | |