Update various object construction functions to more efficient approaches

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1196>
This commit is contained in:
Sebastian Dröge 2023-01-22 09:48:51 +02:00
parent 38dd1f462b
commit d5e24b9fbd
15 changed files with 304 additions and 392 deletions

View file

@ -400,7 +400,7 @@ mod cairo_compositor {
impl CairoCompositor {
// Creates a new instance of our compositor with the given name.
pub fn new(name: Option<&str>) -> Self {
glib::Object::new(&[("name", &name)])
glib::Object::builder().property("name", name).build()
}
}

View file

@ -54,7 +54,7 @@ mod mirror {
impl GLMirrorFilter {
pub fn new(name: Option<&str>) -> Self {
glib::Object::new(&[("name", &name)])
glib::Object::builder().property("name", name).build()
}
}

View file

@ -154,7 +154,7 @@ mod media_factory {
impl Default for Factory {
// Creates a new instance of our factory
fn default() -> Factory {
glib::Object::new(&[])
glib::Object::new_default()
}
}
}
@ -266,7 +266,7 @@ mod server {
impl Default for Server {
// Creates a new instance of our factory
fn default() -> Server {
glib::Object::new(&[])
glib::Object::new_default()
}
}
}
@ -315,7 +315,7 @@ mod client {
impl Default for Client {
// Creates a new instance of our factory
fn default() -> Client {
glib::Object::new(&[])
glib::Object::new_default()
}
}
}
@ -359,7 +359,7 @@ mod mount_points {
impl Default for MountPoints {
// Creates a new instance of our factory
fn default() -> Self {
glib::Object::new(&[])
glib::Object::new_default()
}
}
}

View file

@ -216,7 +216,7 @@ mod fir_filter {
impl FirFilter {
// Creates a new instance of our filter with the given name
pub fn new(name: Option<&str>) -> FirFilter {
glib::Object::new(&[("name", &name)])
glib::Object::builder().property("name", name).build()
}
// Sets the coefficients by getting access to the private

View file

@ -277,7 +277,7 @@ impl AppSink {
/// This method returns an instance of [`AppSinkBuilder`](crate::builders::AppSinkBuilder) which can be used to create [`AppSink`] objects.
pub fn builder() -> AppSinkBuilder {
assert_initialized_main_thread!();
AppSinkBuilder::default()
AppSinkBuilder::new()
}
#[doc(alias = "gst_app_sink_set_callbacks")]
@ -931,100 +931,31 @@ impl AppSink {
}
}
#[derive(Default)]
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`AppSink`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct AppSinkBuilder {
async_: Option<bool>,
buffer_list: Option<bool>,
builder: glib::object::ObjectBuilder<'static, AppSink>,
callbacks: Option<AppSinkCallbacks>,
caps: Option<gst::Caps>,
drop: Option<bool>,
drop_out_of_segment: Option<bool>,
enable_last_sample: Option<bool>,
max_bitrate: Option<u64>,
max_buffers: Option<u32>,
max_lateness: Option<i64>,
#[cfg(any(feature = "v1_16", feature = "dox"))]
processing_deadline: Option<i64>,
qos: Option<bool>,
render_delay: Option<Option<gst::ClockTime>>,
sync: Option<bool>,
throttle_time: Option<u64>,
ts_offset: Option<gst::ClockTimeDiff>,
wait_on_eos: Option<bool>,
name: Option<String>,
}
impl AppSinkBuilder {
// rustdoc-stripper-ignore-next
/// Create a new [`AppSinkBuilder`].
pub fn new() -> Self {
Self::default()
fn new() -> Self {
Self {
builder: glib::Object::builder(),
callbacks: None,
drop_out_of_segment: None,
}
}
// rustdoc-stripper-ignore-next
/// Build the [`AppSink`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> AppSink {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
if let Some(ref async_) = self.async_ {
properties.push(("async", async_));
}
if let Some(ref buffer_list) = self.buffer_list {
properties.push(("buffer-list", buffer_list));
}
if let Some(ref caps) = self.caps {
properties.push(("caps", caps));
}
if let Some(ref drop) = self.drop {
properties.push(("drop", drop));
}
if let Some(ref enable_last_sample) = self.enable_last_sample {
properties.push(("enable-last-sample", enable_last_sample));
}
if let Some(ref max_bitrate) = self.max_bitrate {
properties.push(("max-bitrate", max_bitrate));
}
if let Some(ref max_buffers) = self.max_buffers {
properties.push(("max-buffers", max_buffers));
}
if let Some(ref max_lateness) = self.max_lateness {
properties.push(("max-lateness", max_lateness));
}
#[cfg(any(feature = "v1_16", feature = "dox"))]
if let Some(ref processing_deadline) = self.processing_deadline {
properties.push(("processing-deadline", processing_deadline));
}
if let Some(ref qos) = self.qos {
properties.push(("qos", qos));
}
if let Some(ref render_delay) = self.render_delay {
properties.push(("render-delay", render_delay));
}
if let Some(ref sync) = self.sync {
properties.push(("sync", sync));
}
if let Some(ref throttle_time) = self.throttle_time {
properties.push(("throttle-time", throttle_time));
}
if let Some(ref ts_offset) = self.ts_offset {
properties.push(("ts-offset", ts_offset));
}
if let Some(ref qos) = self.qos {
properties.push(("qos", qos));
}
if let Some(ref wait_on_eos) = self.wait_on_eos {
properties.push(("wait-on-eos", wait_on_eos));
}
if let Some(ref name) = self.name {
properties.push(("name", name));
}
let appsink = glib::Object::new::<AppSink>(&properties);
let appsink = self.builder.build();
if let Some(callbacks) = self.callbacks {
appsink.set_callbacks(callbacks);
@ -1037,96 +968,138 @@ impl AppSinkBuilder {
appsink
}
pub fn async_(mut self, async_: bool) -> Self {
self.async_ = Some(async_);
self
pub fn async_(self, async_: bool) -> Self {
Self {
builder: self.builder.property("async", async_),
..self
}
}
pub fn buffer_list(mut self, buffer_list: bool) -> Self {
self.buffer_list = Some(buffer_list);
self
pub fn buffer_list(self, buffer_list: bool) -> Self {
Self {
builder: self.builder.property("buffer-list", buffer_list),
..self
}
}
pub fn callbacks(mut self, callbacks: AppSinkCallbacks) -> Self {
self.callbacks = Some(callbacks);
self
pub fn callbacks(self, callbacks: AppSinkCallbacks) -> Self {
Self {
callbacks: Some(callbacks),
..self
}
}
pub fn caps(mut self, caps: &gst::Caps) -> Self {
self.caps = Some(caps.clone());
self
pub fn caps(self, caps: &gst::Caps) -> Self {
Self {
builder: self.builder.property("caps", caps),
..self
}
}
pub fn drop(mut self, drop: bool) -> Self {
self.drop = Some(drop);
self
pub fn drop(self, drop: bool) -> Self {
Self {
builder: self.builder.property("drop", drop),
..self
}
}
pub fn drop_out_of_segment(mut self, drop_out_of_segment: bool) -> Self {
self.drop_out_of_segment = Some(drop_out_of_segment);
self
pub fn drop_out_of_segment(self, drop_out_of_segment: bool) -> Self {
Self {
builder: self
.builder
.property("drop-out-of-segment", drop_out_of_segment),
..self
}
}
pub fn enable_last_sample(mut self, enable_last_sample: bool) -> Self {
self.enable_last_sample = Some(enable_last_sample);
self
pub fn enable_last_sample(self, enable_last_sample: bool) -> Self {
Self {
builder: self
.builder
.property("enable-last-sample", enable_last_sample),
..self
}
}
pub fn max_bitrate(mut self, max_bitrate: u64) -> Self {
self.max_bitrate = Some(max_bitrate);
self
pub fn max_bitrate(self, max_bitrate: u64) -> Self {
Self {
builder: self.builder.property("max-bitrate", max_bitrate),
..self
}
}
pub fn max_buffers(mut self, max_buffers: u32) -> Self {
self.max_buffers = Some(max_buffers);
self
pub fn max_buffers(self, max_buffers: u32) -> Self {
Self {
builder: self.builder.property("max-buffers", max_buffers),
..self
}
}
pub fn max_lateness(mut self, max_lateness: i64) -> Self {
self.max_lateness = Some(max_lateness);
self
pub fn max_lateness(self, max_lateness: i64) -> Self {
Self {
builder: self.builder.property("max-lateness", max_lateness),
..self
}
}
#[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn processing_deadline(mut self, processing_deadline: i64) -> Self {
self.processing_deadline = Some(processing_deadline);
self
pub fn processing_deadline(self, processing_deadline: i64) -> Self {
Self {
builder: self
.builder
.property("processing-deadline", processing_deadline),
..self
}
}
pub fn qos(mut self, qos: bool) -> Self {
self.qos = Some(qos);
self
pub fn qos(self, qos: bool) -> Self {
Self {
builder: self.builder.property("qos", qos),
..self
}
}
pub fn render_delay(mut self, render_delay: Option<gst::ClockTime>) -> Self {
self.render_delay = Some(render_delay);
self
pub fn render_delay(self, render_delay: Option<gst::ClockTime>) -> Self {
Self {
builder: self.builder.property("render-delay", render_delay),
..self
}
}
pub fn sync(mut self, sync: bool) -> Self {
self.sync = Some(sync);
self
pub fn sync(self, sync: bool) -> Self {
Self {
builder: self.builder.property("sync", sync),
..self
}
}
pub fn throttle_time(mut self, throttle_time: u64) -> Self {
self.throttle_time = Some(throttle_time);
self
pub fn throttle_time(self, throttle_time: u64) -> Self {
Self {
builder: self.builder.property("throttle-time", throttle_time),
..self
}
}
pub fn ts_offset(mut self, ts_offset: gst::ClockTimeDiff) -> Self {
self.ts_offset = Some(ts_offset);
self
pub fn ts_offset(self, ts_offset: gst::ClockTimeDiff) -> Self {
Self {
builder: self.builder.property("ts-offset", ts_offset),
..self
}
}
pub fn wait_on_eos(mut self, wait_on_eos: bool) -> Self {
self.wait_on_eos = Some(wait_on_eos);
self
pub fn wait_on_eos(self, wait_on_eos: bool) -> Self {
Self {
builder: self.builder.property("wait_on_eos", wait_on_eos),
..self
}
}
pub fn name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
pub fn name(self, name: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("name", name.into()),
..self
}
}
}

View file

@ -218,7 +218,7 @@ impl AppSrc {
/// This method returns an instance of [`AppSrcBuilder`](crate::builders::AppSrcBuilder) which can be used to create [`AppSrc`] objects.
pub fn builder() -> AppSrcBuilder {
assert_initialized_main_thread!();
AppSrcBuilder::default()
AppSrcBuilder::new()
}
#[doc(alias = "gst_app_src_set_callbacks")]
@ -353,111 +353,31 @@ impl AppSrc {
}
}
#[derive(Default)]
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`AppSrc`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct AppSrcBuilder {
automatic_eos: Option<bool>,
block: Option<bool>,
builder: glib::object::ObjectBuilder<'static, AppSrc>,
callbacks: Option<AppSrcCallbacks>,
caps: Option<gst::Caps>,
do_timestamp: Option<bool>,
duration: Option<u64>,
format: Option<gst::Format>,
#[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
handle_segment_change: Option<bool>,
is_live: Option<bool>,
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
leaky_type: Option<crate::AppLeakyType>,
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
max_buffers: Option<u64>,
max_bytes: Option<u64>,
max_latency: Option<i64>,
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
max_time: Option<Option<gst::ClockTime>>,
min_latency: Option<i64>,
min_percent: Option<u32>,
size: Option<i64>,
stream_type: Option<crate::AppStreamType>,
name: Option<String>,
automatic_eos: Option<bool>,
}
impl AppSrcBuilder {
// rustdoc-stripper-ignore-next
/// Create a new [`AppSrcBuilder`].
pub fn new() -> Self {
Self::default()
fn new() -> Self {
Self {
builder: glib::Object::builder(),
callbacks: None,
automatic_eos: None,
}
}
// rustdoc-stripper-ignore-next
/// Build the [`AppSrc`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> AppSrc {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
if let Some(ref block) = self.block {
properties.push(("block", block));
}
if let Some(ref caps) = self.caps {
properties.push(("caps", caps));
}
if let Some(ref do_timestamp) = self.do_timestamp {
properties.push(("do-timestamp", do_timestamp));
}
if let Some(ref duration) = self.duration {
properties.push(("duration", duration));
}
if let Some(ref format) = self.format {
properties.push(("format", format));
}
#[cfg(any(feature = "v1_18", feature = "dox"))]
if let Some(ref handle_segment_change) = self.handle_segment_change {
properties.push(("handle-segment-change", handle_segment_change));
}
if let Some(ref is_live) = self.is_live {
properties.push(("is-live", is_live));
}
#[cfg(any(feature = "v1_20", feature = "dox"))]
if let Some(ref leaky_type) = self.leaky_type {
properties.push(("leaky-type", leaky_type));
}
#[cfg(any(feature = "v1_20", feature = "dox"))]
if let Some(ref max_buffers) = self.max_buffers {
properties.push(("max-buffers", max_buffers));
}
if let Some(ref max_bytes) = self.max_bytes {
properties.push(("max-bytes", max_bytes));
}
if let Some(ref max_latency) = self.max_latency {
properties.push(("max-latency", max_latency));
}
#[cfg(any(feature = "v1_20", feature = "dox"))]
if let Some(ref max_time) = self.max_time {
properties.push(("max-time", max_time));
}
if let Some(ref min_latency) = self.min_latency {
properties.push(("min-latency", min_latency));
}
if let Some(ref min_percent) = self.min_percent {
properties.push(("min-percent", min_percent));
}
if let Some(ref size) = self.size {
properties.push(("size", size));
}
if let Some(ref stream_type) = self.stream_type {
properties.push(("stream-type", stream_type));
}
if let Some(ref name) = self.name {
properties.push(("name", name));
}
let appsrc = glib::Object::new::<AppSrc>(&properties);
let appsrc = self.builder.build();
if let Some(callbacks) = self.callbacks {
appsrc.set_callbacks(callbacks);
@ -470,107 +390,147 @@ impl AppSrcBuilder {
appsrc
}
pub fn automatic_eos(mut self, automatic_eos: bool) -> Self {
self.automatic_eos = Some(automatic_eos);
self
pub fn automatic_eos(self, automatic_eos: bool) -> Self {
Self {
automatic_eos: Some(automatic_eos),
..self
}
}
pub fn block(mut self, block: bool) -> Self {
self.block = Some(block);
self
pub fn block(self, block: bool) -> Self {
Self {
builder: self.builder.property("block", block),
..self
}
}
pub fn callbacks(mut self, callbacks: AppSrcCallbacks) -> Self {
self.callbacks = Some(callbacks);
self
pub fn callbacks(self, callbacks: AppSrcCallbacks) -> Self {
Self {
callbacks: Some(callbacks),
..self
}
}
pub fn caps(mut self, caps: &gst::Caps) -> Self {
self.caps = Some(caps.clone());
self
pub fn caps(self, caps: &gst::Caps) -> Self {
Self {
builder: self.builder.property("caps", caps),
..self
}
}
pub fn do_timestamp(mut self, do_timestamp: bool) -> Self {
self.do_timestamp = Some(do_timestamp);
self
pub fn do_timestamp(self, do_timestamp: bool) -> Self {
Self {
builder: self.builder.property("do-timestamp", do_timestamp),
..self
}
}
pub fn duration(mut self, duration: u64) -> Self {
self.duration = Some(duration);
self
pub fn duration(self, duration: u64) -> Self {
Self {
builder: self.builder.property("duration", duration),
..self
}
}
pub fn format(mut self, format: gst::Format) -> Self {
self.format = Some(format);
self
pub fn format(self, format: gst::Format) -> Self {
Self {
builder: self.builder.property("format", format),
..self
}
}
#[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
pub fn handle_segment_change(mut self, handle_segment_change: bool) -> Self {
self.handle_segment_change = Some(handle_segment_change);
self
pub fn handle_segment_change(self, handle_segment_change: bool) -> Self {
Self {
builder: self
.builder
.property("handle-segment-change", handle_segment_change),
..self
}
}
pub fn is_live(mut self, is_live: bool) -> Self {
self.is_live = Some(is_live);
self
pub fn is_live(self, is_live: bool) -> Self {
Self {
builder: self.builder.property("is-live", is_live),
..self
}
}
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
pub fn leaky_type(mut self, leaky_type: crate::AppLeakyType) -> Self {
self.leaky_type = Some(leaky_type);
self
pub fn leaky_type(self, leaky_type: crate::AppLeakyType) -> Self {
Self {
builder: self.builder.property("leaky-type", leaky_type),
..self
}
}
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
pub fn max_buffers(mut self, max_buffers: u64) -> Self {
self.max_buffers = Some(max_buffers);
self
pub fn max_buffers(self, max_buffers: u64) -> Self {
Self {
builder: self.builder.property("max-buffers", max_buffers),
..self
}
}
pub fn max_bytes(mut self, max_bytes: u64) -> Self {
self.max_bytes = Some(max_bytes);
self
pub fn max_bytes(self, max_bytes: u64) -> Self {
Self {
builder: self.builder.property("max-bytes", max_bytes),
..self
}
}
pub fn max_latency(mut self, max_latency: i64) -> Self {
self.max_latency = Some(max_latency);
self
pub fn max_latency(self, max_latency: i64) -> Self {
Self {
builder: self.builder.property("max-latency", max_latency),
..self
}
}
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
pub fn max_time(mut self, max_time: Option<gst::ClockTime>) -> Self {
self.max_time = Some(max_time);
self
pub fn max_time(self, max_time: Option<gst::ClockTime>) -> Self {
Self {
builder: self.builder.property("max-time", max_time),
..self
}
}
pub fn min_latency(mut self, min_latency: i64) -> Self {
self.min_latency = Some(min_latency);
self
pub fn min_latency(self, min_latency: i64) -> Self {
Self {
builder: self.builder.property("min-latency", min_latency),
..self
}
}
pub fn min_percent(mut self, min_percent: u32) -> Self {
self.min_percent = Some(min_percent);
self
pub fn min_percent(self, min_percent: u32) -> Self {
Self {
builder: self.builder.property("min-percent", min_percent),
..self
}
}
pub fn size(mut self, size: i64) -> Self {
self.size = Some(size);
self
pub fn size(self, size: i64) -> Self {
Self {
builder: self.builder.property("size", size),
..self
}
}
pub fn stream_type(mut self, stream_type: crate::AppStreamType) -> Self {
self.stream_type = Some(stream_type);
self
pub fn stream_type(self, stream_type: crate::AppStreamType) -> Self {
Self {
builder: self.builder.property("stream-type", stream_type),
..self
}
}
pub fn name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
pub fn name(self, name: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("name", name.into()),
..self
}
}
}

View file

@ -17,7 +17,7 @@ impl Bin {
///
/// This method returns an instance of [`BinBuilder`](crate::builders::BinBuilder) which can be used to create [`Bin`] objects.
pub fn builder() -> BinBuilder {
BinBuilder::default()
BinBuilder::new()
}
}
@ -223,59 +223,49 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
impl Default for Bin {
fn default() -> Self {
glib::object::Object::new::<Self>(&[])
glib::object::Object::new_default()
}
}
#[derive(Clone, Default)]
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Bin`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct BinBuilder {
async_handling: Option<bool>,
message_forward: Option<bool>,
name: Option<String>,
builder: glib::object::ObjectBuilder<'static, Bin>,
}
impl BinBuilder {
// rustdoc-stripper-ignore-next
/// Create a new [`BinBuilder`].
pub fn new() -> Self {
Self::default()
fn new() -> Self {
Self {
builder: glib::Object::builder(),
}
}
// rustdoc-stripper-ignore-next
/// Build the [`Bin`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Bin {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
if let Some(ref async_handling) = self.async_handling {
properties.push(("async-handling", async_handling));
}
if let Some(ref message_forward) = self.message_forward {
properties.push(("message-forward", message_forward));
}
if let Some(ref name) = self.name {
properties.push(("name", name));
}
glib::Object::new::<Bin>(&properties)
self.builder.build()
}
pub fn async_handling(mut self, async_handling: bool) -> Self {
self.async_handling = Some(async_handling);
self
pub fn async_handling(self, async_handling: bool) -> Self {
Self {
builder: self.builder.property("async-handling", async_handling),
}
}
pub fn message_forward(mut self, message_forward: bool) -> Self {
self.message_forward = Some(message_forward);
self
pub fn message_forward(self, message_forward: bool) -> Self {
Self {
builder: self.builder.property("message-forward", message_forward),
}
}
pub fn name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
pub fn name(self, name: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("name", name.into()),
}
}
}

View file

@ -48,7 +48,7 @@ impl ElementFactory {
ElementBuilder {
name_or_factory: NameOrFactory::Factory(self),
properties: Vec::new(),
properties: smallvec::SmallVec::new(),
}
}
@ -60,7 +60,7 @@ impl ElementFactory {
ElementBuilder {
name_or_factory: NameOrFactory::Name(factoryname),
properties: Vec::new(),
properties: smallvec::SmallVec::new(),
}
}
@ -219,7 +219,7 @@ impl ElementFactory {
#[must_use = "The builder must be built to be used"]
pub struct ElementBuilder<'a> {
name_or_factory: NameOrFactory<'a>,
properties: Vec<(&'a str, ValueOrStr<'a>)>,
properties: smallvec::SmallVec<[(&'a str, ValueOrStr<'a>); 16]>,
}
#[derive(Copy, Clone)]
@ -236,12 +236,14 @@ enum ValueOrStr<'a> {
impl<'a> ElementBuilder<'a> {
// rustdoc-stripper-ignore-next
/// Sets the name property to the given `name`.
pub fn name(self, name: &'a str) -> Self {
self.property("name", name)
#[inline]
pub fn name(self, name: impl Into<glib::GString>) -> Self {
self.property("name", name.into())
}
// rustdoc-stripper-ignore-next
/// Set property `name` to the given value `value`.
#[inline]
pub fn property(self, name: &'a str, value: impl Into<glib::Value> + 'a) -> Self {
Self {
name_or_factory: self.name_or_factory,
@ -255,6 +257,7 @@ impl<'a> ElementBuilder<'a> {
// rustdoc-stripper-ignore-next
/// Set property `name` to the given string value `value`.
#[inline]
pub fn property_from_str(self, name: &'a str, value: &'a str) -> Self {
Self {
name_or_factory: self.name_or_factory,
@ -328,7 +331,7 @@ impl<'a> ElementBuilder<'a> {
));
}
let mut properties = Vec::with_capacity(self.properties.len());
let mut properties = smallvec::SmallVec::<[_; 16]>::with_capacity(self.properties.len());
let klass = glib::Class::<Element>::from_type(element_type).unwrap();
for (name, value) in self.properties {
match value {
@ -386,9 +389,10 @@ impl<'a> ElementBuilder<'a> {
}
}
let element = glib::Object::with_values(element_type, &properties)
.downcast::<crate::Element>()
.unwrap();
let element = unsafe {
glib::Object::with_mut_values(element_type, &mut properties)
.unsafe_cast::<crate::Element>()
};
unsafe {
use std::sync::atomic;

View file

@ -1617,7 +1617,10 @@ impl<T: IsA<Pad> + IsA<glib::Object> + glib::object::IsClass> PadBuilder<T> {
pub fn new(name: Option<&str>, direction: crate::PadDirection) -> Self {
assert_initialized_main_thread!();
let pad = glib::Object::new::<T>(&[("name", &name), ("direction", &direction)]);
let pad = glib::Object::builder::<T>()
.property("name", name)
.property("direction", direction)
.build();
// Ghost pads are a bit special
if let Some(pad) = pad.dynamic_cast_ref::<crate::GhostPad>() {
@ -1660,16 +1663,14 @@ impl<T: IsA<Pad> + IsA<glib::Object> + glib::object::IsClass> PadBuilder<T> {
}
}
let pad = glib::Object::with_type(
type_,
&[
("name", &name),
("direction", &templ.direction()),
("template", templ),
],
)
.downcast::<T>()
.unwrap();
let mut properties = [
("name", name.map(glib::GString::from).into()),
("direction", templ.direction().into()),
("template", templ.into()),
];
let pad =
unsafe { glib::Object::with_mut_values(type_, &mut properties).unsafe_cast::<T>() };
// Ghost pads are a bit special
if let Some(pad) = pad.dynamic_cast_ref::<crate::GhostPad>() {

View file

@ -10,7 +10,7 @@ impl Pipeline {
///
/// This method returns an instance of [`PipelineBuilder`](crate::builders::PipelineBuilder) which can be used to create [`Pipeline`] objects.
pub fn builder() -> PipelineBuilder {
PipelineBuilder::default()
PipelineBuilder::new()
}
}
@ -51,85 +51,66 @@ impl<O: IsA<crate::Pipeline>> GstPipelineExtManual for O {
impl Default for Pipeline {
fn default() -> Self {
glib::object::Object::new::<Self>(&[])
glib::object::Object::new_default()
}
}
#[derive(Clone, Default)]
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Pipeline`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct PipelineBuilder {
auto_flush_bus: Option<bool>,
delay: Option<u64>,
latency: Option<u64>,
async_handling: Option<bool>,
message_forward: Option<bool>,
name: Option<String>,
builder: glib::object::ObjectBuilder<'static, Pipeline>,
}
impl PipelineBuilder {
// rustdoc-stripper-ignore-next
/// Create a new [`PipelineBuilder`].
pub fn new() -> Self {
Self::default()
fn new() -> Self {
Self {
builder: glib::Object::builder(),
}
}
// rustdoc-stripper-ignore-next
/// Build the [`Pipeline`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Pipeline {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
if let Some(ref auto_flush_bus) = self.auto_flush_bus {
properties.push(("auto-flush-bus", auto_flush_bus));
}
if let Some(ref delay) = self.delay {
properties.push(("delay", delay));
}
if let Some(ref latency) = self.latency {
properties.push(("latency", latency));
}
if let Some(ref async_handling) = self.async_handling {
properties.push(("async-handling", async_handling));
}
if let Some(ref message_forward) = self.message_forward {
properties.push(("message-forward", message_forward));
}
if let Some(ref name) = self.name {
properties.push(("name", name));
}
glib::Object::new::<Pipeline>(&properties)
self.builder.build()
}
pub fn auto_flush_bus(mut self, auto_flush_bus: bool) -> Self {
self.auto_flush_bus = Some(auto_flush_bus);
self
pub fn auto_flush_bus(self, auto_flush_bus: bool) -> Self {
Self {
builder: self.builder.property("auto-flush-bus", auto_flush_bus),
}
}
pub fn delay(mut self, delay: u64) -> Self {
self.delay = Some(delay);
self
pub fn delay(self, delay: u64) -> Self {
Self {
builder: self.builder.property("delay", delay),
}
}
pub fn latency(mut self, latency: u64) -> Self {
self.latency = Some(latency);
self
pub fn latency(self, latency: crate::ClockTime) -> Self {
Self {
builder: self.builder.property("latency", latency),
}
}
pub fn async_handling(mut self, async_handling: bool) -> Self {
self.async_handling = Some(async_handling);
self
pub fn async_handling(self, async_handling: bool) -> Self {
Self {
builder: self.builder.property("async-handling", async_handling),
}
}
pub fn message_forward(mut self, message_forward: bool) -> Self {
self.message_forward = Some(message_forward);
self
pub fn message_forward(self, message_forward: bool) -> Self {
Self {
builder: self.builder.property("message-forward", message_forward),
}
}
pub fn name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
pub fn name(self, name: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("name", name.into()),
}
}
}

View file

@ -150,7 +150,7 @@ mod tests {
impl Default for TestAllocator {
fn default() -> Self {
glib::Object::new(&[])
glib::Object::new_default()
}
}

View file

@ -517,7 +517,7 @@ mod tests {
impl Default for TestBufferPool {
fn default() -> Self {
glib::Object::new(&[])
glib::Object::new_default()
}
}

View file

@ -708,7 +708,7 @@ mod tests {
impl TestElement {
pub fn new(name: Option<&str>) -> Self {
glib::Object::new(&[("name", &name)])
glib::Object::builder().property("name", name).build()
}
}

View file

@ -126,7 +126,10 @@ mod tests {
impl TestPad {
pub fn new(name: &str, direction: PadDirection) -> Self {
glib::Object::new(&[("name", &name), ("direction", &direction)])
glib::Object::builder()
.property("name", name)
.property("direction", direction)
.build()
}
}

View file

@ -306,7 +306,7 @@ mod tests {
impl Default for TestPool {
fn default() -> Self {
glib::Object::new(&[])
glib::Object::new_default()
}
}