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

Various cleanups

parent 086ec5b6
......@@ -63,7 +63,7 @@ impl FileSink {
impl Sink for FileSink {
fn set_uri(&self, uri: Option<Url>) -> bool {
let ref mut location = self.settings.lock().unwrap().location;
let location = &mut self.settings.lock().unwrap().location;
match uri {
None => {
......@@ -87,14 +87,14 @@ impl Sink for FileSink {
}
fn get_uri(&self) -> Option<Url> {
let ref location = self.settings.lock().unwrap().location;
let location = &self.settings.lock().unwrap().location;
location.as_ref()
.map(|l| Url::from_file_path(l).ok())
.and_then(|i| i) // join()
}
fn start(&self) -> bool {
let ref location = self.settings.lock().unwrap().location;
let location = &self.settings.lock().unwrap().location;
let mut streaming_state = self.streaming_state.lock().unwrap();
if let StreamingState::Started { .. } = *streaming_state {
......@@ -137,15 +137,15 @@ impl Sink for FileSink {
match file.write_all(data) {
Ok(_) => {
*position += data.len() as u64;
return GstFlowReturn::Ok;
GstFlowReturn::Ok
}
Err(err) => {
println_err!("Failed to write: {}", err);
return GstFlowReturn::Error;
GstFlowReturn::Error
}
}
} else {
return GstFlowReturn::Error;
GstFlowReturn::Error
}
}
}
......@@ -64,7 +64,7 @@ impl FileSrc {
impl Source for FileSrc {
fn set_uri(&self, uri: Option<Url>) -> bool {
let ref mut location = self.settings.lock().unwrap().location;
let location = &mut self.settings.lock().unwrap().location;
match uri {
None => {
......@@ -88,7 +88,8 @@ impl Source for FileSrc {
}
fn get_uri(&self) -> Option<Url> {
let ref location = self.settings.lock().unwrap().location;
let location = &self.settings.lock().unwrap().location;
location.as_ref()
.map(|l| Url::from_file_path(l).ok())
.and_then(|i| i) // join()
......@@ -104,15 +105,14 @@ impl Source for FileSrc {
if let StreamingState::Started { ref file, .. } = *streaming_state {
file.metadata()
.ok()
.map(|m| m.len())
.unwrap_or(u64::MAX)
.map_or(u64::MAX, |m| m.len())
} else {
u64::MAX
}
}
fn start(&self) -> bool {
let ref location = self.settings.lock().unwrap().location;
let location = &self.settings.lock().unwrap().location;
let mut streaming_state = self.streaming_state.lock().unwrap();
if let StreamingState::Started { .. } = *streaming_state {
......
......@@ -73,7 +73,7 @@ impl HttpSrc {
}
fn do_request(&self, start: u64, stop: u64) -> StreamingState {
let ref url = self.settings.lock().unwrap().url;
let url = &self.settings.lock().unwrap().url;
match *url {
None => StreamingState::Stopped,
......@@ -142,29 +142,29 @@ impl HttpSrc {
impl Source for HttpSrc {
fn set_uri(&self, uri: Option<Url>) -> bool {
let ref mut url = self.settings.lock().unwrap().url;
let url = &mut self.settings.lock().unwrap().url;
match uri {
None => {
*url = None;
return true;
true
}
Some(uri) => {
if uri.scheme() == "http" || uri.scheme() == "https" {
*url = Some(uri);
return true;
true
} else {
*url = None;
println_err!("Unsupported URI '{}'", uri.as_str());
return false;
false
}
}
}
}
fn get_uri(&self) -> Option<Url> {
let ref url = self.settings.lock().unwrap().url;
url.as_ref().map(|u| u.clone())
let url = &self.settings.lock().unwrap().url;
url.as_ref().cloned()
}
fn is_seekable(&self) -> bool {
......
......@@ -22,11 +22,8 @@ use std::ffi::CString;
#[macro_export]
macro_rules! println_err(
($($arg:tt)*) => { {
let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
if let Err(_) = writeln!(&mut ::std::io::stderr(), $($arg)*) {
// Ignore when writing fails
match r {
Ok(_) => (),
Err(_) => ()
};
} }
);
......
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