msdk: vpp: Allocation query fixes

prpose_allocation:
-- always instantiate a pool for for upstream
-- use async_depth + 1 as min buffer count

decide_allocation:
-- always create a new bufferpool for source pad.
Each of the msdk element has to create it's own mfxsurfacepool
which is an msdk contraint. For eg: Each Msdk component (vpp, dec and
enc)
will invoke the external Frame allocator for video-memory usage
So sharing the pool between gst-msdk elements might not be a good idea.

https://bugzilla.gnome.org/show_bug.cgi?id=793705
This commit is contained in:
Sreerenj Balachandran 2018-04-24 16:45:24 -08:00
parent ede8b1c8ce
commit 5184f85d77

View file

@ -325,32 +325,36 @@ gst_msdkvpp_decide_allocation (GstBaseTransform * trans, GstQuery * query)
else else
thiz->add_video_meta = FALSE; thiz->add_video_meta = FALSE;
if (gst_query_get_n_allocation_pools (query) > 0) { /* Check whether the query has pool */
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min_buffers, if (gst_query_get_n_allocation_pools (query) > 0)
&max_buffers);
update_pool = TRUE; update_pool = TRUE;
size = MAX (size, GST_VIDEO_INFO_SIZE (&info));
if (pool && !GST_IS_MSDK_BUFFER_POOL (pool)) { /* increase the min_buffers with number of concurrent vpp operations */
GST_INFO_OBJECT (thiz, "ignoring non-msdk pool: %" GST_PTR_FORMAT, pool); min_buffers += thiz->async_depth;
g_clear_object (&pool);
}
}
if (!pool) { /* invalidate the cached pool if there is an allocation_query */
if (thiz->srcpad_buffer_pool)
gst_object_unref (thiz->srcpad_buffer_pool); gst_object_unref (thiz->srcpad_buffer_pool);
pool =
gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, caps, min_buffers);
thiz->srcpad_buffer_pool = pool;
/* get the configured pool properties inorder to set in query */ /* Always create a pool for vpp out buffers. Each of the msdk element
config = gst_buffer_pool_get_config (pool); * has to create it's own mfxsurfacepool which is an msdk contraint.
gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers, * For eg: Each Msdk component (vpp, dec and enc) will invoke the external
&max_buffers); * Frame allocator for video-memory usage.So sharing the pool between
if (gst_buffer_pool_config_get_allocator (config, &allocator, &params)) * gst-msdk elements might not be a good idea, rather each element
gst_query_add_allocation_param (query, allocator, &params); * can check the buffer type (whether it is from msdk-buffer pool)
gst_structure_free (config); * to make sure there is no copy. Since we share the context between
} * msdk elements, using buffers from one sdk's framealloator in another
* sdk-components is perfectly fine */
pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, caps, min_buffers);
thiz->srcpad_buffer_pool = pool;
/* get the configured pool properties inorder to set in query */
config = gst_buffer_pool_get_config (pool);
gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
&max_buffers);
if (gst_buffer_pool_config_get_allocator (config, &allocator, &params))
gst_query_add_allocation_param (query, allocator, &params);
gst_structure_free (config);
if (update_pool) if (update_pool)
gst_query_set_nth_allocation_pool (query, 0, pool, size, min_buffers, gst_query_set_nth_allocation_pool (query, 0, pool, size, min_buffers,
@ -377,8 +381,9 @@ gst_msdkvpp_propose_allocation (GstBaseTransform * trans,
GstCaps *caps; GstCaps *caps;
GstStructure *config; GstStructure *config;
gboolean need_pool; gboolean need_pool;
guint size;
GstAllocationParams params; GstAllocationParams params;
guint size;
guint min_buffers = thiz->async_depth + 1;
gst_query_parse_allocation (query, &caps, &need_pool); gst_query_parse_allocation (query, &caps, &need_pool);
if (!caps) { if (!caps) {
@ -391,37 +396,37 @@ gst_msdkvpp_propose_allocation (GstBaseTransform * trans,
return FALSE; return FALSE;
} }
size = MAX (info.size, GST_VIDEO_INFO_SIZE (&thiz->sinkpad_buffer_pool_info)); if (need_pool) {
/* alwys provide a new pool for upstream to help re-negotiation
/* We already created a pool while setting the caps * more info here: https://bugzilla.gnome.org/show_bug.cgi?id=748344 */
* just to make sure the pipeline works even if there is pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
* no allocation query from upstream (theoratical ??).Provide the min_buffers);
* same pool in query if required/possible */
if (!gst_video_info_is_equal (&thiz->sinkpad_buffer_pool_info, &info)) {
gst_object_unref (thiz->sinkpad_buffer_pool);
thiz->sinkpad_buffer_pool =
gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
thiz->in_num_surfaces);
} }
pool = thiz->sinkpad_buffer_pool; /* Update the internal pool if any allocation attribute changed */
if (!gst_video_info_is_equal (&thiz->sinkpad_buffer_pool_info, &info)) {
gst_object_unref (thiz->sinkpad_buffer_pool);
thiz->sinkpad_buffer_pool = gst_msdkvpp_create_buffer_pool (thiz,
GST_PAD_SINK, caps, min_buffers);
}
/* get the size and allocator params from configured pool and set it in query */
if (!need_pool)
pool = gst_object_ref (thiz->sinkpad_buffer_pool);
config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool)); config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
gst_buffer_pool_config_get_params (config, NULL, &size, NULL, NULL); gst_buffer_pool_config_get_params (config, NULL, &size, NULL, NULL);
if (gst_buffer_pool_config_get_allocator (config, &allocator, &params)) if (gst_buffer_pool_config_get_allocator (config, &allocator, &params))
gst_query_add_allocation_param (query, allocator, &params); gst_query_add_allocation_param (query, allocator, &params);
gst_structure_free (config); gst_structure_free (config);
/* if upstream does't have a pool requirement, set only /* if upstream does't have a pool requirement, set only
* size, min_buffers and max_buffers in query */ * size, min_buffers and max_buffers in query */
if (!need_pool) gst_query_add_allocation_pool (query, need_pool ? pool : NULL, size,
pool = NULL; min_buffers, 0);
gst_query_add_allocation_pool (query, pool, size, thiz->in_num_surfaces, 0);
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL); gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
gst_object_unref (pool);
return GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans, return GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans,
decide_query, query); decide_query, query);
} }