Update for gstreamer-rs MR 200

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/200
This commit is contained in:
François Laignel 2019-01-12 00:45:05 +01:00
parent abe87fae12
commit e930133bdf
23 changed files with 399 additions and 569 deletions

View file

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

View file

@ -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 {
} => (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"]); gst::FlowError::Error
return gst::FlowReturn::Error; })?;
}
Some(map) => map,
};
match file.write_all(map.as_ref()) { file.write_all(map.as_ref()).map_err(|err| {
Ok(()) => { gst_element_error!(
*position += map.len() as u64; element,
gst::ResourceError::Write,
["Failed to write buffer: {}", err]
);
gst::FlowError::Error
})?;
gst::FlowReturn::Ok *position += map.len() as u64;
}
Err(err) => {
gst_element_error!(
element,
gst::ResourceError::Write,
["Failed to write buffer: {}", err]
);
gst::FlowReturn::Error Ok(gst::FlowSuccess::Ok)
}
}
} }
} }

View file

@ -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 {
} => (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, gst_element_error!(
Err(err) => { element,
gst_element_error!( gst::LibraryError::Failed,
element, ["Failed to read at {}: {}", offset, err.to_string()]
gst::LibraryError::Failed, );
["Failed to read at {}: {}", offset, err.to_string()] gst::FlowError::Error
); })?
return gst::FlowReturn::Error;
}
}
}; };
*position += size as u64; *position += size as u64;
buffer.set_size(size); buffer.set_size(size);
gst::FlowReturn::Ok Ok(gst::FlowSuccess::Ok)
} }
} }

View file

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

View file

@ -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 {
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,45 +373,39 @@ 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, gst_error!(self.cat, obj: src, "Failed to read: {:?}", err);
Err(err) => { gst_element_error!(
gst_error!(self.cat, obj: src, "Failed to read: {:?}", err); src,
gst_element_error!( gst::ResourceError::Read,
src, ["Failed to read at {}: {}", offset, err.to_string()]
gst::ResourceError::Read, );
["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)
} }
} }

View file

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

View file

@ -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");

View file

@ -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 {
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 {
&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
} })?;
Ok(_) => (), }
}, gst::StateChange::PlayingToPaused => {
gst::StateChange::PlayingToPaused => match self.stop(element) { self.stop(element).map_err(|_| gst::StateChangeError)?;
Err(_) => return gst::StateChangeReturn::Failure, }
Ok(_) => (), gst::StateChange::ReadyToNull => {
}, self.unprepare(element).map_err(|_| gst::StateChangeError)?;
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 {
_ => (), _ => (),
} }
ret Ok(success)
} }
} }

View file

