2 * Copyright (C) <2007> Wim Taymans <wim@fluendo.com>
4 * gstrtcpbuffer.h: various helper functions to manipulate buffers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #ifndef __GST_RTCPBUFFER_H__
24 #define __GST_RTCPBUFFER_H__
33 * The supported RTCP version 2.
35 #define GST_RTCP_VERSION 2
39 * @GST_RTCP_TYPE_INVALID: Invalid type
40 * @GST_RTCP_TYPE_SR: Sender report
41 * @GST_RTCP_TYPE_RR: Receiver report
42 * @GST_RTCP_TYPE_SDES: Source description
43 * @GST_RTCP_TYPE_BYE: Goodbye
44 * @GST_RTCP_TYPE_APP: Application defined
45 * @GST_RTCP_TYPE_RTPFB: Transport layer feedback. Since: 0.10.23
46 * @GST_RTCP_TYPE_PSFB: Payload-specific feedback. Since: 0.10.23
48 * Different RTCP packet types.
52 GST_RTCP_TYPE_INVALID = 0,
53 GST_RTCP_TYPE_SR = 200,
54 GST_RTCP_TYPE_RR = 201,
55 GST_RTCP_TYPE_SDES = 202,
56 GST_RTCP_TYPE_BYE = 203,
57 GST_RTCP_TYPE_APP = 204,
58 GST_RTCP_TYPE_RTPFB = 205,
59 GST_RTCP_TYPE_PSFB = 206
64 * @GST_RTCP_FB_TYPE_INVALID: Invalid type
65 * @GST_RTCP_RTPFB_TYPE_NACK: Generic NACK
66 * @GST_RTCP_PSFB_TYPE_PLI: Picture Loss Indication
67 * @GST_RTCP_PSFB_TYPE_SLI: Slice Loss Indication
68 * @GST_RTCP_PSFB_TYPE_RPSI: Reference Picture Selection Indication
69 * @GST_RTCP_PSFB_TYPE_AFB: Application layer Feedback
71 * Different types of feedback messages.
78 GST_RTCP_FB_TYPE_INVALID = 0,
80 GST_RTCP_RTPFB_TYPE_NACK = 1,
82 GST_RTCP_PSFB_TYPE_PLI = 1,
83 GST_RTCP_PSFB_TYPE_SLI = 2,
84 GST_RTCP_PSFB_TYPE_RPSI = 3,
85 GST_RTCP_PSFB_TYPE_AFB = 15
90 * @GST_RTCP_SDES_INVALID: Invalid SDES entry
91 * @GST_RTCP_SDES_END: End of SDES list
92 * @GST_RTCP_SDES_CNAME: Canonical name
93 * @GST_RTCP_SDES_NAME: User name
94 * @GST_RTCP_SDES_EMAIL: User's electronic mail address
95 * @GST_RTCP_SDES_PHONE: User's phone number
96 * @GST_RTCP_SDES_LOC: Geographic user location
97 * @GST_RTCP_SDES_TOOL: Name of application or tool
98 * @GST_RTCP_SDES_NOTE: Notice about the source
99 * @GST_RTCP_SDES_PRIV: Private extensions
101 * Different types of SDES content.
105 GST_RTCP_SDES_INVALID = -1,
106 GST_RTCP_SDES_END = 0,
107 GST_RTCP_SDES_CNAME = 1,
108 GST_RTCP_SDES_NAME = 2,
109 GST_RTCP_SDES_EMAIL = 3,
110 GST_RTCP_SDES_PHONE = 4,
111 GST_RTCP_SDES_LOC = 5,
112 GST_RTCP_SDES_TOOL = 6,
113 GST_RTCP_SDES_NOTE = 7,
114 GST_RTCP_SDES_PRIV = 8
120 * The maximum text length for an SDES item.
122 #define GST_RTCP_MAX_SDES 255
125 * GST_RTCP_MAX_RB_COUNT:
127 * The maximum amount of Receiver report blocks in RR and SR messages.
129 #define GST_RTCP_MAX_RB_COUNT 31
132 * GST_RTCP_MAX_SDES_ITEM_COUNT:
134 * The maximum amount of SDES items.
136 #define GST_RTCP_MAX_SDES_ITEM_COUNT 31
139 * GST_RTCP_MAX_BYE_SSRC_COUNT:
141 * The maximum amount of SSRCs in a BYE packet.
143 #define GST_RTCP_MAX_BYE_SSRC_COUNT 31
146 * GST_RTCP_VALID_MASK:
148 * Mask for version, padding bit and packet type pair
150 #define GST_RTCP_VALID_MASK (0xc000 | 0x2000 | 0xfe)
152 * GST_RTCP_VALID_VALUE:
154 * Valid value for the first two bytes of an RTCP packet after applying
155 * #GST_RTCP_VALID_MASK to them.
157 #define GST_RTCP_VALID_VALUE ((GST_RTCP_VERSION << 14) | GST_RTCP_TYPE_SR)
159 typedef struct _GstRTCPPacket GstRTCPPacket;
163 * @buffer: pointer to RTCP buffer
164 * @offset: offset of packet in buffer data
166 * Data structure that points to a packet at @offset in @buffer.
167 * The size of the structure is made public to allow stack allocations.
169 struct _GstRTCPPacket
175 gboolean padding; /* padding field of current packet */
176 guint8 count; /* count field of current packet */
177 GstRTCPType type; /* type of current packet */
178 guint16 length; /* length of current packet in 32-bits words */
180 guint item_offset; /* current item offset for navigating SDES */
181 guint item_count; /* current item count */
182 guint entry_offset; /* current entry offset for navigating SDES items */
185 /* creating buffers */
186 GstBuffer* gst_rtcp_buffer_new_take_data (gpointer data, guint len);
187 GstBuffer* gst_rtcp_buffer_new_copy_data (gpointer data, guint len);
189 gboolean gst_rtcp_buffer_validate_data (guint8 *data, guint len);
190 gboolean gst_rtcp_buffer_validate (GstBuffer *buffer);
192 GstBuffer* gst_rtcp_buffer_new (guint mtu);
193 void gst_rtcp_buffer_end (GstBuffer *buffer);
195 /* adding/retrieving packets */
196 guint gst_rtcp_buffer_get_packet_count (GstBuffer *buffer);
197 gboolean gst_rtcp_buffer_get_first_packet (GstBuffer *buffer, GstRTCPPacket *packet);
198 gboolean gst_rtcp_packet_move_to_next (GstRTCPPacket *packet);
200 gboolean gst_rtcp_buffer_add_packet (GstBuffer *buffer, GstRTCPType type,
201 GstRTCPPacket *packet);
202 gboolean gst_rtcp_packet_remove (GstRTCPPacket *packet);
204 /* working with packets */
205 gboolean gst_rtcp_packet_get_padding (GstRTCPPacket *packet);
206 guint8 gst_rtcp_packet_get_count (GstRTCPPacket *packet);
207 GstRTCPType gst_rtcp_packet_get_type (GstRTCPPacket *packet);
208 guint16 gst_rtcp_packet_get_length (GstRTCPPacket *packet);
212 void gst_rtcp_packet_sr_get_sender_info (GstRTCPPacket *packet, guint32 *ssrc,
213 guint64 *ntptime, guint32 *rtptime,
214 guint32 *packet_count, guint32 *octet_count);
215 void gst_rtcp_packet_sr_set_sender_info (GstRTCPPacket *packet, guint32 ssrc,
216 guint64 ntptime, guint32 rtptime,
217 guint32 packet_count, guint32 octet_count);
218 /* receiver reports */
219 guint32 gst_rtcp_packet_rr_get_ssrc (GstRTCPPacket *packet);
220 void gst_rtcp_packet_rr_set_ssrc (GstRTCPPacket *packet, guint32 ssrc);
223 /* report blocks for SR and RR */
224 guint gst_rtcp_packet_get_rb_count (GstRTCPPacket *packet);
225 void gst_rtcp_packet_get_rb (GstRTCPPacket *packet, guint nth, guint32 *ssrc,
226 guint8 *fractionlost, gint32 *packetslost,
227 guint32 *exthighestseq, guint32 *jitter,
228 guint32 *lsr, guint32 *dlsr);
229 gboolean gst_rtcp_packet_add_rb (GstRTCPPacket *packet, guint32 ssrc,
230 guint8 fractionlost, gint32 packetslost,
231 guint32 exthighestseq, guint32 jitter,
232 guint32 lsr, guint32 dlsr);
233 void gst_rtcp_packet_set_rb (GstRTCPPacket *packet, guint nth, guint32 ssrc,
234 guint8 fractionlost, gint32 packetslost,
235 guint32 exthighestseq, guint32 jitter,
236 guint32 lsr, guint32 dlsr);
238 /* source description packet */
239 guint gst_rtcp_packet_sdes_get_item_count (GstRTCPPacket *packet);
240 gboolean gst_rtcp_packet_sdes_first_item (GstRTCPPacket *packet);
241 gboolean gst_rtcp_packet_sdes_next_item (GstRTCPPacket *packet);
242 guint32 gst_rtcp_packet_sdes_get_ssrc (GstRTCPPacket *packet);
243 gboolean gst_rtcp_packet_sdes_first_entry (GstRTCPPacket *packet);
244 gboolean gst_rtcp_packet_sdes_next_entry (GstRTCPPacket *packet);
245 gboolean gst_rtcp_packet_sdes_get_entry (GstRTCPPacket *packet,
246 GstRTCPSDESType *type, guint8 *len,
248 gboolean gst_rtcp_packet_sdes_copy_entry (GstRTCPPacket *packet,
249 GstRTCPSDESType *type, guint8 *len,
252 gboolean gst_rtcp_packet_sdes_add_item (GstRTCPPacket *packet, guint32 ssrc);
253 gboolean gst_rtcp_packet_sdes_add_entry (GstRTCPPacket *packet, GstRTCPSDESType type,
254 guint8 len, const guint8 *data);
257 guint gst_rtcp_packet_bye_get_ssrc_count (GstRTCPPacket *packet);
258 guint32 gst_rtcp_packet_bye_get_nth_ssrc (GstRTCPPacket *packet, guint nth);
259 gboolean gst_rtcp_packet_bye_add_ssrc (GstRTCPPacket *packet, guint32 ssrc);
260 gboolean gst_rtcp_packet_bye_add_ssrcs (GstRTCPPacket *packet, guint32 *ssrc, guint len);
261 guint8 gst_rtcp_packet_bye_get_reason_len (GstRTCPPacket *packet);
262 gchar* gst_rtcp_packet_bye_get_reason (GstRTCPPacket *packet);
263 gboolean gst_rtcp_packet_bye_set_reason (GstRTCPPacket *packet, const gchar *reason);
265 /* feedback packets */
266 guint32 gst_rtcp_packet_fb_get_sender_ssrc (GstRTCPPacket *packet);
267 void gst_rtcp_packet_fb_set_sender_ssrc (GstRTCPPacket *packet, guint32 ssrc);
268 guint32 gst_rtcp_packet_fb_get_media_ssrc (GstRTCPPacket *packet);
269 void gst_rtcp_packet_fb_set_media_ssrc (GstRTCPPacket *packet, guint32 ssrc);
270 GstRTCPFBType gst_rtcp_packet_fb_get_type (GstRTCPPacket *packet);
271 void gst_rtcp_packet_fb_set_type (GstRTCPPacket *packet, GstRTCPFBType type);
272 guint16 gst_rtcp_packet_fb_get_fci_length (GstRTCPPacket *packet);
273 gboolean gst_rtcp_packet_fb_set_fci_length (GstRTCPPacket *packet, guint16 wordlen);
274 guint8 * gst_rtcp_packet_fb_get_fci (GstRTCPPacket *packet);
276 /* helper functions */
277 guint64 gst_rtcp_ntp_to_unix (guint64 ntptime);
278 guint64 gst_rtcp_unix_to_ntp (guint64 unixtime);
280 const gchar * gst_rtcp_sdes_type_to_name (GstRTCPSDESType type);
281 GstRTCPSDESType gst_rtcp_sdes_name_to_type (const gchar *name);
285 #endif /* __GST_RTCPBUFFER_H__ */