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 true
} }
fn stop(&self, _element: &gst_base::BaseTransform) -> bool { fn stop(&self, _element: &gst_base::BaseTransform) -> Result<(), gst::ErrorMessage> {
// Drop state // Drop state
let _ = self.state.lock().unwrap().take(); let _ = self.state.lock().unwrap().take();
true Ok(())
} }
} }

View file

@ -199,63 +199,51 @@ impl ObjectImpl for FileSink {
impl ElementImpl for FileSink {} impl ElementImpl for FileSink {}
impl BaseSinkImpl 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(); let mut state = self.state.lock().unwrap();
if let State::Started { .. } = *state { if let State::Started { .. } = *state {
unreachable!("FileSink already started"); unreachable!("FileSink already started");
} }
let settings = self.settings.lock().unwrap(); let settings = self.settings.lock().unwrap();
let location = match settings.location { let location = settings.location.as_ref().ok_or_else(|| {
Some(ref location) => location, gst_error_msg!(
None => { gst::ResourceError::Settings,
gst_element_error!( ["File location is not defined"]
element, )
gst::ResourceError::Settings, })?;
["File location is not defined"]
);
return false;
}
};
let file = match File::create(location) { let file = File::create(location).map_err(|err| {
Ok(file) => file, gst_error_msg!(
Err(err) => { gst::ResourceError::OpenWrite,
gst_element_error!( [
element, "Could not open file {} for writing: {}",
gst::ResourceError::OpenWrite, location,
[ err.to_string(),
"Could not open file {} for writing: {}", ]
location, )
err.to_string(), })?;
]
);
return false;
}
};
gst_debug!(self.cat, obj: element, "Opened file {:?}", file); gst_debug!(self.cat, obj: element, "Opened file {:?}", file);
*state = State::Started { file, position: 0 }; *state = State::Started { file, position: 0 };
gst_info!(self.cat, obj: element, "Started"); 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(); let mut state = self.state.lock().unwrap();
if let State::Stopped = *state { if let State::Stopped = *state {
gst_element_warning!( return Err(gst_error_msg!(
element, gst::ResourceError::Settings,
gst::CoreError::StateChange,
["FileSink not started"] ["FileSink not started"]
); ));
return false;
} }
*state = State::Stopped; *state = State::Stopped;
gst_info!(self.cat, obj: element, "Stopped"); gst_info!(self.cat, obj: element, "Stopped");
true Ok(())
} }
// TODO: implement seek in BYTES format // 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(); let mut state = self.state.lock().unwrap();
if let State::Started { .. } = *state { if let State::Started { .. } = *state {
unreachable!("FileSrc already started"); unreachable!("FileSrc already started");
} }
let settings = self.settings.lock().unwrap(); let settings = self.settings.lock().unwrap();
let location = match settings.location { let location = settings.location.as_ref().ok_or_else(|| {
Some(ref location) => location, gst_error_msg!(
None => { gst::ResourceError::Settings,
gst_element_error!( ["File location is not defined"]
element, )
gst::CoreError::StateChange, })?;
["File location is not defined"]
);
return false;
}
};
let file = match File::open(location) { let file = File::open(location).map_err(|err| {
Ok(file) => file, gst_error_msg!(
Err(err) => { gst::ResourceError::OpenRead,
gst_element_error!( [
element, "Could not open file {} for reading: {}",
gst::ResourceError::OpenRead, location,
[ err.to_string(),
"Could not open file {} for reading: {}", ]
location, )
err.to_string(), })?;
]
);
return false;
}
};
gst_debug!(self.cat, obj: element, "Opened file {:?}", file); gst_debug!(self.cat, obj: element, "Opened file {:?}", file);
@ -274,25 +264,23 @@ impl BaseSrcImpl for FileSrc {
gst_info!(self.cat, obj: element, "Started"); 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(); let mut state = self.state.lock().unwrap();
if let State::Stopped = *state { if let State::Stopped = *state {
gst_element_warning!( return Err(gst_error_msg!(
element, gst::ResourceError::Settings,
gst::CoreError::StateChange, ["FileSrc not started"]
["FileSink not started"] ));
);
return false;
} }
*state = State::Stopped; *state = State::Stopped;
gst_info!(self.cat, obj: element, "Stopped"); gst_info!(self.cat, obj: element, "Stopped");
true Ok(())
} }
fn fill( 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(); let mut state = self.state.lock().unwrap();
*state = State::Stopped; *state = State::Stopped;
let uri = match self.settings.lock().unwrap().location { let uri = self
Some(ref uri) => uri.clone(), .settings
None => { .lock()
gst_element_error!( .unwrap()
src, .location
gst::CoreError::StateChange, .as_ref()
["Can't start without an URI"] .ok_or_else(|| {
); gst_error_msg!(gst::CoreError::StateChange, ["Can't start without an URI"])
return false; })
} .map(|uri| uri.clone())?;
};
match self.do_request(src, uri, 0, None) { *state = self.do_request(src, uri, 0, None)?;
Ok(s) => {
*state = s; Ok(())
true
}
Err(err) => {
src.post_error_message(&err);
false
}
}
} }
fn stop(&self, _src: &gst_base::BaseSrc) -> bool { fn stop(&self, _src: &gst_base::BaseSrc) -> Result<(), gst::ErrorMessage> {
*self.state.lock().unwrap() = State::Stopped; *self.state.lock().unwrap() = State::Stopped;
true Ok(())
} }
fn do_seek(&self, src: &gst_base::BaseSrc, segment: &mut gst::Segment) -> bool { 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 // 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 // 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 // Drop state
let _ = self.state.lock().unwrap().take(); let _ = self.state.lock().unwrap().take();
gst_info!(self.cat, obj: element, "Stopped"); gst_info!(self.cat, obj: element, "Stopped");
true Ok(())
} }
// Does the actual transformation of the input buffer to the output buffer // 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 // We simply remember the resulting AudioInfo from the caps to be able to use this for knowing
// the sample rate, etc. when creating buffers // 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; use std::f64::consts::PI;
let info = match gst_audio::AudioInfo::from_caps(caps) { let info = gst_audio::AudioInfo::from_caps(caps).ok_or_else(|| {
None => return false, gst_loggable_error!(self.cat, "Failed to build `AudioInfo` from caps {}", caps)
Some(info) => info, })?;
};
gst_debug!(self.cat, obj: element, "Configuring for 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()); 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 // 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 // Reset state
*self.state.lock().unwrap() = Default::default(); *self.state.lock().unwrap() = Default::default();
self.unlock_stop(element); self.unlock_stop(element)?;
gst_info!(self.cat, obj: element, "Started"); gst_info!(self.cat, obj: element, "Started");
true Ok(())
} }
// Called when shutting down the element so we can release all stream-related state // 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 // Reset state
*self.state.lock().unwrap() = Default::default(); *self.state.lock().unwrap() = Default::default();
self.unlock(element); self.unlock(element)?;
gst_info!(self.cat, obj: element, "Stopped"); gst_info!(self.cat, obj: element, "Stopped");
true Ok(())
} }
fn query(&self, element: &gst_base::BaseSrc, query: &mut gst::QueryRef) -> bool { 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 // This should unblock the create() function ASAP, so we
// just unschedule the clock it here, if any. // just unschedule the clock it here, if any.
gst_debug!(self.cat, obj: element, "Unlocking"); gst_debug!(self.cat, obj: element, "Unlocking");
@ -837,17 +840,17 @@ impl BaseSrcImpl for SineSrc {
} }
clock_wait.flushing = true; 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 // This signals that unlocking is done, so we can reset
// all values again. // all values again.
gst_debug!(self.cat, obj: element, "Unlock stop"); gst_debug!(self.cat, obj: element, "Unlock stop");
let mut clock_wait = self.clock_wait.lock().unwrap(); let mut clock_wait = self.clock_wait.lock().unwrap();
clock_wait.flushing = false; clock_wait.flushing = false;
true Ok(())
} }
} }