mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
xvimagesink: Don't share internal pool
Sharing the internal pool results in situation where the pool may have two upstream owners. This creates a race upon deactivation. Instead, always offer a new pool, and keep the internal pool internal in case we absolutely need it. https://bugzilla.gnome.org/show_bug.cgi?id=748344
This commit is contained in:
parent
ae20ba7ad4
commit
df313a6dbc
1 changed files with 37 additions and 55 deletions
|
@ -659,19 +659,42 @@ gst_xvimagesink_getcaps (GstBaseSink * bsink, GstCaps * filter)
|
||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GstBufferPool *
|
||||||
|
gst_xvimagesink_create_pool (GstXvImageSink * xvimagesink, GstCaps * caps,
|
||||||
|
gsize size, gint min)
|
||||||
|
{
|
||||||
|
GstBufferPool *pool;
|
||||||
|
GstStructure *config;
|
||||||
|
|
||||||
|
pool = gst_xvimage_buffer_pool_new (xvimagesink->allocator);
|
||||||
|
|
||||||
|
config = gst_buffer_pool_get_config (pool);
|
||||||
|
gst_buffer_pool_config_set_params (config, caps, size, min, 0);
|
||||||
|
|
||||||
|
if (!gst_buffer_pool_set_config (pool, config))
|
||||||
|
goto config_failed;
|
||||||
|
|
||||||
|
return pool;
|
||||||
|
|
||||||
|
config_failed:
|
||||||
|
{
|
||||||
|
GST_ERROR_OBJECT (xvimagesink, "failed to set config.");
|
||||||
|
gst_object_unref (pool);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_xvimagesink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
gst_xvimagesink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstXvImageSink *xvimagesink;
|
GstXvImageSink *xvimagesink;
|
||||||
GstXvContext *context;
|
GstXvContext *context;
|
||||||
GstStructure *structure;
|
|
||||||
GstBufferPool *newpool, *oldpool;
|
GstBufferPool *newpool, *oldpool;
|
||||||
GstVideoInfo info;
|
GstVideoInfo info;
|
||||||
guint32 im_format = 0;
|
guint32 im_format = 0;
|
||||||
gint video_par_n, video_par_d; /* video's PAR */
|
gint video_par_n, video_par_d; /* video's PAR */
|
||||||
gint display_par_n, display_par_d; /* display's PAR */
|
gint display_par_n, display_par_d; /* display's PAR */
|
||||||
guint num, den;
|
guint num, den;
|
||||||
gint size;
|
|
||||||
|
|
||||||
xvimagesink = GST_XVIMAGESINK (bsink);
|
xvimagesink = GST_XVIMAGESINK (bsink);
|
||||||
context = xvimagesink->context;
|
context = xvimagesink->context;
|
||||||
|
@ -698,8 +721,6 @@ gst_xvimagesink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
||||||
|
|
||||||
gst_xvcontext_set_colorimetry (context, &info.colorimetry);
|
gst_xvcontext_set_colorimetry (context, &info.colorimetry);
|
||||||
|
|
||||||
size = info.size;
|
|
||||||
|
|
||||||
/* get aspect ratio from caps if it's present, and
|
/* get aspect ratio from caps if it's present, and
|
||||||
* convert video width and height to a display width and height
|
* convert video width and height to a display width and height
|
||||||
* using wd / hd = wv / hv * PARv / PARd */
|
* using wd / hd = wv / hv * PARv / PARd */
|
||||||
|
@ -778,24 +799,16 @@ gst_xvimagesink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
||||||
xvimagesink->redraw_border = TRUE;
|
xvimagesink->redraw_border = TRUE;
|
||||||
|
|
||||||
/* create a new pool for the new configuration */
|
/* create a new pool for the new configuration */
|
||||||
newpool = gst_xvimage_buffer_pool_new (xvimagesink->allocator);
|
newpool = gst_xvimagesink_create_pool (xvimagesink, caps, info.size, 2);
|
||||||
|
|
||||||
structure = gst_buffer_pool_get_config (newpool);
|
|
||||||
gst_buffer_pool_config_set_params (structure, caps, size, 2, 0);
|
|
||||||
if (!gst_buffer_pool_set_config (newpool, structure))
|
|
||||||
goto config_failed;
|
|
||||||
|
|
||||||
|
/* we don't activate the internal pool yet as it may not be needed */
|
||||||
oldpool = xvimagesink->pool;
|
oldpool = xvimagesink->pool;
|
||||||
/* we don't activate the pool yet, this will be done by downstream after it
|
|
||||||
* has configured the pool. If downstream does not want our pool we will
|
|
||||||
* activate it when we render into it */
|
|
||||||
xvimagesink->pool = newpool;
|
xvimagesink->pool = newpool;
|
||||||
g_mutex_unlock (&xvimagesink->flow_lock);
|
g_mutex_unlock (&xvimagesink->flow_lock);
|
||||||
|
|
||||||
/* unref the old sink */
|
/* deactivate and unref the old internal pool */
|
||||||
if (oldpool) {
|
if (oldpool) {
|
||||||
/* we don't deactivate, some elements might still be using it, it will
|
gst_buffer_pool_set_active (oldpool, FALSE);
|
||||||
* be deactivated when the last ref is gone */
|
|
||||||
gst_object_unref (oldpool);
|
gst_object_unref (oldpool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -825,13 +838,6 @@ no_display_size:
|
||||||
("Error calculating the output display ratio of the video."));
|
("Error calculating the output display ratio of the video."));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
config_failed:
|
|
||||||
{
|
|
||||||
GST_ERROR_OBJECT (xvimagesink, "failed to set config.");
|
|
||||||
gst_object_unref (newpool);
|
|
||||||
g_mutex_unlock (&xvimagesink->flow_lock);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstStateChangeReturn
|
static GstStateChangeReturn
|
||||||
|
@ -1043,8 +1049,7 @@ static gboolean
|
||||||
gst_xvimagesink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
|
gst_xvimagesink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
|
||||||
{
|
{
|
||||||
GstXvImageSink *xvimagesink = GST_XVIMAGESINK (bsink);
|
GstXvImageSink *xvimagesink = GST_XVIMAGESINK (bsink);
|
||||||
GstBufferPool *pool;
|
GstBufferPool *pool = NULL;
|
||||||
GstStructure *config;
|
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
guint size;
|
guint size;
|
||||||
gboolean need_pool;
|
gboolean need_pool;
|
||||||
|
@ -1054,44 +1059,22 @@ gst_xvimagesink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
|
||||||
if (caps == NULL)
|
if (caps == NULL)
|
||||||
goto no_caps;
|
goto no_caps;
|
||||||
|
|
||||||
g_mutex_lock (&xvimagesink->flow_lock);
|
if (need_pool) {
|
||||||
if ((pool = xvimagesink->pool))
|
|
||||||
gst_object_ref (pool);
|
|
||||||
g_mutex_unlock (&xvimagesink->flow_lock);
|
|
||||||
|
|
||||||
if (pool != NULL) {
|
|
||||||
GstCaps *pcaps;
|
|
||||||
|
|
||||||
/* we had a pool, check caps */
|
|
||||||
GST_DEBUG_OBJECT (xvimagesink, "check existing pool caps");
|
|
||||||
config = gst_buffer_pool_get_config (pool);
|
|
||||||
gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
|
|
||||||
|
|
||||||
if (!gst_caps_is_equal (caps, pcaps)) {
|
|
||||||
GST_DEBUG_OBJECT (xvimagesink, "pool has different caps");
|
|
||||||
/* different caps, we can't use this pool */
|
|
||||||
gst_object_unref (pool);
|
|
||||||
pool = NULL;
|
|
||||||
}
|
|
||||||
gst_structure_free (config);
|
|
||||||
}
|
|
||||||
if (pool == NULL && need_pool) {
|
|
||||||
GstVideoInfo info;
|
GstVideoInfo info;
|
||||||
|
|
||||||
if (!gst_video_info_from_caps (&info, caps))
|
if (!gst_video_info_from_caps (&info, caps))
|
||||||
goto invalid_caps;
|
goto invalid_caps;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (xvimagesink, "create new pool");
|
GST_DEBUG_OBJECT (xvimagesink, "create new pool");
|
||||||
pool = gst_xvimage_buffer_pool_new (xvimagesink->allocator);
|
pool = gst_xvimagesink_create_pool (xvimagesink, caps, info.size, 0);
|
||||||
|
|
||||||
/* the normal size of a frame */
|
/* the normal size of a frame */
|
||||||
size = info.size;
|
size = info.size;
|
||||||
|
|
||||||
config = gst_buffer_pool_get_config (pool);
|
if (pool == NULL)
|
||||||
gst_buffer_pool_config_set_params (config, caps, size, 0, 0);
|
goto no_pool;
|
||||||
if (!gst_buffer_pool_set_config (pool, config))
|
|
||||||
goto config_failed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pool) {
|
if (pool) {
|
||||||
/* we need at least 2 buffer because we hold on to the last one */
|
/* we need at least 2 buffer because we hold on to the last one */
|
||||||
gst_query_add_allocation_pool (query, pool, size, 2, 0);
|
gst_query_add_allocation_pool (query, pool, size, 2, 0);
|
||||||
|
@ -1115,10 +1098,9 @@ invalid_caps:
|
||||||
GST_DEBUG_OBJECT (bsink, "invalid caps specified");
|
GST_DEBUG_OBJECT (bsink, "invalid caps specified");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
config_failed:
|
no_pool:
|
||||||
{
|
{
|
||||||
GST_DEBUG_OBJECT (bsink, "failed setting config");
|
/* Already warned in create_pool */
|
||||||
gst_object_unref (pool);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue