| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2005, 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: 4 $ |
|---|
| 12 | * $brcm_Date: 9/1/05 3:36p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: Converts startcode index to bcmplayer index |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /BSEAV/lib/utils/bvlc.h $ |
|---|
| 19 | * |
|---|
| 20 | * 4 9/1/05 3:36p erickson |
|---|
| 21 | * PR16964: added const to parameter |
|---|
| 22 | * |
|---|
| 23 | * 3 7/8/05 10:05a erickson |
|---|
| 24 | * PR16155: modified b_vlc_decode to require current_index instead of |
|---|
| 25 | * always starting from data[0]. This makes keeping track of where you |
|---|
| 26 | * are in the buffer much easier for the application. Also changed and |
|---|
| 27 | * expanded the examples. |
|---|
| 28 | * |
|---|
| 29 | * 2 4/6/05 5:17p erickson |
|---|
| 30 | * PR14708: use bstd.h if at all possible for maximum portability |
|---|
| 31 | * |
|---|
| 32 | * 1 3/21/05 3:43p erickson |
|---|
| 33 | * PR14451: added generic vlc decode algorithm |
|---|
| 34 | * |
|---|
| 35 | ************************************************************/ |
|---|
| 36 | #ifndef BVLC_H__ |
|---|
| 37 | #define BVLC_H__ |
|---|
| 38 | |
|---|
| 39 | #ifndef USE_LEGACY_KERNAL_INTERFACE |
|---|
| 40 | #include "bstd.h" |
|---|
| 41 | #else |
|---|
| 42 | #include <stdint.h> |
|---|
| 43 | #endif |
|---|
| 44 | |
|---|
| 45 | /*=************************************* |
|---|
| 46 | bvlc is a set of Broadcom VLC decode algorithms. |
|---|
| 47 | |
|---|
| 48 | Examples: |
|---|
| 49 | unsigned char data[size]; |
|---|
| 50 | int next_index, next_bit; |
|---|
| 51 | |
|---|
| 52 | // Decode 3 contiguous vlc values |
|---|
| 53 | val1 = b_vlc_decode(data, size, 0, 7, &next_index, &next_bit); |
|---|
| 54 | val2 = b_vlc_decode(data, size, next_index, next_bit, &next_index, &next_bit |
|---|
| 55 | val3 = b_vlc_decode(data, size, next_index, next_bit, NULL, NULL); |
|---|
| 56 | |
|---|
| 57 | // Decode the 4th vlc value |
|---|
| 58 | b_vlc_skip(data, size, 0, 7, &next_index, &next_bit); |
|---|
| 59 | b_vlc_skip(data, size, next_index, next_bit, &next_index, &next_bit); |
|---|
| 60 | b_vlc_skip(data, size, next_index, next_bit, &next_index, &next_bit); |
|---|
| 61 | val = b_vlc_decode(data, size, next_index, next_bit, NULL, NULL); |
|---|
| 62 | |
|---|
| 63 | // Decode a vlc value which is an index of the subsequent VLC value to decode. |
|---|
| 64 | val = b_vlc_decode(data, size, 0, 7, &next_index, &next_bit); |
|---|
| 65 | while (val--) |
|---|
| 66 | b_vlc_skip(data, size, next_index, next_bit, &next_index, &next_bit); |
|---|
| 67 | val = b_vlc_decode(data, size, next_index, next_bit, NULL, NULL); |
|---|
| 68 | ********************************************/ |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | Summary: |
|---|
| 72 | Decodes a VLC value in a byte stream. |
|---|
| 73 | |
|---|
| 74 | Description: |
|---|
| 75 | |
|---|
| 76 | Return Value: |
|---|
| 77 | Returns a VLC decoded value if >= 0. |
|---|
| 78 | If -1 there was a VLC decode failure. |
|---|
| 79 | **/ |
|---|
| 80 | int b_vlc_decode( |
|---|
| 81 | const uint8_t *data, /* [size_is(size)] Array of bytes which contain a vlc encoded value */ |
|---|
| 82 | unsigned size, /* Size of data */ |
|---|
| 83 | unsigned current_index, /* The starting index the data array. */ |
|---|
| 84 | unsigned current_bit, /* The bit in data[current_index] where the vlc decode should start. |
|---|
| 85 | vlc decode proceeds from MSB to LSB, so the first |
|---|
| 86 | bit will be 7. */ |
|---|
| 87 | unsigned *next_index, /* [out] the index in data which should be used for an |
|---|
| 88 | adjacent vlc decode. Can be NULL. */ |
|---|
| 89 | unsigned *next_bit /* [out] the bit in data[index] which should be used for an |
|---|
| 90 | adjacent vlc decode. Can be NULL. */ |
|---|
| 91 | ); |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | This works by short circuiting the VLC decode algorithm in order to skip |
|---|
| 96 | over a VLC encoded value. |
|---|
| 97 | |
|---|
| 98 | Return Value: |
|---|
| 99 | 0 if successfully skipped. next_index and next_bit are updated. |
|---|
| 100 | If -1 there was a VLC decode failure. |
|---|
| 101 | **/ |
|---|
| 102 | int b_vlc_skip( |
|---|
| 103 | const uint8_t *data, /* [size_is(size)] see b_vlc_decode */ |
|---|
| 104 | unsigned size, /* see b_vlc_decode */ |
|---|
| 105 | unsigned current_index, /* see b_vlc_decode */ |
|---|
| 106 | unsigned current_bit, /* see b_vlc_decode */ |
|---|
| 107 | unsigned *next_index, /* [out] the index in data which should be used for an |
|---|
| 108 | adjacent vlc decode. Required. */ |
|---|
| 109 | unsigned *next_bit /* [out] the bit in data[index] which should be used for an |
|---|
| 110 | adjacent vlc decode. Required. */ |
|---|
| 111 | ); |
|---|
| 112 | |
|---|
| 113 | #endif |
|---|
| 114 | |
|---|