1 #ifndef VIDDEC_PM_UTILS_BSTREAM_H
2 #define VIDDEC_PM_UTILS_BSTREAM_H
3
4 #include "viddec_pm_utils_list.h"
5
6 #define CUBBY_SIZE 1024
7 //#define CUBBY_SIZE 512
8 #define SCRATCH_SIZE 20
9 #define MIN_DATA 8
10
11 typedef struct
12 {
13 #ifdef VBP
14 uint8_t *buf;
15 #else
16 uint8_t buf[CUBBY_SIZE + 8 + MIN_DATA];/* extra 8 bytes for alignmet, extra 8 bytes for old data */
17 #endif
18 uint32_t buf_st; /* start pos in buf */
19 uint32_t buf_end; /* first invalid byte in buf */
20 uint32_t buf_index; /* current index in buf */
21 uint32_t buf_bitoff; /* bit offset in current index position */
22 }viddec_pm_utils_bstream_buf_cxt_t;
23
24 typedef struct
25 {
26 uint8_t buf_scratch[SCRATCH_SIZE];/* scratch for boundary reads*/
27 uint32_t st; /* start index of valid byte */
28 uint32_t size;/* Total number of bytes in current buffer */
29 uint32_t bitoff; /* bit offset in first valid byte */
30 }viddec_pm_utils_bstream_scratch_cxt_t;
31
32 typedef struct
33 {
34 #ifdef VBP
35 /* counter of emulation preventation byte */
36 uint32_t emulation_byte_counter;
37 #endif
38 /* After First pass of scan we figure out how many bytes are in the current access unit(N bytes). We store
39 the bstream buffer's first valid byte index wrt to accessunit in this variable */
40 uint32_t au_pos;
41 /* This is for keeping track of which list item was used to load data last */
42 uint32_t list_off;
43 /* This is for tracking emulation prevention bytes */
44 uint32_t phase;
45 /* This flag tells us whether to look for emulation prevention or not */
46 uint32_t is_emul_reqd;
47 /* A pointer to list of es buffers which contribute to current access unit */
48 viddec_pm_utils_list_t *list;
49 /* scratch buffer to stage data on boundaries and reloads */
50 viddec_pm_utils_bstream_scratch_cxt_t scratch;
51 /* Actual context which has valid data for get bits functionality */
52 viddec_pm_utils_bstream_buf_cxt_t bstrm_buf;
53 }viddec_pm_utils_bstream_cxt_t;
54
55 void viddec_pm_utils_bstream_init(viddec_pm_utils_bstream_cxt_t *cxt, viddec_pm_utils_list_t *list, uint32_t is_emul);
56
57 int32_t viddec_pm_utils_bstream_skipbits(viddec_pm_utils_bstream_cxt_t *cxt, uint32_t num_bits);
58
59 int32_t viddec_pm_utils_bstream_peekbits(viddec_pm_utils_bstream_cxt_t *cxt, uint32_t *out, uint32_t num_bits, uint8_t skip);
60
61 int32_t viddec_pm_utils_bstream_get_current_byte(viddec_pm_utils_bstream_cxt_t *cxt, uint8_t *byte);
62
63 uint8_t viddec_pm_utils_bstream_nomoredata(viddec_pm_utils_bstream_cxt_t *cxt);
64
65 uint8_t viddec_pm_utils_bstream_nomorerbspdata(viddec_pm_utils_bstream_cxt_t *cxt);
66
viddec_pm_utils_bstream_get_au_offsets(viddec_pm_utils_bstream_cxt_t * cxt,uint32_t * bit,uint32_t * byte,uint8_t * is_emul)67 static inline void viddec_pm_utils_bstream_get_au_offsets(viddec_pm_utils_bstream_cxt_t *cxt, uint32_t *bit, uint32_t *byte, uint8_t *is_emul)
68 {
69 uint32_t phase=cxt->phase;
70
71 *bit = cxt->bstrm_buf.buf_bitoff;
72 *byte = cxt->au_pos + (cxt->bstrm_buf.buf_index - cxt->bstrm_buf.buf_st);
73 if(cxt->phase > 0)
74 {
75 phase = phase - ((cxt->bstrm_buf.buf_bitoff != 0)? 1: 0 );
76 }
77 *is_emul = (cxt->is_emul_reqd) && (phase > 0) &&
78 (cxt->bstrm_buf.buf[cxt->bstrm_buf.buf_index] == 0) &&
79 (cxt->bstrm_buf.buf[cxt->bstrm_buf.buf_index+1] == 0x3);
80 }
81 #endif
82