+static void
+peek_sink_buffer (GstWebRTCBin * webrtc, guint rtp_session_id,
+ guint media_idx, WebRTCTransceiver * trans, GstBuffer * buffer)
+{
+ GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
+ SsrcMapItem *item;
+ guint ssrc;
+
+ if (!gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp))
+ return;
+ ssrc = gst_rtp_buffer_get_ssrc (&rtp);
+ gst_rtp_buffer_unmap (&rtp);
+
+ if (!ssrc) {
+ GST_WARNING_OBJECT (webrtc,
+ "incoming buffer does not contain a valid ssrc");
+ return;
+ }
+
+ PC_LOCK (webrtc);
+ item =
+ find_or_add_ssrc_map_item (webrtc,
+ GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_SENDONLY, rtp_session_id, ssrc,
+ media_idx);
+ if (item->media_idx == -1) {
+ char *str;
+
+ GST_DEBUG_OBJECT (webrtc, "updating media idx of ssrc item %p to %u", item,
+ media_idx);
+ item->media_idx = media_idx;
+
+ /* ensure that the rtx mapping contains a valid ssrc to use for rtx when
+ * used even when there are no ssrc's in the input/codec preferences caps */
+ str = g_strdup_printf ("%u", ssrc);
+ if (!gst_structure_has_field_typed (trans->local_rtx_ssrc_map, str,
+ G_TYPE_UINT)) {
+ /* TODO: ssrc-collision? */
+ gst_structure_set (trans->local_rtx_ssrc_map, str, G_TYPE_UINT,
+ g_random_int (), NULL);
+ _set_internal_rtpbin_element_props_from_stream (webrtc, trans->stream);
+ }
+ g_free (str);
+ }
+ PC_UNLOCK (webrtc);
+}
+
+static GstPadProbeReturn
+sink_pad_buffer_peek (GstPad * pad, GstPadProbeInfo * info,
+ GstWebRTCBin * webrtc)
+{
+ GstWebRTCBinPad *webrtc_pad = GST_WEBRTC_BIN_PAD (pad);
+ WebRTCTransceiver *trans;
+ guint rtp_session_id, media_idx;
+
+ if (!webrtc_pad->trans)
+ return GST_PAD_PROBE_OK;
+
+ trans = (WebRTCTransceiver *) webrtc_pad->trans;
+ if (!trans->stream)
+ return GST_PAD_PROBE_OK;
+
+ rtp_session_id = trans->stream->session_id;
+ media_idx = webrtc_pad->trans->mline;
+
+ if (media_idx != G_MAXUINT)
+ return GST_PAD_PROBE_OK;
+
+ if (info->type & GST_PAD_PROBE_TYPE_BUFFER) {
+ GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER (info);
+ peek_sink_buffer (webrtc, rtp_session_id, media_idx, trans, buffer);
+ } else if (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST) {
+ GstBufferList *list = GST_PAD_PROBE_INFO_BUFFER_LIST (info);
+ guint i, n;
+
+ n = gst_buffer_list_length (list);
+ for (i = 0; i < n; i++) {
+ GstBuffer *buffer = gst_buffer_list_get (list, i);
+ peek_sink_buffer (webrtc, rtp_session_id, media_idx, trans, buffer);
+ }
+ } else {
+ g_assert_not_reached ();
+ }
+
+ return GST_PAD_PROBE_OK;
+}