@ -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 {
struct SharedQueueInner { struct SharedQueueInner {
name: String, name: String,
queue: Option<DataQueue>, queue: Option<DataQueue>,
last_ret: gst::FlowReturn, last_res: Result<gst::FlowSuccess, gst::FlowError>,
pending_queue: Option<(Option<task::Task>, bool, VecDeque<DataQueueItem>)>, pending_queue: Option<(Option<task::Task>, bool, VecDeque<DataQueueItem>)>,
pending_future_cancel: Option<futures::sync::oneshot::Sender<()>>, pending_future_cancel: Option<futures::sync::oneshot::Sender<()>>,
have_sink: bool, have_sink: bool,
@ -296,7 +296,7 @@ impl ProxySink {
_pad: &gst::Pad, _pad: &gst::Pad,
element: &gst::Element, element: &gst::Element,
item: DataQueueItem, item: DataQueueItem,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let wait_future = { let wait_future = {
let state = self.state.lock().unwrap(); let state = self.state.lock().unwrap();
let StateSink { let StateSink {
@ -305,10 +305,7 @@ impl ProxySink {
pending_future_id, pending_future_id,
.. ..
} = *state; } = *state;
let queue = match *queue { let queue = queue.as_ref().ok_or(gst::FlowError::Error)?;
None => return gst::FlowReturn::Error,
Some(ref queue) => queue,
};
let mut queue = queue.0.lock().unwrap(); let mut queue = queue.0.lock().unwrap();
@ -472,23 +469,20 @@ impl ProxySink {
if let Some(wait_future) = wait_future { if let Some(wait_future) = wait_future {
gst_log!(self.cat, obj: element, "Blocking until queue becomes empty"); gst_log!(self.cat, obj: element, "Blocking until queue becomes empty");
match executor::current_thread::block_on_all(wait_future) { executor::current_thread::block_on_all(wait_future).map_err(|_| {
Err(_) => { gst_element_error!(
gst_element_error!( element,
element, gst::StreamError::Failed,
gst::StreamError::Failed, ["failed to wait for queue to become empty again"]
["failed to wait for queue to become empty again"] );
); gst::FlowError::Error
return gst::FlowReturn::Error; })?;
}
Ok(_) => (),
}
} }
let state = self.state.lock().unwrap(); let state = self.state.lock().unwrap();
let queue = state.queue.as_ref().unwrap(); let queue = state.queue.as_ref().unwrap();
let ret = queue.0.lock().unwrap().last_ret; let res = queue.0.lock().unwrap().last_res;
ret res
} }
fn sink_chain( fn sink_chain(
@ -496,7 +490,7 @@ impl ProxySink {
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!(self.cat, obj: pad, "Handling buffer {:?}", buffer); gst_log!(self.cat, obj: pad, "Handling buffer {:?}", buffer);
self.enqueue_item(pad, element, DataQueueItem::Buffer(buffer)) self.enqueue_item(pad, element, DataQueueItem::Buffer(buffer))
} }
@ -506,7 +500,7 @@ impl ProxySink {
pad: &gst::Pad, pad: &gst::Pad,
element: &gst::Element, element: &gst::Element,
list: gst::BufferList, list: gst::BufferList,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
gst_log!(self.cat, obj: pad, "Handling buffer list {:?}", list); gst_log!(self.cat, obj: pad, "Handling buffer list {:?}", list);
self.enqueue_item(pad, element, DataQueueItem::BufferList(list)) self.enqueue_item(pad, element, DataQueueItem::BufferList(list))
} }
@ -524,9 +518,9 @@ impl ProxySink {
let _ = self.stop(element); let _ = self.stop(element);
} }
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::Paused if res == Ok(gst::StateChangeSuccess::Success) && state == gst::State::Paused
|| ret == gst::StateChangeReturn::Async && pending == gst::State::Paused || res == Ok(gst::StateChangeSuccess::Async) && pending == gst::State::Paused
{ {
let _ = self.start(element); let _ = self.start(element);
} }
@ -605,7 +599,7 @@ impl ProxySink {
let state = self.state.lock().unwrap(); let state = self.state.lock().unwrap();
let mut queue = state.queue.as_ref().unwrap().0.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"); gst_debug!(self.cat, obj: element, "Started");
@ -624,7 +618,7 @@ impl ProxySink {
if let Some((Some(task), _, _)) = queue.pending_queue.take() { if let Some((Some(task), _, _)) = queue.pending_queue.take() {
task.notify(); task.notify();
} }
queue.last_ret = gst::FlowReturn::Flushing; queue.last_res = Err(gst::FlowError::Flushing);
gst_debug!(self.cat, obj: element, "Stopped"); gst_debug!(self.cat, obj: element, "Stopped");
@ -668,14 +662,14 @@ impl ObjectSubclass for ProxySink {
sink_pad.set_chain_function(|pad, parent, buffer| { sink_pad.set_chain_function(|pad, parent, buffer| {
ProxySink::catch_panic_pad_function( ProxySink::catch_panic_pad_function(
parent, parent,
|| gst::FlowReturn::Error, || Err(gst::FlowError::Error),
|queue, element| queue.sink_chain(pad, element, buffer), |queue, element| queue.sink_chain(pad, element, buffer),
) )
}); });
sink_pad.set_chain_list_function(|pad, parent, list| { sink_pad.set_chain_list_function(|pad, parent, list| {
ProxySink::catch_panic_pad_function( ProxySink::catch_panic_pad_function(
parent, parent,
|| gst::FlowReturn::Error, || Err(gst::FlowError::Error),
|queue, element| queue.sink_chain_list(pad, element, list), |queue, element| queue.sink_chain_list(pad, element, list),
) )
}); });
@ -749,42 +743,32 @@ impl ElementImpl for ProxySink {
&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
} })?;
Ok(_) => (), }
}, gst::StateChange::PausedToReady => {
gst::StateChange::PausedToReady => match self.stop(element) { self.stop(element).map_err(|_| gst::StateChangeError)?;
Err(_) => return gst::StateChangeReturn::Failure, }
Ok(_) => (), gst::StateChange::ReadyToNull => {
}, self.unprepare(element).map_err(|_| gst::StateChangeError)?;
gst::StateChange::ReadyToNull => match self.unprepare(element) { }
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
_ => (), _ => (),
} }
let ret = self.parent_change_state(element, transition); let success = self.parent_change_state(element, transition)?;
if ret == gst::StateChangeReturn::Failure {
return ret; if transition == gst::StateChange::ReadyToPaused {
self.start(element).map_err(|_| gst::StateChangeError)?;
} }
match transition { Ok(success)
gst::StateChange::ReadyToPaused => match self.start(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
_ => (),
}
ret
} }
} }
@ -824,9 +808,9 @@ impl ProxySrc {
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);
} }
@ -920,11 +904,11 @@ impl ProxySrc {
let res = match item { let res = match item {
DataQueueItem::Buffer(buffer) => { DataQueueItem::Buffer(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(|_| ())
} }
DataQueueItem::BufferList(list) => { DataQueueItem::BufferList(list) => {
gst_log!(self.cat, obj: element, "Forwarding buffer list {:?}", list); gst_log!(self.cat, obj: element, "Forwarding buffer list {:?}", list);
self.src_pad.push_list(list).into_result().map(|_| ()) self.src_pad.push_list(list).map(|_| ())
} }
DataQueueItem::Event(event) => { DataQueueItem::Event(event) => {
use gst::EventView; use gst::EventView;
@ -960,7 +944,7 @@ impl ProxySrc {
gst_log!(self.cat, obj: element, "Successfully pushed item"); gst_log!(self.cat, obj: element, "Successfully pushed item");
let state = self.state.lock().unwrap(); let state = self.state.lock().unwrap();
let mut queue = state.queue.as_ref().unwrap().0.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);
Ok(()) Ok(())
} }
Err(gst::FlowError::Flushing) => { Err(gst::FlowError::Flushing) => {
@ -970,7 +954,7 @@ impl ProxySrc {
if let Some(ref queue) = queue.queue { if let Some(ref queue) = queue.queue {
queue.pause(); queue.pause();
} }
queue.last_ret = gst::FlowReturn::Flushing; queue.last_res = Err(gst::FlowError::Flushing);
Ok(()) Ok(())
} }
Err(gst::FlowError::Eos) => { Err(gst::FlowError::Eos) => {
@ -980,7 +964,7 @@ impl ProxySrc {
if let Some(ref queue) = queue.queue { if let Some(ref queue) = queue.queue {
queue.pause(); queue.pause();
} }
queue.last_ret = gst::FlowReturn::Eos; queue.last_res = Err(gst::FlowError::Eos);
Ok(()) Ok(())
} }
Err(err) => { Err(err) => {
@ -993,7 +977,7 @@ impl ProxySrc {
); );
let state = self.state.lock().unwrap(); let state = self.state.lock().unwrap();
let mut queue = state.queue.as_ref().unwrap().0.lock().unwrap(); let mut queue = state.queue.as_ref().unwrap().0.lock().unwrap();
queue.last_ret = gst::FlowReturn::from_error(err); queue.last_res = Err(err);
Err(gst::FlowError::CustomError) Err(gst::FlowError::CustomError)
} }
}; };
@ -1036,15 +1020,9 @@ impl ProxySrc {
) )
})?; })?;
let queue = match SharedQueue::get(&settings.proxy_context, false) { let queue = SharedQueue::get(&settings.proxy_context, false).ok_or_else(|| {
Some(queue) => queue, gst_error_msg!(gst::ResourceError::OpenRead, ["Failed to create get queue"])
None => { })?;
return Err(gst_error_msg!(
gst::ResourceError::OpenRead,
["Failed to create get queue"]
));
}
};
let dataqueue = DataQueue::new( let dataqueue = DataQueue::new(
&element.clone().upcast(), &element.clone().upcast(),
@ -1095,7 +1073,7 @@ impl ProxySrc {
gst::ResourceError::OpenRead, gst::ResourceError::OpenRead,
["Failed to schedule data queue"] ["Failed to schedule data queue"]
) )
})?;; })?;
let pending_future_id = io_context.acquire_pending_future_id(); let pending_future_id = io_context.acquire_pending_future_id();
gst_debug!( gst_debug!(
@ -1332,45 +1310,38 @@ impl ElementImpl for ProxySrc {
&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
} })?;
Ok(_) => (), }
}, gst::StateChange::PlayingToPaused => {
gst::StateChange::PlayingToPaused => match self.stop(element) { self.stop(element).map_err(|_| gst::StateChangeError)?;
Err(_) => return gst::StateChangeReturn::Failure, }
Ok(_) => (), gst::StateChange::ReadyToNull => {
}, self.unprepare(element).map_err(|_| gst::StateChangeError)?;
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(_) => (),
},
_ => (), _ => (),
} }
ret Ok(success)
} }
} }

