Lines Matching refs:rbsp

17 #include "nal-rbsp.h"
19 void rbsp_init(struct rbsp *rbsp, void *addr, size_t size,
22 if (!rbsp)
25 rbsp->data = addr;
26 rbsp->size = size;
27 rbsp->pos = 0;
28 rbsp->ops = ops;
29 rbsp->error = 0;
32 void rbsp_unsupported(struct rbsp *rbsp)
34 rbsp->error = -EINVAL;
37 static int rbsp_read_bits(struct rbsp *rbsp, int n, unsigned int *value);
38 static int rbsp_write_bits(struct rbsp *rbsp, int n, unsigned int value);
48 static int add_emulation_prevention_three_byte(struct rbsp *rbsp)
50 rbsp->num_consecutive_zeros = 0;
51 rbsp_write_bits(rbsp, 8, EMULATION_PREVENTION_THREE_BYTE);
56 static int discard_emulation_prevention_three_byte(struct rbsp *rbsp)
60 rbsp->num_consecutive_zeros = 0;
61 rbsp_read_bits(rbsp, 8, &tmp);
68 static inline int rbsp_read_bit(struct rbsp *rbsp)
75 if (rbsp->num_consecutive_zeros == 22) {
76 err = discard_emulation_prevention_three_byte(rbsp);
81 shift = 7 - (rbsp->pos % 8);
82 ofs = rbsp->pos / 8;
83 if (ofs >= rbsp->size)
86 bit = (rbsp->data[ofs] >> shift) & 1;
88 rbsp->pos++;
91 (rbsp->num_consecutive_zeros < 7 && (rbsp->pos % 8 == 0)))
92 rbsp->num_consecutive_zeros = 0;
94 rbsp->num_consecutive_zeros++;
99 static inline int rbsp_write_bit(struct rbsp *rbsp, bool value)
104 if (rbsp->num_consecutive_zeros == 22)
105 add_emulation_prevention_three_byte(rbsp);
107 shift = 7 - (rbsp->pos % 8);
108 ofs = rbsp->pos / 8;
109 if (ofs >= rbsp->size)
112 rbsp->data[ofs] &= ~(1 << shift);
113 rbsp->data[ofs] |= value << shift;
115 rbsp->pos++;
118 (rbsp->num_consecutive_zeros < 7 && (rbsp->pos % 8 == 0))) {
119 rbsp->num_consecutive_zeros = 0;
121 rbsp->num_consecutive_zeros++;
127 static inline int rbsp_read_bits(struct rbsp *rbsp, int n, unsigned int *value)
137 bit = rbsp_read_bit(rbsp);
149 static int rbsp_write_bits(struct rbsp *rbsp, int n, unsigned int value)
157 ret = rbsp_write_bit(rbsp, (value >> n) & 1);
165 static int rbsp_read_uev(struct rbsp *rbsp, unsigned int *value)
171 while ((ret = rbsp_read_bit(rbsp)) == 0)
177 ret = rbsp_read_bits(rbsp, leading_zero_bits, &tmp);
188 static int rbsp_write_uev(struct rbsp *rbsp, unsigned int *value)
198 ret = rbsp_write_bits(rbsp, leading_zero_bits, 0);
202 return rbsp_write_bits(rbsp, leading_zero_bits + 1, *value + 1);
205 static int rbsp_read_sev(struct rbsp *rbsp, int *value)
210 ret = rbsp_read_uev(rbsp, &tmp);
224 static int rbsp_write_sev(struct rbsp *rbsp, int *value)
236 return rbsp_write_uev(rbsp, &tmp);
239 static int __rbsp_write_bit(struct rbsp *rbsp, int *value)
241 return rbsp_write_bit(rbsp, *value);
244 static int __rbsp_write_bits(struct rbsp *rbsp, int n, unsigned int *value)
246 return rbsp_write_bits(rbsp, n, *value);
256 static int __rbsp_read_bit(struct rbsp *rbsp, int *value)
258 int tmp = rbsp_read_bit(rbsp);
274 void rbsp_bit(struct rbsp *rbsp, int *value)
276 if (rbsp->error)
278 rbsp->error = rbsp->ops->rbsp_bit(rbsp, value);
281 void rbsp_bits(struct rbsp *rbsp, int n, int *value)
283 if (rbsp->error)
285 rbsp->error = rbsp->ops->rbsp_bits(rbsp, n, value);
288 void rbsp_uev(struct rbsp *rbsp, unsigned int *value)
290 if (rbsp->error)
292 rbsp->error = rbsp->ops->rbsp_uev(rbsp, value);
295 void rbsp_sev(struct rbsp *rbsp, int *value)
297 if (rbsp->error)
299 rbsp->error = rbsp->ops->rbsp_sev(rbsp, value);
302 void rbsp_trailing_bits(struct rbsp *rbsp)
307 rbsp_bit(rbsp, &rbsp_stop_one_bit);
308 rbsp_bits(rbsp, round_up(rbsp->pos, 8) - rbsp->pos,