How to get the STUN Messages received on the RTP/RTCP port?

Sunil sunil.p at globaledgesoft.com
Tue Nov 29 21:10:21 PST 2011


I found that the below function processes the received packets on RTP 
port.Please let me know if there any framework available to pass the 
Invalid RTP packets to application.


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
  * rtp_session_process_rtp:
  * @sess: and #RTPSession
  * @buffer: an RTP buffer
  * @current_time: the current system time
  * @running_time: the running_time of @buffer
  *
  * Process an RTP buffer in the session manager. This function takes 
ownership
  * of @buffer.
  *
  * Returns: a #GstFlowReturn.
  */
GstFlowReturn
rtp_session_process_rtp (RTPSession * sess, GstBuffer * buffer,
     GstClockTime current_time, GstClockTime running_time)
{
   GstFlowReturn result;
   guint32 ssrc;
   RTPSource *source;
   gboolean created;
   gboolean prevsender, prevactive;
   RTPArrivalStats arrival;
   guint32 csrcs[16];
   guint8 i, count;
   guint64 oldrate;

   g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
   g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);

   if (!gst_rtp_buffer_validate (buffer))
     goto invalid_packet;

   RTP_SESSION_LOCK (sess);
   /* update arrival stats */
   update_arrival_stats (sess, &arrival, TRUE, buffer, current_time,
       running_time);

   /* ignore more RTP packets when we left the session */
   if (sess->source->received_bye)

  /* get SSRC and look up in session database */
   ssrc = gst_rtp_buffer_get_ssrc (buffer);
   source = obtain_source (sess, ssrc, &created, &arrival, TRUE);
   if (!source)
     goto collision;

   prevsender = RTP_SOURCE_IS_SENDER (source);
   prevactive = RTP_SOURCE_IS_ACTIVE (source);
   oldrate = source->bitrate;

   /* copy available csrc for later */
   count = gst_rtp_buffer_get_csrc_count (buffer);
   /* make sure to not overflow our array. An RTP buffer can maximally 
contain
    * 16 CSRCs */
   count = MIN (count, 16);

   for (i = 0; i < count; i++)
     csrcs[i] = gst_rtp_buffer_get_csrc (buffer, i);

   /* let source process the packet */
   result = rtp_source_process_rtp (source, buffer, &arrival);

   /* source became active */
   if (prevactive != RTP_SOURCE_IS_ACTIVE (source)) {
     sess->stats.active_sources++;
     GST_DEBUG ("source: %08x became active, %d active sources", ssrc,
         sess->stats.active_sources);
     on_ssrc_validated (sess, source);
   }
        if (prevsender != RTP_SOURCE_IS_SENDER (source)) {
     sess->stats.sender_sources++;
     GST_DEBUG ("source: %08x became sender, %d sender sources", ssrc,
         sess->stats.sender_sources);
   }
   if (oldrate != source->bitrate)
     sess->recalc_bandwidth = TRUE;

   if (created)
     on_new_ssrc (sess, source);

   if (source->validated) {
     gboolean created;

     /* for validated sources, we add the CSRCs as well */
     for (i = 0; i < count; i++) {
       guint32 csrc;
       RTPSource *csrc_src;

       csrc = csrcs[i];

       /* get source */
       csrc_src = obtain_source (sess, csrc, &created, &arrival, TRUE);
       if (!csrc_src)
         continue;

       if (created) {
         GST_DEBUG ("created new CSRC: %08x", csrc);
         rtp_source_set_as_csrc (csrc_src);
         if (RTP_SOURCE_IS_ACTIVE (csrc_src))
           sess->stats.active_sources++;
         on_new_ssrc (sess, csrc_src);
       }
          g_object_unref (csrc_src);
     }
   }
   g_object_unref (source);

   RTP_SESSION_UNLOCK (sess);

   return result;

   /* ERRORS */
invalid_packet:
   {
     gst_buffer_unref (buffer);
     GST_DEBUG ("invalid RTP packet received");
     return GST_FLOW_OK;
   }
ignore:
   {
     gst_buffer_unref (buffer);
     RTP_SESSION_UNLOCK (sess);
     GST_DEBUG ("ignoring RTP packet because we are leaving");
     return GST_FLOW_OK;
   }
     collision:
   {
     gst_buffer_unref (buffer);
     RTP_SESSION_UNLOCK (sess);
     GST_DEBUG ("ignoring packet because its collisioning");
     return GST_FLOW_OK;
   }
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 



Thanks and Regards,
Sunil



On Tuesday 29 November 2011 05:29 PM, Sunil wrote:
> Is there any provision to get the NON-RTP/RTCP(STUN) packets from 
> gStreamer to application?
>
> RTP/RTCP is received by gStreamer. our application needs the 
> NON-RTP/RTCP packets received on RTP/RTCP port for processing.This is 
> basically De-Multiplexing of RTP/RTCP from NON-RTP/RTCP packets like 
> STUN(RFC 5389) packets.
>
> Regards,
> Sunil



More information about the gstreamer-devel mailing list