Skip to content

Commit

Permalink
Backport faster T.35 payload copy from dav1d 1.2.1 (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen authored Apr 24, 2024
2 parents 8768cf7 + 7161609 commit da22e8c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/getbits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
7 changes: 5 additions & 2 deletions src/obu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/obu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit da22e8c

Please sign in to comment.