Update signatures further to gstreamer-base changes

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/216
This commit is contained in:
François Laignel 2019-01-26 16:07:51 +01:00
parent 3596870751
commit 2a656a98b6
6 changed files with 86 additions and 115 deletions

View file

@ -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(())
}
}

View file

@ -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

View file

@ -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 location = settings.location.as_ref().ok_or_else(|| {
gst_error_msg!(
gst::ResourceError::Settings,
["File location is not defined"]
)
})?;
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 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(

View file

@ -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 {

View file

@ -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

View file

@ -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(())
}
}