diff --git a/gst/inter/gstinter.c b/gst/inter/gstinter.c index bae82bc0fd..8a7786dbca 100644 --- a/gst/inter/gstinter.c +++ b/gst/inter/gstinter.c @@ -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; } diff --git a/gst/inter/gstinteraudiosink.c b/gst/inter/gstinteraudiosink.c index a05248b837..342ebf519f 100644 --- a/gst/inter/gstinteraudiosink.c +++ b/gst/inter/gstinteraudiosink.c @@ -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 diff --git a/gst/inter/gstinteraudiosrc.c b/gst/inter/gstinteraudiosrc.c index 1b98adc8fc..af9c295b20 100644 --- a/gst/inter/gstinteraudiosrc.c +++ b/gst/inter/gstinteraudiosrc.c @@ -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)); } diff --git a/gst/inter/gstintersurface.c b/gst/inter/gstintersurface.c index 545cd6ffa2..1d23e5de15 100644 --- a/gst/inter/gstintersurface.c +++ b/gst/inter/gstintersurface.c @@ -21,22 +21,43 @@ #include "config.h" #endif +#include + #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; + } + } + + 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_init (void) +gst_inter_surface_unref (GstInterSurface * surface) { - surface = g_malloc0 (sizeof (GstInterSurface)); - surface->mutex = g_mutex_new (); - surface->audio_adapter = gst_adapter_new (); + } diff --git a/gst/inter/gstintersurface.h b/gst/inter/gstintersurface.h index 3e7e10c27e..d8ba11f4c9 100644 --- a/gst/inter/gstintersurface.h +++ b/gst/inter/gstintersurface.h @@ -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 diff --git a/gst/inter/gstintervideosink.c b/gst/inter/gstintervideosink.c index 43349f9d22..c77328885a 100644 --- a/gst/inter/gstintervideosink.c +++ b/gst/inter/gstintervideosink.c @@ -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; } diff --git a/gst/inter/gstintervideosink.h b/gst/inter/gstintervideosink.h index 5b02efe62d..5e421c6d02 100644 --- a/gst/inter/gstintervideosink.h +++ b/gst/inter/gstintervideosink.h @@ -39,6 +39,7 @@ struct _GstInterVideoSink GstBaseSink base_intervideosink; GstInterSurface *surface; + char *channel; int fps_n; int fps_d; diff --git a/gst/inter/gstintervideosrc.c b/gst/inter/gstintervideosrc.c index 2f5dbbac0f..4fa1df8eae 100644 --- a/gst/inter/gstintervideosrc.c +++ b/gst/inter/gstintervideosrc.c @@ -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); diff --git a/gst/inter/gstintervideosrc.h b/gst/inter/gstintervideosrc.h index e7a3cd045d..100c21489a 100644 --- a/gst/inter/gstintervideosrc.h +++ b/gst/inter/gstintervideosrc.h @@ -41,6 +41,8 @@ struct _GstInterVideoSrc GstInterSurface *surface; + char *channel; + GstVideoFormat format; int fps_n; int fps_d;