video: Update for g_type_class_add_private() deprecation in recent GLib
authorTim-Philipp Müller <tim@centricular.com>
Sat, 23 Jun 2018 19:33:16 +0000 (21:33 +0200)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 23 Jun 2018 19:59:13 +0000 (21:59 +0200)
https://gitlab.gnome.org/GNOME/glib/merge_requests/7

gst-libs/gst/video/gstvideodecoder.c
gst-libs/gst/video/gstvideoencoder.c
gst-libs/gst/video/gstvideopool.c
gst-libs/gst/video/gstvideosink.c

index 3b2daaa..8636c2f 100644 (file)
 GST_DEBUG_CATEGORY (videodecoder_debug);
 #define GST_CAT_DEFAULT videodecoder_debug
 
-#define GST_VIDEO_DECODER_GET_PRIVATE(obj)  \
-    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_VIDEO_DECODER, \
-        GstVideoDecoderPrivate))
-
 struct _GstVideoDecoderPrivate
 {
   /* FIXME introduce a context ? */
@@ -410,6 +406,8 @@ struct _GstVideoDecoderPrivate
 };
 
 static GstElementClass *parent_class = NULL;
+static gint private_offset = 0;
+
 static void gst_video_decoder_class_init (GstVideoDecoderClass * klass);
 static void gst_video_decoder_init (GstVideoDecoder * dec,
     GstVideoDecoderClass * klass);
@@ -493,11 +491,21 @@ gst_video_decoder_get_type (void)
 
     _type = g_type_register_static (GST_TYPE_ELEMENT,
         "GstVideoDecoder", &info, G_TYPE_FLAG_ABSTRACT);
+
+    private_offset =
+        g_type_add_instance_private (_type, sizeof (GstVideoDecoderPrivate));
+
     g_once_init_leave (&type, _type);
   }
   return type;
 }
 
+static inline GstVideoDecoderPrivate *
+gst_video_decoder_get_instance_private (GstVideoDecoder * self)
+{
+  return (G_STRUCT_MEMBER_P (self, private_offset));
+}
+
 static void
 gst_video_decoder_class_init (GstVideoDecoderClass * klass)
 {
@@ -511,7 +519,9 @@ gst_video_decoder_class_init (GstVideoDecoderClass * klass)
       "Base Video Decoder");
 
   parent_class = g_type_class_peek_parent (klass);
-  g_type_class_add_private (klass, sizeof (GstVideoDecoderPrivate));
+
+  if (private_offset != 0)
+    g_type_class_adjust_private_offset (klass, &private_offset);
 
   gobject_class->finalize = gst_video_decoder_finalize;
 
@@ -536,7 +546,7 @@ gst_video_decoder_init (GstVideoDecoder * decoder, GstVideoDecoderClass * klass)
 
   GST_DEBUG_OBJECT (decoder, "gst_video_decoder_init");
 
-  decoder->priv = GST_VIDEO_DECODER_GET_PRIVATE (decoder);
+  decoder->priv = gst_video_decoder_get_instance_private (decoder);
 
   pad_template =
       gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "sink");
index 2e40a91..dc59989 100644 (file)
 GST_DEBUG_CATEGORY (videoencoder_debug);
 #define GST_CAT_DEFAULT videoencoder_debug
 
-#define GST_VIDEO_ENCODER_GET_PRIVATE(obj)  \
-    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_VIDEO_ENCODER, \
-        GstVideoEncoderPrivate))
-
 /* properties */
 
 #define DEFAULT_QOS                 FALSE
@@ -211,6 +207,8 @@ forced_key_unit_event_new (GstClockTime running_time, gboolean all_headers,
 }
 
 static GstElementClass *parent_class = NULL;
+static gint private_offset = 0;
+
 static void gst_video_encoder_class_init (GstVideoEncoderClass * klass);
 static void gst_video_encoder_init (GstVideoEncoder * enc,
     GstVideoEncoderClass * klass);
@@ -285,6 +283,8 @@ gst_video_encoder_get_type (void)
 
     _type = g_type_register_static (GST_TYPE_ELEMENT,
         "GstVideoEncoder", &info, G_TYPE_FLAG_ABSTRACT);
+    private_offset =
+        g_type_add_instance_private (_type, sizeof (GstVideoEncoderPrivate));
     g_type_add_interface_static (_type, GST_TYPE_PRESET,
         &preset_interface_info);
     g_once_init_leave (&type, _type);
@@ -292,6 +292,12 @@ gst_video_encoder_get_type (void)
   return type;
 }
 
+static inline GstVideoEncoderPrivate *
+gst_video_encoder_get_instance_private (GstVideoEncoder * self)
+{
+  return (G_STRUCT_MEMBER_P (self, private_offset));
+}
+
 static void
 gst_video_encoder_set_property (GObject * object, guint prop_id,
     const GValue * value, GParamSpec * pspec)
