gstreamer/promise: Convert None promise replies to an empty structure in the change_func

webrtcbin likes to put a NULL structure into the reply under some
circumstances when the promise successfully resolved.

See https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1300
for details.
This commit is contained in:
Sebastian Dröge 2020-05-27 12:21:14 +03:00
parent 8e96888c63
commit c2acb000b1

View file

@ -52,15 +52,19 @@ impl Promise {
promise: *mut gst_sys::GstPromise,
user_data: glib_sys::gpointer,
) {
lazy_static! {
static ref EMPTY: Structure = Structure::new_empty("EMPTY");
}
let user_data: &mut Option<F> = &mut *(user_data as *mut _);
let callback = user_data.take().unwrap();
let promise: Promise = from_glib_borrow(promise);
let res = match promise.wait() {
PromiseResult::Replied => {
Ok(promise.get_reply().expect("Promise resolved but no reply"))
}
// Return an empty structure if it's None as workaround for
// https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1300
PromiseResult::Replied => Ok(promise.get_reply().unwrap_or(&EMPTY)),
PromiseResult::Interrupted => Err(PromiseError::Interrupted),
PromiseResult::Expired => Err(PromiseError::Expired),
PromiseResult::Pending => {