diff --git a/README.md b/README.md index d5078347a..c5306b671 100644 --- a/README.md +++ b/README.md @@ -1303,6 +1303,7 @@ Optionally included keys are: * `codec` Contains a dictionary controlling various aspects of codecs (or RTP payload types). + Most of these options should only be used in an `offer` message. The following keys are understood: * `strip` @@ -1362,6 +1363,16 @@ Optionally included keys are: e.g. `opus/48000/2/32000`. In this case, all format parameters (clock rate, channels) must also be specified. + As a special case, if the `strip=all` option has been used and the `transcode` + option is used on a codec that was originally present in the offer, then + *rtpengine* will treat this codec the same as if it had been used with the `offer` + option, i.e. it will simply restore it from the list of stripped codecs and won't + actually engage transcoding for this codec. On the other hand, if a codec has + been stripped explicitly by name using the `strip` option and then used again + with the `transcode` option, then the codec will not simply be restored from the + list of stripped codecs, but instead a new transcoded instance of the codec will + be inserted into the offer. + * `mask` Similar to `strip` except that codecs listed here will still be accepted and @@ -1374,6 +1385,9 @@ Optionally included keys are: hand, if `strip=opus, transcode=G723` were given, then Opus would be unavailable for transcoding. + As with the `strip` option, the special keyword `all` can be used to mask all + codecs that have been offered. + * `ptime` Contains an integer. If set, changes the `a=ptime` attribute's value in the outgoing diff --git a/daemon/codec.c b/daemon/codec.c index f45863c3b..ecb9a9583 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -922,7 +922,7 @@ void codec_rtp_payload_types(struct call_media *media, struct call_media *other_ struct rtp_payload_type *pt; static const str str_all = STR_CONST_INIT("all"); GHashTable *removed = g_hash_table_new_full(str_hash, str_equal, NULL, __payload_queue_free); - int remove_all = 0; + int strip_all = 0, mask_all = 0; // start fresh // receiving part for 'media' @@ -935,7 +935,9 @@ void codec_rtp_payload_types(struct call_media *media, struct call_media *other_ g_hash_table_remove_all(other_media->codec_names_send); if (strip && g_hash_table_lookup(strip, &str_all)) - remove_all = 1; + strip_all = 1; + if (mask && g_hash_table_lookup(mask, &str_all)) + mask_all = 1; /* we steal the entire list to avoid duplicate allocs */ while ((pt = g_queue_pop_head(types))) { @@ -943,7 +945,7 @@ void codec_rtp_payload_types(struct call_media *media, struct call_media *other_ // codec stripping if (strip) { - if (remove_all || g_hash_table_lookup(strip, &pt->encoding) + if (strip_all || g_hash_table_lookup(strip, &pt->encoding) || g_hash_table_lookup(strip, &pt->encoding_with_params)) { ilog(LOG_DEBUG, "Stripping codec '" STR_FORMAT "'", @@ -955,7 +957,7 @@ void codec_rtp_payload_types(struct call_media *media, struct call_media *other_ continue; } } - if (!g_hash_table_lookup(mask, &pt->encoding) + if (!mask_all && !g_hash_table_lookup(mask, &pt->encoding) && !g_hash_table_lookup(mask, &pt->encoding_with_params)) __rtp_payload_type_add(media, other_media, pt); else @@ -972,10 +974,11 @@ void codec_rtp_payload_types(struct call_media *media, struct call_media *other_ // add transcode codecs for (GList *l = transcode ? transcode->head : NULL; l; l = l->next) { str *codec = l->data; - // if we wish to 'transcode' to a codec that was offered originally, + // if we wish to 'transcode' to a codec that was offered originally + // and removed by a strip=all option, // simply restore it from the original list and handle it the same way // as 'offer' - if (__revert_codec_strip(removed, codec, media, other_media)) + if (strip_all && __revert_codec_strip(removed, codec, media, other_media)) continue; // also check if maybe the codec was never stripped if (g_hash_table_lookup(media->codec_names_recv, codec)) {