libosmo-netif 1.5.1.5-89a1
Osmocom network interface library
rtp.h
1#ifndef _OSMO_RTP_H_
2#define _OSMO_RTP_H_
3
4#include <osmocom/core/endian.h>
5
6/* RTP header as defined by RFC 3550 */
7struct rtp_hdr {
8#if OSMO_IS_LITTLE_ENDIAN
9 uint8_t csrc_count:4,
10 extension:1,
11 padding:1,
12 version:2;
13 uint8_t payload_type:7,
14 marker:1;
15#elif OSMO_IS_BIG_ENDIAN
16/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */
17 uint8_t version:2, padding:1, extension:1, csrc_count:4;
18 uint8_t marker:1, payload_type:7;
19#endif
20 uint16_t sequence;
21 uint32_t timestamp;
22 uint32_t ssrc;
23 uint8_t data[0];
24} __attribute__((packed));
25
26#define RTP_VERSION 2
27
28/* 5.3.1 RTP Header Extension
29 *
30 * If the X bit in the RTP header is one, a variable-length header
31 * extension MUST be appended to the RTP header, following the CSRC list
32 * if present. The header extension contains a 16-bit length field that
33 * counts the number of 32-bit words in the extension, excluding the
34 * four-octet extension header (therefore zero is a valid length). Only
35 * a single extension can be appended to the RTP data header.
36 */
37struct rtp_x_hdr {
38 uint16_t by_profile;
39 uint16_t length;
40} __attribute__((packed));
41
42/* RTPC header. */
43struct rtcp_hdr {
44 uint8_t byte0;
45 uint8_t type;
46 uint16_t length;
47} __attribute__((packed));
48
49/* XXX: RFC specifies that MTU should used, add generic function to obtain
50 existing MTU. */
51#define RTP_MSGB_SIZE 1500
52
53
54struct msgb;
55
56struct osmo_rtp_handle *osmo_rtp_handle_create(void *ctx);
57void osmo_rtp_handle_free(struct osmo_rtp_handle *h);
58
59int osmo_rtp_handle_tx_set_sequence(struct osmo_rtp_handle *h, uint16_t seq);
60int osmo_rtp_handle_tx_set_ssrc(struct osmo_rtp_handle *h, uint32_t ssrc);
61int osmo_rtp_handle_tx_set_timestamp(struct osmo_rtp_handle *h, uint32_t timestamp);
62
63struct rtp_hdr *osmo_rtp_get_hdr(struct msgb *msg);
64void *osmo_rtp_get_payload(struct rtp_hdr *rtph, struct msgb *msg, uint32_t *plen);
65
66struct msgb *osmo_rtp_build(struct osmo_rtp_handle *h, uint8_t payload_type, uint32_t payload_len, const void *data, uint32_t duration);
67
68int osmo_rtp_snprintf(char *buf, size_t size, struct msgb *msg);
69
70/* supported RTP payload types. */
71#define RTP_PT_RTCP 72 /* RFC 3551: 72-76 for RTCP */
72
73#define RTP_PT_GSM_FULL 3
74#define RTP_PT_GSM_FULL_PAYLOAD_LEN 33
75#define RTP_PT_GSM_FULL_DURATION 160 /* in samples. */
76
77#define RTP_PT_GSM_HALF 96
78
79#define RTP_PT_GSM_EFR 97
80#define RTP_PT_GSM_EFR_PAYLOAD_LEN 31
81#define RTP_PT_GSM_EFR_DURATION 160 /* in samples. */
82
83#define RTP_PT_AMR 98
84
85#define RTP_PT_CSDATA 120 /* 3GPP TS 48.103 table 5.4.2.2.1 */
86
87#endif
Definition: rtp.h:43
Definition: rtp.h:7
Definition: rtp.h:37