Fork me on GitHub
rtp.h
Go to the documentation of this file.
1 
13 #ifndef _JANUS_RTP_H
14 #define _JANUS_RTP_H
15 
16 #include <arpa/inet.h>
17 #ifdef __MACH__
18 #include <machine/endian.h>
19 #define __BYTE_ORDER BYTE_ORDER
20 #define __BIG_ENDIAN BIG_ENDIAN
21 #define __LITTLE_ENDIAN LITTLE_ENDIAN
22 #else
23 #include <endian.h>
24 #endif
25 #include <inttypes.h>
26 #include <string.h>
27 #include <glib.h>
28 
29 #ifdef HAVE_SRTP_2
30 #include <srtp2/srtp.h>
31 #include <openssl/rand.h>
32 #include <openssl/err.h>
33 int srtp_crypto_get_random(uint8_t *key, int len);
34 #else
35 #include <srtp/srtp.h>
36 #include <srtp/crypto_kernel.h>
37 #define srtp_err_status_t err_status_t
38 #define srtp_err_status_ok err_status_ok
39 #define srtp_err_status_replay_fail err_status_replay_fail
40 #define srtp_err_status_replay_old err_status_replay_old
41 #define srtp_crypto_policy_set_rtp_default crypto_policy_set_rtp_default
42 #define srtp_crypto_policy_set_rtcp_default crypto_policy_set_rtcp_default
43 #define srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32 crypto_policy_set_aes_cm_128_hmac_sha1_32
44 #define srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80 crypto_policy_set_aes_cm_128_hmac_sha1_80
45 #define srtp_crypto_get_random crypto_get_random
46 #endif
47 
48 #define RTP_HEADER_SIZE 12
49 
50 /* SRTP stuff (http://tools.ietf.org/html/rfc3711) */
51 #define SRTP_MASTER_KEY_LENGTH 16
52 #define SRTP_MASTER_SALT_LENGTH 14
53 #define SRTP_MASTER_LENGTH (SRTP_MASTER_KEY_LENGTH + SRTP_MASTER_SALT_LENGTH)
54 
56 typedef struct rtp_header
57 {
58 #if __BYTE_ORDER == __BIG_ENDIAN
59  uint16_t version:2;
60  uint16_t padding:1;
61  uint16_t extension:1;
62  uint16_t csrccount:4;
63  uint16_t markerbit:1;
64  uint16_t type:7;
65 #elif __BYTE_ORDER == __LITTLE_ENDIAN
66  uint16_t csrccount:4;
67  uint16_t extension:1;
68  uint16_t padding:1;
69  uint16_t version:2;
70  uint16_t type:7;
71  uint16_t markerbit:1;
72 #endif
73  uint16_t seq_number;
74  uint32_t timestamp;
75  uint32_t ssrc;
76  uint32_t csrc[16];
77 } rtp_header;
78 
80 typedef struct janus_rtp_packet {
81  char *data;
82  gint length;
83  gint64 created;
86 
89  uint16_t type;
90  uint16_t length;
92 
94 #define JANUS_RTP_EXTMAP_AUDIO_LEVEL "urn:ietf:params:rtp-hdrext:ssrc-audio-level"
95 
96 #define JANUS_RTP_EXTMAP_TOFFSET "urn:ietf:params:rtp-hdrext:toffset"
97 
98 #define JANUS_RTP_EXTMAP_ABS_SEND_TIME "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"
99 
100 #define JANUS_RTP_EXTMAP_VIDEO_ORIENTATION "urn:3gpp:video-orientation"
101 
102 #define JANUS_RTP_EXTMAP_CC_EXTENSIONS "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
103 
104 #define JANUS_RTP_EXTMAP_PLAYOUT_DELAY "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"
105 
111 char *janus_rtp_payload(char *buf, int len, int *plen);
112 
117 int janus_rtp_header_extension_get_id(const char *sdp, const char *extension);
118 
124 const char *janus_rtp_header_extension_get_from_id(const char *sdp, int id);
125 
132 int janus_rtp_header_extension_parse_audio_level(char *buf, int len, int id, int *level);
133 
143 int janus_rtp_header_extension_parse_video_orientation(char *buf, int len, int id,
144  gboolean *c, gboolean *f, gboolean *r1, gboolean *r0);
145 
153 int janus_rtp_header_extension_parse_playout_delay(char *buf, int len, int id,
154  uint16_t *min_delay, uint16_t *max_delay);
155 
158  uint32_t a_last_ssrc, a_last_ts, a_base_ts, a_base_ts_prev,
159  v_last_ssrc, v_last_ts, v_base_ts, v_base_ts_prev;
160  uint16_t a_last_seq, a_base_seq, a_base_seq_prev,
161  v_last_seq, v_base_seq, v_base_seq_prev;
162  gboolean a_seq_reset, v_seq_reset;
164 
168 
174 void janus_rtp_header_update(rtp_header *header, janus_rtp_switching_context *context, gboolean video, int step);
175 
179 const char *janus_srtp_error_str(int error);
180 
181 #endif
#define srtp_crypto_get_random
Definition: rtp.h:45
uint16_t v_last_seq
Definition: rtp.h:160
uint32_t timestamp
Definition: rtp.h:74
gint64 created
Definition: rtp.h:83
uint16_t markerbit
Definition: rtp.h:63
int janus_rtp_header_extension_parse_video_orientation(char *buf, int len, int id, gboolean *c, gboolean *f, gboolean *r1, gboolean *r0)
Helper to parse a video-orientation RTP extension (http://www.3gpp.org/ftp/Specs/html-info/26114.htm)
Definition: rtp.c:162
struct janus_rtp_header_extension janus_rtp_header_extension
RTP extension.
char * janus_rtp_payload(char *buf, int len, int *plen)
Helper to quickly access the RTP payload, skipping header and extensions.
Definition: rtp.c:17
uint32_t ssrc
Definition: rtp.h:75
uint16_t extension
Definition: rtp.h:61
uint16_t seq_number
Definition: rtp.h:73
uint32_t v_last_ts
Definition: rtp.h:158
struct rtp_header rtp_header
RTP Header (http://tools.ietf.org/html/rfc3550#section-5.1)
uint16_t csrccount
Definition: rtp.h:62
RTP packet.
Definition: rtp.h:80
uint32_t csrc[16]
Definition: rtp.h:76
RTP context, in order to make sure SSRC changes result in coherent seq/ts increases.
Definition: rtp.h:157
uint16_t padding
Definition: rtp.h:60
void janus_rtp_header_update(rtp_header *header, janus_rtp_switching_context *context, gboolean video, int step)
Use the context info to update the RTP header of a packet, if needed.
Definition: rtp.c:209
gint64 last_retransmit
Definition: rtp.h:84
RTP extension.
Definition: rtp.h:88
struct janus_rtp_packet janus_rtp_packet
RTP packet.
struct janus_rtp_switching_context janus_rtp_switching_context
RTP context, in order to make sure SSRC changes result in coherent seq/ts increases.
uint16_t version
Definition: rtp.h:59
RTP Header (http://tools.ietf.org/html/rfc3550#section-5.1)
Definition: rtp.h:56
gboolean v_seq_reset
Definition: rtp.h:162
uint16_t length
Definition: rtp.h:90
char * data
Definition: rtp.h:81
const char * janus_rtp_header_extension_get_from_id(const char *sdp, int id)
Ugly and dirty helper to quickly get the RTP extension namespace associated with an id (extmap) in an...
Definition: rtp.c:66
int janus_rtp_header_extension_get_id(const char *sdp, const char *extension)
Ugly and dirty helper to quickly get the id associated with an RTP extension (extmap) in an SDP...
Definition: rtp.c:38
void janus_rtp_switching_context_reset(janus_rtp_switching_context *context)
Set (or reset) the context fields to their default values.
Definition: rtp.c:202
uint16_t type
Definition: rtp.h:89
int janus_rtp_header_extension_parse_audio_level(char *buf, int len, int id, int *level)
Helper to parse a ssrc-audio-level RTP extension (https://tools.ietf.org/html/rfc6464) ...
Definition: rtp.c:149
gint length
Definition: rtp.h:82
int janus_rtp_header_extension_parse_playout_delay(char *buf, int len, int id, uint16_t *min_delay, uint16_t *max_delay)
Helper to parse a playout-delay RTP extension (https://webrtc.org/experiments/rtp-hdrext/playout-dela...
Definition: rtp.c:184
uint16_t type
Definition: rtp.h:64
const char * janus_srtp_error_str(int error)
Helper method to get a string representation of a libsrtp error code.
Definition: rtp.c:335