View file

@ -127,7 +127,7 @@ struct State {
pending_future_id_in: Option<PendingFutureId>, pending_future_id_in: Option<PendingFutureId>,
queue: Option<DataQueue>, queue: Option<DataQueue>,
pending_queue: Option<(Option<task::Task>, bool, VecDeque<DataQueueItem>)>, pending_queue: Option<(Option<task::Task>, bool, VecDeque<DataQueueItem>)>,
last_ret: gst::FlowReturn, last_res: Result<gst::FlowSuccess, gst::FlowError>,
pending_future_cancel: Option<futures::sync::oneshot::Sender<()>>, pending_future_cancel: Option<futures::sync::oneshot::Sender<()>>,
} }
@ -140,7 +140,7 @@ impl Default for State {
pending_future_id_in: None, pending_future_id_in: None,
queue: None, queue: None,
pending_queue: None, pending_queue: None,
last_ret: gst::FlowReturn::Ok, last_res: Ok(gst::FlowSuccess::Ok),
pending_future_cancel: None, pending_future_cancel: None,
} }
} }
@ -177,7 +177,7 @@ impl Queue {
_pad: &gst::Pad, _pad: &gst::Pad,
element: &gst::Element, element: &gst::Element,
item: DataQueueItem, item: DataQueueItem,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let wait_future = { let wait_future = {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
let State { let State {
@ -187,10 +187,8 @@ impl Queue {
pending_future_id_in, pending_future_id_in,
.. ..
} = *state; } = *state;
let queue = match *queue {
None => return gst::FlowReturn::Error, let queue = queue.as_ref().ok_or(gst::FlowError::Error)?;
Some(ref queue) => queue,
};
let item = match pending_queue { let item = match pending_queue {
None => queue.push(item), None => queue.push(item),
@ -331,20 +329,17 @@ impl Queue {
if let Some(wait_future) = wait_future { if let Some(wait_future) = wait_future {
gst_log!(self.cat, obj: element, "Blocking until queue becomes empty"); gst_log!(self.cat, obj: element, "Blocking until queue becomes empty");
match executor::current_thread::block_on_all(wait_future) { executor::current_thread::block_on_all(wait_future).map_err(|_| {
Err(_) => { gst_element_error!(
gst_element_error!( element,
element, gst::StreamError::Failed,
gst::StreamError::Failed, ["failed to wait for queue to become empty again"]
["failed to wait for queue to become empty again"] );
); gst::FlowError::Error
return gst::FlowReturn::Error; })?;
}
Ok(_) => (),
}
} }
self.state.lock().unwrap().last_ret self.state.lock().unwrap().last_res
} }
fn sink_chain( fn sink_chain(
@ -352,7 +347,7 @@ impl Queue {
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!(self.cat, obj: pad, "Handling buffer {:?}", buffer); gst_log!(self.cat, obj: pad, "Handling buffer {:?}", buffer);
self.enqueue_item(pad, element, DataQueueItem::Buffer(buffer)) self.enqueue_item(pad, element, DataQueueItem::Buffer(buffer))
} }
@ -362,7 +357,7 @@ impl Queue {
pad: &gst::Pad, pad: &gst::Pad,
element: &gst::Element, element: &gst::Element,
list: gst::BufferList, list: gst::BufferList,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
gst_log!(self.cat, obj: pad, "Handling buffer list {:?}", list); gst_log!(self.cat, obj: pad, "Handling buffer list {:?}", list);
self.enqueue_item(pad, element, DataQueueItem::BufferList(list)) self.enqueue_item(pad, element, DataQueueItem::BufferList(list))
} }
@ -378,9 +373,9 @@ impl Queue {
let _ = self.stop(element); let _ = self.stop(element);
} }
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::Paused if res == Ok(gst::StateChangeSuccess::Success) && state == gst::State::Paused
|| ret == gst::StateChangeReturn::Async && pending == gst::State::Paused || res == Ok(gst::StateChangeSuccess::Async) && pending == gst::State::Paused
{ {
let _ = self.start(element); let _ = self.start(element);
} }
@ -453,9 +448,9 @@ impl Queue {
let _ = self.stop(element); let _ = self.stop(element);
} }
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);
} }
@ -534,11 +529,11 @@ impl Queue {
let res = match item { let res = match item {
DataQueueItem::Buffer(buffer) => { DataQueueItem::Buffer(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(|_| ())
} }
DataQueueItem::BufferList(list) => { DataQueueItem::BufferList(list) => {
gst_log!(self.cat, obj: element, "Forwarding buffer list {:?}", list); gst_log!(self.cat, obj: element, "Forwarding buffer list {:?}", list);
self.src_pad.push_list(list).into_result().map(|_| ()) self.src_pad.push_list(list).map(|_| ())
} }
DataQueueItem::Event(event) => { DataQueueItem::Event(event) => {
gst_log!(self.cat, obj: element, "Forwarding event {:?}", event); gst_log!(self.cat, obj: element, "Forwarding event {:?}", event);
@ -551,7 +546,7 @@ impl Queue {
Ok(_) => { Ok(_) => {
gst_log!(self.cat, obj: element, "Successfully pushed item"); gst_log!(self.cat, obj: element, "Successfully pushed item");
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
state.last_ret = gst::FlowReturn::Ok; state.last_res = Ok(gst::FlowSuccess::Ok);
Ok(()) Ok(())
} }
Err(gst::FlowError::Flushing) => { Err(gst::FlowError::Flushing) => {
@ -560,7 +555,7 @@ impl Queue {
if let Some(ref queue) = state.queue { if let Some(ref queue) = state.queue {
queue.pause(); queue.pause();
} }
state.last_ret = gst::FlowReturn::Flushing; state.last_res = Err(gst::FlowError::Flushing);
Ok(()) Ok(())
} }
Err(gst::FlowError::Eos) => { Err(gst::FlowError::Eos) => {
@ -569,7 +564,7 @@ impl Queue {
if let Some(ref queue) = state.queue { if let Some(ref queue) = state.queue {
queue.pause(); queue.pause();
} }
state.last_ret = gst::FlowReturn::Eos; state.last_res = Err(gst::FlowError::Eos);
Ok(()) Ok(())
} }
Err(err) => { Err(err) => {
@ -581,7 +576,7 @@ impl Queue {
["streaming stopped, reason {}", err] ["streaming stopped, reason {}", err]
); );
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
state.last_ret = gst::FlowReturn::from_error(err); state.last_res = Err(err);
Err(gst::FlowError::CustomError) Err(gst::FlowError::CustomError)
} }
}; };
@ -673,7 +668,7 @@ impl Queue {
gst::ResourceError::OpenRead, gst::ResourceError::OpenRead,
["Failed to schedule data queue"] ["Failed to schedule data queue"]
) )
})?;; })?;
let pending_future_id = io_context.acquire_pending_future_id(); let pending_future_id = io_context.acquire_pending_future_id();
gst_debug!( gst_debug!(
@ -729,7 +724,7 @@ impl Queue {
if let Some(ref queue) = state.queue { if let Some(ref queue) = state.queue {
queue.unpause(); queue.unpause();
} }
state.last_ret = gst::FlowReturn::Ok; state.last_res = Ok(gst::FlowSuccess::Ok);
gst_debug!(self.cat, obj: element, "Started"); gst_debug!(self.cat, obj: element, "Started");
@ -748,7 +743,7 @@ impl Queue {
task.notify(); task.notify();
} }
let _ = state.pending_future_cancel.take(); let _ = state.pending_future_cancel.take();
state.last_ret = gst::FlowReturn::Flushing; state.last_res = Err(gst::FlowError::Flushing);
gst_debug!(self.cat, obj: element, "Stopped"); gst_debug!(self.cat, obj: element, "Stopped");
@ -802,14 +797,14 @@ impl ObjectSubclass for Queue {
sink_pad.set_chain_function(|pad, parent, buffer| { sink_pad.set_chain_function(|pad, parent, buffer| {
Queue::catch_panic_pad_function( Queue::catch_panic_pad_function(
parent, parent,
|| gst::FlowReturn::Error, || Err(gst::FlowError::Error),
|queue, element| queue.sink_chain(pad, element, buffer), |queue, element| queue.sink_chain(pad, element, buffer),
) )
}); });
sink_pad.set_chain_list_function(|pad, parent, list| { sink_pad.set_chain_list_function(|pad, parent, list| {
Queue::catch_panic_pad_function( Queue::catch_panic_pad_function(
parent, parent,
|| gst::FlowReturn::Error, || Err(gst::FlowError::Error),
|queue, element| queue.sink_chain_list(pad, element, list), |queue, element| queue.sink_chain_list(pad, element, list),
) )
}); });
@ -930,42 +925,32 @@ impl ElementImpl for Queue {
&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
} })?;
Ok(_) => (), }
}, gst::StateChange::PausedToReady => {
gst::StateChange::PausedToReady => match self.stop(element) { self.stop(element).map_err(|_| gst::StateChangeError)?;
Err(_) => return gst::StateChangeReturn::Failure, }
Ok(_) => (), gst::StateChange::ReadyToNull => {
}, self.unprepare(element).map_err(|_| gst::StateChangeError)?;
gst::StateChange::ReadyToNull => match self.unprepare(element) { }
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
_ => (), _ => (),
} }
let ret = self.parent_change_state(element, transition); let success = self.parent_change_state(element, transition)?;
if ret == gst::StateChangeReturn::Failure {
return ret; if transition == gst::StateChange::ReadyToPaused {
self.start(element).map_err(|_| gst::StateChangeError)?;
} }
match transition { Ok(success)
gst::StateChange::ReadyToPaused => match self.start(element) {
Err(_) => return gst::StateChangeReturn::Failure,
Ok(_) => (),
},
_ => (),
}
ret
} }
} }

