mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-07-18 04:18:20 +00:00
vaapidecode: adopt non-deprecrated glib locking primitive pattern.
The use of heap allocated GMutex/GCond is deprecated. Instead place them inside the structure they are locking. These changes switch to use g_mutex_init/g_cond_init rather than the heap allocation functions. Because we cannot test for a NULL pointer for the GMutex/GCond we must initialise inside the GObject _init function and clear inside the _finalize which is guaranteed to only be called once and after the object is no longer in use.
This commit is contained in:
parent
7d1b583d91
commit
4bcfa3fe0a
|
@ -173,12 +173,9 @@ gst_vaapidecode_update_src_caps(GstVaapiDecode *decode, GstCaps *caps)
|
|||
static void
|
||||
gst_vaapidecode_release(GstVaapiDecode *decode, GObject *dead_object)
|
||||
{
|
||||
if (!decode->decoder_mutex || !decode->decoder_ready)
|
||||
return;
|
||||
|
||||
g_mutex_lock(decode->decoder_mutex);
|
||||
g_cond_signal(decode->decoder_ready);
|
||||
g_mutex_unlock(decode->decoder_mutex);
|
||||
g_mutex_lock(&decode->decoder_mutex);
|
||||
g_cond_signal(&decode->decoder_ready);
|
||||
g_mutex_unlock(&decode->decoder_mutex);
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
|
@ -202,13 +199,13 @@ gst_vaapidecode_step(GstVaapiDecode *decode)
|
|||
if (!proxy) {
|
||||
if (status == GST_VAAPI_DECODER_STATUS_ERROR_NO_SURFACE) {
|
||||
gboolean was_signalled;
|
||||
g_mutex_lock(decode->decoder_mutex);
|
||||
g_mutex_lock(&decode->decoder_mutex);
|
||||
was_signalled = g_cond_wait_until(
|
||||
decode->decoder_ready,
|
||||
decode->decoder_mutex,
|
||||
&decode->decoder_ready,
|
||||
&decode->decoder_mutex,
|
||||
end_time
|
||||
);
|
||||
g_mutex_unlock(decode->decoder_mutex);
|
||||
g_mutex_unlock(&decode->decoder_mutex);
|
||||
if (was_signalled)
|
||||
continue;
|
||||
goto error_decode_timeout;
|
||||
|
@ -317,14 +314,6 @@ gst_vaapidecode_create(GstVaapiDecode *decode, GstCaps *caps)
|
|||
return FALSE;
|
||||
dpy = decode->display;
|
||||
|
||||
decode->decoder_mutex = g_mutex_new();
|
||||
if (!decode->decoder_mutex)
|
||||
return FALSE;
|
||||
|
||||
decode->decoder_ready = g_cond_new();
|
||||
if (!decode->decoder_ready)
|
||||
return FALSE;
|
||||
|
||||
switch (gst_vaapi_codec_from_caps(caps)) {
|
||||
case GST_VAAPI_CODEC_MPEG2:
|
||||
decode->decoder = gst_vaapi_decoder_mpeg2_new(dpy, caps);
|
||||
|
@ -377,16 +366,7 @@ gst_vaapidecode_destroy(GstVaapiDecode *decode)
|
|||
decode->decoder_caps = NULL;
|
||||
}
|
||||
|
||||
if (decode->decoder_ready) {
|
||||
gst_vaapidecode_release(decode, NULL);
|
||||
g_cond_free(decode->decoder_ready);
|
||||
decode->decoder_ready = NULL;
|
||||
}
|
||||
|
||||
if (decode->decoder_mutex) {
|
||||
g_mutex_free(decode->decoder_mutex);
|
||||
decode->decoder_mutex = NULL;
|
||||
}
|
||||
gst_vaapidecode_release(decode, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -481,6 +461,9 @@ gst_vaapidecode_finalize(GObject *object)
|
|||
decode->delayed_new_seg = NULL;
|
||||
}
|
||||
|
||||
g_cond_clear(&decode->decoder_ready);
|
||||
g_mutex_clear(&decode->decoder_mutex);
|
||||
|
||||
G_OBJECT_CLASS(gst_vaapidecode_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
|
@ -738,8 +721,6 @@ gst_vaapidecode_init(GstVaapiDecode *decode)
|
|||
|
||||
decode->display = NULL;
|
||||
decode->decoder = NULL;
|
||||
decode->decoder_mutex = NULL;
|
||||
decode->decoder_ready = NULL;
|
||||
decode->decoder_caps = NULL;
|
||||
decode->allowed_caps = NULL;
|
||||
decode->delayed_new_seg = NULL;
|
||||
|
@ -747,6 +728,9 @@ gst_vaapidecode_init(GstVaapiDecode *decode)
|
|||
decode->last_buffer_time = 0;
|
||||
decode->is_ready = FALSE;
|
||||
|
||||
g_mutex_init(&decode->decoder_mutex);
|
||||
g_cond_init(&decode->decoder_ready);
|
||||
|
||||
/* Pad through which data comes in to the element */
|
||||
decode->sinkpad = gst_pad_new_from_template(
|
||||
gst_element_class_get_pad_template(element_class, "sink"),
|
||||
|
|
|
@ -67,8 +67,8 @@ struct _GstVaapiDecode {
|
|||
GstCaps *srcpad_caps;
|
||||
GstVaapiDisplay *display;
|
||||
GstVaapiDecoder *decoder;
|
||||
GMutex *decoder_mutex;
|
||||
GCond *decoder_ready;
|
||||
GMutex decoder_mutex;
|
||||
GCond decoder_ready;
|
||||
GstCaps *decoder_caps;
|
||||
GstCaps *allowed_caps;
|
||||
GstEvent *delayed_new_seg;
|
||||
|
|
Loading…
Reference in a new issue