From 08fc00906d15bb856131ddbd9c8d97872f13390c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 4 Jul 2018 11:40:04 -0400 Subject: [PATCH] fix segfault with DTMF logging and implicit payload types fixes #571 Change-Id: Id2b575ff555d7968006309bcb5b5d6bbac2ed1e7 --- daemon/codec.c | 10 +++++++++ t/transcode-test.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/daemon/codec.c b/daemon/codec.c index abb89a410..268b0172b 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -523,6 +523,16 @@ static int handler_func_passthrough(struct codec_handler *h, struct media_packet static int __handler_func_sequencer(struct codec_handler *h, struct media_packet *mp, struct transcode_packet *packet) { + if (G_UNLIKELY(!h->ssrc_hash)) { + if (!packet->func || !packet->handler || !packet->handler->ssrc_hash) { + h->func(h, mp); + return 0; + } + // DTMF handler with implicit (not negotiated) primary payload type + h = packet->handler; + /// fall through + } + struct codec_ssrc_handler *ch = get_ssrc(mp->rtp->ssrc, h->ssrc_hash); if (G_UNLIKELY(!ch)) return 0; diff --git a/t/transcode-test.c b/t/transcode-test.c index 7ed93c505..5a50e670b 100644 --- a/t/transcode-test.c +++ b/t/transcode-test.c @@ -754,5 +754,57 @@ int main() { packet_seq_exp(A, 8, PCMA_payload, 1000960, 212, 0, PCMU_payload, 5); // expected seq is 207+5 for PT 8 end(); + // plain DTMF passthrough w/o transcoding w/ implicit primary payload type + start(); + sdp_pt(8, PCMA, 8000); + sdp_pt(101, telephone-event, 8000); + offer(); + expect(A, recv, ""); + expect(A, send, "8/PCMA/8000 101/telephone-event/8000"); + expect(B, recv, "8/PCMA/8000 101/telephone-event/8000"); + expect(B, send, ""); + sdp_pt(8, PCMA, 8000); + sdp_pt(101, telephone-event, 8000); + answer(); + expect(A, recv, "8/PCMA/8000 101/telephone-event/8000"); + expect(A, send, "8/PCMA/8000 101/telephone-event/8000"); + expect(B, recv, "8/PCMA/8000 101/telephone-event/8000"); + expect(B, send, "8/PCMA/8000 101/telephone-event/8000"); + packet_seq(A, 0, PCMU_payload, 1000000, 200, 0, PCMU_payload); + // start with marker + packet_seq(A, 101 | 0x80, "\x08\x0a\x00\xa0", 1000160, 201, 101 | 0x80, "\x08\x0a\x00\xa0"); + dtmf(""); + // continuous event with increasing length + // XXX check output ts, seq, ssrc + packet_seq(A, 101, "\x08\x0a\x01\x40", 1000160, 202, 101, "\x08\x0a\x01\x40"); + packet_seq(A, 101, "\x08\x0a\x01\xe0", 1000160, 203, 101, "\x08\x0a\x01\xe0"); + packet_seq(A, 101, "\x08\x0a\x02\x80", 1000160, 204, 101, "\x08\x0a\x02\x80"); + dtmf(""); + // end + packet_seq(A, 101, "\x08\x8a\x03\x20", 1000160, 205, 101, "\x08\x8a\x03\x20"); + dtmf("{\"callid\":\"test-call\",\"source_tag\":\"tag_A\",\"tags\":[],\"type\":\"DTMF\",\"timestamp\":0,\"source_ip\":\"(null)\",\"event\":8,\"duration\":100,\"volume\":10}"); + packet_seq_exp(A, 101, "\x08\x8a\x03\x20", 1000160, 205, 101, "\x08\x8a\x03\x20", 0); + packet_seq_exp(A, 101, "\x08\x8a\x03\x20", 1000160, 205, 101, "\x08\x8a\x03\x20", 0); + dtmf(""); + // send some more audio + packet_seq_exp(A, 0, PCMU_payload, 1000960, 206, 0, PCMU_payload, 6); // expected seq is 200+6 for PT 8 + packet_seq(A, 0, PCMU_payload, 1001120, 207, 0, PCMU_payload); + // start with marker + packet_seq_exp(A, 101 | 0x80, "\x05\x0a\x00\xa0", 1001280, 208, 101 | 0x80, "\x05\x0a\x00\xa0", 3); // expected seq is 205+3 for PT 101 + dtmf(""); + // continuous event with increasing length + packet_seq(A, 101, "\x05\x0a\x01\x40", 1001280, 209, 101, "\x05\x0a\x01\x40"); + packet_seq(A, 101, "\x05\x0a\x01\xe0", 1001280, 210, 101, "\x05\x0a\x01\xe0"); + dtmf(""); + // end + packet_seq(A, 101, "\x05\x8a\x02\x80", 1001280, 211, 101, "\x05\x8a\x02\x80"); + dtmf("{\"callid\":\"test-call\",\"source_tag\":\"tag_A\",\"tags\":[],\"type\":\"DTMF\",\"timestamp\":0,\"source_ip\":\"(null)\",\"event\":5,\"duration\":80,\"volume\":10}"); + packet_seq_exp(A, 101, "\x05\x8a\x02\x80", 1001280, 211, 101, "\x05\x8a\x02\x80", 0); + packet_seq_exp(A, 101, "\x05\x8a\x02\x80", 1001280, 211, 101, "\x05\x8a\x02\x80", 0); + dtmf(""); + // final audio RTP test + packet_seq_exp(A, 0, PCMU_payload, 1000960, 212, 0, PCMU_payload, 5); // expected seq is 207+5 for PT 8 + end(); + return 0; }