ts/pad: don't pass self as ref in remaining handler traits functions

- They are either unit types or `Clone` (in which case they are implemented
  as pointers).
- Internally, we already use an owned version, so there's no need to get a
  reference.
- It facilitates implementation if the handler must be moved into a closure
  or a `Future`.
This commit is contained in:
François Laignel 2022-10-24 11:57:27 +02:00
parent 43e28e5a6d
commit 554ce7e7d6
11 changed files with 42 additions and 40 deletions

View file

@ -133,7 +133,7 @@ impl PadSinkHandler for TestSinkPadHandler {
.boxed() .boxed()
} }
fn sink_event(&self, _pad: &PadSinkRef, imp: &TestSink, event: gst::Event) -> bool { fn sink_event(self, _pad: &PadSinkRef, imp: &TestSink, event: gst::Event) -> bool {
if let EventView::FlushStart(..) = event.view() { if let EventView::FlushStart(..) = event.view() {
return imp.task.flush_start().await_maybe_on_context().is_ok(); return imp.task.flush_start().await_maybe_on_context().is_ok();
} }

View file

@ -82,7 +82,7 @@ struct AppSrcPadHandler;
impl PadSrcHandler for AppSrcPadHandler { impl PadSrcHandler for AppSrcPadHandler {
type ElementImpl = AppSrc; type ElementImpl = AppSrc;
fn src_event(&self, pad: &PadSrcRef, imp: &AppSrc, event: gst::Event) -> bool { fn src_event(self, pad: &PadSrcRef, imp: &AppSrc, event: gst::Event) -> bool {
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event);
use gst::EventView; use gst::EventView;
@ -103,7 +103,7 @@ impl PadSrcHandler for AppSrcPadHandler {
ret ret
} }
fn src_query(&self, pad: &PadSrcRef, imp: &AppSrc, query: &mut gst::QueryRef) -> bool { fn src_query(self, pad: &PadSrcRef, imp: &AppSrc, query: &mut gst::QueryRef) -> bool {
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query);
use gst::QueryViewMut; use gst::QueryViewMut;

View file

@ -219,7 +219,7 @@ impl PadSinkHandler for InputSelectorPadSinkHandler {
.boxed() .boxed()
} }
fn sink_event(&self, _pad: &PadSinkRef, imp: &InputSelector, event: gst::Event) -> bool { fn sink_event(self, _pad: &PadSinkRef, imp: &InputSelector, event: gst::Event) -> bool {
/* Drop all events for now */ /* Drop all events for now */
if let gst::EventView::FlushStart(..) = event.view() { if let gst::EventView::FlushStart(..) = event.view() {
/* Unblock downstream */ /* Unblock downstream */
@ -234,7 +234,7 @@ impl PadSinkHandler for InputSelectorPadSinkHandler {
true true
} }
fn sink_query(&self, pad: &PadSinkRef, imp: &InputSelector, query: &mut gst::QueryRef) -> bool { fn sink_query(self, pad: &PadSinkRef, imp: &InputSelector, query: &mut gst::QueryRef) -> bool {
gst::log!(CAT, obj: pad.gst_pad(), "Handling query {:?}", query); gst::log!(CAT, obj: pad.gst_pad(), "Handling query {:?}", query);
if query.is_serialized() { if query.is_serialized() {
@ -254,7 +254,7 @@ struct InputSelectorPadSrcHandler;
impl PadSrcHandler for InputSelectorPadSrcHandler { impl PadSrcHandler for InputSelectorPadSrcHandler {
type ElementImpl = InputSelector; type ElementImpl = InputSelector;
fn src_query(&self, pad: &PadSrcRef, imp: &InputSelector, query: &mut gst::QueryRef) -> bool { fn src_query(self, pad: &PadSrcRef, imp: &InputSelector, query: &mut gst::QueryRef) -> bool {
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query);
use gst::QueryViewMut; use gst::QueryViewMut;

View file

@ -562,7 +562,7 @@ impl PadSinkHandler for SinkHandler {
.boxed() .boxed()
} }
fn sink_event(&self, pad: &PadSinkRef, jb: &JitterBuffer, event: gst::Event) -> bool { fn sink_event(self, pad: &PadSinkRef, jb: &JitterBuffer, event: gst::Event) -> bool {
use gst::EventView; use gst::EventView;
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event);
@ -870,7 +870,7 @@ impl SrcHandler {
impl PadSrcHandler for SrcHandler { impl PadSrcHandler for SrcHandler {
type ElementImpl = JitterBuffer; type ElementImpl = JitterBuffer;
fn src_event(&self, pad: &PadSrcRef, jb: &JitterBuffer, event: gst::Event) -> bool { fn src_event(self, pad: &PadSrcRef, jb: &JitterBuffer, event: gst::Event) -> bool {
use gst::EventView; use gst::EventView;
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event);
@ -907,7 +907,7 @@ impl PadSrcHandler for SrcHandler {
jb.sink_pad.gst_pad().push_event(event) jb.sink_pad.gst_pad().push_event(event)
} }
fn src_query(&self, pad: &PadSrcRef, jb: &JitterBuffer, query: &mut gst::QueryRef) -> bool { fn src_query(self, pad: &PadSrcRef, jb: &JitterBuffer, query: &mut gst::QueryRef) -> bool {
use gst::QueryViewMut; use gst::QueryViewMut;
gst::log!(CAT, obj: pad.gst_pad(), "Forwarding {:?}", query); gst::log!(CAT, obj: pad.gst_pad(), "Forwarding {:?}", query);

View file

@ -243,7 +243,7 @@ impl PadSinkHandler for ProxySinkPadHandler {
.boxed() .boxed()
} }
fn sink_event(&self, pad: &PadSinkRef, imp: &ProxySink, event: gst::Event) -> bool { fn sink_event(self, pad: &PadSinkRef, imp: &ProxySink, event: gst::Event) -> bool {
gst::debug!(SINK_CAT, obj: pad.gst_pad(), "Handling non-serialized {:?}", event); gst::debug!(SINK_CAT, obj: pad.gst_pad(), "Handling non-serialized {:?}", event);
let src_pad = { let src_pad = {
@ -666,7 +666,7 @@ struct ProxySrcPadHandler;
impl PadSrcHandler for ProxySrcPadHandler { impl PadSrcHandler for ProxySrcPadHandler {
type ElementImpl = ProxySrc; type ElementImpl = ProxySrc;
fn src_event(&self, pad: &PadSrcRef, imp: &ProxySrc, event: gst::Event) -> bool { fn src_event(self, pad: &PadSrcRef, imp: &ProxySrc, event: gst::Event) -> bool {
gst::log!(SRC_CAT, obj: pad.gst_pad(), "Handling {:?}", event); gst::log!(SRC_CAT, obj: pad.gst_pad(), "Handling {:?}", event);
let sink_pad = { let sink_pad = {
@ -718,7 +718,7 @@ impl PadSrcHandler for ProxySrcPadHandler {
} }
} }
fn src_query(&self, pad: &PadSrcRef, _proxysrc: &ProxySrc, query: &mut gst::QueryRef) -> bool { fn src_query(self, pad: &PadSrcRef, _proxysrc: &ProxySrc, query: &mut gst::QueryRef) -> bool {
gst::log!(SRC_CAT, obj: pad.gst_pad(), "Handling {:?}", query); gst::log!(SRC_CAT, obj: pad.gst_pad(), "Handling {:?}", query);
use gst::QueryViewMut; use gst::QueryViewMut;

View file

@ -113,7 +113,7 @@ impl PadSinkHandler for QueuePadSinkHandler {
.boxed() .boxed()
} }
fn sink_event(&self, pad: &PadSinkRef, imp: &Queue, event: gst::Event) -> bool { fn sink_event(self, pad: &PadSinkRef, imp: &Queue, event: gst::Event) -> bool {
gst::debug!(CAT, obj: pad.gst_pad(), "Handling non-serialized {:?}", event); gst::debug!(CAT, obj: pad.gst_pad(), "Handling non-serialized {:?}", event);
if let gst::EventView::FlushStart(..) = event.view() { if let gst::EventView::FlushStart(..) = event.view() {
@ -164,7 +164,7 @@ impl PadSinkHandler for QueuePadSinkHandler {
.boxed() .boxed()
} }
fn sink_query(&self, pad: &PadSinkRef, imp: &Queue, query: &mut gst::QueryRef) -> bool { fn sink_query(self, pad: &PadSinkRef, imp: &Queue, query: &mut gst::QueryRef) -> bool {
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query);
if query.is_serialized() { if query.is_serialized() {
@ -184,7 +184,7 @@ struct QueuePadSrcHandler;
impl PadSrcHandler for QueuePadSrcHandler { impl PadSrcHandler for QueuePadSrcHandler {
type ElementImpl = Queue; type ElementImpl = Queue;
fn src_event(&self, pad: &PadSrcRef, imp: &Queue, event: gst::Event) -> bool { fn src_event(self, pad: &PadSrcRef, imp: &Queue, event: gst::Event) -> bool {
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event);
use gst::EventView; use gst::EventView;
@ -213,7 +213,7 @@ impl PadSrcHandler for QueuePadSrcHandler {
imp.sink_pad.gst_pad().push_event(event) imp.sink_pad.gst_pad().push_event(event)
} }
fn src_query(&self, pad: &PadSrcRef, imp: &Queue, query: &mut gst::QueryRef) -> bool { fn src_query(self, pad: &PadSrcRef, imp: &Queue, query: &mut gst::QueryRef) -> bool {
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query);
if let gst::QueryViewMut::Scheduling(q) = query.view_mut() { if let gst::QueryViewMut::Scheduling(q) = query.view_mut() {

View file

@ -122,7 +122,7 @@ pub trait PadSrcHandler: Clone + Send + Sync + 'static {
type ElementImpl: ElementImpl + ObjectSubclass; type ElementImpl: ElementImpl + ObjectSubclass;
fn src_activate( fn src_activate(
&self, self,
pad: &PadSrcRef, pad: &PadSrcRef,
_imp: &Self::ElementImpl, _imp: &Self::ElementImpl,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
@ -151,7 +151,7 @@ pub trait PadSrcHandler: Clone + Send + Sync + 'static {
} }
fn src_activatemode( fn src_activatemode(
&self, self,
_pad: &PadSrcRef, _pad: &PadSrcRef,
_imp: &Self::ElementImpl, _imp: &Self::ElementImpl,
_mode: gst::PadMode, _mode: gst::PadMode,
@ -160,7 +160,7 @@ pub trait PadSrcHandler: Clone + Send + Sync + 'static {
Ok(()) Ok(())
} }
fn src_event(&self, pad: &PadSrcRef, imp: &Self::ElementImpl, event: gst::Event) -> bool { fn src_event(self, pad: &PadSrcRef, imp: &Self::ElementImpl, event: gst::Event) -> bool {
gst::log!(RUNTIME_CAT, obj: pad.gst_pad(), "Handling {:?}", event); gst::log!(RUNTIME_CAT, obj: pad.gst_pad(), "Handling {:?}", event);
let elem = imp.obj(); let elem = imp.obj();
@ -174,7 +174,7 @@ pub trait PadSrcHandler: Clone + Send + Sync + 'static {
} }
fn src_event_full( fn src_event_full(
&self, self,
pad: &PadSrcRef, pad: &PadSrcRef,
imp: &Self::ElementImpl, imp: &Self::ElementImpl,
event: gst::Event, event: gst::Event,
@ -186,7 +186,7 @@ pub trait PadSrcHandler: Clone + Send + Sync + 'static {
} }
fn src_query( fn src_query(
&self, self,
pad: &PadSrcRef, pad: &PadSrcRef,
imp: &Self::ElementImpl, imp: &Self::ElementImpl,
query: &mut gst::QueryRef, query: &mut gst::QueryRef,
@ -406,7 +406,7 @@ impl PadSrc {
"Panic in PadSrc activate" "Panic in PadSrc activate"
)) ))
}, },
move |imp| handler.src_activate(&PadSrcRef::new(inner_arc), imp), move |imp| H::src_activate(handler, &PadSrcRef::new(inner_arc), imp),
) )
}); });
@ -428,7 +428,7 @@ impl PadSrc {
move |imp| { move |imp| {
let this_ref = PadSrcRef::new(inner_arc); let this_ref = PadSrcRef::new(inner_arc);
this_ref.activate_mode_hook(mode, active)?; this_ref.activate_mode_hook(mode, active)?;
handler.src_activatemode(&this_ref, imp, mode, active) H::src_activatemode(handler, &this_ref, imp, mode, active)
}, },
) )
}); });
@ -444,7 +444,9 @@ impl PadSrc {
H::ElementImpl::catch_panic_pad_function( H::ElementImpl::catch_panic_pad_function(
parent, parent,
|| Err(FlowError::Error), || Err(FlowError::Error),
move |imp| handler.src_event_full(&PadSrcRef::new(inner_arc), imp, event), move |imp| {
H::src_event_full(handler, &PadSrcRef::new(inner_arc), imp, event)
},
) )
}); });
@ -458,7 +460,7 @@ impl PadSrc {
|| false, || false,
move |imp| { move |imp| {
if !query.is_serialized() { if !query.is_serialized() {
handler.src_query(&PadSrcRef::new(inner_arc), imp, query) H::src_query(handler, &PadSrcRef::new(inner_arc), imp, query)
} else { } else {
gst::fixme!(RUNTIME_CAT, obj: inner_arc.gst_pad(), "Serialized Query not supported"); gst::fixme!(RUNTIME_CAT, obj: inner_arc.gst_pad(), "Serialized Query not supported");
false false
@ -511,7 +513,7 @@ pub trait PadSinkHandler: Clone + Send + Sync + 'static {
type ElementImpl: ElementImpl + ObjectSubclass; type ElementImpl: ElementImpl + ObjectSubclass;
fn sink_activate( fn sink_activate(
&self, self,
pad: &PadSinkRef, pad: &PadSinkRef,
_imp: &Self::ElementImpl, _imp: &Self::ElementImpl,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
@ -540,7 +542,7 @@ pub trait PadSinkHandler: Clone + Send + Sync + 'static {
} }
fn sink_activatemode( fn sink_activatemode(
&self, self,
_pad: &PadSinkRef, _pad: &PadSinkRef,
_imp: &Self::ElementImpl, _imp: &Self::ElementImpl,
_mode: gst::PadMode, _mode: gst::PadMode,
@ -567,7 +569,7 @@ pub trait PadSinkHandler: Clone + Send + Sync + 'static {
future::err(FlowError::NotSupported).boxed() future::err(FlowError::NotSupported).boxed()
} }
fn sink_event(&self, pad: &PadSinkRef, imp: &Self::ElementImpl, event: gst::Event) -> bool { fn sink_event(self, pad: &PadSinkRef, imp: &Self::ElementImpl, event: gst::Event) -> bool {
assert!(!event.is_serialized()); assert!(!event.is_serialized());
gst::log!(RUNTIME_CAT, obj: pad.gst_pad(), "Handling {:?}", event); gst::log!(RUNTIME_CAT, obj: pad.gst_pad(), "Handling {:?}", event);
@ -604,7 +606,7 @@ pub trait PadSinkHandler: Clone + Send + Sync + 'static {
} }
fn sink_event_full( fn sink_event_full(
&self, self,
pad: &PadSinkRef, pad: &PadSinkRef,
imp: &Self::ElementImpl, imp: &Self::ElementImpl,
event: gst::Event, event: gst::Event,
@ -633,7 +635,7 @@ pub trait PadSinkHandler: Clone + Send + Sync + 'static {
} }
fn sink_query( fn sink_query(
&self, self,
pad: &PadSinkRef, pad: &PadSinkRef,
imp: &Self::ElementImpl, imp: &Self::ElementImpl,
query: &mut gst::QueryRef, query: &mut gst::QueryRef,
@ -807,7 +809,7 @@ impl PadSink {
"Panic in PadSink activate" "Panic in PadSink activate"
)) ))
}, },
move |imp| handler.sink_activate(&PadSinkRef::new(inner_arc), imp), move |imp| H::sink_activate(handler, &PadSinkRef::new(inner_arc), imp),
) )
}); });
@ -829,7 +831,7 @@ impl PadSink {
move |imp| { move |imp| {
let this_ref = PadSinkRef::new(inner_arc); let this_ref = PadSinkRef::new(inner_arc);
this_ref.activate_mode_hook(mode, active)?; this_ref.activate_mode_hook(mode, active)?;
handler.sink_activatemode(&this_ref, imp, mode, active) H::sink_activatemode(handler, &this_ref, imp, mode, active)
}, },
) )
}); });
@ -945,7 +947,7 @@ impl PadSink {
|| false, || false,
move |imp| { move |imp| {
if !query.is_serialized() { if !query.is_serialized() {
handler.sink_query(&PadSinkRef::new(inner_arc), imp, query) H::sink_query(handler, &PadSinkRef::new(inner_arc), imp, query)
} else { } else {
gst::fixme!(RUNTIME_CAT, obj: inner_arc.gst_pad(), "Serialized Query not supported"); gst::fixme!(RUNTIME_CAT, obj: inner_arc.gst_pad(), "Serialized Query not supported");
false false

View file

@ -96,7 +96,7 @@ struct TcpClientSrcPadHandler;
impl PadSrcHandler for TcpClientSrcPadHandler { impl PadSrcHandler for TcpClientSrcPadHandler {
type ElementImpl = TcpClientSrc; type ElementImpl = TcpClientSrc;
fn src_event(&self, pad: &PadSrcRef, imp: &TcpClientSrc, event: gst::Event) -> bool { fn src_event(self, pad: &PadSrcRef, imp: &TcpClientSrc, event: gst::Event) -> bool {
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event);
use gst::EventView; use gst::EventView;
@ -117,7 +117,7 @@ impl PadSrcHandler for TcpClientSrcPadHandler {
ret ret
} }
fn src_query(&self, pad: &PadSrcRef, imp: &TcpClientSrc, query: &mut gst::QueryRef) -> bool { fn src_query(self, pad: &PadSrcRef, imp: &TcpClientSrc, query: &mut gst::QueryRef) -> bool {
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query);
use gst::QueryViewMut; use gst::QueryViewMut;

View file

@ -190,7 +190,7 @@ impl PadSinkHandler for UdpSinkPadHandler {
.boxed() .boxed()
} }
fn sink_event(&self, _pad: &PadSinkRef, imp: &UdpSink, event: gst::Event) -> bool { fn sink_event(self, _pad: &PadSinkRef, imp: &UdpSink, event: gst::Event) -> bool {
if let EventView::FlushStart(..) = event.view() { if let EventView::FlushStart(..) = event.view() {
return imp.task.flush_start().await_maybe_on_context().is_ok(); return imp.task.flush_start().await_maybe_on_context().is_ok();
} }

View file

@ -113,7 +113,7 @@ struct UdpSrcPadHandler;
impl PadSrcHandler for UdpSrcPadHandler { impl PadSrcHandler for UdpSrcPadHandler {
type ElementImpl = UdpSrc; type ElementImpl = UdpSrc;
fn src_event(&self, pad: &PadSrcRef, imp: &UdpSrc, event: gst::Event) -> bool { fn src_event(self, pad: &PadSrcRef, imp: &UdpSrc, event: gst::Event) -> bool {
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", event);
use gst::EventView; use gst::EventView;
@ -134,7 +134,7 @@ impl PadSrcHandler for UdpSrcPadHandler {
ret ret
} }
fn src_query(&self, pad: &PadSrcRef, imp: &UdpSrc, query: &mut gst::QueryRef) -> bool { fn src_query(self, pad: &PadSrcRef, imp: &UdpSrc, query: &mut gst::QueryRef) -> bool {
gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query); gst::log!(CAT, obj: pad.gst_pad(), "Handling {:?}", query);
use gst::QueryViewMut; use gst::QueryViewMut;

View file

@ -89,7 +89,7 @@ mod imp_src {
impl PadSrcHandler for PadSrcTestHandler { impl PadSrcHandler for PadSrcTestHandler {
type ElementImpl = ElementSrcTest; type ElementImpl = ElementSrcTest;
fn src_event(&self, pad: &PadSrcRef, imp: &ElementSrcTest, event: gst::Event) -> bool { fn src_event(self, pad: &PadSrcRef, imp: &ElementSrcTest, event: gst::Event) -> bool {
gst::log!(SRC_CAT, obj: pad.gst_pad(), "Handling {:?}", event); gst::log!(SRC_CAT, obj: pad.gst_pad(), "Handling {:?}", event);
let ret = match event.view() { let ret = match event.view() {
@ -465,7 +465,7 @@ mod imp_sink {
.boxed() .boxed()
} }
fn sink_event(&self, pad: &PadSinkRef, imp: &ElementSinkTest, event: gst::Event) -> bool { fn sink_event(self, pad: &PadSinkRef, imp: &ElementSinkTest, event: gst::Event) -> bool {
gst::debug!(SINK_CAT, obj: pad.gst_pad(), "Handling non-serialized {:?}", event); gst::debug!(SINK_CAT, obj: pad.gst_pad(), "Handling non-serialized {:?}", event);
match event.view() { match event.view() {