mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-06-26 01:50:35 +00:00
Don't lock the URI mutex all the time while {Sink,Source}::{start,stop} is called but only when needed
This commit is contained in:
parent
fa855ec2b2
commit
245d576159
|
@ -60,7 +60,7 @@ impl Sink for FileSink {
|
||||||
Box::new(validate_uri)
|
Box::new(validate_uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start(&mut self, uri: &Url) -> Result<(), ErrorMessage> {
|
fn start(&mut self, uri: Url) -> Result<(), ErrorMessage> {
|
||||||
if let StreamingState::Started { .. } = self.streaming_state {
|
if let StreamingState::Started { .. } = self.streaming_state {
|
||||||
return Err(error_msg!(SinkError::Failure, ["Sink already started"]));
|
return Err(error_msg!(SinkError::Failure, ["Sink already started"]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ impl Source for FileSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start(&mut self, uri: &Url) -> Result<(), ErrorMessage> {
|
fn start(&mut self, uri: Url) -> Result<(), ErrorMessage> {
|
||||||
if let StreamingState::Started { .. } = self.streaming_state {
|
if let StreamingState::Started { .. } = self.streaming_state {
|
||||||
return Err(error_msg!(SourceError::Failure, ["Source already started"]));
|
return Err(error_msg!(SourceError::Failure, ["Source already started"]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,9 +153,9 @@ impl Source for HttpSrc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start(&mut self, uri: &Url) -> Result<(), ErrorMessage> {
|
fn start(&mut self, uri: Url) -> Result<(), ErrorMessage> {
|
||||||
self.streaming_state = StreamingState::Stopped;
|
self.streaming_state = StreamingState::Stopped;
|
||||||
self.streaming_state = try!(self.do_request(uri.clone(), 0, None));
|
self.streaming_state = try!(self.do_request(uri, 0, None));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub struct SinkWrapper {
|
||||||
pub trait Sink {
|
pub trait Sink {
|
||||||
fn uri_validator(&self) -> Box<UriValidator>;
|
fn uri_validator(&self) -> Box<UriValidator>;
|
||||||
|
|
||||||
fn start(&mut self, uri: &Url) -> Result<(), ErrorMessage>;
|
fn start(&mut self, uri: Url) -> Result<(), ErrorMessage>;
|
||||||
fn stop(&mut self) -> Result<(), ErrorMessage>;
|
fn stop(&mut self) -> Result<(), ErrorMessage>;
|
||||||
|
|
||||||
fn render(&mut self, data: &[u8]) -> Result<(), FlowError>;
|
fn render(&mut self, data: &[u8]) -> Result<(), FlowError>;
|
||||||
|
@ -147,10 +147,13 @@ pub unsafe extern "C" fn sink_get_uri(ptr: *const SinkWrapper) -> *mut c_char {
|
||||||
pub unsafe extern "C" fn sink_start(ptr: *mut SinkWrapper) -> GBoolean {
|
pub unsafe extern "C" fn sink_start(ptr: *mut SinkWrapper) -> GBoolean {
|
||||||
let wrap: &mut SinkWrapper = &mut *ptr;
|
let wrap: &mut SinkWrapper = &mut *ptr;
|
||||||
let sink = &mut wrap.sink.lock().unwrap();
|
let sink = &mut wrap.sink.lock().unwrap();
|
||||||
let uri_storage = &mut wrap.uri.lock().unwrap();
|
|
||||||
|
|
||||||
let (uri, started) = match **uri_storage {
|
let uri = match *wrap.uri.lock().unwrap() {
|
||||||
(Some(ref uri), ref mut started) => (uri, started),
|
(Some(ref uri), ref mut started) => {
|
||||||
|
*started = true;
|
||||||
|
|
||||||
|
uri.clone()
|
||||||
|
}
|
||||||
(None, _) => {
|
(None, _) => {
|
||||||
error_msg!(SinkError::OpenFailed, ["No URI given"]).post(wrap.sink_raw);
|
error_msg!(SinkError::OpenFailed, ["No URI given"]).post(wrap.sink_raw);
|
||||||
return GBoolean::False;
|
return GBoolean::False;
|
||||||
|
@ -158,12 +161,9 @@ pub unsafe extern "C" fn sink_start(ptr: *mut SinkWrapper) -> GBoolean {
|
||||||
};
|
};
|
||||||
|
|
||||||
match sink.start(uri) {
|
match sink.start(uri) {
|
||||||
Ok(..) => {
|
Ok(..) => GBoolean::True,
|
||||||
*started = true;
|
|
||||||
|
|
||||||
GBoolean::True
|
|
||||||
}
|
|
||||||
Err(ref msg) => {
|
Err(ref msg) => {
|
||||||
|
wrap.uri.lock().unwrap().1 = false;
|
||||||
msg.post(wrap.sink_raw);
|
msg.post(wrap.sink_raw);
|
||||||
GBoolean::False
|
GBoolean::False
|
||||||
}
|
}
|
||||||
|
@ -174,11 +174,10 @@ pub unsafe extern "C" fn sink_start(ptr: *mut SinkWrapper) -> GBoolean {
|
||||||
pub unsafe extern "C" fn sink_stop(ptr: *mut SinkWrapper) -> GBoolean {
|
pub unsafe extern "C" fn sink_stop(ptr: *mut SinkWrapper) -> GBoolean {
|
||||||
let wrap: &mut SinkWrapper = &mut *ptr;
|
let wrap: &mut SinkWrapper = &mut *ptr;
|
||||||
let sink = &mut wrap.sink.lock().unwrap();
|
let sink = &mut wrap.sink.lock().unwrap();
|
||||||
let uri_storage = &mut wrap.uri.lock().unwrap();
|
|
||||||
|
|
||||||
match sink.stop() {
|
match sink.stop() {
|
||||||
Ok(..) => {
|
Ok(..) => {
|
||||||
uri_storage.1 = false;
|
wrap.uri.lock().unwrap().1 = false;
|
||||||
GBoolean::True
|
GBoolean::True
|
||||||
}
|
}
|
||||||
Err(ref msg) => {
|
Err(ref msg) => {
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub trait Source {
|
||||||
fn is_seekable(&self) -> bool;
|
fn is_seekable(&self) -> bool;
|
||||||
fn get_size(&self) -> Option<u64>;
|
fn get_size(&self) -> Option<u64>;
|
||||||
|
|
||||||
fn start(&mut self, uri: &Url) -> Result<(), ErrorMessage>;
|
fn start(&mut self, uri: Url) -> Result<(), ErrorMessage>;
|
||||||
fn stop(&mut self) -> Result<(), ErrorMessage>;
|
fn stop(&mut self) -> Result<(), ErrorMessage>;
|
||||||
fn fill(&mut self, offset: u64, data: &mut [u8]) -> Result<usize, FlowError>;
|
fn fill(&mut self, offset: u64, data: &mut [u8]) -> Result<usize, FlowError>;
|
||||||
fn seek(&mut self, start: u64, stop: Option<u64>) -> Result<(), ErrorMessage>;
|
fn seek(&mut self, start: u64, stop: Option<u64>) -> Result<(), ErrorMessage>;
|
||||||
|
@ -169,10 +169,13 @@ pub unsafe extern "C" fn source_get_size(ptr: *const SourceWrapper) -> u64 {
|
||||||
pub unsafe extern "C" fn source_start(ptr: *mut SourceWrapper) -> GBoolean {
|
pub unsafe extern "C" fn source_start(ptr: *mut SourceWrapper) -> GBoolean {
|
||||||
let wrap: &mut SourceWrapper = &mut *ptr;
|
let wrap: &mut SourceWrapper = &mut *ptr;
|
||||||
let source = &mut wrap.source.lock().unwrap();
|
let source = &mut wrap.source.lock().unwrap();
|
||||||
let uri_storage = &mut wrap.uri.lock().unwrap();
|
|
||||||
|
|
||||||
let (uri, started) = match **uri_storage {
|
let uri = match *wrap.uri.lock().unwrap() {
|
||||||
(Some(ref uri), ref mut started) => (uri, started),
|
(Some(ref uri), ref mut started) => {
|
||||||
|
*started = true;
|
||||||
|
|
||||||
|
uri.clone()
|
||||||
|
}
|
||||||
(None, _) => {
|
(None, _) => {
|
||||||
error_msg!(SourceError::OpenFailed, ["No URI given"]).post(wrap.source_raw);
|
error_msg!(SourceError::OpenFailed, ["No URI given"]).post(wrap.source_raw);
|
||||||
return GBoolean::False;
|
return GBoolean::False;
|
||||||
|
@ -180,11 +183,9 @@ pub unsafe extern "C" fn source_start(ptr: *mut SourceWrapper) -> GBoolean {
|
||||||
};
|
};
|
||||||
|
|
||||||
match source.start(uri) {
|
match source.start(uri) {
|
||||||
Ok(..) => {
|
Ok(..) => GBoolean::True,
|
||||||
*started = true;
|
|
||||||
GBoolean::True
|
|
||||||
}
|
|
||||||
Err(ref msg) => {
|
Err(ref msg) => {
|
||||||
|
wrap.uri.lock().unwrap().1 = false;
|
||||||
msg.post(wrap.source_raw);
|
msg.post(wrap.source_raw);
|
||||||
GBoolean::False
|
GBoolean::False
|
||||||
}
|
}
|
||||||
|
@ -195,11 +196,10 @@ pub unsafe extern "C" fn source_start(ptr: *mut SourceWrapper) -> GBoolean {
|
||||||
pub unsafe extern "C" fn source_stop(ptr: *mut SourceWrapper) -> GBoolean {
|
pub unsafe extern "C" fn source_stop(ptr: *mut SourceWrapper) -> GBoolean {
|
||||||
let wrap: &mut SourceWrapper = &mut *ptr;
|
let wrap: &mut SourceWrapper = &mut *ptr;
|
||||||
let source = &mut wrap.source.lock().unwrap();
|
let source = &mut wrap.source.lock().unwrap();
|
||||||
let uri_storage = &mut wrap.uri.lock().unwrap();
|
|
||||||
|
|
||||||
match source.stop() {
|
match source.stop() {
|
||||||
Ok(..) => {
|
Ok(..) => {
|
||||||
uri_storage.1 = false;
|
wrap.uri.lock().unwrap().1 = false;
|
||||||
GBoolean::True
|
GBoolean::True
|
||||||
}
|
}
|
||||||
Err(ref msg) => {
|
Err(ref msg) => {
|
||||||
|
|
Loading…
Reference in a new issue