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 #define RTP_HEADER_SIZE 12
30 
32 typedef struct rtp_header
33 {
34 #if __BYTE_ORDER == __BIG_ENDIAN
35  uint16_t version:2;
36  uint16_t padding:1;
37  uint16_t extension:1;
38  uint16_t csrccount:4;
39  uint16_t markerbit:1;
40  uint16_t type:7;
41 #elif __BYTE_ORDER == __LITTLE_ENDIAN
42  uint16_t csrccount:4;
43  uint16_t extension:1;
44  uint16_t padding:1;
45  uint16_t version:2;
46  uint16_t type:7;
47  uint16_t markerbit:1;
48 #endif
49  uint16_t seq_number;
50  uint32_t timestamp;
51  uint32_t ssrc;
52  uint32_t csrc[16];
53 } rtp_header;
55 
57 typedef struct janus_rtp_packet {
58  char *data;
59  gint length;
60  gint64 created;
63 
66  uint16_t type;
67  uint16_t length;
69 
71 #define JANUS_RTP_EXTMAP_AUDIO_LEVEL "urn:ietf:params:rtp-hdrext:ssrc-audio-level"
72 
73 #define JANUS_RTP_EXTMAP_TOFFSET "urn:ietf:params:rtp-hdrext:toffset"
74 
75 #define JANUS_RTP_EXTMAP_ABS_SEND_TIME "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"
76 
77 #define JANUS_RTP_EXTMAP_VIDEO_ORIENTATION "urn:3gpp:video-orientation"
78 
79 #define JANUS_RTP_EXTMAP_TRANSPORT_WIDE_CC "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
80 
81 #define JANUS_RTP_EXTMAP_PLAYOUT_DELAY "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"
82 
83 #define JANUS_RTP_EXTMAP_RTP_STREAM_ID "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"
84 
90 char *janus_rtp_payload(char *buf, int len, int *plen);
91 
96 int janus_rtp_header_extension_get_id(const char *sdp, const char *extension);
97 
103 const char *janus_rtp_header_extension_get_from_id(const char *sdp, int id);
104 
111 int janus_rtp_header_extension_parse_audio_level(char *buf, int len, int id, int *level);
112 
122 int janus_rtp_header_extension_parse_video_orientation(char *buf, int len, int id,
123  gboolean *c, gboolean *f, gboolean *r1, gboolean *r0);
124 
132 int janus_rtp_header_extension_parse_playout_delay(char *buf, int len, int id,
133  uint16_t *min_delay, uint16_t *max_delay);
134 
142 int janus_rtp_header_extension_parse_rtp_stream_id(char *buf, int len, int id,
143  char *sdes_item, int sdes_len);
144 
151 int janus_rtp_header_extension_parse_transport_wide_cc(char *buf, int len, int id,
152  uint16_t *transSeqNum);
153 
156  uint32_t a_last_ssrc, a_last_ts, a_base_ts, a_base_ts_prev, a_prev_ts, a_target_ts, a_start_ts,
157  v_last_ssrc, v_last_ts, v_base_ts, v_base_ts_prev, v_prev_ts, v_target_ts, v_start_ts;
158  uint16_t a_last_seq, a_prev_seq, a_base_seq, a_base_seq_prev,
159  v_last_seq, v_prev_seq, v_base_seq, v_base_seq_prev;
160  gboolean a_seq_reset, a_new_ssrc,
161  v_seq_reset, v_new_ssrc;
162  gint16 a_seq_offset,
163  v_seq_offset;
164  gint32 a_prev_delay, a_active_delay, a_ts_offset,
165  v_prev_delay, v_active_delay, v_ts_offset;
166  gint64 a_last_time, a_reference_time, a_start_time, a_evaluating_start_time,
167  v_last_time, v_reference_time, v_start_time, v_evaluating_start_time;
169 
173 
179 void janus_rtp_header_update(janus_rtp_header *header, janus_rtp_switching_context *context, gboolean video, int step);
180 
181 #define RTP_AUDIO_SKEW_TH_MS 120
182 #define RTP_VIDEO_SKEW_TH_MS 120
183 #define SKEW_DETECTION_WAIT_TIME_SECS 10
184 
197 
198 typedef enum janus_audiocodec {
207 const char *janus_audiocodec_name(janus_audiocodec acodec);
210 
211 typedef enum janus_videocodec {
217 const char *janus_videocodec_name(janus_videocodec vcodec);
220 
221 
233  gint64 last_relayed;
239  gboolean need_pli;
241 
245 
257  char *buf, int len, uint32_t *ssrcs, janus_videocodec vcodec, janus_rtp_switching_context *sc);
258 
259 #endif
gboolean changed_temporal
Whether the temporal layer has changed after processing a packet.
Definition: rtp.h:237
Definition: rtp.h:212
int templayer_target
As above, but to handle transitions (e.g., wait for keyframe)
Definition: rtp.h:231
gint64 v_start_time
Definition: rtp.h:166
uint32_t timestamp
Definition: rtp.h:50
gint64 created
Definition: rtp.h:60
gboolean janus_rtp_simulcasting_context_process_rtp(janus_rtp_simulcasting_context *context, char *buf, int len, uint32_t *ssrcs, janus_videocodec vcodec, janus_rtp_switching_context *sc)
Process an RTP packet, and decide whether this should be relayed or not, updating the context accordi...
Definition: rtp.c:772
Definition: rtp.h:203
gint64 last_relayed
When we relayed the last packet (used to detect when substreams become unavailable) ...
Definition: rtp.h:233
Definition: rtp.h:205
int janus_videocodec_pt(janus_videocodec vcodec)
Definition: rtp.c:747
uint16_t markerbit
Definition: rtp.h:39
int templayer
Which simulcast temporal layer we should forward back.
Definition: rtp.h:229
Definition: rtp.h:204
int janus_rtp_skew_compensate_video(janus_rtp_header *header, janus_rtp_switching_context *context, gint64 now)
Use the context info to compensate for video source skew, if needed.
Definition: rtp.c:363
gboolean changed_substream
Whether the substream has changed after processing a packet.
Definition: rtp.h:235
Definition: rtp.h:213
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:169
janus_videocodec
Definition: rtp.h:211
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:19
uint32_t ssrc
Definition: rtp.h:51
uint16_t extension
Definition: rtp.h:37
uint16_t seq_number
Definition: rtp.h:49
const char * janus_videocodec_name(janus_videocodec vcodec)
Definition: rtp.c:720
Definition: rtp.h:199
struct rtp_header rtp_header
RTP Header (http://tools.ietf.org/html/rfc3550#section-5.1)
struct janus_rtp_simulcasting_context janus_rtp_simulcasting_context
Helper struct for processing and tracking simulcast streams.
int janus_rtp_header_extension_parse_transport_wide_cc(char *buf, int len, int id, uint16_t *transSeqNum)
Helper to parse a rtp-stream-id RTP extension (https://tools.ietf.org/html/draft-ietf-avtext-rid-09) ...
Definition: rtp.c:225
uint16_t csrccount
Definition: rtp.h:38
janus_audiocodec
Definition: rtp.h:198
RTP packet.
Definition: rtp.h:57
void janus_rtp_header_update(janus_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:477
int janus_rtp_skew_compensate_audio(janus_rtp_header *header, janus_rtp_switching_context *context, gint64 now)
Use the context info to compensate for audio source skew, if needed.
Definition: rtp.c:247
janus_videocodec janus_videocodec_from_name(const char *name)
Definition: rtp.c:735
uint32_t csrc[16]
Definition: rtp.h:52
RTP context, in order to make sure SSRC changes result in coherent seq/ts increases.
Definition: rtp.h:155
Definition: rtp.h:201
gboolean need_pli
Whether we need to send the user a keyframe request (PLI)
Definition: rtp.h:239
int substream
Which simulcast substream we should forward back.
Definition: rtp.h:225
uint16_t padding
Definition: rtp.h:36
gint32 v_ts_offset
Definition: rtp.h:164
gint64 last_retransmit
Definition: rtp.h:61
RTP extension.
Definition: rtp.h:65
Definition: rtp.h:200
Definition: rtp.h:214
struct janus_rtp_packet janus_rtp_packet
RTP packet.
int janus_rtp_header_extension_parse_rtp_stream_id(char *buf, int len, int id, char *sdes_item, int sdes_len)
Helper to parse a rtp-stream-id RTP extension (https://tools.ietf.org/html/draft-ietf-avtext-rid-09) ...
Definition: rtp.c:207
janus_audiocodec janus_audiocodec_from_name(const char *name)
Definition: rtp.c:680
int substream_target
As above, but to handle transitions (e.g., wait for keyframe, or get this if available) ...
Definition: rtp.h:227
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:35
RTP Header (http://tools.ietf.org/html/rfc3550#section-5.1)
Definition: rtp.h:32
gboolean v_seq_reset
Definition: rtp.h:160
uint32_t v_target_ts
Definition: rtp.h:156
uint16_t length
Definition: rtp.h:67
int janus_audiocodec_pt(janus_audiocodec acodec)
Definition: rtp.c:698
gint16 v_seq_offset
Definition: rtp.h:162
rtp_header janus_rtp_header
Definition: rtp.h:54
Definition: rtp.h:215
char * data
Definition: rtp.h:58
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:68
uint16_t v_prev_seq
Definition: rtp.h:158
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:40
Helper struct for processing and tracking simulcast streams.
Definition: rtp.h:223
void janus_rtp_switching_context_reset(janus_rtp_switching_context *context)
Set (or reset) the context fields to their default values.
Definition: rtp.c:240
uint16_t type
Definition: rtp.h:66
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:156
gint length
Definition: rtp.h:59
Definition: rtp.h:202
const char * janus_audiocodec_name(janus_audiocodec acodec)
Definition: rtp.c:659
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:191
uint16_t type
Definition: rtp.h:40
void janus_rtp_simulcasting_context_reset(janus_rtp_simulcasting_context *context)
Set (or reset) the context fields to their default values.
Definition: rtp.c:763