gstrtpbuffer.h 9.36 KB
Newer Older
1 2
/* GStreamer
 * Copyright (C) <2005> Philippe Khalaf <burger@speedy.org>
3 4 5 6
 *               <2005> Wim Taymans <wim@fluendo.com>
 *
 * gstrtpbuffer.h: various helper functions to manipulate buffers
 *     with RTP payload.
7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
20 21
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
22 23 24 25 26 27
 */

#ifndef __GST_RTPBUFFER_H__
#define __GST_RTPBUFFER_H__

#include <gst/gst.h>
28
#include <gst/rtp/gstrtppayloads.h>
29 30 31

G_BEGIN_DECLS

Wim Taymans's avatar
Wim Taymans committed
32 33 34 35 36
/**
 * GST_RTP_VERSION:
 *
 * The supported RTP version 2.
 */
37 38
#define GST_RTP_VERSION 2

Wim Taymans's avatar
Wim Taymans committed
39 40 41 42 43 44

typedef struct _GstRTPBuffer GstRTPBuffer;

/**
 * GstRTPBuffer:
 * @buffer: pointer to RTP buffer
Wim Taymans's avatar
Wim Taymans committed
45
 * @state: internal state
Wim Taymans's avatar
Wim Taymans committed
46 47
 * @data: array of data
 * @size: array of size
Wim Taymans's avatar
Wim Taymans committed
48
 * @map: array of #GstMapInfo
Wim Taymans's avatar
Wim Taymans committed
49 50 51 52 53 54 55
 *
 * Data structure that points to an RTP packet.
 * The size of the structure is made public to allow stack allocations.
 */
struct _GstRTPBuffer
{
  GstBuffer   *buffer;
Wim Taymans's avatar
Wim Taymans committed
56
  guint        state;
57 58
  gpointer     data[4];
  gsize        size[4];
Wim Taymans's avatar
Wim Taymans committed
59
  GstMapInfo   map[4];
Wim Taymans's avatar
Wim Taymans committed
60 61
};

Wim Taymans's avatar
Wim Taymans committed
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_EXPORT
Wim Taymans's avatar
Wim Taymans committed
68
void            gst_rtp_buffer_allocate_data         (GstBuffer *buffer, guint payload_len,
Wim Taymans's avatar
Wim Taymans committed
69
                                                      guint8 pad_len, guint8 csrc_count);
70

71
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
72
GstBuffer*      gst_rtp_buffer_new_take_data         (gpointer data, gsize len);
73 74

GST_EXPORT
75
GstBuffer*      gst_rtp_buffer_new_copy_data         (gconstpointer data, gsize len);
76 77

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
78
GstBuffer*      gst_rtp_buffer_new_allocate          (guint payload_len, guint8 pad_len, guint8 csrc_count);
79 80

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
81
GstBuffer*      gst_rtp_buffer_new_allocate_len      (guint packet_len, guint8 pad_len, guint8 csrc_count);
82

83
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
84
guint           gst_rtp_buffer_calc_header_len       (guint8 csrc_count);
85 86

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
87
guint           gst_rtp_buffer_calc_packet_len       (guint payload_len, guint8 pad_len, guint8 csrc_count);
88 89

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
90
guint           gst_rtp_buffer_calc_payload_len      (guint packet_len, guint8 pad_len, guint8 csrc_count);
91

92
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
93
gboolean        gst_rtp_buffer_map                   (GstBuffer *buffer, GstMapFlags flags, GstRTPBuffer *rtp);
94 95

GST_EXPORT
96
void            gst_rtp_buffer_unmap                 (GstRTPBuffer *rtp);
Wim Taymans's avatar
Wim Taymans committed
97

98
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
99
void            gst_rtp_buffer_set_packet_len        (GstRTPBuffer *rtp, guint len);
100 101

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
102 103
guint           gst_rtp_buffer_get_packet_len        (GstRTPBuffer *rtp);

