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