Statistics
| Branch: | Revision:

janus-gateway / rtp.h @ a27e90d3

History | View | Annotate | Download (5.58 KB)

1
/*! \file    rtp.h
2
 * \author   Lorenzo Miniero <lorenzo@meetecho.com>
3
 * \copyright GNU General Public License v3
4
 * \brief    RTP processing (headers)
5
 * \details  Implementation of the RTP header. Since the gateway does not
6
 * much more than relaying frames around, the only thing we're interested
7
 * in is the RTP header and how to get its payload, and parsing extensions.
8
 * 
9
 * \ingroup protocols
10
 * \ref protocols
11
 */
12
 
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

    
31
/*! \brief RTP Header (http://tools.ietf.org/html/rfc3550#section-5.1) */
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;
54

    
55
/*! \brief RTP packet */
56
typedef struct janus_rtp_packet {
57
        char *data;
58
        gint length;
59
        gint64 created;
60
        gint64 last_retransmit;
61
} janus_rtp_packet;
62

    
63
/*! \brief RTP extension */
64
typedef struct janus_rtp_header_extension {
65
        uint16_t type;
66
        uint16_t length;
67
} janus_rtp_header_extension;
68

    
69
/*! \brief a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level */
70
#define JANUS_RTP_EXTMAP_AUDIO_LEVEL                "urn:ietf:params:rtp-hdrext:ssrc-audio-level"
71
/*! \brief a=extmap:2 urn:ietf:params:rtp-hdrext:toffset */
72
#define JANUS_RTP_EXTMAP_TOFFSET                        "urn:ietf:params:rtp-hdrext:toffset"
73
/*! \brief a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time */
74
#define JANUS_RTP_EXTMAP_ABS_SEND_TIME                "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"
75
/*! \brief a=extmap:4 urn:3gpp:video-orientation */
76
#define JANUS_RTP_EXTMAP_VIDEO_ORIENTATION        "urn:3gpp:video-orientation"
77
/*! \brief a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 */
78
#define JANUS_RTP_EXTMAP_CC_EXTENSIONS                "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
79
/*! \brief a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay */
80
#define JANUS_RTP_EXTMAP_PLAYOUT_DELAY                "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"
81

    
82
/*! \brief Helper to quickly access the RTP payload, skipping header and extensions
83
 * @param[in] buf The packet data
84
 * @param[in] len The packet data length in bytes
85
 * @param[out] plen The payload data length in bytes
86
 * @returns A pointer to where the payload data starts, or NULL otherwise; plen is also set accordingly */
87
char *janus_rtp_payload(char *buf, int len, int *plen);
88

    
89
/*! \brief Ugly and dirty helper to quickly get the id associated with an RTP extension (extmap) in an SDP
90
 * @param sdp The SDP to parse
91
 * @param extension The extension namespace to look for
92
 * @returns The extension id, if found, -1 otherwise */
93
int janus_rtp_header_extension_get_id(const char *sdp, const char *extension);
94

    
95
/*! \brief Ugly and dirty helper to quickly get the RTP extension namespace associated with an id (extmap) in an SDP
96
 * @note This only looks for the extensions we know about, those defined in rtp.h
97
 * @param sdp The SDP to parse
98
 * @param id The extension id to look for
99
 * @returns The extension namespace, if found, NULL otherwise */
100
const char *janus_rtp_header_extension_get_from_id(const char *sdp, int id);
101

    
102
/*! \brief Helper to parse a ssrc-audio-level RTP extension (https://tools.ietf.org/html/rfc6464)
103
 * @param[in] buf The packet data
104
 * @param[in] len The packet data length in bytes
105
 * @param[in] id The extension ID to look for
106
 * @param[out] level The level value in dBov (0=max, 127=min)
107
 * @returns 0 if found, -1 otherwise */
108
int janus_rtp_header_extension_parse_audio_level(char *buf, int len, int id, int *level);
109

    
110
/*! \brief Helper to parse a ssrc-audio-level RTP extension (https://tools.ietf.org/html/rfc6464)
111
 * @param[in] buf The packet data
112
 * @param[in] len The packet data length in bytes
113
 * @param[in] id The extension ID to look for
114
 * @param[out] level The level value in dBov (0=max, 127=min)
115
 * @returns dBov level of audio, 0 otherwise */
116
int janus_rtp_header_extension_parse_audio_level_and_return(char *buf, int len, int id, int *level);
117

    
118
/*! \brief Helper to parse a video-orientation RTP extension (http://www.3gpp.org/ftp/Specs/html-info/26114.htm)
119
 * @param[in] buf The packet data
120
 * @param[in] len The packet data length in bytes
121
 * @param[in] id The extension ID to look for
122
 * @param[out] c The value of the Camera (C) bit
123
 * @param[out] f The value of the Flip (F) bit
124
 * @param[out] r1 The value of the first Rotation (R1) bit
125
 * @param[out] r0 The value of the second Rotation (R0) bit
126
 * @returns 0 if found, -1 otherwise */
127
int janus_rtp_header_extension_parse_video_orientation(char *buf, int len, int id,
128
        gboolean *c, gboolean *f, gboolean *r1, gboolean *r0);
129

    
130
/*! \brief Helper to parse a playout-delay RTP extension (https://webrtc.org/experiments/rtp-hdrext/playout-delay)
131
 * @param[in] buf The packet data
132
 * @param[in] len The packet data length in bytes
133
 * @param[in] id The extension ID to look for
134
 * @param[out] min_delay The minimum delay value
135
 * @param[out] max_delay The maximum delay value
136
 * @returns 0 if found, -1 otherwise */
137
int janus_rtp_header_extension_parse_playout_delay(char *buf, int len, int id,
138
        uint16_t *min_delay, uint16_t *max_delay);
139

    
140
#endif