Run everything through rustfmt

This commit is contained in:
Sebastian Dröge 2016-07-20 11:28:58 +03:00
parent 3db8882ce8
commit 31fd26b982
7 changed files with 142 additions and 109 deletions

View file

@ -43,27 +43,29 @@ use std::ffi::CString;
extern "C" { extern "C" {
fn gst_rs_source_register(plugin: *const c_void, fn gst_rs_source_register(plugin: *const c_void,
name: *const c_char, name: *const c_char,
long_name: *const c_char, long_name: *const c_char,
description: *const c_char, description: *const c_char,
classification: *const c_char, classification: *const c_char,
author: *const c_char, author: *const c_char,
rank: i32, rank: i32,
create_instance: extern fn() -> *mut Box<Source>, create_instance: extern "C" fn() -> *mut Box<Source>,
protocols: *const c_char, protocols: *const c_char,
push_only: GBoolean) -> GBoolean; push_only: GBoolean)
-> GBoolean;
} }
extern "C" { extern "C" {
fn gst_rs_sink_register(plugin: *const c_void, fn gst_rs_sink_register(plugin: *const c_void,
name: *const c_char, name: *const c_char,
long_name: *const c_char, long_name: *const c_char,
description: *const c_char, description: *const c_char,
classification: *const c_char, classification: *const c_char,
author: *const c_char, author: *const c_char,
rank: i32, rank: i32,
create_instance: extern fn() -> *mut Box<Sink>, create_instance: extern "C" fn() -> *mut Box<Sink>,
protocols: *const c_char) -> GBoolean; protocols: *const c_char)
-> GBoolean;
} }
#[no_mangle] #[no_mangle]
@ -71,26 +73,30 @@ pub extern "C" fn sources_register(plugin: *const c_void) -> GBoolean {
unsafe { unsafe {
gst_rs_source_register(plugin, gst_rs_source_register(plugin,
CString::new("rsfilesrc").unwrap().as_ptr(), CString::new("rsfilesrc").unwrap().as_ptr(),
CString::new("File Source").unwrap().as_ptr(), CString::new("File Source").unwrap().as_ptr(),
CString::new("Reads local files").unwrap().as_ptr(), CString::new("Reads local files").unwrap().as_ptr(),
CString::new("Source/File").unwrap().as_ptr(), CString::new("Source/File").unwrap().as_ptr(),
CString::new("Sebastian Dröge <sebastian@centricular.com>").unwrap().as_ptr(), CString::new("Sebastian Dröge <sebastian@centricular.com>")
256 + 100, .unwrap()
FileSrc::new_ptr, .as_ptr(),
CString::new("file").unwrap().as_ptr(), 256 + 100,
GBoolean::False); FileSrc::new_ptr,
CString::new("file").unwrap().as_ptr(),
GBoolean::False);
gst_rs_source_register(plugin, gst_rs_source_register(plugin,
CString::new("rshttpsrc").unwrap().as_ptr(), CString::new("rshttpsrc").unwrap().as_ptr(),
CString::new("HTTP Source").unwrap().as_ptr(), CString::new("HTTP Source").unwrap().as_ptr(),
CString::new("Read HTTP/HTTPS files").unwrap().as_ptr(), CString::new("Read HTTP/HTTPS files").unwrap().as_ptr(),
CString::new("Source/Network/HTTP").unwrap().as_ptr(), CString::new("Source/Network/HTTP").unwrap().as_ptr(),
CString::new("Sebastian Dröge <sebastian@centricular.com>").unwrap().as_ptr(), CString::new("Sebastian Dröge <sebastian@centricular.com>")
256 + 100, .unwrap()
HttpSrc::new_ptr, .as_ptr(),
CString::new("http:https").unwrap().as_ptr(), 256 + 100,
GBoolean::True); HttpSrc::new_ptr,
CString::new("http:https").unwrap().as_ptr(),
GBoolean::True);
} }
return GBoolean::True; return GBoolean::True;
@ -101,14 +107,16 @@ pub extern "C" fn sinks_register(plugin: *const c_void) -> GBoolean {
unsafe { unsafe {
gst_rs_sink_register(plugin, gst_rs_sink_register(plugin,
CString::new("rsfilesink").unwrap().as_ptr(), CString::new("rsfilesink").unwrap().as_ptr(),
CString::new("File Sink").unwrap().as_ptr(), CString::new("File Sink").unwrap().as_ptr(),
CString::new("Writes to local files").unwrap().as_ptr(), CString::new("Writes to local files").unwrap().as_ptr(),
CString::new("Sink/File").unwrap().as_ptr(), CString::new("Sink/File").unwrap().as_ptr(),
CString::new("Luis de Bethencourt <luisbg@osg.samsung.com>").unwrap().as_ptr(), CString::new("Luis de Bethencourt <luisbg@osg.samsung.com>")
256 + 100, .unwrap()
FileSink::new_ptr, .as_ptr(),
CString::new("file").unwrap().as_ptr()); 256 + 100,
FileSink::new_ptr,
CString::new("file").unwrap().as_ptr());
} }
return GBoolean::True; return GBoolean::True;
} }