104
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
105
guint           gst_rtp_buffer_get_header_len        (GstRTPBuffer *rtp);
106

107
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
108
guint8          gst_rtp_buffer_get_version           (GstRTPBuffer *rtp);
109 110

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
111
void            gst_rtp_buffer_set_version           (GstRTPBuffer *rtp, guint8 version);
112

113
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
114
gboolean        gst_rtp_buffer_get_padding           (GstRTPBuffer *rtp);
115 116

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
117
void            gst_rtp_buffer_set_padding           (GstRTPBuffer *rtp, gboolean padding);
118 119

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
120
void            gst_rtp_buffer_pad_to                (GstRTPBuffer *rtp, guint len);
121

122
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
123
gboolean        gst_rtp_buffer_get_extension         (GstRTPBuffer *rtp);
124 125

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
126
void            gst_rtp_buffer_set_extension         (GstRTPBuffer *rtp, gboolean extension);
127 128

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
129
gboolean        gst_rtp_buffer_get_extension_data    (GstRTPBuffer *rtp, guint16 *bits,
Wim Taymans's avatar
Wim Taymans committed
130
                                                      gpointer *data, guint *wordlen);
131 132

GST_EXPORT
133
GBytes*         gst_rtp_buffer_get_extension_bytes   (GstRTPBuffer *rtp, guint16 *bits);
134 135

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
136
gboolean        gst_rtp_buffer_set_extension_data    (GstRTPBuffer *rtp, guint16 bits, guint16 length);
137

138
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
139
guint32         gst_rtp_buffer_get_ssrc              (GstRTPBuffer *rtp);
140 141

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
142
void            gst_rtp_buffer_set_ssrc              (GstRTPBuffer *rtp, guint32 ssrc);
143

144
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
145
guint8          gst_rtp_buffer_get_csrc_count        (GstRTPBuffer *rtp);
146 147

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
148
guint32         gst_rtp_buffer_get_csrc              (GstRTPBuffer *rtp, guint8 idx);
149 150

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
151
void            gst_rtp_buffer_set_csrc              (GstRTPBuffer *rtp, guint8 idx, guint32 csrc);
152

153
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
154
gboolean        gst_rtp_buffer_get_marker            (GstRTPBuffer *rtp);
155 156

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
157
void            gst_rtp_buffer_set_marker            (GstRTPBuffer *rtp, gboolean marker);
158

159
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
160
guint8          gst_rtp_buffer_get_payload_type      (GstRTPBuffer *rtp);
161 162

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
163
void            gst_rtp_buffer_set_payload_type      (GstRTPBuffer *rtp, guint8 payload_type);
164

165
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
166
guint16         gst_rtp_buffer_get_seq               (GstRTPBuffer *rtp);
167 168

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
169
void            gst_rtp_buffer_set_seq               (GstRTPBuffer *rtp, guint16 seq);
Wim Taymans's avatar
Wim Taymans committed
170

171
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
172
guint32         gst_rtp_buffer_get_timestamp         (GstRTPBuffer *rtp);
173 174

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
175
void            gst_rtp_buffer_set_timestamp         (GstRTPBuffer *rtp, guint32 timestamp);
176

177
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
178
GstBuffer*      gst_rtp_buffer_get_payload_buffer    (GstRTPBuffer *rtp);
179 180

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
181
GstBuffer*      gst_rtp_buffer_get_payload_subbuffer (GstRTPBuffer *rtp, guint offset, guint len);
Wim Taymans's avatar
Wim Taymans committed
182

183
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
184
guint           gst_rtp_buffer_get_payload_len       (GstRTPBuffer *rtp);
185 186

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
187
gpointer        gst_rtp_buffer_get_payload           (GstRTPBuffer *rtp);
188 189

GST_EXPORT
190
GBytes*         gst_rtp_buffer_get_payload_bytes     (GstRTPBuffer *rtp);
191

