Commit bda91a73 authored by Ghislain MARY's avatar Ghislain MARY

Add parsing of RTCP-XR SDP attribute.

parent 0654b530
This diff is collapsed.
......@@ -89,7 +89,9 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sdp_media_description_t),
BELLE_SIP_TYPE_ID(belle_sdp_origin_t),
BELLE_SIP_TYPE_ID(belle_sdp_phone_t),
BELLE_SIP_TYPE_ID(belle_sdp_raw_attribute_t),
BELLE_SIP_TYPE_ID(belle_sdp_repeate_time_t),
BELLE_SIP_TYPE_ID(belle_sdp_rtcp_xr_attribute_t),
BELLE_SIP_TYPE_ID(belle_sdp_session_description_t),
BELLE_SIP_TYPE_ID(belle_sdp_session_name_t),
BELLE_SIP_TYPE_ID(belle_sdp_time_t),
......
This diff is collapsed.
......@@ -169,7 +169,9 @@ BELLE_SIP_DECLARE_VPTR(belle_sdp_media_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_media_description_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_origin_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_phone_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_raw_attribute_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_repeate_time_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_rtcp_xr_attribute_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_session_description_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_session_name_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_time_t);
......
......@@ -219,11 +219,53 @@ key_value options { greedy = false; }: (~(CR|LF))*;
//key_data: email_safe;
attribute returns [belle_sdp_attribute_t* ret]
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_description returns [belle_sdp_media_description_t* ret]
attribute returns [belle_sdp_attribute_t* ret]
scope {int has_value;}
@init {$ret=NULL;}
: {IS_TOKEN(a)}?alpha_num EQUAL attribute_content{$ret=$attribute_content.ret;};
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
if ($ret) belle_sip_object_unref($ret);
$ret=NULL;
}
attribute_content returns [belle_sdp_attribute_t* ret]
//options { greedy = false; }
@init {$ret=NULL;}
: (attribute_name COLON attribute_value) {
$ret=belle_sdp_attribute_create((const char*)$attribute_name.text->chars,(const char*)$attribute_value.text->chars);
}| attribute_name {
$ret=belle_sdp_attribute_create((const char*)$attribute_name.text->chars,NULL);
};
rtcp_xr_attribute returns [belle_sdp_rtcp_xr_attribute_t* ret]
scope { belle_sdp_rtcp_xr_attribute_t* current; }
@init { $rtcp_xr_attribute::current = belle_sdp_rtcp_xr_attribute_new();$ret = $rtcp_xr_attribute::current;}
: {IS_TOKEN(a)}?alpha_num EQUAL {IS_TOKEN(rtcp-xr)}? attribute_name /*'rtcp-xr'*/ (COLON rtcp_xr_attribute_value (SPACE rtcp_xr_attribute_value)*)?;
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($ret);
$ret=NULL;
}
rtcp_xr_attribute_value
: ({IS_TOKEN(rcvr-rtt)}? rtcp_xr_attribute_name /*'rcvr-rtt'*/ EQUAL {IS_TOKEN(all) || IS_TOKEN(sender)}? rtcp_xr_rcvr_rtt_mode {
belle_sdp_rtcp_xr_attribute_set_rcvr_rtt_mode($rtcp_xr_attribute::current,(const char*)$rtcp_xr_rcvr_rtt_mode.text->chars);
})
| ({IS_TOKEN(stat-summary)}? rtcp_xr_attribute_name /*'stat-summary'*/ {
belle_sdp_rtcp_xr_attribute_set_stat_summary($rtcp_xr_attribute::current,1);
} (EQUAL rtcp_xr_stat_summary_flag (COMMA rtcp_xr_stat_summary_flag)*)?)
| ({IS_TOKEN(voip-metrics)}? rtcp_xr_attribute_name /*'voip-metrics'*/ {
belle_sdp_rtcp_xr_attribute_set_voip_metrics($rtcp_xr_attribute::current,1);
});
rtcp_xr_stat_summary_flag
: {IS_TOKEN(loss) || IS_TOKEN(dup) || IS_TOKEN(jitt) || IS_TOKEN(TTL) || IS_TOKEN(HL)}?rtcp_xr_stat_summary_flag_value {
belle_sdp_rtcp_xr_attribute_add_stat_summary_flag($rtcp_xr_attribute::current,(const char*)$rtcp_xr_stat_summary_flag_value.text->chars);
};
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);}
......@@ -232,13 +274,13 @@ scope { belle_sdp_media_description_t* current; }
(bandwidth {belle_sdp_media_description_add_bandwidth($media_description::current,$bandwidth.ret);} CR LF)*
(key_field CR LF)?
(attribute {belle_sdp_media_description_add_attribute($media_description::current,$attribute.ret);} CR LF)*;
catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($ret);
$ret=NULL;
}
}
media returns [belle_sdp_media_t* ret]
scope { belle_sdp_media_t* current; }
@init {$media::current = belle_sdp_media_new(); $ret=$media::current; }
......@@ -260,7 +302,7 @@ media_value: alpha_num+;
fmt
scope { int is_number; }
@init { $fmt::is_number=0;}: ((DIGIT+)=>(DIGIT+){$fmt::is_number=1;} | token+ )
@init { $fmt::is_number=0;}: ((DIGIT+)=>(DIGIT+){$fmt::is_number=1;} | token )
{belle_sdp_media_set_media_formats($media::current
,belle_sip_list_append(belle_sdp_media_get_media_formats($media::current)
,(void*)($fmt::is_number?(void*)(long)atoi((const char*)$fmt.text->chars):$fmt.text->chars)));};
......@@ -273,13 +315,15 @@ port: DIGIT+;
// ;should in the range "1024" to "65535" inclusive
// ;for UDP based media
attribute_value: (att_field {belle_sdp_attribute_set_name($attribute::current,(const char*)$att_field.text->chars);}
COLON att_value {belle_sdp_attribute_set_value($attribute::current,(const char*)$att_value.text->chars);})
| att_field {belle_sdp_attribute_set_name($attribute::current,(const char*)$att_field.text->chars);};
attribute_name: token;
attribute_value options { greedy = false; }: ~(CR|LF)*;
rtcp_xr_attribute_name: word;
att_field: token+;
rtcp_xr_rcvr_rtt_mode: word;
att_value options { greedy = false; }: ~(CR|LF)*;
rtcp_xr_stat_summary_flag_value: word;
sess_id: DIGIT+;
// ;should be unique for this originating username/host
......@@ -378,11 +422,12 @@ integer: DIGIT+;
email_safe : byte_string;
token : alpha_num | '!' | '#' | '$' |'&'| '%'| '\'' | '*' |'+' | DASH | DOT ;
token : (alpha_num | '!' | '#' | '$' |'&'| '%'| '\'' | '*' |'+' | DASH | DOT)+;
alpha_num: (alpha | DIGIT) ;
hexdigit: (HEX_CHAR | DIGIT) ;
alpha: (COMMON_CHAR | HEX_CHAR);
word: (alpha | DASH)+;
DIGIT: ZERO | POS_DIGIT;
fragment ZERO: '0';
......@@ -404,4 +449,5 @@ EQUAL: '=';
COLON: ':';
SLASH: '/';
DASH: '-';
COMMA: ',';
ANY_EXCEPT_CR_LF: ~(CR|LF);
......@@ -42,34 +42,68 @@
//a=fmtp:98 CIF=1;QCIF=1
static void test_attribute(void) {
static belle_sdp_attribute_t* attribute_parse_marshall_parse_clone(const char* raw_attribute) {
belle_sdp_attribute_t* lTmp;
belle_sdp_attribute_t* lAttribute = belle_sdp_attribute_parse("a=rtpmap:101 telephone-event/8000");
belle_sdp_attribute_t* lAttribute = belle_sdp_attribute_parse(raw_attribute);
char* l_raw_attribute = belle_sip_object_to_string(BELLE_SIP_OBJECT(lAttribute));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
lTmp = belle_sdp_attribute_parse(l_raw_attribute);
belle_sip_free(l_raw_attribute);
lAttribute = BELLE_SDP_ATTRIBUTE(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
return lAttribute;
}
static void test_attribute(void) {
belle_sdp_attribute_t* lAttribute = attribute_parse_marshall_parse_clone("a=rtpmap:101 telephone-event/8000");
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(lAttribute), "rtpmap");
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_value(lAttribute), "101 telephone-event/8000");
CU_ASSERT_TRUE(belle_sdp_attribute_as_value(lAttribute));
CU_ASSERT_STRING_EQUAL(belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(lAttribute)), "101 telephone-event/8000");
CU_ASSERT_TRUE(belle_sdp_raw_attribute_has_value(BELLE_SDP_RAW_ATTRIBUTE(lAttribute)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
}
static void test_attribute_2(void) {
belle_sdp_attribute_t* lTmp;
belle_sdp_attribute_t* lAttribute = belle_sdp_attribute_parse("a=ice-pwd:31ec21eb38b2ec6d36e8dc7b\r\n");
char* l_raw_attribute = belle_sip_object_to_string(BELLE_SIP_OBJECT(lAttribute));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
lTmp = belle_sdp_attribute_parse(l_raw_attribute);
belle_sip_free(l_raw_attribute);
lAttribute = BELLE_SDP_ATTRIBUTE(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp));
belle_sdp_attribute_t* lAttribute = attribute_parse_marshall_parse_clone("a=ice-pwd:31ec21eb38b2ec6d36e8dc7b");
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(lAttribute), "ice-pwd");
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_value(lAttribute), "31ec21eb38b2ec6d36e8dc7b");
CU_ASSERT_TRUE(belle_sdp_attribute_as_value(lAttribute));
CU_ASSERT_STRING_EQUAL(belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(lAttribute)), "31ec21eb38b2ec6d36e8dc7b");
CU_ASSERT_TRUE(belle_sdp_raw_attribute_has_value(BELLE_SDP_RAW_ATTRIBUTE(lAttribute)));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
}
static void test_rtcp_xr_attribute(void) {
belle_sdp_rtcp_xr_attribute_t* lAttribute;
lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr"));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr");
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_stat_summary(lAttribute) == FALSE);
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_voip_metrics(lAttribute) == FALSE);
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
/*lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:rcvr-rtt=all"));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr");
CU_ASSERT_STRING_EQUAL(belle_sdp_rtcp_xr_attribute_get_rcvr_rtt_mode(lAttribute), "all");
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));*/
/*lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:stat-summary"));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr");
CU_ASSERT_PTR_NULL(belle_sdp_rtcp_xr_attribute_get_rcvr_rtt_mode(lAttribute));
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_stat_summary(lAttribute) == TRUE);
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_voip_metrics(lAttribute) == FALSE);
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));*/
/*lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:stat-summary=loss,jitt"));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr");
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_stat_summary(lAttribute) == TRUE);
CU_ASSERT_PTR_NOT_NULL(belle_sip_list_find_custom(belle_sdp_rtcp_xr_attribute_get_stat_summary_flags(lAttribute), (belle_sip_compare_func)strcasecmp, "loss"));
CU_ASSERT_PTR_NOT_NULL(belle_sip_list_find_custom(belle_sdp_rtcp_xr_attribute_get_stat_summary_flags(lAttribute), (belle_sip_compare_func)strcasecmp, "jitt"));
CU_ASSERT_PTR_NULL(belle_sip_list_find_custom(belle_sdp_rtcp_xr_attribute_get_stat_summary_flags(lAttribute), (belle_sip_compare_func)strcasecmp, "HL"));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));*/
/*lAttribute = BELLE_SDP_RTCP_XR_ATTRIBUTE(attribute_parse_marshall_parse_clone("a=rtcp-xr:voip-metrics"));
CU_ASSERT_STRING_EQUAL(belle_sdp_attribute_get_name(BELLE_SDP_ATTRIBUTE(lAttribute)), "rtcp-xr");
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_stat_summary(lAttribute) == FALSE);
CU_ASSERT_TRUE(belle_sdp_rtcp_xr_attribute_has_voip_metrics(lAttribute) == TRUE);
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));*/
}
static void test_bandwidth(void) {
......@@ -223,7 +257,7 @@ static void test_media_description_base(belle_sdp_media_description_t* media_des
CU_ASSERT_PTR_NOT_NULL(list);
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++]);
CU_ASSERT_STRING_EQUAL(belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE((belle_sdp_attribute_t*)(list->data))),attr[i++]);
}
}
......@@ -452,7 +486,7 @@ static void check_mime_param (belle_sdp_mime_parameter_t* mime_param
}
int static compare_attribute(belle_sdp_attribute_t* attr, const char* value) {
return strcasecmp(belle_sdp_attribute_get_name(attr),"rtpmap")==0
|| strcasecmp(belle_sdp_attribute_get_value(attr),value)==0;
|| strcasecmp(belle_sdp_raw_attribute_get_value(BELLE_SDP_RAW_ATTRIBUTE(attr)),value)==0;
}
static void test_mime_parameter(void) {
const char* l_src = "m=audio 7078 RTP/AVP 111 110 0 8 9 3 18 101\r\n"\
......@@ -548,6 +582,7 @@ static void test_mime_parameter(void) {
test_t sdp_tests[] = {
{ "a= (attribute)", test_attribute },
{ "a= (attribute) 2", test_attribute_2 },
{ "a=rtcp-xr", test_rtcp_xr_attribute },
{ "b= (bandwidth)", test_bandwidth },
{ "o= (IPv4 origin)", test_connection },
{ "o= (malformed origin)", test_malformed_origin },
......
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