omxbufferpool: fix early input buffer release
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 15 Nov 2018 10:17:59 +0000 (11:17 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.com>
Fri, 21 Dec 2018 16:16:31 +0000 (17:16 +0100)
We used to track the 'allocating' status on the pool. It is used while
allocating so output buffers aren't passed right away to OMX and input
ones are not re-added to the pending queue.

This was causing a bug when exporting buffers to v4l2src. On start
v4l2src acquires a buffer, read its stride and release it right away.
As no buffer was received by the encoder element at this point, 'allocating'
was still on TRUE and so the the buffer wasn't put back to the pending
queue and, as result, no longer available to the pool.

Fix this by checking the active status of the pool instead of manually
tracking it down. The pool is considered as active at the very end of
the activation process so we're good when buffers are released during
the activation.

omx/gstomxbufferpool.c
omx/gstomxbufferpool.h
omx/gstomxvideodec.c
omx/gstomxvideoenc.c

index 7bb31f5..910f3ff 100644 (file)
@@ -405,8 +405,6 @@ gst_omx_buffer_pool_alloc_buffer (GstBufferPool * bpool,
   GstBuffer *buf;
   GstOMXBuffer *omx_buf;
 
-  g_return_val_if_fail (pool->allocating, GST_FLOW_ERROR);
-
   omx_buf = g_ptr_array_index (pool->port->buffers, pool->current_buffer_index);
   g_return_val_if_fail (omx_buf != NULL, GST_FLOW_ERROR);
 
@@ -659,7 +657,7 @@ gst_omx_buffer_pool_release_buffer (GstBufferPool * bpool, GstBuffer * buffer)
 
   g_assert (pool->component && pool->port);
 
-  if (!pool->allocating) {
+  if (gst_buffer_pool_is_active (bpool)) {
     omx_buf = gst_omx_buffer_get_omx_buf (buffer);
     if (pool->port->port_def.eDir == OMX_DirOutput && !omx_buf->used &&
         !pool->deactivated) {
index 71d1afc..a09c825 100644 (file)
@@ -68,8 +68,6 @@ struct _GstOMXBufferPool
   GstAllocator *allocator;
 
   /* Set from outside this pool */
-  /* TRUE if we're currently allocating all our buffers */
-  gboolean allocating;
   /* TRUE if the pool is not used anymore */
   gboolean deactivated;
 
index e1aec3f..f68911e 100644 (file)
@@ -1165,14 +1165,11 @@ gst_omx_video_dec_allocate_output_buffers (GstOMXVideoDec * self)
       goto done;
     }
 
-    GST_OMX_BUFFER_POOL (self->out_port_pool)->allocating = TRUE;
     /* This now allocates all the buffers */
     if (!gst_buffer_pool_set_active (self->out_port_pool, TRUE)) {
       GST_INFO_OBJECT (self, "Failed to activate internal pool");
       gst_object_unref (self->out_port_pool);
       self->out_port_pool = NULL;
-    } else {
-      GST_OMX_BUFFER_POOL (self->out_port_pool)->allocating = FALSE;
     }
   } else if (self->out_port_pool) {
     gst_object_unref (self->out_port_pool);
index abac46d..6fa57fb 100644 (file)
@@ -2054,8 +2054,6 @@ gst_omx_video_enc_enable (GstOMXVideoEnc * self, GstBuffer * input)
 
   /* Is downstream using our buffer pool? */
   if (buffer_is_from_input_pool (self, input)) {
-    /* We're done allocating as we received the first buffer from upstream */
-    GST_OMX_BUFFER_POOL (input->pool)->allocating = FALSE;
     self->in_pool_used = TRUE;
   }
 
@@ -3059,7 +3057,6 @@ create_input_pool (GstOMXVideoEnc * self, GstCaps * caps, guint num_buffers)
   pool =
       gst_omx_buffer_pool_new (GST_ELEMENT_CAST (self), self->enc,
       self->enc_in_port, GST_OMX_BUFFER_MODE_DMABUF);
-  GST_OMX_BUFFER_POOL (pool)->allocating = TRUE;
 
   g_signal_connect_object (pool, "allocate",
       G_CALLBACK (pool_request_allocate_cb), self, 0);