va: Use a lock to protect the surface copy by using vpp.
authorHe Junyan <junyan.he@intel.com>
Tue, 23 Nov 2021 08:35:16 +0000 (16:35 +0800)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 29 Nov 2021 19:25:31 +0000 (19:25 +0000)
 If we use vpp to do the surface copy, its operation is not atomic.
 We need to maintain the filter's context unchanged during the whole
 copy progress.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1373>

subprojects/gst-plugins-bad/sys/va/gstvasurfacecopy.c

index fcbeee1..44fd6d9 100644 (file)
@@ -34,6 +34,8 @@ struct _GstVaSurfaceCopy
 
   GstVideoInfo info;
   gboolean has_copy;
+
+  GRecMutex lock;
   GstVaFilter *filter;
 };
 
@@ -77,6 +79,7 @@ gst_va_surface_copy_new (GstVaDisplay * display, GstVideoInfo * vinfo)
   self->has_copy = _has_copy (display);
   self->info = *vinfo;
   self->filter = NULL;
+  g_rec_mutex_init (&self->lock);
 
   if (gst_va_display_has_vpp (display)) {
     self->filter = gst_va_filter_new (display);
@@ -98,19 +101,29 @@ gst_va_surface_copy_free (GstVaSurfaceCopy * self)
     gst_va_filter_close (self->filter);
     gst_clear_object (&self->filter);
   }
+
+  g_rec_mutex_clear (&self->lock);
+
   g_slice_free (GstVaSurfaceCopy, self);
 }
 
 static gboolean
-_vpp_copy_surface (GstVaFilter * filter, VASurfaceID dst, VASurfaceID src)
+_vpp_copy_surface (GstVaSurfaceCopy * self, VASurfaceID dst, VASurfaceID src)
 {
+  gboolean ret;
+
   GstVaSample gst_src = {
     .surface = src,
   };
   GstVaSample gst_dst = {
     .surface = dst,
   };
-  return gst_va_filter_process (filter, &gst_src, &gst_dst);
+
+  g_rec_mutex_lock (&self->lock);
+  ret = gst_va_filter_process (self->filter, &gst_src, &gst_dst);
+  g_rec_mutex_unlock (&self->lock);
+
+  return ret;
 }
 
 gboolean
@@ -126,7 +139,7 @@ gst_va_surface_copy (GstVaSurfaceCopy * self, VASurfaceID dst, VASurfaceID src)
     return TRUE;
   }
 
-  if (self->filter && _vpp_copy_surface (self->filter, dst, src)) {
+  if (self->filter && _vpp_copy_surface (self, dst, src)) {
     GST_LOG ("VPP copy of %#x to %#x", src, dst);
     return TRUE;
   }