Make use of downcast_ref() to prevent some clones

This commit is contained in:
Sebastian Dröge 2018-07-12 08:31:58 +03:00
parent b3089ca047
commit 6e33313b78
5 changed files with 37 additions and 41 deletions

View file

@ -340,9 +340,8 @@ impl Demuxer {
) -> bool {
let element = parent
.as_ref()
.cloned()
.unwrap()
.downcast::<Element>()
.downcast_ref::<Element>()
.unwrap();
let demuxer = element.get_impl().downcast_ref::<Demuxer>().unwrap();
@ -352,7 +351,7 @@ impl Demuxer {
.peer_query_duration::<gst::format::Bytes>()
.and_then(|v| v.0);
if !demuxer.start(&element, upstream_size, mode == gst::PadMode::Pull) {
if !demuxer.start(element, upstream_size, mode == gst::PadMode::Pull) {
return false;
}
@ -367,7 +366,7 @@ impl Demuxer {
let _ = demuxer.sinkpad.stop_task();
}
demuxer.stop(&element)
demuxer.stop(element)
}
}
@ -378,23 +377,22 @@ impl Demuxer {
) -> gst::FlowReturn {
let element = parent
.as_ref()
.cloned()
.unwrap()
.downcast::<Element>()
.downcast_ref::<Element>()
.unwrap();
let demuxer = element.get_impl().downcast_ref::<Demuxer>().unwrap();
let mut res = {
let demuxer_impl = &mut demuxer.imp.lock().unwrap();
gst_trace!(demuxer.cat, obj: &element, "Handling buffer {:?}", buffer);
gst_trace!(demuxer.cat, obj: element, "Handling buffer {:?}", buffer);
match demuxer_impl.handle_buffer(&element, Some(buffer)) {
match demuxer_impl.handle_buffer(element, Some(buffer)) {
Ok(res) => res,
Err(flow_error) => {
gst_error!(
demuxer.cat,
obj: &element,
obj: element,
"Failed handling buffer: {:?}",
flow_error
);
@ -411,33 +409,33 @@ impl Demuxer {
// Loop until AllEos, NeedMoreData or error when pushing downstream
loop {
gst_trace!(demuxer.cat, obj: &element, "Handled {:?}", res);
gst_trace!(demuxer.cat, obj: element, "Handled {:?}", res);
match res {
HandleBufferResult::NeedMoreData => {
return gst::FlowReturn::Ok;
}
HandleBufferResult::StreamAdded(stream) => {
demuxer.add_stream(&element, stream.index, stream.caps, &stream.stream_id);
demuxer.add_stream(element, stream.index, stream.caps, &stream.stream_id);
}
HandleBufferResult::HaveAllStreams => {
demuxer.added_all_streams(&element);
demuxer.added_all_streams(element);
}
HandleBufferResult::StreamChanged(stream) => {
demuxer.stream_format_changed(&element, stream.index, stream.caps);
demuxer.stream_format_changed(element, stream.index, stream.caps);
}
HandleBufferResult::StreamsChanged(streams) => for stream in streams {
demuxer.stream_format_changed(&element, stream.index, stream.caps);
demuxer.stream_format_changed(element, stream.index, stream.caps);
},
HandleBufferResult::BufferForStream(index, buffer) => {
let flow_ret = demuxer.stream_push_buffer(&element, index, buffer);
let flow_ret = demuxer.stream_push_buffer(element, index, buffer);
if flow_ret != gst::FlowReturn::Ok {
return flow_ret;
}
}
HandleBufferResult::Eos(index) => {
demuxer.stream_eos(&element, index);
demuxer.stream_eos(element, index);
return gst::FlowReturn::Eos;
}
HandleBufferResult::Again => {
@ -445,16 +443,16 @@ impl Demuxer {
}
};
gst_trace!(demuxer.cat, obj: &element, "Calling again");
gst_trace!(demuxer.cat, obj: element, "Calling again");
res = {
let demuxer_impl = &mut demuxer.imp.lock().unwrap();
match demuxer_impl.handle_buffer(&element, None) {
match demuxer_impl.handle_buffer(element, None) {
Ok(res) => res,
Err(flow_error) => {
gst_error!(
demuxer.cat,
obj: &element,
obj: element,
"Failed calling again: {:?}",
flow_error
);
@ -476,9 +474,8 @@ impl Demuxer {
let element = parent
.as_ref()
.cloned()
.unwrap()
.downcast::<Element>()
.downcast_ref::<Element>()
.unwrap();
let demuxer = element.get_impl().downcast_ref::<Demuxer>().unwrap();
@ -486,13 +483,13 @@ impl Demuxer {
EventView::Eos(..) => {
let demuxer_impl = &mut demuxer.imp.lock().unwrap();
gst_debug!(demuxer.cat, obj: &element, "End of stream");
match demuxer_impl.end_of_stream(&element) {
gst_debug!(demuxer.cat, obj: element, "End of stream");
match demuxer_impl.end_of_stream(element) {
Ok(_) => (),
Err(ref msg) => {
gst_error!(
demuxer.cat,
obj: &element,
obj: element,
"Failed end of stream: {:?}",
msg
);
@ -511,9 +508,8 @@ impl Demuxer {
let element = parent
.as_ref()
.cloned()
.unwrap()
.downcast::<Element>()
.downcast_ref::<Element>()
.unwrap();
let demuxer = element.get_impl().downcast_ref::<Demuxer>().unwrap();
@ -526,7 +522,7 @@ impl Demuxer {
let position = demuxer_impl.get_position(&element);
gst_trace!(
demuxer.cat,
obj: &element,
obj: element,
"Returning position {:?}",
position
);
@ -550,7 +546,7 @@ impl Demuxer {
let duration = demuxer_impl.get_duration(&element);
gst_trace!(
demuxer.cat,
obj: &element,
obj: element,
"Returning duration {:?}",
duration
);

View file

@ -1194,7 +1194,7 @@ impl ToggleRecord {
impl ObjectImpl<Element> for ToggleRecord {
fn set_property(&self, obj: &glib::Object, id: u32, value: &glib::Value) {
let prop = &PROPERTIES[id as usize];
let element = obj.clone().downcast::<Element>().unwrap();
let element = obj.downcast_ref::<Element>().unwrap();
match *prop {
Property::Boolean("record", ..) => {
@ -1202,7 +1202,7 @@ impl ObjectImpl<Element> for ToggleRecord {
let record = value.get().unwrap();
gst_debug!(
self.cat,
obj: &element,
obj: element,
"Setting record from {:?} to {:?}",
settings.record,
record

View file

@ -206,7 +206,7 @@ impl ObjectImpl<BaseTransform> for Rgb2Gray {
// at any time from any thread.
fn set_property(&self, obj: &glib::Object, id: u32, value: &glib::Value) {
let prop = &PROPERTIES[id as usize];
let element = obj.clone().downcast::<BaseTransform>().unwrap();
let element = obj.downcast_ref::<BaseTransform>().unwrap();
match *prop {
Property::Boolean("invert", ..) => {
@ -214,7 +214,7 @@ impl ObjectImpl<BaseTransform> for Rgb2Gray {
let invert = value.get().unwrap();
gst_info!(
self.cat,
obj: &element,
obj: element,
"Changing invert from {} to {}",
settings.invert,
invert
@ -226,7 +226,7 @@ impl ObjectImpl<BaseTransform> for Rgb2Gray {
let shift = value.get().unwrap();
gst_info!(
self.cat,
obj: &element,
obj: element,
"Changing shift from {} to {}",
settings.shift,
shift

View file

@ -251,7 +251,7 @@ impl ObjectImpl<BaseSrc> for SineSrc {
// at any time from any thread.
fn set_property(&self, obj: &glib::Object, id: u32, value: &glib::Value) {
let prop = &PROPERTIES[id as usize];
let element = obj.clone().downcast::<BaseSrc>().unwrap();
let element = obj.downcast_ref::<BaseSrc>().unwrap();
match *prop {
Property::UInt("samples-per-buffer", ..) => {
@ -259,7 +259,7 @@ impl ObjectImpl<BaseSrc> for SineSrc {
let samples_per_buffer = value.get().unwrap();
gst_info!(
self.cat,
obj: &element,
obj: element,
"Changing samples-per-buffer from {} to {}",
settings.samples_per_buffer,
samples_per_buffer
@ -268,14 +268,14 @@ impl ObjectImpl<BaseSrc> for SineSrc {
drop(settings);
let _ =
element.post_message(&gst::Message::new_latency().src(Some(&element)).build());
element.post_message(&gst::Message::new_latency().src(Some(element)).build());
}
Property::UInt("freq", ..) => {
let mut settings = self.settings.lock().unwrap();
let freq = value.get().unwrap();
gst_info!(
self.cat,
obj: &element,
obj: element,
"Changing freq from {} to {}",
settings.freq,
freq
@ -287,7 +287,7 @@ impl ObjectImpl<BaseSrc> for SineSrc {
let volume = value.get().unwrap();
gst_info!(
self.cat,
obj: &element,
obj: element,
"Changing volume from {} to {}",
settings.volume,
volume
@ -299,7 +299,7 @@ impl ObjectImpl<BaseSrc> for SineSrc {
let mute = value.get().unwrap();
gst_info!(
self.cat,
obj: &element,
obj: element,
"Changing mute from {} to {}",
settings.mute,
mute
@ -311,7 +311,7 @@ impl ObjectImpl<BaseSrc> for SineSrc {
let is_live = value.get().unwrap();
gst_info!(
self.cat,
obj: &element,
obj: element,
"Changing is-live from {} to {}",
settings.is_live,
is_live

View file

@ -78,7 +78,7 @@ where
f: F,
) -> R {
// FIXME: Does this work for element subclasses?
let element = parent.as_ref().cloned().unwrap().downcast::<T>().unwrap();
let element = parent.as_ref().unwrap().downcast_ref::<T>().unwrap();
let imp = element.get_impl();
let imp = Any::downcast_ref::<Box<ElementImpl<T> + 'static>>(imp).unwrap();
let imp = imp.downcast_ref::<S>().unwrap();