RTCP: add beginnings of Feedback messages
authorJohann Prieur <johann.prieur at gmail.com>
Tue, 14 Apr 2009 14:45:20 +0000 (16:45 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 14 Apr 2009 14:45:20 +0000 (16:45 +0200)
Add the beginnings of parsing and constructing Feedback messages.
Fixes #577610.

docs/libs/gst-plugins-base-libs-sections.txt
gst-libs/gst/rtp/gstrtcpbuffer.c
gst-libs/gst/rtp/gstrtcpbuffer.h
win32/common/libgstrtp.def

index 15d2a9c..f639378 100644 (file)
@@ -1015,6 +1015,7 @@ GST_RTCP_VALID_VALUE
 GstRTCPType
 GstRTCPPacket
 GstRTCPSDESType
+GstRTCPFBType
 
 gst_rtcp_buffer_new_take_data
 gst_rtcp_buffer_new_copy_data
@@ -1068,6 +1069,15 @@ gst_rtcp_packet_bye_get_reason_len
 gst_rtcp_packet_bye_get_reason
 gst_rtcp_packet_bye_set_reason
 
+gst_rtcp_packet_fb_get_type
+gst_rtcp_packet_fb_set_type
+
+gst_rtcp_packet_fb_get_sender_ssrc
+gst_rtcp_packet_fb_set_sender_ssrc
+
+gst_rtcp_packet_fb_get_media_ssrc
+gst_rtcp_packet_fb_set_media_ssrc
+
 gst_rtcp_ntp_to_unix
 gst_rtcp_unix_to_ntp
 
index ab77c8a..602ab65 100644 (file)
@@ -449,6 +449,11 @@ gst_rtcp_buffer_add_packet (GstBuffer * buffer, GstRTCPType type,
     case GST_RTCP_TYPE_APP:
       len = 12;
       break;
+    case GST_RTCP_TYPE_RTPFB:
+      len = 12;
+      break;
+    case GST_RTCP_TYPE_PSFB:
+      len = 12;
     default:
       goto unknown_type;
   }
@@ -1637,6 +1642,163 @@ no_space:
 }
 
 /**
+ * gst_rtcp_packet_fb_get_sender_ssrc:
+ * @packet: a valid RTPFB or PSFB #GstRTCPPacket
+ *
+ * Get the sender SSRC field of the RTPFB or PSFB @packet.
+ *
+ * Returns: the sender SSRC.
+ *
+ * Since: 0.10.23
+ */
+guint32
+gst_rtcp_packet_fb_get_sender_ssrc (GstRTCPPacket * packet)
+{
+  guint8 *data;
+  guint32 ssrc;
+
+  g_return_val_if_fail (packet != NULL, 0);
+  g_return_val_if_fail ((packet->type == GST_RTCP_TYPE_RTPFB ||
+          packet->type == GST_RTCP_TYPE_PSFB), 0);
+  g_return_val_if_fail (GST_IS_BUFFER (packet->buffer), 0);
+
+  data = GST_BUFFER_DATA (packet->buffer);
+
+  /* skip header */
+  data += packet->offset + 4;
+  ssrc = GST_READ_UINT32_BE (data);
+
+  return ssrc;
+}
+
+/**
+ * gst_rtcp_packet_fb_set_sender_ssrc:
+ * @packet: a valid RTPFB or PSFB #GstRTCPPacket
+ * @ssrc: a sender SSRC
+ *
+ * Set the sender SSRC field of the RTPFB or PSFB @packet.
+ *
+ * Since: 0.10.23
+ */
+void
+gst_rtcp_packet_fb_set_sender_ssrc (GstRTCPPacket * packet, guint32 ssrc)
+{
+  guint8 *data;
+
+  g_return_if_fail (packet != NULL);
+  g_return_if_fail (packet->type == GST_RTCP_TYPE_RTPFB ||
+      packet->type == GST_RTCP_TYPE_PSFB);
+  g_return_if_fail (GST_IS_BUFFER (packet->buffer));
+
+  data = GST_BUFFER_DATA (packet->buffer);
+
+  /* skip header */
+  data += packet->offset + 4;
+  GST_WRITE_UINT32_BE (data, ssrc);
+}
+
+/**
+ * gst_rtcp_packet_fb_get_media_ssrc:
+ * @packet: a valid RTPFB or PSFB #GstRTCPPacket
+ *
+ * Get the media SSRC field of the RTPFB or PSFB @packet.
+ *
+ * Returns: the media SSRC.
+ *
+ * Since: 0.10.23
+ */
+guint32
+gst_rtcp_packet_fb_get_media_ssrc (GstRTCPPacket * packet)
+{
+  guint8 *data;
+  guint32 ssrc;
+
+  g_return_val_if_fail (packet != NULL, 0);
+  g_return_val_if_fail ((packet->type == GST_RTCP_TYPE_RTPFB ||
+          packet->type == GST_RTCP_TYPE_PSFB), 0);
+  g_return_val_if_fail (GST_IS_BUFFER (packet->buffer), 0);
+
+  data = GST_BUFFER_DATA (packet->buffer);
+
+  /* skip header and sender ssrc */
+  data += packet->offset + 8;
+  ssrc = GST_READ_UINT32_BE (data);
+
+  return ssrc;
+}
+
+/**
+ * gst_rtcp_packet_fb_set_media_ssrc:
+ * @packet: a valid RTPFB or PSFB #GstRTCPPacket
+ * @ssrc: a media SSRC
+ *
+ * Set the media SSRC field of the RTPFB or PSFB @packet.
+ *
+ * Since: 0.10.23
+ */
+void
+gst_rtcp_packet_fb_set_media_ssrc (GstRTCPPacket * packet, guint32 ssrc)
+{
+  guint8 *data;
+
+  g_return_if_fail (packet != NULL);
+  g_return_if_fail (packet->type == GST_RTCP_TYPE_RTPFB ||
+      packet->type == GST_RTCP_TYPE_PSFB);
+  g_return_if_fail (GST_IS_BUFFER (packet->buffer));
+
+  data = GST_BUFFER_DATA (packet->buffer);
+
+  /* skip header and sender ssrc */
+  data += packet->offset + 8;
+  GST_WRITE_UINT32_BE (data, ssrc);
+}
+
+/**
+ * gst_rtcp_packet_fb_get_type:
+ * @packet: a valid RTPFB or PSFB #GstRTCPPacket
+ *
+ * Get the feedback message type of the FB @packet.
+ *
+ * Returns: The feedback message type.
+ *
+ * Since: 0.10.23
+ */
+GstRTCPFBType
+gst_rtcp_packet_fb_get_type (GstRTCPPacket * packet)
+{
+  g_return_val_if_fail (packet != NULL, GST_RTCP_FB_TYPE_INVALID);
+  g_return_val_if_fail (packet->type == GST_RTCP_TYPE_RTPFB ||
+      packet->type == GST_RTCP_TYPE_PSFB, GST_RTCP_FB_TYPE_INVALID);
+
+  return packet->count;
+}
+
+/**
+ * gst_rtcp_packet_fb_set_type:
+ * @packet: a valid RTPFB or PSFB #GstRTCPPacket
+ * @type: the #GstRTCPFBType to set
+ *
+ * Set the feedback message type of the FB @packet.
+ *
+ * Since: 0.10.23
+ */
+void
+gst_rtcp_packet_fb_set_type (GstRTCPPacket * packet, GstRTCPFBType type)
+{
+  guint8 *data;
+
+  g_return_if_fail (packet != NULL);
+  g_return_if_fail (packet->type == GST_RTCP_TYPE_RTPFB ||
+      packet->type == GST_RTCP_TYPE_PSFB);
+  g_return_if_fail (GST_IS_BUFFER (packet->buffer));
+
+  data = GST_BUFFER_DATA (packet->buffer);
+
+  data[packet->offset] = (data[packet->offset] & 0xe0) | type;
+  packet->count = type;
+}
+
+/**
  * gst_rtcp_ntp_to_unix:
  * @ntptime: an NTP timestamp
  *
index 9c908a8..75ab4bc 100644 (file)
@@ -42,6 +42,8 @@ G_BEGIN_DECLS
  * @GST_RTCP_TYPE_SDES: Source description
  * @GST_RTCP_TYPE_BYE: Goodbye
  * @GST_RTCP_TYPE_APP: Application defined
+ * @GST_RTCP_TYPE_RTPFB: Transport layer feedback. Since: 0.10.23
+ * @GST_RTCP_TYPE_PSFB: Payload-specific feedback. Since: 0.10.23
  *
  * Different RTCP packet types.
  */