@@ -338,7 +344,8 @@ gst_video_encoder_class_init (GstVideoEncoderClass * klass)
 
   parent_class = g_type_class_peek_parent (klass);
 
-  g_type_class_add_private (klass, sizeof (GstVideoEncoderPrivate));
+  if (private_offset != 0)
+    g_type_class_adjust_private_offset (klass, &private_offset);
 
   gobject_class->set_property = gst_video_encoder_set_property;
   gobject_class->get_property = gst_video_encoder_get_property;
@@ -491,7 +498,7 @@ gst_video_encoder_init (GstVideoEncoder * encoder, GstVideoEncoderClass * klass)
 
   GST_DEBUG_OBJECT (encoder, "gst_video_encoder_init");
 
-  priv = encoder->priv = GST_VIDEO_ENCODER_GET_PRIVATE (encoder);
+  priv = encoder->priv = gst_video_encoder_get_instance_private (encoder);
 
   pad_template =
       gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "sink");
index 671e657..1b919fd 100644 (file)
@@ -104,11 +104,9 @@ struct _GstVideoBufferPoolPrivate
 
 static void gst_video_buffer_pool_finalize (GObject * object);
 
-#define GST_VIDEO_BUFFER_POOL_GET_PRIVATE(obj)  \
-   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_VIDEO_BUFFER_POOL, GstVideoBufferPoolPrivate))
-
 #define gst_video_buffer_pool_parent_class parent_class
-G_DEFINE_TYPE (GstVideoBufferPool, gst_video_buffer_pool, GST_TYPE_BUFFER_POOL);
+G_DEFINE_TYPE_WITH_PRIVATE (GstVideoBufferPool, gst_video_buffer_pool,
+    GST_TYPE_BUFFER_POOL);
 
 static const gchar **
 video_buffer_pool_get_options (GstBufferPool * pool)
@@ -296,8 +294,6 @@ gst_video_buffer_pool_class_init (GstVideoBufferPoolClass * klass)
   GObjectClass *gobject_class = (GObjectClass *) klass;
   GstBufferPoolClass *gstbufferpool_class = (GstBufferPoolClass *) klass;
 
-  g_type_class_add_private (klass, sizeof (GstVideoBufferPoolPrivate));
-
   gobject_class->finalize = gst_video_buffer_pool_finalize;
 
   gstbufferpool_class->get_options = video_buffer_pool_get_options;
@@ -311,7 +307,7 @@ gst_video_buffer_pool_class_init (GstVideoBufferPoolClass * klass)
 static void
 gst_video_buffer_pool_init (GstVideoBufferPool * pool)
 {
-  pool->priv = GST_VIDEO_BUFFER_POOL_GET_PRIVATE (pool);
+  pool->priv = gst_video_buffer_pool_get_instance_private (pool);
 }
 
 static void
index 9cfe780..819eea6 100644 (file)
@@ -37,8 +37,6 @@
 
 #include "gstvideosink.h"
 
-G_DEFINE_TYPE (GstVideoSink, gst_video_sink, GST_TYPE_BASE_SINK);
-
 enum
 {
   PROP_SHOW_PREROLL_FRAME = 1
@@ -51,6 +49,8 @@ struct _GstVideoSinkPrivate
   gboolean show_preroll_frame;  /* ATOMIC */
 };
 
+G_DEFINE_TYPE_WITH_PRIVATE (GstVideoSink, gst_video_sink, GST_TYPE_BASE_SINK);
+
 #ifndef GST_DISABLE_GST_DEBUG
 #define GST_CAT_DEFAULT gst_video_sink_ensure_debug_category()
 
@@ -145,8 +145,7 @@ gst_video_sink_init (GstVideoSink * videosink)
   gst_base_sink_set_max_lateness (GST_BASE_SINK (videosink), 20 * GST_MSECOND);
   gst_base_sink_set_qos_enabled (GST_BASE_SINK (videosink), TRUE);
 
-  videosink->priv = G_TYPE_INSTANCE_GET_PRIVATE (videosink,
-      GST_TYPE_VIDEO_SINK, GstVideoSinkPrivate);
+  videosink->priv = gst_video_sink_get_instance_private (videosink);
 }
 
 static void
@@ -175,8 +174,6 @@ gst_video_sink_class_init (GstVideoSinkClass * klass)
   basesink_class->render = GST_DEBUG_FUNCPTR (gst_video_sink_show_frame);
   basesink_class->preroll =
       GST_DEBUG_FUNCPTR (gst_video_sink_show_preroll_frame);
-
-  g_type_class_add_private (klass, sizeof (GstVideoSinkPrivate));
 }
 
 static GstFlowReturn