diff --git a/src/getbits.rs b/src/getbits.rs index 408aab7ca..6bfdb2a2f 100644 --- a/src/getbits.rs +++ b/src/getbits.rs @@ -197,4 +197,11 @@ impl<'a> GetBits<'a> { pub const fn has_pending_bits(&self) -> bool { self.state != 0 || self.bits_left != 0 } + + pub fn get_bytes(&mut self, n: usize) -> &[u8] { + assert_eq!(self.bits_left, 0); + let i = self.index; + self.index += n; + &self.data[i..][..n] + } } diff --git a/src/obu.c b/src/obu.c index cbb500303..44aa9e8ba 100644 --- a/src/obu.c +++ b/src/obu.c @@ -1597,10 +1597,13 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in) { itut_t35_metadata->country_code = country_code; itut_t35_metadata->country_code_extension_byte = country_code_extension_byte; - for (int i = 0; i < payload_size; i++) - itut_t35_metadata->payload[i] = dav1d_get_bits(&gb, 8); itut_t35_metadata->payload_size = payload_size; + // We know that we've read a whole number of bytes and that the + // payload is within the OBU boundaries, so just use memcpy() + assert(gb.bits_left == 0); + memcpy(itut_t35_metadata->payload, gb.ptr, payload_size); + c->n_itut_t35++; break; } diff --git a/src/obu.rs b/src/obu.rs index 3516ee7bc..98621e6c8 100644 --- a/src/obu.rs +++ b/src/obu.rs @@ -2460,7 +2460,7 @@ unsafe fn parse_obus( } else { let country_code = country_code as u8; let country_code_extension_byte = country_code_extension_byte as u8; - let payload = (0..payload_size).map(|_| gb.get_bits(8) as u8).collect(); // TODO(kkysen) fallible allocation + let payload = gb.get_bytes(payload_size as usize).into(); // TODO fallible allocation let itut_t35 = Rav1dITUTT35 { country_code, country_code_extension_byte,