*
* 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.
*/
/**
* <refsect2>
* <title>Example pipelines</title>
* |[
- * gst-launch udpsrc caps="application/x-rtp" ! gstrtpptdemux ! fakesink
+ * gst-launch-1.0 udpsrc caps="application/x-rtp" ! gstrtpptdemux ! fakesink
* ]| Takes an RTP stream and send the RTP packets with the first detected
* payload type to fakesink, discarding the other payload types.
* </refsect2>
GstStateChange transition);
static void gst_rtp_pt_demux_clear_pt_map (GstRtpPtDemux * rtpdemux);
-static GstRtpPtDemuxPad *find_pad_for_pt (GstRtpPtDemux * rtpdemux, guint8 pt);
+static GstPad *find_pad_for_pt (GstRtpPtDemux * rtpdemux, guint8 pt);
static gboolean gst_rtp_pt_demux_src_event (GstPad * pad, GstObject * parent,
GstEvent * event);
gst_element_class_add_pad_template (gstelement_klass,
gst_static_pad_template_get (&rtp_pt_demux_src_template));
- gst_element_class_set_details_simple (gstelement_klass, "RTP Demux",
+ gst_element_class_set_static_metadata (gstelement_klass, "RTP Demux",
"Demux/Network/RTP",
"Parses codec streams transmitted in the same RTP session",
"Kai Vehmanen <kai.vehmanen@nokia.com>");
GST_OBJECT_UNLOCK (rtpdemux);
}
+static gboolean
+need_caps_for_pt (GstRtpPtDemux * rtpdemux, guint8 pt)
+{
+ GSList *walk;
+ gboolean ret = FALSE;
+
+ GST_OBJECT_LOCK (rtpdemux);
+ for (walk = rtpdemux->srcpads; walk; walk = g_slist_next (walk)) {
+ GstRtpPtDemuxPad *pad = walk->data;
+
+ if (pad->pt == pt) {
+ ret = pad->newcaps;
+ }
+ }
+ GST_OBJECT_UNLOCK (rtpdemux);
+
+ return ret;
+}
+
+
+static void
+clear_newcaps_for_pt (GstRtpPtDemux * rtpdemux, guint8 pt)
+{
+ GSList *walk;
+
+ GST_OBJECT_LOCK (rtpdemux);
+ for (walk = rtpdemux->srcpads; walk; walk = g_slist_next (walk)) {
+ GstRtpPtDemuxPad *pad = walk->data;
+
+ if (pad->pt == pt) {
+ pad->newcaps = FALSE;
+ break;
+ }
+ }
+ GST_OBJECT_UNLOCK (rtpdemux);
+}
+
+static gboolean
+forward_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
+{
+ GstPad *srcpad = GST_PAD_CAST (user_data);
+
+ gst_pad_push_event (srcpad, gst_event_ref (*event));
+
+ return TRUE;
+}
+
static GstFlowReturn
gst_rtp_pt_demux_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
{
GstRtpPtDemux *rtpdemux;
guint8 pt;
GstPad *srcpad;
- GstRtpPtDemuxPad *rtpdemuxpad;
GstCaps *caps;
GstRTPBuffer rtp = { NULL };
rtpdemux = GST_RTP_PT_DEMUX (parent);
- if (!gst_rtp_buffer_validate (buf))
+ if (!gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp))
goto invalid_buffer;
- gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
pt = gst_rtp_buffer_get_payload_type (&rtp);
gst_rtp_buffer_unmap (&rtp);
GST_DEBUG_OBJECT (rtpdemux, "received buffer for pt %d", pt);
- rtpdemuxpad = find_pad_for_pt (rtpdemux, pt);
- if (rtpdemuxpad == NULL) {
+ srcpad = find_pad_for_pt (rtpdemux, pt);
+ if (srcpad == NULL) {
/* new PT, create a src pad */
+ GstRtpPtDemuxPad *rtpdemuxpad;
GstElementClass *klass;
GstPadTemplate *templ;
gchar *padname;
g_free (padname);
gst_pad_set_event_function (srcpad, gst_rtp_pt_demux_src_event);
- caps = gst_caps_make_writable (caps);
- gst_caps_set_simple (caps, "payload", G_TYPE_INT, pt, NULL);
- gst_pad_set_caps (srcpad, caps);
- gst_caps_unref (caps);
-
GST_DEBUG ("Adding pt=%d to the list.", pt);
- rtpdemuxpad = g_new0 (GstRtpPtDemuxPad, 1);
+ rtpdemuxpad = g_slice_new0 (GstRtpPtDemuxPad);
rtpdemuxpad->pt = pt;
rtpdemuxpad->newcaps = FALSE;
rtpdemuxpad->pad = srcpad;
+ gst_object_ref (srcpad);
GST_OBJECT_LOCK (rtpdemux);
rtpdemux->srcpads = g_slist_append (rtpdemux->srcpads, rtpdemuxpad);
GST_OBJECT_UNLOCK (rtpdemux);
gst_pad_set_active (srcpad, TRUE);
+
+ caps = gst_caps_make_writable (caps);
+ gst_caps_set_simple (caps, "payload", G_TYPE_INT, pt, NULL);
+ gst_pad_set_caps (srcpad, caps);
+ gst_caps_unref (caps);
+
+ gst_pad_sticky_events_foreach (rtpdemux->sink, forward_sticky_events,
+ srcpad);
gst_element_add_pad (GST_ELEMENT_CAST (rtpdemux), srcpad);
GST_DEBUG ("emitting new-payload-type for pt %d", pt);
gst_rtp_pt_demux_signals[SIGNAL_NEW_PAYLOAD_TYPE], 0, pt, srcpad);
}
- srcpad = rtpdemuxpad->pad;
-
if (pt != rtpdemux->last_pt) {
gint emit_pt = pt;
gst_rtp_pt_demux_signals[SIGNAL_PAYLOAD_TYPE_CHANGE], 0, emit_pt);
}
- if (rtpdemuxpad->newcaps) {
- GST_DEBUG ("need new caps");
+ while (need_caps_for_pt (rtpdemux, pt)) {
+ GST_DEBUG ("need new caps for %d", pt);
caps = gst_rtp_pt_demux_get_caps (rtpdemux, pt);
if (!caps)
goto no_caps;
+ clear_newcaps_for_pt (rtpdemux, pt);
+
caps = gst_caps_make_writable (caps);
gst_caps_set_simple (caps, "payload", G_TYPE_INT, pt, NULL);
gst_pad_set_caps (srcpad, caps);
gst_caps_unref (caps);
- rtpdemuxpad->newcaps = FALSE;
}
/* push to srcpad */
ret = gst_pad_push (srcpad, buf);
+ gst_object_unref (srcpad);
+
return ret;
/* ERRORS */
GST_ELEMENT_ERROR (rtpdemux, STREAM, DECODE, (NULL),
("Could not get caps for payload"));
gst_buffer_unref (buf);
+ if (srcpad)
+ gst_object_unref (srcpad);
return GST_FLOW_ERROR;
}
}
-static GstRtpPtDemuxPad *
+static GstPad *
find_pad_for_pt (GstRtpPtDemux * rtpdemux, guint8 pt)
{
- GstRtpPtDemuxPad *respad = NULL;
+ GstPad *respad = NULL;
GSList *walk;
+ GST_OBJECT_LOCK (rtpdemux);
for (walk = rtpdemux->srcpads; walk; walk = g_slist_next (walk)) {
GstRtpPtDemuxPad *pad = walk->data;
if (pad->pt == pt) {
- respad = pad;
+ respad = gst_object_ref (pad->pad);
break;
}
}
+ GST_OBJECT_UNLOCK (rtpdemux);
+
return respad;
}
rtpdemux = GST_RTP_PT_DEMUX (parent);
switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_CAPS:
+ {
+ gst_rtp_pt_demux_clear_pt_map (rtpdemux);
+ /* don't forward the event, we cleared the ptmap and on the next buffer we
+ * will add the pt to the caps and push a new caps event */
+ gst_event_unref (event);
+ res = TRUE;
+ break;
+ }
case GST_EVENT_CUSTOM_DOWNSTREAM:
{
const GstStructure *s;
s = gst_event_get_structure (event);
if (gst_structure_has_name (s, "GstRTPPacketLost")) {
- GstRtpPtDemuxPad *rtpdemuxpad =
- find_pad_for_pt (rtpdemux, rtpdemux->last_pt);
+ GstPad *srcpad = find_pad_for_pt (rtpdemux, rtpdemux->last_pt);
- if (rtpdemuxpad)
- res = gst_pad_push_event (rtpdemuxpad->pad, event);
- else
+ if (srcpad) {
+ res = gst_pad_push_event (srcpad, event);
+ gst_object_unref (srcpad);
+ } else {
gst_event_unref (event);
+ }
} else {
res = gst_pad_event_default (pad, parent, event);
if (s && !gst_structure_has_field (s, "payload")) {
GSList *walk;
+ GST_OBJECT_LOCK (demux);
for (walk = demux->srcpads; walk; walk = g_slist_next (walk)) {
GstRtpPtDemuxPad *dpad = (GstRtpPtDemuxPad *) walk->data;
break;
}
}
+ GST_OBJECT_UNLOCK (demux);
}
break;
default:
static void
gst_rtp_pt_demux_release (GstRtpPtDemux * ptdemux)
{
+ GSList *tmppads;
GSList *walk;
- for (walk = ptdemux->srcpads; walk; walk = g_slist_next (walk)) {
+ GST_OBJECT_LOCK (ptdemux);
+ tmppads = ptdemux->srcpads;
+ ptdemux->srcpads = NULL;
+ GST_OBJECT_UNLOCK (ptdemux);
+
+ for (walk = tmppads; walk; walk = g_slist_next (walk)) {
GstRtpPtDemuxPad *pad = walk->data;
gst_pad_set_active (pad->pad, FALSE);
gst_element_remove_pad (GST_ELEMENT_CAST (ptdemux), pad->pad);
- g_free (pad);
+ g_slice_free (GstRtpPtDemuxPad, pad);
}
- g_slist_free (ptdemux->srcpads);
- ptdemux->srcpads = NULL;
+ g_slist_free (tmppads);
}
static GstStateChangeReturn