@@ -52,9 +54,37 @@ typedef enum
   GST_RTCP_TYPE_RR      = 201,
   GST_RTCP_TYPE_SDES    = 202,
   GST_RTCP_TYPE_BYE     = 203,
-  GST_RTCP_TYPE_APP     = 204
+  GST_RTCP_TYPE_APP     = 204,
+  GST_RTCP_TYPE_RTPFB   = 205,
+  GST_RTCP_TYPE_PSFB    = 206
 } GstRTCPType;
 
+/**
+ * GstRTCPFBType:
+ * @GST_RTCP_FB_TYPE_INVALID: Invalid type
+ * @GST_RTCP_RTPFB_TYPE_NACK: Generic NACK
+ * @GST_RTCP_PSFB_TYPE_PLI: Picture Loss Indication
+ * @GST_RTCP_PSFB_TYPE_SLI: Slice Loss Indication
+ * @GST_RTCP_PSFB_TYPE_RPSI: Reference Picture Selection Indication
+ * @GST_RTCP_PSFB_TYPE_AFB: Application layer Feedback
+ *
+ * Different types of feedback messages.
+ *
+ * Since: 0.10.23
+ */
+typedef enum
+{
+  /* generic */
+  GST_RTCP_FB_TYPE_INVALID    = 0,
+  /* RTPFB types */
+  GST_RTCP_RTPFB_TYPE_NACK    = 1,
+  /* PSFB types */
+  GST_RTCP_PSFB_TYPE_PLI      = 1,
+  GST_RTCP_PSFB_TYPE_SLI      = 2,
+  GST_RTCP_PSFB_TYPE_RPSI     = 3,
+  GST_RTCP_PSFB_TYPE_AFB      = 15
+} GstRTCPFBType;
+
 /** 
  * GstRTCPSDESType:
  * @GST_RTCP_SDES_INVALID: Invalid SDES entry
@@ -232,6 +262,14 @@ guint8          gst_rtcp_packet_bye_get_reason_len    (GstRTCPPacket *packet);
 gchar*          gst_rtcp_packet_bye_get_reason        (GstRTCPPacket *packet);
 gboolean        gst_rtcp_packet_bye_set_reason        (GstRTCPPacket *packet, const gchar *reason);
 
+/* feedback packets */
+guint32         gst_rtcp_packet_fb_get_sender_ssrc    (GstRTCPPacket *packet);
+void            gst_rtcp_packet_fb_set_sender_ssrc    (GstRTCPPacket *packet, guint32 ssrc);
+guint32         gst_rtcp_packet_fb_get_media_ssrc     (GstRTCPPacket *packet);
+void            gst_rtcp_packet_fb_set_media_ssrc     (GstRTCPPacket *packet, guint32 ssrc);
+GstRTCPFBType   gst_rtcp_packet_fb_get_type           (GstRTCPPacket *packet);
+void            gst_rtcp_packet_fb_set_type           (GstRTCPPacket *packet, GstRTCPFBType type);
+
 /* helper functions */
 guint64         gst_rtcp_ntp_to_unix                  (guint64 ntptime);
 guint64         gst_rtcp_unix_to_ntp                  (guint64 unixtime);
index df7747d..75b2c7c 100644 (file)
@@ -33,6 +33,12 @@ EXPORTS
        gst_rtcp_packet_bye_get_reason_len
        gst_rtcp_packet_bye_get_ssrc_count
        gst_rtcp_packet_bye_set_reason
+       gst_rtcp_packet_fb_get_media_ssrc
+       gst_rtcp_packet_fb_get_sender_ssrc
+       gst_rtcp_packet_fb_get_type
+       gst_rtcp_packet_fb_set_media_ssrc
+       gst_rtcp_packet_fb_set_sender_ssrc
+       gst_rtcp_packet_fb_set_type
        gst_rtcp_packet_get_count
        gst_rtcp_packet_get_length
        gst_rtcp_packet_get_padding