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

Run everything through rustfmt

parent 3db8882c
......@@ -43,27 +43,29 @@ use std::ffi::CString;
extern "C" {
fn gst_rs_source_register(plugin: *const c_void,
name: *const c_char,
long_name: *const c_char,
description: *const c_char,
classification: *const c_char,
author: *const c_char,
rank: i32,
create_instance: extern fn() -> *mut Box<Source>,
protocols: *const c_char,
push_only: GBoolean) -> GBoolean;
name: *const c_char,
long_name: *const c_char,
description: *const c_char,
classification: *const c_char,
author: *const c_char,
rank: i32,
create_instance: extern "C" fn() -> *mut Box<Source>,
protocols: *const c_char,
push_only: GBoolean)
-> GBoolean;
}
extern "C" {
fn gst_rs_sink_register(plugin: *const c_void,
name: *const c_char,
long_name: *const c_char,
description: *const c_char,
classification: *const c_char,
author: *const c_char,
rank: i32,
create_instance: extern fn() -> *mut Box<Sink>,
protocols: *const c_char) -> GBoolean;
name: *const c_char,
long_name: *const c_char,
description: *const c_char,
classification: *const c_char,
author: *const c_char,
rank: i32,
create_instance: extern "C" fn() -> *mut Box<Sink>,
protocols: *const c_char)
-> GBoolean;
}
#[no_mangle]
......@@ -71,26 +73,30 @@ pub extern "C" fn sources_register(plugin: *const c_void) -> GBoolean {
unsafe {
gst_rs_source_register(plugin,
CString::new("rsfilesrc").unwrap().as_ptr(),
CString::new("File Source").unwrap().as_ptr(),
CString::new("Reads local files").unwrap().as_ptr(),
CString::new("Source/File").unwrap().as_ptr(),
CString::new("Sebastian Dröge <sebastian@centricular.com>").unwrap().as_ptr(),
256 + 100,
FileSrc::new_ptr,
CString::new("file").unwrap().as_ptr(),
GBoolean::False);
CString::new("rsfilesrc").unwrap().as_ptr(),
CString::new("File Source").unwrap().as_ptr(),
CString::new("Reads local files").unwrap().as_ptr(),
CString::new("Source/File").unwrap().as_ptr(),
CString::new("Sebastian Dröge <sebastian@centricular.com>")
.unwrap()
.as_ptr(),
256 + 100,
FileSrc::new_ptr,
CString::new("file").unwrap().as_ptr(),
GBoolean::False);
gst_rs_source_register(plugin,
CString::new("rshttpsrc").unwrap().as_ptr(),
CString::new("HTTP Source").unwrap().as_ptr(),
CString::new("Read HTTP/HTTPS files").unwrap().as_ptr(),
CString::new("Source/Network/HTTP").unwrap().as_ptr(),
CString::new("Sebastian Dröge <sebastian@centricular.com>").unwrap().as_ptr(),
256 + 100,
HttpSrc::new_ptr,
CString::new("http:https").unwrap().as_ptr(),
GBoolean::True);
CString::new("rshttpsrc").unwrap().as_ptr(),
CString::new("HTTP Source").unwrap().as_ptr(),
CString::new("Read HTTP/HTTPS files").unwrap().as_ptr(),
CString::new("Source/Network/HTTP").unwrap().as_ptr(),
CString::new("Sebastian Dröge <sebastian@centricular.com>")
.unwrap()
.as_ptr(),
256 + 100,
HttpSrc::new_ptr,
CString::new("http:https").unwrap().as_ptr(),
GBoolean::True);
}
return GBoolean::True;
......@@ -101,14 +107,16 @@ pub extern "C" fn sinks_register(plugin: *const c_void) -> GBoolean {
unsafe {
gst_rs_sink_register(plugin,
CString::new("rsfilesink").unwrap().as_ptr(),
CString::new("File Sink").unwrap().as_ptr(),
CString::new("Writes to local files").unwrap().as_ptr(),
CString::new("Sink/File").unwrap().as_ptr(),
CString::new("Luis de Bethencourt <luisbg@osg.samsung.com>").unwrap().as_ptr(),
256 + 100,
FileSink::new_ptr,
CString::new("file").unwrap().as_ptr());
CString::new("rsfilesink").unwrap().as_ptr(),
CString::new("File Sink").unwrap().as_ptr(),
CString::new("Writes to local files").unwrap().as_ptr(),
CString::new("Sink/File").unwrap().as_ptr(),
CString::new("Luis de Bethencourt <luisbg@osg.samsung.com>")
.unwrap()
.as_ptr(),
256 + 100,
FileSink::new_ptr,
CString::new("file").unwrap().as_ptr());
}
return GBoolean::True;
}
......@@ -38,7 +38,11 @@ unsafe impl Send for FileSink {}
impl 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> {
......@@ -57,14 +61,14 @@ impl Sink for FileSink {
let mut location = self.location.lock().unwrap();
*location = None;
return true;
},
}
Some(ref uri) => {
match uri.to_file_path().ok() {
Some(p) => {
let mut location = self.location.lock().unwrap();
*location = Some(p);
return true;
},
}
None => {
let mut location = self.location.lock().unwrap();
*location = None;
......@@ -78,7 +82,8 @@ impl Sink for FileSink {
fn get_uri(&self) -> Option<Url> {
let location = self.location.lock().unwrap();
(*location).as_ref()
(*location)
.as_ref()
.map(|l| Url::from_file_path(l).ok())
.and_then(|i| i) // join()
}
......@@ -95,13 +100,15 @@ impl Sink for FileSink {
Ok(file) => {
self.file = Some(file);
return true;
},
}
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;
}
}
},
}
}
}
......@@ -117,15 +124,13 @@ impl Sink for FileSink {
None => return GstFlowReturn::Error,
Some(ref mut f) => {
match f.write_all(data) {
Ok(_) => {
return GstFlowReturn::Ok
},
Ok(_) => return GstFlowReturn::Ok,
Err(err) => {
println_err!("Failed to write: {}", err);
return GstFlowReturn::Error
},
return GstFlowReturn::Error;
}
}
},
}
}
}
}
......@@ -39,7 +39,11 @@ unsafe impl Send for FileSrc {}
impl 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> {
......@@ -58,14 +62,14 @@ impl Source for FileSrc {
let mut location = self.location.lock().unwrap();
*location = None;
return true;
},
}
Some(uri) => {
match uri.to_file_path().ok() {
Some(p) => {
let mut location = self.location.lock().unwrap();
*location = Some(p);
return true;
},
}
None => {
let mut location = self.location.lock().unwrap();
*location = None;
......@@ -79,7 +83,8 @@ impl Source for FileSrc {
fn get_uri(&self) -> Option<Url> {
let location = self.location.lock().unwrap();
(*location).as_ref()
(*location)
.as_ref()
.map(|l| Url::from_file_path(l).ok())
.and_then(|i| i) // join()
}
......@@ -108,13 +113,15 @@ impl Source for FileSrc {
Ok(file) => {
self.file = Some(file);
return true;
},
}
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;
},
}
}
},
}
}
}
......@@ -133,7 +140,7 @@ impl Source for FileSrc {
match f.seek(SeekFrom::Start(offset)) {
Ok(_) => {
self.position = offset;
},
}
Err(err) => {
println_err!("Failed to seek to {}: {}", offset, err.to_string());
return Err(GstFlowReturn::Error);
......@@ -144,14 +151,14 @@ impl Source for FileSrc {
match f.read(data) {
Ok(size) => {
self.position += size as u64;
return Ok(size)
},
return Ok(size);
}
Err(err) => {
println_err!("Failed to read at {}: {}", offset, err.to_string());
return Err(GstFlowReturn::Error);
},
}
}
},
}
}
}
......@@ -159,4 +166,3 @@ impl Source for FileSrc {
true
}
}
......@@ -18,7 +18,8 @@
use std::u64;
use std::io::Read;
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::response::Response;
......@@ -46,7 +47,16 @@ unsafe impl Send for HttpSrc {}
impl 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> {
......@@ -71,27 +81,30 @@ impl HttpSrc {
if start != 0 || stop != u64::MAX {
req = if stop == u64::MAX {
req.header(Range::Bytes(vec![ByteRangeSpec::AllFrom(start)]))
} else {
req.header(Range::Bytes(vec![ByteRangeSpec::FromTo(start, stop)]))
};
req.header(Range::Bytes(vec![ByteRangeSpec::AllFrom(start)]))
} else {
req.header(Range::Bytes(vec![ByteRangeSpec::FromTo(start, stop)]))
};
}
match req.send() {
Ok(response) => {
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
} else {
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)
} else {
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.stop = stop;
......@@ -114,13 +127,13 @@ impl HttpSrc {
println_err!("Failed to fetch {}: {}", url, response.status);
return false;
}
},
}
Err(err) => {
println_err!("Failed to fetch {}: {}", url, err.to_string());
return false;
}
}
},
}
}
}
}
......@@ -137,10 +150,9 @@ impl Source for HttpSrc {
let mut url = self.url.lock().unwrap();
*url = None;
return true;
},
}
Some(uri) => {
if uri.scheme() == "http" ||
uri.scheme() == "https" {
if uri.scheme() == "http" || uri.scheme() == "https" {
let mut url = self.url.lock().unwrap();
*url = Some(uri);
return true;
......@@ -178,7 +190,7 @@ impl Source for HttpSrc {
self.size = u64::MAX;
match self.response {
Some(ref mut response) => drop(response),
None => ()
None => (),
}
self.response = None;
......@@ -208,15 +220,14 @@ impl Source for HttpSrc {
}
self.position += size as u64;
return Ok(size)
},
return Ok(size);
}
Err(err) => {
println_err!("Failed to read at {}: {}", offset, err.to_string());
return Err(GstFlowReturn::Error);
},
}
}
},
}
}
}
}
......@@ -43,7 +43,7 @@ pub extern "C" fn sink_drop(ptr: *mut Box<Sink>) {
}
#[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 };
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 };
match sink.get_uri() {
Some(uri) =>
CString::new(uri.into_string().into_bytes()).unwrap().into_raw(),
None =>
ptr::null_mut()
Some(uri) => CString::new(uri.into_string().into_bytes()).unwrap().into_raw(),
None => ptr::null_mut(),
}
}
#[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 data = unsafe { slice::from_raw_parts(data_ptr, data_len) };
......
......@@ -47,7 +47,7 @@ pub extern "C" fn source_drop(ptr: *mut Box<Source>) {
}
#[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 };
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 };
match source.get_uri() {
Some(uri) =>
CString::new(uri.into_string().into_bytes()).unwrap().into_raw(),
None =>
ptr::null_mut()
Some(uri) => CString::new(uri.into_string().into_bytes()).unwrap().into_raw(),
None => ptr::null_mut(),
}
}
#[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 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) => {
*data_len = actual_len;
GstFlowReturn::Ok
},
}
Err(ret) => ret,
}
}
#[no_mangle]
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();
}
......@@ -115,7 +117,7 @@ pub extern "C" fn source_stop(ptr: *mut Box<Source>) -> GBoolean {
#[no_mangle]
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())
}
......@@ -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))
}
......@@ -23,7 +23,7 @@ use std::ffi::CString;
macro_rules! println_err(
($($arg:tt)*) => { {
let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
// Ignore when writing fails
// Ignore when writing fails
match r {
Ok(_) => (),
Err(_) => ()
......@@ -58,6 +58,7 @@ impl GBoolean {
#[no_mangle]
pub extern "C" fn cstring_drop(ptr: *mut c_char) {
unsafe { CString::from_raw(ptr); }
unsafe {
CString::from_raw(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