View file

@ -38,7 +38,11 @@ unsafe impl Send for FileSink {}
impl FileSink { impl FileSink {
fn new() -> FileSink { fn new() -> FileSink {
FileSink { location: Mutex::new(None), file: None, position: 0 } FileSink {
location: Mutex::new(None),
file: None,
position: 0,
}
} }
fn new_source() -> Box<Sink> { fn new_source() -> Box<Sink> {
@ -57,14 +61,14 @@ impl Sink for FileSink {
let mut location = self.location.lock().unwrap(); let mut location = self.location.lock().unwrap();
*location = None; *location = None;
return true; return true;
}, }
Some(ref uri) => { Some(ref uri) => {
match uri.to_file_path().ok() { match uri.to_file_path().ok() {
Some(p) => { Some(p) => {
let mut location = self.location.lock().unwrap(); let mut location = self.location.lock().unwrap();
*location = Some(p); *location = Some(p);
return true; return true;
}, }
None => { None => {
let mut location = self.location.lock().unwrap(); let mut location = self.location.lock().unwrap();
*location = None; *location = None;
@ -78,7 +82,8 @@ impl Sink for FileSink {
fn get_uri(&self) -> Option<Url> { fn get_uri(&self) -> Option<Url> {
let location = self.location.lock().unwrap(); let location = self.location.lock().unwrap();
(*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()
} }
@ -95,13 +100,15 @@ impl Sink for FileSink {
Ok(file) => { Ok(file) => {
self.file = Some(file); self.file = Some(file);
return true; return true;
}, }
Err(err) => { Err(err) => {
println_err!("Could not open file for writing '{}': {}", location.to_str().unwrap_or("Non-UTF8 path"), err.to_string()); println_err!("Could not open file for writing '{}': {}",
location.to_str().unwrap_or("Non-UTF8 path"),
err.to_string());
return false; return false;
} }
} }
}, }
} }
} }
@ -117,15 +124,13 @@ impl Sink for FileSink {
None => return GstFlowReturn::Error, None => return GstFlowReturn::Error,
Some(ref mut f) => { Some(ref mut f) => {
match f.write_all(data) { match f.write_all(data) {
Ok(_) => { Ok(_) => return GstFlowReturn::Ok,
return GstFlowReturn::Ok
},
Err(err) => { Err(err) => {
println_err!("Failed to write: {}", err); println_err!("Failed to write: {}", err);
return GstFlowReturn::Error return GstFlowReturn::Error;
}, }
} }
}, }
} }
} }
} }

View file

