Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.sip.sdp
Class SdpUtils

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.sip.sdp.SdpUtils

public class SdpUtils
extends Object

The class contains a number of utility methods that are meant to facilitate creating and parsing SDP descriptions.

Author:
Emil Ivov, Lubomir Marinov

Field Summary
static String ZRTP_HASH_ATTR
          The name of the SDP attribute that defines zrtp hello hash.
 
Constructor Summary
SdpUtils()
           
 
Method Summary
static boolean containsAttribute(javax.sdp.MediaDescription description, String attributeName)
          Returns the media type (e.g.
static javax.sdp.Attribute createAttribute(String name, String value)
          Creates an Attribute object with the specified values.
static javax.sdp.MediaDescription createDisablingAnswer(javax.sdp.MediaDescription offer)
          Creates and returns a MediaDescription in answer of the specified offer that disables the corresponding stream by setting a 0 port and keeping the original list of formats and eliminating all attributes.
static javax.sdp.MediaDescription createMediaDescription(String transport, List<MediaFormat> formats, StreamConnector connector, MediaDirection direction, List<RTPExtension> rtpExtensions, DynamicPayloadTypeRegistry dynamicPayloadTypes, DynamicRTPExtensionsRegistry rtpExtensionsRegistry)
          Creates a new MediaDescription instance according to the specified formats, connector and direction, and using the dynamicPayloadTypes registry to handle dynamic payload type registrations.
static javax.sdp.SessionDescription createSessionDescription(InetAddress localAddress)
          Creates an empty instance of a SessionDescription with preinitialized s, v, c, o and t parameters.
static javax.sdp.SessionDescription createSessionDescription(InetAddress localAddress, String userName, Vector<javax.sdp.MediaDescription> mediaDescriptions)
          Creates an empty instance of a SessionDescription with preinitialized s, v, c, o and t parameters.
static javax.sdp.SessionDescription createSessionUpdateDescription(javax.sdp.SessionDescription descToUpdate, InetAddress newConnectionAddress, Vector<javax.sdp.MediaDescription> newMediaDescriptions)
          Creates and returns a new SessionDescription that is supposed to update our previous descToUpdate and advertise the brand new newMediaDescriptions.
static MediaStreamTarget extractDefaultTarget(javax.sdp.MediaDescription mediaDesc, javax.sdp.SessionDescription sessDesc)
          Returns a MediaStreamTarget instance reflecting the address pair (RTP + RTCP) where we should send media in this stream.
static List<MediaFormat> extractFormats(javax.sdp.MediaDescription mediaDesc, DynamicPayloadTypeRegistry ptRegistry)
          Extracts and returns the list of MediaFormats advertised in mediaDesc preserving their oder and registering dynamic payload type numbers in the specified ptRegistry.
static Vector<javax.sdp.MediaDescription> extractMediaDescriptions(javax.sdp.SessionDescription sessionDescription)
          Extracts and returns all MediaDescriptions provided in sessionDescription.
static List<RTPExtension> extractRTPExtensions(javax.sdp.MediaDescription mediaDesc, DynamicRTPExtensionsRegistry extMap)
          Extracts and returns the list of RTPExtensions advertised in mediaDesc and registers newly encountered ones into the specified extMap.
static URL getCallInfoURL(javax.sdp.SessionDescription sessDesc)
          Returns a URL pointing to a location with more details (and possibly call control utilities) about the session.
static String getContentAsString(javax.sip.message.Message message)
          Gets the content of the specified SIP Message in the form of a String value.
static MediaDirection getDirection(javax.sdp.MediaDescription mediaDesc)
          Determines the direction of the media stream that mediaDesc describes and returns the corresponding MediaDirection enum entry.
static MediaType getMediaType(javax.sdp.MediaDescription description)
          Returns the media type (e.g.
static javax.sdp.SessionDescription parseSdpString(String sdp)
          Parses the specified sdp String into a SessionDescription and returns it;
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZRTP_HASH_ATTR

public static final String ZRTP_HASH_ATTR
The name of the SDP attribute that defines zrtp hello hash.

See Also:
Constant Field Values
Constructor Detail

SdpUtils

public SdpUtils()
Method Detail

parseSdpString

public static javax.sdp.SessionDescription parseSdpString(String sdp)
                                                   throws IllegalArgumentException
Parses the specified sdp String into a SessionDescription and returns it;

Parameters:
sdp - the sdp String that we'd like to parse.
Returns:
the SessionDescription instance corresponding to the specified sdp String.
Throws:
IllegalArgumentException - in case sdp is not a valid SDP String.

createAttribute

public static javax.sdp.Attribute createAttribute(String name,
                                                  String value)
Creates an Attribute object with the specified values.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
Attribute

createSessionDescription

public static javax.sdp.SessionDescription createSessionDescription(InetAddress localAddress)
                                                             throws OperationFailedException
Creates an empty instance of a SessionDescription with preinitialized s, v, c, o and t parameters.

Parameters:
localAddress - the InetAddress corresponding to the local address that we'd like to use when talking to the remote party.
Returns:
an empty instance of a SessionDescription with preinitialized s, v, and t parameters.
Throws:
OperationFailedException - if the SDP creation failed

createSessionDescription

public static javax.sdp.SessionDescription createSessionDescription(InetAddress localAddress,
                                                                    String userName,
                                                                    Vector<javax.sdp.MediaDescription> mediaDescriptions)
                                                             throws OperationFailedException
Creates an empty instance of a SessionDescription with preinitialized s, v, c, o and t parameters.

Parameters:
localAddress - the InetAddress corresponding to the local address that we'd like to use when talking to the remote party.
userName - the user name to use in the origin parameter or null in case we'd like to use a default.
mediaDescriptions - a Vector containing the list of MediaDescriptions that we'd like to advertise (leave null if you'd like to add these later).
Returns:
an empty instance of a SessionDescription with preinitialized s, v, and t parameters.
Throws:
OperationFailedException - if the SDP creation failed

createSessionUpdateDescription

public static javax.sdp.SessionDescription createSessionUpdateDescription(javax.sdp.SessionDescription descToUpdate,
                                                                          InetAddress newConnectionAddress,
                                                                          Vector<javax.sdp.MediaDescription> newMediaDescriptions)
                                                                   throws OperationFailedException
Creates and returns a new SessionDescription that is supposed to update our previous descToUpdate and advertise the brand new newMediaDescriptions. The method also respects other 3264 policies like reusing the origin field and augmenting its version number for example.

Parameters:
descToUpdate - the SessionDescription that we'd like to update.
newConnectionAddress - the InetAddress that we'd like to use in the new c= field.
newMediaDescriptions - the descriptions of the new streams that we'd like to have in the updated session.
Returns:
a new SessionDescription that updates descToUpdate;
Throws:
OperationFailedException - if the SDP creation failed

extractFormats

public static List<MediaFormat> extractFormats(javax.sdp.MediaDescription mediaDesc,
                                               DynamicPayloadTypeRegistry ptRegistry)
Extracts and returns the list of MediaFormats advertised in mediaDesc preserving their oder and registering dynamic payload type numbers in the specified ptRegistry. Note that this method would only include in the result list MediaFormat instances that are currently supported by our MediaService implementation and enabled in its configuration. This means that the method could return an empty list even if there were actually some formats in the mediaDesc if we support none of them or if all these we support are not enabled in the MediaService configuration form.

Parameters:
mediaDesc - the MediaDescription that we'd like to probe for a list of MediaFormats
ptRegistry - a reference to the DynamycPayloadTypeRegistry where we should be registering newly added payload type number to format mappings.
Returns:
an ordered list of MediaFormats that are both advertised in the mediaDesc description and supported by our MediaService implementation.

extractRTPExtensions

public static List<RTPExtension> extractRTPExtensions(javax.sdp.MediaDescription mediaDesc,
                                                      DynamicRTPExtensionsRegistry extMap)
Extracts and returns the list of RTPExtensions advertised in mediaDesc and registers newly encountered ones into the specified extMap. The method returns an empty list in case there were no extmap advertisements in mediaDesc.

Parameters:
mediaDesc - the MediaDescription that we'd like to probe for a list of RTPExtensions
extMap - a reference to the DynamycRTPExtensionsRegistry where we should be registering newly added extension mappings.
Returns:
a List of RTPExtensions advertised in the mediaDesc description.

extractDefaultTarget

public static MediaStreamTarget extractDefaultTarget(javax.sdp.MediaDescription mediaDesc,
                                                     javax.sdp.SessionDescription sessDesc)
                                              throws IllegalArgumentException
Returns a MediaStreamTarget instance reflecting the address pair (RTP + RTCP) where we should send media in this stream. The method takes into account the possibility to have a connection (i.e. c=) parameter in either the media description (i.e. mediaDesc) or (i.e. sessDesc), or both and handles their priority as defined by the SDP spec [RFC 4566].

Parameters:
mediaDesc - the media description that we'd like to extract our RTP and RTCP destination addresses.
sessDesc - the session description that we received mediaDesc in.
Returns:
a MediaStreamTarget containing the RTP and RTCP destinations that our interlocutor has specified for this media stream.
Throws:
IllegalArgumentException - in case we couldn't find connection data or stumble upon other problems while analyzing the SDP.

getDirection

public static MediaDirection getDirection(javax.sdp.MediaDescription mediaDesc)
Determines the direction of the media stream that mediaDesc describes and returns the corresponding MediaDirection enum entry. The method looks for a direction specifier attribute (e.g. sendrecv, recvonly, etc.) or the absence thereof and returns the corresponding MediaDirection entry.

Parameters:
mediaDesc - the description of the media stream whose direction we are trying to determine.
Returns:
one of the MediaDirection values indicating the direction of the media steam described by mediaDesc.

getCallInfoURL

public static URL getCallInfoURL(javax.sdp.SessionDescription sessDesc)
Returns a URL pointing to a location with more details (and possibly call control utilities) about the session. This corresponds to the "u=" field of the SDP data.

Parameters:
sessDesc - the session description that we'd like to extract an URL form.
Returns:
a URL pointing to a location with more details about the session or null if the remote party did not provide one.

createMediaDescription

public static javax.sdp.MediaDescription createMediaDescription(String transport,
                                                                List<MediaFormat> formats,
                                                                StreamConnector connector,
                                                                MediaDirection direction,
                                                                List<RTPExtension> rtpExtensions,
                                                                DynamicPayloadTypeRegistry dynamicPayloadTypes,
                                                                DynamicRTPExtensionsRegistry rtpExtensionsRegistry)
                                                         throws OperationFailedException
Creates a new MediaDescription instance according to the specified formats, connector and direction, and using the dynamicPayloadTypes registry to handle dynamic payload type registrations. The type (e.g. audio/video) of the media description is determined via from the type of the first MediaFormat in the formats list.

Parameters:
transport - the profile name (RTP/SAVP or RTP/AVP)
formats - the list of formats that should be advertised in the newly created MediaDescription.
connector - the socket couple that will be used for the media stream which we are advertising with the media description created here.
direction - the direction of the media stream that we are describing here.
rtpExtensions - a list of RTPExtensions supported by the MediaDevice that we will be advertising.
dynamicPayloadTypes - a reference to the DynamicPayloadTypeRegistry that we should be using to lookup and register dynamic RTP mappings.
rtpExtensionsRegistry - a reference to the DynamicRTPExtensionRegistry that we should be using to lookup and register URN to ID mappings.
Returns:
the newly create SDP MediaDescription.
Throws:
OperationFailedException - in case we fail to get payload type numbers for dynamic payload types or in case our SDP generation fails for some other reason.

getMediaType

public static MediaType getMediaType(javax.sdp.MediaDescription description)
                              throws IllegalArgumentException
Returns the media type (e.g. audio or video) for the specified media description.

Parameters:
description - the MediaDescription whose media type we'd like to extract.
Returns:
the media type (e.g. audio or video) for the specified media description.
Throws:
IllegalArgumentException - if description does not contain a known media type.

containsAttribute

public static boolean containsAttribute(javax.sdp.MediaDescription description,
                                        String attributeName)
                                 throws IllegalArgumentException
Returns the media type (e.g. audio or video) for the specified media whether it contains the specified attributeName.

Parameters:
description - the MediaDescription whose media type we'd like to extract.
attributeName - name of the attribute to check
Returns:
the media type (e.g. audio or video) for the specified media description.
Throws:
IllegalArgumentException - if description does not contain a known media type.

createDisablingAnswer

public static javax.sdp.MediaDescription createDisablingAnswer(javax.sdp.MediaDescription offer)
                                                        throws IllegalArgumentException
Creates and returns a MediaDescription in answer of the specified offer that disables the corresponding stream by setting a 0 port and keeping the original list of formats and eliminating all attributes.

Parameters:
offer - the MediaDescription of the stream that we'd like to disable.
Returns:
a MediaDescription meant to disable the media stream specified by the offer description.
Throws:
IllegalArgumentException - if the offer argument is so in-parsable that there was no way we could create a meaningful answer.

extractMediaDescriptions

public static Vector<javax.sdp.MediaDescription> extractMediaDescriptions(javax.sdp.SessionDescription sessionDescription)
                                                                   throws IllegalArgumentException
Extracts and returns all MediaDescriptions provided in sessionDescription.

Parameters:
sessionDescription - the SessionDescription that we'd like to extract MediaDescriptions from.
Returns:
a non null Vector containing all media descriptions from the sessionDescription.
Throws:
IllegalArgumentException - in case there were no media descriptions in sessionDescription.

getContentAsString

public static String getContentAsString(javax.sip.message.Message message)
Gets the content of the specified SIP Message in the form of a String value.

Parameters:
message - the SIP Message to get the content of
Returns:
a String value which represents the content of the specified SIP Message

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.