diff options
Diffstat (limited to 'src/input/libdvdnav/nav_read.c')
-rw-r--r-- | src/input/libdvdnav/nav_read.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/input/libdvdnav/nav_read.c b/src/input/libdvdnav/nav_read.c index eb5f3ae07..e4114034a 100644 --- a/src/input/libdvdnav/nav_read.c +++ b/src/input/libdvdnav/nav_read.c @@ -69,6 +69,11 @@ static uint32_t getbits(getbits_state_t *state, uint32_t number_of_bits) { byte = byte >> (8 - number_of_bits); result = byte; state->bit_position += number_of_bits; /* Here it is impossible for bit_position > 8 */ + if (state->bit_position == 8) { + state->bit_position = 0; + state->byte_position++; + state->byte = state->start[state->byte_position]; + } number_of_bits = 0; } } @@ -91,8 +96,32 @@ static uint32_t getbits(getbits_state_t *state, uint32_t number_of_bits) { return result; } +/* WARNING: This function can only be used on a byte boundary. + No checks are made that we are in fact on a byte boundary. + */ +static uint16_t get16bits(getbits_state_t *state) { + uint16_t result; + state->byte_position++; + result = (state->byte << 8) + state->start[state->byte_position++]; + state->byte = state->start[state->byte_position]; + return result; +} + +/* WARNING: This function can only be used on a byte boundary. + No checks are made that we are in fact on a byte boundary. + */ +static uint32_t get32bits(getbits_state_t *state) { + uint32_t result; + state->byte_position++; + result = (state->byte << 8) + state->start[state->byte_position++]; + result = (result << 8) + state->start[state->byte_position++]; + result = (result << 8) + state->start[state->byte_position++]; + state->byte = state->start[state->byte_position]; + return result; +} + void navRead_PCI(pci_t *pci, unsigned char *buffer) { - int32_t result, i, j; + int32_t i, j; getbits_state_t state; if (getbits_init(&state, buffer)) assert(0); /* Passed NULL pointers */ |