mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-06 14:32:31 +00:00
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
This commit is contained in:
parent
a072101441
commit
0e34c02dd6
1 changed files with 12 additions and 0 deletions
|
@ -70,6 +70,11 @@ enum
|
||||||
PROP_DEVICE_ID,
|
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
|
#if HAVE_NVENC_GST_GL
|
||||||
struct gl_input_resource
|
struct gl_input_resource
|
||||||
{
|
{
|
||||||
|
@ -878,10 +883,14 @@ gst_nv_base_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
|
||||||
NVENCSTATUS nv_ret;
|
NVENCSTATUS nv_ret;
|
||||||
|
|
||||||
g_assert (nvenc_class->initialize_encoder);
|
g_assert (nvenc_class->initialize_encoder);
|
||||||
|
|
||||||
|
G_LOCK (initialization_lock);
|
||||||
if (!nvenc_class->initialize_encoder (nvenc, old_state, state)) {
|
if (!nvenc_class->initialize_encoder (nvenc, old_state, state)) {
|
||||||
GST_ERROR_OBJECT (enc, "Subclass failed to reconfigure encoder");
|
GST_ERROR_OBJECT (enc, "Subclass failed to reconfigure encoder");
|
||||||
|
G_UNLOCK (initialization_lock);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
G_UNLOCK (initialization_lock);
|
||||||
|
|
||||||
if (!nvenc->max_encode_width && !nvenc->max_encode_height) {
|
if (!nvenc->max_encode_width && !nvenc->max_encode_height) {
|
||||||
gst_nv_base_enc_set_max_encode_size (nvenc, GST_VIDEO_INFO_WIDTH (info),
|
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.size = 1024 * 1024;
|
||||||
cout_buf.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
|
cout_buf.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
|
||||||
|
|
||||||
|
G_LOCK (initialization_lock);
|
||||||
nv_ret = NvEncCreateBitstreamBuffer (nvenc->encoder, &cout_buf);
|
nv_ret = NvEncCreateBitstreamBuffer (nvenc->encoder, &cout_buf);
|
||||||
|
G_UNLOCK (initialization_lock);
|
||||||
|
|
||||||
if (nv_ret != NV_ENC_SUCCESS) {
|
if (nv_ret != NV_ENC_SUCCESS) {
|
||||||
GST_WARNING_OBJECT (enc, "Failed to allocate input buffer: %d", nv_ret);
|
GST_WARNING_OBJECT (enc, "Failed to allocate input buffer: %d", nv_ret);
|
||||||
/* FIXME: clean up */
|
/* FIXME: clean up */
|
||||||
|
|
Loading…
Reference in a new issue