@ -39,7 +39,11 @@ unsafe impl Send for FileSrc {}
impl FileSrc { impl FileSrc {
fn new() -> FileSrc { fn new() -> FileSrc {
FileSrc { location: Mutex::new(None), file: None, position: 0 } FileSrc {
location: Mutex::new(None),
file: None,
position: 0,
}
} }
fn new_source() -> Box<Source> { fn new_source() -> Box<Source> {
@ -58,14 +62,14 @@ impl Source for FileSrc {
let mut location = self.location.lock().unwrap(); let mut location = self.location.lock().unwrap();
*location = None; *location = None;
return true; return true;
}, }
Some(uri) => { Some(uri) => {
match uri.to_file_path().ok() { match uri.to_file_path().ok() {
Some(p) => { Some(p) => {
let mut location = self.location.lock().unwrap(); let mut location = self.location.lock().unwrap();
*location = Some(p); *location = Some(p);
return true; return true;
}, }
None => { None => {
let mut location = self.location.lock().unwrap(); let mut location = self.location.lock().unwrap();
*location = None; *location = None;
@ -79,7 +83,8 @@ impl Source for FileSrc {
fn get_uri(&self) -> Option<Url> { fn get_uri(&self) -> Option<Url> {
let location = self.location.lock().unwrap(); let location = self.location.lock().unwrap();
(*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()
} }
@ -108,13 +113,15 @@ impl Source for FileSrc {
Ok(file) => { Ok(file) => {
self.file = Some(file); self.file = Some(file);
return true; return true;
}, }
Err(err) => { Err(err) => {
println_err!("Failed to open file '{}': {}", location.to_str().unwrap_or("Non-UTF8 path"), err.to_string()); println_err!("Failed to open file '{}': {}",
location.to_str().unwrap_or("Non-UTF8 path"),
err.to_string());
return false; return false;
}, }
} }
}, }
} }
} }
@ -133,7 +140,7 @@ impl Source for FileSrc {
match f.seek(SeekFrom::Start(offset)) { match f.seek(SeekFrom::Start(offset)) {
Ok(_) => { Ok(_) => {
self.position = offset; self.position = offset;
}, }
Err(err) => { Err(err) => {
println_err!("Failed to seek to {}: {}", offset, err.to_string()); println_err!("Failed to seek to {}: {}", offset, err.to_string());
return Err(GstFlowReturn::Error); return Err(GstFlowReturn::Error);
@ -144,14 +151,14 @@ impl Source for FileSrc {
match f.read(data) { match f.read(data) {
Ok(size) => { Ok(size) => {
self.position += size as u64; self.position += size as u64;
return Ok(size) return Ok(size);
}, }
Err(err) => { Err(err) => {
println_err!("Failed to read at {}: {}", offset, err.to_string()); println_err!("Failed to read at {}: {}", offset, err.to_string());
return Err(GstFlowReturn::Error); return Err(GstFlowReturn::Error);
}, }
} }
}, }
} }
} }
@ -159,4 +166,3 @@ impl Source for FileSrc {
true true
} }
} }

View file

@ -18,7 +18,8 @@
use std::u64; use std::u64;
use std::io::Read; use std::io::Read;
use url::Url; use url::Url;
use hyper::header::{ContentLength, ContentRange, ContentRangeSpec, Range, ByteRangeSpec, AcceptRanges, RangeUnit}; use hyper::header::{ContentLength, ContentRange, ContentRangeSpec, Range, ByteRangeSpec,
AcceptRanges, RangeUnit};
use hyper::client::Client; use hyper::client::Client;
use hyper::client::response::Response; use hyper::client::response::Response;
@ -46,7 +47,16 @@ unsafe impl Send for HttpSrc {}
impl HttpSrc { impl HttpSrc {
fn new() -> HttpSrc { fn new() -> HttpSrc {
HttpSrc { url: Mutex::new(None), client: Client::new(), response: None, seekable: AtomicBool::new(false), position: 0, size: u64::MAX, start: 0, stop: u64::MAX } HttpSrc {
url: Mutex::new(None),
client: Client::new(),
response: None,
seekable: AtomicBool::new(false),
position: 0,
size: u64::MAX,
start: 0,
stop: u64::MAX,
}
} }
fn new_source() -> Box<Source> { fn new_source() -> Box<Source> {
@ -71,27 +81,30 @@ impl HttpSrc {
if start != 0 || stop != u64::MAX { if start != 0 || stop != u64::MAX {
req = if stop == u64::MAX { req = if stop == u64::MAX {
req.header(Range::Bytes(vec![ByteRangeSpec::AllFrom(start)])) req.header(Range::Bytes(vec![ByteRangeSpec::AllFrom(start)]))
} else { } else {
req.header(Range::Bytes(vec![ByteRangeSpec::FromTo(start, stop)])) req.header(Range::Bytes(vec![ByteRangeSpec::FromTo(start, stop)]))
}; };
} }
match req.send() { match req.send() {
Ok(response) => { Ok(response) => {
if response.status.is_success() { if response.status.is_success() {
self.size = if let Some(&ContentLength(content_length)) = response.headers.get() { self.size = if let Some(&ContentLength(content_length)) =
response.headers.get() {
content_length + start content_length + start
} else { } else {
u64::MAX u64::MAX
}; };
let accept_byte_ranges = if let Some(&AcceptRanges(ref ranges)) = response.headers.get() { let accept_byte_ranges = if let Some(&AcceptRanges(ref ranges)) =
response.headers.get() {
ranges.iter().any(|u| *u == RangeUnit::Bytes) ranges.iter().any(|u| *u == RangeUnit::Bytes)
} else { } else {
false false
}; };
self.seekable.store(self.size != u64::MAX && accept_byte_ranges, Ordering::Relaxed); self.seekable.store(self.size != u64::MAX && accept_byte_ranges,
Ordering::Relaxed);
self.start = start; self.start = start;
self.stop = stop; self.stop = stop;
@ -114,13 +127,13 @@ impl HttpSrc {
println_err!("Failed to fetch {}: {}", url, response.status); println_err!("Failed to fetch {}: {}", url, response.status);
return false; return false;
} }
}, }
Err(err) => { Err(err) => {
println_err!("Failed to fetch {}: {}", url, err.to_string()); println_err!("Failed to fetch {}: {}", url, err.to_string());
return false; return false;
} }
} }
}, }
} }
} }
} }
@ -137,10 +150,9 @@ impl Source for HttpSrc {
let mut url = self.url.lock().unwrap(); let mut url = self.url.lock().unwrap();
*url = None; *url = None;
return true; return true;
}, }
Some(uri) => { Some(uri) => {
if uri.scheme() == "http" || if uri.scheme() == "http" || uri.scheme() == "https" {
uri.scheme() == "https" {
let mut url = self.url.lock().unwrap(); let mut url = self.url.lock().unwrap();
*url = Some(uri); *url = Some(uri);
return true; return true;
@ -178,7 +190,7 @@ impl Source for HttpSrc {
self.size = u64::MAX; self.size = u64::MAX;
match self.response { match self.response {
Some(ref mut response) => drop(response), Some(ref mut response) => drop(response),
None => () None => (),
} }
self.response = None; self.response = None;
@ -208,15 +220,14 @@ impl Source for HttpSrc {
} }
self.position += size as u64; self.position += size as u64;
return Ok(size) return Ok(size);
}, }
Err(err) => { Err(err) => {
println_err!("Failed to read at {}: {}", offset, err.to_string()); println_err!("Failed to read at {}: {}", offset, err.to_string());
return Err(GstFlowReturn::Error); return Err(GstFlowReturn::Error);
}, }
} }
}, }
} }
} }
} }

