Update URIHander::set_uri based on gstreamer-rs API changes

Went from Option<String> to &str.
This commit is contained in:
Arun Raghavan 2019-05-25 19:23:55 +02:00
parent 857800b7b6
commit e70937a8d7
4 changed files with 28 additions and 54 deletions

View file

@ -303,19 +303,18 @@ impl URIHandlerImpl for FileSink {
}) })
} }
fn set_uri(&self, element: &gst::URIHandler, uri: Option<String>) -> Result<(), glib::Error> { fn set_uri(&self, element: &gst::URIHandler, uri: &str) -> Result<(), glib::Error> {
let element = element.dynamic_cast_ref::<gst_base::BaseSink>().unwrap(); let element = element.dynamic_cast_ref::<gst_base::BaseSink>().unwrap();
// Special case for "file://" as this is used by some applications to test // Special case for "file://" as this is used by some applications to test
// with `gst_element_make_from_uri` if there's an element that supports the URI protocol // with `gst_element_make_from_uri` if there's an element that supports the URI protocol
let uri = uri.filter(|uri| uri != "file://");
let file_location = match uri { if uri != "file://" {
Some(uri) => Some(FileLocation::try_from_uri_str(&uri)?), let file_location = FileLocation::try_from_uri_str(uri)?;
None => None, self.set_location(&element, Some(file_location))
}; } else {
Ok(())
self.set_location(&element, file_location) }
} }
fn get_uri_type() -> gst::URIType { fn get_uri_type() -> gst::URIType {

View file

@ -357,19 +357,18 @@ impl URIHandlerImpl for FileSrc {
}) })
} }
fn set_uri(&self, element: &gst::URIHandler, uri: Option<String>) -> Result<(), glib::Error> { fn set_uri(&self, element: &gst::URIHandler, uri: &str) -> Result<(), glib::Error> {
let element = element.dynamic_cast_ref::<gst_base::BaseSrc>().unwrap(); let element = element.dynamic_cast_ref::<gst_base::BaseSrc>().unwrap();
// Special case for "file://" as this is used by some applications to test // Special case for "file://" as this is used by some applications to test
// with `gst_element_make_from_uri` if there's an element that supports the URI protocol // with `gst_element_make_from_uri` if there's an element that supports the URI protocol
let uri = uri.filter(|uri| uri != "file://");
let file_location = match uri { if uri != "file://" {
Some(uri) => Some(FileLocation::try_from_uri_str(&uri)?), let file_location = FileLocation::try_from_uri_str(uri)?;
None => None, self.set_location(&element, Some(file_location))
}; } else {
Ok(())
self.set_location(&element, file_location) }
} }
fn get_uri_type() -> gst::URIType { fn get_uri_type() -> gst::URIType {

View file

@ -80,11 +80,7 @@ pub struct HttpSrc {
} }
impl HttpSrc { impl HttpSrc {
fn set_location( fn set_location(&self, _element: &gst_base::BaseSrc, uri: &str) -> Result<(), glib::Error> {
&self,
_element: &gst_base::BaseSrc,
uri: Option<String>,
) -> Result<(), glib::Error> {
let state = self.state.lock().unwrap(); let state = self.state.lock().unwrap();
if let State::Started { .. } = *state { if let State::Started { .. } = *state {
return Err(glib::Error::new( return Err(glib::Error::new(
@ -95,15 +91,7 @@ impl HttpSrc {
let mut settings = self.settings.lock().unwrap(); let mut settings = self.settings.lock().unwrap();
let uri = match uri { let uri = Url::parse(uri).map_err(|err| {
Some(uri) => uri,
None => {
settings.location = None;
return Ok(());
}
};
let uri = Url::parse(uri.as_str()).map_err(|err| {
glib::Error::new( glib::Error::new(
gst::URIError::BadUri, gst::URIError::BadUri,
format!("Failed to parse URI '{}': {:?}", uri, err,).as_str(), format!("Failed to parse URI '{}': {:?}", uri, err,).as_str(),
@ -216,7 +204,7 @@ impl ObjectImpl for HttpSrc {
subclass::Property("location", ..) => { subclass::Property("location", ..) => {
let element = obj.downcast_ref::<gst_base::BaseSrc>().unwrap(); let element = obj.downcast_ref::<gst_base::BaseSrc>().unwrap();
let location = value.get::<String>(); let location = value.get::<&str>().unwrap();
let res = self.set_location(element, location); let res = self.set_location(element, location);
if let Err(err) = res { if let Err(err) = res {
@ -408,7 +396,7 @@ impl URIHandlerImpl for HttpSrc {
settings.location.as_ref().map(Url::to_string) settings.location.as_ref().map(Url::to_string)
} }
fn set_uri(&self, element: &gst::URIHandler, uri: Option<String>) -> Result<(), glib::Error> { fn set_uri(&self, element: &gst::URIHandler, uri: &str) -> Result<(), glib::Error> {
let element = element.dynamic_cast_ref::<gst_base::BaseSrc>().unwrap(); let element = element.dynamic_cast_ref::<gst_base::BaseSrc>().unwrap();
self.set_location(&element, uri) self.set_location(&element, uri)

View file

@ -98,11 +98,7 @@ impl S3Src {
Ok(S3Client::new(url.region.clone())) Ok(S3Client::new(url.region.clone()))
} }
fn set_uri( fn set_uri(self: &S3Src, _: &gst_base::BaseSrc, url_str: &str) -> Result<(), glib::Error> {
self: &S3Src,
_: &gst_base::BaseSrc,
url_str: Option<String>,
) -> Result<(), glib::Error> {
let state = self.state.lock().unwrap(); let state = self.state.lock().unwrap();
if let StreamingState::Started { .. } = *state { if let StreamingState::Started { .. } = *state {
@ -114,21 +110,15 @@ impl S3Src {
let mut url = self.url.lock().unwrap(); let mut url = self.url.lock().unwrap();
match url_str { match parse_s3_url(&url_str) {
Some(s) => match parse_s3_url(&s) { Ok(s3url) => {
Ok(s3url) => { *url = Some(s3url);
*url = Some(s3url);
Ok(())
}
Err(_) => Err(gst::Error::new(
gst::URIError::BadUri,
"Could not parse URI",
)),
},
None => {
*url = None;
Ok(()) Ok(())
} }
Err(_) => Err(gst::Error::new(
gst::URIError::BadUri,
"Could not parse URI",
)),
} }
} }
@ -302,9 +292,7 @@ impl ObjectImpl for S3Src {
match *prop { match *prop {
subclass::Property("uri", ..) => { subclass::Property("uri", ..) => {
self.set_uri(basesrc, value.get()).unwrap_or_else(|err| { let _ = self.set_uri(basesrc, value.get().unwrap());
gst_error!(self.cat, obj: basesrc, "Could not set URI: {}", err);
});
} }
_ => unimplemented!(), _ => unimplemented!(),
} }
@ -345,7 +333,7 @@ impl URIHandlerImpl for S3Src {
self.url.lock().unwrap().as_ref().map(|s| s.to_string()) self.url.lock().unwrap().as_ref().map(|s| s.to_string())
} }
fn set_uri(&self, element: &gst::URIHandler, uri: Option<String>) -> Result<(), glib::Error> { fn set_uri(&self, element: &gst::URIHandler, uri: &str) -> Result<(), glib::Error> {
let basesrc = element.dynamic_cast_ref::<gst_base::BaseSrc>().unwrap(); let basesrc = element.dynamic_cast_ref::<gst_base::BaseSrc>().unwrap();
self.set_uri(basesrc, uri) self.set_uri(basesrc, uri)
} }