diff --git a/daemon/codec.c b/daemon/codec.c index f8ea40180..3621489d6 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -2152,12 +2152,22 @@ static void codec_add_raw_packet_dup(struct media_packet *mp, unsigned int clock // don't just duplicate the string. need to ensure enough room // if encryption is enabled on this stream // or for RTP header extensions - size_t ext_len = mp->sink.rtpext->length(mp); - p->s.s = bufferpool_alloc(media_bufferpool, mp->raw.len + ext_len + RTP_BUFFER_TAIL_ROOM); - memcpy(p->s.s, mp->raw.s, mp->raw.len); - p->s.len = mp->raw.len; + if (mp->rtp) { + size_t ext_len = mp->sink.rtpext->length(mp); + size_t tot_len = sizeof(*mp->rtp) + ext_len + mp->payload.len; + p->s.s = bufferpool_alloc(media_bufferpool, tot_len + RTP_BUFFER_TAIL_ROOM); + p->s.len = tot_len; + p->rtp = (struct rtp_header *) p->s.s; + *p->rtp = *mp->rtp; + mp->sink.rtpext->print(p->rtp, p->s.s + sizeof(*p->rtp), mp); + memcpy(p->s.s + sizeof(*p->rtp) + ext_len, mp->payload.s, mp->payload.len); + } + else { + p->s.s = bufferpool_alloc(media_bufferpool, mp->raw.len + RTP_BUFFER_TAIL_ROOM); + memcpy(p->s.s, mp->raw.s, mp->raw.len); + p->s.len = mp->raw.len; + } p->free_func = bufferpool_unref; - p->rtp = (struct rtp_header *) p->s.s; codec_add_raw_packet_common(mp, clockrate, p); } diff --git a/t/auto-daemon-tests-rtp-ext.pl b/t/auto-daemon-tests-rtp-ext.pl index 83e5b8b29..89cd5198f 100755 --- a/t/auto-daemon-tests-rtp-ext.pl +++ b/t/auto-daemon-tests-rtp-ext.pl @@ -436,9 +436,9 @@ a=rtcp:PORT SDP snd($sock_a, $port_b, rtp( 8, 1000, 3000+160*0, 0x1234, "\x10" . ("\x00" x 158) . "\x50", [[1, "foo"], [2, "woot"], [3, "meh"], [4, "yugh"]])); -rcv($sock_b, $port_a, rtpm(8, 1000, 3000+160*0, 0x1234, "\x10" . ("\x00" x 158) . "\x50", [[1, "foo"], [2, "woot"], [3, "meh"], [4, "yugh"]])); +rcv($sock_b, $port_a, rtpm(8, 1000, 3000+160*0, 0x1234, "\x10" . ("\x00" x 158) . "\x50", [[2, "woot"]])); snd($sock_b, $port_a, rtp( 8, 8000, 7000+160*0, 0x6543, "\x10" . ("\x00" x 158) . "\x50", [[1, "foo"], [2, "woot"], [3, "meh"], [4, "yugh"]])); -rcv($sock_a, $port_b, rtpm(8, 8000, 7000+160*0, 0x6543, "\x10" . ("\x00" x 158) . "\x50", [[1, "foo"], [2, "woot"], [3, "meh"], [4, "yugh"]])); +rcv($sock_a, $port_b, rtpm(8, 8000, 7000+160*0, 0x6543, "\x10" . ("\x00" x 158) . "\x50", [[1, "foo"], [2, "woot"]])); # XXX should be just 2 ? @@ -505,9 +505,9 @@ a=rtcp:PORT SDP snd($sock_a, $port_b, rtp( 8, 1000, 3000+160*0, 0x1234, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"], [4, "argh"], [3, "yikes"]])); -rcv($sock_b, $port_a, rtpm(8, 1000, 3000+160*0, 0x1234, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"], [4, "argh"], [3, "yikes"]])); +rcv($sock_b, $port_a, rtpm(8, 1000, 3000+160*0, 0x1234, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"], [3, "yikes"]])); snd($sock_b, $port_a, rtp( 8, 8000, 7000+160*0, 0x6543, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"], [4, "argh"], [3, "yikes"]])); -rcv($sock_a, $port_b, rtpm(8, 8000, 7000+160*0, 0x6543, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"], [4, "argh"], [3, "yikes"]])); +rcv($sock_a, $port_b, rtpm(8, 8000, 7000+160*0, 0x6543, "\x39" . ("\x29" x 158) . "\x74", [[1, "foo"], [2, "blah"]]));