From 755496d0f98fdd60cb3a92a416e02754065852b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Wed, 18 Nov 2020 14:16:59 +0100 Subject: [PATCH] Pad: allow handling Events in PadProbes --- gstreamer/src/pad.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index 28ac4a9b0..8345276b9 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -1133,8 +1133,14 @@ unsafe fn update_probe_info( assert_eq!(data_type, Some(Buffer::static_type())); // Buffer not consumed by probe; consume it here } - None if data_type == Some(Buffer::static_type()) => { - // Buffer consumed by probe + Some(PadProbeData::Event(_)) => { + assert_eq!(data_type, Some(Event::static_type())); + // Event not consumed by probe; consume it here + } + None if data_type == Some(Buffer::static_type()) + || data_type == Some(Event::static_type()) => + { + // Buffer or Event consumed by probe } other => panic!( "Bad data for {:?} pad probe returning Handled: {:?}", @@ -1999,6 +2005,19 @@ mod tests { }); } + { + let events = events.clone(); + pad.add_probe(::PadProbeType::EVENT_UPSTREAM, move |_, info| { + if let Some(PadProbeData::Event(event)) = info.data.take() { + let mut events = events.lock().unwrap(); + events.push(event); + } else { + unreachable!(); + } + ::PadProbeReturn::Handled + }); + } + { let buffers = buffers.clone(); let flow_override = flow_override; @@ -2020,6 +2039,7 @@ mod tests { pad.set_active(true).unwrap(); + assert!(pad.send_event(::event::Latency::new(::ClockTime::from_nseconds(10)))); assert!(pad.push_event(::event::StreamStart::new("test"))); let segment = ::FormattedSegment::<::ClockTime>::new(); assert!(pad.push_event(::event::Segment::new(segment.as_ref()))); @@ -2029,11 +2049,12 @@ mod tests { let events = events.lock().unwrap(); let buffers = buffers.lock().unwrap(); - assert_eq!(events.len(), 2); + assert_eq!(events.len(), 3); assert_eq!(buffers.len(), 2); - assert_eq!(events[0].get_type(), ::EventType::StreamStart); - assert_eq!(events[1].get_type(), ::EventType::Segment); + assert_eq!(events[0].get_type(), ::EventType::Latency); + assert_eq!(events[1].get_type(), ::EventType::StreamStart); + assert_eq!(events[2].get_type(), ::EventType::Segment); assert!( buffers.iter().all(|b| b.is_writable()),