diff options
author | François Laignel <fengalin@free.fr> | 2019-01-26 18:07:51 +0300 |
---|---|---|
committer | François Laignel <fengalin@free.fr> | 2019-01-26 18:35:52 +0300 |
commit | 2a656a98b66c133b63225b049fb9dba44d420218 (patch) | |
tree | d63619608cb7eaa3b7661bd937e0ae483d2e0028 | |
parent | 35968707516fd4d7ec19f93fc5209da2b82374f4 (diff) |
Update signatures further to gstreamer-base changes
See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/216
-rw-r--r-- | gst-plugin-audiofx/src/audioecho.rs | 4 | ||||
-rw-r--r-- | gst-plugin-file/src/filesink.rs | 58 | ||||
-rw-r--r-- | gst-plugin-file/src/filesrc.rs | 62 | ||||
-rw-r--r-- | gst-plugin-http/src/httpsrc.rs | 40 | ||||
-rw-r--r-- | gst-plugin-tutorial/src/rgb2gray.rs | 4 | ||||
-rw-r--r-- | gst-plugin-tutorial/src/sinesrc.rs | 35 |
6 files changed, 87 insertions, 116 deletions
diff --git a/gst-plugin-audiofx/src/audioecho.rs b/gst-plugin-audiofx/src/audioecho.rs index 211622130..4fe136f24 100644 --- a/gst-plugin-audiofx/src/audioecho.rs +++ b/gst-plugin-audiofx/src/audioecho.rs @@ -305,11 +305,11 @@ impl BaseTransformImpl for AudioEcho { true } - fn stop(&self, _element: &gst_base::BaseTransform) -> bool { + fn stop(&self, _element: &gst_base::BaseTransform) -> Result<(), gst::ErrorMessage> { // Drop state let _ = self.state.lock().unwrap().take(); - true + Ok(()) } } diff --git a/gst-plugin-file/src/filesink.rs b/gst-plugin-file/src/filesink.rs index 5d1ac214f..5c8adfa84 100644 --- a/gst-plugin-file/src/filesink.rs +++ b/gst-plugin-file/src/filesink.rs @@ -199,63 +199,51 @@ impl ObjectImpl for FileSink { impl ElementImpl for FileSink {} impl BaseSinkImpl for FileSink { - fn start(&self, element: &gst_base::BaseSink) -> bool { + fn start(&self, element: &gst_base::BaseSink) -> Result<(), gst::ErrorMessage> { let mut state = self.state.lock().unwrap(); if let State::Started { .. } = *state { unreachable!("FileSink already started"); } let settings = self.settings.lock().unwrap(); - let location = match settings.location { - Some(ref location) => location, - None => { - gst_element_error!( - element, - gst::ResourceError::Settings, - ["File location is not defined"] - ); - return false; - } - }; + let location = settings.location.as_ref().ok_or_else(|| { + gst_error_msg!( + gst::ResourceError::Settings, + ["File location is not defined"] + ) + })?; - let file = match File::create(location) { - Ok(file) => file, - Err(err) => { - gst_element_error!( - element, - gst::ResourceError::OpenWrite, - [ - "Could not open file {} for writing: {}", - location, - err.to_string(), - ] - ); - return false; - } - }; + let file = File::create(location).map_err(|err| { + gst_error_msg!( + gst::ResourceError::OpenWrite, + [ + "Could not open file {} for writing: {}", + location, + err.to_string(), + ] + ) + })?; gst_debug!(self.cat, obj: element, "Opened file {:?}", file); *state = State::Started { file, position: 0 }; gst_info!(self.cat, obj: element, "Started"); - true + Ok(()) } - fn stop(&self, element: &gst_base::BaseSink) -> bool { + fn stop(&self, element: &gst_base::BaseSink) -> Result<(), gst::ErrorMessage> { let mut state = self.state.lock().unwrap(); if let State::Stopped = *state { - gst_element_warning!( - element, - gst::CoreError::StateChange, + return Err(gst_error_msg!( + gst::ResourceError::Settings, ["FileSink not started"] - ); - return false; + )); } *state = State::Stopped; gst_info!(self.cat, obj: element, "Stopped"); - true + Ok(()) } // TODO: implement seek in BYTES format diff --git a/gst-plugin-file/src/filesrc.rs b/gst-plugin-file/src/filesrc.rs index 22663ebe3..ef049bd96 100644 --- a/gst-plugin-file/src/filesrc.rs +++ b/gst-plugin-file/src/filesrc.rs @@ -233,40 +233,30 @@ impl BaseSrcImpl for FileSrc { } } - fn start(&self, element: &gst_base::BaseSrc) -> bool { + fn start(&self, element: &gst_base::BaseSrc) -> Result<(), gst::ErrorMessage> { let mut state = self.state.lock().unwrap(); if let State::Started { .. } = *state { unreachable!("FileSrc already started"); } let settings = self.settings.lock().unwrap(); - let location = match settings.location { - Some(ref location) => location, - None => { - gst_element_error!( - element, - gst::CoreError::StateChange, - ["File location is not defined"] - ); - return false; - } - }; - - let file = match File::open(location) { - Ok(file) => file, - Err(err) => { - gst_element_error!( - element, - gst::ResourceError::OpenRead, - [ - "Could not open file {} for reading: {}", - location, - err.to_string(), - ] - ); - return false; - } - }; + let location = settings.location.as_ref().ok_or_else(|| { + gst_error_msg!( + gst::ResourceError::Settings, + ["File location is not defined"] + ) + })?; + + let file = File::open(location).map_err(|err| { + gst_error_msg!( + gst::ResourceError::OpenRead, + [ + "Could not open file {} for reading: {}", + location, + err.to_string(), + ] + ) + })?; gst_debug!(self.cat, obj: element, "Opened file {:?}", file); @@ -274,25 +264,23 @@ impl BaseSrcImpl for FileSrc { gst_info!(self.cat, obj: element, "Started"); - true + Ok(()) } - fn stop(&self, element: &gst_base::BaseSrc) -> bool { + fn stop(&self, element: &gst_base::BaseSrc) -> Result<(), gst::ErrorMessage> { let mut state = self.state.lock().unwrap(); if let State::Stopped = *state { - gst_element_warning!( - element, - gst::CoreError::StateChange, - ["FileSink not started"] - ); - return false; + return Err(gst_error_msg!( + gst::ResourceError::Settings, + ["FileSrc not started"] + )); } *state = State::Stopped; gst_info!(self.cat, obj: element, "Stopped"); - true + Ok(()) } fn fill( diff --git a/gst-plugin-http/src/httpsrc.rs b/gst-plugin-http/src/httpsrc.rs index 23f21d2d5..9c029eeb7 100644 --- a/gst-plugin-http/src/httpsrc.rs +++ b/gst-plugin-http/src/httpsrc.rs @@ -270,39 +270,31 @@ impl BaseSrcImpl for HttpSrc { } } - fn start(&self, src: &gst_base::BaseSrc) -> bool { + fn start(&self, src: &gst_base::BaseSrc) -> Result<(), gst::ErrorMessage> { let mut state = self.state.lock().unwrap(); *state = State::Stopped; - let uri = match self.settings.lock().unwrap().location { - Some(ref uri) => uri.clone(), - None => { - gst_element_error!( - src, - gst::CoreError::StateChange, - ["Can't start without an URI"] - ); - return false; - } - }; + let uri = self + .settings + .lock() + .unwrap() + .location + .as_ref() + .ok_or_else(|| { + gst_error_msg!(gst::CoreError::StateChange, ["Can't start without an URI"]) + }) + .map(|uri| uri.clone())?; - match self.do_request(src, uri, 0, None) { - Ok(s) => { - *state = s; - true - } - Err(err) => { - src.post_error_message(&err); - false - } - } + *state = self.do_request(src, uri, 0, None)?; + + Ok(()) } - fn stop(&self, _src: &gst_base::BaseSrc) -> bool { + fn stop(&self, _src: &gst_base::BaseSrc) -> Result<(), gst::ErrorMessage> { *self.state.lock().unwrap() = State::Stopped; - true + Ok(()) } fn do_seek(&self, src: &gst_base::BaseSrc, segment: &mut gst::Segment) -> bool { diff --git a/gst-plugin-tutorial/src/rgb2gray.rs b/gst-plugin-tutorial/src/rgb2gray.rs index dd083d86a..54e053c5b 100644 --- a/gst-plugin-tutorial/src/rgb2gray.rs +++ b/gst-plugin-tutorial/src/rgb2gray.rs @@ -401,13 +401,13 @@ impl BaseTransformImpl for Rgb2Gray { // Called when shutting down the element so we can release all stream-related state // There's also start(), which is called whenever starting the element again - fn stop(&self, element: &gst_base::BaseTransform) -> bool { + fn stop(&self, element: &gst_base::BaseTransform) -> Result<(), gst::ErrorMessage> { // Drop state let _ = self.state.lock().unwrap().take(); gst_info!(self.cat, obj: element, "Stopped"); - true + Ok(()) } // Does the actual transformation of the input buffer to the output buffer diff --git a/gst-plugin-tutorial/src/sinesrc.rs b/gst-plugin-tutorial/src/sinesrc.rs index ffa30ffc0..285174d97 100644 --- a/gst-plugin-tutorial/src/sinesrc.rs +++ b/gst-plugin-tutorial/src/sinesrc.rs @@ -433,13 +433,16 @@ 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: &gst_base::BaseSrc, caps: &gst::CapsRef) -> bool { + fn set_caps( + &self, + element: &gst_base::BaseSrc, + caps: &gst::CapsRef, + ) -> Result<(), gst::LoggableError> { use std::f64::consts::PI; - let info = match gst_audio::AudioInfo::from_caps(caps) { - None => return false, - Some(info) => info, - }; + let info = gst_audio::AudioInfo::from_caps(caps).ok_or_else(|| { + gst_loggable_error!(self.cat, "Failed to build `AudioInfo` from caps {}", caps) + })?; gst_debug!(self.cat, obj: element, "Configuring for caps {}", caps); @@ -480,29 +483,29 @@ impl BaseSrcImpl for SineSrc { let _ = element.post_message(&gst::Message::new_latency().src(Some(element)).build()); - true + Ok(()) } // Called when starting, so we can initialize all stream-related state to its defaults - fn start(&self, element: &gst_base::BaseSrc) -> bool { + fn start(&self, element: &gst_base::BaseSrc) -> Result<(), gst::ErrorMessage> { // Reset state *self.state.lock().unwrap() = Default::default(); - self.unlock_stop(element); + self.unlock_stop(element)?; gst_info!(self.cat, obj: element, "Started"); - true + Ok(()) } // Called when shutting down the element so we can release all stream-related state - fn stop(&self, element: &gst_base::BaseSrc) -> bool { + fn stop(&self, element: &gst_base::BaseSrc) -> Result<(), gst::ErrorMessage> { // Reset state *self.state.lock().unwrap() = Default::default(); - self.unlock(element); + self.unlock(element)?; gst_info!(self.cat, obj: element, "Stopped"); - true + Ok(()) } fn query(&self, element: &gst_base::BaseSrc, query: &mut gst::QueryRef) -> bool { @@ -827,7 +830,7 @@ impl BaseSrcImpl for SineSrc { } } - fn unlock(&self, element: &gst_base::BaseSrc) -> bool { + fn unlock(&self, element: &gst_base::BaseSrc) -> Result<(), gst::ErrorMessage> { // This should unblock the create() function ASAP, so we // just unschedule the clock it here, if any. gst_debug!(self.cat, obj: element, "Unlocking"); @@ -837,17 +840,17 @@ impl BaseSrcImpl for SineSrc { } clock_wait.flushing = true; - true + Ok(()) } - fn unlock_stop(&self, element: &gst_base::BaseSrc) -> bool { + fn unlock_stop(&self, element: &gst_base::BaseSrc) -> Result<(), gst::ErrorMessage> { // This signals that unlocking is done, so we can reset // all values again. gst_debug!(self.cat, obj: element, "Unlock stop"); let mut clock_wait = self.clock_wait.lock().unwrap(); clock_wait.flushing = false; - true + Ok(()) } } |