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 => {
let map = buffer.map_readable().ok_or_else(|| {
gst_element_error!(element, gst::CoreError::Failed, ["Failed to map buffer"]);
return gst::FlowReturn::Error;
}
Some(map) => map,
};
match file.write_all(map.as_ref()) {
Ok(()) => {
*position += map.len() as u64;
gst::FlowError::Error
})?;
gst::FlowReturn::Ok
}
Err(err) => {
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::Error
}
}
*position += map.len() as u64;
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;
}
};
let mut map = buffer.map_writable().ok_or_else(|| {
gst_element_error!(element, gst::LibraryError::Failed, ["Failed to map buffer"]);
gst::FlowError::Error
})?;
match file.read(map.as_mut()) {
Ok(size) => size,
Err(err) => {
file.read(map.as_mut()).map_err(|err| {
gst_element_error!(
element,
gst::LibraryError::Failed,
["Failed to read at {}: {}", offset, err.to_string()]
);
return gst::FlowReturn::Error;
}
}
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,24 +373,19 @@ 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 => {
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) => {
response.read(data).map_err(|err| {
gst_error!(self.cat, obj: src, "Failed to read: {:?}", err);
gst_element_error!(
src,
......@@ -398,20 +393,19 @@ impl BaseSrcImpl for HttpSrc {
["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;
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);
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)
}
}
......
......@@ -198,7 +198,7 @@ impl SharedQueue {
let inner = Arc::new(Mutex::new(SharedQueueInner {
name: name.into(),
queue: None,
last_ret: gst::FlowReturn::Flushing,
last_res: Err(gst::FlowError::Flushing),
pending_queue: None,
pending_future_cancel: None,
have_sink: as_sink,
......@@ -236,7 +236,7 @@ impl Drop for SharedQueue {
struct SharedQueueInner {
name: String,
queue: Option<DataQueue>,
last_ret: gst::FlowReturn,
last_res: Result<gst::FlowSuccess, gst::FlowError>,
pending_queue: Option<(Option<task::Task>, bool, VecDeque<DataQueueItem>)>,
pending_future_cancel: Option<futures::sync::oneshot::Sender<()>>,
have_sink: bool,
......@@ -296,7 +296,7 @@ impl ProxySink {
_pad: &gst::Pad,
element: &gst::Element,
item: DataQueueItem,
) -> gst::FlowReturn {
) -> Result<gst::FlowSuccess, gst::FlowError> {
let wait_future = {
let state = self.state.lock().unwrap();
let StateSink {
......@@ -305,10 +305,7 @@ impl ProxySink {
pending_future_id,
..
} = *state;
let queue = match *queue {
None => return gst::FlowReturn::Error,
Some(ref queue) => queue,
};
let queue = queue.as_ref().ok_or(gst::FlowError::Error)?;
let mut queue = queue.0.lock().unwrap();
......@@ -472,23 +469,20 @@ impl ProxySink {
if let Some(wait_future) = wait_future {
gst_log!(self.cat, obj: element, "Blocking until queue becomes empty");
match executor::current_thread::block_on_all(wait_future) {
Err(_) => {
executor::current_thread::block_on_all(wait_future).map_err(|_| {
gst_element_error!(
element,
gst::StreamError::Failed,
["failed to wait for queue to become empty again"]
);
return gst::FlowReturn::Error;
}
Ok(_) => (),
}
gst::FlowError::Error
})?;
}
let state = self.state.lock().unwrap();
let queue = state.queue.as_ref().unwrap();
let ret = queue.0.lock().unwrap().last_ret;
ret
let res = queue.0.lock().unwrap().last_res;
res
}
fn sink_chain(
......@@ -496,7 +490,7 @@ impl ProxySink {
pad: &gst::Pad,
element: &gst::Element,
buffer: gst::Buffer,
) -> gst::FlowReturn {
) -> Result<gst::FlowSuccess, gst::FlowError> {
gst_log!(self.cat, obj: pad, "Handling buffer {:?}", buffer);
self.enqueue_item(pad, element, DataQueueItem::Buffer(buffer))
}
......@@ -506,7 +500,7 @@ impl ProxySink {
pad: &gst::Pad,
element: &gst::Element,
list: gst::BufferList,
) -> gst::FlowReturn {
) -> Result<gst::FlowSuccess, gst::FlowError> {
gst_log!(self.cat, obj: pad, "Handling buffer list {:?}", list);
self.enqueue_item(pad, element, DataQueueItem::BufferList(list))
}
......@@ -524,9 +518,9 @@ impl ProxySink {
let _ = self.stop(element);
}
EventView::FlushStop(..) => {
let (ret, state, pending) = element.get_state(0.into());
if ret == gst::StateChangeReturn::Success && state == gst::State::Paused
|| ret == gst::StateChangeReturn::Async && pending == gst::State::Paused
let (res, state, pending) = element.get_state(0.into());
if res == Ok(gst::StateChangeSuccess::Success) && state == gst::State::Paused
|| res == Ok(gst::StateChangeSuccess::Async) && pending == gst::State::Paused
{
let _ = self.start(element);
}
......@@ -605,7 +599,7 @@ impl ProxySink {
let state = self.state.lock().unwrap();
let mut queue = state.queue.as_ref().unwrap().0.lock().unwrap();
queue.last_ret = gst::FlowReturn::Ok;
queue.last_res = Ok(gst::FlowSuccess::Ok);
gst_debug!(self.cat, obj: element, "Started");
......@@ -624,7 +618,7 @@ impl ProxySink {
if let Some((Some(task), _, _)) = queue.pending_queue.take() {
task.notify();
}
queue.last_ret = gst::FlowReturn::Flushing;
queue.last_res = Err(gst::FlowError::Flushing);
gst_debug!(self.cat, obj: element, "Stopped");
......@@ -668,14 +662,14 @@ impl ObjectSubclass for ProxySink {
sink_pad.set_chain_function(|pad, parent, buffer| {
ProxySink::catch_panic_pad_function(
parent,
|| gst::FlowReturn::Error,
|| Err(gst::FlowError::Error),
|queue, element| queue.sink_chain(pad, element, buffer),
)
});
sink_pad.set_chain_list_function(|pad, parent, list| {
ProxySink::catch_panic_pad_function(
parent,
|| gst::FlowReturn::Error,
|| Err(gst::FlowError::Error),
|queue, element| queue.sink_chain_list(pad, element, list),
)
});
......@@ -749,42 +743,32 @@ impl ElementImpl for ProxySink {
&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;
gst::StateChangeError
})?;
}
gst::StateChange::PausedToReady => {
self.stop(element).map_err(|_| gst::StateChangeError)?;
}
gst::StateChange::ReadyToNull => {
self.unprepare(element).map_err(|_| gst::StateChangeError)?;
}
Ok(_) => (),
},
gst::StateChange::PausedToReady => match self.stop(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
gst::StateChange::ReadyToNull => match self.unprepare(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
_ => (),
}
let ret = self.parent_change_state(element, transition);
if ret == gst::StateChangeReturn::Failure {
return ret;
}
let success = self.parent_change_state(element, transition)?;
match transition {
gst::StateChange::ReadyToPaused => match self.start(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
_ => (),
if transition == gst::StateChange::ReadyToPaused {
self.start(element).map_err(|_| gst::StateChangeError)?;
}
ret
Ok(success)
}
}
<