*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
/**
- * SECTION:element-gstrtpbin
- * @see_also: gstrtpjitterbuffer, gstrtpsession, gstrtpptdemux, gstrtpssrcdemux
+ * SECTION:element-rtpbin
+ * @see_also: rtpjitterbuffer, rtpsession, rtpptdemux, rtpssrcdemux
*
* RTP bin combines the functions of #GstRtpSession, #GstRtpSsrcDemux,
* #GstRtpJitterBuffer and #GstRtpPtDemux in one element. It allows for multiple
* the packets are released from the jitterbuffer, they will be forwarded to a
* #GstRtpPtDemux element. The #GstRtpPtDemux element will demux the packets based
* on the payload type and will create a unique pad recv_rtp_src_\%u_\%u_\%u on
- * gstrtpbin with the session number, SSRC and payload type respectively as the pad
+ * rtpbin with the session number, SSRC and payload type respectively as the pad
* name.
*
* To also use #GstRtpBin as an RTCP receiver, request a recv_rtcp_sink_\%u pad. The
* mapping. One can clear the cached values with the #GstRtpSession::clear-pt-map
* signal.
*
- * Access to the internal statistics of gstrtpbin is provided with the
+ * Access to the internal statistics of rtpbin is provided with the
* get-internal-session property. This action signal gives access to the
* RTPSession object which further provides action signals to retrieve the
* internal source and other sources.
*
+ * #GstRtpBin also has signals (#GstRtpBin::request-rtp-encoder,
+ * #GstRtpBin::request-rtp-decoder, #GstRtpBin::request-rtcp-encoder and
+ * #GstRtpBin::request-rtp-decoder) to dynamically request for RTP and RTCP encoders
+ * and decoders in order to support SRTP. The encoders must provide the pads
+ * rtp_sink_\%d and rtp_src_\%d for RTP and rtcp_sink_\%d and rtcp_src_\%d for
+ * RTCP. The session number will be used in the pad name. The decoders must provide
+ * rtp_sink and rtp_src for RTP and rtcp_sink and rtcp_src for RTCP. The decoders will
+ * be placed before the #GstRtpSession element, thus they must support SSRC demuxing
+ * internally.
+ *
* <refsect2>
* <title>Example pipelines</title>
* |[
- * gst-launch udpsrc port=5000 caps="application/x-rtp, ..." ! .recv_rtp_sink_0 \
- * gstrtpbin ! rtptheoradepay ! theoradec ! xvimagesink
- * ]| Receive RTP data from port 5000 and send to the session 0 in gstrtpbin.
+ * gst-launch-1.0 udpsrc port=5000 caps="application/x-rtp, ..." ! .recv_rtp_sink_0 \
+ * rtpbin ! rtptheoradepay ! theoradec ! xvimagesink
+ * ]| Receive RTP data from port 5000 and send to the session 0 in rtpbin.
* |[
- * gst-launch gstrtpbin name=rtpbin \
- * v4l2src ! ffmpegcolorspace ! ffenc_h263 ! rtph263ppay ! rtpbin.send_rtp_sink_0 \
+ * gst-launch-1.0 rtpbin name=rtpbin \
+ * v4l2src ! videoconvert ! ffenc_h263 ! rtph263ppay ! rtpbin.send_rtp_sink_0 \
* rtpbin.send_rtp_src_0 ! udpsink port=5000 \
* rtpbin.send_rtcp_src_0 ! udpsink port=5001 sync=false async=false \
* udpsrc port=5005 ! rtpbin.recv_rtcp_sink_0 \
* as soon as possible and do not participate in preroll, sync=false and
* async=false is configured on udpsink
* |[
- * gst-launch -v gstrtpbin name=rtpbin \
+ * gst-launch-1.0 -v rtpbin name=rtpbin \
* udpsrc caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H263-1998" \
* port=5000 ! rtpbin.recv_rtp_sink_0 \
* rtpbin. ! rtph263pdepay ! ffdec_h263 ! xvimagesink \
#include <gst/rtp/gstrtpbuffer.h>
#include <gst/rtp/gstrtcpbuffer.h>
-#include "gstrtpbin-marshal.h"
#include "gstrtpbin.h"
#include "rtpsession.h"
#include "gstrtpsession.h"
#include "gstrtpjitterbuffer.h"
+#include <gst/glib-compat-private.h>
+
GST_DEBUG_CATEGORY_STATIC (gst_rtp_bin_debug);
#define GST_CAT_DEFAULT gst_rtp_bin_debug
/* sink pads */
static GstStaticPadTemplate rtpbin_recv_rtp_sink_template =
-GST_STATIC_PAD_TEMPLATE ("recv_rtp_sink_%u",
+ GST_STATIC_PAD_TEMPLATE ("recv_rtp_sink_%u",
GST_PAD_SINK,
GST_PAD_REQUEST,
- GST_STATIC_CAPS ("application/x-rtp")
+ GST_STATIC_CAPS ("application/x-rtp;application/x-srtp")
);
static GstStaticPadTemplate rtpbin_recv_rtcp_sink_template =
-GST_STATIC_PAD_TEMPLATE ("recv_rtcp_sink_%u",
+ GST_STATIC_PAD_TEMPLATE ("recv_rtcp_sink_%u",
GST_PAD_SINK,
GST_PAD_REQUEST,
- GST_STATIC_CAPS ("application/x-rtcp")
+ GST_STATIC_CAPS ("application/x-rtcp;application/x-srtcp")
);
static GstStaticPadTemplate rtpbin_send_rtp_sink_template =
);
static GstStaticPadTemplate rtpbin_send_rtcp_src_template =
-GST_STATIC_PAD_TEMPLATE ("send_rtcp_src_%u",
+ GST_STATIC_PAD_TEMPLATE ("send_rtcp_src_%u",
GST_PAD_SRC,
GST_PAD_REQUEST,
- GST_STATIC_CAPS ("application/x-rtcp")
+ GST_STATIC_CAPS ("application/x-rtcp;application/x-srtcp")
);
static GstStaticPadTemplate rtpbin_send_rtp_src_template =
-GST_STATIC_PAD_TEMPLATE ("send_rtp_src_%u",
+ GST_STATIC_PAD_TEMPLATE ("send_rtp_src_%u",
GST_PAD_SRC,
GST_PAD_SOMETIMES,
- GST_STATIC_CAPS ("application/x-rtp")
+ GST_STATIC_CAPS ("application/x-rtp;application/x-srtp")
);
#define GST_RTP_BIN_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTP_BIN, GstRtpBinPrivate))
-#define GST_RTP_BIN_LOCK(bin) g_mutex_lock ((bin)->priv->bin_lock)
-#define GST_RTP_BIN_UNLOCK(bin) g_mutex_unlock ((bin)->priv->bin_lock)
+#define GST_RTP_BIN_LOCK(bin) g_mutex_lock (&(bin)->priv->bin_lock)
+#define GST_RTP_BIN_UNLOCK(bin) g_mutex_unlock (&(bin)->priv->bin_lock)
/* lock to protect dynamic callbacks, like pad-added and new ssrc. */
-#define GST_RTP_BIN_DYN_LOCK(bin) g_mutex_lock ((bin)->priv->dyn_lock)
-#define GST_RTP_BIN_DYN_UNLOCK(bin) g_mutex_unlock ((bin)->priv->dyn_lock)
+#define GST_RTP_BIN_DYN_LOCK(bin) g_mutex_lock (&(bin)->priv->dyn_lock)
+#define GST_RTP_BIN_DYN_UNLOCK(bin) g_mutex_unlock (&(bin)->priv->dyn_lock)
/* lock for shutdown */
#define GST_RTP_BIN_SHUTDOWN_LOCK(bin,label) \
struct _GstRtpBinPrivate
{
- GMutex *bin_lock;
+ GMutex bin_lock;
/* lock protecting dynamic adding/removing */
- GMutex *dyn_lock;
+ GMutex dyn_lock;
/* if we are shutting down or not */
gint shutdown;
/* UNIX (ntp) time of last SR sync used */
guint64 last_unix;
+
+ /* list of extra elements */
+ GList *elements;
};
/* signals and args */
SIGNAL_ON_TIMEOUT,
SIGNAL_ON_SENDER_TIMEOUT,
SIGNAL_ON_NPT_STOP,
+
+ SIGNAL_REQUEST_RTP_ENCODER,
+ SIGNAL_REQUEST_RTP_DECODER,
+ SIGNAL_REQUEST_RTCP_ENCODER,
+ SIGNAL_REQUEST_RTCP_DECODER,
+
+ SIGNAL_NEW_JITTERBUFFER,
+
LAST_SIGNAL
};
#define DEFAULT_LATENCY_MS 200
+#define DEFAULT_DROP_ON_LATENCY FALSE
#define DEFAULT_SDES NULL
#define DEFAULT_DO_LOST FALSE
#define DEFAULT_IGNORE_PT FALSE
#define DEFAULT_USE_PIPELINE_CLOCK FALSE
#define DEFAULT_RTCP_SYNC GST_RTP_BIN_RTCP_SYNC_ALWAYS
#define DEFAULT_RTCP_SYNC_INTERVAL 0
+#define DEFAULT_DO_SYNC_EVENT FALSE
+#define DEFAULT_DO_RETRANSMISSION FALSE
enum
{
PROP_0,
PROP_LATENCY,
+ PROP_DROP_ON_LATENCY,
PROP_SDES,
PROP_DO_LOST,
PROP_IGNORE_PT,
PROP_AUTOREMOVE,
PROP_BUFFER_MODE,
PROP_USE_PIPELINE_CLOCK,
+ PROP_DO_SYNC_EVENT,
+ PROP_DO_RETRANSMISSION,
PROP_LAST
};
GstRtpBinSession * session);
static void payload_type_change (GstElement * element, guint pt,
GstRtpBinSession * session);
+static void remove_recv_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session);
+static void remove_recv_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session);
+static void remove_send_rtp (GstRtpBin * rtpbin, GstRtpBinSession * session);
+static void remove_rtcp (GstRtpBin * rtpbin, GstRtpBinSession * session);
static void free_client (GstRtpBinClient * client, GstRtpBin * bin);
-static void free_stream (GstRtpBinStream * stream);
+static void free_stream (GstRtpBinStream * stream, GstRtpBin * bin);
/* Manages the RTP stream for one SSRC.
*
gint64 clock_base;
};
-#define GST_RTP_SESSION_LOCK(sess) g_mutex_lock ((sess)->lock)
-#define GST_RTP_SESSION_UNLOCK(sess) g_mutex_unlock ((sess)->lock)
+#define GST_RTP_SESSION_LOCK(sess) g_mutex_lock (&(sess)->lock)
+#define GST_RTP_SESSION_UNLOCK(sess) g_mutex_unlock (&(sess)->lock)
/* Manages the receiving end of the packets.
*
gulong demux_newpad_sig;
gulong demux_padremoved_sig;
- GMutex *lock;
+ GMutex lock;
/* list of GstRtpBinStream */
GSList *streams;
+ /* list of encoders */
+ GSList *encoders;
+
+ /* list of decoders */
+ GSList *decoders;
+
/* mapping of payload type to caps */
GHashTable *ptmap;
GstRtpBinSession * session)
{
GstRtpBinStream *stream = NULL;
+ GstRtpBin *rtpbin;
+
+ rtpbin = session->bin;
+
+ GST_RTP_BIN_LOCK (rtpbin);
GST_RTP_SESSION_LOCK (session);
if ((stream = find_stream_by_ssrc (session, ssrc)))
GST_RTP_SESSION_UNLOCK (session);
if (stream)
- free_stream (stream);
+ free_stream (stream, rtpbin);
+
+ GST_RTP_BIN_UNLOCK (rtpbin);
}
/* create a session with the given id. Must be called with RTP_BIN_LOCK */
GstElement *session, *demux;
GstState target;
- if (!(session = gst_element_factory_make ("gstrtpsession", NULL)))
+ if (!(session = gst_element_factory_make ("rtpsession", NULL)))
goto no_session;
- if (!(demux = gst_element_factory_make ("gstrtpssrcdemux", NULL)))
+ if (!(demux = gst_element_factory_make ("rtpssrcdemux", NULL)))
goto no_demux;
sess = g_new0 (GstRtpBinSession, 1);
- sess->lock = g_mutex_new ();
+ g_mutex_init (&sess->lock);
sess->id = id;
sess->bin = rtpbin;
sess->session = session;
/* ERRORS */
no_session:
{
- g_warning ("gstrtpbin: could not create gstrtpsession element");
+ g_warning ("rtpbin: could not create rtpsession element");
return NULL;
}
no_demux:
{
gst_object_unref (session);
- g_warning ("gstrtpbin: could not create gstrtpssrcdemux element");
+ g_warning ("rtpbin: could not create rtpssrcdemux element");
return NULL;
}
}
+static gboolean
+bin_manage_element (GstRtpBin * bin, GstElement * element)
+{
+ GstRtpBinPrivate *priv = bin->priv;
+
+ if (g_list_find (priv->elements, element)) {
+ GST_DEBUG_OBJECT (bin, "requested element %p already in bin", element);
+ } else {
+ GST_DEBUG_OBJECT (bin, "adding requested element %p", element);
+ if (!gst_bin_add (GST_BIN_CAST (bin), element))
+ goto add_failed;
+ if (!gst_element_sync_state_with_parent (element))
+ GST_WARNING_OBJECT (bin, "unable to sync element state with rtpbin");
+ }
+ /* we add the element multiple times, each we need an equal number of
+ * removes to really remove the element from the bin */
+ priv->elements = g_list_prepend (priv->elements, element);
+
+ return TRUE;
+
+ /* ERRORS */
+add_failed:
+ {
+ GST_WARNING_OBJECT (bin, "unable to add element");
+ return FALSE;
+ }
+}
+
static void
-free_session (GstRtpBinSession * sess, GstRtpBin * bin)
+remove_bin_element (GstElement * element, GstRtpBin * bin)
{
- GSList *client_walk;
+ GstRtpBinPrivate *priv = bin->priv;
+ GList *find;
+
+ find = g_list_find (priv->elements, element);
+ if (find) {
+ priv->elements = g_list_delete_link (priv->elements, find);
+ if (!g_list_find (priv->elements, element))
+ gst_bin_remove (GST_BIN_CAST (bin), element);
+ else
+ gst_object_unref (element);
+ }
+}
+
+/* called with RTP_BIN_LOCK */
+static void
+free_session (GstRtpBinSession * sess, GstRtpBin * bin)
+{
GST_DEBUG_OBJECT (bin, "freeing session %p", sess);
gst_element_set_locked_state (sess->demux, TRUE);
gst_element_set_state (sess->demux, GST_STATE_NULL);
gst_element_set_state (sess->session, GST_STATE_NULL);
- if (sess->recv_rtp_sink != NULL) {
- gst_element_release_request_pad (sess->session, sess->recv_rtp_sink);
- gst_object_unref (sess->recv_rtp_sink);
- }
- if (sess->recv_rtp_src != NULL)
- gst_object_unref (sess->recv_rtp_src);
- if (sess->recv_rtcp_sink != NULL) {
- gst_element_release_request_pad (sess->session, sess->recv_rtcp_sink);
- gst_object_unref (sess->recv_rtcp_sink);
- }
- if (sess->sync_src != NULL)
- gst_object_unref (sess->sync_src);
- if (sess->send_rtp_sink != NULL) {
- gst_element_release_request_pad (sess->session, sess->send_rtp_sink);
- gst_object_unref (sess->send_rtp_sink);
- }
- if (sess->send_rtp_src != NULL)
- gst_object_unref (sess->send_rtp_src);
- if (sess->send_rtcp_src != NULL) {
- gst_element_release_request_pad (sess->session, sess->send_rtcp_src);
- gst_object_unref (sess->send_rtcp_src);
- }
+ remove_recv_rtp (bin, sess);
+ remove_recv_rtcp (bin, sess);
+ remove_send_rtp (bin, sess);
+ remove_rtcp (bin, sess);
gst_bin_remove (GST_BIN_CAST (bin), sess->session);
gst_bin_remove (GST_BIN_CAST (bin), sess->demux);
- /* remove any references in bin->clients to the streams in sess->streams */
- client_walk = bin->clients;
- while (client_walk) {
- GSList *client_node = client_walk;
- GstRtpBinClient *client = (GstRtpBinClient *) client_node->data;
- GSList *stream_walk = client->streams;
-
- while (stream_walk) {
- GSList *stream_node = stream_walk;
- GstRtpBinStream *stream = (GstRtpBinStream *) stream_node->data;
- GSList *inner_walk;
-
- stream_walk = g_slist_next (stream_walk);
-
- for (inner_walk = sess->streams; inner_walk;
- inner_walk = g_slist_next (inner_walk)) {
- if ((GstRtpBinStream *) inner_walk->data == stream) {
- client->streams = g_slist_delete_link (client->streams, stream_node);
- --client->nstreams;
- break;
- }
- }
- }
- client_walk = g_slist_next (client_walk);
+ g_slist_foreach (sess->encoders, (GFunc) remove_bin_element, bin);
+ g_slist_free (sess->encoders);
- g_assert ((client->streams && client->nstreams > 0) || (!client->streams
- && client->streams == 0));
- if (client->nstreams == 0) {
- free_client (client, bin);
- bin->clients = g_slist_delete_link (bin->clients, client_node);
- }
- }
+ g_slist_foreach (sess->decoders, (GFunc) remove_bin_element, bin);
+ g_slist_free (sess->decoders);
- g_slist_foreach (sess->streams, (GFunc) free_stream, NULL);
+ g_slist_foreach (sess->streams, (GFunc) free_stream, bin);
g_slist_free (sess->streams);
- g_mutex_free (sess->lock);
+ g_mutex_clear (&sess->lock);
g_hash_table_destroy (sess->ptmap);
g_free (sess);
return internal_session;
}
+static GstElement *
+gst_rtp_bin_request_encoder (GstRtpBin * bin, guint session_id)
+{
+ GST_DEBUG_OBJECT (bin, "return NULL encoder");
+ return NULL;
+}
+
+static GstElement *
+gst_rtp_bin_request_decoder (GstRtpBin * bin, guint session_id)
+{
+ GST_DEBUG_OBJECT (bin, "return NULL decoder");
+ return NULL;
+}
+
static void
gst_rtp_bin_propagate_property_to_jitterbuffer (GstRtpBin * bin,
const gchar * name, const GValue * value)
clock_time = gst_clock_get_time (clock);
if (bin->use_pipeline_clock) {
- ntpns = clock_time;
+ ntpns = clock_time - base_time;
} else {
GTimeVal current;
static void
stream_set_ts_offset (GstRtpBin * bin, GstRtpBinStream * stream,
- gint64 ts_offset)
+ gint64 ts_offset, gboolean check)
{
gint64 prev_ts_offset;
"ts-offset %" G_GINT64_FORMAT ", prev %" G_GINT64_FORMAT
", diff: %" G_GINT64_FORMAT, ts_offset, prev_ts_offset, diff);
- /* only change diff when it changed more than 4 milliseconds. This
- * compensates for rounding errors in NTP to RTP timestamp
- * conversions */
- if (ABS (diff) > 4 * GST_MSECOND) {
- if (ABS (diff) < (3 * GST_SECOND)) {
- g_object_set (stream->buffer, "ts-offset", ts_offset, NULL);
- } else {
+ if (check) {
+ /* only change diff when it changed more than 4 milliseconds. This
+ * compensates for rounding errors in NTP to RTP timestamp
+ * conversions */
+ if (ABS (diff) < 4 * GST_MSECOND) {
+ GST_DEBUG_OBJECT (bin, "offset too small, ignoring");
+ return;
+ }
+ if (ABS (diff) > (3 * GST_SECOND)) {
GST_WARNING_OBJECT (bin, "offset unusually large, ignoring");
+ return;
}
- } else {
- GST_DEBUG_OBJECT (bin, "offset too small, ignoring");
}
+ g_object_set (stream->buffer, "ts-offset", ts_offset, NULL);
}
GST_DEBUG_OBJECT (bin, "stream SSRC %08x, delta %" G_GINT64_FORMAT,
stream->ssrc, ts_offset);
}
+static void
+gst_rtp_bin_send_sync_event (GstRtpBinStream * stream)
+{
+ if (stream->bin->send_sync_event) {
+ GstEvent *event;
+ GstPad *srcpad;
+
+ GST_DEBUG_OBJECT (stream->bin,
+ "sending GstRTCPSRReceived event downstream");
+
+ event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
+ gst_structure_new_empty ("GstRTCPSRReceived"));
+
+ srcpad = gst_element_get_static_pad (stream->buffer, "src");
+ gst_pad_push_event (srcpad, event);
+ gst_object_unref (srcpad);
+ }
+}
+
/* associate a stream to the given CNAME. This will make sure all streams for
* that CNAME are synchronized together.
* Must be called with GST_RTP_BIN_LOCK */
/* combine to get the final diff to apply to the running_time */
stream->rt_delta = rtdiff - ntpdiff;
- stream_set_ts_offset (bin, stream, stream->rt_delta);
+ stream_set_ts_offset (bin, stream, stream->rt_delta, FALSE);
} else {
gint64 min, rtp_min, clock_base = stream->clock_base;
gboolean all_sync, use_rtp;
* now equating rtptime obtained from RTP-Info,
* where the large time represent the otherwise irrelevant npt/ntp time */
stream->rtp_delta = (GST_SECOND << 28) - rtp_clock_base;
+ } else {
+ clock_base = rtp_clock_base;
}
+ all_sync = TRUE;
for (walk = client->streams; walk; walk = g_slist_next (walk)) {
GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
/* arrange to re-sync for each stream upon significant change,
* e.g. post-seek */
- all_sync = (stream->clock_base == clock_base);
+ all_sync = all_sync && (stream->clock_base == clock_base);
stream->clock_base = clock_base;
/* may need init performed above later on, but nothing more to do now */
else
ts_offset = ostream->rt_delta - min;
- stream_set_ts_offset (bin, ostream, ts_offset);
+ stream_set_ts_offset (bin, ostream, ts_offset, TRUE);
}
}
+ gst_rtp_bin_send_sync_event (stream);
+
return;
}
guint64 clock_base;
guint64 extrtptime;
GstBuffer *buffer;
- GstRTCPBuffer rtcp = { NULL };
+ GstRTCPBuffer rtcp = { NULL, };
bin = stream->bin;
rtpbin = session->bin;
- if (!(buffer = gst_element_factory_make ("gstrtpjitterbuffer", NULL)))
+ if (!(buffer = gst_element_factory_make ("rtpjitterbuffer", NULL)))
goto no_jitterbuffer;
if (!rtpbin->ignore_pt)
- if (!(demux = gst_element_factory_make ("gstrtpptdemux", NULL)))
+ if (!(demux = gst_element_factory_make ("rtpptdemux", NULL)))
goto no_demux;
-
stream = g_new0 (GstRtpBinStream, 1);
stream->ssrc = ssrc;
stream->bin = rtpbin;
/* configure latency and packet lost */
g_object_set (buffer, "latency", rtpbin->latency_ms, NULL);
+ g_object_set (buffer, "drop-on-latency", rtpbin->drop_on_latency, NULL);
g_object_set (buffer, "do-lost", rtpbin->do_lost, NULL);
g_object_set (buffer, "mode", rtpbin->buffer_mode, NULL);
+ g_object_set (buffer, "do-retransmission", rtpbin->do_retransmission, NULL);
+
+ g_signal_emit (rtpbin, gst_rtp_bin_signals[SIGNAL_NEW_JITTERBUFFER], 0,
+ buffer, session->id, ssrc);
if (!rtpbin->ignore_pt)
gst_bin_add (GST_BIN_CAST (rtpbin), demux);
/* link stuff */
if (demux)
- gst_element_link (buffer, demux);
+ gst_element_link_pads_full (buffer, "src", demux, "sink",
+ GST_PAD_LINK_CHECK_NOTHING);
if (rtpbin->buffering) {
guint64 last_out;
/* ERRORS */
no_jitterbuffer:
{
- g_warning ("gstrtpbin: could not create gstrtpjitterbuffer element");
+ g_warning ("rtpbin: could not create rtpjitterbuffer element");
return NULL;
}
no_demux:
{
gst_object_unref (buffer);
- g_warning ("gstrtpbin: could not create gstrtpptdemux element");
+ g_warning ("rtpbin: could not create rtpptdemux element");
return NULL;
}
}
+/* called with RTP_BIN_LOCK */
static void
-free_stream (GstRtpBinStream * stream)
+free_stream (GstRtpBinStream * stream, GstRtpBin * bin)
{
- GstRtpBinSession *session;
+ GSList *clients, *next_client;
- session = stream->session;
+ GST_DEBUG_OBJECT (bin, "freeing stream %p", stream);
if (stream->demux) {
g_signal_handler_disconnect (stream->demux, stream->demux_newpad_sig);
if (stream->demux)
g_signal_handler_disconnect (stream->demux, stream->demux_padremoved_sig);
- gst_bin_remove (GST_BIN_CAST (session->bin), stream->buffer);
+ gst_bin_remove (GST_BIN_CAST (bin), stream->buffer);
if (stream->demux)
- gst_bin_remove (GST_BIN_CAST (session->bin), stream->demux);
+ gst_bin_remove (GST_BIN_CAST (bin), stream->demux);
+
+ for (clients = bin->clients; clients; clients = next_client) {
+ GstRtpBinClient *client = (GstRtpBinClient *) clients->data;
+ GSList *streams, *next_stream;
+
+ next_client = g_slist_next (clients);
+
+ for (streams = client->streams; streams; streams = next_stream) {
+ GstRtpBinStream *ostream = (GstRtpBinStream *) streams->data;
+ next_stream = g_slist_next (streams);
+
+ if (ostream == stream) {
+ client->streams = g_slist_delete_link (client->streams, streams);
+ /* If this was the last stream belonging to this client,
+ * clean up the client. */
+ if (--client->nstreams == 0) {
+ bin->clients = g_slist_delete_link (bin->clients, clients);
+ free_client (client, bin);
+ break;
+ }
+ }
+ }
+ }
g_free (stream);
}
#define gst_rtp_bin_parent_class parent_class
G_DEFINE_TYPE (GstRtpBin, gst_rtp_bin, GST_TYPE_BIN);
+static gboolean
+_gst_element_accumulator (GSignalInvocationHint * ihint,
+ GValue * return_accu, const GValue * handler_return, gpointer dummy)
+{
+ GstElement *element;
+
+ element = g_value_get_object (handler_return);
+ GST_DEBUG ("got element %" GST_PTR_FORMAT, element);
+
+ if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
+ g_value_set_object (return_accu, element);
+
+ /* stop emission if we have an element */
+ return (element == NULL);
+}
+
static void
gst_rtp_bin_class_init (GstRtpBinClass * klass)
{
G_MAXUINT, DEFAULT_LATENCY_MS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, PROP_DROP_ON_LATENCY,
+ g_param_spec_boolean ("drop-on-latency",
+ "Drop buffers when maximum latency is reached",
+ "Tells the jitterbuffer to never exceed the given latency in size",
+ DEFAULT_DROP_ON_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
/**
* GstRtpBin::request-pt-map:
* @rtpbin: the object which received the signal
gst_rtp_bin_signals[SIGNAL_REQUEST_PT_MAP] =
g_signal_new ("request-pt-map", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, request_pt_map),
- NULL, NULL, gst_rtp_bin_marshal_BOXED__UINT_UINT, GST_TYPE_CAPS, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, GST_TYPE_CAPS, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
/**
* GstRtpBin::payload-type-change:
* @pt: the pt
*
* Signal that the current payload type changed to @pt in @session.
- *
- * Since: 0.10.17
*/
gst_rtp_bin_signals[SIGNAL_PAYLOAD_TYPE_CHANGE] =
g_signal_new ("payload-type-change", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, payload_type_change),
- NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
/**
* GstRtpBin::clear-pt-map:
gst_rtp_bin_signals[SIGNAL_GET_INTERNAL_SESSION] =
g_signal_new ("get-internal-session", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
- get_internal_session), NULL, NULL, gst_rtp_bin_marshal_OBJECT__UINT,
+ get_internal_session), NULL, NULL, g_cclosure_marshal_generic,
RTP_TYPE_SESSION, 1, G_TYPE_UINT);
/**
gst_rtp_bin_signals[SIGNAL_ON_NEW_SSRC] =
g_signal_new ("on-new-ssrc", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_new_ssrc),
- NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
/**
* GstRtpBin::on-ssrc-collision:
* @rtpbin: the object which received the signal
gst_rtp_bin_signals[SIGNAL_ON_SSRC_COLLISION] =
g_signal_new ("on-ssrc-collision", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_collision),
- NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
/**
* GstRtpBin::on-ssrc-validated:
* @rtpbin: the object which received the signal
gst_rtp_bin_signals[SIGNAL_ON_SSRC_VALIDATED] =
g_signal_new ("on-ssrc-validated", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_validated),
- NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
/**
* GstRtpBin::on-ssrc-active:
* @rtpbin: the object which received the signal
gst_rtp_bin_signals[SIGNAL_ON_SSRC_ACTIVE] =
g_signal_new ("on-ssrc-active", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_active),
- NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
/**
* GstRtpBin::on-ssrc-sdes:
* @rtpbin: the object which received the signal
gst_rtp_bin_signals[SIGNAL_ON_SSRC_SDES] =
g_signal_new ("on-ssrc-sdes", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_sdes),
- NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
/**
* GstRtpBin::on-bye-ssrc:
gst_rtp_bin_signals[SIGNAL_ON_BYE_SSRC] =
g_signal_new ("on-bye-ssrc", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_ssrc),
- NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
/**
* GstRtpBin::on-bye-timeout:
* @rtpbin: the object which received the signal
gst_rtp_bin_signals[SIGNAL_ON_BYE_TIMEOUT] =
g_signal_new ("on-bye-timeout", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_timeout),
- NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
/**
* GstRtpBin::on-timeout:
* @rtpbin: the object which received the signal
gst_rtp_bin_signals[SIGNAL_ON_TIMEOUT] =
g_signal_new ("on-timeout", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_timeout),
- NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
/**
* GstRtpBin::on-sender-timeout:
* @rtpbin: the object which received the signal
gst_rtp_bin_signals[SIGNAL_ON_SENDER_TIMEOUT] =
g_signal_new ("on-sender-timeout", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_sender_timeout),
- NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
/**
* GstRtpBin::on-npt-stop:
gst_rtp_bin_signals[SIGNAL_ON_NPT_STOP] =
g_signal_new ("on-npt-stop", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_npt_stop),
- NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
+ NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, G_TYPE_UINT,
+ G_TYPE_UINT);
+
+ /**
+ * GstRtpBin::request-rtp-encoder:
+ * @rtpbin: the object which received the signal
+ * @session: the session
+ *
+ * Request an RTP encoder element for the given @session. The encoder
+ * element will be added to the bin if not previously added.
+ *
+ * If no handler is connected, no encoder will be used.
+ *
+ * Since: 1.4
+ */
+ gst_rtp_bin_signals[SIGNAL_REQUEST_RTP_ENCODER] =
+ g_signal_new ("request-rtp-encoder", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
+ request_rtp_encoder), _gst_element_accumulator, NULL,
+ g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
+
+ /**
+ * GstRtpBin::request-rtp-decoder:
+ * @rtpbin: the object which received the signal
+ * @session: the session
+ *
+ * Request an RTP decoder element for the given @session. The decoder
+ * element will be added to the bin if not previously added.
+ *
+ * If no handler is connected, no encoder will be used.
+ *
+ * Since: 1.4
+ */
+ gst_rtp_bin_signals[SIGNAL_REQUEST_RTP_DECODER] =
+ g_signal_new ("request-rtp-decoder", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
+ request_rtp_decoder), _gst_element_accumulator, NULL,
+ g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
+
+ /**
+ * GstRtpBin::request-rtcp-encoder:
+ * @rtpbin: the object which received the signal
+ * @session: the session
+ *
+ * Request an RTCP encoder element for the given @session. The encoder
+ * element will be added to the bin if not previously added.
+ *
+ * If no handler is connected, no encoder will be used.
+ *
+ * Since: 1.4
+ */
+ gst_rtp_bin_signals[SIGNAL_REQUEST_RTCP_ENCODER] =
+ g_signal_new ("request-rtcp-encoder", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
+ request_rtcp_encoder), _gst_element_accumulator, NULL,
+ g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
+
+ /**
+ * GstRtpBin::request-rtcp-decoder:
+ * @rtpbin: the object which received the signal
+ * @session: the session
+ *
+ * Request an RTCP decoder element for the given @session. The decoder
+ * element will be added to the bin if not previously added.
+ *
+ * If no handler is connected, no encoder will be used.
+ *
+ * Since: 1.4
+ */
+ gst_rtp_bin_signals[SIGNAL_REQUEST_RTCP_DECODER] =
+ g_signal_new ("request-rtcp-decoder", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
+ request_rtcp_decoder), _gst_element_accumulator, NULL,
+ g_cclosure_marshal_generic, GST_TYPE_ELEMENT, 1, G_TYPE_UINT);
+
+ /**
+ * GstRtpBin::new-jitterbuffer:
+ * @rtpbin: the object which received the signal
+ * @jitterbuffer: the new jitterbuffer
+ * @session: the session
+ * @ssrc: the SSRC
+ *
+ * Notify that a new @jitterbuffer was created for @session and @ssrc.
+ * This signal can, for example, be used to configure @jitterbuffer.
+ *
+ * Since: 1.4
+ */
+ gst_rtp_bin_signals[SIGNAL_NEW_JITTERBUFFER] =
+ g_signal_new ("new-jitterbuffer", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass,
+ new_jitterbuffer), NULL, NULL, g_cclosure_marshal_generic,
+ G_TYPE_NONE, 3, GST_TYPE_ELEMENT, G_TYPE_UINT, G_TYPE_UINT);
g_object_class_install_property (gobject_class, PROP_SDES,
g_param_spec_boxed ("sdes", "SDES",
g_object_class_install_property (gobject_class, PROP_USE_PIPELINE_CLOCK,
g_param_spec_boolean ("use-pipeline-clock", "Use pipeline clock",
- "Use the pipeline clock to set the NTP time in the RTCP SR messages",
+ "Use the pipeline running-time to set the NTP time in the RTCP SR messages",
DEFAULT_USE_PIPELINE_CLOCK,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
- * GstRtpBin::buffer-mode:
+ * GstRtpBin:buffer-mode:
*
* Control the buffering and timestamping mode used by the jitterbuffer.
- *
- * Since: 0.10.17
*/
g_object_class_install_property (gobject_class, PROP_BUFFER_MODE,
g_param_spec_enum ("buffer-mode", "Buffer Mode",
"Control the buffering algorithm in use", RTP_TYPE_JITTER_BUFFER_MODE,
DEFAULT_BUFFER_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
- * GstRtpBin::ntp-sync:
- *
- * Synchronize received streams to the NTP clock. When the NTP clock is shared
- * between the receivers and the senders (such as when using ntpd) this option
- * can be used to synchronize receivers on multiple machines.
+ * GstRtpBin:ntp-sync:
*
- * Since: 0.10.21
+ * Set the NTP time from the sender reports as the running-time on the
+ * buffers. When both the sender and receiver have sychronized
+ * running-time, i.e. when the clock and base-time is shared
+ * between the receivers and the and the senders, this option can be
+ * used to synchronize receivers on multiple machines.
*/
g_object_class_install_property (gobject_class, PROP_NTP_SYNC,
g_param_spec_boolean ("ntp-sync", "Sync on NTP clock",
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
- * GstRtpBin::rtcp-sync:
+ * GstRtpBin:rtcp-sync:
*
* If not synchronizing (directly) to the NTP clock, determines how to sync
* the various streams.
- *
- * Since: 0.10.31
*/
g_object_class_install_property (gobject_class, PROP_RTCP_SYNC,
g_param_spec_enum ("rtcp-sync", "RTCP Sync",
DEFAULT_RTCP_SYNC, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
- * GstRtpBin::rtcp-sync-interval:
+ * GstRtpBin:rtcp-sync-interval:
*
* Determines how often to sync streams using RTCP data.
- *
- * Since: 0.10.31
*/
g_object_class_install_property (gobject_class, PROP_RTCP_SYNC_INTERVAL,
g_param_spec_uint ("rtcp-sync-interval", "RTCP Sync Interval",
0, G_MAXUINT, DEFAULT_RTCP_SYNC_INTERVAL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, PROP_DO_SYNC_EVENT,
+ g_param_spec_boolean ("do-sync-event", "Do Sync Event",
+ "Send event downstream when a stream is synchronized to the sender",
+ DEFAULT_DO_SYNC_EVENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_DO_RETRANSMISSION,
+ g_param_spec_boolean ("do-retransmission", "Do retransmission",
+ "Send an event downstream to request packet retransmission",
+ DEFAULT_DO_RETRANSMISSION,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_bin_change_state);
gstelement_class->request_new_pad =
GST_DEBUG_FUNCPTR (gst_rtp_bin_request_new_pad);
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&rtpbin_send_rtp_src_template));
- gst_element_class_set_details_simple (gstelement_class, "RTP Bin",
+ gst_element_class_set_static_metadata (gstelement_class, "RTP Bin",
"Filter/Network/RTP",
"Real-Time Transport Protocol bin",
"Wim Taymans <wim.taymans@gmail.com>");
klass->reset_sync = GST_DEBUG_FUNCPTR (gst_rtp_bin_reset_sync);
klass->get_internal_session =
GST_DEBUG_FUNCPTR (gst_rtp_bin_get_internal_session);
+ klass->request_rtp_encoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_encoder);
+ klass->request_rtp_decoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_decoder);
+ klass->request_rtcp_encoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_encoder);
+ klass->request_rtcp_decoder = GST_DEBUG_FUNCPTR (gst_rtp_bin_request_decoder);
GST_DEBUG_CATEGORY_INIT (gst_rtp_bin_debug, "rtpbin", 0, "RTP bin");
}
static void
gst_rtp_bin_init (GstRtpBin * rtpbin)
{
- gchar *str;
+ gchar *cname;
rtpbin->priv = GST_RTP_BIN_GET_PRIVATE (rtpbin);
- rtpbin->priv->bin_lock = g_mutex_new ();
- rtpbin->priv->dyn_lock = g_mutex_new ();
+ g_mutex_init (&rtpbin->priv->bin_lock);
+ g_mutex_init (&rtpbin->priv->dyn_lock);
rtpbin->latency_ms = DEFAULT_LATENCY_MS;
rtpbin->latency_ns = DEFAULT_LATENCY_MS * GST_MSECOND;
+ rtpbin->drop_on_latency = DEFAULT_DROP_ON_LATENCY;
rtpbin->do_lost = DEFAULT_DO_LOST;
rtpbin->ignore_pt = DEFAULT_IGNORE_PT;
rtpbin->ntp_sync = DEFAULT_NTP_SYNC;
rtpbin->priv->autoremove = DEFAULT_AUTOREMOVE;
rtpbin->buffer_mode = DEFAULT_BUFFER_MODE;
rtpbin->use_pipeline_clock = DEFAULT_USE_PIPELINE_CLOCK;
+ rtpbin->send_sync_event = DEFAULT_DO_SYNC_EVENT;
+ rtpbin->do_retransmission = DEFAULT_DO_RETRANSMISSION;
/* some default SDES entries */
- str = g_strdup_printf ("%s@%s", g_get_user_name (), g_get_host_name ());
+ cname = g_strdup_printf ("user%u@host-%x", g_random_int (), g_random_int ());
rtpbin->sdes = gst_structure_new ("application/x-rtp-source-sdes",
- "cname", G_TYPE_STRING, str,
- "name", G_TYPE_STRING, g_get_real_name (),
- "tool", G_TYPE_STRING, "GStreamer", NULL);
- g_free (str);
+ "cname", G_TYPE_STRING, cname, "tool", G_TYPE_STRING, "GStreamer", NULL);
+ g_free (cname);
}
static void
rtpbin = GST_RTP_BIN (object);
+ GST_RTP_BIN_LOCK (rtpbin);
GST_DEBUG_OBJECT (object, "freeing sessions");
g_slist_foreach (rtpbin->sessions, (GFunc) free_session, rtpbin);
g_slist_free (rtpbin->sessions);
rtpbin->sessions = NULL;
- GST_DEBUG_OBJECT (object, "freeing clients");
- g_slist_foreach (rtpbin->clients, (GFunc) free_client, rtpbin);
- g_slist_free (rtpbin->clients);
- rtpbin->clients = NULL;
+ GST_RTP_BIN_UNLOCK (rtpbin);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
if (rtpbin->sdes)
gst_structure_free (rtpbin->sdes);
- g_mutex_free (rtpbin->priv->bin_lock);
- g_mutex_free (rtpbin->priv->dyn_lock);
+ g_mutex_clear (&rtpbin->priv->bin_lock);
+ g_mutex_clear (&rtpbin->priv->dyn_lock);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/* propagate the property down to the jitterbuffer */
gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin, "latency", value);
break;
+ case PROP_DROP_ON_LATENCY:
+ GST_RTP_BIN_LOCK (rtpbin);
+ rtpbin->drop_on_latency = g_value_get_boolean (value);
+ GST_RTP_BIN_UNLOCK (rtpbin);
+ /* propagate the property down to the jitterbuffer */
+ gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
+ "drop-on-latency", value);
+ break;
case PROP_SDES:
gst_rtp_bin_set_sdes_struct (rtpbin, g_value_get_boxed (value));
break;
GST_RTP_BIN_UNLOCK (rtpbin);
}
break;
+ case PROP_DO_SYNC_EVENT:
+ rtpbin->send_sync_event = g_value_get_boolean (value);
+ break;
case PROP_BUFFER_MODE:
GST_RTP_BIN_LOCK (rtpbin);
rtpbin->buffer_mode = g_value_get_enum (value);
/* propagate the property down to the jitterbuffer */
gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin, "mode", value);
break;
+ case PROP_DO_RETRANSMISSION:
+ GST_RTP_BIN_LOCK (rtpbin);
+ rtpbin->do_retransmission = g_value_get_boolean (value);
+ GST_RTP_BIN_UNLOCK (rtpbin);
+ gst_rtp_bin_propagate_property_to_jitterbuffer (rtpbin,
+ "do-retransmission", value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
g_value_set_uint (value, rtpbin->latency_ms);
GST_RTP_BIN_UNLOCK (rtpbin);
break;
+ case PROP_DROP_ON_LATENCY:
+ GST_RTP_BIN_LOCK (rtpbin);
+ g_value_set_boolean (value, rtpbin->drop_on_latency);
+ GST_RTP_BIN_UNLOCK (rtpbin);
+ break;
case PROP_SDES:
g_value_take_boxed (value, gst_rtp_bin_get_sdes_struct (rtpbin));
break;
case PROP_USE_PIPELINE_CLOCK:
g_value_set_boolean (value, rtpbin->use_pipeline_clock);
break;
+ case PROP_DO_SYNC_EVENT:
+ g_value_set_boolean (value, rtpbin->send_sync_event);
+ break;
+ case PROP_DO_RETRANSMISSION:
+ GST_RTP_BIN_LOCK (rtpbin);
+ g_value_set_boolean (value, rtpbin->do_retransmission);
+ GST_RTP_BIN_UNLOCK (rtpbin);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
return res;
}
+static GstElement *
+session_request_encoder (GstRtpBinSession * session, guint signal)
+{
+ GstElement *encoder = NULL;
+ GstRtpBin *bin = session->bin;
+
+ g_signal_emit (bin, gst_rtp_bin_signals[signal], 0, session->id, &encoder);
+
+ if (encoder) {
+ if (!bin_manage_element (bin, encoder))
+ goto manage_failed;
+ session->encoders = g_slist_prepend (session->encoders, encoder);
+ }
+ return encoder;
+
+ /* ERRORS */
+manage_failed:
+ {
+ GST_WARNING_OBJECT (bin, "unable to manage encoder");
+ gst_object_unref (encoder);
+ return NULL;
+ }
+}
+
+static GstElement *
+session_request_decoder (GstRtpBinSession * session, guint signal)
+{
+ GstElement *decoder = NULL;
+ GstRtpBin *bin = session->bin;
+
+ g_signal_emit (bin, gst_rtp_bin_signals[signal], 0, session->id, &decoder);
+
+ if (decoder) {
+ if (!bin_manage_element (bin, decoder))
+ goto manage_failed;
+ session->decoders = g_slist_prepend (session->decoders, decoder);
+ }
+ return decoder;
+
+ /* ERRORS */
+manage_failed:
+ {
+ GST_WARNING_OBJECT (bin, "unable to manage decoder");
+ gst_object_unref (decoder);
+ return NULL;
+ }
+}
+
/* a new pad (SSRC) was created in @session. This signal is emited from the
* payload demuxer. */
static void
srcpad = gst_element_get_static_pad (element, padname);
g_free (padname);
sinkpad = gst_element_get_static_pad (stream->buffer, "sink");
- gst_pad_link (srcpad, sinkpad);
+ gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_NOTHING);
gst_object_unref (sinkpad);
gst_object_unref (srcpad);
srcpad = gst_element_get_static_pad (element, padname);
g_free (padname);
sinkpad = gst_element_get_request_pad (stream->buffer, "sink_rtcp");
- gst_pad_link (srcpad, sinkpad);
+ gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_NOTHING);
gst_object_unref (sinkpad);
gst_object_unref (srcpad);
stream->demux_ptchange_sig = g_signal_connect (stream->demux,
"payload-type-change", (GCallback) payload_type_change, session);
} else {
- /* add gstrtpjitterbuffer src pad to pads */
+ /* add rtpjitterbuffer src pad to pads */
GstElementClass *klass;
GstPadTemplate *templ;
gchar *padname;
static GstPad *
create_recv_rtp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
{
- GstPad *sinkdpad;
guint sessid;
+ GstElement *decoder;
+ GstPad *sinkdpad, *decsink;
GstRtpBinSession *session;
- GstPadLinkReturn lres;
/* first get the session number */
if (name == NULL || sscanf (name, "recv_rtp_sink_%u", &sessid) != 1)
g_signal_connect (session->recv_rtp_sink, "notify::caps",
(GCallback) caps_changed, session);
+ GST_DEBUG_OBJECT (rtpbin, "requesting RTP decoder");
+ decoder = session_request_decoder (session, SIGNAL_REQUEST_RTP_DECODER);
+ if (decoder) {
+ GstPad *decsrc;
+ GstPadLinkReturn ret;
+
+ GST_DEBUG_OBJECT (rtpbin, "linking RTP decoder");
+ decsink = gst_element_get_static_pad (decoder, "rtp_sink");
+ decsrc = gst_element_get_static_pad (decoder, "rtp_src");
+
+ if (decsink == NULL)
+ goto dec_sink_failed;
+
+ if (decsrc == NULL)
+ goto dec_src_failed;
+
+ ret = gst_pad_link (decsrc, session->recv_rtp_sink);
+ gst_object_unref (decsrc);
+
+ if (ret != GST_PAD_LINK_OK)
+ goto dec_link_failed;
+ } else {
+ GST_DEBUG_OBJECT (rtpbin, "no RTP decoder given");
+ decsink = gst_object_ref (session->recv_rtp_sink);
+ }
+
GST_DEBUG_OBJECT (rtpbin, "getting RTP src pad");
/* get srcpad, link to SSRCDemux */
session->recv_rtp_src =
gst_element_get_static_pad (session->session, "recv_rtp_src");
if (session->recv_rtp_src == NULL)
- goto pad_failed;
+ goto src_pad_failed;
GST_DEBUG_OBJECT (rtpbin, "getting demuxer RTP sink pad");
sinkdpad = gst_element_get_static_pad (session->demux, "sink");
GST_DEBUG_OBJECT (rtpbin, "linking demuxer RTP sink pad");
- lres = gst_pad_link (session->recv_rtp_src, sinkdpad);
+ gst_pad_link_full (session->recv_rtp_src, sinkdpad,
+ GST_PAD_LINK_CHECK_NOTHING);
gst_object_unref (sinkdpad);
- if (lres != GST_PAD_LINK_OK)
- goto link_failed;
/* connect to the new-ssrc-pad signal of the SSRC demuxer */
session->demux_newpad_sig = g_signal_connect (session->demux,
GST_DEBUG_OBJECT (rtpbin, "ghosting session sink pad");
session->recv_rtp_sink_ghost =
- gst_ghost_pad_new_from_template (name, session->recv_rtp_sink, templ);
+ gst_ghost_pad_new_from_template (name, decsink, templ);
+ gst_object_unref (decsink);
gst_pad_set_active (session->recv_rtp_sink_ghost, TRUE);
gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->recv_rtp_sink_ghost);
/* ERRORS */
no_name:
{
- g_warning ("gstrtpbin: invalid name given");
+ g_warning ("rtpbin: invalid name given");
return NULL;
}
create_error:
}
pad_failed:
{
- g_warning ("gstrtpbin: failed to get session pad");
+ g_warning ("rtpbin: failed to get session rtp_sink pad");
+ return NULL;
+ }
+dec_sink_failed:
+ {
+ g_warning ("rtpbin: failed to get decoder sink pad for session %d", sessid);
+ return NULL;
+ }
+dec_src_failed:
+ {
+ g_warning ("rtpbin: failed to get decoder src pad for session %d", sessid);
+ gst_object_unref (decsink);
+ return NULL;
+ }
+dec_link_failed:
+ {
+ g_warning ("rtpbin: failed to link rtp decoder for session %d", sessid);
+ gst_object_unref (decsink);
return NULL;
}
-link_failed:
+src_pad_failed:
{
- g_warning ("gstrtpbin: failed to link pads");
+ g_warning ("rtpbin: failed to get session rtp_src pad");
+ gst_object_unref (decsink);
return NULL;
}
}
const gchar * name)
{
guint sessid;
+ GstElement *decoder;
GstRtpBinSession *session;
- GstPad *sinkdpad;
- GstPadLinkReturn lres;
+ GstPad *sinkdpad, *decsink;
/* first get the session number */
if (name == NULL || sscanf (name, "recv_rtcp_sink_%u", &sessid) != 1)
if (session->recv_rtcp_sink == NULL)
goto pad_failed;
+ GST_DEBUG_OBJECT (rtpbin, "getting RTCP decoder");
+ decoder = session_request_decoder (session, SIGNAL_REQUEST_RTCP_DECODER);
+ if (decoder) {
+ GstPad *decsrc;
+ GstPadLinkReturn ret;
+
+ GST_DEBUG_OBJECT (rtpbin, "linking RTCP decoder");
+ decsink = gst_element_get_static_pad (decoder, "rtcp_sink");
+ decsrc = gst_element_get_static_pad (decoder, "rtcp_src");
+
+ if (decsink == NULL)
+ goto dec_sink_failed;
+
+ if (decsrc == NULL)
+ goto dec_src_failed;
+
+ ret = gst_pad_link (decsrc, session->recv_rtcp_sink);
+ gst_object_unref (decsrc);
+
+ if (ret != GST_PAD_LINK_OK)
+ goto dec_link_failed;
+ } else {
+ GST_DEBUG_OBJECT (rtpbin, "no RTCP decoder given");
+ decsink = gst_object_ref (session->recv_rtcp_sink);
+ }
+
/* get srcpad, link to SSRCDemux */
GST_DEBUG_OBJECT (rtpbin, "getting sync src pad");
session->sync_src = gst_element_get_static_pad (session->session, "sync_src");
if (session->sync_src == NULL)
- goto pad_failed;
+ goto src_pad_failed;
GST_DEBUG_OBJECT (rtpbin, "getting demuxer RTCP sink pad");
sinkdpad = gst_element_get_static_pad (session->demux, "rtcp_sink");
- lres = gst_pad_link (session->sync_src, sinkdpad);
+ gst_pad_link_full (session->sync_src, sinkdpad, GST_PAD_LINK_CHECK_NOTHING);
gst_object_unref (sinkdpad);
- if (lres != GST_PAD_LINK_OK)
- goto link_failed;
session->recv_rtcp_sink_ghost =
- gst_ghost_pad_new_from_template (name, session->recv_rtcp_sink, templ);
+ gst_ghost_pad_new_from_template (name, decsink, templ);
+ gst_object_unref (decsink);
gst_pad_set_active (session->recv_rtcp_sink_ghost, TRUE);
gst_element_add_pad (GST_ELEMENT_CAST (rtpbin),
session->recv_rtcp_sink_ghost);
/* ERRORS */
no_name:
{
- g_warning ("gstrtpbin: invalid name given");
+ g_warning ("rtpbin: invalid name given");
return NULL;
}
create_error:
}
pad_failed:
{
- g_warning ("gstrtpbin: failed to get session pad");
+ g_warning ("rtpbin: failed to get session rtcp_sink pad");
+ return NULL;
+ }
+dec_sink_failed:
+ {
+ g_warning ("rtpbin: failed to get decoder sink pad for session %d", sessid);
return NULL;
}
-link_failed:
+dec_src_failed:
{
- g_warning ("gstrtpbin: failed to link pads");
+ g_warning ("rtpbin: failed to get decoder src pad for session %d", sessid);
+ gst_object_unref (decsink);
+ return NULL;
+ }
+dec_link_failed:
+ {
+ g_warning ("rtpbin: failed to link rtcp decoder for session %d", sessid);
+ gst_object_unref (decsink);
+ return NULL;
+ }
+src_pad_failed:
+ {
+ g_warning ("rtpbin: failed to get session sync_src pad");
+ gst_object_unref (decsink);
return NULL;
}
}
{
gchar *gname;
guint sessid;
+ GstPad *encsrc;
+ GstElement *encoder;
GstRtpBinSession *session;
GstElementClass *klass;
if (session->send_rtp_src == NULL)
goto no_srcpad;
+ GST_DEBUG_OBJECT (rtpbin, "getting RTP encoder");
+ encoder = session_request_encoder (session, SIGNAL_REQUEST_RTP_ENCODER);
+ if (encoder) {
+ gchar *ename;
+ GstPad *encsink;
+ GstPadLinkReturn ret;
+
+ GST_DEBUG_OBJECT (rtpbin, "linking RTP encoder");
+ ename = g_strdup_printf ("rtp_sink_%d", sessid);
+ encsink = gst_element_get_static_pad (encoder, ename);
+ g_free (ename);
+ ename = g_strdup_printf ("rtp_src_%d", sessid);
+ encsrc = gst_element_get_static_pad (encoder, ename);
+ g_free (ename);
+
+ if (encsrc == NULL)
+ goto enc_src_failed;
+
+ if (encsink == NULL)
+ goto enc_sink_failed;
+
+ ret = gst_pad_link (session->send_rtp_src, encsink);
+ gst_object_unref (encsink);
+
+ if (ret != GST_PAD_LINK_OK)
+ goto enc_link_failed;
+ } else {
+ GST_DEBUG_OBJECT (rtpbin, "no RTP encoder given");
+ encsrc = gst_object_ref (session->send_rtp_src);
+ }
+
/* ghost the new source pad */
klass = GST_ELEMENT_GET_CLASS (rtpbin);
gname = g_strdup_printf ("send_rtp_src_%u", sessid);
templ = gst_element_class_get_pad_template (klass, "send_rtp_src_%u");
session->send_rtp_src_ghost =
- gst_ghost_pad_new_from_template (gname, session->send_rtp_src, templ);
+ gst_ghost_pad_new_from_template (gname, encsrc, templ);
+ gst_object_unref (encsrc);
gst_pad_set_active (session->send_rtp_src_ghost, TRUE);
gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->send_rtp_src_ghost);
g_free (gname);
/* ERRORS */
no_name:
{
- g_warning ("gstrtpbin: invalid name given");
+ g_warning ("rtpbin: invalid name given");
return NULL;
}
create_error:
}
pad_failed:
{
- g_warning ("gstrtpbin: failed to get session pad for session %d", sessid);
+ g_warning ("rtpbin: failed to get session pad for session %d", sessid);
return NULL;
}
no_srcpad:
{
- g_warning ("gstrtpbin: failed to get rtp source pad for session %d",
- sessid);
+ g_warning ("rtpbin: failed to get rtp source pad for session %d", sessid);
+ return NULL;
+ }
+enc_src_failed:
+ {
+ g_warning ("rtpbin: failed to get encoder src pad for session %d", sessid);
+ return NULL;
+ }
+enc_sink_failed:
+ {
+ g_warning ("rtpbin: failed to get encoder sink pad for session %d", sessid);
+ gst_object_unref (encsrc);
+ return NULL;
+ }
+enc_link_failed:
+ {
+ g_warning ("rtpbin: failed to link rtp encoder for session %d", sessid);
+ gst_object_unref (encsrc);
return NULL;
}
}
create_rtcp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
{
guint sessid;
+ GstPad *encsrc;
+ GstElement *encoder;
GstRtpBinSession *session;
/* first get the session number */
if (session->send_rtcp_src == NULL)
goto pad_failed;
+ GST_DEBUG_OBJECT (rtpbin, "getting RTCP encoder");
+ encoder = session_request_encoder (session, SIGNAL_REQUEST_RTCP_ENCODER);
+ if (encoder) {
+ gchar *ename;
+ GstPad *encsink;
+ GstPadLinkReturn ret;
+
+ GST_DEBUG_OBJECT (rtpbin, "linking RTCP encoder");
+ ename = g_strdup_printf ("rtcp_sink_%d", sessid);
+ encsink = gst_element_get_static_pad (encoder, ename);
+ g_free (ename);
+ ename = g_strdup_printf ("rtcp_src_%d", sessid);
+ encsrc = gst_element_get_static_pad (encoder, ename);
+ g_free (ename);
+
+ if (encsrc == NULL)
+ goto enc_src_failed;
+
+ if (encsink == NULL)
+ goto enc_sink_failed;
+
+ ret = gst_pad_link (session->send_rtcp_src, encsink);
+ gst_object_unref (encsink);
+
+ if (ret != GST_PAD_LINK_OK)
+ goto enc_link_failed;
+ } else {
+ GST_DEBUG_OBJECT (rtpbin, "no RTCP encoder given");
+ encsrc = gst_object_ref (session->send_rtcp_src);
+ }
+
session->send_rtcp_src_ghost =
- gst_ghost_pad_new_from_template (name, session->send_rtcp_src, templ);
+ gst_ghost_pad_new_from_template (name, encsrc, templ);
+ gst_object_unref (encsrc);
gst_pad_set_active (session->send_rtcp_src_ghost, TRUE);
gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), session->send_rtcp_src_ghost);
/* ERRORS */
no_name:
{
- g_warning ("gstrtpbin: invalid name given");
+ g_warning ("rtpbin: invalid name given");
return NULL;
}
no_session:
{
- g_warning ("gstrtpbin: session with id %d does not exist", sessid);
+ g_warning ("rtpbin: session with id %d does not exist", sessid);
return NULL;
}
pad_failed:
{
- g_warning ("gstrtpbin: failed to get rtcp pad for session %d", sessid);
+ g_warning ("rtpbin: failed to get rtcp pad for session %d", sessid);
+ return NULL;
+ }
+enc_src_failed:
+ {
+ g_warning ("rtpbin: failed to get encoder src pad for session %d", sessid);
+ return NULL;
+ }
+enc_sink_failed:
+ {
+ g_warning ("rtpbin: failed to get encoder sink pad for session %d", sessid);
+ gst_object_unref (encsrc);
+ return NULL;
+ }
+enc_link_failed:
+ {
+ g_warning ("rtpbin: failed to link rtcp encoder for session %d", sessid);
+ gst_object_unref (encsrc);
return NULL;
}
}
{
g_free (pad_name);
GST_RTP_BIN_UNLOCK (rtpbin);
- g_warning ("gstrtpbin: this is not our template");
+ g_warning ("rtpbin: this is not our template");
return NULL;
}
}
unknown_pad:
{
GST_RTP_BIN_UNLOCK (rtpbin);
- g_warning ("gstrtpbin: %s:%s is not one of our request pads",
+ g_warning ("rtpbin: %s:%s is not one of our request pads",
GST_DEBUG_PAD_NAME (pad));
return;
}