summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Marsh <matt@stonethree.com>2015-12-22 11:10:31 +0200
committerTim-Philipp Müller <tim@centricular.com>2015-12-22 13:27:51 +0000
commit0e34c02dd60f8d301a1b4c1bbcd3c90ee05bdb0a (patch)
tree9d59353701b9eb1146341449f13c530e585f9179
parenta072101441a648ccd315a3ed8212071404bacc55 (diff)
downloadgstreamer-plugins-bad-0e34c02dd60f8d301a1b4c1bbcd3c90ee05bdb0a.tar.gz
nvenc: fix high CPU use on initialization of multiple encoders at the same time
We need a static lock to protect various NVENC methods in _set_format(). Without this the CPU use increases dramatically on initialisation of the element when there are multiple elements being initialised at the same time. https://bugzilla.gnome.org/show_bug.cgi?id=759742
-rw-r--r--sys/nvenc/gstnvbaseenc.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/sys/nvenc/gstnvbaseenc.c b/sys/nvenc/gstnvbaseenc.c
index ccf7186a9..8e5b08826 100644
--- a/sys/nvenc/gstnvbaseenc.c
+++ b/sys/nvenc/gstnvbaseenc.c
@@ -70,6 +70,11 @@ enum
PROP_DEVICE_ID,
};
+/* This lock is needed to prevent the situation where multiple encoders are
+ * initialised at the same time which appears to cause excessive CPU usage over
+ * some period of time. */
+G_LOCK_DEFINE_STATIC (initialization_lock);
+
#if HAVE_NVENC_GST_GL
struct gl_input_resource
{
@@ -878,10 +883,14 @@ gst_nv_base_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
NVENCSTATUS nv_ret;
g_assert (nvenc_class->initialize_encoder);
+
+ G_LOCK (initialization_lock);
if (!nvenc_class->initialize_encoder (nvenc, old_state, state)) {
GST_ERROR_OBJECT (enc, "Subclass failed to reconfigure encoder");
+ G_UNLOCK (initialization_lock);
return FALSE;
}
+ G_UNLOCK (initialization_lock);
if (!nvenc->max_encode_width && !nvenc->max_encode_height) {
gst_nv_base_enc_set_max_encode_size (nvenc, GST_VIDEO_INFO_WIDTH (info),
@@ -1020,7 +1029,10 @@ gst_nv_base_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
cout_buf.size = 1024 * 1024;
cout_buf.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
+ G_LOCK (initialization_lock);
nv_ret = NvEncCreateBitstreamBuffer (nvenc->encoder, &cout_buf);
+ G_UNLOCK (initialization_lock);
+
if (nv_ret != NV_ENC_SUCCESS) {
GST_WARNING_OBJECT (enc, "Failed to allocate input buffer: %d", nv_ret);
/* FIXME: clean up */