@@ -258,6 +258,7 @@ pub(crate) struct ContextInner<T: Pixel> {
258
258
next_lookahead_output_frameno : u64 ,
259
259
/// Optional opaque to be sent back to the user
260
260
opaque_q : BTreeMap < u64 , Opaque > ,
261
+ is_flushing : bool ,
261
262
}
262
263
263
264
impl < T : Pixel > ContextInner < T > {
@@ -325,6 +326,7 @@ impl<T: Pixel> ContextInner<T> {
325
326
next_lookahead_frame : 1 ,
326
327
next_lookahead_output_frameno : 0 ,
327
328
opaque_q : BTreeMap :: new ( ) ,
329
+ is_flushing : false ,
328
330
}
329
331
}
330
332
@@ -333,8 +335,9 @@ impl<T: Pixel> ContextInner<T> {
333
335
& mut self , frame : Option < Arc < Frame < T > > > , params : Option < FrameParameters > ,
334
336
) -> Result < ( ) , EncoderStatus > {
335
337
let input_frameno = self . frame_count ;
336
- let is_flushing = frame. is_none ( ) ;
337
- if !is_flushing {
338
+
339
+ self . is_flushing = frame. is_none ( ) ;
340
+ if !self . is_flushing {
338
341
self . frame_count += 1 ;
339
342
}
340
343
self . frame_q . insert ( input_frameno, frame) ;
@@ -348,33 +351,6 @@ impl<T: Pixel> ContextInner<T> {
348
351
}
349
352
}
350
353
351
- if !self . needs_more_frame_q_lookahead ( self . next_lookahead_frame ) {
352
- let lookahead_frames = self
353
- . frame_q
354
- . range ( self . next_lookahead_frame - 1 ..)
355
- . filter_map ( |( & _input_frameno, frame) | frame. clone ( ) )
356
- . collect :: < Vec < _ > > ( ) ;
357
-
358
- if is_flushing {
359
- // This is the last time send_frame is called, process all the
360
- // remaining frames.
361
- for cur_lookahead_frames in
362
- std:: iter:: successors ( Some ( & lookahead_frames[ ..] ) , |s| s. get ( 1 ..) )
363
- {
364
- if cur_lookahead_frames. len ( ) < 2 {
365
- // All frames have been processed
366
- break ;
367
- }
368
-
369
- self . compute_keyframe_placement ( cur_lookahead_frames) ;
370
- }
371
- } else {
372
- self . compute_keyframe_placement ( & lookahead_frames) ;
373
- }
374
- }
375
-
376
- self . compute_frame_invariants ( ) ;
377
-
378
354
Ok ( ( ) )
379
355
}
380
356
@@ -1288,12 +1264,44 @@ impl<T: Pixel> ContextInner<T> {
1288
1264
}
1289
1265
}
1290
1266
1267
+ // lookahead computations
1268
+ pub ( crate ) fn compute_fi ( & mut self ) {
1269
+ if !self . needs_more_frame_q_lookahead ( self . next_lookahead_frame ) {
1270
+ let lookahead_frames = self
1271
+ . frame_q
1272
+ . range ( self . next_lookahead_frame - 1 ..)
1273
+ . filter_map ( |( & _input_frameno, frame) | frame. clone ( ) )
1274
+ . collect :: < Vec < _ > > ( ) ;
1275
+
1276
+ if self . is_flushing {
1277
+ // This is the last time send_frame is called, process all the
1278
+ // remaining frames.
1279
+ for cur_lookahead_frames in
1280
+ std:: iter:: successors ( Some ( & lookahead_frames[ ..] ) , |s| s. get ( 1 ..) )
1281
+ {
1282
+ if cur_lookahead_frames. len ( ) < 2 {
1283
+ // All frames have been processed
1284
+ break ;
1285
+ }
1286
+
1287
+ self . compute_keyframe_placement ( cur_lookahead_frames) ;
1288
+ }
1289
+ } else {
1290
+ self . compute_keyframe_placement ( & lookahead_frames) ;
1291
+ }
1292
+ }
1293
+
1294
+ self . compute_frame_invariants ( ) ;
1295
+ }
1296
+
1291
1297
#[ hawktracer( receive_packet) ]
1292
1298
pub fn receive_packet ( & mut self ) -> Result < Packet < T > , EncoderStatus > {
1293
1299
if self . done_processing ( ) {
1294
1300
return Err ( EncoderStatus :: LimitReached ) ;
1295
1301
}
1296
1302
1303
+ self . compute_fi ( ) ;
1304
+
1297
1305
if self . needs_more_fi_lookahead ( ) {
1298
1306
return Err ( EncoderStatus :: NeedMoreData ) ;
1299
1307
}
0 commit comments