View file

@ -211,9 +211,9 @@ impl TcpClientSrc {
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);
} }
@ -341,7 +341,7 @@ impl TcpClientSrc {
self.src_pad.push_event(event); 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(_) => { Ok(_) => {
gst_log!(self.cat, obj: element, "Successfully pushed buffer"); gst_log!(self.cat, obj: element, "Successfully pushed buffer");
Ok(()) Ok(())
@ -706,38 +706,31 @@ impl ElementImpl for TcpClientSrc {
&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)
element.post_error_message(&err); .map_err(|err| {
return gst::StateChangeReturn::Failure; element.post_error_message(&err);
} gst::StateChangeError
Ok(_) => match self.start(element) { })
Err(_) => return gst::StateChangeReturn::Failure, .and_then(|_| self.start(element).map_err(|_| gst::StateChangeError))?;
Ok(_) => (), }
}, gst::StateChange::PlayingToPaused => {
}, self.stop(element)
gst::StateChange::PlayingToPaused => match self.stop(element) { .and_then(|_| self.unprepare(element))
Err(_) => return gst::StateChangeReturn::Failure, .map_err(|_| gst::StateChangeError)?;
Ok(_) => 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::Success; success = gst::StateChangeSuccess::Success;
} }
gst::StateChange::PausedToReady => { gst::StateChange::PausedToReady => {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
@ -746,7 +739,7 @@ impl ElementImpl for TcpClientSrc {
_ => (), _ => (),
} }
ret Ok(success)
} }
} }

View file

@ -328,9 +328,9 @@ impl UdpSrc {
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);
} }
@ -453,7 +453,7 @@ impl UdpSrc {
self.src_pad.push_event(event); 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(_) => { Ok(_) => {
gst_log!(self.cat, obj: element, "Successfully pushed buffer"); gst_log!(self.cat, obj: element, "Successfully pushed buffer");
Ok(()) Ok(())
@ -1024,41 +1024,34 @@ impl ElementImpl for UdpSrc {
&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
} })?;
Ok(_) => (), }
}, gst::StateChange::PlayingToPaused => {
gst::StateChange::PlayingToPaused => match self.stop(element) { self.stop(element).map_err(|_| gst::StateChangeError)?;
Err(_) => return gst::StateChangeReturn::Failure, }
Ok(_) => (), gst::StateChange::ReadyToNull => {
}, self.unprepare(element).map_err(|_| gst::StateChangeError)?;
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;
@ -1066,7 +1059,7 @@ impl ElementImpl for UdpSrc {
_ => (), _ => (),
} }
ret Ok(success)
} }
} }

