libosmo-netif
0.2.0-dirty
Osmocom network interface library
|
00001 #ifndef _OSMO_RTP_H_ 00002 #define _OSMO_RTP_H_ 00003 00004 #include <osmocom/core/endian.h> 00005 00006 /* RTP header as defined by RFC 3550 */ 00007 struct rtp_hdr { 00008 #if OSMO_IS_LITTLE_ENDIAN 00009 uint8_t csrc_count:4, 00010 extension:1, 00011 padding:1, 00012 version:2; 00013 uint8_t payload_type:7, 00014 marker:1; 00015 #elif OSMO_IS_BIG_ENDIAN 00016 uint8_t version:2, 00017 padding:1, 00018 extension:1, 00019 csrc_count:4; 00020 uint8_t marker:1, 00021 payload_type:7; 00022 #endif 00023 uint16_t sequence; 00024 uint32_t timestamp; 00025 uint32_t ssrc; 00026 uint8_t data[0]; 00027 } __attribute__((packed)); 00028 00029 #define RTP_VERSION 2 00030 00031 /* 5.3.1 RTP Header Extension 00032 * 00033 * If the X bit in the RTP header is one, a variable-length header 00034 * extension MUST be appended to the RTP header, following the CSRC list 00035 * if present. The header extension contains a 16-bit length field that 00036 * counts the number of 32-bit words in the extension, excluding the 00037 * four-octet extension header (therefore zero is a valid length). Only 00038 * a single extension can be appended to the RTP data header. 00039 */ 00040 struct rtp_x_hdr { 00041 uint16_t by_profile; 00042 uint16_t length; 00043 } __attribute__((packed)); 00044 00045 /* RTPC header. */ 00046 struct rtcp_hdr { 00047 uint8_t byte0; 00048 uint8_t type; 00049 uint16_t length; 00050 } __attribute__((packed)); 00051 00052 /* XXX: RFC specifies that MTU should used, add generic function to obtain 00053 existing MTU. */ 00054 #define RTP_MSGB_SIZE 1500 00055 00056 00057 struct msgb; 00058 00059 struct osmo_rtp_handle *osmo_rtp_handle_create(void *ctx); 00060 void osmo_rtp_handle_free(struct osmo_rtp_handle *h); 00061 00062 int osmo_rtp_handle_tx_set_sequence(struct osmo_rtp_handle *h, uint16_t seq); 00063 int osmo_rtp_handle_tx_set_ssrc(struct osmo_rtp_handle *h, uint32_t ssrc); 00064 int osmo_rtp_handle_tx_set_timestamp(struct osmo_rtp_handle *h, uint32_t timestamp); 00065 00066 struct rtp_hdr *osmo_rtp_get_hdr(struct msgb *msg); 00067 void *osmo_rtp_get_payload(struct rtp_hdr *rtph, struct msgb *msg, uint32_t *plen); 00068 00069 struct msgb *osmo_rtp_build(struct osmo_rtp_handle *h, uint8_t payload_type, uint32_t payload_len, const void *data, uint32_t duration); 00070 00071 int osmo_rtp_snprintf(char *buf, size_t size, struct msgb *msg); 00072 00073 /* supported RTP payload types. */ 00074 #define RTP_PT_RTCP 72 /* RFC 3551: 72-76 for RTCP */ 00075 00076 #define RTP_PT_GSM_FULL 3 00077 #define RTP_PT_GSM_FULL_PAYLOAD_LEN 33 00078 #define RTP_PT_GSM_FULL_DURATION 160 /* in samples. */ 00079 00080 #define RTP_PT_GSM_HALF 96 00081 00082 #define RTP_PT_GSM_EFR 97 00083 #define RTP_PT_GSM_EFR_PAYLOAD_LEN 31 00084 #define RTP_PT_GSM_EFR_DURATION 160 /* in samples. */ 00085 00086 #define RTP_PT_AMR 98 00087 00088 #endif