Commit 9864413b authored by Sebastian Dröge's avatar Sebastian Dröge 🍵
Browse files

Run everything through new rustfmt

parent 021de8af
......@@ -51,10 +51,12 @@ impl FileSink {
}
fn validate_uri(uri: &Url) -> Result<(), UriError> {
let _ = try!(uri.to_file_path().or_else(|_| {
Err(UriError::new(UriErrorKind::UnsupportedProtocol,
Some(format!("Unsupported file URI '{}'", uri.as_str()))))
}));
let _ = try!(uri.to_file_path()
.or_else(|_| {
Err(UriError::new(UriErrorKind::UnsupportedProtocol,
Some(format!("Unsupported file URI '{}'",
uri.as_str()))))
}));
Ok(())
}
......@@ -68,11 +70,13 @@ impl Sink for FileSink {
return Err(error_msg!(SinkError::Failure, ["Sink already started"]));
}
let location = try!(uri.to_file_path().or_else(|_| {
error!(self.logger, "Unsupported file URI '{}'", uri.as_str());
Err(error_msg!(SinkError::Failure,
["Unsupported file URI '{}'", uri.as_str()]))
}));
let location =
try!(uri.to_file_path()
.or_else(|_| {
error!(self.logger, "Unsupported file URI '{}'", uri.as_str());
Err(error_msg!(SinkError::Failure,
["Unsupported file URI '{}'", uri.as_str()]))
}));
let file = try!(File::create(location.as_path()).or_else(|err| {
......@@ -108,7 +112,10 @@ impl Sink for FileSink {
trace!(logger, "Rendering {:?}", buffer);
let (file, position) = match self.streaming_state {
StreamingState::Started { ref mut file, ref mut position } => (file, position),
StreamingState::Started {
ref mut file,
ref mut position,
} => (file, position),
StreamingState::Stopped => {
return Err(FlowError::Error(error_msg!(SinkError::Failure, ["Not started yet"])));
}
......@@ -123,10 +130,12 @@ impl Sink for FileSink {
};
let data = map.as_slice();
try!(file.write_all(data).or_else(|err| {
error!(logger, "Failed to write: {}", err);
Err(FlowError::Error(error_msg!(SinkError::WriteFailed, ["Failed to write: {}", err])))
}));
try!(file.write_all(data)
.or_else(|err| {
error!(logger, "Failed to write: {}", err);
Err(FlowError::Error(error_msg!(SinkError::WriteFailed,
["Failed to write: {}", err])))
}));
*position += data.len() as u64;
......
......@@ -49,10 +49,12 @@ impl FileSrc {
}
fn validate_uri(uri: &Url) -> Result<(), UriError> {
let _ = try!(uri.to_file_path().or_else(|_| {
Err(UriError::new(UriErrorKind::UnsupportedProtocol,
Some(format!("Unsupported file URI '{}'", uri.as_str()))))
}));
let _ = try!(uri.to_file_path()
.or_else(|_| {
Err(UriError::new(UriErrorKind::UnsupportedProtocol,
Some(format!("Unsupported file URI '{}'",
uri.as_str()))))
}));
Ok(())
}
......@@ -78,11 +80,13 @@ impl Source for FileSrc {
return Err(error_msg!(SourceError::Failure, ["Source already started"]));
}
let location = try!(uri.to_file_path().or_else(|_| {
error!(self.logger, "Unsupported file URI '{}'", uri.as_str());
Err(error_msg!(SourceError::Failure,
["Unsupported file URI '{}'", uri.as_str()]))
}));
let location =
try!(uri.to_file_path()
.or_else(|_| {
error!(self.logger, "Unsupported file URI '{}'", uri.as_str());
Err(error_msg!(SourceError::Failure,
["Unsupported file URI '{}'", uri.as_str()]))
}));
let file = try!(File::open(location.as_path()).or_else(|err| {
error!(self.logger,
......@@ -115,20 +119,24 @@ impl Source for FileSrc {
let logger = self.logger.clone();
let (file, position) = match self.streaming_state {
StreamingState::Started { ref mut file, ref mut position } => (file, position),
StreamingState::Started {
ref mut file,
ref mut position,
} => (file, position),
StreamingState::Stopped => {
return Err(FlowError::Error(error_msg!(SourceError::Failure, ["Not started yet"])));
}
};
if *position != offset {
try!(file.seek(SeekFrom::Start(offset)).or_else(|err| {
error!(logger, "Failed to seek to {}: {:?}", offset, err);
Err(FlowError::Error(error_msg!(SourceError::SeekFailed,
["Failed to seek to {}: {}",
offset,
err.to_string()])))
}));
try!(file.seek(SeekFrom::Start(offset))
.or_else(|err| {
error!(logger, "Failed to seek to {}: {:?}", offset, err);
Err(FlowError::Error(error_msg!(SourceError::SeekFailed,
["Failed to seek to {}: {}",
offset,
err.to_string()])))
}));
*position = offset;
}
......@@ -143,13 +151,14 @@ impl Source for FileSrc {
let data = map.as_mut_slice();
try!(file.read(data).or_else(|err| {
error!(logger, "Failed to read: {:?}", err);
Err(FlowError::Error(error_msg!(SourceError::ReadFailed,
["Failed to read at {}: {}",
offset,
err.to_string()])))
}))
try!(file.read(data)
.or_else(|err| {
error!(logger, "Failed to read: {:?}", err);
Err(FlowError::Error(error_msg!(SourceError::ReadFailed,
["Failed to read at {}: {}",
offset,
err.to_string()])))
}))
};
*position += size as u64;
......
......@@ -76,11 +76,13 @@ impl HttpSrc {
debug!(self.logger, "Doing new request {:?}", req);
let response = try!(req.send().or_else(|err| {
error!(self.logger, "Request failed: {:?}", err);
Err(error_msg!(SourceError::ReadFailed,
["Failed to fetch {}: {}", uri, err.to_string()]))
}));
let response =
try!(req.send()
.or_else(|err| {
error!(self.logger, "Request failed: {:?}", err);
Err(error_msg!(SourceError::ReadFailed,
["Failed to fetch {}: {}", uri, err.to_string()]))
}));
if !response.status().is_success() {
error!(self.logger, "Request status failed: {:?}", response);
......@@ -88,7 +90,10 @@ impl HttpSrc {
["Failed to fetch {}: {}", uri, response.status()]));
}
let size = response.headers().get().map(|&ContentLength(cl)| cl + start);
let size = response
.headers()
.get()
.map(|&ContentLength(cl)| cl + start);
let accept_byte_ranges = if let Some(&AcceptRanges(ref ranges)) =
response.headers().get() {
......@@ -99,10 +104,9 @@ impl HttpSrc {
let seekable = size.is_some() && accept_byte_ranges;
let position = if let Some(&ContentRange(ContentRangeSpec::Bytes { range: Some((range_start,
_)),
.. })) = response.headers()
.get() {
let position = if let Some(&ContentRange(ContentRangeSpec::Bytes {
range: Some((range_start, _)), ..
})) = response.headers().get() {
range_start
} else {
start
......@@ -170,9 +174,12 @@ impl Source for HttpSrc {
fn seek(&mut self, start: u64, stop: Option<u64>) -> Result<(), ErrorMessage> {
let (position, old_stop, uri) = match self.streaming_state {
StreamingState::Started { position, stop, ref uri, .. } => {
(position, stop, uri.clone())
}
StreamingState::Started {
position,
stop,
ref uri,
..
} => (position, stop, uri.clone()),
StreamingState::Stopped => {
return Err(error_msg!(SourceError::Failure, ["Not started yet"]));
}
......@@ -192,9 +199,11 @@ impl Source for HttpSrc {
let logger = self.logger.clone();
let (response, position) = match self.streaming_state {
StreamingState::Started { ref mut response, ref mut position, .. } => {
(response, position)
}
StreamingState::Started {
ref mut response,
ref mut position,
..
} => (response, position),
StreamingState::Stopped => {
return Err(FlowError::Error(error_msg!(SourceError::Failure, ["Not started yet"])));
}
......@@ -218,13 +227,15 @@ impl Source for HttpSrc {
let data = map.as_mut_slice();
try!(response.read(data).or_else(|err| {
error!(logger, "Failed to read: {:?}", err);
Err(FlowError::Error(error_msg!(SourceError::ReadFailed,
["Failed to read at {}: {}",
offset,
err.to_string()])))
}))
try!(response
.read(data)
.or_else(|err| {
error!(logger, "Failed to read: {:?}", err);
Err(FlowError::Error(error_msg!(SourceError::ReadFailed,
["Failed to read at {}: {}",
offset,
err.to_string()])))
}))
};
if size == 0 {
......
......@@ -55,7 +55,8 @@ impl Adapter {
buffer,
size,
self.size);
self.deque.push_back(Buffer::into_read_mapped_buffer(buffer).unwrap());
self.deque
.push_back(Buffer::into_read_mapped_buffer(buffer).unwrap());
}
pub fn clear(&mut self) {
......@@ -163,13 +164,18 @@ impl Adapter {
return Ok(Buffer::new());
}
let sub = self.deque.front().and_then(|front| if front.get_size() - self.skip >= size {
trace!(LOGGER, "Get buffer of {} bytes, subbuffer of first", size);
let new = front.get_buffer().copy_region(self.skip, Some(size)).unwrap();
Some(new)
} else {
None
});
let sub = self.deque
.front()
.and_then(|front| if front.get_size() - self.skip >= size {
trace!(LOGGER, "Get buffer of {} bytes, subbuffer of first", size);
let new = front
.get_buffer()
.copy_region(self.skip, Some(size))
.unwrap();
Some(new)
} else {
None
});
if let Some(s) = sub {
self.flush(size).unwrap();
......@@ -179,10 +185,7 @@ impl Adapter {
trace!(LOGGER, "Get buffer of {} bytes, copy into new buffer", size);
let mut new = Buffer::new_with_size(size).unwrap();
{
let mut map = new.get_mut()
.unwrap()
.map_readwrite()
.unwrap();
let mut map = new.get_mut().unwrap().map_readwrite().unwrap();
let data = map.as_mut_slice();
Self::copy_data(&self.deque, self.skip, data, size);
}
......@@ -207,10 +210,7 @@ impl Adapter {
let mut left = size;
while left > 0 {
let front_size = self.deque
.front()
.unwrap()
.get_size() - self.skip;
let front_size = self.deque.front().unwrap().get_size() - self.skip;
if front_size <= left {
trace!(LOGGER,
......
......@@ -102,18 +102,24 @@ impl ErrorMessage {
pub unsafe fn post(&self, element: *mut gst::GstElement) {
let ErrorMessage { error_domain,
error_code,
ref message,
ref debug,
filename,
function,
line } = *self;
let message_cstr = message.as_ref().map(|m| CString::new(m.as_bytes()).unwrap());
let ErrorMessage {
error_domain,
error_code,
ref message,
ref debug,
filename,
function,
line,
} = *self;
let message_cstr = message
.as_ref()
.map(|m| CString::new(m.as_bytes()).unwrap());
let message_ptr = message_cstr.as_ref().map_or(ptr::null(), |m| m.as_ptr());
let debug_cstr = debug.as_ref().map(|m| CString::new(m.as_bytes()).unwrap());
let debug_cstr = debug
.as_ref()
.map(|m| CString::new(m.as_bytes()).unwrap());
let debug_ptr = debug_cstr.as_ref().map_or(ptr::null(), |m| m.as_ptr());
let file_cstr = CString::new(filename.as_bytes()).unwrap();
......
......@@ -44,9 +44,9 @@ impl<T: MiniObject> GstRc<T> {
return &mut self.obj;
}
self.obj.replace_ptr(gst::gst_mini_object_make_writable(ptr as
*mut gst::GstMiniObject) as
*mut T::PtrType);
self.obj
.replace_ptr(gst::gst_mini_object_make_writable(ptr as *mut gst::GstMiniObject) as
*mut T::PtrType);
assert!(self.is_writable());
&mut self.obj
......
......@@ -119,7 +119,10 @@ impl SinkWrapper {
fn get_uri(&self) -> Option<String> {
let uri_storage = &self.uri.lock().unwrap();
uri_storage.0.as_ref().map(|uri| String::from(uri.as_str()))
uri_storage
.0
.as_ref()
.map(|uri| String::from(uri.as_str()))
}
fn start(&self) -> bool {
......@@ -147,10 +150,7 @@ impl SinkWrapper {
Err(ref msg) => {
error!(self.logger, "Failed to start: {:?}", msg);
self.uri
.lock()
.unwrap()
.1 = false;
self.uri.lock().unwrap().1 = false;
self.post_message(msg);
false
}
......@@ -165,10 +165,7 @@ impl SinkWrapper {
match sink.stop() {
Ok(..) => {
trace!(self.logger, "Stopped successfully");
self.uri
.lock()
.unwrap()
.1 = false;
self.uri.lock().unwrap().1 = false;
true
}
Err(ref msg) => {
......@@ -356,7 +353,8 @@ unsafe extern "C" fn sink_class_init(klass: glib::gpointer, klass_data: glib::gp
let sink_info = &*(klass_data as *const SinkInfo);
{
let gobject_klass = &mut sink_klass.parent_class
let gobject_klass = &mut sink_klass
.parent_class
.parent_class
.parent_class
.parent_class;
......
......@@ -122,7 +122,10 @@ impl SourceWrapper {
fn get_uri(&self) -> Option<String> {
let uri_storage = &self.uri.lock().unwrap();
uri_storage.0.as_ref().map(|uri| String::from(uri.as_str()))
uri_storage
.0
.as_ref()
.map(|uri| String::from(uri.as_str()))
}
fn is_seekable(&self) -> bool {
......@@ -160,10 +163,7 @@ impl SourceWrapper {
Err(ref msg) => {
error!(self.logger, "Failed to start: {:?}", msg);
self.uri
.lock()
.unwrap()
.1 = false;
self.uri.lock().unwrap().1 = false;
self.post_message(msg);
false
}
......@@ -178,10 +178,7 @@ impl SourceWrapper {
match source.stop() {
Ok(..) => {
trace!(self.logger, "Stopped successfully");
self.uri
.lock()
.unwrap()
.1 = false;
self.uri.lock().unwrap().1 = false;
true
}
Err(ref msg) => {
......@@ -434,7 +431,8 @@ unsafe extern "C" fn source_class_init(klass: glib::gpointer, klass_data: glib::
let source_info = &*(klass_data as *const SourceInfo);
{
let gobject_klass = &mut src_klass.parent_class
let gobject_klass = &mut src_klass
.parent_class
.parent_class
.parent_class
.parent_class
......
......@@ -45,7 +45,8 @@ impl Stream {
flags: StreamFlags)
-> Self {
let stream_id_cstr = CString::new(stream_id).unwrap();
let caps = caps.map(|caps| unsafe { caps.as_ptr() }).unwrap_or(ptr::null_mut());
let caps = caps.map(|caps| unsafe { caps.as_ptr() })
.unwrap_or(ptr::null_mut());
Stream(unsafe {
gst::gst_stream_new(stream_id_cstr.as_ptr(),
......@@ -93,7 +94,8 @@ impl Stream {
}
pub fn set_caps(&self, caps: Option<GstRc<Caps>>) {
let ptr = caps.map(|caps| unsafe { caps.as_ptr() }).unwrap_or(ptr::null_mut());
let ptr = caps.map(|caps| unsafe { caps.as_ptr() })
.unwrap_or(ptr::null_mut());
unsafe { gst::gst_stream_set_caps(self.0, ptr) }
}
......@@ -107,7 +109,8 @@ impl Stream {
}
pub fn set_tags(&self, tags: Option<TagList>) {
let ptr = tags.map(|tags| unsafe { tags.as_ptr() }).unwrap_or(ptr::null_mut());
let ptr = tags.map(|tags| unsafe { tags.as_ptr() })
.unwrap_or(ptr::null_mut());
unsafe { gst::gst_stream_set_tags(self.0, ptr) }
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment