Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2022-10-09 16:06:59 +0300
committerSebastian Dröge <sebastian@centricular.com>2022-10-10 15:03:25 +0300
commit7ee4afacf413b2e3c386bb1070994ed4325994e6 (patch)
treeeddcc0e047ab4704e5a459dd551a55196e8a1848 /tutorial
parent7818ac658b02417fda071ce025b6d6a7fdb54a76 (diff)
Change *Impl trait methods to only take &self and not Self::Type in addition
Diffstat (limited to 'tutorial')
-rw-r--r--tutorial/src/identity/imp.rs39
-rw-r--r--tutorial/src/progressbin/imp.rs24
-rw-r--r--tutorial/src/rgb2gray/imp.rs18
-rw-r--r--tutorial/src/sinesrc/imp.rs129
-rw-r--r--tutorial/tutorial-1.md32
-rw-r--r--tutorial/tutorial-2.md92
6 files changed, 156 insertions, 178 deletions
diff --git a/tutorial/src/identity/imp.rs b/tutorial/src/identity/imp.rs
index e166a0d19..49e40ccb3 100644
--- a/tutorial/src/identity/imp.rs
+++ b/tutorial/src/identity/imp.rs
@@ -40,7 +40,6 @@ impl Identity {
fn sink_chain(
&self,
pad: &gst::Pad,
- _element: &super::Identity,
buffer: gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
gst::log!(CAT, obj: pad, "Handling buffer {:?}", buffer);
@@ -54,7 +53,7 @@ impl Identity {
//
// See the documentation of gst::Event and gst::EventRef to see what can be done with
// events, and especially the gst::EventView type for inspecting events.
- fn sink_event(&self, pad: &gst::Pad, _element: &super::Identity, event: gst::Event) -> bool {
+ fn sink_event(&self, pad: &gst::Pad, event: gst::Event) -> bool {
gst::log!(CAT, obj: pad, "Handling event {:?}", event);
self.srcpad.push_event(event)
}
@@ -68,12 +67,7 @@ impl Identity {
//
// See the documentation of gst::Query and gst::QueryRef to see what can be done with
// queries, and especially the gst::QueryView type for inspecting and modifying queries.
- fn sink_query(
- &self,
- pad: &gst::Pad,
- _element: &super::Identity,
- query: &mut gst::QueryRef,
- ) -> bool {
+ fn sink_query(&self, pad: &gst::Pad, query: &mut gst::QueryRef) -> bool {
gst::log!(CAT, obj: pad, "Handling query {:?}", query);
self.srcpad.peer_query(query)
}
@@ -86,7 +80,7 @@ impl Identity {
//
// See the documentation of gst::Event and gst::EventRef to see what can be done with
// events, and especially the gst::EventView type for inspecting events.
- fn src_event(&self, pad: &gst::Pad, _element: &super::Identity, event: gst::Event) -> bool {
+ fn src_event(&self, pad: &gst::Pad, event: gst::Event) -> bool {
gst::log!(CAT, obj: pad, "Handling event {:?}", event);
self.sinkpad.push_event(event)
}
@@ -100,12 +94,7 @@ impl Identity {
//
// See the documentation of gst::Query and gst::QueryRef to see what can be done with
// queries, and especially the gst::QueryView type for inspecting and modifying queries.
- fn src_query(
- &self,
- pad: &gst::Pad,
- _element: &super::Identity,
- query: &mut gst::QueryRef,
- ) -> bool {
+ fn src_query(&self, pad: &gst::Pad, query: &mut gst::QueryRef) -> bool {
gst::log!(CAT, obj: pad, "Handling query {:?}", query);
self.sinkpad.peer_query(query)
}
@@ -139,21 +128,21 @@ impl ObjectSubclass for Identity {
Identity::catch_panic_pad_function(
parent,
|| Err(gst::FlowError::Error),
- |identity, element| identity.sink_chain(pad, element, buffer),
+ |identity| identity.sink_chain(pad, buffer),
)
})
.event_function(|pad, parent, event| {
Identity::catch_panic_pad_function(
parent,
|| false,
- |identity, element| identity.sink_event(pad, element, event),
+ |identity| identity.sink_event(pad, event),
)
})
.query_function(|pad, parent, query| {
Identity::catch_panic_pad_function(
parent,
|| false,
- |identity, element| identity.sink_query(pad, element, query),
+ |identity| identity.sink_query(pad, query),
)
})
.build();
@@ -164,14 +153,14 @@ impl ObjectSubclass for Identity {
Identity::catch_panic_pad_function(
parent,
|| false,
- |identity, element| identity.src_event(pad, element, event),
+ |identity| identity.src_event(pad, event),
)
})
.query_function(|pad, parent, query| {
Identity::catch_panic_pad_function(
parent,
|| false,
- |identity, element| identity.src_query(pad, element, query),
+ |identity| identity.src_query(pad, query),
)
})
.build();
@@ -186,12 +175,13 @@ impl ObjectSubclass for Identity {
// Implementation of glib::Object virtual methods
impl ObjectImpl for Identity {
// Called right after construction of a new instance
- fn constructed(&self, obj: &Self::Type) {
+ fn constructed(&self) {
// Call the parent class' ::constructed() implementation first
- self.parent_constructed(obj);
+ self.parent_constructed();
// Here we actually add the pads we created in Identity::new() to the
// element so that GStreamer is aware of their existence.
+ let obj = self.instance();
obj.add_pad(&self.sinkpad).unwrap();
obj.add_pad(&self.srcpad).unwrap();
}
@@ -255,12 +245,11 @@ impl ElementImpl for Identity {
// the element again.
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);
// Call the parent class' implementation of ::change_state()
- self.parent_change_state(element, transition)
+ self.parent_change_state(transition)
}
}
diff --git a/tutorial/src/progressbin/imp.rs b/tutorial/src/progressbin/imp.rs
index d80e2a88e..3c35ac2bc 100644
--- a/tutorial/src/progressbin/imp.rs
+++ b/tutorial/src/progressbin/imp.rs
@@ -96,13 +96,7 @@ impl ObjectImpl for ProgressBin {
// Called whenever a value of a property is changed. It can be called
// at any time from any thread.
- 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() {
"output" => {
let mut output_type = self.output_type.lock().unwrap();
@@ -111,7 +105,7 @@ impl ObjectImpl for ProgressBin {
.expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing output from {:?} to {:?}",
output_type,
new_output_type
@@ -124,7 +118,7 @@ impl ObjectImpl for ProgressBin {
// Called whenever a value of a property is read. It can be called
// at any time from any thread.
- 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() {
"output" => {
let output_type = self.output_type.lock().unwrap();
@@ -135,13 +129,15 @@ impl ObjectImpl for ProgressBin {
}
// Called right after construction of a new instance
- fn constructed(&self, obj: &Self::Type) {
+ fn constructed(&self) {
// Call the parent class' ::constructed() implementation first
- self.parent_constructed(obj);
+ self.parent_constructed();
// Here we actually add the pads we created in ProgressBin::new() to the
// element so that GStreamer is aware of their existence.
+ let obj = self.instance();
+
// Add the progressreport element to the bin.
obj.add(&self.progress).unwrap();
@@ -215,7 +211,7 @@ impl ElementImpl for ProgressBin {
// Implementation of gst::Bin virtual methods
impl BinImpl for ProgressBin {
- fn handle_message(&self, bin: &Self::Type, msg: gst::Message) {
+ fn handle_message(&self, msg: gst::Message) {
use gst::MessageView;
match msg.view() {
@@ -236,12 +232,12 @@ impl BinImpl for ProgressBin {
match output_type {
ProgressBinOutput::Println => println!("progress: {:5.1}%", percent),
ProgressBinOutput::DebugCategory => {
- gst::info!(CAT, "progress: {:5.1}%", percent);
+ gst::info!(CAT, imp: self, "progress: {:5.1}%", percent);
}
};
}
}
- _ => self.parent_handle_message(bin, msg),
+ _ => self.parent_handle_message(msg),
}
}
}
diff --git a/tutorial/src/rgb2gray/imp.rs b/tutorial/src/rgb2gray/imp.rs
index 6d65a0968..5fef8ce51 100644
--- a/tutorial/src/rgb2gray/imp.rs
+++ b/tutorial/src/rgb2gray/imp.rs
@@ -119,20 +119,14 @@ impl ObjectImpl for Rgb2Gray {
// Called whenever a value of a property is changed. It can be called
// at any time from any thread.
- 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() {
"invert" => {
let mut settings = self.settings.lock().unwrap();
let invert = value.get().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing invert from {} to {}",
settings.invert,
invert
@@ -144,7 +138,7 @@ impl ObjectImpl for Rgb2Gray {
let shift = value.get().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing shift from {} to {}",
settings.shift,
shift
@@ -157,7 +151,7 @@ impl ObjectImpl for Rgb2Gray {
// Called whenever a value of a property is read. It can be called
// at any time from any thread.
- 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() {
"invert" => {
let settings = self.settings.lock().unwrap();
@@ -281,7 +275,6 @@ impl BaseTransformImpl for Rgb2Gray {
// In our case that means that:
fn transform_caps(
&self,
- element: &Self::Type,
direction: gst::PadDirection,
caps: &gst::Caps,
filter: Option<&gst::Caps>,
@@ -320,7 +313,7 @@ impl BaseTransformImpl for Rgb2Gray {
gst::debug!(
CAT,
- obj: element,
+ imp: self,
"Transformed caps from {} to {} in direction {:?}",
caps,
other_caps,
@@ -341,7 +334,6 @@ impl VideoFilterImpl for Rgb2Gray {
// Does the actual transformation of the input buffer to the output buffer
fn transform_frame(
&self,
- _element: &Self::Type,
in_frame: &gst_video::VideoFrameRef<&gst::BufferRef>,
out_frame: &mut gst_video::VideoFrameRef<&mut gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError> {
diff --git a/tutorial/src/sinesrc/imp.rs b/tutorial/src/sinesrc/imp.rs
index f74340441..d87025ce4 100644
--- a/tutorial/src/sinesrc/imp.rs
+++ b/tutorial/src/sinesrc/imp.rs
@@ -208,10 +208,11 @@ impl ObjectImpl for SineSrc {
}
// Called right after construction of a new instance
- fn constructed(&self, obj: &Self::Type) {
+ fn constructed(&self) {
// Call the parent class' ::constructed() implementation first
- self.parent_constructed(obj);
+ self.parent_constructed();
+ let obj = self.instance();
// Initialize live-ness and notify the base class that
// we'd like to operate in Time format
obj.set_live(DEFAULT_IS_LIVE);
@@ -220,20 +221,14 @@ impl ObjectImpl for SineSrc {
// Called whenever a value of a property is changed. It can be called
// at any time from any thread.
- 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() {
"samples-per-buffer" => {
let mut settings = self.settings.lock().unwrap();
let samples_per_buffer = value.get().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing samples-per-buffer from {} to {}",
settings.samples_per_buffer,
samples_per_buffer
@@ -241,14 +236,18 @@ impl ObjectImpl for SineSrc {
settings.samples_per_buffer = samples_per_buffer;
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(),
+ );
}
"freq" => {
let mut settings = self.settings.lock().unwrap();
let freq = value.get().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing freq from {} to {}",
settings.freq,
freq
@@ -260,7 +259,7 @@ impl ObjectImpl for SineSrc {
let volume = value.get().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing volume from {} to {}",
settings.volume,
volume
@@ -272,7 +271,7 @@ impl ObjectImpl for SineSrc {
let mute = value.get().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing mute from {} to {}",
settings.mute,
mute
@@ -284,7 +283,7 @@ impl ObjectImpl for SineSrc {
let is_live = value.get().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing is-live from {} to {}",
settings.is_live,
is_live
@@ -297,7 +296,7 @@ impl ObjectImpl for SineSrc {
// Called whenever a value of a property is read. It can be called
// at any time from any thread.
- 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() {
"samples-per-buffer" => {
let settings = self.settings.lock().unwrap();
@@ -386,16 +385,16 @@ impl ElementImpl for SineSrc {
// the element again.
fn change_state(
&self,
- element: &Self::Type,
transition: gst::StateChange,
) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
// Configure live'ness once here just before starting the source
if let gst::StateChange::ReadyToPaused = transition {
- element.set_live(self.settings.lock().unwrap().is_live);
+ self.instance()
+ .set_live(self.settings.lock().unwrap().is_live);
}
// Call the parent class' implementation of ::change_state()
- self.parent_change_state(element, transition)
+ self.parent_change_state(transition)
}
}
@@ -407,16 +406,17 @@ impl BaseSrcImpl for SineSrc {
//
// We simply remember the resulting AudioInfo from the caps to be able to use this for knowing
// the sample rate, etc. when creating buffers
- fn set_caps(&self, element: &Self::Type, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
+ fn set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
use std::f64::consts::PI;
let info = gst_audio::AudioInfo::from_caps(caps).map_err(|_| {
gst::loggable_error!(CAT, "Failed to build `AudioInfo` from caps {}", caps)
})?;
- gst::debug!(CAT, obj: element, "Configuring for caps {}", caps);
+ gst::debug!(CAT, imp: self, "Configuring for caps {}", caps);
- element.set_blocksize(info.bpf() * (*self.settings.lock().unwrap()).samples_per_buffer);
+ self.instance()
+ .set_blocksize(info.bpf() * (*self.settings.lock().unwrap()).samples_per_buffer);
let settings = *self.settings.lock().unwrap();
let mut state = self.state.lock().unwrap();
@@ -451,34 +451,38 @@ impl BaseSrcImpl for SineSrc {
drop(state);
- let _ = element.post_message(gst::message::Latency::builder().src(element).build());
+ let _ = self.instance().post_message(
+ gst::message::Latency::builder()
+ .src(&*self.instance())
+ .build(),
+ );
Ok(())
}
// Called when starting, so we can initialize all stream-related state to its defaults
- fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
+ fn start(&self) -> Result<(), gst::ErrorMessage> {
// Reset state
*self.state.lock().unwrap() = Default::default();
- self.unlock_stop(element)?;
+ self.unlock_stop()?;
- gst::info!(CAT, obj: element, "Started");
+ gst::info!(CAT, imp: self, "Started");
Ok(())
}
// Called when shutting down the element so we can release all stream-related state
- fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
+ fn stop(&self) -> Result<(), gst::ErrorMessage> {
// Reset state
*self.state.lock().unwrap() = Default::default();
- self.unlock(element)?;
+ self.unlock()?;
- gst::info!(CAT, obj: element, "Stopped");
+ gst::info!(CAT, imp: self, "Stopped");
Ok(())
}
- fn query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool {
+ fn query(&self, query: &mut gst::QueryRef) -> bool {
use gst::QueryViewMut;
match query.view_mut() {
@@ -493,18 +497,18 @@ impl BaseSrcImpl for SineSrc {
let latency = gst::ClockTime::SECOND
.mul_div_floor(settings.samples_per_buffer as u64, info.rate() as u64)
.unwrap();
- gst::debug!(CAT, obj: element, "Returning latency {}", latency);
+ gst::debug!(CAT, imp: self, "Returning latency {}", latency);
q.set(settings.is_live, latency, gst::ClockTime::NONE);
true
} else {
false
}
}
- _ => BaseSrcImplExt::parent_query(self, element, query),
+ _ => BaseSrcImplExt::parent_query(self, query),
}
}
- fn fixate(&self, element: &Self::Type, mut caps: gst::Caps) -> gst::Caps {
+ fn fixate(&self, mut caps: gst::Caps) -> gst::Caps {
// Fixate the caps. BaseSrc will do some fixation for us, but
// as we allow any rate between 1 and MAX it would fixate to 1. 1Hz
// is generally not a useful sample rate.
@@ -522,14 +526,14 @@ impl BaseSrcImpl for SineSrc {
// Let BaseSrc fixate anything else for us. We could've alternatively have
// called caps.fixate() here
- self.parent_fixate(element, caps)
+ self.parent_fixate(caps)
}
- fn is_seekable(&self, _element: &Self::Type) -> bool {
+ fn is_seekable(&self) -> bool {
true
}
- fn do_seek(&self, element: &Self::Type, segment: &mut gst::Segment) -> bool {
+ fn do_seek(&self, segment: &mut gst::Segment) -> bool {
// Handle seeking here. For Time and Default (sample offset) seeks we can
// do something and have to update our sample offset and accumulator accordingly.
//
@@ -538,7 +542,7 @@ impl BaseSrcImpl for SineSrc {
// and for calculating the timestamps, etc.
if segment.rate() < 0.0 {
- gst::error!(CAT, obj: element, "Reverse playback not supported");
+ gst::error!(CAT, imp: self, "Reverse playback not supported");
return false;
}
@@ -572,7 +576,7 @@ impl BaseSrcImpl for SineSrc {
gst::debug!(
CAT,
- obj: element,
+ imp: self,
"Seeked to {}-{:?} (accum: {}) for segment {:?}",
sample_offset,
sample_stop,
@@ -594,7 +598,7 @@ impl BaseSrcImpl for SineSrc {
if state.info.is_none() {
gst::error!(
CAT,
- obj: element,
+ imp: self,
"Can only seek in Default format if sample rate is known"
);
return false;
@@ -608,7 +612,7 @@ impl BaseSrcImpl for SineSrc {
gst::debug!(
CAT,
- obj: element,
+ imp: self,
"Seeked to {}-{:?} (accum: {}) for segment {:?}",
sample_offset,
sample_stop,
@@ -627,7 +631,7 @@ impl BaseSrcImpl for SineSrc {
} else {
gst::error!(
CAT,
- obj: element,
+ imp: self,
"Can't seek in format {:?}",
segment.format()
);
@@ -636,10 +640,10 @@ impl BaseSrcImpl for SineSrc {
}
}
- fn unlock(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
+ fn unlock(&self) -> Result<(), gst::ErrorMessage> {
// This should unblock the create() function ASAP, so we
// just unschedule the clock it here, if any.
- gst::debug!(CAT, obj: element, "Unlocking");
+ gst::debug!(CAT, imp: self, "Unlocking");
let mut clock_wait = self.clock_wait.lock().unwrap();
if let Some(clock_id) = clock_wait.clock_id.take() {
clock_id.unschedule();
@@ -649,10 +653,10 @@ impl BaseSrcImpl for SineSrc {
Ok(())
}
- fn unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
+ fn unlock_stop(&self) -> Result<(), gst::ErrorMessage> {
// This signals that unlocking is done, so we can reset
// all values again.
- gst::debug!(CAT, obj: element, "Unlock stop");
+ gst::debug!(CAT, imp: self, "Unlock stop");
let mut clock_wait = self.clock_wait.lock().unwrap();
clock_wait.flushing = false;
@@ -664,7 +668,6 @@ impl PushSrcImpl for SineSrc {
// Creates the audio buffers
fn create(
&self,
- element: &Self::Type,
_buffer: Option<&mut gst::BufferRef>,
) -> Result<CreateSuccess, gst::FlowError> {
// Keep a local copy of the values of all our properties at this very moment. This
@@ -676,7 +679,7 @@ impl PushSrcImpl for SineSrc {
let mut state = self.state.lock().unwrap();
let info = match state.info {
None => {
- gst::element_error!(element, gst::CoreError::Negotiation, ["Have no caps yet"]);
+ gst::element_imp_error!(self, gst::CoreError::Negotiation, ["Have no caps yet"]);
return Err(gst::FlowError::NotNegotiated);
}
Some(ref info) => info.clone(),
@@ -686,7 +689,7 @@ impl PushSrcImpl for SineSrc {
// point but at most samples_per_buffer samples per buffer
let n_samples = if let Some(sample_stop) = state.sample_stop {
if sample_stop <= state.sample_offset {
- gst::log!(CAT, obj: element, "At EOS");
+ gst::log!(CAT, imp: self, "At EOS");
return Err(gst::FlowError::Eos);
}
@@ -754,14 +757,18 @@ impl PushSrcImpl for SineSrc {
// Waiting happens based on the pipeline clock, which means that a real live source
// with its own clock would require various translations between the two clocks.
// This is out of scope for the tutorial though.
- if element.is_live() {
- let clock = match element.clock() {
- None => return Ok(CreateSuccess::NewBuffer(buffer)),
- Some(clock) => clock,
- };
-
- let segment = element.segment().downcast::<gst::format::Time>().unwrap();
- let base_time = element.base_time();
+ if self.instance().is_live() {
+ let (clock, base_time) =
+ match Option::zip(self.instance().clock(), self.instance().base_time()) {
+ None => return Ok(CreateSuccess::NewBuffer(buffer)),
+ Some(res) => res,
+ };
+
+ let segment = self
+ .instance()
+ .segment()
+ .downcast::<gst::format::Time>()
+ .unwrap();
let running_time = segment.to_running_time(buffer.pts().opt_add(buffer.duration()));
// The last sample's clock time is the base time of the element plus the
@@ -776,7 +783,7 @@ impl PushSrcImpl for SineSrc {
// so that we immediately stop waiting on e.g. shutdown.
let mut clock_wait = self.clock_wait.lock().unwrap();
if clock_wait.flushing {
- gst::debug!(CAT, obj: element, "Flushing");
+ gst::debug!(CAT, imp: self, "Flushing");
return Err(gst::FlowError::Flushing);
}
@@ -786,24 +793,24 @@ impl PushSrcImpl for SineSrc {
gst::log!(
CAT,
- obj: element,
+ imp: self,
"Waiting until {}, now {}",
wait_until,
clock.time().display(),
);
let (res, jitter) = id.wait();
- gst::log!(CAT, obj: element, "Waited res {:?} jitter {}", res, jitter);
+ gst::log!(CAT, imp: self, "Waited res {:?} jitter {}", res, jitter);
self.clock_wait.lock().unwrap().clock_id.take();
// If the clock ID was unscheduled, unlock() was called
// and we should return Flushing immediately.
if res == Err(gst::ClockError::Unscheduled) {
- gst::debug!(CAT, obj: element, "Flushing");
+ gst::debug!(CAT, imp: self, "Flushing");
return Err(gst::FlowError::Flushing);
}
}
- gst::debug!(CAT, obj: element, "Produced buffer {:?}", buffer);
+ gst::debug!(CAT, imp: self, "Produced buffer {:?}", buffer);
Ok(CreateSuccess::NewBuffer(buffer))
}
diff --git a/tutorial/tutorial-1.md b/tutorial/tutorial-1.md
index 275489095..8923ee31a 100644
--- a/tutorial/tutorial-1.md
+++ b/tutorial/tutorial-1.md
@@ -416,7 +416,6 @@ Whenever input/output caps are configured on our element, the `set_caps` virtual
impl BaseTransformImpl for Rgb2Gray {
fn set_caps(
&self,
- element: &Self::Type,
incaps: &gst::Caps,
outcaps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
@@ -431,7 +430,7 @@ impl BaseTransformImpl for Rgb2Gray {
gst::debug!(
CAT,
- obj: element,
+ imp: self,
"Configured for caps {} to {}",
incaps,
outcaps
@@ -442,11 +441,11 @@ impl BaseTransformImpl for Rgb2Gray {
Ok(())
}
- fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
+ fn stop(&self) -> Result<(), gst::ErrorMessage> {
// Drop state
let _ = self.state.lock().unwrap().take();
- gst::info!(CAT, obj: element, "Stopped");
+ gst::info!(CAT, imp: self, "Stopped");
Ok(())
}
@@ -459,7 +458,7 @@ Next we have to provide information to the `BaseTransform` base class about the
```rust
impl BaseTransformImpl for Rgb2Gray {
- fn get_unit_size(&self, _element: &Self::Type, caps: &gst::Caps) -> Option<usize> {
+ fn get_unit_size(&self, caps: &gst::Caps) -> Option<usize> {
gst_video::VideoInfo::from_caps(caps).map(|info| info.size())
}
}
@@ -479,7 +478,6 @@ This has to be implemented in the `transform_caps` virtual method, and looks as
impl BaseTransformImpl for Rgb2Gray {
fn transform_caps(
&self,
- element: &Self::Type,
direction: gst::PadDirection,
caps: &gst::Caps,
filter: Option<&gst::Caps>,
@@ -511,7 +509,7 @@ impl BaseTransformImpl for Rgb2Gray {
gst::debug!(
CAT,
- obj: element,
+ imp: self,
"Transformed caps from {} to {} in direction {:?}",
caps,
other_caps,
@@ -569,21 +567,20 @@ Afterwards we have to actually call this function on every pixel. For this the t
impl BaseTransformImpl for Rgb2Gray {
fn transform(
&self,
- element: &Self::Type,
inbuf: &gst::Buffer,
outbuf: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
let mut state_guard = self.state.lock().unwrap();
let state = state_guard.as_mut().ok_or_else(|| {
- gst::element_error!(element, gst::CoreError::Negotiation, ["Have no state yet"]);
+ gst::element_imp_error!(self, gst::CoreError::Negotiation, ["Have no state yet"]);
gst::FlowError::NotNegotiated
})?;
let in_frame =
gst_video::VideoFrameRef::from_buffer_ref_readable(inbuf.as_ref(), &state.in_info)
.ok_or_else(|| {
- gst::element_error!(
- element,
+ gst::element_imp_error!(
+ self,
gst::CoreError::Failed,
["Failed to map input buffer readable"]
);
@@ -593,8 +590,8 @@ impl BaseTransformImpl for Rgb2Gray {
let mut out_frame =
gst_video::VideoFrameRef::from_buffer_ref_writable(outbuf, &state.out_info)
.ok_or_else(|| {
- gst::element_error!(
- element,
+ gst::element_imp_error!(
+ self,
gst::CoreError::Failed,
["Failed to map output buffer writable"]
);
@@ -761,14 +758,14 @@ In the next step we have to implement functions that are called whenever a prope
impl ObjectImpl for Rgb2Gray {
[...]
- 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.get_name() {
"invert" => {
let mut settings = self.settings.lock().unwrap();
let invert = value.get_some().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing invert from {} to {}",
settings.invert,
invert
@@ -780,7 +777,7 @@ impl ObjectImpl for Rgb2Gray {
let shift = value.get_some().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing shift from {} to {}",
settings.shift,
shift
@@ -791,7 +788,7 @@ impl ObjectImpl for Rgb2Gray {
}
}
- fn get_property(&self, _obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
+ fn get_property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
match pspec.get_name() {
"invert" => {
let settings = self.settings.lock().unwrap();
@@ -840,7 +837,6 @@ impl Rgb2Gray {
impl BaseTransformImpl for Rgb2Gray {
fn transform(
&self,
- element: &Self::Type,
inbuf: &gst::Buffer,
outbuf: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
diff --git a/tutorial/tutorial-2.md b/tutorial/tutorial-2.md
index accec1ef5..75509ac50 100644
--- a/tutorial/tutorial-2.md
+++ b/tutorial/tutorial-2.md
@@ -208,12 +208,13 @@ impl ObjectImpl for SineSrc {
}
// Called right after construction of a new instance
- fn constructed(&self, obj: &Self::Type) {
+ fn constructed(&self) {
// Call the parent class' ::constructed() implementation first
- self.parent_constructed(obj);
+ self.parent_constructed();
// Initialize live-ness and notify the base class that
// we'd like to operate in Time format
+ let obj = self.instance();
obj.set_live(DEFAULT_IS_LIVE);
obj.set_format(gst::Format::Time);
}
@@ -222,7 +223,6 @@ impl ObjectImpl for SineSrc {
// at any time from any thread.
fn set_property(
&self,
- obj: &Self::Type,
_id: usize,
value: &glib::Value,
pspec: &glib::ParamSpec,
@@ -233,7 +233,7 @@ impl ObjectImpl for SineSrc {
let samples_per_buffer = value.get_some().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing samples-per-buffer from {} to {}",
settings.samples_per_buffer,
samples_per_buffer
@@ -241,14 +241,14 @@ impl ObjectImpl for SineSrc {
settings.samples_per_buffer = samples_per_buffer;
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());
}
"freq" => {
let mut settings = self.settings.lock().unwrap();
let freq = value.get_some().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing freq from {} to {}",
settings.freq,
freq
@@ -260,7 +260,7 @@ impl ObjectImpl for SineSrc {
let volume = value.get_some().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing volume from {} to {}",
settings.volume,
volume
@@ -272,7 +272,7 @@ impl ObjectImpl for SineSrc {
let mute = value.get_some().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing mute from {} to {}",
settings.mute,
mute
@@ -284,7 +284,7 @@ impl ObjectImpl for SineSrc {
let is_live = value.get_some().expect("type checked upstream");
gst::info!(
CAT,
- obj: obj,
+ imp: self,
"Changing is-live from {} to {}",
settings.is_live,
is_live
@@ -297,7 +297,7 @@ impl ObjectImpl for SineSrc {
// Called whenever a value of a property is read. It can be called
// at any time from any thread.
- fn get_property(&self, _obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
+ fn get_property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
match pspec.get_name() {
"samples-per-buffer" => {
let settings = self.settings.lock().unwrap();
@@ -329,21 +329,21 @@ impl ElementImpl for SineSrc { }
impl BaseSrcImpl for SineSrc {
// Called when starting, so we can initialize all stream-related state to its defaults
- fn start(&self, element: &Self::Type) -> bool {
+ fn start(&self) -> bool {
// Reset state
*self.state.lock().unwrap() = Default::default();
- gst::info!(CAT, obj: element, "Started");
+ gst::info!(CAT, imp: self, "Started");
true
}
// Called when shutting down the element so we can release all stream-related state
- fn stop(&self, element: &Self::Type) -> bool {
+ fn stop(&self) -> bool {
// Reset state
*self.state.lock().unwrap() = Default::default();
- gst::info!(CAT, obj: element, "Stopped");
+ gst::info!(CAT, imp: self, "Stopped");
true
}
@@ -400,16 +400,16 @@ The first part that we have to implement, just like last time, is caps negotiati
First of all, we need to get notified whenever the caps that our source is configured for are changing. This will happen once in the very beginning and then whenever the pipeline topology or state changes and new caps would be more optimal for the new situation. This notification happens via the `BaseTransform::set_caps` virtual method.
```rust
- fn set_caps(&self, element: &Self::Type, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
+ fn set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
use std::f64::consts::PI;
let info = gst_audio::AudioInfo::from_caps(caps).map_err(|_| {
gst::loggable_error!(CAT, "Failed to build `AudioInfo` from caps {}", caps)
})?;
- gst::debug!(CAT, obj: element, "Configuring for caps {}", caps);
+ gst::debug!(CAT, imp: self, "Configuring for caps {}", caps);
- element.set_blocksize(info.bpf() * (*self.settings.lock().unwrap()).samples_per_buffer);
+ self.instance().set_blocksize(info.bpf() * (*self.settings.lock().unwrap()).samples_per_buffer);
let settings = *self.settings.lock().unwrap();
let mut state = self.state.lock().unwrap();
@@ -444,7 +444,7 @@ First of all, we need to get notified whenever the caps that our source is confi
drop(state);
- let _ = element.post_message(&gst::Message::new_latency().src(Some(element)).build());
+ let _ = self.instance().post_message(&gst::Message::new_latency().src(Some(&*self.instance())).build());
Ok(())
}
@@ -459,7 +459,7 @@ As a last step we post a new `LATENCY` message on the bus whenever the sample
`BaseSrc` is by default already selecting possible caps for us, if there are multiple options. However these defaults might not be (and often are not) ideal and we should override the default behaviour slightly. This is done in the `BaseSrc::fixate` virtual method.
```rust
- fn fixate(&self, element: &Self::Type, mut caps: gst::Caps) -> gst::Caps {
+ fn fixate(&self, mut caps: gst::Caps) -> gst::Caps {
// Fixate the caps. BaseSrc will do some fixation for us, but
// as we allow any rate between 1 and MAX it would fixate to 1. 1Hz
// is generally not a useful sample rate.
@@ -477,7 +477,7 @@ As a last step we post a new `LATENCY` message on the bus whenever the sample
// Let BaseSrc fixate anything else for us. We could've alternatively have
// called caps.fixate() here
- element.parent_fixate(caps)
+ self.parent_fixate(caps)
}
```
@@ -551,7 +551,6 @@ Now that this is done, we need to implement the `PushSrc::create` virtual meth
```rust
fn create(
&self,
- element: &Self::Type,
) -> Result<gst::Buffer, gst::FlowReturn> {
// Keep a local copy of the values of all our properties at this very moment. This
// ensures that the mutex is never locked for long and the application wouldn't
@@ -562,7 +561,7 @@ Now that this is done, we need to implement the `PushSrc::create` virtual meth
let mut state = self.state.lock().unwrap();
let info = match state.info {
None => {
- gst::element_error!(element, gst::CoreError::Negotiation, ["Have no caps yet"]);
+ gst::element_imp_error!(self, gst::CoreError::Negotiation, ["Have no caps yet"]);
return Err(gst::FlowReturn::NotNegotiated);
}
Some(ref info) => info.clone(),
@@ -572,7 +571,7 @@ Now that this is done, we need to implement the `PushSrc::create` virtual meth
// point but at most samples_per_buffer samples per buffer
let n_samples = if let Some(sample_stop) = state.sample_stop {
if sample_stop <= state.sample_offset {
- gst::log!(CAT, obj: element, "At EOS");
+ gst::log!(CAT, imp: self, "At EOS");
return Err(gst::FlowReturn::Eos);
}
@@ -631,7 +630,7 @@ Now that this is done, we need to implement the `PushSrc::create` virtual meth
state.sample_offset += n_samples;
drop(state);
- gst::debug!(CAT, obj: element, "Produced buffer {:?}", buffer);
+ gst::debug!(CAT, imp: self, "Produced buffer {:?}", buffer);
Ok(buffer)
}
@@ -700,7 +699,7 @@ For working in live mode, we have to add a few different parts in various places
gst::log!(
CAT,
- obj: element,
+ imp: self,
"Waiting until {}, now {}",
wait_until,
clock.get_time().display(),
@@ -708,14 +707,14 @@ For working in live mode, we have to add a few different parts in various places
let (res, jitter) = id.wait();
gst::log!(
CAT,
- obj: element,
+ imp: self,
"Waited res {:?} jitter {}",
res,
jitter
);
}
- gst::debug!(CAT, obj: element, "Produced buffer {:?}", buffer);
+ gst::debug!(CAT, imp: self, "Produced buffer {:?}", buffer);
Ok(buffer)
}
@@ -733,7 +732,6 @@ Now we also have to tell the base class that we're running in live mode now. Thi
impl ElementImpl for SineSrc {
fn change_state(
&self,
- element: &Self::Type,
transition: gst::StateChange,
) -> gst::StateChangeReturn {
// Configure live'ness once here just before starting the source
@@ -744,7 +742,7 @@ impl ElementImpl for SineSrc {
_ => (),
}
- element.parent_change_state(transition)
+ self.parent_change_state(transition)
}
}
```
@@ -754,7 +752,7 @@ And as a last step, we also need to notify downstream elements about our [laten
This querying is done with the `LATENCY` query, which we will have to handle in the `BaseSrc::query()` function.
```rust
- fn query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool {
+ fn query(&self, query: &mut gst::QueryRef) -> bool {
use gst::QueryViewMut;
match query.view_mut() {
@@ -769,14 +767,14 @@ This querying is done with the `LATENCY` query, which we will have to handle i
let latency = gst::ClockTime::SECOND
.mul_div_floor(settings.samples_per_buffer as u64, info.rate() as u64)
.unwrap();
- gst::debug!(CAT, obj: element, "Returning latency {}", latency);
+ gst::debug!(CAT, imp: self, "Returning latency {}", latency);
q.set(settings.is_live, latency, gst::ClockTime::NONE);
true
} else {
false
}
}
- _ => BaseSrcImplExt::parent_query(self, element, query),
+ _ => BaseSrcImplExt::parent_query(self, query),
}
}
@@ -820,10 +818,10 @@ struct SineSrc {
[...]
- fn unlock(&self, element: &Self::Type) -> bool {
+ fn unlock(&self) -> bool {
// This should unblock the create() function ASAP, so we
// just unschedule the clock it here, if any.
- gst::debug!(CAT, obj: element, "Unlocking");
+ gst::debug!(CAT, imp: self, "Unlocking");
let mut clock_wait = self.clock_wait.lock().unwrap();
if let Some(clock_id) = clock_wait.clock_id.take() {
clock_id.unschedule();
@@ -839,10 +837,10 @@ We store the clock ID in our struct, together with a boolean to signal whether w
Once everything is unlocked, we need to reset things again so that data flow can happen in the future. This is done in the `unlock_stop` virtual method.
```rust
- fn unlock_stop(&self, element: &Self::Type) -> bool {
+ fn unlock_stop(&self) -> bool {
// This signals that unlocking is done, so we can reset
// all values again.
- gst::debug!(CAT, obj: element, "Unlock stop");
+ gst::debug!(CAT, imp: self, "Unlock stop");
let mut clock_wait = self.clock_wait.lock().unwrap();
clock_wait.flushing = false;
@@ -860,7 +858,7 @@ Now as a last step, we need to actually make use of the new struct we added arou
// so that we immediately stop waiting on e.g. shutdown.
let mut clock_wait = self.clock_wait.lock().unwrap();
if clock_wait.flushing {
- gst::debug!(CAT, obj: element, "Flushing");
+ gst::debug!(CAT, imp: self, "Flushing");
return Err(gst::FlowReturn::Flushing);
}
@@ -870,7 +868,7 @@ Now as a last step, we need to actually make use of the new struct we added arou
gst::log!(
CAT,
- obj: element,
+ imp: self,
"Waiting until {}, now {}",
wait_until,
clock.get_time().display(),
@@ -878,7 +876,7 @@ Now as a last step, we need to actually make use of the new struct we added arou
let (res, jitter) = id.wait();
gst::log!(
CAT,
- obj: element,
+ imp: self,
"Waited res {:?} jitter {}",
res,
jitter
@@ -888,7 +886,7 @@ Now as a last step, we need to actually make use of the new struct we added arou
// If the clock ID was unscheduled, unlock() was called
// and we should return Flushing immediately.
if res == gst::ClockReturn::Unscheduled {
- gst::debug!(CAT, obj: element, "Flushing");
+ gst::debug!(CAT, imp: self, "Flushing");
return Err(gst::FlowReturn::Flushing);
}
```
@@ -904,11 +902,11 @@ As a last feature we implement seeking on our source element. In our case that o
Seeking is implemented in the `BaseSrc::do_seek` virtual method, and signalling whether we can actually seek in the `is_seekable` virtual method.
```rust
- fn is_seekable(&self, _element: &Self::Type) -> bool {
+ fn is_seekable(&self) -> bool {
true
}
- fn do_seek(&self, element: &Self::Type, segment: &mut gst::Segment) -> bool {
+ fn do_seek(&self, segment: &mut gst::Segment) -> bool {
// Handle seeking here. For Time and Default (sample offset) seeks we can
// do something and have to update our sample offset and accumulator accordingly.
//
@@ -917,7 +915,7 @@ Seeking is implemented in the `BaseSrc::do_seek` virtual method, and signallin
// and for calculating the timestamps, etc.
if segment.get_rate() < 0.0 {
- gst::error!(CAT, obj: element, "Reverse playback not supported");
+ gst::error!(CAT, imp: self, "Reverse playback not supported");
return false;
}
@@ -950,7 +948,7 @@ Seeking is implemented in the `BaseSrc::do_seek` virtual method, and signallin
gst::debug!(
CAT,
- obj: element,
+ imp: self,
"Seeked to {}-{:?} (accum: {}) for segment {:?}",
sample_offset,
sample_stop,
@@ -972,7 +970,7 @@ Seeking is implemented in the `BaseSrc::do_seek` virtual method, and signallin
if state.info.is_none() {
gst::error!(
CAT,
- obj: element,
+ imp: self,
"Can only seek in Default format if sample rate is known"
);
return false;
@@ -986,7 +984,7 @@ Seeking is implemented in the `BaseSrc::do_seek` virtual method, and signallin
gst::debug!(
CAT,
- obj: element,
+ imp: self,
"Seeked to {}-{:?} (accum: {}) for segment {:?}",
sample_offset,
sample_stop,
@@ -1005,7 +1003,7 @@ Seeking is implemented in the `BaseSrc::do_seek` virtual method, and signallin
} else {
gst::error!(
CAT,
- obj: element,
+ imp: self,
"Can't seek in format {:?}",
segment.get_format()
);