@@ -2973,7 +2973,8 @@ fn get_initial_cdfcontext<T: Pixel>(fi: &FrameInvariants<T>) -> CDFContext {
2973
2973
#[ hawktracer( encode_tile_group) ]
2974
2974
fn encode_tile_group < T : Pixel > (
2975
2975
fi : & FrameInvariants < T > , fs : & mut FrameState < T > , inter_cfg : & InterConfig ,
2976
- ) -> Vec < u8 > {
2976
+ progress : & dyn GranularProgress ,
2977
+ ) -> Option < Vec < u8 > > {
2977
2978
let planes =
2978
2979
if fi. sequence . chroma_sampling == ChromaSampling :: Cs400 { 1 } else { 3 } ;
2979
2980
let mut blocks = FrameBlocks :: new ( fi. w_in_b , fi. h_in_b ) ;
@@ -2988,12 +2989,18 @@ fn encode_tile_group<T: Pixel>(
2988
2989
. zip ( cdfs. iter_mut ( ) )
2989
2990
. collect :: < Vec < _ > > ( )
2990
2991
. 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) )
2994
2996
} )
2997
+ . while_some ( )
2995
2998
. unzip ( ) ;
2996
2999
3000
+ if raw_tiles. len ( ) != ti. tile_count ( ) {
3001
+ return None ;
3002
+ }
3003
+
2997
3004
let stats =
2998
3005
tile_states. into_iter ( ) . map ( |ts| ts. enc_stats ) . collect :: < Vec < _ > > ( ) ;
2999
3006
for tile_stats in stats {
@@ -3078,7 +3085,7 @@ fn encode_tile_group<T: Pixel>(
3078
3085
debug_assert ! ( max_tile_size_bytes > 0 && max_tile_size_bytes <= 4 ) ;
3079
3086
fs. max_tile_size_bytes = max_tile_size_bytes;
3080
3087
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) )
3082
3089
}
3083
3090
3084
3091
fn build_raw_tile_group (
@@ -3206,8 +3213,8 @@ fn check_lf_queue<T: Pixel>(
3206
3213
fn encode_tile < ' a , T : Pixel > (
3207
3214
fi : & FrameInvariants < T > , ts : & mut TileStateMut < ' _ , T > ,
3208
3215
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 > > {
3211
3218
let mut w = WriterEncoder :: new ( ) ;
3212
3219
let planes =
3213
3220
if fi. sequence . chroma_sampling == ChromaSampling :: Cs400 { 1 } else { 3 } ;
@@ -3226,6 +3233,11 @@ fn encode_tile<'a, T: Pixel>(
3226
3233
for sbx in 0 ..ts. sb_width {
3227
3234
cw. fc_log . clear ( ) ;
3228
3235
3236
+ let data = ProgressData { } ;
3237
+ if !progress. progress ( & data) {
3238
+ return None ;
3239
+ }
3240
+
3229
3241
let tile_sbo = TileSuperBlockOffset ( SuperBlockOffset { x : sbx, y : sby } ) ;
3230
3242
let mut sbs_qe = SBSQueueEntry {
3231
3243
sbo : tile_sbo,
@@ -3402,7 +3414,7 @@ fn encode_tile<'a, T: Pixel>(
3402
3414
ts. sbo. 0 . x,
3403
3415
ts. sbo. 0 . y
3404
3416
) ;
3405
- w. done ( )
3417
+ Some ( w. done ( ) )
3406
3418
}
3407
3419
3408
3420
#[ allow( unused) ]
@@ -3485,7 +3497,8 @@ fn get_initial_segmentation<T: Pixel>(
3485
3497
3486
3498
pub fn encode_frame < T : Pixel > (
3487
3499
fi : & FrameInvariants < T > , fs : & mut FrameState < T > , inter_cfg : & InterConfig ,
3488
- ) -> Vec < u8 > {
3500
+ progress : & dyn GranularProgress ,
3501
+ ) -> Option < Vec < u8 > > {
3489
3502
debug_assert ! ( !fi. show_existing_frame) ;
3490
3503
debug_assert ! ( !fi. invalid) ;
3491
3504
let obu_extension = 0 ;
@@ -3496,7 +3509,7 @@ pub fn encode_frame<T: Pixel>(
3496
3509
fs. segmentation = get_initial_segmentation ( fi) ;
3497
3510
segmentation_optimize ( fi, fs) ;
3498
3511
}
3499
- let tile_group = encode_tile_group ( fi, fs, inter_cfg) ;
3512
+ let tile_group = encode_tile_group ( fi, fs, inter_cfg, progress ) ? ;
3500
3513
3501
3514
if fi. frame_type == FrameType :: KEY {
3502
3515
write_key_frame_obus ( & mut packet, fi, obu_extension) . unwrap ( ) ;
@@ -3527,7 +3540,7 @@ pub fn encode_frame<T: Pixel>(
3527
3540
buf2. clear ( ) ;
3528
3541
3529
3542
packet. write_all ( & tile_group) . unwrap ( ) ;
3530
- packet
3543
+ Some ( packet)
3531
3544
}
3532
3545
3533
3546
pub fn update_rec_buffer < T : Pixel > (
0 commit comments