@@ -2973,7 +2973,8 @@ fn get_initial_cdfcontext<T: Pixel>(fi: &FrameInvariants<T>) -> CDFContext {
29732973#[ hawktracer( encode_tile_group) ]
29742974fn encode_tile_group < T : Pixel > (
29752975 fi : & FrameInvariants < T > , fs : & mut FrameState < T > , inter_cfg : & InterConfig ,
2976- ) -> Vec < u8 > {
2976+ progress : & dyn GranularProgress ,
2977+ ) -> Option < Vec < u8 > > {
29772978 let planes =
29782979 if fi. sequence . chroma_sampling == ChromaSampling :: Cs400 { 1 } else { 3 } ;
29792980 let mut blocks = FrameBlocks :: new ( fi. w_in_b , fi. h_in_b ) ;
@@ -2988,12 +2989,18 @@ fn encode_tile_group<T: Pixel>(
29882989 . zip ( cdfs. iter_mut ( ) )
29892990 . collect :: < Vec < _ > > ( )
29902991 . into_par_iter ( )
2991- . map ( |( mut ctx, cdf) | {
2992- let raw = encode_tile ( fi, & mut ctx. ts , cdf, & mut ctx. tb , inter_cfg) ;
2993- ( raw, ctx. ts )
2992+ . map ( |( ctx, cdf) | {
2993+ let TileContextMut { mut ts, mut tb, .. } = ctx;
2994+ let raw = encode_tile ( fi, & mut ts, cdf, & mut tb, inter_cfg, progress) ;
2995+ raw. map ( |raw| ( raw, ts) )
29942996 } )
2997+ . while_some ( )
29952998 . unzip ( ) ;
29962999
3000+ if raw_tiles. len ( ) != ti. tile_count ( ) {
3001+ return None ;
3002+ }
3003+
29973004 let stats =
29983005 tile_states. into_iter ( ) . map ( |ts| ts. enc_stats ) . collect :: < Vec < _ > > ( ) ;
29993006 for tile_stats in stats {
@@ -3078,7 +3085,7 @@ fn encode_tile_group<T: Pixel>(
30783085 debug_assert ! ( max_tile_size_bytes > 0 && max_tile_size_bytes <= 4 ) ;
30793086 fs. max_tile_size_bytes = max_tile_size_bytes;
30803087
3081- build_raw_tile_group ( ti, & raw_tiles, max_tile_size_bytes)
3088+ Some ( build_raw_tile_group ( ti, & raw_tiles, max_tile_size_bytes) )
30823089}
30833090
30843091fn build_raw_tile_group (
@@ -3206,8 +3213,8 @@ fn check_lf_queue<T: Pixel>(
32063213fn encode_tile < ' a , T : Pixel > (
32073214 fi : & FrameInvariants < T > , ts : & mut TileStateMut < ' _ , T > ,
32083215 fc : & ' a mut CDFContext , blocks : & ' a mut TileBlocksMut < ' a > ,
3209- inter_cfg : & InterConfig ,
3210- ) -> Vec < u8 > {
3216+ inter_cfg : & InterConfig , progress : & dyn GranularProgress ,
3217+ ) -> Option < Vec < u8 > > {
32113218 let mut w = WriterEncoder :: new ( ) ;
32123219 let planes =
32133220 if fi. sequence . chroma_sampling == ChromaSampling :: Cs400 { 1 } else { 3 } ;
@@ -3226,6 +3233,11 @@ fn encode_tile<'a, T: Pixel>(
32263233 for sbx in 0 ..ts. sb_width {
32273234 cw. fc_log . clear ( ) ;
32283235
3236+ let data = ProgressData { } ;
3237+ if !progress. progress ( & data) {
3238+ return None ;
3239+ }
3240+
32293241 let tile_sbo = TileSuperBlockOffset ( SuperBlockOffset { x : sbx, y : sby } ) ;
32303242 let mut sbs_qe = SBSQueueEntry {
32313243 sbo : tile_sbo,
@@ -3402,7 +3414,7 @@ fn encode_tile<'a, T: Pixel>(
34023414 ts. sbo. 0 . x,
34033415 ts. sbo. 0 . y
34043416 ) ;
3405- w. done ( )
3417+ Some ( w. done ( ) )
34063418}
34073419
34083420#[ allow( unused) ]
@@ -3485,7 +3497,8 @@ fn get_initial_segmentation<T: Pixel>(
34853497
34863498pub fn encode_frame < T : Pixel > (
34873499 fi : & FrameInvariants < T > , fs : & mut FrameState < T > , inter_cfg : & InterConfig ,
3488- ) -> Vec < u8 > {
3500+ progress : & dyn GranularProgress ,
3501+ ) -> Option < Vec < u8 > > {
34893502 debug_assert ! ( !fi. show_existing_frame) ;
34903503 debug_assert ! ( !fi. invalid) ;
34913504 let obu_extension = 0 ;
@@ -3496,7 +3509,7 @@ pub fn encode_frame<T: Pixel>(
34963509 fs. segmentation = get_initial_segmentation ( fi) ;
34973510 segmentation_optimize ( fi, fs) ;
34983511 }
3499- let tile_group = encode_tile_group ( fi, fs, inter_cfg) ;
3512+ let tile_group = encode_tile_group ( fi, fs, inter_cfg, progress ) ? ;
35003513
35013514 if fi. frame_type == FrameType :: KEY {
35023515 write_key_frame_obus ( & mut packet, fi, obu_extension) . unwrap ( ) ;
@@ -3527,7 +3540,7 @@ pub fn encode_frame<T: Pixel>(
35273540 buf2. clear ( ) ;
35283541
35293542 packet. write_all ( & tile_group) . unwrap ( ) ;
3530- packet
3543+ Some ( packet)
35313544}
35323545
35333546pub fn update_rec_buffer < T : Pixel > (
0 commit comments