Commit 51810110 authored by jehan's avatar jehan

close to have an sdp parser

parent 6325daf2
This diff is collapsed.
......@@ -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