Commit 0e11ac87 authored by François Laignel's avatar François Laignel

Update for new `{Value, StructureRef}::get` signature

See https://github.com/gtk-rs/glib/pull/513
and gstreamer-rs!310
parent da2332d8
Pipeline #56015 passed with stages
in 23 minutes and 55 seconds
......@@ -205,20 +205,20 @@ impl ObjectImpl for AudioEcho {
subclass::Property("max-delay", ..) => {
let mut settings = self.settings.lock().unwrap();
if self.state.lock().unwrap().is_none() {
settings.max_delay = value.get().unwrap();
settings.max_delay = value.get_some().expect("type checked upstream");
}
}
subclass::Property("delay", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.delay = value.get().unwrap();
settings.delay = value.get_some().expect("type checked upstream");
}
subclass::Property("intensity", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.intensity = value.get().unwrap();
settings.intensity = value.get_some().expect("type checked upstream");
}
subclass::Property("feedback", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.feedback = value.get().unwrap();
settings.feedback = value.get_some().expect("type checked upstream");
}
_ => unimplemented!(),
}
......
......@@ -21,6 +21,7 @@ use glib::subclass;
use glib::subclass::prelude::*;
use gst;
use gst::prelude::*;
use gst::structure;
use gst::subclass::prelude::*;
use gst_video;
......@@ -139,11 +140,17 @@ impl MccEnc {
.sinkpad
.get_current_caps()
.ok_or(gst::FlowError::NotNegotiated)?;
let framerate = caps
let framerate = match caps
.get_structure(0)
.unwrap()
.get::<gst::Fraction>("framerate")
.ok_or(gst::FlowError::NotNegotiated)?;
.get_some::<gst::Fraction>("framerate")
{
Ok(framerate) => framerate,
Err(structure::GetError::FieldNotFound { .. }) => {
return Err(gst::FlowError::NotNegotiated);
}
err => panic!("MccEnc::generate_headers caps: {:?}", err),
};
if framerate == gst::Fraction::new(60000, 1001) {
buffer.extend_from_slice(PREAMBLE_V2);
......@@ -412,11 +419,13 @@ impl MccEnc {
EventView::Caps(ev) => {
let caps = ev.get_caps();
let s = caps.get_structure(0).unwrap();
let framerate = if let Some(framerate) = s.get::<gst::Fraction>("framerate") {
framerate
} else {
gst_error!(self.cat, obj: pad, "Caps without framerate");
return false;
let framerate = match s.get_some::<gst::Fraction>("framerate") {
Ok(framerate) => framerate,
Err(structure::GetError::FieldNotFound { .. }) => {
gst_error!(self.cat, obj: pad, "Caps without framerate");
return false;
}
err => panic!("MccEnc::sink_event caps: {:?}", err),
};
let mut state = self.state.lock().unwrap();
......@@ -573,11 +582,11 @@ impl ObjectImpl for MccEnc {
match *prop {
subclass::Property("uuid", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.uuid = value.get();
settings.uuid = value.get().expect("type checked upstream");
}
subclass::Property("creation-date", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.creation_date = value.get();
settings.creation_date = value.get().expect("type checked upstream");
}
_ => unimplemented!(),
}
......
......@@ -22,6 +22,7 @@ use glib::subclass;
use glib::subclass::prelude::*;
use gst;
use gst::prelude::*;
use gst::structure;
use gst::subclass::prelude::*;
use gst_video::{self, ValidVideoTimeCode};
......@@ -288,10 +289,13 @@ impl SccEnc {
EventView::Caps(ev) => {
let caps = ev.get_caps();
let s = caps.get_structure(0).unwrap();
let framerate = s.get::<gst::Fraction>("framerate");
if framerate.is_none() {
gst_error!(CAT, obj: pad, "Caps without framerate");
return false;
let framerate = match s.get_some::<gst::Fraction>("framerate") {
Ok(framerate) => Some(framerate),
Err(structure::GetError::FieldNotFound { .. }) => {
gst_error!(CAT, obj: pad, "Caps without framerate");
return false;
}
err => panic!("SccEnc::sink_event caps: {:?}", err),
};
let mut state = self.state.lock().unwrap();
......
......@@ -166,9 +166,10 @@ impl ObjectImpl for FileSink {
let element = obj.downcast_ref::<gst_base::BaseSink>().unwrap();
let res = match value.get::<String>() {
Some(location) => FileLocation::try_from_path_str(location)
Ok(Some(location)) => FileLocation::try_from_path_str(location)
.and_then(|file_location| self.set_location(&element, Some(file_location))),
None => self.set_location(&element, None),
Ok(None) => self.set_location(&element, None),
Err(_) => unreachable!("type checked upstream"),
};
if let Err(err) = res {
......
......@@ -180,9 +180,10 @@ impl ObjectImpl for FileSrc {
let element = obj.downcast_ref::<gst_base::BaseSrc>().unwrap();
let res = match value.get::<String>() {
Some(location) => FileLocation::try_from_path_str(location)
Ok(Some(location)) => FileLocation::try_from_path_str(location)
.and_then(|file_location| self.set_location(&element, Some(file_location))),
None => self.set_location(&element, None),
Ok(None) => self.set_location(&element, None),
Err(_) => unreachable!("type checked upstream"),
};
if let Err(err) = res {
......
......@@ -345,39 +345,42 @@ impl ObjectImpl for Rav1Enc {
match *prop {
subclass::Property("speed-preset", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.speed_preset = value.get().unwrap();
settings.speed_preset = value.get_some().expect("type checked upstream");
}
subclass::Property("low-latency", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.low_latency = value.get().unwrap();
settings.low_latency = value.get_some().expect("type checked upstream");
}
subclass::Property("min-key-frame-interval", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.min_key_frame_interval = value.get().unwrap();
settings.min_key_frame_interval = value.get_some().expect("type checked upstream");
}
subclass::Property("max-key-frame-interval", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.max_key_frame_interval = value.get().unwrap();
settings.max_key_frame_interval = value.get_some().expect("type checked upstream");
}
subclass::Property("bitrate", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.bitrate = value.get().unwrap();
settings.bitrate = value.get_some().expect("type checked upstream");
}
subclass::Property("quantizer", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.quantizer = value.get::<u32>().unwrap() as usize;
settings.quantizer =
value.get_some::<u32>().expect("type checked upstream") as usize;
}
subclass::Property("tile-cols-log2", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.tile_cols_log2 = value.get::<u32>().unwrap() as usize;
settings.tile_cols_log2 =
value.get_some::<u32>().expect("type checked upstream") as usize;
}
subclass::Property("tile-rows-log2", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.tile_rows_log2 = value.get::<u32>().unwrap() as usize;
settings.tile_rows_log2 =
value.get_some::<u32>().expect("type checked upstream") as usize;
}
subclass::Property("threads", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.threads = value.get::<u32>().unwrap() as usize;
settings.threads = value.get_some::<u32>().expect("type checked upstream") as usize;
}
_ => unimplemented!(),
}
......
......@@ -137,7 +137,11 @@ pub struct ReqwestHttpSrc {
}
impl ReqwestHttpSrc {
fn set_location(&self, _element: &gst_base::BaseSrc, uri: &str) -> Result<(), glib::Error> {
fn set_location(
&self,
_element: &gst_base::BaseSrc,
uri: Option<&str>,
) -> Result<(), glib::Error> {
let state = self.state.lock().unwrap();
if let State::Started { .. } = *state {
return Err(glib::Error::new(
......@@ -148,6 +152,12 @@ impl ReqwestHttpSrc {
let mut settings = self.settings.lock().unwrap();
if uri.is_none() {
settings.location = DEFAULT_LOCATION;
return Ok(());
}
let uri = uri.unwrap();
let uri = Url::parse(uri).map_err(|err| {
glib::Error::new(
gst::URIError::BadUri,
......@@ -336,10 +346,8 @@ impl ObjectImpl for ReqwestHttpSrc {
subclass::Property("location", ..) => {
let element = obj.downcast_ref::<gst_base::BaseSrc>().unwrap();
let location = value.get::<&str>().unwrap();
let res = self.set_location(element, location);
if let Err(err) = res {
let location = value.get::<&str>().expect("type checked upstream");
if let Err(err) = self.set_location(element, location) {
gst_error!(
self.cat,
obj: element,
......@@ -350,22 +358,25 @@ impl ObjectImpl for ReqwestHttpSrc {
}
subclass::Property("user-agent", ..) => {
let mut settings = self.settings.lock().unwrap();
let user_agent = value.get().unwrap();
let user_agent = value
.get()
.expect("type checked upstream")
.unwrap_or_else(|| DEFAULT_USER_AGENT.into());
settings.user_agent = user_agent;
}
subclass::Property("is-live", ..) => {
let element = obj.downcast_ref::<gst_base::BaseSrc>().unwrap();
let is_live = value.get().unwrap();
let is_live = value.get_some().expect("type checked upstream");
element.set_live(is_live);
}
subclass::Property("user-id", ..) => {
let mut settings = self.settings.lock().unwrap();
let user_id = value.get();
let user_id = value.get().expect("type checked upstream");
settings.user_id = user_id;
}
subclass::Property("user-pw", ..) => {
let mut settings = self.settings.lock().unwrap();
let user_pw = value.get();
let user_pw = value.get().expect("type checked upstream");
settings.user_pw = user_pw;
}
_ => unimplemented!(),
......@@ -613,7 +624,7 @@ impl URIHandlerImpl for ReqwestHttpSrc {
fn set_uri(&self, element: &gst::URIHandler, uri: &str) -> Result<(), glib::Error> {
let element = element.dynamic_cast_ref::<gst_base::BaseSrc>().unwrap();
self.set_location(&element, uri)
self.set_location(&element, Some(uri))
}
fn get_uri_type() -> gst::URIType {
......
......@@ -432,13 +432,19 @@ impl ObjectImpl for S3Sink {
match *prop {
subclass::Property("bucket", ..) => {
settings.bucket = value.get::<String>();
settings.bucket = value.get::<String>().expect("type checked upstream");
}
subclass::Property("key", ..) => {
settings.key = value.get::<String>();
settings.key = value.get::<String>().expect("type checked upstream");
}
subclass::Property("region", ..) => {
let region = Region::from_str(&value.get::<String>().unwrap()).unwrap();
let region = Region::from_str(
&value
.get::<String>()
.expect("type checked upstream")
.expect("set_property(\"region\"): no value provided"),
)
.unwrap();
if settings.region != region {
let mut client = self.client.lock().unwrap();
std::mem::replace(&mut *client, S3Client::new(region.clone()));
......@@ -446,7 +452,7 @@ impl ObjectImpl for S3Sink {
}
}
subclass::Property("part-size", ..) => {
settings.buffer_size = value.get::<u64>().unwrap();
settings.buffer_size = value.get_some::<u64>().expect("type checked upstream");
}
_ => unimplemented!(),
}
......
......@@ -69,7 +69,11 @@ impl S3Src {
Ok(S3Client::new(url.region.clone()))
}
fn set_uri(self: &S3Src, _: &gst_base::BaseSrc, url_str: &str) -> Result<(), glib::Error> {
fn set_uri(
self: &S3Src,
_: &gst_base::BaseSrc,
url_str: Option<&str>,
) -> Result<(), glib::Error> {
let state = self.state.lock().unwrap();
if let StreamingState::Started { .. } = *state {
......@@ -81,7 +85,13 @@ impl S3Src {
let mut url = self.url.lock().unwrap();
match parse_s3_url(&url_str) {
if url_str.is_none() {
*url = None;
return Ok(());
}
let url_str = url_str.unwrap();
match parse_s3_url(url_str) {
Ok(s3url) => {
*url = Some(s3url);
Ok(())
......@@ -271,7 +281,7 @@ impl ObjectImpl for S3Src {
match *prop {
subclass::Property("uri", ..) => {
let _ = self.set_uri(basesrc, value.get().unwrap());
let _ = self.set_uri(basesrc, value.get().expect("type checked upstream"));
}
_ => unimplemented!(),
}
......@@ -314,7 +324,7 @@ impl URIHandlerImpl for S3Src {
fn set_uri(&self, element: &gst::URIHandler, uri: &str) -> Result<(), glib::Error> {
let basesrc = element.dynamic_cast_ref::<gst_base::BaseSrc>().unwrap();
self.set_uri(basesrc, uri)
self.set_uri(basesrc, Some(uri))
}
fn get_uri_type() -> gst::URIType {
......
......@@ -635,12 +635,12 @@ impl ObjectImpl for Decrypter {
match *prop {
subclass::Property("sender-key", ..) => {
let mut props = self.props.lock().unwrap();
props.sender_key = value.get();
props.sender_key = value.get().expect("type checked upstream");
}
subclass::Property("receiver-key", ..) => {
let mut props = self.props.lock().unwrap();
props.receiver_key = value.get();
props.receiver_key = value.get().expect("type checked upstream");
}
_ => unimplemented!(),
......
......@@ -488,17 +488,17 @@ impl ObjectImpl for Encrypter {
match *prop {
subclass::Property("sender-key", ..) => {
let mut props = self.props.lock().unwrap();
props.sender_key = value.get();
props.sender_key = value.get().expect("type checked upstream");
}
subclass::Property("receiver-key", ..) => {
let mut props = self.props.lock().unwrap();
props.receiver_key = value.get();
props.receiver_key = value.get().expect("type checked upstream");
}
subclass::Property("block-size", ..) => {
let mut props = self.props.lock().unwrap();
props.block_size = value.get().unwrap();
props.block_size = value.get_some().expect("type checked upstream");
}
_ => unimplemented!(),
......
......@@ -519,8 +519,14 @@ impl ObjectSubclass for AppSrc {
&[gst::Buffer::static_type()],
bool::static_type(),
|_, args| {
let element = args[0].get::<gst::Element>().unwrap();
let buffer = args[1].get::<gst::Buffer>().unwrap();
let element = args[0]
.get::<gst::Element>()
.expect("signal arg")
.expect("missing signal arg");
let buffer = args[1]
.get::<gst::Buffer>()
.expect("signal arg")
.expect("missing signal arg");
let appsrc = Self::from_instance(&element);
Some(appsrc.push_buffer(&element, buffer).to_value())
......@@ -533,7 +539,10 @@ impl ObjectSubclass for AppSrc {
&[],
bool::static_type(),
|_, args| {
let element = args[0].get::<gst::Element>().unwrap();
let element = args[0]
.get::<gst::Element>()
.expect("signal arg")
.expect("missing signal arg");
let appsrc = Self::from_instance(&element);
Some(appsrc.end_of_stream(&element).to_value())
},
......@@ -581,23 +590,26 @@ impl ObjectImpl for AppSrc {
match *prop {
subclass::Property("context", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.context = value.get().unwrap_or_else(|| "".into());
settings.context = value
.get()
.expect("type checked upstream")
.unwrap_or_else(|| "".into());
}
subclass::Property("context-wait", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.context_wait = value.get().unwrap();
settings.context_wait = value.get_some().expect("type checked upstream");
}
subclass::Property("caps", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.caps = value.get();
settings.caps = value.get().expect("type checked upstream");
}
subclass::Property("max-buffers", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.max_buffers = value.get().unwrap();
settings.max_buffers = value.get_some().expect("type checked upstream");
}
subclass::Property("do-timestamp", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.do_timestamp = value.get().unwrap();
settings.do_timestamp = value.get_some().expect("type checked upstream");
}
_ => unimplemented!(),
}
......
......@@ -529,8 +529,14 @@ impl ProxySink {
let s = e.get_structure().unwrap();
if s.get_name() == "ts-io-context" {
let mut state = self.state.lock().unwrap();
let io_context = s.get::<&IOContext>("io-context").unwrap();
let pending_future_id = s.get::<&PendingFutureId>("pending-future-id").unwrap();
let io_context = s
.get::<&IOContext>("io-context")
.expect("signal arg")
.expect("missing signal arg");
let pending_future_id = s
.get::<&PendingFutureId>("pending-future-id")
.expect("signal arg")
.expect("missing signal arg");
gst_debug!(
self.cat,
......@@ -711,7 +717,10 @@ impl ObjectImpl for ProxySink {
match *prop {
subclass::Property("proxy-context", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.proxy_context = value.get().unwrap_or_else(|| "".into());
settings.proxy_context = value
.get()
.expect("type checked upstream")
.unwrap_or_else(|| "".into());
}
_ => unimplemented!(),
}
......@@ -1239,27 +1248,33 @@ impl ObjectImpl for ProxySrc {
match *prop {
subclass::Property("max-size-buffers", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.max_size_buffers = value.get().unwrap();
settings.max_size_buffers = value.get_some().expect("type checked upstream");
}
subclass::Property("max-size-bytes", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.max_size_bytes = value.get().unwrap();
settings.max_size_bytes = value.get_some().expect("type checked upstream");
}
subclass::Property("max-size-time", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.max_size_time = value.get().unwrap();
settings.max_size_time = value.get_some().expect("type checked upstream");
}
subclass::Property("context", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.context = value.get().unwrap_or_else(|| "".into());
settings.context = value
.get()
.expect("type checked upstream")
.unwrap_or_else(|| "".into());
}
subclass::Property("context-wait", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.context_wait = value.get().unwrap();
settings.context_wait = value.get_some().expect("type checked upstream");
}
subclass::Property("proxy-context", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.proxy_context = value.get().unwrap_or_else(|| "".into());
settings.proxy_context = value
.get()
.expect("type checked upstream")
.unwrap_or_else(|| "".into());
}
_ => unimplemented!(),
}
......
......@@ -432,8 +432,14 @@ impl Queue {
let s = e.get_structure().unwrap();
if s.get_name() == "ts-io-context" {
let mut state = self.state.lock().unwrap();
let io_context = s.get::<&IOContext>("io-context").unwrap();
let pending_future_id = s.get::<&PendingFutureId>("pending-future-id").unwrap();
let io_context = s
.get::<&IOContext>("io-context")
.expect("signal arg")
.expect("missing signal arg");
let pending_future_id = s
.get::<&PendingFutureId>("pending-future-id")
.expect("signal arg")
.expect("missing signal arg");
gst_debug!(
self.cat,
......@@ -918,23 +924,26 @@ impl ObjectImpl for Queue {
match *prop {
subclass::Property("max-size-buffers", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.max_size_buffers = value.get().unwrap();
settings.max_size_buffers = value.get_some().expect("type checked upstream");
}
subclass::Property("max-size-bytes", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.max_size_bytes = value.get().unwrap();
settings.max_size_bytes = value.get_some().expect("type checked upstream");
}
subclass::Property("max-size-time", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.max_size_time = value.get().unwrap();
settings.max_size_time = value.get_some().expect("type checked upstream");
}
subclass::Property("context", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.context = value.get().unwrap_or_else(|| "".into());
settings.context = value
.get()
.expect("type checked upstream")
.unwrap_or_else(|| "".into());
}
subclass::Property("context-wait", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.context_wait = value.get().unwrap();
settings.context_wait = value.get_some().expect("type checked upstream");
}
_ => unimplemented!(),
}
......
......@@ -640,27 +640,30 @@ impl ObjectImpl for TcpClientSrc {
match *prop {
subclass::Property("address", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.address = value.get();
settings.address = value.get().expect("type checked upstream");
}
subclass::Property("port", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.port = value.get().unwrap();
settings.port = value.get_some().expect("type checked upstream");
}
subclass::Property("caps", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.caps = value.get();
settings.caps = value.get().expect("type checked upstream");
}
subclass::Property("chunk-size", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.chunk_size = value.get().unwrap();
settings.chunk_size = value.get_some().expect("type checked upstream");
}
subclass::Property("context", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.context = value.get().unwrap_or_else(|| "".into());
settings.context = value
.get()
.expect("type checked upstream")
.unwrap_or_else(|| "".into());
}
subclass::Property("context-wait", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.context_wait = value.get().unwrap();
settings.context_wait = value.get_some().expect("type checked upstream");
}
_ => unimplemented!(),
}
......
......@@ -979,28 +979,29 @@ impl ObjectImpl for UdpSrc {
match *prop {
subclass::Property("address", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.address = value.get();
settings.address = value.get().expect("type checked upstream");
}
subclass::Property("port", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.port = value.get().unwrap();
settings.port = value.get_some().expect("type checked upstream");
}
subclass::Property("reuse", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.reuse = value.get().unwrap();
settings.reuse = value.get_some().expect("type checked upstream");
}
subclass::Property("caps", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.caps = value.get();
settings.caps = value.get().expect("type checked upstream");
}
subclass::Property("mtu", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.mtu = value.get().unwrap();
settings.mtu = value.get_some().expect("type checked upstream");
}
subclass::Property("socket", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.socket = value
.get::<gio::Socket>()
.expect("type checked upstream")
.map(|socket| GioSocketWrapper::new(&socket));
}
subclass::Property("used-socket", ..) => {
......@@ -1008,15 +1009,18 @@ impl ObjectImpl for UdpSrc {
}
subclass::Property("context", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.context = value.get().unwrap_or_else(|| "".into());
settings.context = value
.get()
.expect("type checked upstream")
.unwrap_or_else(|| "".into());
}
subclass::Property("context-wait", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.context_wait = value.get().unwrap();
settings.context_wait = value.get_some().expect("type checked upstream");
}
subclass::Property("retrieve-sender-address", ..) => {
let mut settings = self.settings.lock().unwrap();
settings.retrieve_sender_address = value.get().unwrap();
settings.retrieve_sender_address = value.get_some().expect("type checked upstream");
}
_ => unimplemented!(),
}
......
......@@ -56,7 +56,7 @@ fn test_push() {
.emit("push-buffer", &[&gst::Buffer::new()])
.unwrap()
.unwrap()
.get::<bool>()
.get_some::<bool>()
.unwrap());
}
......@@ -64,7 +64,7 @@ fn test_push() {
.emit("end-of-stream", &[])
.unwrap()
.unwrap()
.get::<bool>()
.get_some::<bool>()
.unwrap());
}
......