Various cleanups

This commit is contained in:
Sebastian Dröge 2016-08-22 22:35:16 +03:00
parent 086ec5b68d
commit bb8072c4d8
4 changed files with 19 additions and 22 deletions

View file

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

View file

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

View file

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

View file

@ -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(_) => ()
};
} }
);