summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2018-02-14 17:20:02 +0100
committerTim-Philipp Müller <tim@centricular.com>2018-02-21 11:24:52 +0000
commit2d3816fabc2d0951d814fa312895799116e94693 (patch)
treea624bfdac98d0c07e3e3190d739c18840b9a7de1
parent412df8c74f29992ff93ab88f6d7b7625ebcc8193 (diff)
downloadgst-omx-2d3816fabc2d0951d814fa312895799116e94693.tar.gz
omxvideoenc: protect target_bitrate with the object lock
The 'target-bitrate' property can be changed while PLAYING (GST_PARAM_MUTABLE_PLAYING). Make it thread-safe to prevent concurrent accesses between the application and streaming thread. https://bugzilla.gnome.org/show_bug.cgi?id=793458
-rw-r--r--omx/gstomxvideoenc.c9
-rw-r--r--omx/gstomxvideoenc.h2
2 files changed, 10 insertions, 1 deletions
diff --git a/omx/gstomxvideoenc.c b/omx/gstomxvideoenc.c
index 3e295ff..941f00e 100644
--- a/omx/gstomxvideoenc.c
+++ b/omx/gstomxvideoenc.c
@@ -757,6 +757,7 @@ gst_omx_video_enc_open (GstVideoEncoder * encoder)
{
OMX_ERRORTYPE err;
+ GST_OBJECT_LOCK (self);
if (self->control_rate != 0xffffffff || self->target_bitrate != 0xffffffff) {
OMX_VIDEO_PARAM_BITRATETYPE bitrate_param;
@@ -793,6 +794,7 @@ gst_omx_video_enc_open (GstVideoEncoder * encoder)
GST_ERROR_OBJECT (self,
"Failed to set bitrate parameters: %s (0x%08x)",
gst_omx_error_to_string (err), err);
+ GST_OBJECT_UNLOCK (self);
return FALSE;
}
} else {
@@ -800,6 +802,7 @@ gst_omx_video_enc_open (GstVideoEncoder * encoder)
gst_omx_error_to_string (err), err);
}
}
+ GST_OBJECT_UNLOCK (self);
if (self->quant_i_frames != 0xffffffff ||
self->quant_p_frames != 0xffffffff ||
@@ -919,6 +922,7 @@ gst_omx_video_enc_set_property (GObject * object, guint prop_id,
self->control_rate = g_value_get_enum (value);
break;
case PROP_TARGET_BITRATE:
+ GST_OBJECT_LOCK (self);
self->target_bitrate = g_value_get_uint (value);
if (self->enc) {
OMX_VIDEO_CONFIG_BITRATETYPE config;
@@ -935,6 +939,7 @@ gst_omx_video_enc_set_property (GObject * object, guint prop_id,
"Failed to set bitrate parameter: %s (0x%08x)",
gst_omx_error_to_string (err), err);
}
+ GST_OBJECT_UNLOCK (self);
break;
case PROP_QUANT_I_FRAMES:
self->quant_i_frames = g_value_get_uint (value);
@@ -1009,7 +1014,9 @@ gst_omx_video_enc_get_property (GObject * object, guint prop_id, GValue * value,
g_value_set_enum (value, self->control_rate);
break;
case PROP_TARGET_BITRATE:
+ GST_OBJECT_LOCK (self);
g_value_set_uint (value, self->target_bitrate);
+ GST_OBJECT_UNLOCK (self);
break;
case PROP_QUANT_I_FRAMES:
g_value_set_uint (value, self->quant_i_frames);
@@ -2130,6 +2137,7 @@ gst_omx_video_enc_set_format (GstVideoEncoder * encoder,
NULL) != OMX_ErrorNone)
return FALSE;
+ GST_OBJECT_LOCK (self);
if (self->target_bitrate != 0xffffffff) {
OMX_VIDEO_PARAM_BITRATETYPE config;
OMX_ERRORTYPE err;
@@ -2144,6 +2152,7 @@ gst_omx_video_enc_set_format (GstVideoEncoder * encoder,
GST_ERROR_OBJECT (self, "Failed to set bitrate parameter: %s (0x%08x)",
gst_omx_error_to_string (err), err);
}
+ GST_OBJECT_UNLOCK (self);
if (self->input_state)
gst_video_codec_state_unref (self->input_state);
diff --git a/omx/gstomxvideoenc.h b/omx/gstomxvideoenc.h
index 5c5d3c4..3a5f2cf 100644
--- a/omx/gstomxvideoenc.h
+++ b/omx/gstomxvideoenc.h
@@ -71,7 +71,7 @@ struct _GstOMXVideoEnc
/* properties */
guint32 control_rate;
- guint32 target_bitrate;
+ guint32 target_bitrate; /* protected by object lock */
guint32 quant_i_frames;
guint32 quant_p_frames;
guint32 quant_b_frames;