Browse Source

MT#56128 simplify sdp_manipulations_subst case

In order to perform a substitution we must do a lookup to the hash table
anyway. We can eliminate an extra lookup for the same key to check
whether a substitution exists by combining the two operations into one.

Change-Id: Ife8f1fbfd77ade1986a303a3a5503f4142f7de01
pull/1694/head
Richard Fuchs 2 years ago
parent
commit
e59e03ec05
2 changed files with 12 additions and 25 deletions
  1. +12
    -24
      daemon/sdp.c
  2. +0
    -1
      include/sdp.h

+ 12
- 24
daemon/sdp.c View File

@ -305,18 +305,7 @@ static int sdp_manipulate_check(enum command_type command_type,
GHashTable * ht = NULL;
switch (command_type) {
case CMD_SUBST:
if (!attr_name || !attr_name->len)
break;
ht = sdp_manipulations->subst_commands;
str * l = ht ? g_hash_table_lookup(ht, attr_name) : NULL;
if (l)
return 1;
break;
case CMD_REM:;
case CMD_REM:
if (!attr_name || !attr_name->len)
break;
@ -357,19 +346,16 @@ static void sdp_manipulations_add(struct sdp_chopper *chop,
/**
* Substitute values for a requested session level (global, audio, video)
*/
static void sdp_manipulations_subst(struct sdp_chopper *chop,
struct sdp_manipulations * sdp_manipulations,
static str *sdp_manipulations_subst(struct sdp_manipulations * sdp_manipulations,
str * attr_name) {
if (!sdp_manipulations)
return NULL;
GHashTable * ht = sdp_manipulations->subst_commands;
str * cmd_subst_value = ht ? g_hash_table_lookup(ht, attr_name) : NULL;
if (!cmd_subst_value)
return;
chopper_append_c(chop, "a=");
chopper_append_c(chop, cmd_subst_value->s);
chopper_append_c(chop, "\r\n");
return cmd_subst_value;
}
static void append_attr_to_gstring(GString *s, char * name, const str * value,
@ -2267,7 +2253,8 @@ static int process_session_attributes(struct sdp_chopper *chop, struct sdp_attri
goto strip;
/* if attr is supposed to be substituted don't add to the chop->output, but add another value */
if (sdp_manipulate_check(CMD_SUBST, sdp_manipulations, &attr->line_value))
str *subst_str = sdp_manipulations_subst(sdp_manipulations, &attr->line_value);
if (subst_str)
goto strip_with_subst;
switch (attr->attr) {
@ -2336,7 +2323,7 @@ strip_with_subst:
return -1;
if (skip_over(chop, &attr->full_line))
return -1;
sdp_manipulations_subst(chop, sdp_manipulations, &attr->line_value);
chopper_append_printf(chop, "a=" STR_FORMAT "\r\n", STR_FMT(subst_str));
}
return 0;
@ -2365,7 +2352,8 @@ static int process_media_attributes(struct sdp_chopper *chop, struct sdp_media *
goto strip;
/* if attr is supposed to be substituted don't add to the chop->output, but add another value */
if (sdp_manipulate_check(CMD_SUBST, sdp_manipulations, &attr->line_value))
str *subst_str = sdp_manipulations_subst(sdp_manipulations, &attr->line_value);
if (subst_str)
goto strip_with_subst;
switch (attr->attr) {
@ -2463,7 +2451,7 @@ strip_with_subst:
return -1;
if (skip_over(chop, &attr->full_line))
return -1;
sdp_manipulations_subst(chop, sdp_manipulations, &attr->line_value);
chopper_append_printf(chop, "a=" STR_FORMAT "\r\n", STR_FMT(subst_str));
}
return 0;


+ 0
- 1
include/sdp.h View File

@ -9,7 +9,6 @@
enum command_type {
CMD_REM = 1,
CMD_SUBST,
};
/* A structure for SDP arbitrary manipulations on all levels of SDP:


Loading…
Cancel
Save