aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2014-06-20 14:29:01 +0200
committerJacob Erlbeck <jerlbeck@sysmocom.de>2014-08-04 10:33:01 +0200
commit713187aa937e8903993ac8b951cda2c121e86572 (patch)
tree51d96c88d3017b7869e0f0a08c43f43a9e6dca8f
parentb7ade8a00f27b3edb5babe0cdde4cb90cad50e68 (diff)
rtp: Add header file for RTP header access
This patch adds a header file containing the rtp_hdr struct definition along with getters/setters to access the multibyte fields. Sponsored-by: On-Waves ehf
-rw-r--r--openbsc/include/openbsc/Makefile.am2
-rw-r--r--openbsc/include/openbsc/rtp.h97
2 files changed, 98 insertions, 1 deletions
diff --git a/openbsc/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am
index b739d0f46..23386f1f0 100644
--- a/openbsc/include/openbsc/Makefile.am
+++ b/openbsc/include/openbsc/Makefile.am
@@ -14,7 +14,7 @@ noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \
osmo_msc_data.h osmo_bsc_grace.h sms_queue.h abis_om2000.h \
bss.h gsm_data_shared.h control_cmd.h ipaccess.h mncc_int.h \
arfcn_range_encode.h nat_rewrite_trie.h bsc_nat_callstats.h \
- osmux.h mgcp_transcode.h
+ osmux.h mgcp_transcode.h rtp.h
openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h
openbscdir = $(includedir)/openbsc
diff --git a/openbsc/include/openbsc/rtp.h b/openbsc/include/openbsc/rtp.h
new file mode 100644
index 000000000..c4554c7b8
--- /dev/null
+++ b/openbsc/include/openbsc/rtp.h
@@ -0,0 +1,97 @@
+/* RTP: A Transport Protocol for Real-Time Applications: RFC 3550 */
+
+/*
+ * (C) 2009-2013 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2014 by On-Waves
+ * Author: Jacob Erlbeck <jerlbeck@sysmocom.de>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#pragma once
+
+#include <endian.h>
+#include <stdint.h>
+
+/* according to rtp_proxy.c RFC 3550 */
+struct rtp_hdr {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ uint8_t csrc_count:4,
+ extension:1,
+ padding:1,
+ version:2;
+ uint8_t payload_type:7,
+ marker:1;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ uint8_t version:2,
+ padding:1,
+ extension:1,
+ csrc_count:4;
+ uint8_t marker:1,
+ payload_type:7;
+#endif
+ uint16_t sequence_be;
+ uint32_t timestamp_be;
+ uint32_t ssrc_be;
+ uint8_t data[0];
+} __attribute__((packed));
+
+inline size_t rtp_header_len(const struct rtp_hdr *rtp)
+{
+ size_t len = sizeof(struct rtp_hdr);
+
+#if 0
+ /* TODO: Just fail if csrc or extension present, reenable when test
+ * cases are present */
+ len += rtp->csrc_count * 4;
+ if (rtp->extension)
+ len += 4 + 4 * ntohs(*(uint16_t *)(rtp->data + 2));
+#endif
+
+ return len;
+}
+
+/* TODO: Payload length computation (consider padding) */
+
+inline uint16_t rtp_sequence(const struct rtp_hdr *rtp)
+{
+ return ntohs(rtp->sequence_be);
+}
+
+inline void rtp_set_sequence(struct rtp_hdr *rtp, uint16_t seq)
+{
+ rtp->sequence_be = htons(seq);
+}
+
+inline uint32_t rtp_ssrc(const struct rtp_hdr *rtp)
+{
+ return ntohl(rtp->ssrc_be);
+}
+
+inline void rtp_set_ssrc(struct rtp_hdr *rtp, uint32_t ssrc)
+{
+ rtp->ssrc_be = htonl(ssrc);
+}
+
+inline uint32_t rtp_timestamp(const struct rtp_hdr *rtp)
+{
+ return ntohl(rtp->timestamp_be);
+}
+
+inline void rtp_set_timestamp(struct rtp_hdr *rtp, uint32_t timestamp)
+{
+ rtp->timestamp_be = htonl(timestamp);
+}