let mut paths = glib::ValueArray::new();
paths.append(glib::Value::from("/dev/input/event6");
paths.append(glib::Value::from("/dev/input/event7");
paths.append(glib::Value::from("/dev/input/event8");
let s = gst::Structure::builder("VirtualDevicesReady")
.field("paths", paths)
.build();
let event = gst::event::CustomUpstream::new(s);
self.pipeline().send_event(event);
//
let mut paths = glib::ValueArray::new(/* u32 */);
let paths = glib::ValueArray::new(["/dev/input/event6", "/dev/input/event7", "/dev/input/event8"]);
let s = gst::Structure::builder("VirtualDevicesReady")
.field("paths", paths)
.build();
let event = gst::event::CustomUpstream::new(s);
self.pipeline().send_event(event);
//
Just one error ;
error[E0277]: `*mut ValueArray` cannot be sent between threads safely
--> net/webrtc/examples/webrtc-send.rs:284:33
|
284 | .field("paths", paths)
| ----- ^^^^^ `*mut ValueArray` cannot be sent between threads safely
| |
| required by a bound introduced by this call
|
= help: within `ValueArray`, the trait `std::marker::Send` is not implemented for `*mut ValueArray`, which is required by `ValueArray: std::marker::Send`
note: required because it appears within the type `PhantomData<*mut ValueArray>`
--> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/marker.rs:740:12
note: required because it appears within the type `Boxed<GValueArray, ValueArray>`
Ah I see, yes that won’t work because glib::ValueArray can contain also non-threadsafe types but gst::Structure always has to contain thread-safe types. That would need a bit of unsafe code to promise to the compiler that your array only contains thread-safe types
Is there a reason why you use glib::ValueArray (which is deprecated since a decade) instead of gst::Array?
In any case, this here would work
let s = gst::Structure::builder("VirtualDevicesReady")
- .field("paths", paths)
+ .field("paths", unsafe { glib::SendValue::unsafe_from(glib::Value::from(paths).into_raw()) }) // Safe because all values contained in the array are `Send`
.build();
I think I know now why it needs the glib:ValueArray . Im getting this error:
thread ‘’ panicked at gst-plugin-wayland-display/src/waylandsrc/imp.rs:200:22:
Should contain paths: ValueGetError { name: “paths”, error: WrongValueType(ValueTypeMismatchError { actual: GstValueArray, requested: GValueArray }) }
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace