Commit e930133b authored by François Laignel's avatar François Laignel

Update for gstreamer-rs MR 200

See gstreamer-rs!200
parent abe87fae
......@@ -254,20 +254,14 @@ impl BaseTransformImpl for AudioEcho {
&self,
_element: &gst_base::BaseTransform,
buf: &mut gst::BufferRef,
) -> gst::FlowReturn {
) -> Result<gst::FlowSuccess, gst::FlowError> {
let mut settings = *self.settings.lock().unwrap();
settings.delay = cmp::min(settings.max_delay, settings.delay);
let mut state_guard = self.state.lock().unwrap();
let state = match *state_guard {
None => return gst::FlowReturn::NotNegotiated,
Some(ref mut state) => state,
};
let state = state_guard.as_mut().ok_or(gst::FlowError::NotNegotiated)?;
let mut map = match buf.map_writable() {
None => return gst::FlowReturn::Error,
Some(map) => map,
};
let mut map = buf.map_writable().ok_or(gst::FlowError::Error)?;
match state.info.format() {
gst_audio::AUDIO_FORMAT_F64 => {
......@@ -278,10 +272,10 @@ impl BaseTransformImpl for AudioEcho {
let data = map.as_mut_slice_of::<f32>().unwrap();
Self::process(data, state, &settings);
}
_ => return gst::FlowReturn::NotNegotiated,
_ => return Err(gst::FlowError::NotNegotiated),
}
gst::FlowReturn::Ok
Ok(gst::FlowSuccess::Ok)
}
fn set_caps(
......
......@@ -265,7 +265,11 @@ impl BaseSinkImpl for FileSink {
// TODO: implement seek in BYTES format
fn render(&self, element: &gst_base::BaseSink, buffer: &gst::BufferRef) -> gst::FlowReturn {
fn render(
&self,
element: &gst_base::BaseSink,
buffer: &gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
let mut state = self.state.lock().unwrap();
let (file, position) = match *state {
State::Started {
......@@ -274,35 +278,28 @@ impl BaseSinkImpl for FileSink {
} => (file, position),
State::Stopped => {
gst_element_error!(element, gst::CoreError::Failed, ["Not started yet"]);
return gst::FlowReturn::Error;
return Err(gst::FlowError::Error);
}
};
gst_trace!(self.cat, obj: element, "Rendering {:?}", buffer);
let map = match buffer.map_readable() {
None => {
gst_element_error!(element, gst::CoreError::Failed, ["Failed to map buffer"]);
return gst::FlowReturn::Error;
}
Some(map) => map,
};
let map = buffer.map_readable().ok_or_else(|| {
gst_element_error!(element, gst::CoreError::Failed, ["Failed to map buffer"]);
gst::FlowError::Error
})?;
match file.write_all(map.as_ref()) {
Ok(()) => {
*position += map.len() as u64;
file.write_all(map.as_ref()).map_err(|err| {
gst_element_error!(
element,
gst::ResourceError::Write,
["Failed to write buffer: {}", err]
);
gst::FlowError::Error
})?;
gst::FlowReturn::Ok
}
Err(err) => {
gst_element_error!(
element,
gst::ResourceError::Write,
["Failed to write buffer: {}", err]
);
*position += map.len() as u64;
gst::FlowReturn::Error
}
}
Ok(gst::FlowSuccess::Ok)
}
}
......
......@@ -306,7 +306,7 @@ impl BaseSrcImpl for FileSrc {
offset: u64,
_length: u32,
buffer: &mut gst::BufferRef,
) -> gst::FlowReturn {
) -> Result<gst::FlowSuccess, gst::FlowError> {
let mut state = self.state.lock().unwrap();
let (file, position) = match *state {
......@@ -316,54 +316,44 @@ impl BaseSrcImpl for FileSrc {
} => (file, position),
State::Stopped => {
gst_element_error!(element, gst::CoreError::Failed, ["Not started yet"]);
return gst::FlowReturn::Error;
return Err(gst::FlowError::Error);
}
};
if *position != offset {
if let Err(err) = file.seek(SeekFrom::Start(offset)) {
file.seek(SeekFrom::Start(offset)).map_err(|err| {
gst_element_error!(
element,
gst::LibraryError::Failed,
["Failed to seek to {}: {}", offset, err.to_string()]
);
return gst::FlowReturn::Error;
}
gst::FlowError::Error
})?;
*position = offset;
}
let size = {
let mut map = match buffer.map_writable() {
Some(map) => map,
None => {
gst_element_error!(
element,
gst::LibraryError::Failed,
["Failed to map buffer"]
);
return gst::FlowReturn::Error;
}
};
match file.read(map.as_mut()) {
Ok(size) => size,
Err(err) => {
gst_element_error!(
element,
gst::LibraryError::Failed,
["Failed to read at {}: {}", offset, err.to_string()]
);
return gst::FlowReturn::Error;
}
}
let mut map = buffer.map_writable().ok_or_else(|| {
gst_element_error!(element, gst::LibraryError::Failed, ["Failed to map buffer"]);
gst::FlowError::Error
})?;
file.read(map.as_mut()).map_err(|err| {
gst_element_error!(
element,
gst::LibraryError::Failed,
["Failed to read at {}: {}", offset, err.to_string()]
);
gst::FlowError::Error
})?
};
*position += size as u64;
buffer.set_size(size);
gst::FlowReturn::Ok
Ok(gst::FlowSuccess::Ok)
}
}
......
......@@ -158,7 +158,7 @@ impl ObjectSubclass for FlvDemux {
sinkpad.set_chain_function(|pad, parent, buffer| {
FlvDemux::catch_panic_pad_function(
parent,
|| gst::FlowReturn::Error,
|| Err(gst::FlowError::Error),
|demux, element| demux.sink_chain(pad, element, buffer),
)
});
......@@ -461,7 +461,7 @@ impl FlvDemux {
pad: &gst::Pad,
element: &gst::Element,
buffer: gst::Buffer,
) -> gst::FlowReturn {
) -> Result<gst::FlowSuccess, gst::FlowError> {
gst_log!(CAT, obj: pad, "Handling buffer {:?}", buffer);
let mut adapter = self.adapter.lock().unwrap();
......@@ -476,7 +476,7 @@ impl FlvDemux {
Ok(header) => header,
Err(_) => {
gst_trace!(CAT, obj: element, "Need more data");
return gst::FlowReturn::Ok;
return Ok(gst::FlowSuccess::Ok);
}
};
......@@ -505,7 +505,7 @@ impl FlvDemux {
let avail = adapter.available();
if avail == 0 {
gst_trace!(CAT, obj: element, "Need more data");
return gst::FlowReturn::Ok;
return Ok(gst::FlowSuccess::Ok);
}
let skip = cmp::min(avail, *skip_left as usize);
adapter.flush(skip);
......@@ -517,22 +517,20 @@ impl FlvDemux {
match res {
Ok(None) => {
gst_trace!(CAT, obj: element, "Need more data");
return gst::FlowReturn::Ok;
return Ok(gst::FlowSuccess::Ok);
}
Ok(Some(events)) => {
drop(state);
drop(adapter);
if let Err(err) = self.handle_events(element, events) {
return err.into();
}
self.handle_events(element, events)?;
adapter = self.adapter.lock().unwrap();
state = self.state.lock().unwrap();
}
Err(err) => {
element.post_error_message(&err);
return gst::FlowReturn::Error;
return Err(gst::FlowError::Error);
}
}
}
......@@ -622,8 +620,7 @@ impl FlvDemux {
self.flow_combiner
.lock()
.unwrap()
.update_pad_flow(&pad, res)
.into_result()?;
.update_pad_flow(&pad, res)?;
}
}
Event::HaveAllStreams => {
......
......@@ -350,7 +350,7 @@ impl BaseSrcImpl for HttpSrc {
offset: u64,
_: u32,
buffer: &mut gst::BufferRef,
) -> gst::FlowReturn {
) -> Result<gst::FlowSuccess, gst::FlowError> {
let mut state = self.state.lock().unwrap();
let (response, position) = match *state {
......@@ -362,7 +362,7 @@ impl BaseSrcImpl for HttpSrc {
State::Stopped => {
gst_element_error!(src, gst::LibraryError::Failed, ["Not started yet"]);
return gst::FlowReturn::Error;
return Err(gst::FlowError::Error);
}
};
......@@ -373,45 +373,39 @@ impl BaseSrcImpl for HttpSrc {
["Got unexpected offset {}, expected {}", offset, position]
);
return gst::FlowReturn::Error;
return Err(gst::FlowError::Error);
}
let size = {
let mut map = match buffer.map_writable() {
None => {
gst_element_error!(src, gst::LibraryError::Failed, ["Failed to map buffer"]);
let mut map = buffer.map_writable().ok_or_else(|| {
gst_element_error!(src, gst::LibraryError::Failed, ["Failed to map buffer"]);
return gst::FlowReturn::Error;
}
Some(map) => map,
};
gst::FlowError::Error
})?;
let data = map.as_mut_slice();
match response.read(data) {
Ok(size) => size,
Err(err) => {
gst_error!(self.cat, obj: src, "Failed to read: {:?}", err);
gst_element_error!(
src,
gst::ResourceError::Read,
["Failed to read at {}: {}", offset, err.to_string()]
);
response.read(data).map_err(|err| {
gst_error!(self.cat, obj: src, "Failed to read: {:?}", err);
gst_element_error!(
src,
gst::ResourceError::Read,
["Failed to read at {}: {}", offset, err.to_string()]
);
return gst::FlowReturn::Error;
}
}
gst::FlowError::Error
})?
};
if size == 0 {
return gst::FlowReturn::Eos;
return Err(gst::FlowError::Eos);
}
*position += size as u64;
buffer.set_size(size);
gst::FlowReturn::Ok
Ok(gst::FlowSuccess::Ok)
}
}
......
......@@ -13,6 +13,7 @@ gstreamer-sys = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-s
glib = { git = "https://github.com/gtk-rs/glib", features = ["subclassing"] }
gio = { git = "https://github.com/gtk-rs/gio" }
gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["subclassing"] }
gstreamer-app = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
gstreamer-check = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
tokio = "0.1"
tokio-reactor = "0.1"
......
......@@ -164,10 +164,7 @@ fn main() {
glib::Continue(true)
});
assert_ne!(
pipeline.set_state(gst::State::Playing),
gst::StateChangeReturn::Failure
);
pipeline.set_state(gst::State::Playing).unwrap();
println!("started");
......
......@@ -173,9 +173,9 @@ impl AppSrc {
true
}
EventView::FlushStop(..) => {
let (ret, state, pending) = element.get_state(0.into());
if ret == gst::StateChangeReturn::Success && state == gst::State::Playing
|| ret == gst::StateChangeReturn::Async && pending == gst::State::Playing
let (res, state, pending) = element.get_state(0.into());
if res == Ok(gst::StateChangeSuccess::Success) && state == gst::State::Playing
|| res == Ok(gst::StateChangeSuccess::Async) && pending == gst::State::Playing
{
let _ = self.start(element);
}
......@@ -331,7 +331,7 @@ impl AppSrc {
let res = match item {
Either::Left(buffer) => {
gst_log!(self.cat, obj: element, "Forwarding buffer {:?}", buffer);
self.src_pad.push(buffer).into_result().map(|_| ())
self.src_pad.push(buffer).map(|_| ())
}
Either::Right(event) => {
gst_log!(self.cat, obj: element, "Forwarding event {:?}", event);
......@@ -638,41 +638,34 @@ impl ElementImpl for AppSrc {
&self,
element: &gst::Element,
transition: gst::StateChange,
) -> gst::StateChangeReturn {
) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
gst_trace!(self.cat, obj: element, "Changing state {:?}", transition);
match transition {
gst::StateChange::NullToReady => match self.prepare(element) {
Err(err) => {
gst::StateChange::NullToReady => {
self.prepare(element).map_err(|err| {
element.post_error_message(&err);
return gst::StateChangeReturn::Failure;
}
Ok(_) => (),
},
gst::StateChange::PlayingToPaused => match self.stop(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
gst::StateChange::ReadyToNull => match self.unprepare(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
gst::StateChangeError
})?;
}
gst::StateChange::PlayingToPaused => {
self.stop(element).map_err(|_| gst::StateChangeError)?;
}
gst::StateChange::ReadyToNull => {
self.unprepare(element).map_err(|_| gst::StateChangeError)?;
}
_ => (),
}
let mut ret = self.parent_change_state(element, transition);
if ret == gst::StateChangeReturn::Failure {
return ret;
}
let mut success = self.parent_change_state(element, transition)?;
match transition {
gst::StateChange::ReadyToPaused => {
ret = gst::StateChangeReturn::NoPreroll;
success = gst::StateChangeSuccess::NoPreroll;
}
gst::StateChange::PausedToPlaying => {
self.start(element).map_err(|_| gst::StateChangeError)?;
}
gst::StateChange::PausedToPlaying => match self.start(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
gst::StateChange::PausedToReady => {
let mut state = self.state.lock().unwrap();
state.need_initial_events = true;
......@@ -680,7 +673,7 @@ impl ElementImpl for AppSrc {
_ => (),
}
ret
Ok(success)
}
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -211,9 +211,9 @@ impl TcpClientSrc {
true
}
EventView::FlushStop(..) => {
let (ret, state, pending) = element.get_state(0.into());
if ret == gst::StateChangeReturn::Success && state == gst::State::Playing
|| ret == gst::StateChangeReturn::Async && pending == gst::State::Playing
let (res, state, pending) = element.get_state(0.into());
if res == Ok(gst::StateChangeSuccess::Success) && state == gst::State::Playing
|| res == Ok(gst::StateChangeSuccess::Async) && pending == gst::State::Playing
{
let _ = self.start(element);
}
......@@ -341,7 +341,7 @@ impl TcpClientSrc {
self.src_pad.push_event(event);
}
let res = match self.src_pad.push(buffer).into_result() {
let res = match self.src_pad.push(buffer) {
Ok(_) => {
gst_log!(self.cat, obj: element, "Successfully pushed buffer");
Ok(())
......@@ -706,38 +706,31 @@ impl ElementImpl for TcpClientSrc {
&self,
element: &gst::Element,
transition: gst::StateChange,
) -> gst::StateChangeReturn {
) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
gst_trace!(self.cat, obj: element, "Changing state {:?}", transition);
match transition {
gst::StateChange::NullToReady => match self.prepare(element) {
Err(err) => {
element.post_error_message(&err);
return gst::StateChangeReturn::Failure;
}
Ok(_) => match self.start(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
},
gst::StateChange::PlayingToPaused => match self.stop(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => match self.unprepare(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
},
gst::StateChange::NullToReady => {
self.prepare(element)
.map_err(|err| {
element.post_error_message(&err);
gst::StateChangeError
})
.and_then(|_| self.start(element).map_err(|_| gst::StateChangeError))?;
}
gst::StateChange::PlayingToPaused => {
self.stop(element)
.and_then(|_| self.unprepare(element))
.map_err(|_| gst::StateChangeError)?;
}
_ => (),
}
let mut ret = self.parent_change_state(element, transition);
if ret == gst::StateChangeReturn::Failure {
return ret;
}
let mut success = self.parent_change_state(element, transition)?;
match transition {
gst::StateChange::ReadyToPaused => {
ret = gst::StateChangeReturn::Success;
success = gst::StateChangeSuccess::Success;
}
gst::StateChange::PausedToReady => {
let mut state = self.state.lock().unwrap();
......@@ -746,7 +739,7 @@ impl ElementImpl for TcpClientSrc {
_ => (),
}
ret
Ok(success)
}
}
......
......@@ -328,9 +328,9 @@ impl UdpSrc {
true
}
EventView::FlushStop(..) => {
let (ret, state, pending) = element.get_state(0.into());
if ret == gst::StateChangeReturn::Success && state == gst::State::Playing
|| ret == gst::StateChangeReturn::Async && pending == gst::State::Playing
let (res, state, pending) = element.get_state(0.into());
if res == Ok(gst::StateChangeSuccess::Success) && state == gst::State::Playing
|| res == Ok(gst::StateChangeSuccess::Async) && pending == gst::State::Playing
{
let _ = self.start(element);
}
......@@ -453,7 +453,7 @@ impl UdpSrc {
self.src_pad.push_event(event);
}
let res = match self.src_pad.push(buffer).into_result() {
let res = match self.src_pad.push(buffer) {
Ok(_) => {
gst_log!(self.cat, obj: element, "Successfully pushed buffer");
Ok(())
......@@ -1024,41 +1024,34 @@ impl ElementImpl for UdpSrc {
&self,
element: &gst::Element,
transition: gst::StateChange,
) -> gst::StateChangeReturn {
) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
gst_trace!(self.cat, obj: element, "Changing state {:?}", transition);
match transition {
gst::StateChange::NullToReady => match self.prepare(element) {
Err(err) => {
gst::StateChange::NullToReady => {
self.prepare(element).map_err(|err| {
element.post_error_message(&err);
return gst::StateChangeReturn::Failure;
}
Ok(_) => (),
},
gst::StateChange::PlayingToPaused => match self.stop(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
gst::StateChange::ReadyToNull => match self.unprepare(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
gst::StateChangeError
})?;
}
gst::StateChange::PlayingToPaused => {
self.stop(element).map_err(|_| gst::StateChangeError)?;
}
gst::StateChange::ReadyToNull => {
self.unprepare(element).map_err(|_| gst::StateChangeError)?;
}
_ => (),
}
let mut ret = self.parent_change_state(element, transition);
if ret == gst::StateChangeReturn::Failure {
return ret;
}
let mut success = self.parent_change_state(element, transition)?;
match transition {
gst::StateChange::ReadyToPaused => {
ret = gst::StateChangeReturn::NoPreroll;
success = gst::StateChangeSuccess::NoPreroll;
}
gst::StateChange::PausedToPlaying => {
self.start(element).map_err(|_| gst::StateChangeError)?;
}
gst::StateChange::PausedToPlaying => match self.start(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
gst::StateChange::PausedToReady => {
let mut state = self.state.lock().unwrap();
state.need_initial_events = true;
......@@ -1066,7 +1059,7 @@ impl ElementImpl for UdpSrc {
_ => (),
}
ret
Ok(success)
}
}
......
......@@ -21,6 +21,8 @@ use glib::prelude::*;
extern crate gstreamer as gst;
use gst::prelude::*;
extern crate gstreamer_app as gst_app;
use std::sync::{Arc, Mutex};
extern crate gstthreadshare;
......@@ -59,28 +61,22 @@ fn test_push() {
let samples = Arc::new(Mutex::new(Vec::new()));
let appsink = appsink.dynamic_cast::<gst_app::AppSink>().unwrap();
let samples_clone = samples.clone();
appsink
.connect("new-sample", true, move |args| {
let appsink = args[0].get::<gst::Element>().unwrap();
let sample = appsink
.emit("pull-sample", &[])
.unwrap()
.unwrap()
.get::<gst::Sample>()
.unwrap();
appsink.connect_new_sample(move |appsink| {
let sample = appsink
.emit("pull-sample", &[])
.unwrap()
.unwrap()
.get::<gst::Sample>()
.unwrap();
samples_clone.lock().unwrap().push(sample);
samples_clone.lock().unwrap().push(sample);
Some(gst::FlowReturn::Ok.to_value())
})
.unwrap();
Ok(gst::FlowSuccess::Ok)
});
pipeline
.set_state(gst::State::Playing)
.into_result()
.unwrap();
pipeline.set_state(gst::State::Playing).unwrap();
let mut eos = false;
let bus = pipeline.get_bus().unwrap();
......@@ -104,5 +100,5 @@ fn test_push() {
assert!(sample.get_buffer().is_some());
}
pipeline.set_state(gst::State::Null).into_result().unwrap();
pipeline.set_state(gst::State::Null).unwrap();
}
......@@ -21,6 +21,8 @@ use glib::prelude::*;
extern crate gstreamer as gst;
use gst::prelude::*;
extern crate gstreamer_app as gst_app;
use std::sync::{Arc, Mutex};
extern crate gstthreadshare;
......@@ -54,28 +56,22 @@ fn test_push() {
let samples = Arc::new(Mutex::new(Vec::new()));
let appsink = appsink.dynamic_cast::<gst_app::AppSink>().unwrap();
let samples_clone = samples.clone();