diff options
Diffstat (limited to 'generic/file/src')
-rw-r--r-- | generic/file/src/filesink/imp.rs (renamed from generic/file/src/filesink.rs) | 45 | ||||
-rw-r--r-- | generic/file/src/filesink/mod.rs | 29 | ||||
-rw-r--r-- | generic/file/src/filesrc/imp.rs (renamed from generic/file/src/filesrc.rs) | 54 | ||||
-rw-r--r-- | generic/file/src/filesrc/mod.rs | 28 |
4 files changed, 89 insertions, 67 deletions
diff --git a/generic/file/src/filesink.rs b/generic/file/src/filesink/imp.rs index 2bc0b7c3e..ae01b0849 100644 --- a/generic/file/src/filesink.rs +++ b/generic/file/src/filesink/imp.rs @@ -23,7 +23,7 @@ use std::sync::Mutex; use url::Url; -use file_location::FileLocation; +use crate::file_location::FileLocation; const DEFAULT_LOCATION: Option<FileLocation> = None; @@ -77,7 +77,7 @@ lazy_static! { impl FileSink { fn set_location( &self, - element: &gst_base::BaseSink, + element: &super::FileSink, location: Option<FileLocation>, ) -> Result<(), glib::Error> { let state = self.state.lock().unwrap(); @@ -119,6 +119,7 @@ impl FileSink { impl ObjectSubclass for FileSink { const NAME: &'static str = "RsFileSink"; + type Type = super::FileSink; type ParentType = gst_base::BaseSink; type Instance = gst::subclass::ElementInstanceStruct<Self>; type Class = subclass::simple::ClassStruct<Self>; @@ -136,7 +137,7 @@ impl ObjectSubclass for FileSink { type_.add_interface::<gst::URIHandler>(); } - fn class_init(klass: &mut subclass::simple::ClassStruct<Self>) { + fn class_init(klass: &mut Self::Class) { klass.set_metadata( "File Sink", "Sink/File", @@ -159,33 +160,26 @@ impl ObjectSubclass for FileSink { } impl ObjectImpl for FileSink { - fn set_property(&self, obj: &glib::Object, id: usize, value: &glib::Value) { + fn set_property(&self, obj: &Self::Type, id: usize, value: &glib::Value) { let prop = &PROPERTIES[id]; match *prop { subclass::Property("location", ..) => { - let element = obj.downcast_ref::<gst_base::BaseSink>().unwrap(); - let res = match value.get::<String>() { Ok(Some(location)) => FileLocation::try_from_path_str(location) - .and_then(|file_location| self.set_location(&element, Some(file_location))), - Ok(None) => self.set_location(&element, None), + .and_then(|file_location| self.set_location(obj, Some(file_location))), + Ok(None) => self.set_location(obj, None), Err(_) => unreachable!("type checked upstream"), }; if let Err(err) = res { - gst_error!( - CAT, - obj: element, - "Failed to set property `location`: {}", - err - ); + gst_error!(CAT, obj: obj, "Failed to set property `location`: {}", err); } } _ => unimplemented!(), }; } - fn get_property(&self, _obj: &glib::Object, id: usize) -> Result<glib::Value, ()> { + fn get_property(&self, _obj: &Self::Type, id: usize) -> Result<glib::Value, ()> { let prop = &PROPERTIES[id]; match *prop { subclass::Property("location", ..) => { @@ -205,7 +199,7 @@ impl ObjectImpl for FileSink { impl ElementImpl for FileSink {} impl BaseSinkImpl for FileSink { - fn start(&self, element: &gst_base::BaseSink) -> Result<(), gst::ErrorMessage> { + fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { let mut state = self.state.lock().unwrap(); if let State::Started { .. } = *state { unreachable!("FileSink already started"); @@ -237,7 +231,7 @@ impl BaseSinkImpl for FileSink { Ok(()) } - fn stop(&self, element: &gst_base::BaseSink) -> Result<(), gst::ErrorMessage> { + fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { let mut state = self.state.lock().unwrap(); if let State::Stopped = *state { return Err(gst_error_msg!( @@ -256,7 +250,7 @@ impl BaseSinkImpl for FileSink { fn render( &self, - element: &gst_base::BaseSink, + element: &Self::Type, buffer: &gst::Buffer, ) -> Result<gst::FlowSuccess, gst::FlowError> { let mut state = self.state.lock().unwrap(); @@ -293,7 +287,7 @@ impl BaseSinkImpl for FileSink { } impl URIHandlerImpl for FileSink { - fn get_uri(&self, _element: &gst::URIHandler) -> Option<String> { + fn get_uri(&self, _element: &Self::Type) -> Option<String> { let settings = self.settings.lock().unwrap(); // Conversion to Url already checked while building the `FileLocation` @@ -304,9 +298,7 @@ impl URIHandlerImpl for FileSink { }) } - fn set_uri(&self, element: &gst::URIHandler, uri: &str) -> Result<(), glib::Error> { - let element = element.dynamic_cast_ref::<gst_base::BaseSink>().unwrap(); - + fn set_uri(&self, element: &Self::Type, uri: &str) -> Result<(), glib::Error> { // Special case for "file://" as this is used by some applications to test // with `gst_element_make_from_uri` if there's an element that supports the URI protocol @@ -326,12 +318,3 @@ impl URIHandlerImpl for FileSink { vec!["file".to_string()] } } - -pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { - gst::Element::register( - Some(plugin), - "rsfilesink", - gst::Rank::None, - FileSink::get_type(), - ) -} diff --git a/generic/file/src/filesink/mod.rs b/generic/file/src/filesink/mod.rs new file mode 100644 index 000000000..8ad677156 --- /dev/null +++ b/generic/file/src/filesink/mod.rs @@ -0,0 +1,29 @@ +// Copyright (C) 2016-2017 Sebastian Dröge <sebastian@centricular.com> +// 2016 Luis de Bethencourt <luisbg@osg.samsung.com> +// 2018 François Laignel <fengalin@free.fr> +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use glib::prelude::*; + +mod imp; + +glib_wrapper! { + pub struct FileSink(ObjectSubclass<imp::FileSink>) @extends gst_base::BaseSink, gst::Element, gst::Object, @implements gst::URIHandler; +} + +unsafe impl Send for FileSink {} +unsafe impl Sync for FileSink {} + +pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { + gst::Element::register( + Some(plugin), + "rsfilesink", + gst::Rank::None, + FileSink::static_type(), + ) +} diff --git a/generic/file/src/filesrc.rs b/generic/file/src/filesrc/imp.rs index eb8d1d632..ca58949dc 100644 --- a/generic/file/src/filesrc.rs +++ b/generic/file/src/filesrc/imp.rs @@ -23,7 +23,7 @@ use std::sync::Mutex; use url::Url; -use file_location::FileLocation; +use crate::file_location::FileLocation; const DEFAULT_LOCATION: Option<FileLocation> = None; @@ -77,7 +77,7 @@ lazy_static! { impl FileSrc { fn set_location( &self, - element: &gst_base::BaseSrc, + element: &super::FileSrc, location: Option<FileLocation>, ) -> Result<(), glib::Error> { let state = self.state.lock().unwrap(); @@ -133,6 +133,7 @@ impl FileSrc { impl ObjectSubclass for FileSrc { const NAME: &'static str = "RsFileSrc"; + type Type = super::FileSrc; type ParentType = gst_base::BaseSrc; type Instance = gst::subclass::ElementInstanceStruct<Self>; type Class = subclass::simple::ClassStruct<Self>; @@ -150,7 +151,7 @@ impl ObjectSubclass for FileSrc { type_.add_interface::<gst::URIHandler>(); } - fn class_init(klass: &mut subclass::simple::ClassStruct<Self>) { + fn class_init(klass: &mut Self::Class) { klass.set_metadata( "File Source", "Source/File", @@ -173,33 +174,26 @@ impl ObjectSubclass for FileSrc { } impl ObjectImpl for FileSrc { - fn set_property(&self, obj: &glib::Object, id: usize, value: &glib::Value) { + fn set_property(&self, obj: &Self::Type, id: usize, value: &glib::Value) { let prop = &PROPERTIES[id]; match *prop { subclass::Property("location", ..) => { - let element = obj.downcast_ref::<gst_base::BaseSrc>().unwrap(); - let res = match value.get::<String>() { Ok(Some(location)) => FileLocation::try_from_path_str(location) - .and_then(|file_location| self.set_location(&element, Some(file_location))), - Ok(None) => self.set_location(&element, None), + .and_then(|file_location| self.set_location(obj, Some(file_location))), + Ok(None) => self.set_location(obj, None), Err(_) => unreachable!("type checked upstream"), }; if let Err(err) = res { - gst_error!( - CAT, - obj: element, - "Failed to set property `location`: {}", - err - ); + gst_error!(CAT, obj: obj, "Failed to set property `location`: {}", err); } } _ => unimplemented!(), }; } - fn get_property(&self, _obj: &glib::Object, id: usize) -> Result<glib::Value, ()> { + fn get_property(&self, _obj: &Self::Type, id: usize) -> Result<glib::Value, ()> { let prop = &PROPERTIES[id]; match *prop { subclass::Property("location", ..) => { @@ -215,22 +209,21 @@ impl ObjectImpl for FileSrc { } } - fn constructed(&self, obj: &glib::Object) { + fn constructed(&self, obj: &Self::Type) { self.parent_constructed(obj); - let element = obj.downcast_ref::<gst_base::BaseSrc>().unwrap(); - element.set_format(gst::Format::Bytes); + obj.set_format(gst::Format::Bytes); } } impl ElementImpl for FileSrc {} impl BaseSrcImpl for FileSrc { - fn is_seekable(&self, _src: &gst_base::BaseSrc) -> bool { + fn is_seekable(&self, _src: &Self::Type) -> bool { true } - fn get_size(&self, _src: &gst_base::BaseSrc) -> Option<u64> { + fn get_size(&self, _src: &Self::Type) -> Option<u64> { let state = self.state.lock().unwrap(); if let State::Started { ref file, .. } = *state { file.metadata().ok().map(|m| m.len()) @@ -239,7 +232,7 @@ impl BaseSrcImpl for FileSrc { } } - fn start(&self, element: &gst_base::BaseSrc) -> Result<(), gst::ErrorMessage> { + fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { let mut state = self.state.lock().unwrap(); if let State::Started { .. } = *state { unreachable!("FileSrc already started"); @@ -273,7 +266,7 @@ impl BaseSrcImpl for FileSrc { Ok(()) } - fn stop(&self, element: &gst_base::BaseSrc) -> Result<(), gst::ErrorMessage> { + fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { let mut state = self.state.lock().unwrap(); if let State::Stopped = *state { return Err(gst_error_msg!( @@ -291,7 +284,7 @@ impl BaseSrcImpl for FileSrc { fn fill( &self, - element: &gst_base::BaseSrc, + element: &Self::Type, offset: u64, _length: u32, buffer: &mut gst::BufferRef, @@ -347,7 +340,7 @@ impl BaseSrcImpl for FileSrc { } impl URIHandlerImpl for FileSrc { - fn get_uri(&self, _element: &gst::URIHandler) -> Option<String> { + fn get_uri(&self, _element: &Self::Type) -> Option<String> { let settings = self.settings.lock().unwrap(); // Conversion to Url already checked while building the `FileLocation` @@ -358,9 +351,7 @@ impl URIHandlerImpl for FileSrc { }) } - fn set_uri(&self, element: &gst::URIHandler, uri: &str) -> Result<(), glib::Error> { - let element = element.dynamic_cast_ref::<gst_base::BaseSrc>().unwrap(); - + fn set_uri(&self, element: &Self::Type, uri: &str) -> Result<(), glib::Error> { // Special case for "file://" as this is used by some applications to test // with `gst_element_make_from_uri` if there's an element that supports the URI protocol @@ -380,12 +371,3 @@ impl URIHandlerImpl for FileSrc { vec!["file".to_string()] } } - -pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { - gst::Element::register( - Some(plugin), - "rsfilesrc", - gst::Rank::None, - FileSrc::get_type(), - ) -} diff --git a/generic/file/src/filesrc/mod.rs b/generic/file/src/filesrc/mod.rs new file mode 100644 index 000000000..70ed45de7 --- /dev/null +++ b/generic/file/src/filesrc/mod.rs @@ -0,0 +1,28 @@ +// Copyright (C) 2016-2017 Sebastian Dröge <sebastian@centricular.com> +// 2018 François Laignel <fengalin@free.fr> +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use glib::prelude::*; + +mod imp; + +glib_wrapper! { + pub struct FileSrc(ObjectSubclass<imp::FileSrc>) @extends gst_base::BaseSrc, gst::Element, gst::Object, @implements gst::URIHandler; +} + +unsafe impl Send for FileSrc {} +unsafe impl Sync for FileSrc {} + +pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { + gst::Element::register( + Some(plugin), + "rsfilesrc", + gst::Rank::None, + FileSrc::static_type(), + ) +} |