| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2005-2010, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bvlc.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/2 $ |
|---|
| 12 | * $brcm_Date: 9/23/10 3:09p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: Converts startcode index to bcmplayer index |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/commonutils/vlc/bvlc.h $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/2 9/23/10 3:09p jtna |
|---|
| 21 | * SW7405-4865: cleaned up header and added an example |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/1 9/20/10 3:03p jtna |
|---|
| 24 | * SW7405-4865: added vlc |
|---|
| 25 | * |
|---|
| 26 | * $old_brcm_Workfile: bvlc.h $ |
|---|
| 27 | * $old_brcm_Revision: 4 $ |
|---|
| 28 | * $old_brcm_Date: 9/1/05 3:36p $ |
|---|
| 29 | * |
|---|
| 30 | * $old_brcm_Log: /BSEAV/lib/utils/bvlc.h $ |
|---|
| 31 | * |
|---|
| 32 | * 4 9/1/05 3:36p erickson |
|---|
| 33 | * PR16964: added const to parameter |
|---|
| 34 | * |
|---|
| 35 | * 3 7/8/05 10:05a erickson |
|---|
| 36 | * PR16155: modified b_vlc_decode to require current_index instead of |
|---|
| 37 | * always starting from data[0]. This makes keeping track of where you |
|---|
| 38 | * are in the buffer much easier for the application. Also changed and |
|---|
| 39 | * expanded the examples. |
|---|
| 40 | * |
|---|
| 41 | * 2 4/6/05 5:17p erickson |
|---|
| 42 | * PR14708: use bstd.h if at all possible for maximum portability |
|---|
| 43 | * |
|---|
| 44 | * 1 3/21/05 3:43p erickson |
|---|
| 45 | * PR14451: added generic vlc decode algorithm |
|---|
| 46 | * |
|---|
| 47 | ************************************************************/ |
|---|
| 48 | #ifndef BVLC_H__ |
|---|
| 49 | #define BVLC_H__ |
|---|
| 50 | |
|---|
| 51 | #include "bstd.h" |
|---|
| 52 | |
|---|
| 53 | #ifdef __cplusplus |
|---|
| 54 | extern "C" { |
|---|
| 55 | #endif |
|---|
| 56 | |
|---|
| 57 | /* for backward compatibility */ |
|---|
| 58 | #define b_vlc_decode BVLC_Decode |
|---|
| 59 | #define b_vlc_skip BVLC_Skip |
|---|
| 60 | |
|---|
| 61 | /*************************************************************************** |
|---|
| 62 | BVLC is a set of Broadcom VLC (Variable Length Coding) decode algorithms. |
|---|
| 63 | |
|---|
| 64 | Examples: |
|---|
| 65 | unsigned char data[size]; |
|---|
| 66 | int next_index, next_bit; |
|---|
| 67 | |
|---|
| 68 | // Decode 3 contiguous vlc values |
|---|
| 69 | val1 = BVLC_Decode(data, size, 0, 7, &next_index, &next_bit); |
|---|
| 70 | val2 = BVLC_Decode(data, size, next_index, next_bit, &next_index, &next_bit); |
|---|
| 71 | val3 = BVLC_Decode(data, size, next_index, next_bit, NULL, NULL); |
|---|
| 72 | |
|---|
| 73 | // Decode the 4th vlc value |
|---|
| 74 | BVLC_Skip(data, size, 0, 7, &next_index, &next_bit); |
|---|
| 75 | BVLC_Skip(data, size, next_index, next_bit, &next_index, &next_bit); |
|---|
| 76 | BVLC_Skip(data, size, next_index, next_bit, &next_index, &next_bit); |
|---|
| 77 | val = BVLC_Decode(data, size, next_index, next_bit, NULL, NULL); |
|---|
| 78 | |
|---|
| 79 | // Decode a vlc value which is an index of the subsequent vlc value to decode. |
|---|
| 80 | val = BVLC_Decode(data, size, 0, 7, &next_index, &next_bit); |
|---|
| 81 | while (val--) |
|---|
| 82 | BVLC_Skip(data, size, next_index, next_bit, &next_index, &next_bit); |
|---|
| 83 | val = BVLC_Decode(data, size, next_index, next_bit, NULL, NULL); |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | Examples: |
|---|
| 87 | // Decode a vlc value and calculate the number of bits the processed |
|---|
| 88 | // by the last BVLC_Decode or BVLC_Skip call. |
|---|
| 89 | |
|---|
| 90 | int current_index, current_bit, num_bits; |
|---|
| 91 | |
|---|
| 92 | // save next_index and next_bit before BVLC_Decode |
|---|
| 93 | current_index = next_index; |
|---|
| 94 | current_bit = next_bit; |
|---|
| 95 | |
|---|
| 96 | BVLC_Decode(data, size, next_index, next_bit, &next_index, &next_bit); |
|---|
| 97 | |
|---|
| 98 | num_bits = (next_index-current_index)*8 + (current_bit-next_bit); |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | ***************************************************************************/ |
|---|
| 102 | |
|---|
| 103 | /*************************************************************************** |
|---|
| 104 | Summary: |
|---|
| 105 | Decodes a VLC value in a byte stream. |
|---|
| 106 | |
|---|
| 107 | Description: |
|---|
| 108 | |
|---|
| 109 | Input: |
|---|
| 110 | data - [size_is(size)] Array of bytes which contain a vlc |
|---|
| 111 | encoded value |
|---|
| 112 | size - Size of data. |
|---|
| 113 | current_index - The starting index the data array. |
|---|
| 114 | current_bit - The bit in data[current_index] where the vlc decode |
|---|
| 115 | should start. |
|---|
| 116 | next_index - [out] the index in data which should be used for an |
|---|
| 117 | adjacent vlc decode. Can be NULL. |
|---|
| 118 | next_bit - [out] the bit in data[index] which should be used for |
|---|
| 119 | an adjacent vlc decode. Can be NULL. |
|---|
| 120 | |
|---|
| 121 | Returns: |
|---|
| 122 | Returns a VLC decoded value if >= 0. |
|---|
| 123 | If -1 there was a VLC decode failure. |
|---|
| 124 | |
|---|
| 125 | See Also: |
|---|
| 126 | |
|---|
| 127 | ***************************************************************************/ |
|---|
| 128 | |
|---|
| 129 | int BVLC_Decode( |
|---|
| 130 | const uint8_t *data, |
|---|
| 131 | unsigned size, |
|---|
| 132 | unsigned current_index, |
|---|
| 133 | unsigned current_bit, |
|---|
| 134 | unsigned *next_index, |
|---|
| 135 | unsigned *next_bit |
|---|
| 136 | ); |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | /*************************************************************************** |
|---|
| 140 | Summary: |
|---|
| 141 | This works by short circuiting the VLC decode algorithm in order to skip |
|---|
| 142 | over a VLC encoded value. |
|---|
| 143 | |
|---|
| 144 | Description: |
|---|
| 145 | |
|---|
| 146 | Input: |
|---|
| 147 | data - [size_is(size)] see BVLC_Decode |
|---|
| 148 | size - see BVLC_Decode |
|---|
| 149 | current_index - see BVLC_Decode |
|---|
| 150 | current_bit - see BVLC_Decode |
|---|
| 151 | next_index - [out] the index in data which should be used for an |
|---|
| 152 | adjacent vlc decode. Required. |
|---|
| 153 | next_bit - [out] the bit in data[index] which should be used for |
|---|
| 154 | an adjacent vlc decode. Required. |
|---|
| 155 | |
|---|
| 156 | Returns: |
|---|
| 157 | 0 if successfully skipped. next_index and next_bit are updated. |
|---|
| 158 | If -1 there was a VLC decode failure. |
|---|
| 159 | |
|---|
| 160 | See Also: |
|---|
| 161 | BVLC_Decode |
|---|
| 162 | ***************************************************************************/ |
|---|
| 163 | int BVLC_Skip( |
|---|
| 164 | const uint8_t *data, |
|---|
| 165 | unsigned size, |
|---|
| 166 | unsigned current_index, |
|---|
| 167 | unsigned current_bit, |
|---|
| 168 | unsigned *next_index, |
|---|
| 169 | unsigned *next_bit |
|---|
| 170 | ); |
|---|
| 171 | |
|---|
| 172 | #ifdef __cplusplus |
|---|
| 173 | } |
|---|
| 174 | #endif |
|---|
| 175 | |
|---|
| 176 | #endif /* #ifndef BVLC_H__ */ |
|---|
| 177 | /* End of File */ |
|---|
| 178 | |
|---|