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 { impl Sink for FileSink {
fn set_uri(&self, uri: Option<Url>) -> bool { 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 { match uri {
None => { None => {
@ -87,14 +87,14 @@ impl Sink for FileSink {
} }
fn get_uri(&self) -> Option<Url> { fn get_uri(&self) -> Option<Url> {
let ref location = self.settings.lock().unwrap().location; let location = &self.settings.lock().unwrap().location;
location.as_ref() location.as_ref()
.map(|l| Url::from_file_path(l).ok()) .map(|l| Url::from_file_path(l).ok())
.and_then(|i| i) // join() .and_then(|i| i) // join()
} }
fn start(&self) -> bool { 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(); let mut streaming_state = self.streaming_state.lock().unwrap();
if let StreamingState::Started { .. } = *streaming_state { if let StreamingState::Started { .. } = *streaming_state {
@ -137,15 +137,15 @@ impl Sink for FileSink {
match file.write_all(data) { match file.write_all(data) {
Ok(_) => { Ok(_) => {
*position += data.len() as u64; *position += data.len() as u64;
return GstFlowReturn::Ok; GstFlowReturn::Ok
} }
Err(err) => { Err(err) => {
println_err!("Failed to write: {}", err); println_err!("Failed to write: {}", err);
return GstFlowReturn::Error; GstFlowReturn::Error
} }
} }
} else { } else {
return GstFlowReturn::Error; GstFlowReturn::Error
} }
} }
} }

View file

@ -64,7 +64,7 @@ impl FileSrc {
impl Source for FileSrc { impl Source for FileSrc {
fn set_uri(&self, uri: Option<Url>) -> bool { 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 { match uri {
None => { None => {
@ -88,7 +88,8 @@ impl Source for FileSrc {
} }
fn get_uri(&self) -> Option<Url> { fn get_uri(&self) -> Option<Url> {
let ref location = self.settings.lock().unwrap().location; let location = &self.settings.lock().unwrap().location;
location.as_ref() location.as_ref()
.map(|l| Url::from_file_path(l).ok()) .map(|l| Url::from_file_path(l).ok())
.and_then(|i| i) // join() .and_then(|i| i) // join()
@ -104,15 +105,14 @@ impl Source for FileSrc {
if let StreamingState::Started { ref file, .. } = *streaming_state { if let StreamingState::Started { ref file, .. } = *streaming_state {
file.metadata() file.metadata()
.ok() .ok()
.map(|m| m.len()) .map_or(u64::MAX, |m| m.len())
.unwrap_or(u64::MAX)
} else { } else {
u64::MAX u64::MAX
} }
} }
fn start(&self) -> bool { 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(); let mut streaming_state = self.streaming_state.lock().unwrap();
if let StreamingState::Started { .. } = *streaming_state { if let StreamingState::Started { .. } = *streaming_state {

View file

@ -73,7 +73,7 @@ impl HttpSrc {
} }
fn do_request(&self, start: u64, stop: u64) -> StreamingState { 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 { match *url {
None => StreamingState::Stopped, None => StreamingState::Stopped,
@ -142,29 +142,29 @@ impl HttpSrc {
impl Source for HttpSrc { impl Source for HttpSrc {
fn set_uri(&self, uri: Option<Url>) -> bool { 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 { match uri {
None => { None => {
*url = None; *url = None;
return true; true
} }
Some(uri) => { Some(uri) => {
if uri.scheme() == "http" || uri.scheme() == "https" { if uri.scheme() == "http" || uri.scheme() == "https" {
*url = Some(uri); *url = Some(uri);
return true; true
} else { } else {
*url = None; *url = None;
println_err!("Unsupported URI '{}'", uri.as_str()); println_err!("Unsupported URI '{}'", uri.as_str());
return false; false
} }
} }
} }
} }
fn get_uri(&self) -> Option<Url> { fn get_uri(&self) -> Option<Url> {
let ref url = self.settings.lock().unwrap().url; let url = &self.settings.lock().unwrap().url;
url.as_ref().map(|u| u.clone()) url.as_ref().cloned()
} }
fn is_seekable(&self) -> bool { fn is_seekable(&self) -> bool {

View file

@ -22,11 +22,8 @@ use std::ffi::CString;
#[macro_export] #[macro_export]
macro_rules! println_err( macro_rules! println_err(
($($arg:tt)*) => { { ($($arg:tt)*) => { {
let r = writeln!(&mut ::std::io::stderr(), $($arg)*); if let Err(_) = writeln!(&mut ::std::io::stderr(), $($arg)*) {
// Ignore when writing fails // Ignore when writing fails
match r {
Ok(_) => (),
Err(_) => ()
}; };
} } } }
); );