2 * Copyright (C) 2011-2012 Juho Vähä-Herttua
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
24 /* Actual SDP records */
27 const char *connection
;
32 /* Additional SDP records */
35 const char *rsaaeskey
;
37 const char *min_latency
;
41 parse_sdp_line(sdp_t
*sdp
, char *line
)
43 int len
= strlen(line
);
44 if (len
< 2 || line
[1] != '=') {
50 sdp
->version
= &line
[2];
53 sdp
->origin
= &line
[2];
56 sdp
->session
= &line
[2];
59 sdp
->connection
= &line
[2];
65 sdp
->media
= &line
[2];
72 /* Parse key and value */
74 value
= strstr(line
, ":");
78 if (!strcmp(key
, "rtpmap") && !sdp
->rtpmap
) {
80 } else if (!strcmp(key
, "fmtp") && !sdp
->fmtp
) {
82 } else if (!strcmp(key
, "rsaaeskey")) {
83 sdp
->rsaaeskey
= value
;
84 } else if (!strcmp(key
, "aesiv")) {
86 } else if (!strcmp(key
, "min-latency")) {
87 sdp
->min_latency
= value
;
95 parse_sdp_data(sdp_t
*sdp
)
100 len
= strlen(sdp
->data
);
104 /* Find newline in string */
105 for (lfpos
=pos
; sdp
->data
[lfpos
]; lfpos
++) {
106 if (sdp
->data
[lfpos
] == '\n') {
110 if (sdp
->data
[lfpos
] != '\n') {
114 /* Replace newline with '\0' and parse line */
115 sdp
->data
[lfpos
] = '\0';
116 if (lfpos
> pos
&& sdp
->data
[lfpos
-1] == '\r') {
117 sdp
->data
[lfpos
-1] = '\0';
119 parse_sdp_line(sdp
, sdp
->data
+pos
);
125 sdp_init(const char *sdpdata
, int sdpdatalen
)
129 sdp
= calloc(1, sizeof(sdp_t
));
134 /* Allocate data buffer */
135 sdp
->data
= malloc(sdpdatalen
+1);
140 memcpy(sdp
->data
, sdpdata
, sdpdatalen
);
141 sdp
->data
[sdpdatalen
] = '\0';
147 sdp_destroy(sdp_t
*sdp
)
156 sdp_get_version(sdp_t
*sdp
)
164 sdp_get_origin(sdp_t
*sdp
)
172 sdp_get_session(sdp_t
*sdp
)
180 sdp_get_connection(sdp_t
*sdp
)
184 return sdp
->connection
;
188 sdp_get_time(sdp_t
*sdp
)
196 sdp_get_media(sdp_t
*sdp
)
204 sdp_get_rtpmap(sdp_t
*sdp
)
212 sdp_get_fmtp(sdp_t
*sdp
)
220 sdp_get_rsaaeskey(sdp_t
*sdp
)
224 return sdp
->rsaaeskey
;
228 sdp_get_aesiv(sdp_t
*sdp
)
236 sdp_get_min_latency(sdp_t
*sdp
)
240 return sdp
->min_latency
;