mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-29 13:01:05 +00:00
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:
parent
dfdf01b868
commit
0b3bfa7ea2
1 changed files with 6 additions and 3 deletions
|
@ -13,6 +13,7 @@ use PromiseResult;
|
||||||
use Structure;
|
use Structure;
|
||||||
use StructureRef;
|
use StructureRef;
|
||||||
|
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
|
@ -53,15 +54,17 @@ impl Promise {
|
||||||
promise: *mut gst_sys::GstPromise,
|
promise: *mut gst_sys::GstPromise,
|
||||||
user_data: glib_sys::gpointer,
|
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 user_data: &mut Option<F> = &mut *(user_data as *mut _);
|
||||||
let callback = user_data.take().unwrap();
|
let callback = user_data.take().unwrap();
|
||||||
|
|
||||||
let promise: Borrowed<Promise> = from_glib_borrow(promise);
|
let promise: Borrowed<Promise> = from_glib_borrow(promise);
|
||||||
|
|
||||||
let res = match promise.wait() {
|
let res = match promise.wait() {
|
||||||
PromiseResult::Replied => {
|
// Return an empty structure if it's None as workaround for
|
||||||
Ok(promise.get_reply().expect("Promise resolved but no reply"))
|
// 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::Interrupted => Err(PromiseError::Interrupted),
|
||||||
PromiseResult::Expired => Err(PromiseError::Expired),
|
PromiseResult::Expired => Err(PromiseError::Expired),
|
||||||
PromiseResult::Pending => {
|
PromiseResult::Pending => {
|
||||||
|
|
Loading…
Reference in a new issue