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

Run everything through rustfmt-nightly

parent 3c27685e
......@@ -37,11 +37,10 @@ impl FileSink {
pub fn new(element: Element) -> FileSink {
FileSink {
streaming_state: StreamingState::Stopped,
logger: Logger::root(GstDebugDrain::new(Some(&element),
"rsfilesink",
0,
"Rust file sink"),
o!()),
logger: Logger::root(
GstDebugDrain::new(Some(&element), "rsfilesink", 0, "Rust file sink"),
o!(),
),
}
}
......@@ -51,12 +50,12 @@ impl FileSink {
}
fn validate_uri(uri: &Url) -> Result<(), UriError> {
let _ = try!(uri.to_file_path()
.or_else(|_| {
Err(UriError::new(UriErrorKind::UnsupportedProtocol,
Some(format!("Unsupported file URI '{}'",
uri.as_str()))))
}));
let _ = try!(uri.to_file_path().or_else(|_| {
Err(UriError::new(
UriErrorKind::UnsupportedProtocol,
Some(format!("Unsupported file URI '{}'", uri.as_str())),
))
}));
Ok(())
}
......@@ -70,23 +69,29 @@ impl Sink for FileSink {
return Err(error_msg!(SinkError::Failure, ["Sink already started"]));
}
let location =
try!(uri.to_file_path()
.or_else(|_| {
error!(self.logger, "Unsupported file URI '{}'", uri.as_str());
Err(error_msg!(SinkError::Failure,
["Unsupported file URI '{}'", uri.as_str()]))
}));
let location = try!(uri.to_file_path().or_else(|_| {
error!(self.logger, "Unsupported file URI '{}'", uri.as_str());
Err(error_msg!(
SinkError::Failure,
["Unsupported file URI '{}'", uri.as_str()]
))
}));
let file = try!(File::create(location.as_path()).or_else(|err| {
error!(self.logger,
"Could not open file for writing: {}",
err.to_string());
Err(error_msg!(SinkError::OpenFailed,
["Could not open file for writing '{}': {}",
location.to_str().unwrap_or("Non-UTF8 path"),
err.to_string()]))
error!(
self.logger,
"Could not open file for writing: {}",
err.to_string()
);
Err(error_msg!(
SinkError::OpenFailed,
[
"Could not open file for writing '{}': {}",
location.to_str().unwrap_or("Non-UTF8 path"),
err.to_string()
]
))
}));
debug!(self.logger, "Opened file {:?}", file);
......@@ -117,25 +122,29 @@ impl Sink for FileSink {
ref mut position,
} => (file, position),
StreamingState::Stopped => {
return Err(FlowError::Error(error_msg!(SinkError::Failure, ["Not started yet"])));
return Err(FlowError::Error(
error_msg!(SinkError::Failure, ["Not started yet"]),
));
}
};
let map = match buffer.map_read() {
None => {
return Err(FlowError::Error(error_msg!(SinkError::Failure,
["Failed to map buffer"])));
return Err(FlowError::Error(
error_msg!(SinkError::Failure, ["Failed to map buffer"]),
));
}
Some(map) => map,
};
let data = map.as_slice();
try!(file.write_all(data)
.or_else(|err| {
error!(logger, "Failed to write: {}", err);
Err(FlowError::Error(error_msg!(SinkError::WriteFailed,
["Failed to write: {}", err])))
}));
try!(file.write_all(data).or_else(|err| {
error!(logger, "Failed to write: {}", err);
Err(FlowError::Error(error_msg!(
SinkError::WriteFailed,
["Failed to write: {}", err]
)))
}));
*position += data.len() as u64;
......
......@@ -35,11 +35,10 @@ impl FileSrc {
pub fn new(element: Element) -> FileSrc {
FileSrc {
streaming_state: StreamingState::Stopped,
logger: Logger::root(GstDebugDrain::new(Some(&element),
"rsfilesrc",
0,
"Rust file source"),
o!()),
logger: Logger::root(
GstDebugDrain::new(Some(&element), "rsfilesrc", 0, "Rust file source"),
o!(),
),
}
}
......@@ -49,12 +48,12 @@ impl FileSrc {
}
fn validate_uri(uri: &Url) -> Result<(), UriError> {
let _ = try!(uri.to_file_path()
.or_else(|_| {
Err(UriError::new(UriErrorKind::UnsupportedProtocol,
Some(format!("Unsupported file URI '{}'",
uri.as_str()))))
}));
let _ = try!(uri.to_file_path().or_else(|_| {
Err(UriError::new(
UriErrorKind::UnsupportedProtocol,
Some(format!("Unsupported file URI '{}'", uri.as_str())),
))
}));
Ok(())
}
......@@ -80,22 +79,28 @@ impl Source for FileSrc {
return Err(error_msg!(SourceError::Failure, ["Source already started"]));
}
let location =
try!(uri.to_file_path()
.or_else(|_| {
error!(self.logger, "Unsupported file URI '{}'", uri.as_str());
Err(error_msg!(SourceError::Failure,
["Unsupported file URI '{}'", uri.as_str()]))
}));
let location = try!(uri.to_file_path().or_else(|_| {
error!(self.logger, "Unsupported file URI '{}'", uri.as_str());
Err(error_msg!(
SourceError::Failure,
["Unsupported file URI '{}'", uri.as_str()]
))
}));
let file = try!(File::open(location.as_path()).or_else(|err| {
error!(self.logger,
"Could not open file for reading: {}",
err.to_string());
Err(error_msg!(SourceError::OpenFailed,
["Could not open file for reading '{}': {}",
location.to_str().unwrap_or("Non-UTF8 path"),
err.to_string()]))
error!(
self.logger,
"Could not open file for reading: {}",
err.to_string()
);
Err(error_msg!(
SourceError::OpenFailed,
[
"Could not open file for reading '{}': {}",
location.to_str().unwrap_or("Non-UTF8 path"),
err.to_string()
]
))
}));
debug!(self.logger, "Opened file {:?}", file);
......@@ -124,41 +129,42 @@ impl Source for FileSrc {
ref mut position,
} => (file, position),
StreamingState::Stopped => {
return Err(FlowError::Error(error_msg!(SourceError::Failure, ["Not started yet"])));
return Err(FlowError::Error(
error_msg!(SourceError::Failure, ["Not started yet"]),
));
}
};
if *position != offset {
try!(file.seek(SeekFrom::Start(offset))
.or_else(|err| {
error!(logger, "Failed to seek to {}: {:?}", offset, err);
Err(FlowError::Error(error_msg!(SourceError::SeekFailed,
["Failed to seek to {}: {}",
offset,
err.to_string()])))
}));
try!(file.seek(SeekFrom::Start(offset)).or_else(|err| {
error!(logger, "Failed to seek to {}: {:?}", offset, err);
Err(FlowError::Error(error_msg!(
SourceError::SeekFailed,
["Failed to seek to {}: {}", offset, err.to_string()]
)))
}));
*position = offset;
}
let size = {
let mut map = match buffer.map_readwrite() {
None => {
return Err(FlowError::Error(error_msg!(SourceError::Failure,
["Failed to map buffer"])));
return Err(FlowError::Error(
error_msg!(SourceError::Failure, ["Failed to map buffer"]),
));
}
Some(map) => map,
};
let data = map.as_mut_slice();
try!(file.read(data)
.or_else(|err| {
error!(logger, "Failed to read: {:?}", err);
Err(FlowError::Error(error_msg!(SourceError::ReadFailed,
["Failed to read at {}: {}",
offset,
err.to_string()])))
}))
try!(file.read(data).or_else(|err| {
error!(logger, "Failed to read: {:?}", err);
Err(FlowError::Error(error_msg!(
SourceError::ReadFailed,
["Failed to read at {}: {}", offset, err.to_string()]
)))
}))
};
*position += size as u64;
......
......@@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type="cdylib"]
#![crate_type = "cdylib"]
extern crate url;
#[macro_use]
......@@ -25,40 +25,46 @@ use filesrc::FileSrc;
use filesink::FileSink;
fn plugin_init(plugin: &Plugin) -> bool {
source_register(plugin,
SourceInfo {
name: "rsfilesrc".into(),
long_name: "File Source".into(),
description: "Reads local files".into(),
classification: "Source/File".into(),
author: "Sebastian Dröge <sebastian@centricular.com>".into(),
rank: 256 + 100,
create_instance: FileSrc::new_boxed,
protocols: vec!["file".into()],
push_only: false,
});
source_register(
plugin,
SourceInfo {
name: "rsfilesrc".into(),
long_name: "File Source".into(),
description: "Reads local files".into(),
classification: "Source/File".into(),
author: "Sebastian Dröge <sebastian@centricular.com>".into(),
rank: 256 + 100,
create_instance: FileSrc::new_boxed,
protocols: vec!["file".into()],
push_only: false,
},
);
sink_register(plugin,
SinkInfo {
name: "rsfilesink".into(),
long_name: "File Sink".into(),
description: "Writes to local files".into(),
classification: "Sink/File".into(),
author: "Luis de Bethencourt <luisbg@osg.samsung.com>".into(),
rank: 256 + 100,
create_instance: FileSink::new_boxed,
protocols: vec!["file".into()],
});
sink_register(
plugin,
SinkInfo {
name: "rsfilesink".into(),
long_name: "File Sink".into(),
description: "Writes to local files".into(),
classification: "Sink/File".into(),
author: "Luis de Bethencourt <luisbg@osg.samsung.com>".into(),
rank: 256 + 100,
create_instance: FileSink::new_boxed,
protocols: vec!["file".into()],
},
);
true
}
plugin_define!(b"rsfile\0",
b"Rust File Plugin\0",
plugin_init,
b"1.0\0",
b"MIT/X11\0",
b"rsfile\0",
b"rsfile\0",
b"https://github.com/sdroege/rsplugin\0",
b"2016-12-08\0");
plugin_define!(
b"rsfile\0",
b"Rust File Plugin\0",
plugin_init,
b"1.0\0",
b"MIT/X11\0",
b"rsfile\0",
b"rsfile\0",
b"https://github.com/sdroege/rsplugin\0",
b"2016-12-08\0"
);
This diff is collapsed.
......@@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type="cdylib"]
#![crate_type = "cdylib"]
extern crate url;
#[macro_use]
......@@ -26,28 +26,32 @@ mod flvdemux;
use flvdemux::FlvDemux;
fn plugin_init(plugin: &Plugin) -> bool {
demuxer_register(plugin,
&DemuxerInfo {
name: "rsflvdemux",
long_name: "FLV Demuxer",
description: "Demuxes FLV Streams",
classification: "Codec/Demuxer",
author: "Sebastian Dröge <sebastian@centricular.com>",
rank: 256 + 100,
create_instance: FlvDemux::new_boxed,
input_caps: &Caps::new_simple("video/x-flv", &[]),
output_caps: &Caps::new_any(),
});
demuxer_register(
plugin,
&DemuxerInfo {
name: "rsflvdemux",
long_name: "FLV Demuxer",
description: "Demuxes FLV Streams",
classification: "Codec/Demuxer",
author: "Sebastian Dröge <sebastian@centricular.com>",
rank: 256 + 100,
create_instance: FlvDemux::new_boxed,
input_caps: &Caps::new_simple("video/x-flv", &[]),
output_caps: &Caps::new_any(),
},
);
true
}
plugin_define!(b"rsflv\0",
b"Rust FLV Plugin\0",
plugin_init,
b"1.0\0",
b"MIT/X11\0",
b"rsflv\0",
b"rsflv\0",
b"https://github.com/sdroege/rsplugin\0",
b"2016-12-08\0");
plugin_define!(
b"rsflv\0",
b"Rust FLV Plugin\0",
plugin_init,
b"1.0\0",
b"MIT/X11\0",
b"rsflv\0",
b"rsflv\0",
b"https://github.com/sdroege/rsplugin\0",
b"2016-12-08\0"
);
......@@ -10,8 +10,8 @@ use std::u64;
use std::io::Read;
use url::Url;
use reqwest::{Client, Response};
use reqwest::header::{ContentLength, ContentRange, ContentRangeSpec, Range, ByteRangeSpec,
AcceptRanges, RangeUnit};
use reqwest::header::{AcceptRanges, ByteRangeSpec, ContentLength, ContentRange, ContentRangeSpec,
Range, RangeUnit};
use gst_plugin::error::*;
use gst_plugin::source::*;
......@@ -46,11 +46,10 @@ impl HttpSrc {
pub fn new(element: Element) -> HttpSrc {
HttpSrc {
streaming_state: StreamingState::Stopped,
logger: Logger::root(GstDebugDrain::new(Some(&element),
"rshttpsink",
0,
"Rust http sink"),
o!()),
logger: Logger::root(
GstDebugDrain::new(Some(&element), "rshttpsink", 0, "Rust http sink"),
o!(),
),
client: Client::new().unwrap(),
}
}
......@@ -59,11 +58,12 @@ impl HttpSrc {
Box::new(HttpSrc::new(element))
}
fn do_request(&self,
uri: Url,
start: u64,
stop: Option<u64>)
-> Result<StreamingState, ErrorMessage> {
fn do_request(
&self,
uri: Url,
start: u64,
stop: Option<u64>,
) -> Result<StreamingState, ErrorMessage> {
let mut req = self.client.get(uri.clone()).unwrap();
match (start != 0, stop) {
......@@ -78,18 +78,20 @@ impl HttpSrc {
debug!(self.logger, "Doing new request {:?}", req);
let response =
try!(req.send()
.or_else(|err| {
error!(self.logger, "Request failed: {:?}", err);
Err(error_msg!(SourceError::ReadFailed,
["Failed to fetch {}: {}", uri, err.to_string()]))
}));
let response = try!(req.send().or_else(|err| {
error!(self.logger, "Request failed: {:?}", err);
Err(error_msg!(
SourceError::ReadFailed,
["Failed to fetch {}: {}", uri, err.to_string()]
))
}));
if !response.status().is_success() {
error!(self.logger, "Request status failed: {:?}", response);
return Err(error_msg!(SourceError::ReadFailed,
["Failed to fetch {}: {}", uri, response.status()]));
return Err(error_msg!(
SourceError::ReadFailed,
["Failed to fetch {}: {}", uri, response.status()]
));
}
let size = response
......@@ -97,8 +99,7 @@ impl HttpSrc {
.get()
.map(|&ContentLength(cl)| cl + start);
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
......@@ -106,37 +107,45 @@ impl HttpSrc {
let seekable = size.is_some() && accept_byte_ranges;
let position = if let Some(&ContentRange(ContentRangeSpec::Bytes {
range: Some((range_start, _)), ..
})) = response.headers().get() {
let position = if let Some(
&ContentRange(ContentRangeSpec::Bytes {
range: Some((range_start, _)),
..
}),
) = response.headers().get()
{
range_start
} else {
start
};
if position != start {
return Err(error_msg!(SourceError::SeekFailed,
["Failed to seek to {}: Got {}", start, position]));
return Err(error_msg!(
SourceError::SeekFailed,
["Failed to seek to {}: Got {}", start, position]
));
}
debug!(self.logger, "Request successful: {:?}", response);
Ok(StreamingState::Started {
uri: uri,
response: response,
seekable: seekable,
position: 0,
size: size,
start: start,
stop: stop,
})
uri: uri,
response: response,
seekable: seekable,
position: 0,
size: size,
start: start,
stop: stop,
})
}
}
fn validate_uri(uri: &Url) -> Result<(), UriError> {
if uri.scheme() != "http" && uri.scheme() != "https" {
return Err(UriError::new(UriErrorKind::UnsupportedProtocol,
Some(format!("Unsupported URI '{}'", uri.as_str()))));
return Err(UriError::new(
UriErrorKind::UnsupportedProtocol,
Some(format!("Unsupported URI '{}'", uri.as_str())),
));
}
Ok(())
......@@ -207,37 +216,38 @@ impl Source for HttpSrc {
..
} => (response, position),
StreamingState::Stopped => {
return Err(FlowError::Error(error_msg!(SourceError::Failure, ["Not started yet"])));
return Err(FlowError::Error(
error_msg!(SourceError::Failure, ["Not started yet"]),
));
}
};
if *position != offset {
return Err(FlowError::Error(error_msg!(SourceError::SeekFailed,
["Got unexpected offset {}, expected {}",
offset,
position])));
return Err(FlowError::Error(error_msg!(
SourceError::SeekFailed,
["Got unexpected offset {}, expected {}", offset, position]
)));
}
let size = {
let mut map = match buffer.map_readwrite() {
None => {
return Err(FlowError::Error(error_msg!(SourceError::Failure,
["Failed to map buffer"])));
return Err(FlowError::Error(
error_msg!(SourceError::Failure, ["Failed to map buffer"]),
));
}
Some(map) => map,
};
let data = map.as_mut_slice();
try!(response
.read(data)
.or_else(|err| {
error!(logger, "Failed to read: {:?}", err);
Err(FlowError::Error(error_msg!(SourceError::ReadFailed,
["Failed to read at {}: {}",
offset,
err.to_string()])))
}))
try!(response.read(data).or_else(|err| {
error!(logger, "Failed to read: {:?}", err);
Err(FlowError::Error(error_msg!(