Work around deprecated thread API in glib master

Add private replacements for deprecated functions such as
g_mutex_new(), g_mutex_free(), g_cond_new() etc., mostly
to avoid the deprecation warnings. We'll change these
over to the new API once we depend on glib >= 2.32.

Replace g_thread_create() with g_thread_try_new().
This commit is contained in:
Tim-Philipp Müller 2011-12-04 16:43:38 +00:00
parent 6098442bd0
commit 0d98aa25b8
29 changed files with 206 additions and 19 deletions

View file

@ -26,6 +26,8 @@
#include "gstalsadeviceprobe.h"
#include "gst/interfaces/propertyprobe.h"
G_LOCK_DEFINE_STATIC (probe_lock);
static const GList *
gst_alsa_device_property_probe_get_properties (GstPropertyProbe * probe)
{
@ -34,7 +36,7 @@ gst_alsa_device_property_probe_get_properties (GstPropertyProbe * probe)
/* well, not perfect, but better than no locking at all.
* In the worst case we leak a list node, so who cares? */
GST_CLASS_LOCK (GST_OBJECT_CLASS (klass));
G_LOCK (probe_lock);
if (!list) {
GParamSpec *pspec;
@ -43,7 +45,7 @@ gst_alsa_device_property_probe_get_properties (GstPropertyProbe * probe)
list = g_list_append (NULL, pspec);
}
GST_CLASS_UNLOCK (GST_OBJECT_CLASS (klass));
G_UNLOCK (probe_lock);
return list;
}

View file