View file

@ -43,7 +43,7 @@ pub extern "C" fn sink_drop(ptr: *mut Box<Sink>) {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn sink_set_uri(ptr: *mut Box<Sink>, uri_ptr: *const c_char) -> GBoolean{ pub extern "C" fn sink_set_uri(ptr: *mut Box<Sink>, uri_ptr: *const c_char) -> GBoolean {
let sink: &mut Box<Sink> = unsafe { &mut *ptr }; let sink: &mut Box<Sink> = unsafe { &mut *ptr };
if uri_ptr.is_null() { if uri_ptr.is_null() {
@ -66,15 +66,16 @@ pub extern "C" fn sink_get_uri(ptr: *const Box<Sink>) -> *mut c_char {
let sink: &Box<Sink> = unsafe { &*ptr }; let sink: &Box<Sink> = unsafe { &*ptr };
match sink.get_uri() { match sink.get_uri() {
Some(uri) => Some(uri) => CString::new(uri.into_string().into_bytes()).unwrap().into_raw(),
CString::new(uri.into_string().into_bytes()).unwrap().into_raw(), None => ptr::null_mut(),
None =>
ptr::null_mut()
} }
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn sink_render(ptr: *mut Box<Sink>, data_ptr: *const u8, data_len: usize) -> GstFlowReturn { pub extern "C" fn sink_render(ptr: *mut Box<Sink>,
data_ptr: *const u8,
data_len: usize)
-> GstFlowReturn {
let sink: &mut Box<Sink> = unsafe { &mut *ptr }; let sink: &mut Box<Sink> = unsafe { &mut *ptr };
let data = unsafe { slice::from_raw_parts(data_ptr, data_len) }; let data = unsafe { slice::from_raw_parts(data_ptr, data_len) };

View file

@ -47,7 +47,7 @@ pub extern "C" fn source_drop(ptr: *mut Box<Source>) {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn source_set_uri(ptr: *mut Box<Source>, uri_ptr: *const c_char) -> GBoolean{ pub extern "C" fn source_set_uri(ptr: *mut Box<Source>, uri_ptr: *const c_char) -> GBoolean {
let source: &mut Box<Source> = unsafe { &mut *ptr }; let source: &mut Box<Source> = unsafe { &mut *ptr };
if uri_ptr.is_null() { if uri_ptr.is_null() {
@ -70,15 +70,17 @@ pub extern "C" fn source_get_uri(ptr: *mut Box<Source>) -> *mut c_char {
let source: &mut Box<Source> = unsafe { &mut *ptr }; let source: &mut Box<Source> = unsafe { &mut *ptr };
match source.get_uri() { match source.get_uri() {
Some(uri) => Some(uri) => CString::new(uri.into_string().into_bytes()).unwrap().into_raw(),
CString::new(uri.into_string().into_bytes()).unwrap().into_raw(), None => ptr::null_mut(),
None =>
ptr::null_mut()
} }
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn source_fill(ptr: *mut Box<Source>, offset: u64, data_ptr: *mut u8, data_len_ptr: *mut usize) -> GstFlowReturn { pub extern "C" fn source_fill(ptr: *mut Box<Source>,
offset: u64,
data_ptr: *mut u8,
data_len_ptr: *mut usize)
-> GstFlowReturn {
let source: &mut Box<Source> = unsafe { &mut *ptr }; let source: &mut Box<Source> = unsafe { &mut *ptr };
let mut data_len: &mut usize = unsafe { &mut *data_len_ptr }; let mut data_len: &mut usize = unsafe { &mut *data_len_ptr };
@ -87,14 +89,14 @@ pub extern "C" fn source_fill(ptr: *mut Box<Source>, offset: u64, data_ptr: *mut
Ok(actual_len) => { Ok(actual_len) => {
*data_len = actual_len; *data_len = actual_len;
GstFlowReturn::Ok GstFlowReturn::Ok
}, }
Err(ret) => ret, Err(ret) => ret,
} }
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn source_get_size(ptr: *const Box<Source>) -> u64 { pub extern "C" fn source_get_size(ptr: *const Box<Source>) -> u64 {
let source: &Box<Source> = unsafe { & *ptr }; let source: &Box<Source> = unsafe { &*ptr };
return source.get_size(); return source.get_size();
} }
@ -115,7 +117,7 @@ pub extern "C" fn source_stop(ptr: *mut Box<Source>) -> GBoolean {
#[no_mangle] #[no_mangle]
pub extern "C" fn source_is_seekable(ptr: *const Box<Source>) -> GBoolean { pub extern "C" fn source_is_seekable(ptr: *const Box<Source>) -> GBoolean {
let source: &Box<Source> = unsafe { & *ptr }; let source: &Box<Source> = unsafe { &*ptr };
GBoolean::from_bool(source.is_seekable()) GBoolean::from_bool(source.is_seekable())
} }
@ -126,4 +128,3 @@ pub extern "C" fn source_do_seek(ptr: *mut Box<Source>, start: u64, stop: u64) -
GBoolean::from_bool(source.do_seek(start, stop)) GBoolean::from_bool(source.do_seek(start, stop))
} }

View file

@ -23,7 +23,7 @@ use std::ffi::CString;
macro_rules! println_err( macro_rules! println_err(
($($arg:tt)*) => { { ($($arg:tt)*) => { {
let r = writeln!(&mut ::std::io::stderr(), $($arg)*); let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
// Ignore when writing fails // Ignore when writing fails
match r { match r {
Ok(_) => (), Ok(_) => (),
Err(_) => () Err(_) => ()
@ -58,6 +58,7 @@ impl GBoolean {
#[no_mangle] #[no_mangle]
pub extern "C" fn cstring_drop(ptr: *mut c_char) { pub extern "C" fn cstring_drop(ptr: *mut c_char) {
unsafe { CString::from_raw(ptr); } unsafe {
CString::from_raw(ptr);
}
} }