omx: call gst_omx_buffer_unmap() when handling BUFFER_DONE
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 24 May 2018 14:28:21 +0000 (16:28 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 30 Aug 2018 08:59:30 +0000 (10:59 +0200)
When using a input buffer pool, the buffer may be released to the pool when
gst_omx_buffer_unmap() is called. We need to have buf->used unset at
this point as the pool may use it to check the status of the pool.

{Empty,Fill}BufferDone is called from OMX internal threads while
messages are handled from gst elements' thread. Best to do all this
when handling the message so we don't mess with OMX threads and keep
the original thread/logic split.

https://bugzilla.gnome.org/show_bug.cgi?id=796918

omx/gstomx.c

index f7a548f..0acf413 100644 (file)
@@ -247,6 +247,8 @@ gst_omx_buffer_reset (GstOMXBuffer * buf)
   GST_OMX_SET_TICKS (buf->omx_buf->nTimeStamp, G_GUINT64_CONSTANT (0));
 }
 
+static void gst_omx_buffer_unmap (GstOMXBuffer * buffer);
+
 /* NOTE: Call with comp->lock, comp->messages_lock will be used */
 static void
 gst_omx_component_handle_messages (GstOMXComponent * comp)
@@ -388,6 +390,8 @@ gst_omx_component_handle_messages (GstOMXComponent * comp)
 
         port = buf->port;
 
+        buf->used = FALSE;
+
         if (msg->content.buffer_done.empty) {
           /* Input buffer is empty again and can be used to contain new input */
           GST_LOG_OBJECT (port->comp->parent,
@@ -399,6 +403,9 @@ gst_omx_component_handle_messages (GstOMXComponent * comp)
            * valid anymore after the buffer was consumed
            */
           gst_omx_buffer_reset (buf);
+
+          /* Release and unmap the parent buffer, if any */
+          gst_omx_buffer_unmap (buf);
         } else {
           /* Output buffer contains output now or
            * the port was flushed */
@@ -411,8 +418,6 @@ gst_omx_component_handle_messages (GstOMXComponent * comp)
             port->eos = TRUE;
         }
 
-        buf->used = FALSE;
-
         g_queue_push_tail (&port->pending_buffers, buf);
 
         break;
@@ -710,9 +715,6 @@ EmptyBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR pAppData,
     return OMX_ErrorBadParameter;
   }
 
-  /* Release and unmap the parent buffer, if any */
-  gst_omx_buffer_unmap (buf);
-
   comp = buf->port->comp;
 
   msg = g_slice_new (GstOMXMessage);