[farsight2/master] Stop encoding when no one is sending
Olivier Crête
olivier.crete at collabora.co.uk
Wed Apr 8 17:39:47 PDT 2009
---
docs/plugins/farsight2-plugins-sections.txt | 1 +
gst/fsrtpconference/fs-rtp-session.c | 28 +++++++++++++++++++++++---
gst/fsrtpconference/fs-rtp-stream.c | 24 +++++++++++++++++++++++
gst/fsrtpconference/fs-rtp-stream.h | 3 ++
4 files changed, 52 insertions(+), 4 deletions(-)
diff --git a/docs/plugins/farsight2-plugins-sections.txt b/docs/plugins/farsight2-plugins-sections.txt
index 38faae2..484f226 100644
--- a/docs/plugins/farsight2-plugins-sections.txt
+++ b/docs/plugins/farsight2-plugins-sections.txt
@@ -189,6 +189,7 @@ FsRtpStreamPrivate
fs_rtp_stream_new
fs_rtp_stream_add_substream_unlock
fs_rtp_stream_set_negotiated_codecs_unlock
+stream_sending_changed_locked_cb
</SECTION>
diff --git a/gst/fsrtpconference/fs-rtp-session.c b/gst/fsrtpconference/fs-rtp-session.c
index ee0fd46..ecc286b 100644
--- a/gst/fsrtpconference/fs-rtp-session.c
+++ b/gst/fsrtpconference/fs-rtp-session.c
@@ -167,6 +167,7 @@ struct _FsRtpSessionPrivate
GList *streams;
guint streams_cookie;
GList *free_substreams;
+ guint streams_sending;
/* The static list of all the blueprints */
GList *blueprints;
@@ -1371,6 +1372,24 @@ _stream_known_source_packet_received (FsRtpStream *stream, guint component,
fs_rtp_session_has_disposed_exit (self);
}
+static void
+_stream_sending_changed_locked (FsRtpStream *stream, gboolean sending,
+ gpointer user_data)
+{
+ FsRtpSession *session = user_data;
+
+ if (sending)
+ session->priv->streams_sending++;
+ else
+ session->priv->streams_sending--;
+
+ if (session->priv->streams_sending && session->priv->send_codecbin)
+ g_object_set (session->priv->media_sink_valve, "drop", FALSE, NULL);
+ else
+ g_object_set (session->priv->media_sink_valve, "drop", TRUE, NULL);
+
+}
+
static gboolean
_remove_stream_from_ht (gpointer key, gpointer value, gpointer user_data)
{
@@ -1449,7 +1468,8 @@ fs_rtp_session_new_stream (FsSession *session,
new_stream = FS_STREAM_CAST (fs_rtp_stream_new (self, rtpparticipant,
direction, st, _stream_new_remote_codecs,
- _stream_known_source_packet_received, self, error));
+ _stream_known_source_packet_received,
+ _stream_sending_changed_locked, self, error));
FS_RTP_SESSION_LOCK (self);
self->priv->streams = g_list_append (self->priv->streams, new_stream);
@@ -3378,13 +3398,13 @@ fs_rtp_session_add_send_codec_bin_unlock (FsRtpSession *session,
g_object_unref (transmitter);
FS_RTP_SESSION_LOCK (session);
}
- FS_RTP_SESSION_UNLOCK (session);
- g_object_set (session->priv->media_sink_valve, "drop", FALSE, NULL);
+ if (session->priv->streams_sending)
+ g_object_set (session->priv->media_sink_valve, "drop", FALSE, NULL);
+
session->priv->send_codecbin = codecbin;
- FS_RTP_SESSION_LOCK (session);
session->priv->current_send_codec = fs_codec_copy (codec);
FS_RTP_SESSION_UNLOCK (session);
diff --git a/gst/fsrtpconference/fs-rtp-stream.c b/gst/fsrtpconference/fs-rtp-stream.c
index 1004ead..2eacae8 100644
--- a/gst/fsrtpconference/fs-rtp-stream.c
+++ b/gst/fsrtpconference/fs-rtp-stream.c
@@ -73,6 +73,7 @@ struct _FsRtpStreamPrivate
stream_new_remote_codecs_cb new_remote_codecs_cb;
stream_known_source_packet_receive_cb known_source_packet_received_cb;
+ stream_sending_changed_locked_cb sending_changed_locked_cb;
gpointer user_data_for_cb;
GMutex *mutex;
@@ -261,6 +262,12 @@ fs_rtp_stream_dispose (GObject *object)
g_mutex_unlock (self->priv->mutex);
FS_RTP_SESSION_LOCK (session);
+
+ if (self->priv->sending_changed_locked_cb &&
+ self->priv->direction & FS_DIRECTION_SEND)
+ self->priv->sending_changed_locked_cb (self, FALSE,
+ self->priv->user_data_for_cb);
+
participant = self->participant;
self->participant = NULL;
@@ -419,6 +426,13 @@ fs_rtp_stream_set_property (GObject *object,
}
FS_RTP_SESSION_LOCK (session);
+ if (self->priv->sending_changed_locked_cb &&
+ (self->priv->direction & FS_DIRECTION_SEND) !=
+ (g_value_get_flags (value) & FS_DIRECTION_SEND))
+ self->priv->sending_changed_locked_cb (self,
+ g_value_get_flags (value) & FS_DIRECTION_SEND,
+ self->priv->user_data_for_cb);
+
dir = self->priv->direction = g_value_get_flags (value);
FS_RTP_SESSION_UNLOCK (session);
st = fs_rtp_stream_get_stream_transmitter (self, NULL);
@@ -655,6 +669,8 @@ fs_rtp_stream_set_remote_codecs (FsStream *stream,
* the session lock across calls.
* @known_source_packet_received: Callback called when a packet from a
* known source is receive.
+ * @sending_changed_locked_cb: Callback called when the sending status of
+ * this stream changes
* @user_data: User data for the callbacks.
* This function create a new stream
*
@@ -668,6 +684,7 @@ fs_rtp_stream_new (FsRtpSession *session,
FsStreamTransmitter *stream_transmitter,
stream_new_remote_codecs_cb new_remote_codecs_cb,
stream_known_source_packet_receive_cb known_source_packet_received_cb,
+ stream_sending_changed_locked_cb sending_changed_locked_cb,
gpointer user_data_for_cb,
GError **error)
{
@@ -688,8 +705,15 @@ fs_rtp_stream_new (FsRtpSession *session,
self->priv->new_remote_codecs_cb = new_remote_codecs_cb;
self->priv->known_source_packet_received_cb = known_source_packet_received_cb;
+ self->priv->sending_changed_locked_cb = sending_changed_locked_cb;
self->priv->user_data_for_cb = user_data_for_cb;
+ FS_RTP_SESSION_LOCK (session);
+ if (sending_changed_locked_cb && (direction & FS_DIRECTION_SEND))
+ sending_changed_locked_cb (self, direction & FS_DIRECTION_SEND,
+ user_data_for_cb);
+ FS_RTP_SESSION_UNLOCK (session);
+
if (self->priv->construction_error) {
g_propagate_error (error, self->priv->construction_error);
g_object_unref (self);
diff --git a/gst/fsrtpconference/fs-rtp-stream.h b/gst/fsrtpconference/fs-rtp-stream.h
index 0f169e5..d58a80f 100644
--- a/gst/fsrtpconference/fs-rtp-stream.h
+++ b/gst/fsrtpconference/fs-rtp-stream.h
@@ -90,6 +90,8 @@ 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);
+typedef void (*stream_sending_changed_locked_cb) (FsRtpStream *stream,
+ gboolean sending, gpointer user_data);
FsRtpStream *fs_rtp_stream_new (FsRtpSession *session,
FsRtpParticipant *participant,
@@ -97,6 +99,7 @@ FsRtpStream *fs_rtp_stream_new (FsRtpSession *session,
FsStreamTransmitter *stream_transmitter,
stream_new_remote_codecs_cb new_remote_codecs_cb,
stream_known_source_packet_receive_cb known_source_packet_received_cb,
+ stream_sending_changed_locked_cb sending_changed_locked_cb,
gpointer user_data_for_cb,
GError **error);
--
1.5.6.5
More information about the farsight-commits
mailing list