sdp: add decode function for RTP Extensions map (RFC 5285)

thanks to Jose Carlos Pujol
This commit is contained in:
Alfred E. Heggestad 2014-08-15 10:59:05 +00:00
parent 8ff6567c06
commit fc306d1577
3 changed files with 65 additions and 0 deletions

View file

@ -166,3 +166,17 @@ extern const char sdp_media_text[];
extern const char sdp_proto_rtpavp[];
extern const char sdp_proto_rtpsavp[];
/* utility functions */
/** RTP Header Extensions, as defined in RFC 5285 */
struct sdp_extmap {
struct pl name;
struct pl attrs;
enum sdp_dir dir;
bool dir_set;
uint32_t id;
};
int sdp_extmap_decode(struct sdp_extmap *ext, const char *val);

View file

@ -10,3 +10,4 @@ SRCS += sdp/media.c
SRCS += sdp/msg.c
SRCS += sdp/session.c
SRCS += sdp/str.c
SRCS += sdp/util.c

50
src/sdp/util.c Normal file
View file

@ -0,0 +1,50 @@
/**
* @file sdp/util.c SDP utility functions
*
* Copyright (C) 2010 Creytiv.com
*/
#include <string.h>
#include <re_types.h>
#include <re_fmt.h>
#include <re_list.h>
#include <re_sa.h>
#include <re_sdp.h>
/**
* Decode RTP Header Extension SDP attribute value
*
* @param ext Extension-map object
* @param val SDP attribute value
*
* @return 0 for success, otherwise errorcode
*/
int sdp_extmap_decode(struct sdp_extmap *ext, const char *val)
{
struct pl id, dir;
if (!ext || !val)
return EINVAL;
if (re_regex(val, strlen(val), "[0-9]+[/]*[a-z]* [^ ]+[ ]*[^ ]*",
&id, NULL, &dir, &ext->name, NULL, &ext->attrs))
return EBADMSG;
ext->dir_set = false;
ext->dir = SDP_SENDRECV;
if (pl_isset(&dir)) {
ext->dir_set = true;
if (!pl_strcmp(&dir, "sendonly")) ext->dir = SDP_SENDONLY;
else if (!pl_strcmp(&dir, "sendrecv")) ext->dir = SDP_SENDRECV;
else if (!pl_strcmp(&dir, "recvonly")) ext->dir = SDP_RECVONLY;
else if (!pl_strcmp(&dir, "inactive")) ext->dir = SDP_INACTIVE;
else ext->dir_set = false;
}
ext->id = pl_u32(&id);
return 0;
}