diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2012-09-24 12:13:32 +0200 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2012-11-06 09:18:54 +0100 |
commit | 82d327fb9191bdb3632b680c4a2794f6538afc63 (patch) | |
tree | 17eec7f3e0fba68ee6bfefd9e60e5ec2c5a2ddca /gst-libs | |
parent | 6cbcca0bc5a32a47cfb85b8a3dcf17223dccbba2 (diff) |
rtp: add helpers for header extensions
Add helpers and defines for the NTP-64 and NTP-56 header extensions.
Diffstat (limited to 'gst-libs')
-rw-r--r-- | gst-libs/gst/rtp/Makefile.am | 2 | ||||
-rw-r--r-- | gst-libs/gst/rtp/gstrtcpbuffer.h | 28 | ||||
-rw-r--r-- | gst-libs/gst/rtp/gstrtphdrext.c | 139 | ||||
-rw-r--r-- | gst-libs/gst/rtp/gstrtphdrext.h | 50 |
4 files changed, 207 insertions, 12 deletions
diff --git a/gst-libs/gst/rtp/Makefile.am b/gst-libs/gst/rtp/Makefile.am index fc65d52e5..38f3cf583 100644 --- a/gst-libs/gst/rtp/Makefile.am +++ b/gst-libs/gst/rtp/Makefile.am @@ -3,6 +3,7 @@ libgstrtpincludedir = $(includedir)/gstreamer-@GST_API_VERSION@/gst/rtp libgstrtpinclude_HEADERS = gstrtpbuffer.h \ gstrtcpbuffer.h \ gstrtppayloads.h \ + gstrtphdrext.h \ gstrtpbaseaudiopayload.h \ gstrtpbasepayload.h \ gstrtpbasedepayload.h @@ -12,6 +13,7 @@ lib_LTLIBRARIES = libgstrtp-@GST_API_VERSION@.la libgstrtp_@GST_API_VERSION@_la_SOURCES = gstrtpbuffer.c \ gstrtcpbuffer.c \ gstrtppayloads.c \ + gstrtphdrext.c \ gstrtpbaseaudiopayload.c \ gstrtpbasepayload.c \ gstrtpbasedepayload.c diff --git a/gst-libs/gst/rtp/gstrtcpbuffer.h b/gst-libs/gst/rtp/gstrtcpbuffer.h index 8e41b50f9..b5ff4a179 100644 --- a/gst-libs/gst/rtp/gstrtcpbuffer.h +++ b/gst-libs/gst/rtp/gstrtcpbuffer.h @@ -66,6 +66,8 @@ typedef enum * @GST_RTCP_RTPFB_TYPE_TMMBR: Temporary Maximum Media Stream Bit Rate Request * @GST_RTCP_RTPFB_TYPE_TMMBN: Temporary Maximum Media Stream Bit Rate * Notification + * @GST_RTCP_RTPFB_TYPE_RTCP_SR_SEQ: Request an SR packet for early + * synchronization * @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 @@ -80,22 +82,24 @@ typedef enum typedef enum { /* generic */ - GST_RTCP_FB_TYPE_INVALID = 0, + GST_RTCP_FB_TYPE_INVALID = 0, /* RTPFB types */ - GST_RTCP_RTPFB_TYPE_NACK = 1, + GST_RTCP_RTPFB_TYPE_NACK = 1, /* RTPFB types assigned in RFC 5104 */ - GST_RTCP_RTPFB_TYPE_TMMBR = 3, - GST_RTCP_RTPFB_TYPE_TMMBN = 4, + GST_RTCP_RTPFB_TYPE_TMMBR = 3, + GST_RTCP_RTPFB_TYPE_TMMBN = 4, + /* RTPFB types assigned in RFC 6051 */ + GST_RTCP_RTPFB_TYPE_RCTP_SR_REQ = 5, /* 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, + GST_RTCP_PSFB_TYPE_PLI = 1, + GST_RTCP_PSFB_TYPE_SLI = 2, + GST_RTCP_PSFB_TYPE_RPSI = 3, + GST_RTCP_PSFB_TYPE_AFB = 15, /* PSFB types assigned in RFC 5104 */ - GST_RTCP_PSFB_TYPE_FIR = 4, - GST_RTCP_PSFB_TYPE_TSTR = 5, - GST_RTCP_PSFB_TYPE_TSTN = 6, - GST_RTCP_PSFB_TYPE_VBCN = 7, + GST_RTCP_PSFB_TYPE_FIR = 4, + GST_RTCP_PSFB_TYPE_TSTR = 5, + GST_RTCP_PSFB_TYPE_TSTN = 6, + GST_RTCP_PSFB_TYPE_VBCN = 7, } GstRTCPFBType; /** diff --git a/gst-libs/gst/rtp/gstrtphdrext.c b/gst-libs/gst/rtp/gstrtphdrext.c new file mode 100644 index 000000000..fd83b0e50 --- /dev/null +++ b/gst-libs/gst/rtp/gstrtphdrext.c @@ -0,0 +1,139 @@ +/* GStreamer + * Copyright (C) <2012> Wim Taymans <wim.taymans@gmail.com> + * + * 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 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:gstrtpexthdr + * @short_description: Helper methods for dealing with RTP header extensions + * @see_also: #GstRTPBasePayload, #GstRTPBaseDepayload, gstrtpbuffer + * + * <refsect2> + * <para> + * </para> + * </refsect2> + * + * Last reviewed on 2012-09-24 (1.0) + */ + +#include "gstrtphdrext.h" + +#include <stdlib.h> +#include <string.h> + +/** + * gst_rtp_hdrext_set_ntp_64: + * @data: the data to write to + * @size: the size of @data + * @ntptime: the NTP time + * + * Writes the NTP time in @ntptime to the format required for the NTP-64 header + * extension. @data must hold at least #GST_RTP_HDREXT_NTP_64_SIZE bytes. + * + * Returns: %TRUE on success. + */ +gboolean +gst_rtp_hdrext_set_ntp_64 (gpointer data, guint size, guint64 ntptime) +{ + g_return_val_if_fail (data != NULL, FALSE); + g_return_val_if_fail (size >= GST_RTP_HDREXT_NTP_64_SIZE, FALSE); + + GST_WRITE_UINT64_BE (data, ntptime); + + return TRUE; +} + +/** + * gst_rtp_hdrext_get_ntp_64: + * @data: the data to read from + * @size: the size of @data + * @ntptime: the result NTP time + * + * Reads the NTP time from the @size NTP-64 extension bytes in @data and store the + * result in @ntptime. + * + * Returns: %TRUE on success. + */ +gboolean +gst_rtp_hdrext_get_ntp_64 (gpointer data, guint size, guint64 * ntptime) +{ + g_return_val_if_fail (data != NULL, FALSE); + g_return_val_if_fail (size >= GST_RTP_HDREXT_NTP_64_SIZE, FALSE); + + if (ntptime) + *ntptime = GST_READ_UINT64_BE (data); + + return TRUE; +} + +/** + * gst_rtp_hdrext_set_ntp_56: + * @data: the data to write to + * @size: the size of @data + * @ntptime: the NTP time + * + * Writes the NTP time in @ntptime to the format required for the NTP-56 header + * extension. @data must hold at least #GST_RTP_HDREXT_NTP_56_SIZE bytes. + * + * Returns: %TRUE on success. + */ +gboolean +gst_rtp_hdrext_set_ntp_56 (gpointer data, guint size, guint64 ntptime) +{ + guint8 *d = data; + gint i; + + g_return_val_if_fail (data != NULL, FALSE); + g_return_val_if_fail (size >= GST_RTP_HDREXT_NTP_56_SIZE, FALSE); + + for (i = 0; i < 7; i++) { + d[6 - i] = ntptime & 0xff; + ntptime >>= 8; + } + return TRUE; +} + +/** + * gst_rtp_hdrext_get_ntp_56: + * @data: the data to read from + * @size: the size of @data + * @ntptime: the result NTP time + * + * Reads the NTP time from the @size NTP-56 extension bytes in @data and store the + * result in @ntptime. + * + * Returns: %TRUE on success. + */ +gboolean +gst_rtp_hdrext_get_ntp_56 (gpointer data, guint size, guint64 * ntptime) +{ + guint8 *d = data; + + g_return_val_if_fail (data != NULL, FALSE); + g_return_val_if_fail (size >= GST_RTP_HDREXT_NTP_56_SIZE, FALSE); + + if (ntptime) { + gint i; + + *ntptime = 0; + for (i = 0; i < 7; i++) { + *ntptime |= d[6 - i]; + *ntptime <<= 8; + } + } + return TRUE; +} diff --git a/gst-libs/gst/rtp/gstrtphdrext.h b/gst-libs/gst/rtp/gstrtphdrext.h new file mode 100644 index 000000000..0447a7f21 --- /dev/null +++ b/gst-libs/gst/rtp/gstrtphdrext.h @@ -0,0 +1,50 @@ +/* GStreamer + * Copyright (C) <2012> Wim Taymans <wim.taymans@gmail.com> + * + * gstrtphdrext.h: RTP header extensions + * + * 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 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_RTPHDREXT_H__ +#define __GST_RTPHDREXT_H__ + +#include <gst/gst.h> +#include <gst/rtp/gstrtpbuffer.h> + +G_BEGIN_DECLS + +#define GST_RTP_HDREXT_BASE "urn:ietf:params:rtp-hdrext:" + +/* RFC 6051 */ +#define GST_RTP_HDREXT_NTP_64 "ntp-64" + +#define GST_RTP_HDREXT_NTP_64_SIZE 8 + +gboolean gst_rtp_hdrext_set_ntp_64 (gpointer data, guint size, guint64 ntptime); +gboolean gst_rtp_hdrext_get_ntp_64 (gpointer data, guint size, guint64 *ntptime); + +#define GST_RTP_HDREXT_NTP_56 "ntp-56" + +#define GST_RTP_HDREXT_NTP_56_SIZE 7 + +gboolean gst_rtp_hdrext_set_ntp_56 (gpointer data, guint size, guint64 ntptime); +gboolean gst_rtp_hdrext_get_ntp_56 (gpointer data, guint size, guint64 *ntptime); + +G_END_DECLS + +#endif /* __GST_RTPHDREXT_H__ */ + |