From 8d937b2e49ec6f2cd78acd0bd6905389953cf4b4 Mon Sep 17 00:00:00 2001 From: Emil Ivov Date: Sat, 28 Nov 2009 19:40:50 +0000 Subject: [PATCH] Adds support for the negotiation of RTP extensions use in media sessions --- .../protocol/sip/CallPeerMediaHandler.java | 67 ++++++++++++++++--- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/sip/CallPeerMediaHandler.java b/src/net/java/sip/communicator/impl/protocol/sip/CallPeerMediaHandler.java index 85fb7eca9..14794c5d7 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/CallPeerMediaHandler.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/CallPeerMediaHandler.java @@ -903,10 +903,6 @@ private Vector createMediaDescriptionsForAnswer( List supportedFormats = SdpUtils.extractFormats( mediaDescription, dynamicPayloadTypes); - List offeredRTPExtensions - = SdpUtils.extractRTPExtensions( - mediaDescription, this.rtpExtensionsRegistry); - MediaDevice dev = getDefaultDevice(mediaType); MediaDirection devDirection = (dev == null) ? MediaDirection.INACTIVE : dev.getDirection(); @@ -943,6 +939,17 @@ private Vector createMediaDescriptionsForAnswer( MediaDirection direction = devDirection .getDirectionForAnswer(remoteDirection); + // check whether we will be exchanging any RTP extensions. + List offeredRTPExtensions + = SdpUtils.extractRTPExtensions( + mediaDescription, this.rtpExtensionsRegistry); + + List supportedExtensions + = getExtensionsForType(mediaType); + + List rtpExtensions = intersectRTPExtensions( + offeredRTPExtensions, supportedExtensions); + // create the corresponding stream... initStream(connector, dev, supportedFormats.get(0), target, direction); @@ -950,7 +957,7 @@ private Vector createMediaDescriptionsForAnswer( // create the answer description answerDescriptions.add(createMediaDescription( supportedFormats, connector, - direction, supportedRTPExtensions)); + direction, rtpExtensions)); atLeastOneValidDescription = true; } @@ -972,12 +979,12 @@ private Vector createMediaDescriptionsForAnswer( * the local device that we are dealing with. Direction attributes of both * lists are also intersected and the returned RTPExtensions have * directions valid from a local perspective. In other words, if - * offeredExtensions contains an extension that the remote party + * remoteExtensions contains an extension that the remote party * supports in a SENDONLY mode, and we support that extension in a * SENDRECV mode, the corresponding entry in the returned list will * have a RECVONLY direction. * - * @param offeredExtensions the List of RTPExtensions as + * @param remoteExtensions the List of RTPExtensions as * advertised by the remote party. * @param supportedExtensions the List of RTPExtensions * that a local MediaDevice returned as supported. @@ -987,15 +994,33 @@ private Vector createMediaDescriptionsForAnswer( * for configuring a stream. */ private List intersectRTPExtensions( - List offeredExtensions, + List remoteExtensions, List supportedExtensions) { - List + List intersection = new ArrayList( + Math.min(remoteExtensions.size(), supportedExtensions.size())); + //loop through the list that the remote party sent - for(RTPExtension offeredExtension : offeredExtensions) + for(RTPExtension remoteExtension : remoteExtensions) { - RTPExtension localExtension + RTPExtension localExtension = findExtension( + supportedExtensions, remoteExtension.getURI().toString()); + + if(localExtension == null) + continue; + + MediaDirection localDir = localExtension.getDirection(); + MediaDirection remoteDir = remoteExtension.getDirection(); + + RTPExtension intersected = new RTPExtension( + localExtension.getURI(), + localDir.getDirectionForAnswer(remoteDir), + remoteExtension.getExtensionAttributes()); + + intersection.add(intersected); } + + return intersection; } /** @@ -1025,6 +1050,26 @@ private RTPExtension findExtension(List extList, return null; } + /** + * Returns a (possibly empty) List of RTPExtensions + * supported by the device that this media handler uses to handle media of + * the specified type. + * + * @param type the MediaType of the device whose + * RTPExtensions we are interested in. + * + * @return a (possibly empty) List of RTPExtensions + * supported by the device that this media handler uses to handle media of + * the specified type. + */ + private List getExtensionsForType(MediaType type) + { + List supportedExtensions + = new ArrayList(); + + return supportedExtensions; + } + /** * Handles the specified answer by creating and initializing the * corresponding MediaStreams.