From df85ae417f865bf392f92913fde858d777af7811 Mon Sep 17 00:00:00 2001 From: damencho Date: Tue, 7 Feb 2017 22:27:54 +0200 Subject: Updates libjitsi and sends hole punch packets for audio. When sending hole punch packets, use as a content a generated rtp packet. --- .../protocol/media/CallPeerMediaHandler.java | 30 +++++++++++++++++++--- .../service/protocol/media/TransportManager.java | 21 ++++++++++++++- 2 files changed, 46 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java b/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java index c8a3a12..ead01d1 100644 --- a/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java +++ b/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java @@ -87,6 +87,16 @@ public abstract class CallPeerMediaHandler> public static final String VIDEO_REMOTE_SSRC = "VIDEO_REMOTE_SSRC"; /** + * The initial content of a hole punch packet. It has some fields pre-set. + * Like rtp verion, sequence number and timestamp. + */ + private static final byte[] HOLE_PUNCH_PACKET = + { + (byte)0x80, 0x00, 0x02, (byte)0x9E, 0x00, 0x09, + (byte)0xD0, (byte)0x80, 0x00, 0x00, 0x00, (byte)0x00, + }; + + /** * List of advertised encryption methods. Indicated before establishing the * call. */ @@ -1575,11 +1585,21 @@ public abstract class CallPeerMediaHandler> * to open port on NAT or RTP proxy if any. In order to be really efficient, * this method should be called after we send our offer or answer. * - * @param target MediaStreamTarget + * @param stream MediaStream non-null stream + * @param mediaType MediaType */ - protected void sendHolePunchPacket(MediaStreamTarget target) + protected void sendHolePunchPacket(MediaStream stream, MediaType mediaType) { - getTransportManager().sendHolePunchPacket(target, MediaType.VIDEO); + // send as a hole punch packet a constructed rtp packet + // has the correct payload type and ssrc + RawPacket packet = new RawPacket( + HOLE_PUNCH_PACKET, 0, RawPacket.FIXED_HEADER_SIZE); + packet.setPayloadType( + dynamicPayloadTypes.getPayloadType(stream.getFormat())); + packet.setSSRC((int)stream.getLocalSourceID()); + + getTransportManager().sendHolePunchPacket( + stream.getTarget(), mediaType, packet); } /** @@ -1936,6 +1956,8 @@ public abstract class CallPeerMediaHandler> stream.getTarget(), MediaType.AUDIO); stream.start(); + + sendHolePunchPacket(stream, MediaType.AUDIO); } stream = getStream(MediaType.VIDEO); @@ -1964,7 +1986,7 @@ public abstract class CallPeerMediaHandler> * send the hole-punch packet anyway to let the remote video * reach this local peer. */ - sendHolePunchPacket(stream.getTarget()); + sendHolePunchPacket(stream, MediaType.VIDEO); } } } diff --git a/src/net/java/sip/communicator/service/protocol/media/TransportManager.java b/src/net/java/sip/communicator/service/protocol/media/TransportManager.java index a8222e0..051a302 100644 --- a/src/net/java/sip/communicator/service/protocol/media/TransportManager.java +++ b/src/net/java/sip/communicator/service/protocol/media/TransportManager.java @@ -516,6 +516,21 @@ public abstract class TransportManager> */ public void sendHolePunchPacket(MediaStreamTarget target, MediaType type) { + this.sendHolePunchPacket(target, type, null); + } + + /** + * Sends empty UDP packets to target destination data/control ports in order + * to open ports on NATs or and help RTP proxies latch onto our RTP ports. + * + * @param target MediaStreamTarget + * @param type the {@link MediaType} of the connector we'd like to send the + * hole punching packet through. + * @param packet (optional) use a pre-generated packet that will be sent + */ + public void sendHolePunchPacket( + MediaStreamTarget target, MediaType type, RawPacket packet) + { logger.info("Send NAT hole punch packets"); //check how many hole punch packets we would be supposed to send: @@ -536,7 +551,11 @@ public abstract class TransportManager> if(connector.getProtocol() == StreamConnector.Protocol.TCP) return; - byte[] buf = new byte[0]; + byte[] buf; + if (packet != null) + buf = packet.getBuffer(); + else + buf = new byte[0]; synchronized(connector) { -- cgit v1.1