From ddcb961feeffcf2c839947e9cebbb9bd52e6f594 Mon Sep 17 00:00:00 2001 From: Emil Ivov Date: Tue, 8 Jan 2013 18:52:09 +0000 Subject: [PATCH] Tries to work around Offer/Answer negotiation issues in cases where an offending remote system would try to remap a payload type that has been previously allocated to a different format. --- .../jabber/jinglesdp/JingleUtils.java | 8 +++++-- .../impl/protocol/sip/sdp/SdpUtils.java | 10 ++++++-- .../media/DynamicPayloadTypeRegistry.java | 24 +++++++++++++++---- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/jinglesdp/JingleUtils.java b/src/net/java/sip/communicator/impl/protocol/jabber/jinglesdp/JingleUtils.java index 02b9c67fb..cae2c2899 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/jinglesdp/JingleUtils.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/jinglesdp/JingleUtils.java @@ -200,8 +200,12 @@ public static MediaFormat payloadTypeToMediaFormat( */ if ((ptRegistry != null) && (pt >= MediaFormat.MIN_DYNAMIC_PAYLOAD_TYPE) - && (pt <= MediaFormat.MAX_DYNAMIC_PAYLOAD_TYPE) - && (ptRegistry.findFormat(pt) == null)) + && (pt <= MediaFormat.MAX_DYNAMIC_PAYLOAD_TYPE)) + //some systems will violate 3264 by reusing previously defined + //payload types for new formats. we try and salvage that + //situation by creating an overriding mapping in such cases + //we therefore don't do the following check. + //&& (ptRegistry.findFormat(pt) == null)) { ptRegistry.addMapping(format, pt); } diff --git a/src/net/java/sip/communicator/impl/protocol/sip/sdp/SdpUtils.java b/src/net/java/sip/communicator/impl/protocol/sip/sdp/SdpUtils.java index 5e1b48d5a..1a38e5afc 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/sdp/SdpUtils.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/sdp/SdpUtils.java @@ -771,9 +771,15 @@ private static MediaFormat createFormat( if ((payloadType >= MediaFormat.MIN_DYNAMIC_PAYLOAD_TYPE) && (payloadType <= MediaFormat.MAX_DYNAMIC_PAYLOAD_TYPE) - && (format != null) - && (ptRegistry.findFormat(payloadType) == null)) + && (format != null)) + //some systems will violate 3264 by reusing previously defined + //payload types for new formats. we try and salvage that + //situation by creating an overriding mapping in such cases + //we therefore don't do the following check. + //&& (ptRegistry.findFormat(payloadType) == null)) + { ptRegistry.addMapping(format, payloadType); + } return format; } diff --git a/src/net/java/sip/communicator/service/protocol/media/DynamicPayloadTypeRegistry.java b/src/net/java/sip/communicator/service/protocol/media/DynamicPayloadTypeRegistry.java index 1893a923e..8d2171436 100644 --- a/src/net/java/sip/communicator/service/protocol/media/DynamicPayloadTypeRegistry.java +++ b/src/net/java/sip/communicator/service/protocol/media/DynamicPayloadTypeRegistry.java @@ -8,6 +8,8 @@ import java.util.*; +import net.java.sip.communicator.impl.protocol.sip.*; +import net.java.sip.communicator.util.*; import org.jitsi.service.neomedia.*; import org.jitsi.service.neomedia.format.*; @@ -30,6 +32,11 @@ */ public class DynamicPayloadTypeRegistry { + /** + * Our class logger. + */ + private static final Logger logger + = Logger.getLogger(DynamicPayloadTypeRegistry.class); /** * A field that we use to track dynamic payload numbers that we allocate. */ @@ -244,12 +251,13 @@ public void addMapping(MediaFormat format, byte payloadType) throws IllegalArgumentException { MediaFormat alreadyMappedFmt = findFormat(payloadType); - if(alreadyMappedFmt != null) { - throw new IllegalArgumentException( - payloadType + " has already been allocated to " - + alreadyMappedFmt); + logger.warn("Remote party is trying to remap payload type " + + payloadType + " and reassign it from " + + alreadyMappedFmt + " to " + format + + ". We'll go along but there might be issues because" + + " of this."); } if( payloadType < MediaFormat.MIN_DYNAMIC_PAYLOAD_TYPE) @@ -267,7 +275,13 @@ public void addMapping(MediaFormat format, byte payloadType) if(payloadTypeMappings.containsKey(format)) { byte originalPayloadType = payloadTypeMappings.get(format); - payloadTypeOverrides.put(originalPayloadType, payloadType); + + if(originalPayloadType != payloadType) + { + payloadTypeOverrides.put(originalPayloadType, payloadType); + } + //else: we already have the exact same mapping, so no need to + //override anything. } else {