Commit 51810110 authored by jehan's avatar jehan
Browse files

close to have an sdp parser

parent 6325daf2
......@@ -100,9 +100,7 @@ void belle_sdp_info_set_value(belle_sdp_info_t* info, const char* value);
typedef struct _belle_sdp_media belle_sdp_media_t;
belle_sdp_media_t* belle_sdp_media_new();
belle_sdp_media_t* belle_sdp_media_parse (const char* media);
const char* belle_sdp_media_get_value(const belle_sdp_media_t* media);
void belle_sdp_media_set_value(belle_sdp_media_t* media, const char* value);
belle_sip_list_t* belle_sdp_media_get_media_formats(const belle_sdp_media_t* media, unsigned int create);
belle_sip_list_t* belle_sdp_media_get_media_formats(const belle_sdp_media_t* media);
int belle_sdp_media_get_media_port(const belle_sdp_media_t* media);
const char* belle_sdp_media_get_media_type(const belle_sdp_media_t* media);
int belle_sdp_media_get_port_count(const belle_sdp_media_t* media);
......@@ -111,7 +109,7 @@ void belle_sdp_media_set_media_formats(belle_sdp_media_t* media, belle_sip_list_
void belle_sdp_media_set_media_port(belle_sdp_media_t* media, int port);
void belle_sdp_media_set_media_type(belle_sdp_media_t* media, const char* mediaType);
void belle_sdp_media_set_port_count(belle_sdp_media_t* media, int portCount);
void belle_sdp_media_set_media_protocol(belle_sdp_media_t* media, const char* protocole);
void belle_sdp_media_set_protocol(belle_sdp_media_t* media, const char* protocole);
#define BELLE_SDP_MEDIA(t) BELLE_SDP_CAST(t,belle_sdp_media_t);
/***************************************************************************************
......@@ -123,9 +121,9 @@ belle_sdp_media_description_t* belle_sdp_media_description_new();
belle_sdp_media_description_t* belle_sdp_media_description_parse (const char* media_description);
void belle_sdp_media_description_add_dynamic_payloads(belle_sdp_media_description_t* media_description, belle_sip_list_t* payloadNames, belle_sip_list_t* payloadValues);
const char* belle_sdp_media_description_get_attribute(const belle_sdp_media_description_t* media_description, const char* name);
belle_sip_list_t* belle_sdp_media_description_get_attributes(const belle_sdp_media_description_t* media_description, unsigned int create);
belle_sip_list_t* belle_sdp_media_description_get_attributes(const belle_sdp_media_description_t* media_description);
int belle_sdp_media_description_get_bandwidth(const belle_sdp_media_description_t* media_description, const char* name);
belle_sip_list_t* belle_sdp_media_description_get_bandwidths(const belle_sdp_media_description_t* media_description, unsigned int create);
belle_sip_list_t* belle_sdp_media_description_get_bandwidths(const belle_sdp_media_description_t* media_description);
belle_sdp_connection_t* belle_sdp_media_description_get_connection(const belle_sdp_media_description_t* media_description);
belle_sdp_info_t* belle_sdp_media_description_get_info(const belle_sdp_media_description_t* media_description);
/*belle_sdp_key_t* belle_sdp_media_description_get_key(const belle_sdp_media_description_t* media_description);*/
......@@ -135,14 +133,29 @@ belle_sip_list_t* belle_sdp_media_description_get_mime_types(const belle_sdp_med
void belle_sdp_media_description_remove_attribute(belle_sdp_media_description_t* media_description,const char* attribute);
void belle_sdp_media_description_remove_bandwidth(belle_sdp_media_description_t* media_description,const char* bandwidth);
void belle_sdp_media_description_set_attribute(belle_sdp_media_description_t* media_description, const char* name, const char* value);
void belle_sdp_media_description_add_attribute(belle_sdp_media_description_t* media_description, const belle_sdp_attribute_t* attr);
void belle_sdp_media_description_set_attributes(belle_sdp_media_description_t* media_description, belle_sip_list_t* Attributes);
void belle_sdp_media_description_set_bandwidth(belle_sdp_media_description_t* media_description, const char* name, int value);
void belle_sdp_media_description_add_bandwidth(belle_sdp_media_description_t* media_description, const belle_sdp_bandwidth_t* bandwidth);
void belle_sdp_media_description_set_bandwidths(belle_sdp_media_description_t* media_description, belle_sip_list_t* bandwidths);
void belle_sdp_media_description_set_connection(belle_sdp_media_description_t* media_description, belle_sdp_connection_t* conn);
void belle_sdp_media_description_set_info(belle_sdp_media_description_t* media_description,belle_sdp_info_t* i);
/*void belle_sdp_media_description_set_key(belle_sdp_media_description_t* media_description,belle_sdp_key_t* key);*/
void belle_sdp_media_description_set_media(belle_sdp_media_description_t* media_description, belle_sdp_media_t* media);
#define BELLE_SDP_MEDIA_DESCRIPTION(t) BELLE_SDP_CAST(t,belle_sdp_media_description_t);
/***************************************************************************************
* mime_parameter
*
**************************************************************************************/
typedef struct _belle_sdp_mime_parameter belle_sdp_mime_parameter_t;
belle_sdp_mime_parameter_t* belle_sdp_mime_parameter_new();
int belle_sdp_mime_get_rate(const belle_sdp_mime_parameter_t* mime_parameter);
int belle_sdp_mime_get_channnel_count(const belle_sdp_mime_parameter_t* mime_parameter);
int belle_sdp_mime_get_ptime(const belle_sdp_mime_parameter_t* mime_parameter);
int belle_sdp_mime_get_max_ptime(const belle_sdp_mime_parameter_t* mime_parameter);
belle_sip_list_t* belle_sdp_mime_get_parameters(const belle_sdp_mime_parameter_t* mime_parameter);
/***************************************************************************************
* Origin
*
......@@ -153,9 +166,9 @@ belle_sdp_origin_t* belle_sdp_origin_parse (const char* origin);
const char* belle_sdp_origin_get_address(const belle_sdp_origin_t* origin);
const char* belle_sdp_origin_get_address_type(const belle_sdp_origin_t* origin);
const char* belle_sdp_origin_get_network_type(const belle_sdp_origin_t* origin);
long belle_sdp_origin_get_session_id(const belle_sdp_origin_t* origin);
long belle_sdp_origin_get_session_version(const belle_sdp_origin_t* origin);
long belle_sdp_origin_get_session_username(const belle_sdp_origin_t* origin);
int belle_sdp_origin_get_session_id(const belle_sdp_origin_t* origin);
int belle_sdp_origin_get_session_version(const belle_sdp_origin_t* origin);
const char* belle_sdp_origin_get_username(const belle_sdp_origin_t* origin);
void belle_sdp_origin_set_address(belle_sdp_origin_t* origin, const char* address);
void belle_sdp_origin_set_address_type(belle_sdp_origin_t* origin, const char* address);
void belle_sdp_origin_set_session_id(belle_sdp_origin_t* origin, long address);
......@@ -244,19 +257,19 @@ belle_sdp_session_description_t* belle_sdp_session_description_new();
belle_sdp_session_description_t* belle_sdp_session_description_parse (const char* session_description);
const char* belle_sdp_session_description_get_attribute(const belle_sdp_session_description_t* session_description, const char* name);
int belle_sdp_session_description_get_bandwidth(const belle_sdp_session_description_t* session_description, const char* name);
belle_sip_list_t* belle_sdp_session_description_get_bandwidths(const belle_sdp_session_description_t* session_description, unsigned int create);
belle_sip_list_t* belle_sdp_session_description_get_bandwidths(const belle_sdp_session_description_t* session_description);
belle_sdp_connection_t* belle_sdp_session_description_get_connection(const belle_sdp_session_description_t* session_description);
belle_sip_list_t* belle_sdp_session_description_get_emails(const belle_sdp_session_description_t* session_description, unsigned int create);
belle_sip_list_t* belle_sdp_session_description_get_emails(const belle_sdp_session_description_t* session_description);
belle_sdp_info_t* belle_sdp_session_description_get_info(const belle_sdp_session_description_t* session_description);
/*belle_sdp_key_t* belle_sdp_session_description_get_key(const belle_sdp_session_description_t* session_description);*/
belle_sdp_info_t* belle_sdp_session_description_get_mediaDescriptions(const belle_sdp_session_description_t* session_description, unsigned int create);
belle_sip_list_t* belle_sdp_session_description_get_media_descriptions(const belle_sdp_session_description_t* session_description);
belle_sdp_origin_t* belle_sdp_session_description_get_origin(const belle_sdp_session_description_t* session_description);
belle_sip_list_t* belle_sdp_session_description_get_phones(const belle_sdp_session_description_t* session_description, unsigned int create);
belle_sip_list_t* belle_sdp_session_description_get_phones(const belle_sdp_session_description_t* session_description);
belle_sdp_session_name_t* belle_sdp_session_description_get_session_name(const belle_sdp_session_description_t* session_description);
belle_sip_list_t* belle_sdp_session_description_get_time_descriptions(const belle_sdp_session_description_t* session_description, unsigned int create);
belle_sip_list_t* belle_sdp_session_description_get_time_descriptions(const belle_sdp_session_description_t* session_description);
belle_sdp_uri_t* belle_sdp_session_description_get_uri(const belle_sdp_session_description_t* session_description);
belle_sdp_version_t* belle_sdp_session_description_get_version(const belle_sdp_session_description_t* session_description);
belle_sdp_uri_t* belle_sdp_session_description_get_zone_adjustments(const belle_sdp_session_description_t* session_description, unsigned int create);
belle_sdp_uri_t* belle_sdp_session_description_get_zone_adjustments(const belle_sdp_session_description_t* session_description);
void belle_sdp_session_description_remove_attribute(belle_sdp_session_description_t* session_description, const char* name);
void belle_sdp_session_description_remove_bandwidth(belle_sdp_session_description_t* session_description, const char* name);
void belle_sdp_session_description_set_attribute(belle_sdp_session_description_t* session_description, const char* name, const char* value);
......@@ -274,6 +287,6 @@ void belle_sdp_session_description_set_session_name(belle_sdp_session_descriptio
void belle_sdp_session_description_set_time_descriptions(belle_sdp_session_description_t* session_description, belle_sip_list_t* times);
void belle_sdp_session_description_set_uri(belle_sdp_session_description_t* session_description, belle_sdp_uri_t* uri);
void belle_sdp_session_description_set_version(belle_sdp_session_description_t* session_description, belle_sdp_version_t* v);
void belle_sdp_session_description_set_zone_adjustments(belle_sdp_session_description_t* session_description, belle_sip_list_t* zoneAdjustments);
void belle_sdp_session_description_set_zone_adjustments(belle_sdp_session_description_t* session_description, belle_sdp_uri_t* zoneAdjustments);
#define BELLE_SDP_SESSION_DESCRIPTION(t) BELLE_SDP_CAST(t,belle_sdp_session_description_t);
#endif /* BELLE_SDP_H_ */
......@@ -90,6 +90,7 @@ typedef enum belle_sip_type_id{
BELLE_SIP_TYPE_ID(belle_sdp_time_description_t),
BELLE_SIP_TYPE_ID(belle_sdp_uri_t),
BELLE_SIP_TYPE_ID(belle_sdp_version_t),
BELLE_SIP_TYPE_ID(belle_sdp_base_description_t),
belle_sip_type_id_end
}belle_sip_type_id_t;
......
......@@ -18,6 +18,11 @@
#ifndef BELLE_SIP_LIST_H_
#define BELLE_SIP_LIST_H_
struct _belle_sip_list {
struct _belle_sip_list *next;
struct _belle_sip_list *prev;
void *data;
};
typedef struct _belle_sip_list belle_sip_list_t;
belle_sip_list_t * belle_sip_list_append(belle_sip_list_t * elem, void * data);
......
......@@ -28,8 +28,11 @@ options {
#include "belle_sip_internal.h"
}
session_description: proto_version
origin_field
session_description returns [belle_sdp_session_description_t* ret]
scope { belle_sdp_session_description_t* current; }
@init {$session_description::current = belle_sdp_session_description_new(); $ret=$session_description::current; }
: version CR LF
origin CR LF
session_name_field
(info CR LF)?
uri_field?
......@@ -44,13 +47,18 @@ session_description: proto_version
(attribute CR LF)*
media_descriptions;
proto_version: {IS_TOKEN(v)}?alpha_num EQUAL DIGIT+ CR LF;
version: {IS_TOKEN(v)}?alpha_num EQUAL v=DIGIT+ {belle_sdp_version_t* version =belle_sdp_version_new();
belle_sdp_version_set_version(version,atoi((const char*)$v.text->chars));
belle_sdp_session_description_set_version($session_description::current,version);};
// ;this memo describes version 0
origin_field: {IS_TOKEN(o)}?alpha_num EQUAL username SPACE
origin returns [belle_sdp_origin_t* ret]
scope { belle_sdp_origin_t* current; }
@init {$origin::current = belle_sdp_origin_new(); $ret=$origin::current; }
: {IS_TOKEN(o)}?alpha_num EQUAL username SPACE
sess_id SPACE sess_version SPACE
nettype SPACE addrtype SPACE
addr CR LF;
addr ;
session_name_field: {IS_TOKEN(s)}? alpha_num EQUAL text CR LF;
......@@ -73,7 +81,7 @@ phone_field: {IS_TOKEN(p)}?alpha_num EQUAL phone_number CR LF;
connection returns [belle_sdp_connection_t* ret]
scope { belle_sdp_connection_t* current; }
@init {$connection::current = belle_sdp_connection_new(); $ret=$connection::current; }
: 'c=' nettype { belle_sdp_connection_set_network_type($connection::current,(const char*)$nettype.text->chars);}
: {IS_TOKEN(c)}?alpha_num EQUAL nettype { belle_sdp_connection_set_network_type($connection::current,(const char*)$nettype.text->chars);}
SPACE addrtype{ belle_sdp_connection_set_address_type($connection::current,(const char*)$addrtype.text->chars);}
SPACE connection_address {belle_sdp_connection_set_address($connection::current,(const char*)$connection_address.text->chars);}
;
......@@ -109,32 +117,36 @@ scope { belle_sdp_attribute_t* current; }
@init {$attribute::current = belle_sdp_attribute_new(); $ret=$attribute::current; }: {IS_TOKEN(a)}?alpha_num EQUAL attribute_value;
media_descriptions: media_description*;
media_description: media CR LF
(info CR LF)?
(connection CR LF)?
(bandwidth CR LF)*
media_description returns [belle_sdp_media_description_t* ret]
scope { belle_sdp_media_description_t* current; }
@init {$media_description::current = belle_sdp_media_description_new(); $ret=$media_description::current; }
: media CR LF {belle_sdp_media_description_set_media($media_description::current,$media.ret);}
(info {belle_sdp_media_description_set_info($media_description::current,$info.ret);} CR LF)?
(connection { belle_sdp_media_description_set_connection($media_description::current,$connection.ret);} CR LF)?
(bandwidth {belle_sdp_media_description_add_bandwidth($media_description::current,$bandwidth.ret);} CR LF)*
key_field ?
(attribute CR LF)*;
(attribute {belle_sdp_media_description_add_attribute($media_description::current,$attribute.ret);} CR LF)*;
media returns [belle_sdp_media_t* ret]
scope { belle_sdp_media_t* current; }
@init {$media::current = belle_sdp_media_new(); $ret=$media::current; }
: {IS_TOKEN(m)}?alpha_num EQUAL
media_value {belle_sdp_media_set_value($media::current,(const char*)$media_value.text->chars);}
media_value {belle_sdp_media_set_media_type($media::current,(const char*)$media_value.text->chars);}
SPACE port {belle_sdp_media_set_media_port($media::current,atoi((const char*)$port.text->chars));}
(SLASH integer{belle_sdp_media_set_port_count($media::current,atoi((const char*)$integer.text->chars));})?
SPACE proto {belle_sdp_media_set_media_protocol($media::current,(const char*)$proto.text->chars);}
(SPACE fmt)?;
SPACE proto {belle_sdp_media_set_protocol($media::current,(const char*)$proto.text->chars);}
(SPACE fmt)*;
media_value: alpha_num+;
// ;typically "audio", "video", "application"
// ;or "data"
fmt: DIGIT+;
fmt: DIGIT+ {belle_sdp_media_set_media_formats($media::current
,belle_sip_list_append(belle_sdp_media_get_media_formats($media::current)
,(void*)atoi((const char*)$fmt.text->chars)));};
//;typically an RTP payload type for audio
//;and video media
proto options { greedy = false; }: ~(SPACE|CR|LF)*;
//;typically "RTP/AVP" or "udp" for IP4
......
This diff is collapsed.
......@@ -106,11 +106,7 @@ BELLE_SIP_DECLARE_VPTR(belle_sip_parameters_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_contact_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_source_t);
struct _belle_sip_list {
struct _belle_sip_list *next;
struct _belle_sip_list *prev;
void *data;
};
typedef void (*belle_sip_source_remove_callback_t)(belle_sip_source_t *);
......@@ -566,7 +562,18 @@ belle_sdp_##object_type##_t* belle_sdp_##object_type##_parse (const char* value)
super_type##_init((super_type##_t*)l_object); \
return l_object;\
}
#define BELLE_SDP_NEW_WITH_CTR(object_type,super_type) \
BELLE_SIP_INSTANCIATE_VPTR( belle_sdp_##object_type##_t\
, super_type##_t\
, belle_sdp_##object_type##_destroy\
, belle_sdp_##object_type##_clone\
, belle_sdp_##object_type##_marshal); \
belle_sdp_##object_type##_t* belle_sdp_##object_type##_new () { \
belle_sdp_##object_type##_t* l_object = belle_sip_object_new(belle_sdp_##object_type##_t);\
super_type##_init((super_type##_t*)l_object); \
belle_sdp_##object_type##_init(l_object); \
return l_object;\
}
......
......@@ -93,7 +93,75 @@ static void test_info(void) {
CU_ASSERT_STRING_EQUAL(belle_sdp_info_get_value(l_info), "A Seminar on the session description protocol");
belle_sip_object_unref(BELLE_SIP_OBJECT(l_info));
}
static void test_media(void) {
belle_sdp_media_t* l_media = belle_sdp_media_parse("m=audio 7078 RTP/AVP 111 110 3 0 8 101");
char* l_raw_media = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_media));
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media));
l_media = belle_sdp_media_parse(l_raw_media);
CU_ASSERT_STRING_EQUAL(belle_sdp_media_get_media_type(l_media), "audio");
CU_ASSERT_EQUAL(belle_sdp_media_get_media_port(l_media), 7078);
CU_ASSERT_STRING_EQUAL(belle_sdp_media_get_protocol(l_media), "RTP/AVP");
belle_sip_list_t* list = belle_sdp_media_get_media_formats(l_media);
CU_ASSERT_PTR_NOT_NULL(list);
int fmt[] ={111,110,3,0,8,101};
int i=0;
for(;list!=NULL;list=list->next){
CU_ASSERT_EQUAL((int)(list->data),fmt[i++]);
}
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media));
}
static void test_media_description(void) {
const char* l_src = "m=video 8078 RTP/AVP 99 97 98\r\n"\
"c=IN IP4 192.168.0.18\r\n"\
"b=AS:380\r\n"\
"a=rtpmap:99 MP4V-ES/90000\r\n"\
"a=fmtp:99 profile-level-id=3\r\n"\
"a=rtpmap:97 theora/90000\r\n"\
"a=rtpmap:98 H263-1998/90000\r\n"\
"a=fmtp:98 CIF=1;QCIF=1\r\n";
belle_sdp_media_description_t* l_media_description = belle_sdp_media_description_parse(l_src);
char* l_raw_media_description = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_media_description));
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media_description));
l_media_description = belle_sdp_media_description_parse(l_raw_media_description);
/*media*/
belle_sdp_media_t* l_media = belle_sdp_media_description_get_media(l_media_description);
CU_ASSERT_PTR_NOT_NULL(l_media);
CU_ASSERT_STRING_EQUAL(belle_sdp_media_get_media_type(l_media), "video");
CU_ASSERT_EQUAL(belle_sdp_media_get_media_port(l_media), 8078);
CU_ASSERT_STRING_EQUAL(belle_sdp_media_get_protocol(l_media), "RTP/AVP");
belle_sip_list_t* list = belle_sdp_media_get_media_formats(l_media);
CU_ASSERT_PTR_NOT_NULL(list);
int fmt[] ={99,97,98};
int i=0;
for(;list!=NULL;list=list->next){
CU_ASSERT_EQUAL((int)(list->data),fmt[i++]);
}
/*connection*/
belle_sdp_connection_t* lConnection = belle_sdp_media_description_get_connection(l_media_description);
CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_address(lConnection), "192.168.0.18");
CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_address_type(lConnection), "IP4");
CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_network_type(lConnection), "IN");
/*bandwidth*/
CU_ASSERT_EQUAL(belle_sdp_media_description_get_bandwidth(l_media_description,"AS"),380);
/*attributes*/
list = belle_sdp_media_description_get_attributes(l_media_description);
CU_ASSERT_PTR_NOT_NULL(list);
const char* attr[] ={"99 MP4V-ES/90000"
,"99 profile-level-id=3"
,"97 theora/90000"
,"98 H263-1998/90000"
,"98 CIF=1;QCIF=1"};
i=0;
for(;list!=NULL;list=list->next){
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_value((belle_sdp_attribute_t*)(list->data)),attr[i++]);
}
belle_sip_object_unref(BELLE_SIP_OBJECT(l_media_description));
}
int belle_sdp_test_suite () {
......@@ -117,5 +185,12 @@ int belle_sdp_test_suite () {
}
if (NULL == CU_add_test(pSuite, "info", test_info)) {
return CU_get_error();
} return 0;
}
if (NULL == CU_add_test(pSuite, "media", test_media)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "media_description", test_media_description)) {
return CU_get_error();
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment