Work around deprecated thread API in glib master
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 4 Dec 2011 16:43:38 +0000 (16:43 +0000)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 4 Dec 2011 17:16:30 +0000 (17:16 +0000)
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().

29 files changed:
ext/alsa/gstalsadeviceprobe.c
ext/alsa/gstalsamixer.c
ext/alsa/gstalsasink.c
ext/alsa/gstalsasrc.c
ext/ogg/gstoggdemux.c
ext/pango/gsttextoverlay.c
gst-libs/gst/Makefile.am
gst-libs/gst/app/gstappsink.c
gst-libs/gst/app/gstappsrc.c
gst-libs/gst/audio/gstaudiosink.c
gst-libs/gst/audio/gstaudiosrc.c
gst-libs/gst/audio/gstringbuffer.c
gst-libs/gst/glib-compat-private.h [new file with mode: 0644]
gst-libs/gst/pbutils/gstdiscoverer.c
gst-libs/gst/rtsp/gstrtspconnection.c
gst-libs/gst/video/convertframe.c
gst/encoding/gststreamcombiner.c
gst/encoding/gststreamsplitter.c
gst/playback/gstdecodebin.c
gst/playback/gstdecodebin2.c
gst/playback/gstplaybasebin.c
gst/playback/gstplaybin2.c
gst/playback/gstplaysinkconvertbin.c
gst/playback/gststreamsynchronizer.c
gst/playback/gstsubtitleoverlay.c
gst/playback/gsturidecodebin.c
gst/tcp/gstmultifdsink.c
sys/ximage/ximagesink.c
sys/xvimage/xvimagesink.c

index 83596a3..4b22d34 100644 (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;
 }
index 46c10c4..84e0654 100644 (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,
index a878b5e..24b1d8a 100644 (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    ""
index 1a99a68..917f0dc 100644 (file)
@@ -48,6 +48,7 @@
 
 #include "gstalsasrc.h"
 #include "gstalsadeviceprobe.h"
+#include "gst/glib-compat-private.h"
 
 #include <gst/gst-i18n-plugin.h>
 
index 6e924f9..ba5fc20 100644 (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 */
index 6abff7d..76b8f74 100644 (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
index 6f261b3..0984251 100644 (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
index a1a20a5..9a891b6 100644 (file)
@@ -76,6 +76,8 @@
 
 #include "gstappsink.h"
 
+#include "gst/glib-compat-private.h"
+
 struct _GstAppSinkPrivate
 {
   GstCaps *caps;
index 6ae59e5..543a2ad 100644 (file)
 #include "gstapp-marshal.h"
 #include "gstappsrc.h"
 
+#include "gst/glib-compat-private.h"
+
 struct _GstAppSrcPrivate
 {
   GCond *cond;
index ac39cb1..c5fec73 100644 (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;
 
index d7a6b54..004153e 100644 (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;
index ab1880c..5069304 100644 (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
 
diff --git a/gst-libs/gst/glib-compat-private.h b/gst-libs/gst/glib-compat-private.h
new file mode 100644 (file)
index 0000000..d143d32
--- /dev/null
@@ -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
index bce956e..6af71dc 100644 (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
 
index da39c21..5fcfa25 100644 (file)
@@ -93,6 +93,8 @@
 #include "gstrtspconnection.h"
 #include "gstrtspbase64.h"
 
+#include "gst/glib-compat-private.h"
+
 union gst_sockaddr
 {
   struct sockaddr sa;
index 58dc426..756ce71 100644 (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)
 {
index 7328695..c601cf8 100644 (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);
index 9221b35..8c568a9 100644 (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);
index 7ce222f..771a1db 100644 (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"
 
index 45ff2b1..187221e 100644 (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",
index 2d26aad..7ab2c29 100644 (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
 
index 9f86e3e..f9478e2 100644 (file)
 #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
 
index d05f2ac..51ede9b 100644 (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
index 594b4b2..c6c53db 100644 (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",
index 2828a8c..8ca5184 100644 (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);
index e0660b5..2a5026f 100644 (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",
index 912c273..a52dabd 100644 (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);
 
index 7e5cb1a..2adcc73 100644 (file)
 /* 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) {
index d0cc4a8..8a7913b 100644 (file)
 
 /* 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) {