View file

@ -21,6 +21,8 @@ use glib::prelude::*;
extern crate gstreamer as gst; extern crate gstreamer as gst;
use gst::prelude::*; use gst::prelude::*;
extern crate gstreamer_app as gst_app;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
extern crate gstthreadshare; extern crate gstthreadshare;
@ -59,28 +61,22 @@ fn test_push() {
let samples = Arc::new(Mutex::new(Vec::new())); let samples = Arc::new(Mutex::new(Vec::new()));
let appsink = appsink.dynamic_cast::<gst_app::AppSink>().unwrap();
let samples_clone = samples.clone(); let samples_clone = samples.clone();
appsink appsink.connect_new_sample(move |appsink| {
.connect("new-sample", true, move |args| { let sample = appsink
let appsink = args[0].get::<gst::Element>().unwrap(); .emit("pull-sample", &[])
.unwrap()
.unwrap()
.get::<gst::Sample>()
.unwrap();
let sample = appsink samples_clone.lock().unwrap().push(sample);
.emit("pull-sample", &[])
.unwrap()
.unwrap()
.get::<gst::Sample>()
.unwrap();
samples_clone.lock().unwrap().push(sample); Ok(gst::FlowSuccess::Ok)
});
Some(gst::FlowReturn::Ok.to_value()) pipeline.set_state(gst::State::Playing).unwrap();
})
.unwrap();
pipeline
.set_state(gst::State::Playing)
.into_result()
.unwrap();
let mut eos = false; let mut eos = false;
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
@ -104,5 +100,5 @@ fn test_push() {
assert!(sample.get_buffer().is_some()); assert!(sample.get_buffer().is_some());
} }
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }

View file

@ -21,6 +21,8 @@ use glib::prelude::*;
extern crate gstreamer as gst; extern crate gstreamer as gst;
use gst::prelude::*; use gst::prelude::*;
extern crate gstreamer_app as gst_app;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
extern crate gstthreadshare; extern crate gstthreadshare;
@ -54,28 +56,22 @@ fn test_push() {
let samples = Arc::new(Mutex::new(Vec::new())); let samples = Arc::new(Mutex::new(Vec::new()));
let appsink = appsink.dynamic_cast::<gst_app::AppSink>().unwrap();
let samples_clone = samples.clone(); let samples_clone = samples.clone();
appsink appsink.connect_new_sample(move |appsink| {
.connect("new-sample", true, move |args| { let sample = appsink
let appsink = args[0].get::<gst::Element>().unwrap(); .emit("pull-sample", &[])
.unwrap()
.unwrap()
.get::<gst::Sample>()
.unwrap();
let sample = appsink samples_clone.lock().unwrap().push(sample);
.emit("pull-sample", &[])
.unwrap()
.unwrap()
.get::<gst::Sample>()
.unwrap();
samples_clone.lock().unwrap().push(sample); Ok(gst::FlowSuccess::Ok)
});
Some(gst::FlowReturn::Ok.to_value()) pipeline.set_state(gst::State::Playing).unwrap();
})
.unwrap();
pipeline
.set_state(gst::State::Playing)
.into_result()
.unwrap();
let mut eos = false; let mut eos = false;
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
@ -99,5 +95,5 @@ fn test_push() {
assert!(sample.get_buffer().is_some()); assert!(sample.get_buffer().is_some());
} }
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }

View file

@ -22,6 +22,8 @@ use glib::prelude::*;
extern crate gstreamer as gst; extern crate gstreamer as gst;
use gst::prelude::*; use gst::prelude::*;
extern crate gstreamer_app as gst_app;
use std::io::Write; use std::io::Write;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::{thread, time}; use std::{thread, time};
@ -75,28 +77,22 @@ fn test_push() {
let samples = Arc::new(Mutex::new(Vec::new())); let samples = Arc::new(Mutex::new(Vec::new()));
let appsink = appsink.dynamic_cast::<gst_app::AppSink>().unwrap();
let samples_clone = samples.clone(); let samples_clone = samples.clone();
appsink appsink.connect_new_sample(move |appsink| {
.connect("new-sample", true, move |args| { let sample = appsink
let appsink = args[0].get::<gst::Element>().unwrap(); .emit("pull-sample", &[])
.unwrap()
.unwrap()
.get::<gst::Sample>()
.unwrap();
let sample = appsink let mut samples = samples_clone.lock().unwrap();
.emit("pull-sample", &[]) samples.push(sample);
.unwrap() Ok(gst::FlowSuccess::Ok)
.unwrap() });
.get::<gst::Sample>()
.unwrap();
let mut samples = samples_clone.lock().unwrap(); pipeline.set_state(gst::State::Playing).unwrap();
samples.push(sample);
Some(gst::FlowReturn::Ok.to_value())
})
.unwrap();
pipeline
.set_state(gst::State::Playing)
.into_result()
.unwrap();
let mut eos = false; let mut eos = false;
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
@ -123,7 +119,7 @@ fn test_push() {
}); });
assert_eq!(total_received_size, 3 * 160); assert_eq!(total_received_size, 3 * 160);
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
handler.join().unwrap(); handler.join().unwrap();
} }

View file

