winegstreamer: Handle allocation query in a separate helper.
This commit is contained in:
parent
6dae92cfb9
commit
ec759079a5
1 changed files with 63 additions and 59 deletions
|
@ -125,6 +125,66 @@ static gboolean transform_src_query_cb(GstPad *pad, GstObject *parent, GstQuery
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean transform_sink_query_allocation(struct wg_transform *transform, GstQuery *query)
|
||||
{
|
||||
gsize plane_align = transform->attrs.output_plane_align;
|
||||
GstStructure *config, *params;
|
||||
GstVideoAlignment align;
|
||||
gboolean needs_pool;
|
||||
GstBufferPool *pool;
|
||||
GstVideoInfo info;
|
||||
GstCaps *caps;
|
||||
|
||||
gst_query_parse_allocation(query, &caps, &needs_pool);
|
||||
if (stream_type_from_caps(caps) != GST_STREAM_TYPE_VIDEO || !needs_pool)
|
||||
return false;
|
||||
|
||||
if (!gst_video_info_from_caps(&info, caps)
|
||||
|| !(pool = gst_video_buffer_pool_new()))
|
||||
return false;
|
||||
|
||||
align_video_info_planes(plane_align, &info, &align);
|
||||
|
||||
if ((params = gst_structure_new("video-meta",
|
||||
"padding-top", G_TYPE_UINT, align.padding_top,
|
||||
"padding-bottom", G_TYPE_UINT, align.padding_bottom,
|
||||
"padding-left", G_TYPE_UINT, align.padding_left,
|
||||
"padding-right", G_TYPE_UINT, align.padding_right,
|
||||
NULL)))
|
||||
{
|
||||
gst_query_add_allocation_meta(query, GST_VIDEO_META_API_TYPE, params);
|
||||
gst_structure_free(params);
|
||||
}
|
||||
|
||||
if (!(config = gst_buffer_pool_get_config(pool)))
|
||||
GST_ERROR("Failed to get pool %p config.", pool);
|
||||
else
|
||||
{
|
||||
gst_buffer_pool_config_add_option(config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
gst_buffer_pool_config_add_option(config, GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
|
||||
gst_buffer_pool_config_set_video_alignment(config, &align);
|
||||
|
||||
gst_buffer_pool_config_set_params(config, caps,
|
||||
info.size, 0, 0);
|
||||
gst_buffer_pool_config_set_allocator(config, transform->allocator, NULL);
|
||||
if (!gst_buffer_pool_set_config(pool, config))
|
||||
GST_ERROR("Failed to set pool %p config.", pool);
|
||||
}
|
||||
|
||||
/* Prevent pool reconfiguration, we don't want another alignment. */
|
||||
if (!gst_buffer_pool_set_active(pool, true))
|
||||
GST_ERROR("Pool %p failed to activate.", pool);
|
||||
|
||||
gst_query_add_allocation_pool(query, pool, info.size, 0, 0);
|
||||
gst_query_add_allocation_param(query, transform->allocator, NULL);
|
||||
|
||||
GST_INFO("Proposing pool %p, buffer size %#zx, allocator %p, for query %p.",
|
||||
pool, info.size, transform->allocator, query);
|
||||
|
||||
g_object_unref(pool);
|
||||
return true;
|
||||
}
|
||||
|
||||
static gboolean transform_sink_query_cb(GstPad *pad, GstObject *parent, GstQuery *query)
|
||||
{
|
||||
struct wg_transform *transform = gst_pad_get_element_private(pad);
|
||||
|
@ -134,65 +194,9 @@ static gboolean transform_sink_query_cb(GstPad *pad, GstObject *parent, GstQuery
|
|||
switch (query->type)
|
||||
{
|
||||
case GST_QUERY_ALLOCATION:
|
||||
{
|
||||
gsize plane_align = transform->attrs.output_plane_align;
|
||||
GstStructure *config, *params;
|
||||
GstVideoAlignment align;
|
||||
gboolean needs_pool;
|
||||
GstBufferPool *pool;
|
||||
GstVideoInfo info;
|
||||
GstCaps *caps;
|
||||
|
||||
gst_query_parse_allocation(query, &caps, &needs_pool);
|
||||
if (stream_type_from_caps(caps) != GST_STREAM_TYPE_VIDEO || !needs_pool)
|
||||
break;
|
||||
|
||||
if (!gst_video_info_from_caps(&info, caps)
|
||||
|| !(pool = gst_video_buffer_pool_new()))
|
||||
break;
|
||||
|
||||
align_video_info_planes(plane_align, &info, &align);
|
||||
|
||||
if ((params = gst_structure_new("video-meta",
|
||||
"padding-top", G_TYPE_UINT, align.padding_top,
|
||||
"padding-bottom", G_TYPE_UINT, align.padding_bottom,
|
||||
"padding-left", G_TYPE_UINT, align.padding_left,
|
||||
"padding-right", G_TYPE_UINT, align.padding_right,
|
||||
NULL)))
|
||||
{
|
||||
gst_query_add_allocation_meta(query, GST_VIDEO_META_API_TYPE, params);
|
||||
gst_structure_free(params);
|
||||
}
|
||||
|
||||
if (!(config = gst_buffer_pool_get_config(pool)))
|
||||
GST_ERROR("Failed to get pool %p config.", pool);
|
||||
else
|
||||
{
|
||||
gst_buffer_pool_config_add_option(config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
gst_buffer_pool_config_add_option(config, GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
|
||||
gst_buffer_pool_config_set_video_alignment(config, &align);
|
||||
|
||||
gst_buffer_pool_config_set_params(config, caps,
|
||||
info.size, 0, 0);
|
||||
gst_buffer_pool_config_set_allocator(config, transform->allocator, NULL);
|
||||
if (!gst_buffer_pool_set_config(pool, config))
|
||||
GST_ERROR("Failed to set pool %p config.", pool);
|
||||
}
|
||||
|
||||
/* Prevent pool reconfiguration, we don't want another alignment. */
|
||||
if (!gst_buffer_pool_set_active(pool, true))
|
||||
GST_ERROR("Pool %p failed to activate.", pool);
|
||||
|
||||
gst_query_add_allocation_pool(query, pool, info.size, 0, 0);
|
||||
gst_query_add_allocation_param(query, transform->allocator, NULL);
|
||||
|
||||
GST_INFO("Proposing pool %p, buffer size %#zx, allocator %p, for query %p.",
|
||||
pool, info.size, transform->allocator, query);
|
||||
|
||||
g_object_unref(pool);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (transform_sink_query_allocation(transform, query))
|
||||
return true;
|
||||
break;
|
||||
case GST_QUERY_CAPS:
|
||||
{
|
||||
GstCaps *caps, *filter, *temp;
|
||||
|
|
Loading…
Add table
Reference in a new issue