mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-02 20:42:30 +00:00
encoder: fix possible memory leak of coded buffer pools.
Fix gst_vaapi_encoder_reconfigure_internal() to re-/allocate the coded buffer pool only if the coded buffer size actually changed.
This commit is contained in:
parent
5394c75461
commit
20ab910d15
3 changed files with 34 additions and 7 deletions
|
@ -111,3 +111,20 @@ gst_vaapi_coded_buffer_pool_new (GstVaapiEncoder * encoder, gsize buf_size)
|
||||||
context, buf_size);
|
context, buf_size);
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_vaapi_coded_buffer_pool_get_buffer_size:
|
||||||
|
* @pool: a #GstVaapiCodedBufferPool
|
||||||
|
*
|
||||||
|
* Determines the maximum size of each #GstVaapiCodedBuffer held in
|
||||||
|
* the @pool.
|
||||||
|
*
|
||||||
|
* Return value: size of a #GstVaapiCodedBuffer in @pool
|
||||||
|
*/
|
||||||
|
gsize
|
||||||
|
gst_vaapi_coded_buffer_pool_get_buffer_size (GstVaapiCodedBufferPool * pool)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (pool != NULL, 0);
|
||||||
|
|
||||||
|
return pool->buf_size;
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,9 @@ GstVaapiVideoPool *
|
||||||
gst_vaapi_coded_buffer_pool_new (struct _GstVaapiEncoder * encoder,
|
gst_vaapi_coded_buffer_pool_new (struct _GstVaapiEncoder * encoder,
|
||||||
gsize buf_size);
|
gsize buf_size);
|
||||||
|
|
||||||
|
gsize
|
||||||
|
gst_vaapi_coded_buffer_pool_get_buffer_size (GstVaapiCodedBufferPool * pool);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* GST_VAAPI_CODED_BUFFER_POOL_H */
|
#endif /* GST_VAAPI_CODED_BUFFER_POOL_H */
|
||||||
|
|
|
@ -481,6 +481,8 @@ gst_vaapi_encoder_reconfigure_internal (GstVaapiEncoder * encoder)
|
||||||
{
|
{
|
||||||
GstVaapiEncoderClass *const klass = GST_VAAPI_ENCODER_GET_CLASS (encoder);
|
GstVaapiEncoderClass *const klass = GST_VAAPI_ENCODER_GET_CLASS (encoder);
|
||||||
GstVaapiEncoderStatus status;
|
GstVaapiEncoderStatus status;
|
||||||
|
GstVaapiVideoPool *pool;
|
||||||
|
guint codedbuf_size;
|
||||||
|
|
||||||
status = klass->reconfigure (encoder);
|
status = klass->reconfigure (encoder);
|
||||||
if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS)
|
if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS)
|
||||||
|
@ -489,16 +491,21 @@ gst_vaapi_encoder_reconfigure_internal (GstVaapiEncoder * encoder)
|
||||||
if (!gst_vaapi_encoder_ensure_context (encoder))
|
if (!gst_vaapi_encoder_ensure_context (encoder))
|
||||||
goto error_reset_context;
|
goto error_reset_context;
|
||||||
|
|
||||||
encoder->codedbuf_pool = gst_vaapi_coded_buffer_pool_new (encoder,
|
codedbuf_size = encoder->codedbuf_pool ?
|
||||||
encoder->codedbuf_size);
|
gst_vaapi_coded_buffer_pool_get_buffer_size (GST_VAAPI_CODED_BUFFER_POOL
|
||||||
if (!encoder->codedbuf_pool)
|
(encoder)) : 0;
|
||||||
goto error_codedbuf_pool_allocation_failed;
|
if (codedbuf_size != encoder->codedbuf_size) {
|
||||||
|
pool = gst_vaapi_coded_buffer_pool_new (encoder, encoder->codedbuf_size);
|
||||||
gst_vaapi_video_pool_set_capacity (encoder->codedbuf_pool, 5);
|
if (!pool)
|
||||||
|
goto error_alloc_codedbuf_pool;
|
||||||
|
gst_vaapi_video_pool_set_capacity (pool, 5);
|
||||||
|
gst_vaapi_video_pool_replace (&encoder->codedbuf_pool, pool);
|
||||||
|
gst_vaapi_video_pool_unref (pool);
|
||||||
|
}
|
||||||
return GST_VAAPI_ENCODER_STATUS_SUCCESS;
|
return GST_VAAPI_ENCODER_STATUS_SUCCESS;
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
error_codedbuf_pool_allocation_failed:
|
error_alloc_codedbuf_pool:
|
||||||
{
|
{
|
||||||
GST_ERROR ("failed to initialize coded buffer pool");
|
GST_ERROR ("failed to initialize coded buffer pool");
|
||||||
return GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED;
|
return GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED;
|
||||||
|
|
Loading…
Reference in a new issue