Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
video-converter: switch to using a task pool ..
.. and make use of that API in videoaggregator.

When setting certain properties, such as cropping or the scaled
size of pads, a new converter is created by videoaggregator.

Before that patch, this implied spawning new threads, potentially
at each aggregate cycle when interpolating pad properties. This
is obviously wasteful, and re-using a task pool removes that
overhead.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/896>
  • Loading branch information
MathieuDuponchelle authored and GStreamer Merge Bot committed Nov 12, 2020
1 parent f3dc83d commit c50f447
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 129 deletions.
42 changes: 36 additions & 6 deletions gst-libs/gst/video/gstvideoaggregator.c
Expand Up @@ -415,6 +415,8 @@ struct _GstVideoAggregatorConvertPadPrivate
* and as such are protected with the object lock */
GstStructure *converter_config;
gboolean converter_config_changed;

GstTaskPool *task_pool;
};

G_DEFINE_TYPE_WITH_PRIVATE (GstVideoAggregatorConvertPad,
Expand All @@ -433,6 +435,11 @@ gst_video_aggregator_convert_pad_finalize (GObject * o)
gst_structure_free (vaggpad->priv->converter_config);
vaggpad->priv->converter_config = NULL;

if (vaggpad->priv->task_pool)
gst_task_pool_cleanup (vaggpad->priv->task_pool);

gst_object_replace ((GstObject **) & vaggpad->priv->task_pool, NULL);

G_OBJECT_CLASS (gst_video_aggregator_pad_parent_class)->finalize (o);
}

Expand All @@ -447,6 +454,15 @@ static void
GST_OBJECT_UNLOCK (pad);
}

static guint
get_opt_uint (const GstStructure * config, const gchar * opt, guint def)
{
guint res;
if (!gst_structure_get_uint (config, opt, &res))
res = def;
return res;
}

static gboolean
gst_video_aggregator_convert_pad_prepare_frame (GstVideoAggregatorPad * vpad,
GstVideoAggregator * vagg, GstBuffer * buffer,
Expand Down Expand Up @@ -475,19 +491,31 @@ gst_video_aggregator_convert_pad_prepare_frame (GstVideoAggregatorPad * vpad,
pad->priv->convert = NULL;

if (!gst_video_info_is_equal (&vpad->info, &pad->priv->conversion_info)) {
if (pad->priv->converter_config) {
guint n_threads = get_opt_uint (pad->priv->converter_config,
GST_VIDEO_CONVERTER_OPT_THREADS, 1);

if (n_threads == 0 || n_threads > g_get_num_processors ())
n_threads = g_get_num_processors ();

gst_shared_task_pool_set_max_threads (GST_SHARED_TASK_POOL (pad->priv->
task_pool), n_threads);
}

pad->priv->convert =
gst_video_converter_new (&vpad->info, &pad->priv->conversion_info,
pad->priv->converter_config ? gst_structure_copy (pad->priv->
converter_config) : NULL);
gst_video_converter_new_with_pool (&vpad->info,
&pad->priv->conversion_info,
pad->priv->converter_config ? gst_structure_copy (pad->
priv->converter_config) : NULL, pad->priv->task_pool);
if (!pad->priv->convert) {
GST_WARNING_OBJECT (pad, "No path found for conversion");
return FALSE;
}

GST_DEBUG_OBJECT (pad, "This pad will be converted from %s to %s",
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&vpad->info)),
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&pad->
priv->conversion_info)));
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&pad->priv->
conversion_info)));
} else {
GST_DEBUG_OBJECT (pad, "This pad will not need conversion");
}
Expand Down Expand Up @@ -689,8 +717,10 @@ gst_video_aggregator_convert_pad_init (GstVideoAggregatorConvertPad * vaggpad)
vaggpad->priv->convert = NULL;
vaggpad->priv->converter_config = NULL;
vaggpad->priv->converter_config_changed = FALSE;
}
vaggpad->priv->task_pool = gst_shared_task_pool_new ();

gst_task_pool_prepare (vaggpad->priv->task_pool, NULL);
}

/**
* gst_video_aggregator_convert_pad_update_conversion_info:
Expand Down

0 comments on commit c50f447

Please sign in to comment.