From 4481c773ac53896cd79f0b64d1db1b04b415f777 Mon Sep 17 00:00:00 2001 From: Daniel Hauptmann Date: Mon, 26 Jul 2021 11:09:31 -0400 Subject: [PATCH] TT#128050 Squashed commit of the following: commit b0c722da69ad088a2eddced12b37c0546a514890 Author: Daniel Hauptmann Date: Mon Jul 26 15:35:51 2021 +0200 changed flag bit length in call_interfaces.h changed bit length of reuse_codec from 0 to 1 commit 0313a747532d5987f25fa9edb202aa460bf98dd1 Author: Daniel Hauptmann Date: Mon Jul 26 15:29:20 2021 +0200 inversed reuse_codec logic in test-transcode.c and call.c, reuse_codec = 0 (default) will now result in using codec_store_populate instead of codec_store_populate_reuse commit b876bd686bd30df21a5962aca16fc1c85574f554 Author: Daniel Hauptmann Date: Mon Jul 26 15:18:19 2021 +0200 adding option to minimalize changes in the codec_store_population added function codec_store_populate_reuse in codec.c which replaces codec_store_populate but makes fewer changes to the GLists with the old and new codecs added flag to enable this feature (disabled by default) commit 6fd0b701c9589b2fae00300801e02a9b5cc397ab Author: Daniel Hauptmann Date: Mon Jul 26 14:44:42 2021 +0200 Added Option to minimize change in the codecs In codec.c added function to populate codec store with the fewest changes between the old and new GList which contains the codecs. Added new testroutine in test-transcode.c line 1500 Added flag to call_interfaces.h to optionally enable this feature Change-Id: If58d9a07d114b05dfb75553a87eb4372ae949fbb commit 3bf554a8fbae7e948343699f40d935693618b764 Author: Daniel Hauptmann Date: Fri Jul 23 13:58:02 2021 +0200 changing codec-exchange behaviour in codec.c line 3288 function codec_store_populate now doesnt empty dst and copy new codec from src to it, instead codecs from src will be appended to dst and codec from dst, which are not being contained by src are being removed Change-Id: Id6b7ee65595f9cc5c71ef557c7bac5ee38f97cbe --- daemon/call.c | 8 +++++++- daemon/codec.c | 32 ++++++++++++++++++++++++++++++++ include/call_interfaces.h | 1 + include/codec.h | 1 + lib/auxlib.c | 7 ------- t/test-transcode.c | 24 ++++++++++++++++++++++++ 6 files changed, 65 insertions(+), 8 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index c1f386548..2a70718f4 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2180,8 +2180,12 @@ void codecs_offer_answer(struct call_media *media, struct call_media *other_medi ilogs(codec, LOG_DEBUG, "Updating receiver side codecs for offerer " STR_FORMAT " #%u", STR_FMT(&other_media->monologue->tag), other_media->index); - codec_store_populate(&other_media->codecs, &sp->codecs, flags ? flags->codec_set : NULL); if (flags) { + if (flags->reuse_codec){ + codec_store_populate(&other_media->codecs, &sp->codecs, flags ? flags->codec_set : NULL); + }else{ + codec_store_populate_reuse(&other_media->codecs, &sp->codecs, flags ? flags->codec_set : NULL); + } codec_store_strip(&other_media->codecs, &flags->codec_strip, flags->codec_except); codec_store_offer(&other_media->codecs, &flags->codec_offer, &sp->codecs); if (!other_media->codecs.strip_full) @@ -2189,6 +2193,8 @@ void codecs_offer_answer(struct call_media *media, struct call_media *other_medi codec_store_accept(&other_media->codecs, &flags->codec_accept, NULL); codec_store_accept(&other_media->codecs, &flags->codec_consume, &sp->codecs); codec_store_track(&other_media->codecs, &flags->codec_mask); + }else{ + codec_store_populate(&other_media->codecs, &sp->codecs, flags ? flags->codec_set : NULL); } // we don't update the answerer side if the offer is not RTP but is going diff --git a/daemon/codec.c b/daemon/codec.c index 807a29177..56119b2e3 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -3285,6 +3285,38 @@ static void codec_store_add_end(struct codec_store *cs, struct rtp_payload_type codec_store_add_link(cs, pt, NULL); } +void codec_store_populate_reuse(struct codec_store *dst, struct codec_store *src, GHashTable *codec_set) { + // start fresh + struct call_media *media = dst->media; + struct call *call = media ? media->call : NULL; + + for (GList *l = src->codec_prefs.head; l; l = l->next) { + struct rtp_payload_type *pt = l->data; + struct rtp_payload_type *orig_pt = g_hash_table_lookup(dst->codecs, + GINT_TO_POINTER(pt->payload_type)); + ilogs(codec, LOG_DEBUG, "Adding codec " STR_FORMAT " (%i)", + STR_FMT(&pt->encoding_with_params), + pt->payload_type); + + if (!orig_pt) { + __codec_options_set(call, pt, codec_set); + codec_store_add_end(dst, pt); + } + } + if(dst->codec_prefs.head){ + for (GList *l = dst->codec_prefs.head; l;) { + struct rtp_payload_type *pt = l->data; + struct rtp_payload_type *orig_pt = g_hash_table_lookup(src->codecs, + GINT_TO_POINTER(pt->payload_type)); + if(!orig_pt){ + l = __codec_store_delete_link(l, dst); + }else{ + l = l->next; + } + } + } +} + void codec_store_populate(struct codec_store *dst, struct codec_store *src, GHashTable *codec_set) { // start fresh struct codec_store orig_dst; diff --git a/include/call_interfaces.h b/include/call_interfaces.h index 02744ea48..481b04fa1 100644 --- a/include/call_interfaces.h +++ b/include/call_interfaces.h @@ -110,6 +110,7 @@ struct sdp_ng_flags { loop_protect:1, original_sendrecv:1, single_codec:1, + reuse_codec:1, inject_dtmf:1, t38_decode:1, t38_force:1, diff --git a/include/codec.h b/include/codec.h index 2d3f43819..1b1505e28 100644 --- a/include/codec.h +++ b/include/codec.h @@ -88,6 +88,7 @@ void codec_calc_jitter(struct ssrc_ctx *, unsigned long ts, unsigned int clockra void codec_store_cleanup(struct codec_store *cs); void codec_store_init(struct codec_store *cs, struct call_media *); void codec_store_populate(struct codec_store *, struct codec_store *, GHashTable *); +void codec_store_populate_reuse(struct codec_store *, struct codec_store *, GHashTable *); void codec_store_add_raw(struct codec_store *cs, struct rtp_payload_type *pt); void codec_store_strip(struct codec_store *, GQueue *strip, GHashTable *except); void codec_store_offer(struct codec_store *, GQueue *, struct codec_store *); diff --git a/lib/auxlib.c b/lib/auxlib.c index 7387ba9a4..cf9318912 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -163,7 +163,6 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char }; #undef ll - // prepend shared CLI options unsigned int shared_len = options_length(shared_options); unsigned int app_len = options_length(app_entries); @@ -172,7 +171,6 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char AUTO_CLEANUP(GOptionEntry *entries, free_gopte) = malloc(entries_size); memcpy(entries, shared_options, sizeof(*entries) * shared_len); memcpy(&entries[shared_len], app_entries, sizeof(*entries) * (app_len + 1)); - AUTO_CLEANUP(GOptionEntry *entries_copy, free_gopte) = malloc(entries_size); memcpy(entries_copy, entries, entries_size); @@ -180,13 +178,11 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char g_option_context_add_main_entries(c, entries, NULL); if (!g_option_context_parse(c, argc, argv, &er)) goto err; - if (rtpe_common_config_ptr->config_section) { use_section = g_strdup(rtpe_common_config_ptr->config_section); } else { use_section = g_strdup(default_section); } - // is there a config file to load? use_config = default_config; if (rtpe_common_config_ptr->config_file) { @@ -195,18 +191,15 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char goto out; fatal = 1; } - if (!g_key_file_load_from_file(kf, use_config, G_KEY_FILE_NONE, &er)) { if (!fatal && (g_error_matches(er, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND) || g_error_matches(er, G_FILE_ERROR, G_FILE_ERROR_NOENT))) goto out; goto err; } - // destroy the option context to reset - we'll do it again later g_option_context_free(c); c = NULL; - // iterate the options list and see if the config file defines any. // free any strings we come across, as we'll load argv back in. // also keep track of any returned strings so we can free them if diff --git a/t/test-transcode.c b/t/test-transcode.c index e17c1b27c..ebf603308 100644 --- a/t/test-transcode.c +++ b/t/test-transcode.c @@ -1458,6 +1458,30 @@ int main(void) { packet_seq(B, 101, "\x05\x07\x07\x80", 4000, 10, 102, "\x05\x07\x2d\x00"); end(); + //reusing_codecs test + flags.reuse_codec = 1; + start(); + sdp_pt(0, PCMA, 8000); + sdp_pt(8, PCMU, 8000); + sdp_pt(9, PCMA, 8000); + offer(); + expect(A, "0/PCMA/8000 8/PCMU/8000 9/PCMA/8000"); + sdp_pt(7, PCMA, 8000); + sdp_pt(0, PCMA, 8000); + sdp_pt(8, PCMU, 8000); + answer(); + expect(B, "7/PCMA/8000 0/PCMA/8000 8/PCMU/8000"); + sdp_pt(0, PCMA, 8000); + sdp_pt(8, PCMU, 8000); + sdp_pt(9, PCMA, 8000); + offer(); + expect(A, "0/PCMA/8000 8/PCMU/8000 9/PCMA/8000"); + sdp_pt(7, PCMA, 8000); + sdp_pt(0, PCMA, 8000); + sdp_pt(8, PCMU, 8000); + answer(); + expect(B, "7/PCMA/8000 0/PCMA/8000 8/PCMU/8000"); + end(); return 0; }