Browse Source

MT#56465 make sdp manipulations helpers array agnostic

Convert existing sdp manipulation helpers
to work with arrays directly, independently from
which array is actually given.

Moreover, don't use the `G_N_ELEMENTS()`,
since we already have the `__MT_MAX`
as the size of the array, so we can directly use
that instead of relying on the G_N_ELEMENTS macro
(for array size checks).

Change-Id: I38e71dab30a467b933c213c8157fa06651ebaf04
pull/1876/head
Donat Zenichev 1 year ago
parent
commit
b20a37fccd
3 changed files with 23 additions and 21 deletions
  1. +2
    -2
      daemon/call_interfaces.c
  2. +8
    -8
      daemon/sdp.c
  3. +13
    -11
      include/call_interfaces.h

+ 2
- 2
daemon/call_interfaces.c View File

@ -669,7 +669,7 @@ static void ng_sdp_attr_media_iter(const ng_parser_t *parser, str *command_type,
static void ng_sdp_attr_manipulations_iter(const ng_parser_t *parser, str *media_type, parser_arg command_action,
helper_arg arg)
{
struct sdp_manipulations *sm = sdp_manipulations_get_by_name(arg.flags, media_type);
struct sdp_manipulations *sm = sdp_manipulations_get_by_name(arg.flags->sdp_manipulations, media_type);
if (!sm) {
ilog(LOG_WARN, "SDP manipulations: unsupported SDP section '" STR_FORMAT "' targeted.",
STR_FMT(media_type));
@ -924,7 +924,7 @@ static struct sdp_manipulations *call_ng_flags_sdp_attr_helper(str *s, sdp_ng_fl
str token;
if (!str_token(&token, s, '-'))
return NULL;
struct sdp_manipulations *sm = sdp_manipulations_get_by_name(flags, &token);
struct sdp_manipulations *sm = sdp_manipulations_get_by_name(flags->sdp_manipulations, &token);
if (!sm) {
ilog(LOG_WARN, "SDP manipulations: unsupported SDP section '" STR_FORMAT "' targeted.",
STR_FMT(&token));


+ 8
- 8
daemon/sdp.c View File

@ -326,7 +326,7 @@ static void sdp_out_original_media_attributes(GString *out, struct call_media *m
* Checks whether an attribute removal request exists for a given session level.
* `attr_name` must be without `a=`.
*/
static bool sdp_manipulate_remove(struct sdp_manipulations * sdp_manipulations, const str * attr_name) {
static bool sdp_manipulate_remove(const struct sdp_manipulations * sdp_manipulations, const str * attr_name) {
/* no need for checks, if not given in flags */
if (!sdp_manipulations)
@ -350,19 +350,19 @@ static bool sdp_manipulate_remove(struct sdp_manipulations * sdp_manipulations,
* `attr_name` must be without `a=`.
*/
static bool sdp_manipulate_remove_c(const char *attr_name, const sdp_ng_flags *flags, enum media_type media_type) {
struct sdp_manipulations *sdp_manipulations = sdp_manipulations_get_by_id(flags, media_type);
struct sdp_manipulations *sdp_manipulations = sdp_manipulations_get_by_id(flags->sdp_manipulations, media_type);
return sdp_manipulate_remove(sdp_manipulations, STR_PTR(attr_name));
}
/**
* Adds values into a requested session level (global, audio, video)
*/
static void sdp_manipulations_add(GString *s, struct sdp_manipulations * sdp_manipulations) {
static void sdp_manipulations_add(GString *s, const struct sdp_manipulations * sdp_manipulations) {
if (!sdp_manipulations)
return;
str_q * q_ptr = &sdp_manipulations->add_commands;
const str_q * q_ptr = &sdp_manipulations->add_commands;
for (__auto_type l = q_ptr->head; l; l = l->next)
{
@ -377,7 +377,7 @@ static void sdp_manipulations_add(GString *s, struct sdp_manipulations * sdp_man
* Substitute values for a requested session level (global, audio, video).
* `attr_name` must be without `a=`.
*/
static str *sdp_manipulations_subst(struct sdp_manipulations * sdp_manipulations,
static str *sdp_manipulations_subst(const struct sdp_manipulations * sdp_manipulations,
const str * attr_name) {
if (!sdp_manipulations)
@ -2526,7 +2526,7 @@ const char *sdp_get_sendrecv(struct call_media *media) {
static void generic_append_attr_to_gstring(GString *s, const str * attr, char separator, const str * value,
const sdp_ng_flags *flags, enum media_type media_type)
{
struct sdp_manipulations *sdp_manipulations = sdp_manipulations_get_by_id(flags, media_type);
struct sdp_manipulations *sdp_manipulations = sdp_manipulations_get_by_id(flags->sdp_manipulations, media_type);
str * attr_subst = sdp_manipulations_subst(sdp_manipulations, attr);
@ -2845,7 +2845,7 @@ static void sdp_out_add_other(GString *out, struct call_monologue *monologue,
monologue->sdp_attr_print(out, monologue, flags);
/* ADD arbitrary SDP manipulations for a session sessions */
struct sdp_manipulations *sdp_manipulations = sdp_manipulations_get_by_id(flags, MT_UNKNOWN);
struct sdp_manipulations *sdp_manipulations = sdp_manipulations_get_by_id(flags->sdp_manipulations, MT_UNKNOWN);
sdp_manipulations_add(out, sdp_manipulations);
}
@ -3165,7 +3165,7 @@ int sdp_create(str *out, struct call_monologue *monologue, sdp_ng_flags *flags)
sdp_out_handle_osrtp2(s, media, prtp);
/* ADD arbitrary SDP manipulations for audio/video media sessions */
struct sdp_manipulations *sdp_manipulations = sdp_manipulations_get_by_id(flags, media->type_id);
struct sdp_manipulations *sdp_manipulations = sdp_manipulations_get_by_id(flags->sdp_manipulations, media->type_id);
sdp_manipulations_add(s, sdp_manipulations);
}


+ 13
- 11
include/call_interfaces.h View File

@ -298,25 +298,27 @@ void call_ng_main_flags(const ng_parser_t *, str *key, parser_arg value, helper_
void call_ng_codec_flags(const ng_parser_t *, str *key, parser_arg value, helper_arg);
void call_ng_direction_flag(const ng_parser_t *, sdp_ng_flags *, parser_arg value);
INLINE struct sdp_manipulations *sdp_manipulations_get_by_id(const sdp_ng_flags *f, enum media_type id) {
if (id < 0 || id >= G_N_ELEMENTS(f->sdp_manipulations))
INLINE struct sdp_manipulations *sdp_manipulations_get_by_id(struct sdp_manipulations * const array[__MT_MAX], enum media_type id)
{
if (id < 0 || id >= __MT_MAX)
return NULL;
return f->sdp_manipulations[id];
return array[id];
}
INLINE struct sdp_manipulations *sdp_manipulations_get_create_by_id(sdp_ng_flags *f, enum media_type id) {
if (id < 0 || id >= G_N_ELEMENTS(f->sdp_manipulations))
INLINE struct sdp_manipulations *sdp_manipulations_get_create_by_id(struct sdp_manipulations * array[__MT_MAX], enum media_type id)
{
if (id < 0 || id >= __MT_MAX)
return NULL;
if (!f->sdp_manipulations[id])
f->sdp_manipulations[id] = g_slice_alloc0(sizeof(*f->sdp_manipulations[id]));
return f->sdp_manipulations[id];
if (!array[id])
array[id] = g_slice_alloc0(sizeof(*array[id]));
return array[id];
}
INLINE struct sdp_manipulations *sdp_manipulations_get_by_name(sdp_ng_flags *f, const str *s) {
INLINE struct sdp_manipulations *sdp_manipulations_get_by_name(struct sdp_manipulations * array[__MT_MAX], const str *s) {
if (!str_cmp(s, "none") || !str_cmp(s, "global"))
return sdp_manipulations_get_create_by_id(f, MT_UNKNOWN);
return sdp_manipulations_get_create_by_id(array, MT_UNKNOWN);
enum media_type id = codec_get_type(s);
if (id == MT_OTHER)
return NULL;
return sdp_manipulations_get_create_by_id(f, id);
return sdp_manipulations_get_create_by_id(array, id);
}
// set all WebRTC-specific attributes
INLINE void ng_flags_webrtc(sdp_ng_flags *f) {


Loading…
Cancel
Save