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