• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) <2005> Philippe Khalaf <burger@speedy.org>
3  *               <2005> Wim Taymans <wim@fluendo.com>
4  *
5  * gstrtpbuffer.h: various helper functions to manipulate buffers
6  *     with RTP payload.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #ifndef __GST_RTPBUFFER_H__
25 #define __GST_RTPBUFFER_H__
26 
27 #include <gst/gst.h>
28 #include <gst/rtp/gstrtppayloads.h>
29 
30 G_BEGIN_DECLS
31 
32 /**
33  * GST_RTP_VERSION:
34  *
35  * The supported RTP version 2.
36  */
37 #define GST_RTP_VERSION 2
38 
39 
40 typedef struct _GstRTPBuffer GstRTPBuffer;
41 
42 /**
43  * GstRTPBuffer:
44  * @buffer: pointer to RTP buffer
45  * @state: internal state
46  * @data: array of data
47  * @size: array of size
48  * @map: array of #GstMapInfo
49  *
50  * Data structure that points to an RTP packet.
51  * The size of the structure is made public to allow stack allocations.
52  */
53 struct _GstRTPBuffer
54 {
55   GstBuffer   *buffer;
56   guint        state;
57   gpointer     data[4];
58   gsize        size[4];
59   GstMapInfo   map[4];
60 };
61 
62 #define GST_RTP_BUFFER_INIT { NULL, 0, { NULL, NULL, NULL, NULL}, { 0, 0, 0, 0 }, \
63   { GST_MAP_INFO_INIT, GST_MAP_INFO_INIT, GST_MAP_INFO_INIT, GST_MAP_INFO_INIT} }
64 
65 /* creating buffers */
66 
67 GST_RTP_API
68 void            gst_rtp_buffer_allocate_data         (GstBuffer *buffer, guint payload_len,
69                                                       guint8 pad_len, guint8 csrc_count);
70 
71 GST_RTP_API
72 GstBuffer*      gst_rtp_buffer_new_take_data         (gpointer data, gsize len);
73 
74 GST_RTP_API
75 GstBuffer*      gst_rtp_buffer_new_copy_data         (gconstpointer data, gsize len);
76 
77 GST_RTP_API
78 GstBuffer*      gst_rtp_buffer_new_allocate          (guint payload_len, guint8 pad_len, guint8 csrc_count);
79 
80 GST_RTP_API
81 GstBuffer*      gst_rtp_buffer_new_allocate_len      (guint packet_len, guint8 pad_len, guint8 csrc_count);
82 
83 GST_RTP_API
84 guint           gst_rtp_buffer_calc_header_len       (guint8 csrc_count);
85 
86 GST_RTP_API
87 guint           gst_rtp_buffer_calc_packet_len       (guint payload_len, guint8 pad_len, guint8 csrc_count);
88 
89 GST_RTP_API
90 guint           gst_rtp_buffer_calc_payload_len      (guint packet_len, guint8 pad_len, guint8 csrc_count);
91 
92 GST_RTP_API
93 gboolean        gst_rtp_buffer_map                   (GstBuffer *buffer, GstMapFlags flags, GstRTPBuffer *rtp);
94 
95 GST_RTP_API
96 void            gst_rtp_buffer_unmap                 (GstRTPBuffer *rtp);
97 
98 GST_RTP_API
99 void            gst_rtp_buffer_set_packet_len        (GstRTPBuffer *rtp, guint len);
100 
101 GST_RTP_API
102 guint           gst_rtp_buffer_get_packet_len        (GstRTPBuffer *rtp);
103 
104 GST_RTP_API
105 guint           gst_rtp_buffer_get_header_len        (GstRTPBuffer *rtp);
106 
107 GST_RTP_API
108 guint8          gst_rtp_buffer_get_version           (GstRTPBuffer *rtp);
109 
110 GST_RTP_API
111 void            gst_rtp_buffer_set_version           (GstRTPBuffer *rtp, guint8 version);
112 
113 GST_RTP_API
114 gboolean        gst_rtp_buffer_get_padding           (GstRTPBuffer *rtp);
115 
116 GST_RTP_API
117 void            gst_rtp_buffer_set_padding           (GstRTPBuffer *rtp, gboolean padding);
118 
119 GST_RTP_API
120 void            gst_rtp_buffer_pad_to                (GstRTPBuffer *rtp, guint len);
121 
122 GST_RTP_API
123 gboolean        gst_rtp_buffer_get_extension         (GstRTPBuffer *rtp);
124 
125 GST_RTP_API
126 void            gst_rtp_buffer_set_extension         (GstRTPBuffer *rtp, gboolean extension);
127 
128 GST_RTP_API
129 gboolean        gst_rtp_buffer_get_extension_data    (GstRTPBuffer *rtp, guint16 *bits,
130                                                       gpointer *data, guint *wordlen);
131 
132 GST_RTP_API
133 GBytes*         gst_rtp_buffer_get_extension_bytes   (GstRTPBuffer *rtp, guint16 *bits);
134 
135 GST_RTP_API
136 gboolean        gst_rtp_buffer_set_extension_data    (GstRTPBuffer *rtp, guint16 bits, guint16 length);
137 
138 GST_RTP_API
139 void            gst_rtp_buffer_remove_extension_data (GstRTPBuffer *rtp);
140 
141 GST_RTP_API
142 guint32         gst_rtp_buffer_get_ssrc              (GstRTPBuffer *rtp);
143 
144 GST_RTP_API
145 void            gst_rtp_buffer_set_ssrc              (GstRTPBuffer *rtp, guint32 ssrc);
146 
147 GST_RTP_API
148 guint8          gst_rtp_buffer_get_csrc_count        (GstRTPBuffer *rtp);
149 
150 GST_RTP_API
151 guint32         gst_rtp_buffer_get_csrc              (GstRTPBuffer *rtp, guint8 idx);
152 
153 GST_RTP_API
154 void            gst_rtp_buffer_set_csrc              (GstRTPBuffer *rtp, guint8 idx, guint32 csrc);
155 
156 GST_RTP_API
157 gboolean        gst_rtp_buffer_get_marker            (GstRTPBuffer *rtp);
158 
159 GST_RTP_API
160 void            gst_rtp_buffer_set_marker            (GstRTPBuffer *rtp, gboolean marker);
161 
162 GST_RTP_API
163 guint8          gst_rtp_buffer_get_payload_type      (GstRTPBuffer *rtp);
164 
165 GST_RTP_API
166 void            gst_rtp_buffer_set_payload_type      (GstRTPBuffer *rtp, guint8 payload_type);
167 
168 GST_RTP_API
169 guint16         gst_rtp_buffer_get_seq               (GstRTPBuffer *rtp);
170 
171 GST_RTP_API
172 void            gst_rtp_buffer_set_seq               (GstRTPBuffer *rtp, guint16 seq);
173 
174 GST_RTP_API
175 guint32         gst_rtp_buffer_get_timestamp         (GstRTPBuffer *rtp);
176 
177 GST_RTP_API
178 void            gst_rtp_buffer_set_timestamp         (GstRTPBuffer *rtp, guint32 timestamp);
179 
180 GST_RTP_API
181 GstBuffer*      gst_rtp_buffer_get_payload_buffer    (GstRTPBuffer *rtp);
182 
183 GST_RTP_API
184 GstBuffer*      gst_rtp_buffer_get_payload_subbuffer (GstRTPBuffer *rtp, guint offset, guint len);
185 
186 GST_RTP_API
187 guint           gst_rtp_buffer_get_payload_len       (GstRTPBuffer *rtp);
188 
189 GST_RTP_API
190 gpointer        gst_rtp_buffer_get_payload           (GstRTPBuffer *rtp);
191 
192 GST_RTP_API
193 GBytes*         gst_rtp_buffer_get_payload_bytes     (GstRTPBuffer *rtp);
194 
195 /* some helpers */
196 
197 GST_RTP_API
198 guint32         gst_rtp_buffer_default_clock_rate    (guint8 payload_type);
199 
200 GST_RTP_API
201 gint            gst_rtp_buffer_compare_seqnum        (guint16 seqnum1, guint16 seqnum2);
202 
203 GST_RTP_API
204 guint64         gst_rtp_buffer_ext_timestamp         (guint64 *exttimestamp, guint32 timestamp);
205 
206 GST_RTP_API
207 gboolean        gst_rtp_buffer_get_extension_onebyte_header  (GstRTPBuffer *rtp,
208                                                               guint8 id,
209                                                               guint nth,
210                                                               gpointer * data,
211                                                               guint * size);
212 
213 GST_RTP_API
214 gboolean        gst_rtp_buffer_get_extension_twobytes_header (GstRTPBuffer *rtp,
215                                                               guint8 * appbits,
216                                                               guint8 id,
217                                                               guint nth,
218                                                               gpointer * data,
219                                                               guint * size);
220 
221 GST_RTP_API
222 gboolean       gst_rtp_buffer_add_extension_onebyte_header  (GstRTPBuffer *rtp,
223                                                              guint8 id,
224                                                              gconstpointer data,
225                                                              guint size);
226 
227 GST_RTP_API
228 gboolean       gst_rtp_buffer_add_extension_twobytes_header (GstRTPBuffer *rtp,
229                                                              guint8 appbits,
230                                                              guint8 id,
231                                                              gconstpointer data,
232                                                              guint size);
233 
234 GST_RTP_API
235 gboolean gst_rtp_buffer_get_extension_onebyte_header_from_bytes (GBytes * bytes,
236                                                                  guint16 bit_pattern,
237                                                                  guint8 id,
238                                                                  guint nth,
239                                                                  gpointer * data,
240                                                                  guint * size);
241 
242 /**
243  * GstRTPBufferFlags:
244  * @GST_RTP_BUFFER_FLAG_RETRANSMISSION: The #GstBuffer was once wrapped
245  *           in a retransmitted packet as specified by RFC 4588.
246  * @GST_RTP_BUFFER_FLAG_REDUNDANT:      The packet represents redundant RTP packet.
247  *           The flag is used in gstrtpstorage to be able to hold the packetback
248  *           and use it only for recovery from packet loss.
249  *           Since: 1.14
250  * @GST_RTP_BUFFER_FLAG_LAST:           Offset to define more flags.
251  *
252  * Additional RTP buffer flags. These flags can potentially be used on any
253  * buffers carrying RTP packets.
254  *
255  * Note that these are only valid for #GstCaps of type: application/x-rtp (x-rtcp).
256  * They can conflict with other extended buffer flags.
257  *
258  * Since: 1.10
259  */
260 typedef enum {
261   GST_RTP_BUFFER_FLAG_RETRANSMISSION = (GST_BUFFER_FLAG_LAST << 0),
262   GST_RTP_BUFFER_FLAG_REDUNDANT      = (GST_BUFFER_FLAG_LAST << 1),
263   GST_RTP_BUFFER_FLAG_LAST           = (GST_BUFFER_FLAG_LAST << 8)
264 } GstRTPBufferFlags;
265 
266 /**
267  * GstRTPBufferMapFlags:
268  * @GST_RTP_BUFFER_MAP_FLAG_SKIP_PADDING: Skip mapping and validation of RTP
269  *           padding and RTP pad count when present. Useful for buffers where
270  *           the padding may be encrypted.
271  * @GST_RTP_BUFFER_MAP_FLAG_LAST: Offset to define more flags
272  *
273  * Additional mapping flags for gst_rtp_buffer_map().
274  *
275  * Since: 1.6.1
276  */
277 typedef enum {
278   GST_RTP_BUFFER_MAP_FLAG_SKIP_PADDING = (GST_MAP_FLAG_LAST << 0),
279   GST_RTP_BUFFER_MAP_FLAG_LAST         = (GST_MAP_FLAG_LAST << 8)
280   /* 8 more flags possible afterwards */
281 } GstRTPBufferMapFlags;
282 
283 G_END_DECLS
284 
285 #endif /* __GST_RTPBUFFER_H__ */
286 
287