@@ -418,6 +418,7 @@ pub struct FrameState<T: Pixel> {
418418 pub rec : Frame < T > ,
419419 pub cdfs : CDFContext ,
420420 pub context_update_tile_id : usize , // tile id used for the CDFontext
421+ pub max_tile_size_bytes : u32 ,
421422 pub deblock : DeblockState ,
422423 pub segmentation : SegmentationState ,
423424 pub restoration : RestorationState ,
@@ -447,6 +448,7 @@ impl<T: Pixel> FrameState<T> {
447448 rec : Frame :: new ( luma_width, luma_height, fi. sequence . chroma_sampling ) ,
448449 cdfs : CDFContext :: new ( 0 ) ,
449450 context_update_tile_id : 0 ,
451+ max_tile_size_bytes : 0 ,
450452 deblock : Default :: default ( ) ,
451453 segmentation : Default :: default ( ) ,
452454 restoration : rs,
@@ -2144,7 +2146,7 @@ fn encode_tile_group<T: Pixel>(fi: &FrameInvariants<T>, fs: &mut FrameState<T>)
21442146 fs. t . print_code ( ) ;
21452147 }
21462148
2147- let ( idx_max, _max_len ) = raw_tiles
2149+ let ( idx_max, max_len ) = raw_tiles
21482150 . iter ( )
21492151 . map ( Vec :: len)
21502152 . enumerate ( )
@@ -2156,10 +2158,14 @@ fn encode_tile_group<T: Pixel>(fi: &FrameInvariants<T>, fs: &mut FrameState<T>)
21562158 fs. cdfs = cdfs[ idx_max] ;
21572159 fs. cdfs . reset_counts ( ) ;
21582160
2159- build_raw_tile_group ( ti, & raw_tiles)
2161+ let max_tile_size_bytes = ( ( max_len as u32 ) . ilog ( ) + 7 ) / 8 ;
2162+ debug_assert ! ( max_tile_size_bytes > 0 && max_tile_size_bytes <= 4 ) ;
2163+ fs. max_tile_size_bytes = max_tile_size_bytes;
2164+
2165+ build_raw_tile_group ( ti, & raw_tiles, max_tile_size_bytes)
21602166}
21612167
2162- fn build_raw_tile_group ( ti : & TilingInfo , raw_tiles : & [ Vec < u8 > ] ) -> Vec < u8 > {
2168+ fn build_raw_tile_group ( ti : & TilingInfo , raw_tiles : & [ Vec < u8 > ] , max_tile_size_bytes : u32 ) -> Vec < u8 > {
21632169 // <https://aomediacodec.github.io/av1-spec/#general-tile-group-obu-syntax>
21642170 let mut raw = Vec :: new ( ) ;
21652171 let mut bw = BitWriter :: endian ( & mut raw, BigEndian ) ;
@@ -2172,7 +2178,7 @@ fn build_raw_tile_group(ti: &TilingInfo, raw_tiles: &[Vec<u8>]) -> Vec<u8> {
21722178 let last = raw_tiles. len ( ) - 1 ;
21732179 if i != last {
21742180 let tile_size_minus_1 = raw_tile. len ( ) - 1 ;
2175- bw. write_le ( 4 , tile_size_minus_1 as u64 ) . unwrap ( ) ;
2181+ bw. write_le ( max_tile_size_bytes , tile_size_minus_1 as u64 ) . unwrap ( ) ;
21762182 }
21772183 bw. write_bytes ( & raw_tile) . unwrap ( ) ;
21782184 }
0 commit comments