From 39fcc7f58fa258ae8bc2836bc7804434d1afae5a Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Fri, 28 Aug 2020 18:09:15 +0200 Subject: [PATCH] vp9enc: expose row-mt property With recent libvpx versions, multithreading can be enabled on a per-tile basis, instead of on a per tile-column basis. In combination with the new tile-rows property, this allows the encoder to make much better use of the available CPU power. Bump minimum libvpx version to 1.7.0 Part-of: --- docs/gst_plugins_cache.json | 12 ++++++++++++ ext/vpx/gstvp9enc.c | 39 +++++++++++++++++++++++++++++++++++++ ext/vpx/gstvp9enc.h | 3 +++ ext/vpx/meson.build | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/docs/gst_plugins_cache.json b/docs/gst_plugins_cache.json index 460635eb7f..e7f2313b6e 100644 --- a/docs/gst_plugins_cache.json +++ b/docs/gst_plugins_cache.json @@ -25885,6 +25885,18 @@ } }, "properties": { + "row-mt": { + "blurb": "Whether each row should be encoded using multiple threads", + "conditionally-available": false, + "construct": false, + "construct-only": false, + "controllable": false, + "default": "false", + "mutable": "null", + "readable": true, + "type": "gboolean", + "writable": true + }, "tile-columns": { "blurb": "Number of tile columns, log2", "conditionally-available": false, diff --git a/ext/vpx/gstvp9enc.c b/ext/vpx/gstvp9enc.c index 4ac8ffa4b3..47fe47f5f6 100644 --- a/ext/vpx/gstvp9enc.c +++ b/ext/vpx/gstvp9enc.c @@ -70,11 +70,14 @@ GST_DEBUG_CATEGORY_STATIC (gst_vp9enc_debug); #define DEFAULT_TILE_COLUMNS 6 #define DEFAULT_TILE_ROWS 0 +#define DEFAULT_ROW_MT 0 + enum { PROP_0, PROP_TILE_COLUMNS, PROP_TILE_ROWS, + PROP_ROW_MT, }; /* FIXME: Y42B do not work yet it seems */ @@ -157,6 +160,19 @@ gst_vp9_enc_class_init (GstVP9EncClass * klass) 0, 2, DEFAULT_TILE_ROWS, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); + /** + * GstVP9Enc:row-mt: + * + * Whether each row should be encoded using multiple threads + * + * Since: 1.20 + */ + g_object_class_install_property (gobject_class, PROP_ROW_MT, + g_param_spec_boolean ("row-mt", "Row Multithreading", + "Whether each row should be encoded using multiple threads", + DEFAULT_ROW_MT, + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); + gst_element_class_add_static_pad_template (element_class, &gst_vp9_enc_src_template); gst_element_class_add_static_pad_template (element_class, @@ -204,6 +220,7 @@ gst_vp9_enc_init (GstVP9Enc * gst_vp9_enc) gst_vp9_enc->tile_columns = DEFAULT_TILE_COLUMNS; gst_vp9_enc->tile_rows = DEFAULT_TILE_ROWS; + gst_vp9_enc->row_mt = DEFAULT_ROW_MT; } static void @@ -243,6 +260,18 @@ gst_vp9_enc_set_property (GObject * object, guint prop_id, } } break; + case PROP_ROW_MT: + gst_vp9_enc->row_mt = g_value_get_boolean (value); + if (gst_vpx_enc->inited) { + status = + vpx_codec_control (&gst_vpx_enc->encoder, VP9E_SET_ROW_MT, + gst_vp9_enc->row_mt ? 1 : 0); + if (status != VPX_CODEC_OK) { + GST_WARNING_OBJECT (gst_vpx_enc, + "Failed to set VP9E_SET_ROW_MT: %s", gst_vpx_error_name (status)); + } + } + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -267,6 +296,9 @@ gst_vp9_enc_get_property (GObject * object, guint prop_id, GValue * value, case PROP_TILE_ROWS: g_value_set_int (value, gst_vp9_enc->tile_rows); break; + case PROP_ROW_MT: + g_value_set_boolean (value, gst_vp9_enc->row_mt); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -296,6 +328,13 @@ gst_vp9_enc_configure_encoder (GstVPXEnc * encoder) GST_DEBUG_OBJECT (encoder, "Failed to set VP9E_SET_TILE_ROWS: %s", gst_vpx_error_name (status)); } + status = + vpx_codec_control (&encoder->encoder, VP9E_SET_ROW_MT, + vp9enc->row_mt ? 1 : 0); + if (status != VPX_CODEC_OK) { + GST_DEBUG_OBJECT (encoder, + "Failed to set VP9E_SET_ROW_MT: %s", gst_vpx_error_name (status)); + } return TRUE; } diff --git a/ext/vpx/gstvp9enc.h b/ext/vpx/gstvp9enc.h index c20a4d41d7..4e52336f60 100644 --- a/ext/vpx/gstvp9enc.h +++ b/ext/vpx/gstvp9enc.h @@ -47,6 +47,9 @@ struct _GstVP9Enc guint tile_columns; guint tile_rows; +#ifdef VPX_CTRL_VP9E_SET_ROW_MT + gboolean row_mt; +#endif }; G_END_DECLS diff --git a/ext/vpx/meson.build b/ext/vpx/meson.build index 349915cdc7..bedaff03cb 100644 --- a/ext/vpx/meson.build +++ b/ext/vpx/meson.build @@ -17,7 +17,7 @@ vpx_features = [ ] vpx_option = get_option('vpx') -vpx_dep = dependency('vpx', version : '>=1.5.0', required : vpx_option) +vpx_dep = dependency('vpx', version : '>=1.7.0', required : vpx_option) if vpx_dep.found() vpx_args = []