[farsight2/master] Replace the private signals on FsRtpStream with callbacks
Olivier Crête
olivier.crete at collabora.co.uk
Tue Dec 23 15:25:28 PST 2008
---
gst/fsrtpconference/fs-rtp-session.c | 31 +++------
gst/fsrtpconference/fs-rtp-stream.c | 113 ++++++++++-----------------------
gst/fsrtpconference/fs-rtp-stream.h | 16 ++++-
3 files changed, 56 insertions(+), 104 deletions(-)
diff --git a/gst/fsrtpconference/fs-rtp-session.c b/gst/fsrtpconference/fs-rtp-session.c
index 83de722..5dbee5c 100644
--- a/gst/fsrtpconference/fs-rtp-session.c
+++ b/gst/fsrtpconference/fs-rtp-session.c
@@ -213,8 +213,8 @@ static void _substream_no_rtcp_timedout_cb (FsRtpSubStream *substream,
static void _substream_blocked (FsRtpSubStream *substream, FsRtpStream *stream,
FsRtpSession *session);
-static GError* _stream_new_remote_codecs (FsRtpStream *stream, GList *codecs,
- FsRtpSession *session);
+static gboolean _stream_new_remote_codecs (FsRtpStream *stream, GList *codecs,
+ GError **error, gpointer user_data);
static FsStreamTransmitter *fs_rtp_session_get_new_stream_transmitter (
@@ -1260,9 +1260,10 @@ fs_rtp_session_constructed (GObject *object)
static void
_stream_known_source_packet_received (FsRtpStream *stream, guint component,
- GstBuffer *buffer, FsRtpSession *self)
+ GstBuffer *buffer, gpointer user_data)
{
guint32 ssrc;
+ FsRtpSession *self = FS_RTP_SESSION_CAST (user_data);
if (component == 1)
{
@@ -1379,12 +1380,8 @@ fs_rtp_session_new_stream (FsSession *session,
return NULL;
new_stream = FS_STREAM_CAST (fs_rtp_stream_new (self, rtpparticipant,
- direction, st, error));
-
- g_signal_connect (new_stream, "new-remote-codecs",
- G_CALLBACK (_stream_new_remote_codecs), self);
- g_signal_connect (new_stream, "known-source-packet-received",
- G_CALLBACK (_stream_known_source_packet_received), self);
+ direction, st, _stream_new_remote_codecs,
+ _stream_known_source_packet_received, self, error));
FS_RTP_SESSION_LOCK (self);
self->priv->streams = g_list_append (self->priv->streams, new_stream);
@@ -2107,21 +2104,13 @@ fs_rtp_session_update_codecs (FsRtpSession *session,
return TRUE;
}
-static GError *
+static gboolean
_stream_new_remote_codecs (FsRtpStream *stream,
- GList *codecs,
- FsRtpSession *session)
+ GList *codecs, GError **error, gpointer user_data)
{
- GError *error = NULL;
- gboolean rv;
-
- rv = fs_rtp_session_update_codecs (session, stream, codecs, &error);
-
- if (!rv && !error)
- error = g_error_new (FS_ERROR, FS_ERROR_INTERNAL,
- "Unknown error while negotiating codecs");
+ FsRtpSession *session = FS_RTP_SESSION_CAST (user_data);
- return error;
+ return fs_rtp_session_update_codecs (session, stream, codecs, error);
}
diff --git a/gst/fsrtpconference/fs-rtp-stream.c b/gst/fsrtpconference/fs-rtp-stream.c
index f7b32dd..743d7f5 100644
--- a/gst/fsrtpconference/fs-rtp-stream.c
+++ b/gst/fsrtpconference/fs-rtp-stream.c
@@ -42,8 +42,6 @@
/* Signals */
enum
{
- NEW_REMOTE_CODECS,
- KNOWN_SOURCE_PACKET_RECEIVED,
LAST_SIGNAL
};
@@ -79,6 +77,10 @@ struct _FsRtpStreamPrivate
GError *construction_error;
+ stream_new_remote_codecs_cb new_remote_codecs_cb;
+ stream_known_source_packet_receive_cb known_source_packet_received_cb;
+ gpointer user_data_for_cb;
+
gboolean disposed;
};
@@ -112,10 +114,6 @@ static gboolean fs_rtp_stream_force_remote_candidates (FsStream *stream,
static gboolean fs_rtp_stream_set_remote_codecs (FsStream *stream,
GList *remote_codecs,
GError **error);
-static gboolean
-fs_rtp_stream_emit_new_remote_codecs (FsRtpStream *stream,
- GList *codecs,
- GError **error);
static void _local_candidates_prepared (
FsStreamTransmitter *stream_transmitter,
@@ -149,7 +147,7 @@ static void _state_changed (FsStreamTransmitter *stream_transmitter,
static GObjectClass *parent_class = NULL;
-static guint signals[LAST_SIGNAL] = { 0 };
+// static guint signals[LAST_SIGNAL] = { 0 };
static void
fs_rtp_stream_class_init (FsRtpStreamClass *klass)
@@ -194,55 +192,6 @@ fs_rtp_stream_class_init (FsRtpStreamClass *klass)
g_object_class_override_property (gobject_class,
PROP_STREAM_TRANSMITTER,
"stream-transmitter");
-
- /*
- * FsRtpStream::new-remote-codecs
- * @self: #FsRtpStream that emitted the signal
- * @codecs: #GList of new remote #FsCodec
- *
- * This signal is emitted after a user does fs_stream_set_remote_codecs(),
- * with the new codecs.
- *
- * Returns: %NULL on success, or a #GError if an error occured
- */
- /**
- * FsRtpStream::new-remote-codecs:
- *
- * ENTIRELY INTERNAL
- */
- signals[NEW_REMOTE_CODECS] = g_signal_new ("new-remote-codecs",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- _fs_rtp_marshal_POINTER__BOXED,
- G_TYPE_POINTER, 1, FS_TYPE_CODEC_LIST);
-
- /*
- * FsRtpStream::known-source-packet-received:
- * @self: #FsRtpStream that emitted the signal
- * @component: The Component on which this buffer was received
- * @buffer: the #GstBuffer coming from the known source
- *
- * This signal is emitted when a buffer coming from a confirmed known source
- * is received. It is a proxy of the
- * #FsStreamTransmitter::known-source-packet-received signal.
- */
- /**
- * FsRtpStream::known-source-packet-received:
- *
- * ENTIRELY INTERNAL
- */
- signals[KNOWN_SOURCE_PACKET_RECEIVED] = g_signal_new
- ("known-source-packet-received",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_VOID__UINT_POINTER,
- G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_POINTER);
}
static void
@@ -588,7 +537,8 @@ fs_rtp_stream_set_remote_codecs (FsStream *stream,
}
}
- if (fs_rtp_stream_emit_new_remote_codecs (self, remote_codecs, error))
+ if (self->priv->new_remote_codecs_cb (self, remote_codecs, error,
+ self->priv->user_data_for_cb))
{
if (self->remote_codecs)
fs_codec_list_destroy (self->remote_codecs);
@@ -612,7 +562,11 @@ fs_rtp_stream_set_remote_codecs (FsStream *stream,
* @direction: the initial #FsDirection for this stream
* @stream_transmitter: the #FsStreamTransmitter for this stream, one
* reference to it will be eaten
- *
+ * @new_remote_codecs: Callback called when the remote codecs change
+ * (ie when fs_rtp_stream_set_remote_codecs() is called).
+ * @known_source_packet_received: Callback called when a packet from a
+ * known source is receive.
+ * @user_data: User data for the callbacks.
* This function create a new stream
*
* Returns: the newly created string or NULL on error
@@ -620,18 +574,33 @@ fs_rtp_stream_set_remote_codecs (FsStream *stream,
FsRtpStream *
fs_rtp_stream_new (FsRtpSession *session,
- FsRtpParticipant *participant,
- FsStreamDirection direction,
- FsStreamTransmitter *stream_transmitter,
- GError **error)
+ FsRtpParticipant *participant,
+ FsStreamDirection direction,
+ FsStreamTransmitter *stream_transmitter,
+ stream_new_remote_codecs_cb new_remote_codecs_cb,
+ stream_known_source_packet_receive_cb known_source_packet_received_cb,
+ gpointer user_data_for_cb,
+ GError **error)
{
- FsRtpStream *self = g_object_new (FS_TYPE_RTP_STREAM,
+ FsRtpStream *self;
+
+ g_return_val_if_fail (session, NULL);
+ g_return_val_if_fail (participant, NULL);
+ g_return_val_if_fail (stream_transmitter, NULL);
+ g_return_val_if_fail (new_remote_codecs_cb, NULL);
+ g_return_val_if_fail (known_source_packet_received_cb, NULL);
+
+ self = g_object_new (FS_TYPE_RTP_STREAM,
"session", session,
"participant", participant,
"direction", direction,
"stream-transmitter", stream_transmitter,
NULL);
+ self->priv->new_remote_codecs_cb = new_remote_codecs_cb;
+ self->priv->known_source_packet_received_cb = known_source_packet_received_cb;
+ self->priv->user_data_for_cb = user_data_for_cb;
+
if (self->priv->construction_error) {
g_propagate_error (error, self->priv->construction_error);
g_object_unref (self);
@@ -725,8 +694,8 @@ _known_source_packet_received (FsStreamTransmitter *st,
GstBuffer *buffer,
FsRtpStream *self)
{
- g_signal_emit (self, signals[KNOWN_SOURCE_PACKET_RECEIVED], 0,
- component, buffer);
+ self->priv->known_source_packet_received_cb (self, component, buffer,
+ self->priv->user_data_for_cb);
}
static void
@@ -901,20 +870,6 @@ _substream_codec_changed (FsRtpSubStream *substream,
fs_codec_list_destroy (codeclist);
}
-static gboolean
-fs_rtp_stream_emit_new_remote_codecs (FsRtpStream *stream,
- GList *codecs, GError **error)
-{
- GError *myerror = NULL;
-
- g_signal_emit (stream, signals[NEW_REMOTE_CODECS], 0, codecs, &myerror);
-
- if (myerror)
- g_propagate_error (error, myerror);
-
- return !myerror;
-}
-
/**
* fs_rtp_stream_set_negotiated_codecs
* @stream: a #FsRtpStream
diff --git a/gst/fsrtpconference/fs-rtp-stream.h b/gst/fsrtpconference/fs-rtp-stream.h
index f0a6f41..846ebd2 100644
--- a/gst/fsrtpconference/fs-rtp-stream.h
+++ b/gst/fsrtpconference/fs-rtp-stream.h
@@ -84,11 +84,19 @@ struct _FsRtpStream
GType fs_rtp_stream_get_type (void);
+typedef gboolean (*stream_new_remote_codecs_cb) (FsRtpStream *stream,
+ GList *codecs, GError **error, gpointer user_data);
+typedef void (*stream_known_source_packet_receive_cb) (FsRtpStream *stream,
+ guint component, GstBuffer *buffer, gpointer user_data);
+
FsRtpStream *fs_rtp_stream_new (FsRtpSession *session,
- FsRtpParticipant *participant,
- FsStreamDirection direction,
- FsStreamTransmitter *stream_transmitter,
- GError **error);
+ FsRtpParticipant *participant,
+ FsStreamDirection direction,
+ FsStreamTransmitter *stream_transmitter,
+ stream_new_remote_codecs_cb new_remote_codecs_cb,
+ stream_known_source_packet_receive_cb known_source_packet_received_cb,
+ gpointer user_data_for_cb,
+ GError **error);
gboolean fs_rtp_stream_add_substream (FsRtpStream *stream,
FsRtpSubStream *substream,
--
1.5.6.5
More information about the farsight-commits
mailing list