diff --git a/daemon/codec.c b/daemon/codec.c index 8b0106d44..3491fa70f 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -3252,8 +3252,24 @@ void codec_tracker_finish(struct call_media *media) { continue; pt->for_transcoding = 1; + // there should be an existing entry with a different clock rate + GQueue *existing_pts = g_hash_table_lookup(media->codec_names_recv, &pt->encoding); + struct rtp_payload_type *existing_pt = NULL; + if (existing_pts && existing_pts->length) { + int pt_num = GPOINTER_TO_UINT(existing_pts->head->data); + existing_pt = g_hash_table_lookup(media->codecs_recv, &pt_num); + } + struct codec_handler *existing_handler = existing_pt ? codec_handler_get(media, existing_pt->payload_type) : NULL; + __rtp_payload_type_add_recv(media, pt, 1); + if (existing_pt && existing_handler) { + // since this happens after we ran through the codec matchup, we must create the appropriate handler here + struct codec_handler *handler = __get_pt_handler(media, pt); + // duplicate the codec handler of the existing PT + __make_transcoder(handler, &existing_handler->dest_pt, NULL, existing_handler->dtmf_payload_type, 0); + } + g_free(pt_s); } diff --git a/t/transcode-test.c b/t/transcode-test.c index 1f388c2aa..f1bb39cf1 100644 --- a/t/transcode-test.c +++ b/t/transcode-test.c @@ -1687,6 +1687,24 @@ int main(void) { packet_seq(B, 8, PCMA_payload, 160, 1, 8, PCMA_payload); packet_seq(A, 13, "\x20", 320, 2, 8, "\xf5\x5c\x4b\xc2\xde\xf4\x5e\xd4\x47\x70\x5d\x77\x45\x51\xc5\xcd\xd7\x77\x5a\xf5\xcf\x4a\x4c\x40\xc3\x47\x74\x49\x59\xc4\x76\x57\x71\x57\x40\xc5\xf4\x5a\x47\xd6\xc4\xf6\xc7\xf3\x40\x58\x74\x54\x4b\xd7\x5c\xc7\x41\x49\xf5\x5b\x53\xd9\x70\x44\xcd\xc4\xce\xcb\xc7\x58\xcd\x45\xc6\x71\xf5\x70\x43\xca\x43\xd5\x52\x5c\x75\x74\xc6\xc3\x4f\xda\x56\xc3\x46\xf5\x49\xdf\x56\x4f\x71\x5b\x52\xc6\x4e\xd0\x43\xc2\xcd\xd5\xdf\x40\x43\x4a\xf7\xf6\xd9\xdf\xde\x45\xc9\xd9\xc2\xf0\xc1\x4a\x40\x52\xd1\x5b\xd0\x54\xc9\x5e\xde\xd5\x74\x5c\x5d\x59\x71\xc1\xc1\x71\xd2\xcb\x50\x50\x54\x53\x75\xdc\x4b\xcf\xc2\xd7\x4a\xcc\x58\xc7\xdb\xd8\x48\x4a\xd6\x58\xf0\x46"); packet_seq(B, 8, PCMA_silence, 320, 2, 13, "\x40"); + // DTMF PT TC + start(); + sdp_pt(9, G722, 8000); + sdp_pt(8, PCMA, 8000); + sdp_pt(101, telephone-event, 8000); + ht_set(codec_mask, all); + transcode(opus/48000/1); + transcode(PCMA); + transcode(telephone-event); + offer(); + expect(B, recv, "96/opus/48000 8/PCMA/8000 101/telephone-event/8000 97/telephone-event/48000/0-15"); + sdp_pt(96, opus, 48000); + sdp_pt(97, telephone-event, 48000); + flags.single_codec = 1; + answer(); + expect(A, recv, "9/G722/8000 101/telephone-event/8000"); + packet_seq(A, 101, "\x05\x07\x01\x40", 4000, 10, 97, "\x05\x07\x07\x80"); + packet_seq(B, 97, "\x05\x07\x07\x80", 4000, 10, 101, "\x05\x07\x01\x40"); return 0; }