diff options
author | Emil Ivov <emcho@jitsi.org> | 2010-08-06 20:06:24 +0000 |
---|---|---|
committer | Emil Ivov <emcho@jitsi.org> | 2010-08-06 20:06:24 +0000 |
commit | 8cb9a59060b732e4a6e677139327a224ddad3bee (patch) | |
tree | 0b1fadd3b6bb0bc54f51848fced8cf3bf9734456 /src/net/java/sip/communicator/service/protocol/media | |
parent | 6f9c56f2ef9554c60bd6580a0d01ea6bcab9c6e1 (diff) | |
download | jitsi-8cb9a59060b732e4a6e677139327a224ddad3bee.zip jitsi-8cb9a59060b732e4a6e677139327a224ddad3bee.tar.gz jitsi-8cb9a59060b732e4a6e677139327a224ddad3bee.tar.bz2 |
Adds possible assignment of preferred dynamic payload types so that we could gracefully handle systems that statically assigning dynamic payload type numbers. A popular example is telephone-event being assigned the 101 payload type. Problem reported on dev by Daniel Castro
Diffstat (limited to 'src/net/java/sip/communicator/service/protocol/media')
-rw-r--r-- | src/net/java/sip/communicator/service/protocol/media/DynamicPayloadTypeRegistry.java | 66 |
1 files changed, 63 insertions, 3 deletions
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 15594c6..1ddf42d 100644 --- a/src/net/java/sip/communicator/service/protocol/media/DynamicPayloadTypeRegistry.java +++ b/src/net/java/sip/communicator/service/protocol/media/DynamicPayloadTypeRegistry.java @@ -7,6 +7,7 @@ package net.java.sip.communicator.service.protocol.media; import java.util.*; +import java.util.Map.*; import net.java.sip.communicator.service.neomedia.*; import net.java.sip.communicator.service.neomedia.format.*; @@ -82,10 +83,26 @@ public class DynamicPayloadTypeRegistry } } - //hey, we already had this one, let's return it ;) + //seems like we haven't allocated a payload type for this format yet. + //lets try to do so now. if (payloadType == null) { - payloadType = nextPayloadTypeNumber(); + //first, let's check whether there's a particular PT number that + //this format would like to have (e.g. "telephone-event" generally + //loves to be called "101"). + Byte preferredPT = getPreferredDynamicPayloadType(format); + + if(preferredPT != null && findFormat(preferredPT) == null) + { + //the format has a preference and it's free + payloadType = preferredPT; + } + else + { + //the format does not have a preferred PT number or it isn't + //free. + payloadType = nextPayloadTypeNumber(); + } payloadTypeMappings.put(format, payloadType); } @@ -93,6 +110,22 @@ public class DynamicPayloadTypeRegistry } /** + * Returns the payload type number that <tt>format</tt> would like to use if + * possible and <tt>null</tt> if there is no such preference. + * + * @param format the {@link MediaFormat} whose preferred dynamic PT number + * we are trying to obtain. + * + * @return the payload type number that <tt>format</tt> would like to use if + * possible and <tt>null</tt> if there is no such preference. + */ + private Byte getPreferredDynamicPayloadType(MediaFormat format) + { + return ProtocolMediaActivator.getMediaService() + .getDynamicPayloadTypePreferences().get(format); + } + + /** * Adds the specified <tt>format</tt> to <tt>payloadType</tt> mapping to * the list of mappings known to this registry. The method is meant for * use primarily when handling incoming media descriptions, methods @@ -176,7 +209,8 @@ public class DynamicPayloadTypeRegistry byte payloadType = nextDynamicPayloadType++; - if(findFormat(payloadType) == null) + if(findFormat(payloadType) == null + && findFormatWithPreference(payloadType) == null) return payloadType; //if we get here then that means that the number we obtained by @@ -186,6 +220,32 @@ public class DynamicPayloadTypeRegistry } /** + * Returns the {@link MediaFormat} with the specified + * <tt>payloadTypePreference</tt> or <tt>null</tt> if no {@link MediaFormat} + * has claimed this payload type number as preferred. + * + * @param payloadTypePreference the dynamic payload type number that we + * are trying to determine as being claimed as preferred or not by a + * media format. + * + * @return the {@link MediaFormat} with the specified + * <tt>payloadTypePreference</tt> or <tt>null</tt> if no {@link MediaFormat} + * has claimed this payload type number as preferred. + */ + private MediaFormat findFormatWithPreference(Byte payloadTypePreference) + { + for(Entry<MediaFormat, Byte> entry + : ProtocolMediaActivator.getMediaService() + .getDynamicPayloadTypePreferences().entrySet()) + { + if(entry.getValue() == payloadTypePreference) + return entry.getKey(); + } + + return null; + } + + /** * Returns a copy of all mappings currently registered in this registry. * * @return a copy of all mappings currently registered in this registry. |