@ -164,7 +164,7 @@ fn test_socket_reuse() {
for _ in 0..3 { for _ in 0..3 {
let buffer = ts_src_h.pull().unwrap(); let buffer = ts_src_h.pull().unwrap();
sink_h.push(buffer).into_result().unwrap(); sink_h.push(buffer).unwrap();
let buffer = ts_src_h2.pull().unwrap(); let buffer = ts_src_h2.pull().unwrap();
assert_eq!(buffer.get_size(), 160); assert_eq!(buffer.get_size(), 160);

View file

@ -24,4 +24,3 @@ path = "src/lib.rs"
name = "gtk-recording" name = "gtk-recording"
path = "examples/gtk_recording.rs" path = "examples/gtk_recording.rs"
required-features = ["gtk", "gio"] required-features = ["gtk", "gio"]

View file

@ -318,15 +318,13 @@ fn create_ui(app: &gtk::Application) {
glib::Continue(true) glib::Continue(true)
}); });
let ret = pipeline.set_state(gst::State::Playing); pipeline.set_state(gst::State::Playing).unwrap();
assert_ne!(ret, gst::StateChangeReturn::Failure);
// Pipeline reference is owned by the closure below, so will be // Pipeline reference is owned by the closure below, so will be
// destroyed once the app is destroyed // destroyed once the app is destroyed
let timeout_id = RefCell::new(Some(timeout_id)); let timeout_id = RefCell::new(Some(timeout_id));
app.connect_shutdown(move |_| { app.connect_shutdown(move |_| {
let ret = pipeline.set_state(gst::State::Null); pipeline.set_state(gst::State::Null).unwrap();
assert_ne!(ret, gst::StateChangeReturn::Failure);
bus.remove_watch(); bus.remove_watch();

View file

@ -187,7 +187,7 @@ impl ToggleRecord {
sinkpad.set_chain_function(|pad, parent, buffer| { sinkpad.set_chain_function(|pad, parent, buffer| {
ToggleRecord::catch_panic_pad_function( ToggleRecord::catch_panic_pad_function(
parent, parent,
|| gst::FlowReturn::Error, || Err(gst::FlowError::Error),
|togglerecord, element| togglerecord.sink_chain(pad, element, buffer), |togglerecord, element| togglerecord.sink_chain(pad, element, buffer),
) )
}); });
@ -651,25 +651,27 @@ impl ToggleRecord {
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> {
let stream = match self.pads.lock().get(pad) { let stream = self
None => { .pads
.lock()
.get(pad)
.map(|stream| stream.clone())
.ok_or_else(|| {
gst_element_error!( gst_element_error!(
element, element,
gst::CoreError::Pad, gst::CoreError::Pad,
["Unknown pad {:?}", pad.get_name()] ["Unknown pad {:?}", pad.get_name()]
); );
return gst::FlowReturn::Error; gst::FlowError::Error
} })?;
Some(stream) => stream.clone(),
};
gst_log!(self.cat, obj: pad, "Handling buffer {:?}", buffer); gst_log!(self.cat, obj: pad, "Handling buffer {:?}", buffer);
{ {
let state = stream.state.lock(); let state = stream.state.lock();
if state.eos { if state.eos {
return gst::FlowReturn::Eos; return Err(gst::FlowError::Eos);
} }
} }
@ -682,19 +684,19 @@ impl ToggleRecord {
gst::StreamError::Format, gst::StreamError::Format,
["DTS != PTS not supported for secondary streams"] ["DTS != PTS not supported for secondary streams"]
); );
return gst::FlowReturn::Error; return Err(gst::FlowError::Error);
} }
if !pts.is_some() { pts.ok_or_else(|| {
gst_element_error!(element, gst::StreamError::Format, ["Buffer without PTS"]); gst_element_error!(element, gst::StreamError::Format, ["Buffer without PTS"]);
return gst::FlowReturn::Error; gst::FlowError::Error
} })?;
if buffer.get_flags().contains(gst::BufferFlags::DELTA_UNIT) { if buffer.get_flags().contains(gst::BufferFlags::DELTA_UNIT) {
gst_element_error!( gst_element_error!(
element, element,
gst::StreamError::Format, gst::StreamError::Format,
["Delta-units not supported for secondary streams"] ["Delta-units not supported for secondary streams"]
); );
return gst::FlowReturn::Error; return Err(gst::FlowError::Error);
} }
self.handle_secondary_stream(pad, &stream, pts, buffer.get_duration()) self.handle_secondary_stream(pad, &stream, pts, buffer.get_duration())
@ -706,7 +708,7 @@ impl ToggleRecord {
gst::StreamError::Format, gst::StreamError::Format,
["Buffer without DTS or PTS"] ["Buffer without DTS or PTS"]
); );
return gst::FlowReturn::Error; return Err(gst::FlowError::Error);
} }
self.handle_main_stream( self.handle_main_stream(
@ -721,10 +723,10 @@ impl ToggleRecord {
match handle_result { match handle_result {
HandleResult::Drop => { HandleResult::Drop => {
return gst::FlowReturn::Ok; return Ok(gst::FlowSuccess::Ok);
} }
HandleResult::Flushing => { HandleResult::Flushing => {
return gst::FlowReturn::Flushing; return Err(gst::FlowError::Flushing);
} }
HandleResult::Eos => { HandleResult::Eos => {
stream.srcpad.push_event( stream.srcpad.push_event(
@ -732,7 +734,7 @@ impl ToggleRecord {
.seqnum(stream.state.lock().segment_seqnum) .seqnum(stream.state.lock().segment_seqnum)
.build(), .build(),
); );
return gst::FlowReturn::Eos; return Err(gst::FlowError::Eos);
} }
HandleResult::Pass => { HandleResult::Pass => {
// Pass through and actually push the buffer // Pass through and actually push the buffer
@ -1271,7 +1273,7 @@ impl ElementImpl for ToggleRecord {
&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 {
@ -1303,34 +1305,28 @@ impl ElementImpl for ToggleRecord {
_ => (), _ => (),
} }
let ret = self.parent_change_state(element, transition); let success = self.parent_change_state(element, transition)?;
if ret == gst::StateChangeReturn::Failure {
return ret;
}
match transition { if transition == gst::StateChange::PausedToReady {
gst::StateChange::PausedToReady => { for s in self
for s in self .other_streams
.other_streams .lock()
.lock() .0
.0 .iter()
.iter() .chain(iter::once(&self.main_stream))
.chain(iter::once(&self.main_stream)) {
{ let mut state = s.state.lock();
let mut state = s.state.lock();
state.pending_events.clear(); state.pending_events.clear();
}
let mut rec_state = self.state.lock();
*rec_state = State::default();
drop(rec_state);
element.notify("recording");
} }
_ => (),
let mut rec_state = self.state.lock();
*rec_state = State::default();
drop(rec_state);
element.notify("recording");
} }
ret Ok(success)
} }
fn request_new_pad( fn request_new_pad(

View file

@ -73,7 +73,7 @@ fn setup_sender_receiver(
}; };
let fakesink_sinkpad = fakesink.get_static_pad("sink").unwrap(); let fakesink_sinkpad = fakesink.get_static_pad("sink").unwrap();
srcpad.link(&fakesink_sinkpad).into_result().unwrap(); srcpad.link(&fakesink_sinkpad).unwrap();
let (sender_output, receiver_output) = mpsc::channel::<Either<gst::Buffer, gst::Event>>(); let (sender_output, receiver_output) = mpsc::channel::<Either<gst::Buffer, gst::Event>>();
let sender_output = Mutex::new(sender_output); let sender_output = Mutex::new(sender_output);
@ -254,10 +254,7 @@ fn test_one_stream_open() {
let (sender_input, _, receiver_output, thread) = let (sender_input, _, receiver_output, thread) =
setup_sender_receiver(&pipeline, &togglerecord, "src", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &true).unwrap(); togglerecord.set_property("record", &true).unwrap();
sender_input.send(SendData::Buffers(10)).unwrap(); sender_input.send(SendData::Buffers(10)).unwrap();
@ -274,7 +271,7 @@ fn test_one_stream_open() {
thread.join().unwrap(); thread.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -288,10 +285,7 @@ fn test_one_stream_gaps_open() {
let (sender_input, _, receiver_output, thread) = let (sender_input, _, receiver_output, thread) =
setup_sender_receiver(&pipeline, &togglerecord, "src", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &true).unwrap(); togglerecord.set_property("record", &true).unwrap();
sender_input.send(SendData::Buffers(5)).unwrap(); sender_input.send(SendData::Buffers(5)).unwrap();
@ -309,7 +303,7 @@ fn test_one_stream_gaps_open() {
thread.join().unwrap(); thread.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -323,10 +317,7 @@ fn test_one_stream_close_open() {
let (sender_input, receiver_input_done, receiver_output, thread) = let (sender_input, receiver_input_done, receiver_output, thread) =
setup_sender_receiver(&pipeline, &togglerecord, "src", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
sender_input.send(SendData::Buffers(10)).unwrap(); sender_input.send(SendData::Buffers(10)).unwrap();
receiver_input_done.recv().unwrap(); receiver_input_done.recv().unwrap();
@ -345,7 +336,7 @@ fn test_one_stream_close_open() {
thread.join().unwrap(); thread.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -359,10 +350,7 @@ fn test_one_stream_open_close() {
let (sender_input, receiver_input_done, receiver_output, thread) = let (sender_input, receiver_input_done, receiver_output, thread) =
setup_sender_receiver(&pipeline, &togglerecord, "src", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &true).unwrap(); togglerecord.set_property("record", &true).unwrap();
sender_input.send(SendData::Buffers(10)).unwrap(); sender_input.send(SendData::Buffers(10)).unwrap();
@ -382,7 +370,7 @@ fn test_one_stream_open_close() {
thread.join().unwrap(); thread.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -396,10 +384,7 @@ fn test_one_stream_open_close_open() {
let (sender_input, receiver_input_done, receiver_output, thread) = let (sender_input, receiver_input_done, receiver_output, thread) =
setup_sender_receiver(&pipeline, &togglerecord, "src", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &true).unwrap(); togglerecord.set_property("record", &true).unwrap();
sender_input.send(SendData::Buffers(10)).unwrap(); sender_input.send(SendData::Buffers(10)).unwrap();
@ -428,7 +413,7 @@ fn test_one_stream_open_close_open() {
thread.join().unwrap(); thread.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -444,10 +429,7 @@ fn test_two_stream_open() {
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) = let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &true).unwrap(); togglerecord.set_property("record", &true).unwrap();
@ -482,7 +464,7 @@ fn test_two_stream_open() {
thread_1.join().unwrap(); thread_1.join().unwrap();
thread_2.join().unwrap(); thread_2.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -498,10 +480,7 @@ fn test_two_stream_open_shift() {
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) = let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 5 * gst::MSECOND); setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 5 * gst::MSECOND);
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &true).unwrap(); togglerecord.set_property("record", &true).unwrap();
@ -536,7 +515,7 @@ fn test_two_stream_open_shift() {
thread_1.join().unwrap(); thread_1.join().unwrap();
thread_2.join().unwrap(); thread_2.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -552,10 +531,7 @@ fn test_two_stream_open_shift_main() {
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) = let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &true).unwrap(); togglerecord.set_property("record", &true).unwrap();
@ -591,7 +567,7 @@ fn test_two_stream_open_shift_main() {
thread_1.join().unwrap(); thread_1.join().unwrap();
thread_2.join().unwrap(); thread_2.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -607,10 +583,7 @@ fn test_two_stream_open_close() {
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) = let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &true).unwrap(); togglerecord.set_property("record", &true).unwrap();
@ -661,7 +634,7 @@ fn test_two_stream_open_close() {
thread_1.join().unwrap(); thread_1.join().unwrap();
thread_2.join().unwrap(); thread_2.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -677,10 +650,7 @@ fn test_two_stream_close_open() {
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) = let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &false).unwrap(); togglerecord.set_property("record", &false).unwrap();
@ -731,7 +701,7 @@ fn test_two_stream_close_open() {
thread_1.join().unwrap(); thread_1.join().unwrap();
thread_2.join().unwrap(); thread_2.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -747,10 +717,7 @@ fn test_two_stream_open_close_open() {
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) = let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &true).unwrap(); togglerecord.set_property("record", &true).unwrap();
@ -826,7 +793,7 @@ fn test_two_stream_open_close_open() {
thread_1.join().unwrap(); thread_1.join().unwrap();
thread_2.join().unwrap(); thread_2.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -842,10 +809,7 @@ fn test_two_stream_open_close_open_gaps() {
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) = let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &true).unwrap(); togglerecord.set_property("record", &true).unwrap();
@ -927,7 +891,7 @@ fn test_two_stream_open_close_open_gaps() {
thread_1.join().unwrap(); thread_1.join().unwrap();
thread_2.join().unwrap(); thread_2.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -943,10 +907,7 @@ fn test_two_stream_close_open_close_delta() {
let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) = let (sender_input_2, receiver_input_done_2, receiver_output_2, thread_2) =
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &false).unwrap(); togglerecord.set_property("record", &false).unwrap();
@ -1017,7 +978,7 @@ fn test_two_stream_close_open_close_delta() {
thread_1.join().unwrap(); thread_1.join().unwrap();
thread_2.join().unwrap(); thread_2.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }
#[test] #[test]
@ -1035,10 +996,7 @@ fn test_three_stream_open_close_open() {
let (sender_input_3, receiver_input_done_3, receiver_output_3, thread_3) = let (sender_input_3, receiver_input_done_3, receiver_output_3, thread_3) =
setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into()); setup_sender_receiver(&pipeline, &togglerecord, "src_%u", 0.into());
pipeline pipeline.set_state(gst::State::Playing).unwrap();
.set_state(gst::State::Playing)
.into_result()
.unwrap();
togglerecord.set_property("record", &true).unwrap(); togglerecord.set_property("record", &true).unwrap();
@ -1142,5 +1100,5 @@ fn test_three_stream_open_close_open() {
thread_2.join().unwrap(); thread_2.join().unwrap();
thread_3.join().unwrap(); thread_3.join().unwrap();
pipeline.set_state(gst::State::Null).into_result().unwrap(); pipeline.set_state(gst::State::Null).unwrap();
} }

View file

@ -35,7 +35,7 @@ impl Identity {
sinkpad.set_chain_function(|pad, parent, buffer| { sinkpad.set_chain_function(|pad, parent, buffer| {
Identity::catch_panic_pad_function( Identity::catch_panic_pad_function(
parent, parent,
|| gst::FlowReturn::Error, || Err(gst::FlowError::Error),
|identity, element| identity.sink_chain(pad, element, buffer), |identity, element| identity.sink_chain(pad, element, buffer),
) )
}); });
@ -81,7 +81,7 @@ impl Identity {
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!(self.cat, obj: pad, "Handling buffer {:?}", buffer); gst_log!(self.cat, obj: pad, "Handling buffer {:?}", buffer);
self.srcpad.push(buffer) self.srcpad.push(buffer)
} }
@ -260,16 +260,11 @@ impl ElementImpl for Identity {
&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);
// Call the parent class' implementation of ::change_state() // Call the parent class' implementation of ::change_state()
let ret = self.parent_change_state(element, transition); self.parent_change_state(element, transition)
if ret == gst::StateChangeReturn::Failure {
return ret;
}
ret
} }
} }

View file

@ -416,7 +416,7 @@ impl BaseTransformImpl for Rgb2Gray {
element: &gst_base::BaseTransform, element: &gst_base::BaseTransform,
inbuf: &gst::Buffer, inbuf: &gst::Buffer,
outbuf: &mut gst::BufferRef, outbuf: &mut gst::BufferRef,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
// Keep a local copy of the values of all our properties at this very moment. This // Keep a local copy of the values of all our properties at this very moment. This
// ensures that the mutex is never locked for long and the application wouldn't // ensures that the mutex is never locked for long and the application wouldn't
// have to block until this function returns when getting/setting property values // have to block until this function returns when getting/setting property values
@ -424,13 +424,10 @@ impl BaseTransformImpl for Rgb2Gray {
// Get a locked reference to our state, i.e. the input and output VideoInfo // Get a locked reference to our state, i.e. the input and output VideoInfo
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_else(|| {
None => { gst_element_error!(element, gst::CoreError::Negotiation, ["Have no state yet"]);
gst_element_error!(element, gst::CoreError::Negotiation, ["Have no state yet"]); gst::FlowError::NotNegotiated
return gst::FlowReturn::NotNegotiated; })?;
}
Some(ref mut state) => state,
};
// Map the input buffer as a VideoFrameRef. This is similar to directly mapping // Map the input buffer as a VideoFrameRef. This is similar to directly mapping
// the buffer with inbuf.map_readable() but in addition extracts various video // the buffer with inbuf.map_readable() but in addition extracts various video
@ -440,34 +437,28 @@ impl BaseTransformImpl for Rgb2Gray {
// //
// This fails if the buffer can't be read or is invalid in relation to the video // This fails if the buffer can't be read or is invalid in relation to the video
// info that is passed here // info that is passed here
let in_frame = match gst_video::VideoFrameRef::from_buffer_ref_readable( let in_frame =
inbuf.as_ref(), gst_video::VideoFrameRef::from_buffer_ref_readable(inbuf.as_ref(), &state.in_info)
&state.in_info, .ok_or_else(|| {
) { gst_element_error!(
None => { element,
gst_element_error!( gst::CoreError::Failed,
element, ["Failed to map input buffer readable"]
gst::CoreError::Failed, );
["Failed to map input buffer readable"] gst::FlowError::Error
); })?;
return gst::FlowReturn::Error;
}
Some(in_frame) => in_frame,
};
// And now map the output buffer writable, so we can fill it. // And now map the output buffer writable, so we can fill it.
let mut out_frame = let mut out_frame =
match gst_video::VideoFrameRef::from_buffer_ref_writable(outbuf, &state.out_info) { gst_video::VideoFrameRef::from_buffer_ref_writable(outbuf, &state.out_info)
None => { .ok_or_else(|| {
gst_element_error!( gst_element_error!(
element, element,
gst::CoreError::Failed, gst::CoreError::Failed,
["Failed to map output buffer writable"] ["Failed to map output buffer writable"]
); );
return gst::FlowReturn::Error; gst::FlowError::Error
} })?;
Some(out_frame) => out_frame,
};
// Keep the various metadata we need for working with the video frames in // Keep the various metadata we need for working with the video frames in
// local variables. This saves some typing below. // local variables. This saves some typing below.
@ -566,7 +557,7 @@ impl BaseTransformImpl for Rgb2Gray {
unimplemented!(); unimplemented!();
} }
gst::FlowReturn::Ok Ok(gst::FlowSuccess::Ok)
} }
} }

View file

@ -409,7 +409,7 @@ impl ElementImpl for SineSrc {
&self, &self,
element: &gst::Element, element: &gst::Element,
transition: gst::StateChange, transition: gst::StateChange,
) -> gst::StateChangeReturn { ) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
let basesrc = element.downcast_ref::<gst_base::BaseSrc>().unwrap(); let basesrc = element.downcast_ref::<gst_base::BaseSrc>().unwrap();
// Configure live'ness once here just before starting the source // Configure live'ness once here just before starting the source
@ -685,7 +685,7 @@ impl BaseSrcImpl for SineSrc {
// If the clock ID was unscheduled, unlock() was called // If the clock ID was unscheduled, unlock() was called
// and we should return Flushing immediately. // and we should return Flushing immediately.
if res == gst::ClockReturn::Unscheduled { if res == Err(gst::ClockError::Unscheduled) {
gst_debug!(self.cat, obj: element, "Flushing"); gst_debug!(self.cat, obj: element, "Flushing");
return Err(gst::FlowError::Flushing); return Err(gst::FlowError::Flushing);
} }