[farsight2/master] Implement the emission of the recv-codecs-changed signal

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:20:52 PST 2008


---
 gst/fsrtpconference/fs-rtp-stream.c    |   73 ++++++++++++++++++++++++++++++++
 gst/fsrtpconference/fs-rtp-stream.h    |    3 +
 gst/fsrtpconference/fs-rtp-substream.c |   17 +++++++
 3 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/gst/fsrtpconference/fs-rtp-stream.c b/gst/fsrtpconference/fs-rtp-stream.c
index 15c7d36..a8eff07 100644
--- a/gst/fsrtpconference/fs-rtp-stream.c
+++ b/gst/fsrtpconference/fs-rtp-stream.c
@@ -73,6 +73,7 @@ struct _FsRtpStreamPrivate
 
   /* Protected by the session mutex */
   GList *substreams;
+  guint recv_codecs_changed_idle_id;
 
   GError *construction_error;
 
@@ -216,6 +217,12 @@ fs_rtp_stream_dispose (GObject *object)
   }
 
   FS_RTP_SESSION_LOCK (self->priv->session);
+  if (self->priv->recv_codecs_changed_idle_id)
+  {
+    g_source_remove (self->priv->recv_codecs_changed_idle_id);
+    self->priv->recv_codecs_changed_idle_id = 0;
+  }
+
   if (self->priv->substreams) {
     g_list_foreach (self->priv->substreams, (GFunc) g_object_unref, NULL);
     g_list_free (self->priv->substreams);
@@ -647,6 +654,8 @@ fs_rtp_stream_add_substream (FsRtpStream *stream,
   if (codec) {
     ret = fs_rtp_sub_stream_add_output_ghostpad_locked (substream, error);
     fs_codec_destroy (codec);
+
+    fs_rtp_stream_maybe_emit_codecs_changed (stream, substream);
   }
 
   FS_RTP_SESSION_UNLOCK (stream->priv->session);
@@ -698,3 +707,67 @@ fs_rtp_stream_invalidate_codec_locked (FsRtpStream *stream,
        item = g_list_next (item))
     fs_rtp_sub_stream_invalidate_codec_locked (item->data, pt, codec);
 }
+
+
+
+static gboolean
+_idle_emit_recv_codecs_changed (gpointer data)
+{
+  FsRtpStream *stream = FS_RTP_STREAM (data);
+
+  g_signal_emit_by_name (stream, "recv-codecs-changed");
+
+  FS_RTP_SESSION_LOCK (stream->priv->session);
+  stream->priv->recv_codecs_changed_idle_id = 0;
+  FS_RTP_SESSION_UNLOCK (stream->priv->session);
+  return FALSE;
+}
+
+/**
+ * fs_stream_maybe_emit_codecs_changed:
+ * @stream: a #FsRtpStream
+ * @substream: The #FsRtpSubStream that may have a new receive codec
+ *
+ * This function checks if the specified substream introduces not a new codec
+ * not present in another substream and if it does, it schedules an idle task
+ * to emit the signal on the main thread.
+ */
+
+void
+fs_rtp_stream_maybe_emit_codecs_changed (FsRtpStream *stream,
+    FsRtpSubStream *substream)
+{
+  GList *substream_item = NULL;
+  FsCodec *codec = NULL;
+
+  g_object_get (substream, "codec", &codec, NULL);
+
+  if (!codec)
+    return;
+
+  FS_RTP_SESSION_LOCK (stream->priv->session);
+
+  for (substream_item = stream->priv->substreams;
+       substream_item;
+       substream_item = g_list_next (substream_item))
+  {
+    FsRtpSubStream *othersubstream = substream_item->data;
+
+    if (othersubstream != substream)
+    {
+      FsCodec *othercodec = NULL;
+
+      g_object_get (othersubstream, "codec", &othercodec, NULL);
+
+      if (othercodec && ! fs_codec_are_equal (codec, othercodec))
+        break;
+    }
+  }
+
+  if (substream_item == NULL)
+    if (!stream->priv->recv_codecs_changed_idle_id)
+      stream->priv->recv_codecs_changed_idle_id =
+        g_idle_add (_idle_emit_recv_codecs_changed, stream);
+
+  FS_RTP_SESSION_UNLOCK (stream->priv->session);
+}
diff --git a/gst/fsrtpconference/fs-rtp-stream.h b/gst/fsrtpconference/fs-rtp-stream.h
index d9831a6..9e0096c 100644
--- a/gst/fsrtpconference/fs-rtp-stream.h
+++ b/gst/fsrtpconference/fs-rtp-stream.h
@@ -92,6 +92,9 @@ void fs_rtp_stream_src_pad_added (FsRtpStream *stream,
     GstPad *ghostpad,
     FsCodec *codec);
 
+void fs_rtp_stream_maybe_emit_codecs_changed (FsRtpStream *stream,
+    FsRtpSubStream *substream);
+
 
 
 G_END_DECLS
diff --git a/gst/fsrtpconference/fs-rtp-substream.c b/gst/fsrtpconference/fs-rtp-substream.c
index a3b1d40..cdc8255 100644
--- a/gst/fsrtpconference/fs-rtp-substream.c
+++ b/gst/fsrtpconference/fs-rtp-substream.c
@@ -509,6 +509,23 @@ fs_rtp_sub_stream_add_codecbin_locked (FsRtpSubStream *substream,
   substream->priv->codecbin = codecbin;
   substream->priv->codec = codec;
 
+  if (substream->priv->stream)
+  {
+    gboolean ret = TRUE;
+
+    if (!substream->priv->output_ghostpad)
+      ret =  fs_rtp_sub_stream_add_output_ghostpad_locked (substream, error);
+
+    fs_rtp_stream_maybe_emit_codecs_changed (substream->priv->stream,
+        substream);
+
+    return ret;
+  }
+  else
+  {
+    return TRUE;
+  }
+
   /* Announce the pad if it wasnt there already and this substream
    * has a stream
    */
-- 
1.5.6.5




More information about the farsight-commits mailing list