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 dfdf01b868
commit 0b3bfa7ea2

View file

@ -13,6 +13,7 @@ use PromiseResult;
use Structure;
use StructureRef;
use once_cell::sync::Lazy;
use std::pin::Pin;
use std::task::{Context, Poll};
@ -53,15 +54,17 @@ impl Promise {
promise: *mut gst_sys::GstPromise,
user_data: glib_sys::gpointer,
) {
static EMPTY: Lazy<Structure> = Lazy::new(|| Structure::new_empty("EMPTY"));
let user_data: &mut Option<F> = &mut *(user_data as *mut _);
let callback = user_data.take().unwrap();
let promise: Borrowed<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 => {