@@ -138,13 +138,15 @@ impl Drop for FFMpegSource {
138
138
}
139
139
}
140
140
141
+ #[ allow( clippy:: too_many_arguments) ]
141
142
fn handle (
142
143
uri : String ,
143
144
params : HashMap < String , String > ,
144
145
tx : Sender < VideoFrameEnvelope > ,
145
146
signal : Arc < Mutex < bool > > ,
146
147
decode : bool ,
147
148
autoconvert_raw_formats_to_rgb24 : bool ,
149
+ block_if_queue_full : bool ,
148
150
log_level : Arc < Mutex < Option < Level > > > ,
149
151
) {
150
152
let mut queue_full_skipped_count = 0 ;
@@ -317,41 +319,48 @@ fn handle(
317
319
codec, fps, avg_fps, width, height, key_frame, raw_frame. len( ) ,
318
320
pts, dts, corrupted, pixel_format) ;
319
321
320
- if !tx. is_full ( ) {
321
- let frame_processed_ts = i64:: try_from (
322
- SystemTime :: now ( )
323
- . duration_since ( SystemTime :: UNIX_EPOCH )
324
- . unwrap ( )
325
- . as_millis ( ) ,
326
- )
327
- . expect ( "Milliseconds must fit i64" ) ;
328
-
329
- let res = tx. send ( VideoFrameEnvelope {
330
- codec,
331
- frame_width : i64:: from ( width) ,
332
- frame_height : i64:: from ( height) ,
333
- key_frame,
334
- pts,
335
- dts,
336
- corrupted,
337
- time_base : ( time_base_r. 0 as i64 , time_base_r. 1 as i64 ) ,
338
- fps,
339
- avg_fps,
340
- pixel_format,
341
- queue_full_skipped_count,
342
- payload : raw_frame,
343
- frame_received_ts,
344
- frame_processed_ts,
345
- queue_len : i64:: try_from ( tx. len ( ) ) . unwrap ( ) ,
346
- } ) ;
347
-
348
- if let Err ( e) = res {
349
- error ! ( "Unable to send data to upstream. Error is: {:?}" , e) ;
350
- break ;
322
+ let frame_processed_ts = i64:: try_from (
323
+ SystemTime :: now ( )
324
+ . duration_since ( SystemTime :: UNIX_EPOCH )
325
+ . unwrap ( )
326
+ . as_millis ( ) ,
327
+ )
328
+ . expect ( "Milliseconds must fit i64" ) ;
329
+
330
+ let frame_envelope = VideoFrameEnvelope {
331
+ codec,
332
+ frame_width : i64:: from ( width) ,
333
+ frame_height : i64:: from ( height) ,
334
+ key_frame,
335
+ pts,
336
+ dts,
337
+ corrupted,
338
+ time_base : ( time_base_r. 0 as i64 , time_base_r. 1 as i64 ) ,
339
+ fps,
340
+ avg_fps,
341
+ pixel_format,
342
+ queue_full_skipped_count,
343
+ payload : raw_frame,
344
+ frame_received_ts,
345
+ frame_processed_ts,
346
+ queue_len : i64:: try_from ( tx. len ( ) ) . unwrap ( ) ,
347
+ } ;
348
+
349
+ if !block_if_queue_full {
350
+ if !tx. is_full ( ) {
351
+ let res = tx. send ( frame_envelope) ;
352
+
353
+ if let Err ( e) = res {
354
+ error ! ( "Unable to send data to upstream. Error is: {:?}" , e) ;
355
+ break ;
356
+ }
357
+ } else {
358
+ dbg ! ( "Sink queue is full, the frame is skipped." ) ;
359
+ queue_full_skipped_count += 1 ;
351
360
}
352
361
} else {
353
- warn ! ( "Sink queue is full, the frame is skipped." ) ;
354
- queue_full_skipped_count += 1 ;
362
+ tx . send ( frame_envelope )
363
+ . expect ( "Unable to send data to upstream" ) ;
355
364
}
356
365
}
357
366
}
@@ -378,6 +387,7 @@ impl FFMpegSource {
378
387
queue_len = 32 ,
379
388
decode = false ,
380
389
autoconvert_raw_formats_to_rgb24 = false ,
390
+ block_if_queue_full = false ,
381
391
ffmpeg_log_level = FFmpegLogLevel :: Info )
382
392
) ]
383
393
pub fn new (
@@ -386,6 +396,7 @@ impl FFMpegSource {
386
396
queue_len : i64 ,
387
397
decode : bool ,
388
398
autoconvert_raw_formats_to_rgb24 : bool ,
399
+ block_if_queue_full : bool ,
389
400
ffmpeg_log_level : FFmpegLogLevel ,
390
401
) -> Self {
391
402
assert ! ( queue_len > 0 , "Queue length must be a positive number" ) ;
@@ -406,6 +417,7 @@ impl FFMpegSource {
406
417
thread_exit_signal,
407
418
decode,
408
419
autoconvert_raw_formats_to_rgb24,
420
+ block_if_queue_full,
409
421
thread_ll,
410
422
)
411
423
} ) ) ;
0 commit comments