Amazon Kinesis Webrtc C SDK
Sdp.h
Go to the documentation of this file.
1 //
2 // Session Description Protocol Utils
3 //
4 
5 #ifndef __KINESIS_VIDEO_WEBRTC_CLIENT_SDP_SDP__
6 #define __KINESIS_VIDEO_WEBRTC_CLIENT_SDP_SDP__
7 
8 #pragma once
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #define SDP_ATTRIBUTE_MARKER "a="
15 #define SDP_BANDWIDTH_MARKER "b="
16 #define SDP_CONNECTION_INFORMATION_MARKER "c="
17 #define SDP_EMAIL_ADDRESS_MARKER "e="
18 #define SDP_ENCRYPTION_KEY_MARKER "k="
19 
20 // Media title information or Session information
21 #define SDP_INFORMATION_MARKER "i="
22 
23 #define SDP_MEDIA_NAME_MARKER "m="
24 #define SDP_ORIGIN_MARKER "o="
25 #define SDP_PHONE_NUMBER_MARKER "p="
26 #define SDP_SESSION_NAME_MARKER "s="
27 #define SDP_TIME_DESCRIPTION_MARKER "t="
28 #define SDP_TIMEZONE_MARKER "z="
29 #define SDP_URI_MARKER "u="
30 #define SDP_VERSION_MARKER "v="
31 
32 // The sequence CRLF (0x0d0a) is used to end a record, although parsers SHOULD be
33 // tolerant and also accept records terminated with a single newline
34 // character.
35 // Reference: https://tools.ietf.org/html/rfc4566#section-5
36 #define SDP_LINE_SEPARATOR "\r\n"
37 
38 #define SDP_CANDIDATE_TYPE_HOST "host"
39 #define SDP_CANDIDATE_TYPE_SERFLX "srflx"
40 #define SDP_CANDIDATE_TYPE_PRFLX "prflx"
41 #define SDP_CANDIDATE_TYPE_RELAY "relay"
42 #define SDP_CANDIDATE_TYPE_UNKNOWN "unknown"
43 
44 #define SDP_ATTRIBUTE_LENGTH 2
45 
46 #define MAX_SDP_OFFSET_LENGTH 255
47 #define MAX_SDP_ENCRYPTION_KEY_METHOD_LENGTH 255
48 #define MAX_SDP_ENCRYPTION_KEY_LENGTH 255
49 
50 /* https://datatracker.ietf.org/doc/html/rfc4566#section-5.7 -- the SDK hardcodes this to be IN as per spec.
51  * Also, this SDK is to be used in the Internet realm. Allowing for some extra buffer
52  */
53 #define MAX_SDP_NETWORK_TYPE_LENGTH 7
54 
55 /* https://datatracker.ietf.org/doc/html/rfc4566#section-5.7 -- Given the SDK is to operate in IP based sessions,
56  * the possible values are IP4/IP6 as registered with IANA. Allowing for some extra buffer
57  */
58 #define MAX_SDP_ADDRESS_TYPE_LENGTH 7
59 
60 /* https://datatracker.ietf.org/doc/html/rfc4566#section-5.7 -- Given the SDK is to operate in IP based sessions,
61  * an IPv4 address can be a maximum of <IPv4(15)/TTL(3)/multicast number of addresses(3)> characters where TTL is
62  * between 0 and 255. IPv6 can be a maximum of <IPv6 uncompressed(39)>. Setting to 63 for additional padding
63  */
64 #define MAX_SDP_CONNECTION_ADDRESS_LENGTH 63
65 
66 // https://datatracker.ietf.org/doc/html/rfc4566#section-5.2 -- the SDK sets it to "-" and the SDK does not parse incoming username either
67 #define MAX_SDP_SESSION_USERNAME_LENGTH 32
68 
69 // https://datatracker.ietf.org/doc/html/rfc4566#section-6 -- name length restricted based on current supported attribute set
70 #define MAX_SDP_ATTRIBUTE_NAME_LENGTH 32
71 
72 // One of the attributes is streamId + trackId which sums up to 512 maximum characters
73 #define MAX_SDP_ATTRIBUTE_VALUE_LENGTH 512
74 
75 #define MAX_SDP_MEDIA_NAME_LENGTH 255
76 
77 /* https://tools.ietf.org/html/rfc4566#section-5.4. Given these are free-form textual strings, that is, the length could be anything.
78  * Although our SDK parses this information, the SDK does not use it. Leaving this attribute in if SDK uses it in
79  * the future, but keeping it at smaller size to ensure structure memory efficiency
80  */
81 #define MAX_SDP_MEDIA_TITLE_LENGTH 127
82 
83 /* https://tools.ietf.org/html/rfc4566#section-5.4. Given these are free-form textual strings, that is, the length could be anything.
84  * Although our SDK parses this information, the SDK does not use it. Leaving this attribute in if SDK uses it in
85  * the future, but keeping it at smaller size to ensure structure memory efficiency
86  */
87 #define MAX_SDP_SESSION_INFORMATION_LENGTH 127
88 
89 #define MAX_SDP_SESSION_NAME_LENGTH 255
90 #define MAX_SDP_SESSION_URI_LENGTH 255
91 #define MAX_SDP_SESSION_EMAIL_ADDRESS_LENGTH 255
92 #define MAX_SDP_SESSION_PHONE_NUMBER_LENGTH 255
93 
94 #define MAX_SDP_TOKEN_LENGTH 128
95 #define MAX_SDP_FMTP_VALUES 64
96 
97 #define MAX_SDP_SESSION_TIME_DESCRIPTION_COUNT 2
98 #define MAX_SDP_SESSION_TIMEZONE_COUNT 2
104 #define MAX_SDP_SESSION_MEDIA_COUNT 5
105 #define MAX_SDP_MEDIA_BANDWIDTH_COUNT 2
106 
107 #define MAX_SDP_ATTRIBUTES_COUNT 256
108 
109 /*
110  * c=<nettype> <addrtype> <connection-address>
111  * https://tools.ietf.org/html/rfc4566#section-5.7
112  */
113 typedef struct {
114  CHAR networkType[MAX_SDP_NETWORK_TYPE_LENGTH + 1];
115  CHAR addressType[MAX_SDP_ADDRESS_TYPE_LENGTH + 1];
116  CHAR connectionAddress[MAX_SDP_CONNECTION_ADDRESS_LENGTH + 1];
118 
119 /*
120  * o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
121  * https://tools.ietf.org/html/rfc4566#section-5.2
122  */
123 typedef struct {
125  UINT64 sessionId;
129 
130 /*
131  * https://tools.ietf.org/html/rfc4566#section-5.9
132  * https://tools.ietf.org/html/rfc4566#section-5.10
133  */
134 typedef struct {
135  UINT64 startTime;
136  UINT64 stopTime;
138 
139 /*
140  * z=<adjustment time> <offset> <adjustment time> <offset> ...
141  * https://tools.ietf.org/html/rfc4566#section-5.11
142  */
143 typedef struct {
145  CHAR offset[MAX_SDP_OFFSET_LENGTH + 1];
147 
148 typedef struct {
150  CHAR sdpEncryptionKey[MAX_SDP_ENCRYPTION_KEY_LENGTH + 1];
152 
153 /*
154  * a=<attribute>
155  * a=<attribute>:<value>
156  * https://tools.ietf.org/html/rfc4566#section-5.13
157  */
158 typedef struct {
159  CHAR attributeName[MAX_SDP_ATTRIBUTE_NAME_LENGTH + 1];
160  CHAR attributeValue[MAX_SDP_ATTRIBUTE_VALUE_LENGTH + 1];
162 
163 typedef struct {
164  // m=<media> <port>/<number of ports> <proto> <fmt> ...
165  // https://tools.ietf.org/html/rfc4566#section-5.14
166  CHAR mediaName[MAX_SDP_MEDIA_NAME_LENGTH + 1];
167 
168  // i=<session description>
169  // https://tools.ietf.org/html/rfc4566#section-5.4. Given these are free-form strings, the length could be anything.
170  // Although our SDK parses this information, the SDK does not use it. Leaving this attribute in if SDK uses it in
171  // the future
172  CHAR mediaTitle[MAX_SDP_MEDIA_TITLE_LENGTH + 1];
173 
175 
177 
179 
181 
184 
185 typedef struct {
186  // https://tools.ietf.org/html/rfc4566#section-5.1
187  UINT64 version;
188 
190 
191  // s=<session name>
192  // https://tools.ietf.org/html/rfc4566#section-5.3
193  CHAR sessionName[MAX_SDP_SESSION_NAME_LENGTH + 1];
194 
195  // i=<session description>
196  // https://tools.ietf.org/html/rfc4566#section-5.4
197  CHAR sessionInformation[MAX_SDP_SESSION_INFORMATION_LENGTH + 1];
198 
199  // u=<uri>
200  // https://tools.ietf.org/html/rfc4566#section-5.5
202 
203  // e=<email-address>
204  // https://tools.ietf.org/html/rfc4566#section-5.6
205  CHAR emailAddress[MAX_SDP_SESSION_EMAIL_ADDRESS_LENGTH + 1];
206 
207  // p=<phone-number>
208  // https://tools.ietf.org/html/rfc4566#section-5.6
209  CHAR phoneNumber[MAX_SDP_SESSION_PHONE_NUMBER_LENGTH + 1];
210 
212 
214 
216 
218 
220 
222 
224 
225  UINT16 mediaCount;
226 
228 
230 
233 
234 // Return code maps to an errno just for SDP parsing
236 
237 // Return code maps to a code if we are trying to serialize an invalid session_description
238 STATUS serializeSessionDescription(PSessionDescription, PCHAR, PUINT32);
239 
240 STATUS parseMediaName(PSessionDescription, PCHAR, UINT32);
241 STATUS parseSessionAttributes(PSessionDescription, PCHAR, UINT32);
242 STATUS parseMediaAttributes(PSessionDescription, PCHAR, UINT32);
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 #endif //__KINESIS_VIDEO_WEBRTC_CLIENT_SDP_SDP__
#define MAX_SDP_SESSION_URI_LENGTH
Definition: Sdp.h:90
#define MAX_SDP_SESSION_NAME_LENGTH
Definition: Sdp.h:89
#define MAX_SDP_SESSION_PHONE_NUMBER_LENGTH
Definition: Sdp.h:92
#define MAX_SDP_SESSION_EMAIL_ADDRESS_LENGTH
Definition: Sdp.h:91
STATUS deserializeSessionDescription(PSessionDescription, PCHAR)
Definition: Deserialize.c:73
STATUS serializeSessionDescription(PSessionDescription, PCHAR, PUINT32)
Definition: Serialize.c:166
#define MAX_SDP_NETWORK_TYPE_LENGTH
Definition: Sdp.h:53
struct SdpOrigin * PSdpOrigin
#define MAX_SDP_MEDIA_NAME_LENGTH
Definition: Sdp.h:75
#define MAX_SDP_ENCRYPTION_KEY_METHOD_LENGTH
Definition: Sdp.h:47
struct SdpTimeDescription * PSdpTimeDescription
#define MAX_SDP_OFFSET_LENGTH
Definition: Sdp.h:46
#define MAX_SDP_ATTRIBUTE_VALUE_LENGTH
Definition: Sdp.h:73
#define MAX_SDP_SESSION_USERNAME_LENGTH
Definition: Sdp.h:67
struct SdpMediaDescription * PSdpMediaDescription
#define MAX_SDP_SESSION_TIME_DESCRIPTION_COUNT
Definition: Sdp.h:97
#define MAX_SDP_MEDIA_TITLE_LENGTH
Definition: Sdp.h:81
struct SdpAttributes * PSdpAttributes
#define MAX_SDP_SESSION_MEDIA_COUNT
Definition: Sdp.h:104
#define MAX_SDP_ENCRYPTION_KEY_LENGTH
Definition: Sdp.h:48
struct SdpConnectionInformation * PSdpConnectionInformation
#define MAX_SDP_ATTRIBUTE_NAME_LENGTH
Definition: Sdp.h:70
struct SessionDescription * PSessionDescription
struct SdpEncryptionKey * PSdpEncryptionKey
#define MAX_SDP_SESSION_INFORMATION_LENGTH
Definition: Sdp.h:87
#define MAX_SDP_CONNECTION_ADDRESS_LENGTH
Definition: Sdp.h:64
STATUS parseMediaAttributes(PSessionDescription, PCHAR, UINT32)
Definition: Deserialize.c:45
struct SdpTimeZone * PSdpTimeZone
STATUS parseMediaName(PSessionDescription, PCHAR, UINT32)
Definition: Deserialize.c:4
#define MAX_SDP_ATTRIBUTES_COUNT
Definition: Sdp.h:107
#define MAX_SDP_ADDRESS_TYPE_LENGTH
Definition: Sdp.h:58
STATUS parseSessionAttributes(PSessionDescription, PCHAR, UINT32)
Definition: Deserialize.c:19
#define MAX_SDP_SESSION_TIMEZONE_COUNT
Definition: Sdp.h:98
Definition: Sdp.h:158
Definition: Sdp.h:113
Definition: Sdp.h:148
Definition: Sdp.h:163
UINT8 mediaAttributesCount
Definition: Sdp.h:180
UINT8 mediaBandwidthCount
Definition: Sdp.h:182
SdpConnectionInformation sdpConnectionInformation
Definition: Sdp.h:174
SdpEncryptionKey sdpEncryptionKey
Definition: Sdp.h:176
Definition: Sdp.h:123
UINT64 sessionVersion
Definition: Sdp.h:126
SdpConnectionInformation sdpConnectionInformation
Definition: Sdp.h:127
UINT64 sessionId
Definition: Sdp.h:125
Definition: Sdp.h:134
UINT64 startTime
Definition: Sdp.h:135
UINT64 stopTime
Definition: Sdp.h:136
Definition: Sdp.h:143
UINT64 adjustmentTime
Definition: Sdp.h:144
Definition: Sdp.h:185
UINT16 mediaCount
Definition: Sdp.h:225
SdpEncryptionKey sdpEncryptionKey
Definition: Sdp.h:217
SdpConnectionInformation sdpConnectionInformation
Definition: Sdp.h:211
UINT8 bandwidthCount
Definition: Sdp.h:231
UINT64 version
Definition: Sdp.h:187
UINT8 timezoneCount
Definition: Sdp.h:227
UINT16 sessionAttributesCount
Definition: Sdp.h:223
SdpOrigin sdpOrigin
Definition: Sdp.h:189
UINT8 timeDescriptionCount
Definition: Sdp.h:229