@ -35,6 +35,7 @@
#endif
#include "gstalsamixer.h"
#include "gst/glib-compat-private.h"
#include <errno.h>
static void gst_alsa_mixer_update_option (GstAlsaMixer * mixer,

View file

@ -52,6 +52,7 @@
#include "gstalsadeviceprobe.h"
#include <gst/gst-i18n-plugin.h>
#include "gst/glib-compat-private.h"
#define DEFAULT_DEVICE "default"
#define DEFAULT_DEVICE_NAME ""

View file

@ -48,6 +48,7 @@
#include "gstalsasrc.h"
#include "gstalsadeviceprobe.h"
#include "gst/glib-compat-private.h"
#include <gst/gst-i18n-plugin.h>

View file

@ -45,6 +45,8 @@
#include "gstoggdemux.h"
#include "gst/glib-compat-private.h"
#define CHUNKSIZE (8500) /* this is out of vorbisfile */
/* we hope we get a granpos within this many bytes off the end */

View file

@ -92,6 +92,8 @@
#include "gsttextrender.h"
#include <string.h>
#include "gst/glib-compat-private.h"
/* FIXME:
* - use proper strides and offset for I420
* - if text is wider than the video picture, it does not get

View file

@ -18,7 +18,7 @@ SUBDIRS = \
riff \
app
noinst_HEADERS = gettext.h gst-i18n-plugin.h
noinst_HEADERS = gettext.h gst-i18n-plugin.h glib-compat-private.h
# dependencies:
audio: interfaces pbutils

View file

@ -76,6 +76,8 @@
#include "gstappsink.h"
#include "gst/glib-compat-private.h"
struct _GstAppSinkPrivate
{
GstCaps *caps;

View file

@ -102,6 +102,8 @@
#include "gstapp-marshal.h"
#include "gstappsrc.h"
#include "gst/glib-compat-private.h"
struct _GstAppSrcPrivate
{
GCond *cond;

View file

@ -71,6 +71,8 @@
#include "gstaudiosink.h"
#include "gst/glib-compat-private.h"
GST_DEBUG_CATEGORY_STATIC (gst_audio_sink_debug);
#define GST_CAT_DEFAULT gst_audio_sink_debug
@ -426,9 +428,16 @@ gst_audioringbuffer_activate (GstRingBuffer * buf, gboolean active)
abuf->running = TRUE;
GST_DEBUG_OBJECT (sink, "starting thread");
#if !GLIB_CHECK_VERSION (2, 31, 0)
sink->thread =
g_thread_create ((GThreadFunc) audioringbuffer_thread_func, buf, TRUE,
&error);
#else
sink->thread = g_thread_try_new ("audiosink-ringbuffer",
(GThreadFunc) audioringbuffer_thread_func, buf, &error);
#endif
if (!sink->thread || error != NULL)
goto thread_failed;

View file

@ -71,6 +71,8 @@
#include "gstaudiosrc.h"
#include "gst/glib-compat-private.h"
GST_DEBUG_CATEGORY_STATIC (gst_audio_src_debug);
#define GST_CAT_DEFAULT gst_audio_src_debug
@ -382,9 +384,16 @@ gst_audioringbuffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec)
abuf = GST_AUDIORING_BUFFER (buf);
abuf->running = TRUE;
/* FIXME: handle thread creation failure */
#if !GLIB_CHECK_VERSION (2, 31, 0)
src->thread =
g_thread_create ((GThreadFunc) audioringbuffer_thread_func, buf, TRUE,
NULL);
#else
src->thread = g_thread_try_new ("audiosrc-ringbuffer",
(GThreadFunc) audioringbuffer_thread_func, buf, NULL);
#endif
GST_AUDIORING_BUFFER_WAIT (buf);
return result;

View file

@ -43,6 +43,8 @@
#include "gstringbuffer.h"
#include "gst/glib-compat-private.h"
GST_DEBUG_CATEGORY_STATIC (gst_ring_buffer_debug);
#define GST_CAT_DEFAULT gst_ring_buffer_debug

View file

@ -0,0 +1,120 @@
/*
* glib-compat.c
* Functions copied from glib 2.10
*
* Copyright 2005 David Schleef <ds@schleef.org>
*/
#ifndef __GLIB_COMPAT_PRIVATE_H__
#define __GLIB_COMPAT_PRIVATE_H__
#include <glib.h>
G_BEGIN_DECLS
#if !GLIB_CHECK_VERSION(2,25,0)
#if defined (_MSC_VER) && !defined(_WIN64)
typedef struct _stat32 GStatBuf;
#else
typedef struct stat GStatBuf;
#endif
#endif
#if GLIB_CHECK_VERSION(2,26,0)
#define GLIB_HAS_GDATETIME
#endif
/* See bug #651514 */
#if GLIB_CHECK_VERSION(2,29,5)
#define G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE(a,b,c) \
g_atomic_pointer_compare_and_exchange ((a),(b),(c))
#define G_ATOMIC_INT_COMPARE_AND_EXCHANGE(a,b,c) \
g_atomic_int_compare_and_exchange ((a),(b),(c))
#else
#define G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE(a,b,c) \
g_atomic_pointer_compare_and_exchange ((volatile gpointer *)(a),(b),(c))
#define G_ATOMIC_INT_COMPARE_AND_EXCHANGE(a,b,c) \
g_atomic_int_compare_and_exchange ((volatile int *)(a),(b),(c))
#endif
/* See bug #651514 */
#if GLIB_CHECK_VERSION(2,29,5)
#define G_ATOMIC_INT_ADD(a,b) g_atomic_int_add ((a),(b))
#else
#define G_ATOMIC_INT_ADD(a,b) g_atomic_int_exchange_and_add ((a),(b))
#endif
/* copies */
#if GLIB_CHECK_VERSION (2, 31, 0)
#define g_mutex_new gst_g_mutex_new
static inline GMutex *
gst_g_mutex_new (void)
{
GMutex *mutex = g_slice_new (GMutex);
g_mutex_init (mutex);
return mutex;
}
#define g_mutex_free gst_g_mutex_free
static inline void
gst_g_mutex_free (GMutex *mutex)
{
g_mutex_clear (mutex);
g_slice_free (GMutex, mutex);
}
#define g_static_rec_mutex_init gst_g_static_rec_mutex_init
static inline void
gst_g_static_rec_mutex_init (GStaticRecMutex *mutex)
{
static const GStaticRecMutex init_mutex = G_STATIC_REC_MUTEX_INIT;
*mutex = init_mutex;
}
#define g_cond_new gst_g_cond_new
static inline GCond *
gst_g_cond_new (void)
{
GCond *cond = g_slice_new (GCond);
g_cond_init (cond);
return cond;
}
#define g_cond_free gst_g_cond_free
static inline void
gst_g_cond_free (GCond *cond)
{
g_cond_clear (cond);
g_slice_free (GCond, cond);
}
#define g_cond_timed_wait gst_g_cond_timed_wait
static inline gboolean
gst_g_cond_timed_wait (GCond *cond, GMutex *mutex, GTimeVal *abs_time)
{
gint64 end_time;
if (abs_time == NULL) {
g_cond_wait (cond, mutex);
return TRUE;
}
end_time = abs_time->tv_sec;
end_time *= 1000000;
end_time += abs_time->tv_usec;
/* would be nice if we had clock_rtoffset, but that didn't seem to
* make it into the kernel yet...
*/
/* if CLOCK_MONOTONIC is not defined then g_get_montonic_time() and
* g_get_real_time() are returning the same clock and we'd add ~0
*/
end_time += g_get_monotonic_time () - g_get_real_time ();
return g_cond_wait_until (cond, mutex, end_time);
}
#endif /* GLIB_CHECK_VERSION (2, 31, 0) */
/* adaptations */
G_END_DECLS
#endif

View file

@ -48,6 +48,8 @@
#include "pbutils-marshal.h"
#include "pbutils-private.h"
#include "gst/glib-compat-private.h"
GST_DEBUG_CATEGORY_STATIC (discoverer_debug);
#define GST_CAT_DEFAULT discoverer_debug

View file

@ -93,6 +93,8 @@
#include "gstrtspconnection.h"
#include "gstrtspbase64.h"
#include "gst/glib-compat-private.h"
union gst_sockaddr
{
struct sockaddr sa;

View file

@ -22,6 +22,8 @@
#include <string.h>
#include "video.h"
#include "gst/glib-compat-private.h"
static gboolean
caps_are_raw (const GstCaps * caps)
{

View file

@ -23,6 +23,7 @@
#endif
#include "gststreamcombiner.h"
#include "gst/glib-compat-private.h"
static GstStaticPadTemplate src_template =
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
@ -62,10 +63,8 @@ gst_stream_combiner_class_init (GstStreamCombinerClass * klass)
GST_DEBUG_CATEGORY_INIT (gst_stream_combiner_debug, "streamcombiner", 0,
"Stream Combiner");
gst_element_class_add_static_pad_template (gstelement_klass,
&src_template);
gst_element_class_add_static_pad_template (gstelement_klass,
&sink_template);
gst_element_class_add_static_pad_template (gstelement_klass, &src_template);
gst_element_class_add_static_pad_template (gstelement_klass, &sink_template);
gstelement_klass->request_new_pad =
GST_DEBUG_FUNCPTR (gst_stream_combiner_request_new_pad);

View file

@ -23,6 +23,7 @@
#endif
#include "gststreamsplitter.h"
#include "gst/glib-compat-private.h"
static GstStaticPadTemplate src_template =
GST_STATIC_PAD_TEMPLATE ("src_%d", GST_PAD_SRC, GST_PAD_REQUEST,
@ -62,10 +63,8 @@ gst_stream_splitter_class_init (GstStreamSplitterClass * klass)
GST_DEBUG_CATEGORY_INIT (gst_stream_splitter_debug, "streamsplitter", 0,
"Stream Splitter");
gst_element_class_add_static_pad_template (gstelement_klass,
&src_template);
gst_element_class_add_static_pad_template (gstelement_klass,
&sink_template);
gst_element_class_add_static_pad_template (gstelement_klass, &src_template);
gst_element_class_add_static_pad_template (gstelement_klass, &sink_template);
gstelement_klass->request_new_pad =
GST_DEBUG_FUNCPTR (gst_stream_splitter_request_new_pad);

View file

@ -45,6 +45,7 @@
#include <string.h>
#include <gst/gst.h>
#include <gst/pbutils/pbutils.h>
#include "gst/glib-compat-private.h"
#include "gstplay-marshal.h"

View file

@ -96,6 +96,8 @@
#include "gstplayback.h"
#include "gstrawcaps.h"
#include "gst/glib-compat-private.h"
/* generic templates */
static GstStaticPadTemplate decoder_bin_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",

View file

@ -29,6 +29,8 @@
#include <gst/pbutils/pbutils.h>
#include "gst/glib-compat-private.h"
GST_DEBUG_CATEGORY_STATIC (gst_play_base_bin_debug);
#define GST_CAT_DEFAULT gst_play_base_bin_debug

View file

@ -233,6 +233,8 @@
#include "gstplaysink.h"
#include "gstsubtitleoverlay.h"
#include "gst/glib-compat-private.h"
GST_DEBUG_CATEGORY_STATIC (gst_play_bin_debug);
#define GST_CAT_DEFAULT gst_play_bin_debug

View file

@ -26,6 +26,7 @@
#include <gst/pbutils/pbutils.h>
#include <gst/gst-i18n-plugin.h>
#include "gst/glib-compat-private.h"
GST_DEBUG_CATEGORY_STATIC (gst_play_sink_convert_bin_debug);
#define GST_CAT_DEFAULT gst_play_sink_convert_bin_debug

View file

@ -22,6 +22,7 @@
#endif
#include "gststreamsynchronizer.h"
#include "gst/glib-compat-private.h"
GST_DEBUG_CATEGORY_STATIC (stream_synchronizer_debug);
#define GST_CAT_DEFAULT stream_synchronizer_debug
@ -955,10 +956,8 @@ gst_stream_synchronizer_base_init (gpointer g_class)
{
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_static_pad_template (gstelement_class,
&srctemplate);
gst_element_class_add_static_pad_template (gstelement_class,
&sinktemplate);
gst_element_class_add_static_pad_template (gstelement_class, &srctemplate);
gst_element_class_add_static_pad_template (gstelement_class, &sinktemplate);
gst_element_class_set_details_simple (gstelement_class,
"Stream Synchronizer", "Generic",

View file

@ -45,6 +45,8 @@
#include <gst/video/video.h>
#include <string.h>
#include "gst/glib-compat-private.h"
GST_DEBUG_CATEGORY_STATIC (subtitle_overlay_debug);
#define GST_CAT_DEFAULT subtitle_overlay_debug
@ -1617,8 +1619,7 @@ gst_subtitle_overlay_base_init (gpointer g_class)
{
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_static_pad_template (gstelement_class,
&srctemplate);
gst_element_class_add_static_pad_template (gstelement_class, &srctemplate);
gst_element_class_add_static_pad_template (gstelement_class,
&video_sinktemplate);

View file

@ -38,6 +38,8 @@
#include "gstplay-enum.h"
#include "gstrawcaps.h"
#include "gst/glib-compat-private.h"
#define GST_TYPE_URI_DECODE_BIN \
(gst_uri_decode_bin_get_type())
#define GST_URI_DECODE_BIN(obj) \
@ -213,8 +215,7 @@ gst_uri_decode_bin_base_init (gpointer g_class)
{
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_static_pad_template (gstelement_class,
&srctemplate);
gst_element_class_add_static_pad_template (gstelement_class, &srctemplate);
gst_element_class_set_details_simple (gstelement_class,
"URI Decoder", "Generic/Bin/Decoder",
"Autoplug and decode an URI to raw media",

View file

@ -2883,8 +2883,14 @@ gst_multi_fd_sink_start (GstBaseSink * bsink)
}
this->running = TRUE;
#if !GLIB_CHECK_VERSION (2, 31, 0)
this->thread = g_thread_create ((GThreadFunc) gst_multi_fd_sink_thread,
this, TRUE, NULL);
#else
this->thread = g_thread_new ("multifdsink",
(GThreadFunc) gst_multi_fd_sink_thread, this);
#endif
GST_OBJECT_FLAG_SET (this, GST_MULTI_FD_SINK_OPEN);

View file

@ -113,6 +113,8 @@
/* Debugging category */
#include <gst/gstinfo.h>
#include "gst/glib-compat-private.h"
GST_DEBUG_CATEGORY_EXTERN (gst_debug_ximagesink);
#define GST_CAT_DEFAULT gst_debug_ximagesink
@ -1171,8 +1173,13 @@ gst_ximagesink_manage_event_thread (GstXImageSink * ximagesink)
GST_DEBUG_OBJECT (ximagesink, "run xevent thread, expose %d, events %d",
ximagesink->handle_expose, ximagesink->handle_events);
ximagesink->running = TRUE;
#if !GLIB_CHECK_VERSION (2, 31, 0)
ximagesink->event_thread = g_thread_create (
(GThreadFunc) gst_ximagesink_event_thread, ximagesink, TRUE, NULL);
#else
ximagesink->event_thread = g_thread_try_new ("ximagesink-events",
(GThreadFunc) gst_ximagesink_event_thread, ximagesink, NULL);
#endif
}
} else {
if (ximagesink->event_thread) {

View file

@ -126,6 +126,9 @@
/* Debugging category */
#include <gst/gstinfo.h>
#include "gst/glib-compat-private.h"
GST_DEBUG_CATEGORY_STATIC (gst_debug_xvimagesink);
#define GST_CAT_DEFAULT gst_debug_xvimagesink
GST_DEBUG_CATEGORY_STATIC (GST_CAT_PERFORMANCE);
@ -1685,8 +1688,13 @@ gst_xvimagesink_manage_event_thread (GstXvImageSink * xvimagesink)
GST_DEBUG_OBJECT (xvimagesink, "run xevent thread, expose %d, events %d",
xvimagesink->handle_expose, xvimagesink->handle_events);
xvimagesink->running = TRUE;
#if !GLIB_CHECK_VERSION (2, 31, 0)
xvimagesink->event_thread = g_thread_create (
(GThreadFunc) gst_xvimagesink_event_thread, xvimagesink, TRUE, NULL);
#else
xvimagesink->event_thread = g_thread_try_new ("xvimagesink-events",
(GThreadFunc) gst_xvimagesink_event_thread, xvimagesink, NULL);
#endif
}
} else {
if (xvimagesink->event_thread) {