diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2022-10-09 16:06:59 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2022-10-10 15:03:25 +0300 |
commit | 7ee4afacf413b2e3c386bb1070994ed4325994e6 (patch) | |
tree | eddcc0e047ab4704e5a459dd551a55196e8a1848 /text | |
parent | 7818ac658b02417fda071ce025b6d6a7fdb54a76 (diff) |
Change *Impl trait methods to only take &self and not Self::Type in addition
Diffstat (limited to 'text')
-rw-r--r-- | text/ahead/src/textahead/imp.rs | 43 | ||||
-rw-r--r-- | text/json/src/jsongstenc/imp.rs | 41 | ||||
-rw-r--r-- | text/json/src/jsongstparse/imp.rs | 183 | ||||
-rw-r--r-- | text/regex/src/gstregex/imp.rs | 39 | ||||
-rw-r--r-- | text/wrap/src/gsttextwrap/imp.rs | 79 |
5 files changed, 168 insertions, 217 deletions
diff --git a/text/ahead/src/textahead/imp.rs b/text/ahead/src/textahead/imp.rs index 61bb0277b..4cda3e568 100644 --- a/text/ahead/src/textahead/imp.rs +++ b/text/ahead/src/textahead/imp.rs @@ -77,14 +77,14 @@ impl ObjectSubclass for TextAhead { TextAhead::catch_panic_pad_function( parent, || Err(gst::FlowError::Error), - |imp, element| imp.sink_chain(pad, element, buffer), + |imp| imp.sink_chain(pad, buffer), ) }) .event_function(|pad, parent, event| { TextAhead::catch_panic_pad_function( parent, || false, - |imp, element| imp.sink_event(pad, element, event), + |imp| imp.sink_event(pad, event), ) }) .build(); @@ -144,13 +144,7 @@ impl ObjectImpl for TextAhead { PROPERTIES.as_ref() } - fn set_property( - &self, - _obj: &Self::Type, - _id: usize, - value: &glib::Value, - pspec: &glib::ParamSpec, - ) { + fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) { let mut settings = self.settings.lock().unwrap(); match pspec.name() { @@ -173,7 +167,7 @@ impl ObjectImpl for TextAhead { } } - fn property(&self, _obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { + fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { let settings = self.settings.lock().unwrap(); match pspec.name() { @@ -186,9 +180,10 @@ impl ObjectImpl for TextAhead { } } - fn constructed(&self, obj: &Self::Type) { - self.parent_constructed(obj); + fn constructed(&self) { + self.parent_constructed(); + let obj = self.instance(); obj.add_pad(&self.sink_pad).unwrap(); obj.add_pad(&self.src_pad).unwrap(); } @@ -242,10 +237,9 @@ impl ElementImpl for TextAhead { fn change_state( &self, - element: &Self::Type, transition: gst::StateChange, ) -> Result<gst::StateChangeSuccess, gst::StateChangeError> { - let res = self.parent_change_state(element, transition); + let res = self.parent_change_state(transition); match transition { gst::StateChange::ReadyToPaused => *self.state.lock().unwrap() = State::default(), @@ -264,7 +258,6 @@ impl TextAhead { fn sink_chain( &self, _pad: &gst::Pad, - element: &super::TextAhead, buffer: gst::Buffer, ) -> Result<gst::FlowSuccess, gst::FlowError> { let pts = buffer.pts(); @@ -279,7 +272,7 @@ impl TextAhead { // queue buffer let mut state = self.state.lock().unwrap(); - gst::log!(CAT, obj: element, "input {:?}: {}", pts, text); + gst::log!(CAT, imp: self, "input {:?}: {}", pts, text); state.pending.push(Input { text, @@ -295,26 +288,27 @@ impl TextAhead { // then check if we can output // FIXME: this won't work on live pipelines as we can't really report latency if state.pending.len() > n_ahead { - self.push_pending(element, &mut state) + self.push_pending(&mut state) } else { Ok(gst::FlowSuccess::Ok) } } - fn sink_event(&self, pad: &gst::Pad, element: &super::TextAhead, event: gst::Event) -> bool { + fn sink_event(&self, pad: &gst::Pad, event: gst::Event) -> bool { match event.view() { gst::EventView::Eos(_) => { let mut state = self.state.lock().unwrap(); - gst::debug!(CAT, obj: element, "eos"); + gst::debug!(CAT, imp: self, "eos"); while !state.pending.is_empty() { - let _ = self.push_pending(element, &mut state); + let _ = self.push_pending(&mut state); } - pad.event_default(Some(element), event) + pad.event_default(Some(&*self.instance()), event) } gst::EventView::Caps(_caps) => { // set caps on src pad + let element = self.instance(); let templ = element.class().pad_template("src").unwrap(); let _ = self.src_pad.push_event(gst::event::Caps::new(templ.caps())); true @@ -332,16 +326,15 @@ impl TextAhead { } } - pad.event_default(Some(element), event) + pad.event_default(Some(&*self.instance()), event) } - _ => pad.event_default(Some(element), event), + _ => pad.event_default(Some(&*self.instance()), event), } } /// push first pending buffer as current and all the other ones as ahead text fn push_pending( &self, - element: &super::TextAhead, state: &mut MutexGuard<State>, ) -> Result<gst::FlowSuccess, gst::FlowError> { if state.done { @@ -390,7 +383,7 @@ impl TextAhead { } } - gst::log!(CAT, obj: element, "output {:?}: {}", pts, text); + gst::log!(CAT, imp: self, "output {:?}: {}", pts, text); let mut output = gst::Buffer::from_mut_slice(text.into_bytes()); { diff --git a/text/json/src/jsongstenc/imp.rs b/text/json/src/jsongstenc/imp.rs index cfb2e877d..ce504f056 100644 --- a/text/json/src/jsongstenc/imp.rs +++ b/text/json/src/jsongstenc/imp.rs @@ -52,7 +52,6 @@ impl JsonGstEnc { fn sink_chain( &self, _pad: &gst::Pad, - element: &super::JsonGstEnc, buffer: gst::Buffer, ) -> Result<gst::FlowSuccess, gst::FlowError> { let pts = buffer.pts(); @@ -66,8 +65,8 @@ impl JsonGstEnc { }; let mut json = serde_json::to_string(&line).map_err(|err| { - gst::element_error!( - element, + gst::element_imp_error!( + self, gst::ResourceError::Write, ["Failed to serialize as json {}", err] ); @@ -92,8 +91,8 @@ impl JsonGstEnc { } let map = buffer.map_readable().map_err(|_| { - gst::element_error!( - element, + gst::element_imp_error!( + self, gst::ResourceError::Read, ["Failed to map buffer readable"] ); @@ -102,8 +101,8 @@ impl JsonGstEnc { })?; let text = std::str::from_utf8(map.as_slice()).map_err(|err| { - gst::element_error!( - element, + gst::element_imp_error!( + self, gst::ResourceError::Read, ["Failed to map decode as utf8: {}", err] ); @@ -112,8 +111,8 @@ impl JsonGstEnc { })?; let data: &serde_json::value::RawValue = serde_json::from_str(text).map_err(|err| { - gst::element_error!( - element, + gst::element_imp_error!( + self, gst::ResourceError::Read, ["Failed to parse input as json: {}", err] ); @@ -128,8 +127,8 @@ impl JsonGstEnc { }; let mut json = serde_json::to_string(&line).map_err(|err| { - gst::element_error!( - element, + gst::element_imp_error!( + self, gst::ResourceError::Write, ["Failed to serialize as json {}", err] ); @@ -149,7 +148,7 @@ impl JsonGstEnc { self.srcpad.push(buf) } - fn sink_event(&self, pad: &gst::Pad, element: &super::JsonGstEnc, event: gst::Event) -> bool { + fn sink_event(&self, pad: &gst::Pad, event: gst::Event) -> bool { use gst::EventView; gst::log!(CAT, obj: pad, "Handling event {:?}", event); @@ -170,8 +169,8 @@ impl JsonGstEnc { let caps = gst::Caps::builder("application/x-json").build(); self.srcpad.push_event(gst::event::Caps::new(&caps)) } - EventView::Eos(_) => pad.event_default(Some(element), event), - _ => pad.event_default(Some(element), event), + EventView::Eos(_) => pad.event_default(Some(&*self.instance()), event), + _ => pad.event_default(Some(&*self.instance()), event), } } } @@ -189,14 +188,14 @@ impl ObjectSubclass for JsonGstEnc { JsonGstEnc::catch_panic_pad_function( parent, || Err(gst::FlowError::Error), - |enc, element| enc.sink_chain(pad, element, buffer), + |enc| enc.sink_chain(pad, buffer), ) }) .event_function(|pad, parent, event| { JsonGstEnc::catch_panic_pad_function( parent, || false, - |enc, element| enc.sink_event(pad, element, event), + |enc| enc.sink_event(pad, event), ) }) .build(); @@ -213,9 +212,10 @@ impl ObjectSubclass for JsonGstEnc { } impl ObjectImpl for JsonGstEnc { - fn constructed(&self, obj: &Self::Type) { - self.parent_constructed(obj); + fn constructed(&self) { + self.parent_constructed(); + let obj = self.instance(); obj.add_pad(&self.sinkpad).unwrap(); obj.add_pad(&self.srcpad).unwrap(); } @@ -266,10 +266,9 @@ impl ElementImpl for JsonGstEnc { fn change_state( &self, - element: &Self::Type, transition: gst::StateChange, ) -> Result<gst::StateChangeSuccess, gst::StateChangeError> { - gst::trace!(CAT, obj: element, "Changing state {:?}", transition); + gst::trace!(CAT, imp: self, "Changing state {:?}", transition); match transition { gst::StateChange::ReadyToPaused | gst::StateChange::PausedToReady => { @@ -280,6 +279,6 @@ impl ElementImpl for JsonGstEnc { _ => (), } - self.parent_change_state(element, transition) + self.parent_change_state(transition) } } diff --git a/text/json/src/jsongstparse/imp.rs b/text/json/src/jsongstparse/imp.rs index 92d0378a9..75d8c095d 100644 --- a/text/json/src/jsongstparse/imp.rs +++ b/text/json/src/jsongstparse/imp.rs @@ -36,10 +36,12 @@ struct PullState { } impl PullState { - fn new(element: &super::JsonGstParse, pad: &gst::Pad) -> Self { + fn new(imp: &JsonGstParse, pad: &gst::Pad) -> Self { Self { need_stream_start: true, - stream_id: pad.create_stream_id(element, Some("src")).to_string(), + stream_id: pad + .create_stream_id(&*imp.instance(), Some("src")) + .to_string(), offset: 0, duration: None, } @@ -124,7 +126,7 @@ impl State { Ok(Some(line)) } - fn create_events(&mut self, element: &super::JsonGstParse) -> Vec<gst::Event> { + fn create_events(&mut self, imp: &JsonGstParse) -> Vec<gst::Event> { let mut events = Vec::new(); if self.need_flush_stop { @@ -155,7 +157,7 @@ impl State { let caps = caps_builder.build(); events.push(gst::event::Caps::new(&caps)); - gst::info!(CAT, obj: element, "Caps changed to {:?}", &caps); + gst::info!(CAT, imp: imp, "Caps changed to {:?}", &caps); self.need_caps = false; } @@ -176,7 +178,6 @@ impl State { fn add_buffer_metadata( &mut self, - _element: &super::JsonGstParse, buffer: &mut gst::buffer::Buffer, pts: Option<gst::ClockTime>, duration: Option<gst::ClockTime>, @@ -205,15 +206,14 @@ pub struct JsonGstParse { impl JsonGstParse { fn handle_buffer( &self, - element: &super::JsonGstParse, buffer: Option<gst::Buffer>, ) -> Result<gst::FlowSuccess, gst::FlowError> { let mut state = self.state.lock().unwrap(); let drain = if let Some(buffer) = buffer { let buffer = buffer.into_mapped_buffer_readable().map_err(|_| { - gst::element_error!( - element, + gst::element_imp_error!( + self, gst::ResourceError::Read, ["Failed to map buffer readable"] ); @@ -238,7 +238,7 @@ impl JsonGstParse { })) => { gst::debug!( CAT, - obj: element, + imp: self, "Got buffer with timestamp {} and duration {}", pts.display(), duration.display(), @@ -246,7 +246,7 @@ impl JsonGstParse { if !seeking { let data = data.to_string(); - let mut events = state.create_events(element); + let mut events = state.create_events(self); let mut buffer = gst::Buffer::from_mut_slice(data.into_bytes()); @@ -260,7 +260,7 @@ impl JsonGstParse { } } - state.add_buffer_metadata(element, &mut buffer, pts, duration); + state.add_buffer_metadata(&mut buffer, pts, duration); let send_eos = buffer .pts() @@ -272,13 +272,13 @@ impl JsonGstParse { drop(state); for event in events { - gst::debug!(CAT, obj: element, "Pushing event {:?}", event); + gst::debug!(CAT, imp: self, "Pushing event {:?}", event); self.srcpad.push_event(event); } self.srcpad.push(buffer).map_err(|err| { if err != gst::FlowError::Flushing { - gst::error!(CAT, obj: element, "Pushing buffer returned {:?}", err); + gst::error!(CAT, imp: self, "Pushing buffer returned {:?}", err); } err })?; @@ -289,27 +289,27 @@ impl JsonGstParse { state = self.state.lock().unwrap(); } else { - state = self.handle_skipped_line(element, pts, state); + state = self.handle_skipped_line(pts, state); } } Ok(Some(Line::Header { format })) => { if state.format.is_none() { state.format = Some(format); } else { - gst::warning!(CAT, obj: element, "Ignoring format change",); + gst::warning!(CAT, imp: self, "Ignoring format change",); } } Err((line, err)) => { gst::error!( CAT, - obj: element, + imp: self, "Couldn't parse line '{:?}': {:?}", std::str::from_utf8(line), err ); - gst::element_error!( - element, + gst::element_imp_error!( + self, gst::StreamError::Decode, ["Couldn't parse line '{:?}': {:?}", line, err] ); @@ -318,7 +318,7 @@ impl JsonGstParse { } Ok(None) => { if drain && state.pull.is_some() { - eprintln!("Finished draining"); + gst::debug!(CAT, imp: self, "Finished draining"); break Err(gst::FlowError::Eos); } break Ok(gst::FlowSuccess::Ok); @@ -329,7 +329,6 @@ impl JsonGstParse { fn handle_skipped_line( &self, - element: &super::JsonGstParse, pts: impl Into<Option<gst::ClockTime>>, mut state: MutexGuard<State>, ) -> MutexGuard<State> { @@ -339,7 +338,7 @@ impl JsonGstParse { state.replay_last_line = true; state.need_flush_stop = true; - gst::debug!(CAT, obj: element, "Done seeking"); + gst::debug!(CAT, imp: self, "Done seeking"); } drop(state); @@ -347,11 +346,7 @@ impl JsonGstParse { self.state.lock().unwrap() } - fn sink_activate( - &self, - pad: &gst::Pad, - element: &super::JsonGstParse, - ) -> Result<(), gst::LoggableError> { + fn sink_activate(&self, pad: &gst::Pad) -> Result<(), gst::LoggableError> { let mode = { let mut query = gst::query::Scheduling::new(); let mut state = self.state.lock().unwrap(); @@ -366,7 +361,7 @@ impl JsonGstParse { { gst::debug!(CAT, obj: pad, "Activating in Pull mode"); - state.pull = Some(PullState::new(element, &self.srcpad)); + state.pull = Some(PullState::new(self, &self.srcpad)); gst::PadMode::Pull } else { @@ -379,22 +374,10 @@ impl JsonGstParse { Ok(()) } - fn start_task(&self, element: &super::JsonGstParse) -> Result<(), gst::LoggableError> { - let element_weak = element.downgrade(); - let pad_weak = self.sinkpad.downgrade(); + fn start_task(&self) -> Result<(), gst::LoggableError> { + let self_ = self.ref_counted(); let res = self.sinkpad.start_task(move || { - let element = match element_weak.upgrade() { - Some(element) => element, - None => { - if let Some(pad) = pad_weak.upgrade() { - pad.pause_task().unwrap(); - } - return; - } - }; - - let parse = element.imp(); - parse.loop_fn(&element); + self_.loop_fn(); }); if res.is_err() { return Err(gst::loggable_error!(CAT, "Failed to start pad task")); @@ -405,13 +388,12 @@ impl JsonGstParse { fn sink_activatemode( &self, _pad: &gst::Pad, - element: &super::JsonGstParse, mode: gst::PadMode, active: bool, ) -> Result<(), gst::LoggableError> { if mode == gst::PadMode::Pull { if active { - self.start_task(element)?; + self.start_task()?; } else { let _ = self.sinkpad.stop_task(); } @@ -420,11 +402,8 @@ impl JsonGstParse { Ok(()) } - fn scan_duration( - &self, - element: &super::JsonGstParse, - ) -> Result<Option<gst::ClockTime>, gst::LoggableError> { - gst::debug!(CAT, obj: element, "Scanning duration"); + fn scan_duration(&self) -> Result<Option<gst::ClockTime>, gst::LoggableError> { + gst::debug!(CAT, imp: self, "Scanning duration"); /* First let's query the bytes duration upstream */ let mut q = gst::query::Duration::new(gst::Format::Bytes); @@ -493,7 +472,7 @@ impl JsonGstParse { if last_pts.is_some() || offset == 0 { gst::debug!( CAT, - obj: element, + imp: self, "Duration scan done, last_pts: {:?}", last_pts ); @@ -502,14 +481,14 @@ impl JsonGstParse { } } - fn push_eos(&self, element: &super::JsonGstParse) { + fn push_eos(&self) { let mut state = self.state.lock().unwrap(); if state.seeking { state.need_flush_stop = true; } - let mut events = state.create_events(element); + let mut events = state.create_events(self); let mut eos_event = gst::event::Eos::builder(); if let Some(seek_seqnum) = state.seek_seqnum { @@ -522,12 +501,12 @@ impl JsonGstParse { drop(state); for event in events { - gst::debug!(CAT, obj: element, "Pushing event {:?}", event); + gst::debug!(CAT, imp: self, "Pushing event {:?}", event); self.srcpad.push_event(event); } } - fn loop_fn(&self, element: &super::JsonGstParse) { + fn loop_fn(&self) { let mut state = self.state.lock().unwrap(); let State { ref mut pull, .. } = *state; let mut pull = pull.as_mut().unwrap(); @@ -539,7 +518,7 @@ impl JsonGstParse { drop(state); if scan_duration { - match self.scan_duration(element) { + match self.scan_duration() { Ok(pts) => { let mut state = self.state.lock().unwrap(); let mut pull = state.pull.as_mut().unwrap(); @@ -548,8 +527,8 @@ impl JsonGstParse { Err(err) => { err.log(); - gst::element_error!( - element, + gst::element_imp_error!( + self, gst::StreamError::Decode, ["Failed to scan duration"] ); @@ -571,8 +550,8 @@ impl JsonGstParse { Err(flow) => { gst::error!(CAT, obj: &self.sinkpad, "Failed to pull, reason: {:?}", flow); - gst::element_error!( - element, + gst::element_imp_error!( + self, gst::StreamError::Failed, ["Streaming stopped, failed to pull buffer"] ); @@ -582,23 +561,23 @@ impl JsonGstParse { } }; - if let Err(flow) = self.handle_buffer(element, buffer) { + if let Err(flow) = self.handle_buffer(buffer) { match flow { gst::FlowError::Flushing => { - gst::debug!(CAT, obj: element, "Pausing after flow {:?}", flow); + gst::debug!(CAT, imp: self, "Pausing after flow {:?}", flow); } gst::FlowError::Eos => { - self.push_eos(element); + self.push_eos(); - gst::debug!(CAT, obj: element, "Pausing after flow {:?}", flow); + gst::debug!(CAT, imp: self, "Pausing after flow {:?}", flow); } _ => { - self.push_eos(element); + self.push_eos(); - gst::error!(CAT, obj: element, "Pausing after flow {:?}", flow); + gst::error!(CAT, imp: self, "Pausing after flow {:?}", flow); - gst::element_error!( - element, + gst::element_imp_error!( + self, gst::StreamError::Failed, ["Streaming stopped, reason: {:?}", flow] ); @@ -612,12 +591,11 @@ impl JsonGstParse { fn sink_chain( &self, pad: &gst::Pad, - element: &super::JsonGstParse, buffer: gst::Buffer, ) -> Result<gst::FlowSuccess, gst::FlowError> { gst::log!(CAT, obj: pad, "Handling buffer {:?}", buffer); - self.handle_buffer(element, Some(buffer)) + self.handle_buffer(Some(buffer)) } fn flush(&self, mut state: &mut State) { @@ -634,7 +612,7 @@ impl JsonGstParse { state.format = None; } - fn sink_event(&self, pad: &gst::Pad, element: &super::JsonGstParse, event: gst::Event) -> bool { + fn sink_event(&self, pad: &gst::Pad, event: gst::Event) -> bool { use gst::EventView; gst::log!(CAT, obj: pad, "Handling event {:?}", event); @@ -655,14 +633,14 @@ impl JsonGstParse { self.flush(&mut state); drop(state); - pad.event_default(Some(element), event) + pad.event_default(Some(&*self.instance()), event) } EventView::Eos(_) => { gst::log!(CAT, obj: pad, "Draining"); - if let Err(err) = self.handle_buffer(element, None) { + if let Err(err) = self.handle_buffer(None) { gst::error!(CAT, obj: pad, "Failed to drain parser: {:?}", err); } - pad.event_default(Some(element), event) + pad.event_default(Some(&*self.instance()), event) } _ => { if event.is_sticky() @@ -674,15 +652,15 @@ impl JsonGstParse { state.pending_events.push(event); true } else { - pad.event_default(Some(element), event) + pad.event_default(Some(&*self.instance()), event) } } } } - fn perform_seek(&self, event: &gst::event::Seek, element: &super::JsonGstParse) -> bool { + fn perform_seek(&self, event: &gst::event::Seek) -> bool { if self.state.lock().unwrap().pull.is_none() { - gst::error!(CAT, obj: element, "seeking is only supported in pull mode"); + gst::error!(CAT, imp: self, "seeking is only supported in pull mode"); return false; } @@ -691,7 +669,7 @@ impl JsonGstParse { let mut start: Option<gst::ClockTime> = match start.try_into() { Ok(start) => start, Err(_) => { - gst::error!(CAT, obj: element, "seek has invalid format"); + gst::error!(CAT, imp: self, "seek has invalid format"); return false; } }; @@ -699,18 +677,18 @@ impl JsonGstParse { let mut stop: Option<gst::ClockTime> = match stop.try_into() { Ok(stop) => stop, Err(_) => { - gst::error!(CAT, obj: element, "seek has invalid format"); + gst::error!(CAT, imp: self, "seek has invalid format"); return false; } }; if !flags.contains(gst::SeekFlags::FLUSH) { - gst::error!(CAT, obj: element, "only flushing seeks are supported"); + gst::error!(CAT, imp: self, "only flushing seeks are supported"); return false; } if start_type == gst::SeekType::End || stop_type == gst::SeekType::End { - gst::error!(CAT, obj: element, "Relative seeks are not supported"); + gst::error!(CAT, imp: self, "Relative seeks are not supported"); return false; } @@ -720,14 +698,14 @@ impl JsonGstParse { .seqnum(seek_seqnum) .build(); - gst::debug!(CAT, obj: element, "Sending event {:?} upstream", event); + gst::debug!(CAT, imp: self, "Sending event {:?} upstream", event); self.sinkpad.push_event(event); let event = gst::event::FlushStart::builder() .seqnum(seek_seqnum) .build(); - gst::debug!(CAT, obj: element, "Pushing event {:?}", event); + gst::debug!(CAT, imp: self, "Pushing event {:?}", event); self.srcpad.push_event(event); self.sinkpad.pause_task().unwrap(); @@ -755,7 +733,7 @@ impl JsonGstParse { /* Drop our state while we push a serialized event upstream */ drop(state); - gst::debug!(CAT, obj: element, "Sending event {:?} upstream", event); + gst::debug!(CAT, imp: self, "Sending event {:?} upstream", event); self.sinkpad.push_event(event); state = self.state.lock().unwrap(); @@ -764,7 +742,7 @@ impl JsonGstParse { .segment .do_seek(rate, flags, start_type, start, stop_type, stop); - match self.start_task(element) { + match self.start_task() { Err(error) => { error.log(); false @@ -773,22 +751,17 @@ impl JsonGstParse { } } - fn src_event(&self, pad: &gst::Pad, element: &super::JsonGstParse, event: gst::Event) -> bool { + fn src_event(&self, pad: &gst::Pad, event: gst::Event) -> bool { use gst::EventView; gst::log!(CAT, obj: pad, "Handling event {:?}", event); match event.view() { - EventView::Seek(e) => self.perform_seek(e, element), - _ => pad.event_default(Some(element), event), + EventView::Seek(e) => self.perform_seek(e), + _ => pad.event_default(Some(&*self.instance()), event), } } - fn src_query( - &self, - pad: &gst::Pad, - element: &super::JsonGstParse, - query: &mut gst::QueryRef, - ) -> bool { + fn src_query(&self, pad: &gst::Pad, query: &mut gst::QueryRef) -> bool { use gst::QueryViewMut; gst::log!(CAT, obj: pad, "Handling query {:?}", query); @@ -838,7 +811,7 @@ impl JsonGstParse { self.sinkpad.peer_query(query) } } - _ => pad.query_default(Some(element), query), + _ => pad.query_default(Some(&*self.instance()), query), } } } @@ -856,7 +829,7 @@ impl ObjectSubclass for JsonGstParse { JsonGstParse::catch_panic_pad_function( parent, || Err(gst::loggable_error!(CAT, "Panic activating sink pad")), - |parse, element| parse.sink_activate(pad, element), + |parse| parse.sink_activate(pad), ) }) .activatemode_function(|pad, parent, mode, active| { @@ -868,21 +841,21 @@ impl ObjectSubclass for JsonGstParse { "Panic activating sink pad with mode" )) }, - |parse, element| parse.sink_activatemode(pad, element, mode, active), + |parse| parse.sink_activatemode(pad, mode, active), ) }) .chain_function(|pad, parent, buffer| { JsonGstParse::catch_panic_pad_function( parent, || Err(gst::FlowError::Error), - |parse, element| parse.sink_chain(pad, element, buffer), + |parse| parse.sink_chain(pad, buffer), ) }) .event_function(|pad, parent, event| { JsonGstParse::catch_panic_pad_function( parent, || false, - |parse, element| parse.sink_event(pad, element, event), + |parse| parse.sink_event(pad, event), ) }) .build(); @@ -893,14 +866,14 @@ impl ObjectSubclass for JsonGstParse { JsonGstParse::catch_panic_pad_function( parent, || false, - |parse, element| parse.src_event(pad, element, event), + |parse| parse.src_event(pad, event), ) }) .query_function(|pad, parent, query| { JsonGstParse::catch_panic_pad_function( parent, || false, - |parse, element| parse.src_query(pad, element, query), + |parse| parse.src_query(pad, query), ) }) .build(); @@ -914,9 +887,10 @@ impl ObjectSubclass for JsonGstParse { } impl ObjectImpl for JsonGstParse { - fn constructed(&self, obj: &Self::Type) { - self.parent_constructed(obj); + fn constructed(&self) { + self.parent_constructed(); + let obj = self.instance(); obj.add_pad(&self.sinkpad).unwrap(); obj.add_pad(&self.srcpad).unwrap(); } @@ -966,10 +940,9 @@ impl ElementImpl for JsonGstParse { fn change_state( &self, - element: &Self::Type, transition: gst::StateChange, ) -> Result<gst::StateChangeSuccess, gst::StateChangeError> { - gst::trace!(CAT, obj: element, "Changing state {:?}", transition); + gst::trace!(CAT, imp: self, "Changing state {:?}", transition); match transition { gst::StateChange::ReadyToPaused | gst::StateChange::PausedToReady => { @@ -980,6 +953,6 @@ impl ElementImpl for JsonGstParse { _ => (), } - self.parent_change_state(element, transition) + self.parent_change_state(transition) } } diff --git a/text/regex/src/gstregex/imp.rs b/text/regex/src/gstregex/imp.rs index bfb8faa9e..be77ccf4c 100644 --- a/text/regex/src/gstregex/imp.rs +++ b/text/regex/src/gstregex/imp.rs @@ -49,20 +49,19 @@ impl RegEx { fn sink_chain( &self, _pad: &gst::Pad, - element: &super::RegEx, buffer: gst::Buffer, ) -> Result<gst::FlowSuccess, gst::FlowError> { let data = buffer.map_readable().map_err(|_| { - gst::error!(CAT, obj: element, "Can't map buffer readable"); - gst::element_error!(element, gst::CoreError::Failed, ["Failed to map buffer"]); + gst::error!(CAT, imp: self, "Can't map buffer readable"); + gst::element_imp_error!(self, gst::CoreError::Failed, ["Failed to map buffer"]); gst::FlowError::Error })?; let mut data = std::str::from_utf8(&data) .map_err(|err| { - gst::error!(CAT, obj: element, "Can't decode utf8: {}", err); - gst::element_error!( - element, + gst::error!(CAT, imp: self, "Can't decode utf8: {}", err); + gst::element_imp_error!( + self, gst::StreamError::Decode, ["Failed to decode utf8: {}", err] ); @@ -117,7 +116,7 @@ impl ObjectSubclass for RegEx { RegEx::catch_panic_pad_function( parent, || Err(gst::FlowError::Error), - |regex, element| regex.sink_chain(pad, element, buffer), + |regex| regex.sink_chain(pad, buffer), ) }) .flags(gst::PadFlags::PROXY_CAPS | gst::PadFlags::FIXED_CAPS) @@ -157,20 +156,15 @@ impl ObjectImpl for RegEx { PROPERTIES.as_ref() } - fn constructed(&self, obj: &Self::Type) { - self.parent_constructed(obj); + fn constructed(&self) { + self.parent_constructed(); + let obj = self.instance(); obj.add_pad(&self.sinkpad).unwrap(); obj.add_pad(&self.srcpad).unwrap(); } - fn set_property( - &self, - _obj: &Self::Type, - _id: usize, - value: &glib::Value, - pspec: &glib::ParamSpec, - ) { + fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) { match pspec.name() { "commands" => { let mut state = self.state.lock().unwrap(); @@ -191,7 +185,11 @@ impl ObjectImpl for RegEx { let pattern = match s.get::<Option<String>>("pattern") { Ok(Some(pattern)) => pattern, Ok(None) | Err(_) => { - gst::error!(CAT, "All commands require a pattern field as a string"); + gst::error!( + CAT, + imp: self, + "All commands require a pattern field as a string" + ); continue; } }; @@ -199,7 +197,7 @@ impl ObjectImpl for RegEx { let regex = match Regex::new(&pattern) { Ok(regex) => regex, Err(err) => { - gst::error!(CAT, "Failed to compile regex: {:?}", err); + gst::error!(CAT, imp: self, "Failed to compile regex: {:?}", err); continue; } }; @@ -211,6 +209,7 @@ impl ObjectImpl for RegEx { Ok(None) | Err(_) => { gst::error!( CAT, + imp: self, "Replace operations require a replacement field as a string" ); continue; @@ -223,7 +222,7 @@ impl ObjectImpl for RegEx { }); } val => { - gst::error!(CAT, "Unknown operation {}", val); + gst::error!(CAT, imp: self, "Unknown operation {}", val); } } } @@ -232,7 +231,7 @@ impl ObjectImpl for RegEx { } } - fn property(&self, _obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { + fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { match pspec.name() { "commands" => { let state = self.state.lock().unwrap(); diff --git a/text/wrap/src/gsttextwrap/imp.rs b/text/wrap/src/gsttextwrap/imp.rs index bbc32c5c9..7535520be 100644 --- a/text/wrap/src/gsttextwrap/imp.rs +++ b/text/wrap/src/gsttextwrap/imp.rs @@ -84,7 +84,7 @@ fn is_punctuation(word: &str) -> bool { } impl TextWrap { - fn update_wrapper(&self, element: &super::TextWrap) { + fn update_wrapper(&self) { let settings = self.settings.lock().unwrap(); let mut state = self.state.lock().unwrap(); @@ -97,7 +97,7 @@ impl TextWrap { if let Some(dictionary) = &settings.dictionary { let dict_file = match File::open(dictionary) { Err(err) => { - gst::error!(CAT, obj: element, "Failed to open dictionary file: {}", err); + gst::error!(CAT, imp: self, "Failed to open dictionary file: {}", err); return; } Ok(dict_file) => dict_file, @@ -106,12 +106,7 @@ impl TextWrap { let mut reader = io::BufReader::new(dict_file); let standard = match Standard::any_from_reader(&mut reader) { Err(err) => { - gst::error!( - CAT, - obj: element, - "Failed to load standard from file: {}", - err - ); + gst::error!(CAT, imp: self, "Failed to load standard from file: {}", err); return; } Ok(standard) => standard, @@ -128,28 +123,27 @@ impl TextWrap { fn sink_chain( &self, _pad: &gst::Pad, - element: &super::TextWrap, buffer: gst::Buffer, ) -> Result<gst::FlowSuccess, gst::FlowError> { - self.update_wrapper(element); + self.update_wrapper(); let mut pts = buffer.pts().ok_or_else(|| { - gst::error!(CAT, obj: element, "Need timestamped buffers"); + gst::error!(CAT, imp: self, "Need timestamped buffers"); gst::FlowError::Error })?; let duration = buffer.duration().ok_or_else(|| { - gst::error!(CAT, obj: element, "Need buffers with duration"); + gst::error!(CAT, imp: self, "Need buffers with duration"); gst::FlowError::Error })?; let data = buffer.map_readable().map_err(|_| { - gst::error!(CAT, obj: element, "Can't map buffer readable"); + gst::error!(CAT, imp: self, "Can't map buffer readable"); gst::FlowError::Error })?; let data = std::str::from_utf8(&data).map_err(|err| { - gst::error!(CAT, obj: element, "Can't decode utf8: {}", err); + gst::error!(CAT, imp: self, "Can't decode utf8: {}", err); gst::FlowError::Error })?; @@ -225,7 +219,7 @@ impl TextWrap { .join("\n"); gst::info!( CAT, - obj: element, + imp: self, "Outputting contents {}, ts: {}, duration: {}", contents.to_string(), state.start_ts.display(), @@ -318,7 +312,7 @@ impl TextWrap { } } - fn sink_event(&self, pad: &gst::Pad, element: &super::TextWrap, event: gst::Event) -> bool { + fn sink_event(&self, pad: &gst::Pad, event: gst::Event) -> bool { gst::log!(CAT, obj: pad, "Handling event {:?}", event); use gst::EventView; @@ -330,7 +324,7 @@ impl TextWrap { if state.start_ts.is_some() { true } else { - pad.event_default(Some(element), event) + pad.event_default(Some(&*self.instance()), event) } } EventView::FlushStart(_) => { @@ -339,7 +333,7 @@ impl TextWrap { *state = State::default(); state.options = options; drop(state); - pad.event_default(Some(element), event) + pad.event_default(Some(&*self.instance()), event) } EventView::Eos(_) => { let mut state = self.state.lock().unwrap(); @@ -363,18 +357,13 @@ impl TextWrap { } else { drop(state); } - pad.event_default(Some(element), event) + pad.event_default(Some(&*self.instance()), event) } - _ => pad.event_default(Some(element), event), + _ => pad.event_default(Some(&*self.instance()), event), } } - fn src_query( - &self, - pad: &gst::Pad, - element: &super::TextWrap, - query: &mut gst::QueryRef, - ) -> bool { + fn src_query(&self, pad: &gst::Pad, query: &mut gst::QueryRef) -> bool { use gst::QueryViewMut; gst::log!(CAT, obj: pad, "Handling query {:?}", query); @@ -390,7 +379,7 @@ impl TextWrap { let our_latency: gst::ClockTime = self.settings.lock().unwrap().accumulate_time; gst::info!( CAT, - obj: element, + imp: self, "Reporting our latency {} + {}", our_latency, min @@ -399,7 +388,7 @@ impl TextWrap { } ret } - _ => pad.query_default(Some(element), query), + _ => pad.query_default(Some(&*self.instance()), query), } } } @@ -417,14 +406,14 @@ impl ObjectSubclass for TextWrap { TextWrap::catch_panic_pad_function( parent, || Err(gst::FlowError::Error), - |textwrap, element| textwrap.sink_chain(pad, element, buffer), + |textwrap| textwrap.sink_chain(pad, buffer), ) }) .event_function(|pad, parent, event| { TextWrap::catch_panic_pad_function( parent, || false, - |textwrap, element| textwrap.sink_event(pad, element, event), + |textwrap| textwrap.sink_event(pad, event), ) }) .flags(gst::PadFlags::PROXY_CAPS | gst::PadFlags::FIXED_CAPS) @@ -436,7 +425,7 @@ impl ObjectSubclass for TextWrap { TextWrap::catch_panic_pad_function( parent, || false, - |textwrap, element| textwrap.src_query(pad, element, query), + |textwrap| textwrap.src_query(pad, query), ) }) .flags(gst::PadFlags::PROXY_CAPS | gst::PadFlags::FIXED_CAPS) @@ -491,20 +480,15 @@ impl ObjectImpl for TextWrap { PROPERTIES.as_ref() } - fn constructed(&self, obj: &Self::Type) { - self.parent_constructed(obj); + fn constructed(&self) { + self.parent_constructed(); + let obj = self.instance(); obj.add_pad(&self.sinkpad).unwrap(); obj.add_pad(&self.srcpad).unwrap(); } - fn set_property( - &self, - obj: &Self::Type, - _id: usize, - value: &glib::Value, - pspec: &glib::ParamSpec, - ) { + fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) { match pspec.name() { "dictionary" => { let mut settings = self.settings.lock().unwrap(); @@ -530,19 +514,23 @@ impl ObjectImpl for TextWrap { if settings.accumulate_time != old_accumulate_time { gst::debug!( CAT, - obj: obj, + imp: self, "Accumulate time changed: {}", settings.accumulate_time.display(), ); drop(settings); - let _ = obj.post_message(gst::message::Latency::builder().src(obj).build()); + let _ = self.instance().post_message( + gst::message::Latency::builder() + .src(&*self.instance()) + .build(), + ); } } _ => unimplemented!(), } } - fn property(&self, _obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { + fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { match pspec.name() { "dictionary" => { let settings = self.settings.lock().unwrap(); @@ -610,17 +598,16 @@ impl ElementImpl for TextWrap { fn change_state( &self, - element: &Self::Type, transition: gst::StateChange, ) -> Result<gst::StateChangeSuccess, gst::StateChangeError> { - gst::info!(CAT, obj: element, "Changing state {:?}", transition); + gst::info!(CAT, imp: self, "Changing state {:?}", transition); if let gst::StateChange::PausedToReady = transition { let mut state = self.state.lock().unwrap(); *state = State::default(); } - let success = self.parent_change_state(element, transition)?; + let success = self.parent_change_state(transition)?; Ok(success) } |