inter: Add channel property
authorDavid Schleef <ds@schleef.org>
Sun, 22 Jan 2012 23:49:12 +0000 (15:49 -0800)
committerDavid Schleef <ds@schleef.org>
Sun, 22 Jan 2012 23:52:15 +0000 (15:52 -0800)
gst/inter/gstinter.c
gst/inter/gstinteraudiosink.c
gst/inter/gstinteraudiosrc.c
gst/inter/gstintersurface.c
gst/inter/gstintersurface.h
gst/inter/gstintervideosink.c
gst/inter/gstintervideosink.h
gst/inter/gstintervideosrc.c
gst/inter/gstintervideosrc.h

index bae82bc0fdfe8c698dceb2b35805041b1d034403..8a7786dbca0f1952dc1d96aaba9b6ff24176cf6d 100644 (file)
@@ -45,8 +45,6 @@ plugin_init (GstPlugin * plugin)
   gst_element_register (plugin, "intervideosink", GST_RANK_NONE,
       GST_TYPE_INTER_VIDEO_SINK);
 
-  gst_inter_surface_init ();
-
   return TRUE;
 }
 
index a05248b8378a300873ea9c411e4d686b78d86514..342ebf519f0a62173d1f25a1432be1b73f963edd 100644 (file)
@@ -77,7 +77,8 @@ static gboolean gst_inter_audio_sink_unlock_stop (GstBaseSink * sink);
 
 enum
 {
-  PROP_0
+  PROP_0,
+  PROP_CHANNEL
 };
 
 /* pad templates */
@@ -150,6 +151,10 @@ gst_inter_audio_sink_class_init (GstInterAudioSinkClass * klass)
   base_sink_class->unlock_stop =
       GST_DEBUG_FUNCPTR (gst_inter_audio_sink_unlock_stop);
 
