* Initialize GetBitContext. * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes * larger than the actual read bits because some optimized bitstream * readers read 32 or 64 bit at once and could read over the end * @param bit_size the size of the buffer in bits * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow. */
| 515 | * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow. |
| 516 | */ |
| 517 | static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer, |
| 518 | int bit_size) |
| 519 | { |
| 520 | int ret = 0; |
| 521 | |
| 522 | if (bit_size >= INT_MAX - FFMAX(7, AV_INPUT_BUFFER_PADDING_SIZE*8) || bit_size < 0 || !buffer) { |
| 523 | bit_size = 0; |
| 524 | buffer = NULL; |
| 525 | ret = AVERROR_INVALIDDATA; |
| 526 | } |
| 527 | |
| 528 | s->buffer = buffer; |
| 529 | s->size_in_bits = bit_size; |
| 530 | s->size_in_bits_plus8 = bit_size + 8; |
| 531 | s->index = 0; |
| 532 | |
| 533 | return ret; |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Initialize GetBitContext. |
no outgoing calls