Commit 80a2c503 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵
Browse files

Use ErrorMessage from gstreamer bindings

parent cbfb30c7
......@@ -62,9 +62,9 @@ impl SinkImpl for FileSink {
Box::new(validate_uri)
}
fn start(&mut self, sink: &BaseSink, uri: Url) -> Result<(), ErrorMessage> {
fn start(&mut self, sink: &BaseSink, uri: Url) -> Result<(), gst::ErrorMessage> {
if let StreamingState::Started { .. } = self.streaming_state {
return Err(error_msg!(
return Err(gst_error_msg!(
gst::LibraryError::Failed,
["Sink already started"]
));
......@@ -77,7 +77,7 @@ impl SinkImpl for FileSink {
"Unsupported file URI '{}'",
uri.as_str()
);
Err(error_msg!(
Err(gst_error_msg!(
gst::LibraryError::Failed,
["Unsupported file URI '{}'", uri.as_str()]
))
......@@ -90,7 +90,7 @@ impl SinkImpl for FileSink {
"Could not open file for writing: {}",
err.to_string()
);
Err(error_msg!(
Err(gst_error_msg!(
gst::ResourceError::OpenWrite,
[
"Could not open file for writing '{}': {}",
......@@ -110,7 +110,7 @@ impl SinkImpl for FileSink {
Ok(())
}
fn stop(&mut self, _sink: &BaseSink) -> Result<(), ErrorMessage> {
fn stop(&mut self, _sink: &BaseSink) -> Result<(), gst::ErrorMessage> {
self.streaming_state = StreamingState::Stopped;
Ok(())
......@@ -128,7 +128,7 @@ impl SinkImpl for FileSink {
ref mut position,
} => (file, position),
StreamingState::Stopped => {
return Err(FlowError::Error(error_msg!(
return Err(FlowError::Error(gst_error_msg!(
gst::LibraryError::Failed,
["Not started yet"]
)));
......@@ -137,7 +137,7 @@ impl SinkImpl for FileSink {
let map = match buffer.map_readable() {
None => {
return Err(FlowError::Error(error_msg!(
return Err(FlowError::Error(gst_error_msg!(
gst::LibraryError::Failed,
["Failed to map buffer"]
)));
......@@ -148,7 +148,7 @@ impl SinkImpl for FileSink {
try!(file.write_all(data).or_else(|err| {
gst_error!(cat, obj: sink, "Failed to write: {}", err);
Err(FlowError::Error(error_msg!(
Err(FlowError::Error(gst_error_msg!(
gst::ResourceError::Write,
["Failed to write: {}", err]
)))
......
......@@ -72,9 +72,9 @@ impl SourceImpl for FileSrc {
}
}
fn start(&mut self, src: &BaseSrc, uri: Url) -> Result<(), ErrorMessage> {
fn start(&mut self, src: &BaseSrc, uri: Url) -> Result<(), gst::ErrorMessage> {
if let StreamingState::Started { .. } = self.streaming_state {
return Err(error_msg!(
return Err(gst_error_msg!(
gst::LibraryError::Failed,
["Source already started"]
));
......@@ -87,7 +87,7 @@ impl SourceImpl for FileSrc {
"Unsupported file URI '{}'",
uri.as_str()
);
Err(error_msg!(
Err(gst_error_msg!(
gst::LibraryError::Failed,
["Unsupported file URI '{}'", uri.as_str()]
))
......@@ -100,7 +100,7 @@ impl SourceImpl for FileSrc {
"Could not open file for reading: {}",
err.to_string()
);
Err(error_msg!(
Err(gst_error_msg!(
gst::ResourceError::OpenRead,
[
"Could not open file for reading '{}': {}",
......@@ -120,7 +120,7 @@ impl SourceImpl for FileSrc {
Ok(())
}
fn stop(&mut self, _src: &BaseSrc) -> Result<(), ErrorMessage> {
fn stop(&mut self, _src: &BaseSrc) -> Result<(), gst::ErrorMessage> {
self.streaming_state = StreamingState::Stopped;
Ok(())
......@@ -142,7 +142,7 @@ impl SourceImpl for FileSrc {
ref mut position,
} => (file, position),
StreamingState::Stopped => {
return Err(FlowError::Error(error_msg!(
return Err(FlowError::Error(gst_error_msg!(
gst::LibraryError::Failed,
["Not started yet"]
)));
......@@ -152,7 +152,7 @@ impl SourceImpl for FileSrc {
if *position != offset {
try!(file.seek(SeekFrom::Start(offset)).or_else(|err| {
gst_error!(cat, obj: src, "Failed to seek to {}: {:?}", offset, err);
Err(FlowError::Error(error_msg!(
Err(FlowError::Error(gst_error_msg!(
gst::ResourceError::Seek,
["Failed to seek to {}: {}", offset, err.to_string()]
)))
......@@ -163,7 +163,7 @@ impl SourceImpl for FileSrc {
let size = {
let mut map = match buffer.map_writable() {
None => {
return Err(FlowError::Error(error_msg!(
return Err(FlowError::Error(gst_error_msg!(
gst::LibraryError::Failed,
["Failed to map buffer"]
)));
......@@ -175,7 +175,7 @@ impl SourceImpl for FileSrc {
try!(file.read(data).or_else(|err| {
gst_error!(cat, obj: src, "Failed to read: {:?}", err);
Err(FlowError::Error(error_msg!(
Err(FlowError::Error(gst_error_msg!(
gst::ResourceError::Read,
["Failed to read at {}: {}", offset, err.to_string()]
)))
......@@ -189,7 +189,7 @@ impl SourceImpl for FileSrc {
Ok(())
}
fn seek(&mut self, _src: &BaseSrc, _: u64, _: Option<u64>) -> Result<(), ErrorMessage> {
fn seek(&mut self, _src: &BaseSrc, _: u64, _: Option<u64>) -> Result<(), gst::ErrorMessage> {
Ok(())
}
}
......@@ -1094,13 +1094,13 @@ impl DemuxerImpl for FlvDemux {
demuxer: &Element,
_upstream_size: Option<u64>,
_random_access: bool,
) -> Result<(), ErrorMessage> {
) -> Result<(), gst::ErrorMessage> {
self.state = State::NeedHeader;
Ok(())
}
fn stop(&mut self, demuxer: &Element) -> Result<(), ErrorMessage> {
fn stop(&mut self, demuxer: &Element) -> Result<(), gst::ErrorMessage> {
self.state = State::Stopped;
self.adapter.clear();
self.streaming_state = None;
......@@ -1113,7 +1113,7 @@ impl DemuxerImpl for FlvDemux {
demuxer: &Element,
start: gst::ClockTime,
stop: gst::ClockTime,
) -> Result<SeekResult, ErrorMessage> {
) -> Result<SeekResult, gst::ErrorMessage> {
unimplemented!();
}
......@@ -1129,7 +1129,7 @@ impl DemuxerImpl for FlvDemux {
self.update_state(demuxer)
}
fn end_of_stream(&mut self, demuxer: &Element) -> Result<(), ErrorMessage> {
fn end_of_stream(&mut self, demuxer: &Element) -> Result<(), gst::ErrorMessage> {
// nothing to do here, all data we have left is incomplete
Ok(())
}
......
......@@ -64,7 +64,7 @@ impl HttpSrc {
uri: Url,
start: u64,
stop: Option<u64>,
) -> Result<StreamingState, ErrorMessage> {
) -> Result<StreamingState, gst::ErrorMessage> {
let cat = self.cat;
let mut req = self.client.get(uri.clone());
......@@ -82,7 +82,7 @@ impl HttpSrc {
let response = try!(req.send().or_else(|err| {
gst_error!(cat, obj: src, "Request failed: {:?}", err);
Err(error_msg!(
Err(gst_error_msg!(
gst::ResourceError::Read,
["Failed to fetch {}: {}", uri, err.to_string()]
))
......@@ -90,7 +90,7 @@ impl HttpSrc {
if !response.status().is_success() {
gst_error!(cat, obj: src, "Request status failed: {:?}", response);
return Err(error_msg!(
return Err(gst_error_msg!(
gst::ResourceError::Read,
["Failed to fetch {}: {}", uri, response.status()]
));
......@@ -120,7 +120,7 @@ impl HttpSrc {
};
if position != start {
return Err(error_msg!(
return Err(gst_error_msg!(
gst::ResourceError::Seek,
["Failed to seek to {}: Got {}", start, position]
));
......@@ -170,20 +170,25 @@ impl SourceImpl for HttpSrc {
}
}
fn start(&mut self, src: &BaseSrc, uri: Url) -> Result<(), ErrorMessage> {
fn start(&mut self, src: &BaseSrc, uri: Url) -> Result<(), gst::ErrorMessage> {
self.streaming_state = StreamingState::Stopped;
self.streaming_state = try!(self.do_request(src, uri, 0, None));
Ok(())
}
fn stop(&mut self, _src: &BaseSrc) -> Result<(), ErrorMessage> {
fn stop(&mut self, _src: &BaseSrc) -> Result<(), gst::ErrorMessage> {
self.streaming_state = StreamingState::Stopped;
Ok(())
}
fn seek(&mut self, src: &BaseSrc, start: u64, stop: Option<u64>) -> Result<(), ErrorMessage> {
fn seek(
&mut self,
src: &BaseSrc,
start: u64,
stop: Option<u64>,
) -> Result<(), gst::ErrorMessage> {
let (position, old_stop, uri) = match self.streaming_state {
StreamingState::Started {
position,
......@@ -192,7 +197,10 @@ impl SourceImpl for HttpSrc {
..
} => (position, stop, uri.clone()),
StreamingState::Stopped => {
return Err(error_msg!(gst::LibraryError::Failed, ["Not started yet"]));
return Err(gst_error_msg!(
gst::LibraryError::Failed,
["Not started yet"]
));
}
};
......@@ -222,7 +230,7 @@ impl SourceImpl for HttpSrc {
..
} => (response, position),
StreamingState::Stopped => {
return Err(FlowError::Error(error_msg!(
return Err(FlowError::Error(gst_error_msg!(
gst::LibraryError::Failed,
["Not started yet"]
)));
......@@ -230,7 +238,7 @@ impl SourceImpl for HttpSrc {
};
if *position != offset {
return Err(FlowError::Error(error_msg!(
return Err(FlowError::Error(gst_error_msg!(
gst::ResourceError::Seek,
["Got unexpected offset {}, expected {}", offset, position]
)));
......@@ -239,7 +247,7 @@ impl SourceImpl for HttpSrc {
let size = {
let mut map = match buffer.map_writable() {
None => {
return Err(FlowError::Error(error_msg!(
return Err(FlowError::Error(gst_error_msg!(
gst::LibraryError::Failed,
["Failed to map buffer"]
)));
......@@ -251,7 +259,7 @@ impl SourceImpl for HttpSrc {
try!(response.read(data).or_else(|err| {
gst_error!(cat, obj: src, "Failed to read: {:?}", err);
Err(FlowError::Error(error_msg!(
Err(FlowError::Error(gst_error_msg!(
gst::ResourceError::Read,
["Failed to read at {}: {}", offset, err.to_string()]
)))
......
......@@ -52,21 +52,21 @@ pub trait DemuxerImpl: Send + 'static {
demuxer: &Element,
upstream_size: Option<u64>,
random_access: bool,
) -> Result<(), ErrorMessage>;
fn stop(&mut self, demuxer: &Element) -> Result<(), ErrorMessage>;
) -> Result<(), gst::ErrorMessage>;
fn stop(&mut self, demuxer: &Element) -> Result<(), gst::ErrorMessage>;
fn seek(
&mut self,
demuxer: &Element,
start: gst::ClockTime,
stop: gst::ClockTime,
) -> Result<SeekResult, ErrorMessage>;
) -> Result<SeekResult, gst::ErrorMessage>;
fn handle_buffer(
&mut self,
demuxer: &Element,
buffer: Option<gst::Buffer>,
) -> Result<HandleBufferResult, FlowError>;
fn end_of_stream(&mut self, demuxer: &Element) -> Result<(), ErrorMessage>;
fn end_of_stream(&mut self, demuxer: &Element) -> Result<(), gst::ErrorMessage>;
fn is_seekable(&self, demuxer: &Element) -> bool;
fn get_position(&self, demuxer: &Element) -> gst::ClockTime;
......@@ -309,7 +309,7 @@ impl Demuxer {
}
Err(ref msg) => {
gst_error!(self.cat, obj: element, "Failed to start: {:?}", msg);
msg.post(element);
element.post_error_message(msg);
false
}
}
......@@ -327,7 +327,7 @@ impl Demuxer {
}
Err(ref msg) => {
gst_error!(self.cat, obj: element, "Failed to stop: {:?}", msg);
msg.post(element);
element.post_error_message(msg);
false
}
}
......@@ -401,7 +401,7 @@ impl Demuxer {
);
match flow_error {
FlowError::NotNegotiated(ref msg) | FlowError::Error(ref msg) => {
msg.post(&element)
element.post_error_message(msg);
}
_ => (),
}
......@@ -461,7 +461,7 @@ impl Demuxer {
);
match flow_error {
FlowError::NotNegotiated(ref msg) | FlowError::Error(ref msg) => {
msg.post(&element)
element.post_error_message(msg);
}
_ => (),
}
......@@ -497,7 +497,7 @@ impl Demuxer {
"Failed end of stream: {:?}",
msg
);
msg.post(&element);
element.post_error_message(msg);
}
}
pad.event_default(parent.as_ref(), event)
......@@ -603,7 +603,7 @@ impl Demuxer {
Ok(res) => res,
Err(ref msg) => {
gst_error!(self.cat, obj: element, "Failed to seek: {:?}", msg);
msg.post(element);
element.post_error_message(msg);
return false;
}
}
......
......@@ -30,8 +30,8 @@ use UriValidator;
pub trait SinkImpl: Send + 'static {
fn uri_validator(&self) -> Box<UriValidator>;
fn start(&mut self, sink: &BaseSink, uri: Url) -> Result<(), ErrorMessage>;
fn stop(&mut self, sink: &BaseSink) -> Result<(), ErrorMessage>;
fn start(&mut self, sink: &BaseSink, uri: Url) -> Result<(), gst::ErrorMessage>;
fn stop(&mut self, sink: &BaseSink) -> Result<(), gst::ErrorMessage>;
fn render(&mut self, sink: &BaseSink, buffer: &gst::BufferRef) -> Result<(), FlowError>;
}
......@@ -169,7 +169,10 @@ impl BaseSinkImpl<BaseSink> for Sink {
}
(None, _) => {
gst_error!(self.cat, obj: sink, "No URI given");
error_msg!(gst::ResourceError::OpenRead, ["No URI given"]).post(sink);
sink.post_error_message(&gst_error_msg!(
gst::ResourceError::OpenRead,
["No URI given"]
));
return false;
}
};
......@@ -184,7 +187,7 @@ impl BaseSinkImpl<BaseSink> for Sink {
gst_error!(self.cat, obj: sink, "Failed to start: {:?}", msg);
self.uri.lock().unwrap().1 = false;
msg.post(sink);
sink.post_error_message(msg);
false
}
}
......@@ -204,7 +207,7 @@ impl BaseSinkImpl<BaseSink> for Sink {
Err(ref msg) => {
gst_error!(self.cat, obj: sink, "Failed to stop: {:?}", msg);
msg.post(sink);
sink.post_error_message(msg);
false
}
}
......@@ -221,7 +224,7 @@ impl BaseSinkImpl<BaseSink> for Sink {
gst_error!(self.cat, obj: sink, "Failed to render: {:?}", flow_error);
match flow_error {
FlowError::NotNegotiated(ref msg) | FlowError::Error(ref msg) => {
msg.post(sink);
sink.post_error_message(msg);
}
_ => (),
}
......
......@@ -35,8 +35,8 @@ pub trait SourceImpl: Send + 'static {
fn is_seekable(&self, src: &BaseSrc) -> bool;
fn get_size(&self, src: &BaseSrc) -> Option<u64>;
fn start(&mut self, src: &BaseSrc, uri: Url) -> Result<(), ErrorMessage>;
fn stop(&mut self, src: &BaseSrc) -> Result<(), ErrorMessage>;
fn start(&mut self, src: &BaseSrc, uri: Url) -> Result<(), gst::ErrorMessage>;
fn stop(&mut self, src: &BaseSrc) -> Result<(), gst::ErrorMessage>;
fn fill(
&mut self,
src: &BaseSrc,
......@@ -44,7 +44,12 @@ pub trait SourceImpl: Send + 'static {
length: u32,
buffer: &mut gst::BufferRef,
) -> Result<(), FlowError>;
fn seek(&mut self, src: &BaseSrc, start: u64, stop: Option<u64>) -> Result<(), ErrorMessage>;
fn seek(
&mut self,
src: &BaseSrc,
start: u64,
stop: Option<u64>,
) -> Result<(), gst::ErrorMessage>;
}
struct Source {
......@@ -183,7 +188,10 @@ impl BaseSrcImpl<BaseSrc> for Source {
}
(None, _) => {
gst_error!(self.cat, obj: src, "No URI given");
error_msg!(gst::ResourceError::OpenRead, ["No URI given"]).post(src);
src.post_error_message(&gst_error_msg!(
gst::ResourceError::OpenRead,
["No URI given"]
));
return false;
}
};
......@@ -198,7 +206,7 @@ impl BaseSrcImpl<BaseSrc> for Source {
gst_error!(self.cat, obj: src, "Failed to start: {:?}", msg);
self.uri.lock().unwrap().1 = false;
msg.post(src);
src.post_error_message(msg);
false
}
}
......@@ -218,7 +226,7 @@ impl BaseSrcImpl<BaseSrc> for Source {
Err(ref msg) => {
gst_error!(self.cat, obj: src, "Failed to stop: {:?}", msg);
msg.post(src);
src.post_error_message(msg);
false
}
}
......@@ -263,7 +271,7 @@ impl BaseSrcImpl<BaseSrc> for Source {
gst_error!(self.cat, obj: src, "Failed to fill: {:?}", flow_error);
match flow_error {
FlowError::NotNegotiated(ref msg) | FlowError::Error(ref msg) => {
msg.post(src);
src.post_error_message(msg);
}
_ => (),
}
......@@ -292,7 +300,7 @@ impl BaseSrcImpl<BaseSrc> for Source {
Ok(..) => true,
Err(ref msg) => {
gst_error!(self.cat, obj: src, "Failed to seek {:?}", msg);
msg.post(src);
src.post_error_message(msg);
false
}
}
......
......@@ -9,7 +9,6 @@
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::fmt::Error as FmtError;
use std::borrow::Cow;
use glib_ffi;
use gst_ffi;
......@@ -19,111 +18,12 @@ use glib::translate::ToGlibPtr;
use gst;
use gst::prelude::*;
#[macro_export]
macro_rules! error_msg(
// Plain strings
($err:expr, ($msg:expr), [$dbg:expr]) => {
ErrorMessage::new(&$err, Some(From::from($msg)),
Some(From::from($dbg)),
file!(), module_path!(), line!())
};
($err:expr, ($msg:expr)) => {
ErrorMessage::new(&$err, Some(From::from($msg)),
None,
file!(), module_path!(), line!())
};
($err:expr, [$dbg:expr]) => {
ErrorMessage::new(&$err, None,
Some(From::from($dbg)),
file!(), module_path!(), line!())
};
// Format strings
($err:expr, ($($msg:tt)*), [$($dbg:tt)*]) => { {
ErrorMessage::new(&$err, Some(From::from(format!($($msg)*))),
From::from(Some(format!($($dbg)*))),
file!(), module_path!(), line!())
}};
($err:expr, ($($msg:tt)*)) => { {
ErrorMessage::new(&$err, Some(From::from(format!($($msg)*))),
None,
file!(), module_path!(), line!())
}};
($err:expr, [$($dbg:tt)*]) => { {
ErrorMessage::new(&$err, None,
Some(From::from(format!($($dbg)*))),
file!(), module_path!(), line!())
}};
);
#[derive(Debug, PartialEq, Eq)]
pub struct ErrorMessage {
error_domain: glib_ffi::GQuark,
error_code: i32,
message: Option<String>,
debug: Option<String>,
filename: &'static str,
function: &'static str,
line: u32,
}
impl ErrorMessage {
pub fn new<T: gst::MessageErrorDomain>(
error: &T,
message: Option<Cow<str>>,
debug: Option<Cow<str>>,
filename: &'static str,
function: &'static str,
line: u32,
) -> ErrorMessage {
let domain = T::domain();
let code = error.code();
ErrorMessage {
error_domain: domain,
error_code: code,
message: message.map(|m| m.into_owned()),
debug: debug.map(|d| d.into_owned()),
filename: filename,
function: function,
line: line,
}
}
pub fn post<E: IsA<gst::Element>>(&self, element: &E) {
let ErrorMessage {
error_domain,
error_code,
ref message,
ref debug,
filename,
function,
line,
} = *self;
unsafe {
gst_ffi::gst_element_message_full(
element.to_glib_none().0,
gst_ffi::GST_MESSAGE_ERROR,
error_domain,
error_code,
message.to_glib_full(),
debug.to_glib_full(),
filename.to_glib_none().0,
function.to_glib_none().0,
line as i32,
);
}
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum FlowError {
Flushing,
Eos,
NotNegotiated(ErrorMessage),
Error(ErrorMessage),
NotNegotiated(gst::ErrorMessage),
Error(gst::ErrorMessage),
}
impl FlowError {
......@@ -141,18 +41,10 @@ impl Display for FlowError {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
match *self {