compositor: Add "max-threads" property

Adding new property for user to be able to set expected the maximum
number of blend task threads. This can be useful in case that user
wants to restrict the number of parallel task runners for system
resource management or debugging/development purpose.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1242>
This commit is contained in:
Seungha Yang 2021-08-04 00:51:24 +09:00
parent bf71ef17e3
commit 1ae8b61ec0
3 changed files with 46 additions and 1 deletions

View file

@ -1875,6 +1875,20 @@
"type": "GstCompositorBackground",
"writable": true
},
"max-threads": {
"blurb": "Maximum number of blending/rendering worker threads to spawn (0 = auto)",
"conditionally-available": false,
"construct": false,
"construct-only": false,
"controllable": false,
"default": "0",
"max": "2147483647",
"min": "0",
"mutable": "ready",
"readable": true,
"type": "guint",
"writable": true
},
"zero-size-is-unscaled": {
"blurb": "If TRUE, then input video is unscaled in that dimension if width or height is 0 (for backwards compatibility)",
"conditionally-available": false,

View file

@ -701,11 +701,14 @@ gst_compositor_pad_init (GstCompositorPad * compo_pad)
/* GstCompositor */
#define DEFAULT_BACKGROUND COMPOSITOR_BACKGROUND_CHECKER
#define DEFAULT_ZERO_SIZE_IS_UNSCALED TRUE
#define DEFAULT_MAX_THREADS 0
enum
{
PROP_0,
PROP_BACKGROUND,
PROP_ZERO_SIZE_IS_UNSCALED,
PROP_MAX_THREADS,
};
static void
@ -721,6 +724,9 @@ gst_compositor_get_property (GObject * object,
case PROP_ZERO_SIZE_IS_UNSCALED:
g_value_set_boolean (value, self->zero_size_is_unscaled);
break;
case PROP_MAX_THREADS:
g_value_set_uint (value, self->max_threads);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -740,6 +746,9 @@ gst_compositor_set_property (GObject * object,
case PROP_ZERO_SIZE_IS_UNSCALED:
self->zero_size_is_unscaled = g_value_get_boolean (value);
break;
case PROP_MAX_THREADS:
self->max_threads = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1166,7 +1175,11 @@ _negotiated_caps (GstAggregator * agg, GstCaps * caps)
return FALSE;
}
n_threads = g_get_num_processors ();
if (compositor->max_threads == 0)
n_threads = g_get_num_processors ();
else
n_threads = compositor->max_threads;
/* Magic number of 200 lines */
if (GST_VIDEO_INFO_HEIGHT (&v_info) / n_threads < 200)
n_threads = (GST_VIDEO_INFO_HEIGHT (&v_info) + 199) / 200;
@ -1574,6 +1587,20 @@ gst_compositor_class_init (GstCompositorClass * klass)
DEFAULT_ZERO_SIZE_IS_UNSCALED,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* compositor:max-threads:
*
* Maximum number of blending/rendering worker threads to spawn (0 = auto)
*
* Since: 1.20
*/
g_object_class_install_property (gobject_class, PROP_MAX_THREADS,
g_param_spec_uint ("max-threads", "Max Threads",
"Maximum number of blending/rendering worker threads to spawn "
"(0 = auto)", 0, G_MAXINT, DEFAULT_MAX_THREADS,
GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
gst_element_class_add_static_pad_template_with_gtype (gstelement_class,
&src_factory, GST_TYPE_AGGREGATOR_PAD);
gst_element_class_add_static_pad_template_with_gtype (gstelement_class,
@ -1595,6 +1622,7 @@ gst_compositor_init (GstCompositor * self)
/* initialize variables */
self->background = DEFAULT_BACKGROUND;
self->zero_size_is_unscaled = DEFAULT_ZERO_SIZE_IS_UNSCALED;
self->max_threads = DEFAULT_MAX_THREADS;
}
/* GstChildProxy implementation */

View file

@ -134,6 +134,9 @@ struct _GstCompositor
*/
gboolean zero_size_is_unscaled;
/* Max num of allowed for blending/rendering threads */
guint max_threads;
/* The 'blend' compositing function does not preserve the alpha value of the
* background, while 'overlay' does; i.e., COMPOSITOR_OPERATOR_ADD is the
* same as COMPOSITOR_OPERATOR_OVER when using the 'blend' BlendFunction. */