Object lock required in GstGLDisplay
When getting a context from a display, the canonical GStreamer C code involves taking the object lock on the GstGLDisplay, and then calling the functions gst_gl_display_get_gl_context_for_thread
, gst_gl_display_create_context
and gst_gl_display_add_context
before releasing the lock again. At least I think so - I see this code repeated a few times.
All the methods are documented as "Must be called with the object lock held". This isn't reflected in the Rust bindings.
As far as I can tell, the Rust bindings prefer to contain the object locks inside methods so the Rust user doesn't have to think about them. In this case that isn't really possible, since there is three different methods that needs to be used while having the lock held.
Could there be a utility method available for doing the whole dance with the lock and the loop?
Alternatively, something like this, and then the methods in GstDisplay could be changed to explicitly take a ObjectLockGuard?
pub fn acquire_gst_object_lock<T>(obj: &T) -> ObjectLockGuard<T> where T: IsA<gst::Object>,
{
unsafe {
let lock = &mut (*obj.as_ref().as_ptr()).lock;
g_mutex_lock(lock);
ObjectLockGuard { obj, lock }
}
}
pub struct ObjectLockGuard<'a, T> {
obj: &'a T,
lock: &'a mut GMutex,
}
impl<T> Drop for ObjectLockGuard<'_, T> {
fn drop(&mut self) {
unsafe { g_mutex_unlock(self.lock); }
}
}
impl<T> AsRef<T> for ObjectLockGuard<'_, T> { /* ... */ }
impl<T> Deref for ObjectLockGuard<'_, T> { /* ... */ }