192
/* some helpers */
193 194

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
195
guint32         gst_rtp_buffer_default_clock_rate    (guint8 payload_type);
196 197

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
198
gint            gst_rtp_buffer_compare_seqnum        (guint16 seqnum1, guint16 seqnum2);
199 200

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
201
guint64         gst_rtp_buffer_ext_timestamp         (guint64 *exttimestamp, guint32 timestamp);
202

203
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
204 205 206 207 208
gboolean        gst_rtp_buffer_get_extension_onebyte_header  (GstRTPBuffer *rtp,
                                                              guint8 id,
                                                              guint nth,
                                                              gpointer * data,
                                                              guint * size);
209 210

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
211
gboolean        gst_rtp_buffer_get_extension_twobytes_header (GstRTPBuffer *rtp,
212 213 214 215 216 217
                                                              guint8 * appbits,
                                                              guint8 id,
                                                              guint nth,
                                                              gpointer * data,
                                                              guint * size);

218
GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
219 220
gboolean       gst_rtp_buffer_add_extension_onebyte_header  (GstRTPBuffer *rtp,
                                                             guint8 id,
221
                                                             gconstpointer data,
Wim Taymans's avatar
Wim Taymans committed
222
                                                             guint size);
223 224

GST_EXPORT
Wim Taymans's avatar
Wim Taymans committed
225
gboolean       gst_rtp_buffer_add_extension_twobytes_header (GstRTPBuffer *rtp,
226 227
                                                             guint8 appbits,
                                                             guint8 id,
228
                                                             gconstpointer data,
229
                                                             guint size);
230

231 232 233 234
/**
 * GstRTPBufferFlags:
 * @GST_RTP_BUFFER_FLAG_RETRANSMISSION: The #GstBuffer was once wrapped
 *           in a retransmitted packet as specified by RFC 4588.
235 236 237 238
 * @GST_RTP_BUFFER_FLAG_REDUNDANT:      The packet represents redundant RTP packet.
 *           The flag is used in gstrtpstorage to be able to hold the packetback
 *           and use it only for recovery from packet loss.
 *           Since: 1.14
239 240 241 242 243 244 245 246 247 248 249 250
 * @GST_RTP_BUFFER_FLAG_LAST:           Offset to define more flags.
 *
 * Additional RTP buffer flags. These flags can potentially be used on any
 * buffers carrying RTP packets.
 *
 * Note that these are only valid for #GstCaps of type: application/x-rtp (x-rtcp).
 * They can conflict with other extended buffer flags.
 *
 * Since: 1.10
 */
typedef enum {
  GST_RTP_BUFFER_FLAG_RETRANSMISSION = (GST_BUFFER_FLAG_LAST << 0),
251
  GST_RTP_BUFFER_FLAG_REDUNDANT      = (GST_BUFFER_FLAG_LAST << 1),
252 253 254
  GST_RTP_BUFFER_FLAG_LAST           = (GST_BUFFER_FLAG_LAST << 8)
} GstRTPBufferFlags;

255 256 257 258 259 260 261 262 263
/**
 * GstRTPBufferMapFlags:
 * @GST_RTP_BUFFER_MAP_FLAG_SKIP_PADDING: Skip mapping and validation of RTP
 *           padding and RTP pad count when present. Useful for buffers where
 *           the padding may be encrypted.
 * @GST_RTP_BUFFER_MAP_FLAG_LAST: Offset to define more flags
 *
 * Additional mapping flags for gst_rtp_buffer_map().
 *
264
 * Since: 1.6.1
265 266 267 268 269 270
 */
typedef enum {
  GST_RTP_BUFFER_MAP_FLAG_SKIP_PADDING = (GST_MAP_FLAG_LAST << 0),
  GST_RTP_BUFFER_MAP_FLAG_LAST         = (GST_MAP_FLAG_LAST << 8)
  /* 8 more flags possible afterwards */
} GstRTPBufferMapFlags;
271

272 273 274 275
G_END_DECLS

#endif /* __GST_RTPBUFFER_H__ */