From 7b6be347a6dc94c0ca16272fa249bc77b68f43ee Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 28 May 2018 12:20:45 +0200 Subject: [PATCH] omxbufferpool: deallocate OMX buffers when stopping The pool is stopped when all the buffers have been released. Deallocate when stopping so we are sure that the buffers aren't still used by another element. https://bugzilla.gnome.org/show_bug.cgi?id=796918 --- omx/gstomxbufferpool.c | 3 +++ omx/gstomxvideodec.c | 29 ++++++++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/omx/gstomxbufferpool.c b/omx/gstomxbufferpool.c index 4e2033f63d..995687ba6c 100644 --- a/omx/gstomxbufferpool.c +++ b/omx/gstomxbufferpool.c @@ -247,6 +247,9 @@ gst_omx_buffer_pool_stop (GstBufferPool * bpool) /* Remove any buffers that are there */ g_ptr_array_set_size (pool->buffers, 0); + GST_DEBUG_OBJECT (pool, "deallocate OMX buffers"); + gst_omx_port_deallocate_buffers (pool->port); + if (pool->caps) gst_caps_unref (pool->caps); pool->caps = NULL; diff --git a/omx/gstomxvideodec.c b/omx/gstomxvideodec.c index d2d6428755..c699067a17 100644 --- a/omx/gstomxvideodec.c +++ b/omx/gstomxvideodec.c @@ -81,7 +81,7 @@ static GstFlowReturn gst_omx_video_dec_drain (GstVideoDecoder * decoder); static OMX_ERRORTYPE gst_omx_video_dec_allocate_output_buffers (GstOMXVideoDec * self); -static OMX_ERRORTYPE gst_omx_video_dec_deallocate_output_buffers (GstOMXVideoDec +static gboolean gst_omx_video_dec_deallocate_output_buffers (GstOMXVideoDec * self); enum @@ -1135,12 +1135,11 @@ done: return err; } -static OMX_ERRORTYPE +static gboolean gst_omx_video_dec_deallocate_output_buffers (GstOMXVideoDec * self) { - OMX_ERRORTYPE err; - if (self->out_port_pool) { + /* Pool will free buffers when stopping */ gst_buffer_pool_set_active (self->out_port_pool, FALSE); #if 0 gst_buffer_pool_wait_released (self->out_port_pool); @@ -1148,16 +1147,21 @@ gst_omx_video_dec_deallocate_output_buffers (GstOMXVideoDec * self) GST_OMX_BUFFER_POOL (self->out_port_pool)->deactivated = TRUE; gst_object_unref (self->out_port_pool); self->out_port_pool = NULL; - } + } else { + OMX_ERRORTYPE err; + #if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL) - err = - gst_omx_port_deallocate_buffers (self->eglimage ? self-> - egl_out_port : self->dec_out_port); + err = + gst_omx_port_deallocate_buffers (self->eglimage ? self-> + egl_out_port : self->dec_out_port); #else - err = gst_omx_port_deallocate_buffers (self->dec_out_port); + err = gst_omx_port_deallocate_buffers (self->dec_out_port); #endif - return err; + return err == OMX_ErrorNone; + } + + return TRUE; } static OMX_ERRORTYPE @@ -1573,8 +1577,7 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self) if (err != OMX_ErrorNone) goto reconfigure_error; - err = gst_omx_video_dec_deallocate_output_buffers (self); - if (err != OMX_ErrorNone) + if (!gst_omx_video_dec_deallocate_output_buffers (self)) goto reconfigure_error; err = gst_omx_port_wait_enabled (port, 1 * GST_SECOND); @@ -2179,7 +2182,7 @@ gst_omx_video_dec_disable (GstOMXVideoDec * self) if (gst_omx_port_wait_buffers_released (out_port, 1 * GST_SECOND) != OMX_ErrorNone) return FALSE; - if (gst_omx_video_dec_deallocate_output_buffers (self) != OMX_ErrorNone) + if (!gst_omx_video_dec_deallocate_output_buffers (self)) return FALSE; if (gst_omx_port_wait_enabled (out_port, 1 * GST_SECOND) != OMX_ErrorNone) return FALSE;