summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeungha Yang <seungha@centricular.com>2021-08-04 00:51:24 +0900
committerSeungha Yang <seungha@centricular.com>2021-08-20 18:43:26 +0900
commit1ae8b61ec09c48a9f82b3173472903c13d513c74 (patch)
tree6cd5179dab7a0cc7bf0c42e665be3bf720f8471e
parentbf71ef17e31543d6e082a08018ac28b193794ade (diff)
downloadgstreamer-plugins-base-1ae8b61ec09c48a9f82b3173472903c13d513c74.tar.gz
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>
-rw-r--r--docs/plugins/gst_plugins_cache.json14
-rw-r--r--gst/compositor/compositor.c30
-rw-r--r--gst/compositor/compositor.h3
3 files changed, 46 insertions, 1 deletions
diff --git a/docs/plugins/gst_plugins_cache.json b/docs/plugins/gst_plugins_cache.json
index 73789d37f..2ce84963c 100644
--- a/docs/plugins/gst_plugins_cache.json
+++ b/docs/plugins/gst_plugins_cache.json
@@ -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,
diff --git a/gst/compositor/compositor.c b/gst/compositor/compositor.c
index 2b5ccee8f..ca4df6836 100644
--- a/gst/compositor/compositor.c
+++ b/gst/compositor/compositor.c
@@ -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 */
diff --git a/gst/compositor/compositor.h b/gst/compositor/compositor.h
index 2a6f38ba4..863bb126c 100644
--- a/gst/compositor/compositor.h
+++ b/gst/compositor/compositor.h
@@ -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. */