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

Update for gstreamer-rs MR 200

See gstreamer/gstreamer-rs!200
parent abe87fae
...@@ -254,20 +254,14 @@ impl BaseTransformImpl for AudioEcho { ...@@ -254,20 +254,14 @@ impl BaseTransformImpl for AudioEcho {
&self, &self,
_element: &gst_base::BaseTransform, _element: &gst_base::BaseTransform,
buf: &mut gst::BufferRef, buf: &mut gst::BufferRef,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let mut settings = *self.settings.lock().unwrap(); let mut settings = *self.settings.lock().unwrap();
settings.delay = cmp::min(settings.max_delay, settings.delay); settings.delay = cmp::min(settings.max_delay, settings.delay);
let mut state_guard = self.state.lock().unwrap(); let mut state_guard = self.state.lock().unwrap();
let state = match *state_guard { let state = state_guard.as_mut().ok_or(gst::FlowError::NotNegotiated)?;
None => return gst::FlowReturn::NotNegotiated,
Some(ref mut state) => state,
};
let mut map = match buf.map_writable() { let mut map = buf.map_writable().ok_or(gst::FlowError::Error)?;
None => return gst::FlowReturn::Error,
Some(map) => map,
};
match state.info.format() { match state.info.format() {
gst_audio::AUDIO_FORMAT_F64 => { gst_audio::AUDIO_FORMAT_F64 => {
...@@ -278,10 +272,10 @@ impl BaseTransformImpl for AudioEcho { ...@@ -278,10 +272,10 @@ impl BaseTransformImpl for AudioEcho {
let data = map.as_mut_slice_of::<f32>().unwrap(); let data = map.as_mut_slice_of::<f32>().unwrap();
Self::process(data, state, &settings); Self::process(data, state, &settings);
} }
_ => return gst::FlowReturn::NotNegotiated, _ => return Err(gst::FlowError::NotNegotiated),
} }
gst::FlowReturn::Ok Ok(gst::FlowSuccess::Ok)
} }
fn set_caps( fn set_caps(
......
...@@ -265,7 +265,11 @@ impl BaseSinkImpl for FileSink { ...@@ -265,7 +265,11 @@ impl BaseSinkImpl for FileSink {
// TODO: implement seek in BYTES format // 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 mut state = self.state.lock().unwrap();
let (file, position) = match *state { let (file, position) = match *state {
State::Started { State::Started {
...@@ -274,35 +278,28 @@ impl BaseSinkImpl for FileSink { ...@@ -274,35 +278,28 @@ impl BaseSinkImpl for FileSink {
} => (file, position), } => (file, position),
State::Stopped => { State::Stopped => {
gst_element_error!(element, gst::CoreError::Failed, ["Not started yet"]); 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); gst_trace!(self.cat, obj: element, "Rendering {:?}", buffer);
let map = match buffer.map_readable() { let map = buffer.map_readable().ok_or_else(|| {
None => {
gst_element_error!(element, gst::CoreError::Failed, ["Failed to map buffer"]); gst_element_error!(element, gst::CoreError::Failed, ["Failed to map buffer"]);
return gst::FlowReturn::Error; gst::FlowError::Error
} })?;
Some(map) => map,
};
match file.write_all(map.as_ref()) {
Ok(()) => {
*position += map.len() as u64;
gst::FlowReturn::Ok file.write_all(map.as_ref()).map_err(|err| {
}
Err(err) => {
gst_element_error!( gst_element_error!(
element, element,
gst::ResourceError::Write, gst::ResourceError::Write,
["Failed to write buffer: {}", err] ["Failed to write buffer: {}", err]
); );
gst::FlowError::Error
})?;
gst::FlowReturn::Error *position += map.len() as u64;
}
} Ok(gst::FlowSuccess::Ok)
} }
} }
......
...@@ -306,7 +306,7 @@ impl BaseSrcImpl for FileSrc { ...@@ -306,7 +306,7 @@ impl BaseSrcImpl for FileSrc {
offset: u64, offset: u64,
_length: u32, _length: u32,
buffer: &mut gst::BufferRef, buffer: &mut gst::BufferRef,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
let (file, position) = match *state { let (file, position) = match *state {
...@@ -316,54 +316,44 @@ impl BaseSrcImpl for FileSrc { ...@@ -316,54 +316,44 @@ impl BaseSrcImpl for FileSrc {
} => (file, position), } => (file, position),
State::Stopped => { State::Stopped => {
gst_element_error!(element, gst::CoreError::Failed, ["Not started yet"]); gst_element_error!(element, gst::CoreError::Failed, ["Not started yet"]);
return gst::FlowReturn::Error; return Err(gst::FlowError::Error);
} }
}; };
if *position != offset { if *position != offset {
if let Err(err) = file.seek(SeekFrom::Start(offset)) { file.seek(SeekFrom::Start(offset)).map_err(|err| {
gst_element_error!( gst_element_error!(
element, element,
gst::LibraryError::Failed, gst::LibraryError::Failed,
["Failed to seek to {}: {}", offset, err.to_string()] ["Failed to seek to {}: {}", offset, err.to_string()]
); );
return gst::FlowReturn::Error; gst::FlowError::Error
} })?;
*position = offset; *position = offset;
} }
let size = { let size = {
let mut map = match buffer.map_writable() { let mut map = buffer.map_writable().ok_or_else(|| {
Some(map) => map, gst_element_error!(element, gst::LibraryError::Failed, ["Failed to map buffer"]);
None => { gst::FlowError::Error
gst_element_error!( })?;
element,
gst::LibraryError::Failed,
["Failed to map buffer"]
);
return gst::FlowReturn::Error;
}
};
match file.read(map.as_mut()) { file.read(map.as_mut()).map_err(|err| {
Ok(size) => size,
Err(err) => {
gst_element_error!( gst_element_error!(
element, element,
gst::LibraryError::Failed, gst::LibraryError::Failed,
["Failed to read at {}: {}", offset, err.to_string()] ["Failed to read at {}: {}", offset, err.to_string()]
); );
return gst::FlowReturn::Error; gst::FlowError::Error
} })?
}
}; };
*position += size as u64; *position += size as u64;
buffer.set_size(size); buffer.set_size(size);
gst::FlowReturn::Ok Ok(gst::FlowSuccess::Ok)
} }
} }
......
...@@ -158,7 +158,7 @@ impl ObjectSubclass for FlvDemux { ...@@ -158,7 +158,7 @@ impl ObjectSubclass for FlvDemux {
sinkpad.set_chain_function(|pad, parent, buffer| { sinkpad.set_chain_function(|pad, parent, buffer| {
FlvDemux::catch_panic_pad_function( FlvDemux::catch_panic_pad_function(
parent, parent,
|| gst::FlowReturn::Error, || Err(gst::FlowError::Error),
|demux, element| demux.sink_chain(pad, element, buffer), |demux, element| demux.sink_chain(pad, element, buffer),
) )
}); });
...@@ -461,7 +461,7 @@ impl FlvDemux { ...@@ -461,7 +461,7 @@ impl FlvDemux {
pad: &gst::Pad, pad: &gst::Pad,
element: &gst::Element, element: &gst::Element,
buffer: gst::Buffer, buffer: gst::Buffer,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
gst_log!(CAT, obj: pad, "Handling buffer {:?}", buffer); gst_log!(CAT, obj: pad, "Handling buffer {:?}", buffer);
let mut adapter = self.adapter.lock().unwrap(); let mut adapter = self.adapter.lock().unwrap();
...@@ -476,7 +476,7 @@ impl FlvDemux { ...@@ -476,7 +476,7 @@ impl FlvDemux {
Ok(header) => header, Ok(header) => header,
Err(_) => { Err(_) => {
gst_trace!(CAT, obj: element, "Need more data"); gst_trace!(CAT, obj: element, "Need more data");
return gst::FlowReturn::Ok; return Ok(gst::FlowSuccess::Ok);
} }
}; };
...@@ -505,7 +505,7 @@ impl FlvDemux { ...@@ -505,7 +505,7 @@ impl FlvDemux {
let avail = adapter.available(); let avail = adapter.available();
if avail == 0 { if avail == 0 {
gst_trace!(CAT, obj: element, "Need more data"); 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); let skip = cmp::min(avail, *skip_left as usize);
adapter.flush(skip); adapter.flush(skip);
...@@ -517,22 +517,20 @@ impl FlvDemux { ...@@ -517,22 +517,20 @@ impl FlvDemux {
match res { match res {
Ok(None) => { Ok(None) => {
gst_trace!(CAT, obj: element, "Need more data"); gst_trace!(CAT, obj: element, "Need more data");
return gst::FlowReturn::Ok; return Ok(gst::FlowSuccess::Ok);
} }
Ok(Some(events)) => { Ok(Some(events)) => {
drop(state); drop(state);
drop(adapter); drop(adapter);
if let Err(err) = self.handle_events(element, events) { self.handle_events(element, events)?;
return err.into();
}
adapter = self.adapter.lock().unwrap(); adapter = self.adapter.lock().unwrap();
state = self.state.lock().unwrap(); state = self.state.lock().unwrap();
} }
Err(err) => { Err(err) => {
element.post_error_message(&err); element.post_error_message(&err);
return gst::FlowReturn::Error; return Err(gst::FlowError::Error);
} }
} }
} }
...@@ -622,8 +620,7 @@ impl FlvDemux { ...@@ -622,8 +620,7 @@ impl FlvDemux {
self.flow_combiner self.flow_combiner
.lock() .lock()
.unwrap() .unwrap()
.update_pad_flow(&pad, res) .update_pad_flow(&pad, res)?;
.into_result()?;
} }
} }
Event::HaveAllStreams => { Event::HaveAllStreams => {
......
...@@ -350,7 +350,7 @@ impl BaseSrcImpl for HttpSrc { ...@@ -350,7 +350,7 @@ impl BaseSrcImpl for HttpSrc {
offset: u64, offset: u64,
_: u32, _: u32,
buffer: &mut gst::BufferRef, buffer: &mut gst::BufferRef,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
let (response, position) = match *state { let (response, position) = match *state {
...@@ -362,7 +362,7 @@ impl BaseSrcImpl for HttpSrc { ...@@ -362,7 +362,7 @@ impl BaseSrcImpl for HttpSrc {
State::Stopped => { State::Stopped => {
gst_element_error!(src, gst::LibraryError::Failed, ["Not started yet"]); gst_element_error!(src, gst::LibraryError::Failed, ["Not started yet"]);
return gst::FlowReturn::Error; return Err(gst::FlowError::Error);
} }
}; };
...@@ -373,24 +373,19 @@ impl BaseSrcImpl for HttpSrc { ...@@ -373,24 +373,19 @@ impl BaseSrcImpl for HttpSrc {
["Got unexpected offset {}, expected {}", offset, position] ["Got unexpected offset {}, expected {}", offset, position]
); );
return gst::FlowReturn::Error; return Err(gst::FlowError::Error);
} }
let size = { let size = {
let mut map = match buffer.map_writable() { let mut map = buffer.map_writable().ok_or_else(|| {
None => {
gst_element_error!(src, gst::LibraryError::Failed, ["Failed to map buffer"]); gst_element_error!(src, gst::LibraryError::Failed, ["Failed to map buffer"]);
return gst::FlowReturn::Error; gst::FlowError::Error
} })?;
Some(map) => map,
};
let data = map.as_mut_slice(); let data = map.as_mut_slice();
match response.read(data) { response.read(data).map_err(|err| {
Ok(size) => size,
Err(err) => {
gst_error!(self.cat, obj: src, "Failed to read: {:?}", err); gst_error!(self.cat, obj: src, "Failed to read: {:?}", err);
gst_element_error!( gst_element_error!(
src, src,
...@@ -398,20 +393,19 @@ impl BaseSrcImpl for HttpSrc { ...@@ -398,20 +393,19 @@ impl BaseSrcImpl for HttpSrc {
["Failed to read at {}: {}", offset, err.to_string()] ["Failed to read at {}: {}", offset, err.to_string()]
); );
return gst::FlowReturn::Error; gst::FlowError::Error
} })?
}
}; };
if size == 0 { if size == 0 {
return gst::FlowReturn::Eos; return Err(gst::FlowError::Eos);
} }
*position += size as u64; *position += size as u64;
buffer.set_size(size); 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 ...@@ -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"] } glib = { git = "https://github.com/gtk-rs/glib", features = ["subclassing"] }
gio = { git = "https://github.com/gtk-rs/gio" } gio = { git = "https://github.com/gtk-rs/gio" }
gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["subclassing"] } 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" } gstreamer-check = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
tokio = "0.1" tokio = "0.1"
tokio-reactor = "0.1" tokio-reactor = "0.1"
......
...@@ -164,10 +164,7 @@ fn main() { ...@@ -164,10 +164,7 @@ fn main() {
glib::Continue(true) glib::Continue(true)
}); });
assert_ne!( pipeline.set_state(gst::State::Playing).unwrap();
pipeline.set_state(gst::State::Playing),
gst::StateChangeReturn::Failure
);
println!("started"); println!("started");
......
...@@ -173,9 +173,9 @@ impl AppSrc { ...@@ -173,9 +173,9 @@ impl AppSrc {
true true
} }
EventView::FlushStop(..) => { EventView::FlushStop(..) => {
let (ret, state, pending) = element.get_state(0.into()); let (res, state, pending) = element.get_state(0.into());
if ret == gst::StateChangeReturn::Success && state == gst::State::Playing if res == Ok(gst::StateChangeSuccess::Success) && state == gst::State::Playing
|| ret == gst::StateChangeReturn::Async && pending == gst::State::Playing || res == Ok(gst::StateChangeSuccess::Async) && pending == gst::State::Playing
{ {
let _ = self.start(element); let _ = self.start(element);
} }
...@@ -331,7 +331,7 @@ impl AppSrc { ...@@ -331,7 +331,7 @@ impl AppSrc {
let res = match item { let res = match item {
Either::Left(buffer) => { Either::Left(buffer) => {
gst_log!(self.cat, obj: element, "Forwarding buffer {:?}", 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) => { Either::Right(event) => {
gst_log!(self.cat, obj: element, "Forwarding event {:?}", event); gst_log!(self.cat, obj: element, "Forwarding event {:?}", event);
...@@ -638,41 +638,34 @@ impl ElementImpl for AppSrc { ...@@ -638,41 +638,34 @@ impl ElementImpl for AppSrc {
&self, &self,
element: &gst::Element, element: &gst::Element,
transition: gst::StateChange, transition: gst::StateChange,
) -> gst::StateChangeReturn { ) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
gst_trace!(self.cat, obj: element, "Changing state {:?}", transition); gst_trace!(self.cat, obj: element, "Changing state {:?}", transition);
match transition { match transition {
gst::StateChange::NullToReady => match self.prepare(element) { gst::StateChange::NullToReady => {
Err(err) => { self.prepare(element).map_err(|err| {
element.post_error_message(&err); element.post_error_message(&err);
return gst::StateChangeReturn::Failure; gst::StateChangeError
})?;
}
gst::StateChange::PlayingToPaused => {
self.stop(element).map_err(|_| gst::StateChangeError)?;
}
gst::StateChange::ReadyToNull => {
self.unprepare(element).map_err(|_| gst::StateChangeError)?;
} }
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(_) => (),
},
_ => (), _ => (),
} }
let mut ret = self.parent_change_state(element, transition); let mut success = self.parent_change_state(element, transition)?;
if ret == gst::StateChangeReturn::Failure {
return ret;
}
match transition { match transition {
gst::StateChange::ReadyToPaused => { 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 => { gst::StateChange::PausedToReady => {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
state.need_initial_events = true; state.need_initial_events = true;
...@@ -680,7 +673,7 @@ impl ElementImpl for AppSrc { ...@@ -680,7 +673,7 @@ impl ElementImpl for AppSrc {
_ => (), _ => (),
} }
ret Ok(success)
} }
} }
......
...@@ -198,7 +198,7 @@ impl SharedQueue { ...@@ -198,7 +198,7 @@ impl SharedQueue {
let inner = Arc::new(Mutex::new(SharedQueueInner { let inner = Arc::new(Mutex::new(SharedQueueInner {
name: name.into(), name: name.into(),
queue: None, queue: None,
last_ret: gst::FlowReturn::Flushing, last_res: Err(gst::FlowError::Flushing),
pending_queue: None, pending_queue: None,
pending_future_cancel: None, pending_future_cancel: None,
have_sink: as_sink, have_sink: as_sink,
...@@ -236,7 +236,7 @@ impl Drop for SharedQueue { ...@@ -236,7 +236,7 @@ impl Drop for SharedQueue {
struct SharedQueueInner { struct SharedQueueInner {
name: String, name: String,
queue: Option<DataQueue>, queue: Option<DataQueue>,