+  g_object_class_install_property (gobject_class, PROP_CHANNEL,
+      g_param_spec_string ("channel", "Channel",
+          "Channel name to match inter src and sink elements",
+          "default", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 }
 
 static void
index 1b98adc8fc62a0488164197397d774e067dc76a2..af9c295b20a32d6df824fab9b35d974ad8f61a89 100644 (file)
@@ -79,7 +79,8 @@ gst_inter_audio_src_prepare_seek_segment (GstBaseSrc * src, GstEvent * seek,
 
 enum
 {
-  PROP_0
+  PROP_0,
+  PROP_CHANNEL
 };
 
 /* pad templates */
@@ -158,6 +159,10 @@ gst_inter_audio_src_class_init (GstInterAudioSrcClass * klass)
     base_src_class->prepare_seek_segment =
         GST_DEBUG_FUNCPTR (gst_inter_audio_src_prepare_seek_segment);
 
+  g_object_class_install_property (gobject_class, PROP_CHANNEL,
+      g_param_spec_string ("channel", "Channel",
+          "Channel name to match inter src and sink elements",
+          "default", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
 }
 
index 545cd6ffa2b960594340607923808cf7dea7bd48..1d23e5de154f489a56085e1e37b2364f2e5c3c90 100644 (file)
 #include "config.h"
 #endif
 
+#include <string.h>
+
 #include "gstintersurface.h"
 
-static GstInterSurface *surface;
+static GList *list;
+static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
 
 
 GstInterSurface *
 gst_inter_surface_get (const char *name)
 {
-  return surface;
+  GList *g;
+  GstInterSurface *surface;
 
-}
+  g_static_mutex_lock (&mutex);
+
+  for (g = list; g; g = g_list_next (g)) {
+    surface = (GstInterSurface *) g->data;
+    if (strcmp (name, surface->name) == 0) {
+      g_static_mutex_unlock (&mutex);
+      return surface;
+    }
+  }
 
-void
-gst_inter_surface_init (void)
-{
   surface = g_malloc0 (sizeof (GstInterSurface));
+  surface->name = g_strdup (name);
   surface->mutex = g_mutex_new ();
   surface->audio_adapter = gst_adapter_new ();
+
+  list = g_list_append (list, surface);
+  g_static_mutex_unlock (&mutex);
+
+  return surface;
+}
+
+void
+gst_inter_surface_unref (GstInterSurface * surface)
+{
+
 }
index 3e7e10c27e290e7ff253bf890786602c90df9bbf..d8ba11f4c9ed299a9d5f2a842310294ad2848d76 100644 (file)
@@ -30,6 +30,7 @@ typedef struct _GstInterSurface GstInterSurface;
 struct _GstInterSurface
 {
   GMutex *mutex;
+  char *name;
 
   /* video */
   GstVideoFormat format;
@@ -51,7 +52,7 @@ struct _GstInterSurface
 
 
 GstInterSurface * gst_inter_surface_get (const char *name);
-void gst_inter_surface_init (void);
+void gst_inter_surface_unref (GstInterSurface *surface);
 
 
 G_END_DECLS
index 43349f9d2231de8cd94b9ea815b6638479458972..c77328885ae3321d688c72af2fefb94f8c6b928b 100644 (file)
@@ -76,7 +76,8 @@ static gboolean gst_inter_video_sink_unlock_stop (GstBaseSink * sink);
 
 enum
 {
-  PROP_0
+  PROP_0,
+  PROP_CHANNEL
 };
 
 /* pad templates */
@@ -144,6 +145,10 @@ gst_inter_video_sink_class_init (GstInterVideoSinkClass * klass)
   base_sink_class->unlock_stop =
       GST_DEBUG_FUNCPTR (gst_inter_video_sink_unlock_stop);
 
+  g_object_class_install_property (gobject_class, PROP_CHANNEL,
+      g_param_spec_string ("channel", "Channel",
+          "Channel name to match inter src and sink elements",
+          "default", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -151,15 +156,25 @@ gst_inter_video_sink_init (GstInterVideoSink * intervideosink,
     GstInterVideoSinkClass * intervideosink_class)
 {
   intervideosink->surface = gst_inter_surface_get ("default");
+
+  intervideosink->sinkpad =
+      gst_pad_new_from_static_template (&gst_inter_video_sink_sink_template,
+      "sink");
+
+  intervideosink->channel = g_strdup ("default");
 }
 
 void
 gst_inter_video_sink_set_property (GObject * object, guint property_id,
     const GValue * value, GParamSpec * pspec)
 {
-  /* GstInterVideoSink *intervideosink = GST_INTER_VIDEO_SINK (object); */
+  GstInterVideoSink *intervideosink = GST_INTER_VIDEO_SINK (object);
 
   switch (property_id) {
+    case PROP_CHANNEL:
+      g_free (intervideosink->channel);
+      intervideosink->channel = g_value_dup_string (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -170,9 +185,12 @@ void
 gst_inter_video_sink_get_property (GObject * object, guint property_id,
     GValue * value, GParamSpec * pspec)
 {
-  /* GstInterVideoSink *intervideosink = GST_INTER_VIDEO_SINK (object); */
+  GstInterVideoSink *intervideosink = GST_INTER_VIDEO_SINK (object);
 
   switch (property_id) {
+    case PROP_CHANNEL:
+      g_value_set_string (value, intervideosink->channel);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -192,9 +210,10 @@ gst_inter_video_sink_dispose (GObject * object)
 void
 gst_inter_video_sink_finalize (GObject * object)
 {
-  /* GstInterVideoSink *intervideosink = GST_INTER_VIDEO_SINK (object); */
+  GstInterVideoSink *intervideosink = GST_INTER_VIDEO_SINK (object);
 
   /* clean up object here */
+  g_free (intervideosink->channel);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -248,6 +267,9 @@ gst_inter_video_sink_get_times (GstBaseSink * sink, GstBuffer * buffer,
 static gboolean
 gst_inter_video_sink_start (GstBaseSink * sink)
 {
+  GstInterVideoSink *intervideosink = GST_INTER_VIDEO_SINK (sink);
+
+  intervideosink->surface = gst_inter_surface_get (intervideosink->channel);
 
   return TRUE;
 }
@@ -264,6 +286,9 @@ gst_inter_video_sink_stop (GstBaseSink * sink)
   intervideosink->surface->video_buffer = NULL;
   g_mutex_unlock (intervideosink->surface->mutex);
 
+  gst_inter_surface_unref (intervideosink->surface);
+  intervideosink->surface = NULL;
+
   return TRUE;
 }
 
index 5b02efe62d73dff4c27755c041e13740a2e868c4..5e421c6d029c8dd051567f14e389c753b025a5cc 100644 (file)
@@ -39,6 +39,7 @@ struct _GstInterVideoSink
   GstBaseSink base_intervideosink;
 
   GstInterSurface *surface;
+  char *channel;
 
   int fps_n;
   int fps_d;
index 2f5dbbac0f61351ac2613bf5a972a7f48a9d41a0..4fa1df8eae035271fe44b0b57c48ebc42f8b9d7b 100644 (file)
@@ -80,7 +80,8 @@ gst_inter_video_src_prepare_seek_segment (GstBaseSrc * src, GstEvent * seek,
 
 enum
 {
-  PROP_0
+  PROP_0,
+  PROP_CHANNEL
 };
 
 /* pad templates */
@@ -156,6 +157,10 @@ gst_inter_video_src_class_init (GstInterVideoSrcClass * klass)
     base_src_class->prepare_seek_segment =
         GST_DEBUG_FUNCPTR (gst_inter_video_src_prepare_seek_segment);
 
+  g_object_class_install_property (gobject_class, PROP_CHANNEL,
+      g_param_spec_string ("channel", "Channel",
+          "Channel name to match inter src and sink elements",
+          "default", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
 }
 
@@ -166,16 +171,20 @@ gst_inter_video_src_init (GstInterVideoSrc * intervideosrc,
   gst_base_src_set_format (GST_BASE_SRC (intervideosrc), GST_FORMAT_TIME);
   gst_base_src_set_live (GST_BASE_SRC (intervideosrc), TRUE);
 
-  intervideosrc->surface = gst_inter_surface_get ("default");
+  intervideosrc->channel = g_strdup ("default");
 }
 
 void
 gst_inter_video_src_set_property (GObject * object, guint property_id,
     const GValue * value, GParamSpec * pspec)
 {
-  /* GstInterVideoSrc *intervideosrc = GST_INTER_VIDEO_SRC (object); */
+  GstInterVideoSrc *intervideosrc = GST_INTER_VIDEO_SRC (object);
 
   switch (property_id) {
+    case PROP_CHANNEL:
+      g_free (intervideosrc->channel);
+      intervideosrc->channel = g_value_dup_string (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -186,9 +195,12 @@ void
 gst_inter_video_src_get_property (GObject * object, guint property_id,
     GValue * value, GParamSpec * pspec)
 {
-  /* GstInterVideoSrc *intervideosrc = GST_INTER_VIDEO_SRC (object); */
+  GstInterVideoSrc *intervideosrc = GST_INTER_VIDEO_SRC (object);
 
   switch (property_id) {
+    case PROP_CHANNEL:
+      g_value_set_string (value, intervideosrc->channel);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -208,9 +220,10 @@ gst_inter_video_src_dispose (GObject * object)
 void
 gst_inter_video_src_finalize (GObject * object)
 {
-  /* GstInterVideoSrc *intervideosrc = GST_INTER_VIDEO_SRC (object); */
+  GstInterVideoSrc *intervideosrc = GST_INTER_VIDEO_SRC (object);
 
   /* clean up object here */
+  g_free (intervideosrc->channel);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -279,6 +292,8 @@ gst_inter_video_src_start (GstBaseSrc * src)
 
   GST_DEBUG_OBJECT (intervideosrc, "start");
 
+  intervideosrc->surface = gst_inter_surface_get (intervideosrc->channel);
+
   return TRUE;
 }
 
@@ -289,6 +304,9 @@ gst_inter_video_src_stop (GstBaseSrc * src)
 
   GST_DEBUG_OBJECT (intervideosrc, "stop");
 
+  gst_inter_surface_unref (intervideosrc->surface);
+  intervideosrc->surface = NULL;
+
   return TRUE;
 }
 
@@ -391,15 +409,6 @@ gst_inter_video_src_create (GstBaseSrc * src, guint64 offset, guint size,
             intervideosrc->width) *
         gst_video_format_get_component_height (intervideosrc->format, 1,
             intervideosrc->height));
-
-#if 0
-    {
-      int i;
-      for (i = 0; i < 10000; i++) {
-        data[i] = g_random_int () & 0xff;
-      }
-    }
-#endif
   }
 
   buffer = gst_buffer_make_metadata_writable (buffer);
index e7a3cd045d55b03c7d7d8fca68db2d31b69de72d..100c21489a6b35481261245393a1b37c20359d01 100644 (file)
@@ -41,6 +41,8 @@ struct _GstInterVideoSrc
 
   GstInterSurface *surface;
 
+  char *channel;
+
   GstVideoFormat format;
   int fps_n;
   int fps_d;