src/net/java/sip/communicator/impl/protocol/sip/CallPeerMediaHandlerSipImpl.java
/**
     * Creates a <tt>Vector</tt> containing the <tt>MediaDescription</tt>s of
     * streams that this handler is prepared to initiate depending on available
     * <tt>MediaDevice</tt>s and local on-hold and video transmission
     * preferences.
     *
     * @return a <tt>Vector</tt> containing the <tt>MediaDescription</tt>s of
     * streams that this handler is prepared to initiate.
     *
     * @throws OperationFailedException if we fail to create the descriptions
     * for reasons like - problems with device interaction, allocating ports,
     * etc.
     */
Creates a Vector containing the MediaDescriptions of
streams that this handler is prepared to initiate depending on available
MediaDevices and local on-hold and video transmission
preferences.

@return a Vector containing the MediaDescriptions of
streams that this handler is prepared to initiate.

@throws OperationFailedException if we fail to create the descriptions
for reasons like - problems with device interaction, allocating ports,
etc.
Creates a Vector containing the MediaDescriptions of streams that this handler is prepared to initiate depending on available MediaDevices and local on - hold and video transmission preferences . @return a Vector containing the MediaDescriptions of streams that this handler is prepared to initiate . @throws OperationFailedException if we fail to create the descriptions for reasons like - problems with device interaction allocating ports etc .
private List<MediaDescription> createMediaDescriptions()
        throws OperationFailedException
    {
        Vector<MediaDescription> mediaDescs = new Vector<MediaDescription>();
        QualityPreset sendQualityPreset = null;
        QualityPreset receiveQualityPreset = null;
        if(qualityControls != null)
        {
            sendQualityPreset = qualityControls.getRemoteReceivePreset();
            receiveQualityPreset = qualityControls.getRemoteSendMaxPreset();
        }
        for (MediaType mediaType : new MediaType[] { MediaType.AUDIO , MediaType.VIDEO})
        {
            MediaDevice dev = getDefaultDevice(mediaType);
            if (!isDeviceActive(dev, sendQualityPreset, receiveQualityPreset))
            {
                logger.warn("No active device for "  + mediaType.toString()
                + " was found!");
                continue;
            }
            MediaDirection direction
                = dev.getDirection().and(getDirectionUserPreference(mediaType));
            if(isLocallyOnHold())
                direction = direction.and(MediaDirection.SENDONLY);
            if(direction != MediaDirection.INACTIVE)
            {
                for (String proto : getRtpTransports())
                {
                    /*
                     * If we start an audio-only call and re-INVITE the remote
                     * peer for desktop sharing/streaming later on, we will have
                     * effectively switched from the webcam to the
                     * display/screen. It seems beneficial in such a scenario to
                     * not have a send quality preset unless we actually intend
                     * to send video.
                     */
                    QualityPreset effectiveSendQualityPreset
                        = direction.allowsSending() ? sendQualityPreset : null;
                    MediaDescription md
                        = createMediaDescription(
                                proto,
                                getLocallySupportedFormats(
                                        dev,
                                        effectiveSendQualityPreset,
                                        receiveQualityPreset),
                                getTransportManager().getStreamConnector(
                                        mediaType),
                                direction,
                                dev.getSupportedExtensions());
                    try
                    {
                        switch (mediaType)
                        {
                        case AUDIO:
                            /*
                             * Let the remote peer know that we support RTCP XR
                             * in general and VoIP Metrics Report Block in
                             * particular.
                             */
                            String rtcpxr
                                = md.getAttribute(
                                        RTCPExtendedReport.SDP_ATTRIBUTE);
                            if (rtcpxr == null)
                            {
                                md.setAttribute(
                                        RTCPExtendedReport.SDP_ATTRIBUTE,
                                        RTCPExtendedReport
                                            .VoIPMetricsReportBlock
                                                .SDP_PARAMETER);
                            }
                            int ptimeSetting
                                = SipActivator.getConfigurationService().getInt(
                                    "net.java.sip.communicator.impl.protocol" +
                                        ".sip.PTIME_VALUE",
                                    20);
                            if(ptimeSetting != 20)
                            {
                                md.setAttribute(
                                    "ptime",
                                    String.valueOf(ptimeSetting));
                            }
                            break;
                        case VIDEO:
                            if (receiveQualityPreset != null)
                            {
                                int frameRate
                                    = (int) receiveQualityPreset.getFameRate();
                                if (frameRate > 0)
                                {
                                    md.setAttribute(
                                            "framerate",
                                            String.valueOf(frameRate));
                                }
                            }
                            break;
                        default:
                            break;
                        }
                    }
                    catch(SdpException e)
                    {
                    }
                    if (DtlsControl.UDP_TLS_RTP_SAVP.equals(proto)
                            || DtlsControl.UDP_TLS_RTP_SAVPF.equals(proto))
                    {
                        /*
                         * RFC 5764 "Datagram Transport Layer Security (DTLS)
                         * Extension to Establish Keys for the Secure Real-time
                         * Transport Protocol (SRTP)"
                         */
                        updateMediaDescriptionForDtls(mediaType, md, null);
                    }
                    else
                    {
                        /*
                         * According to RFC 6189 "ZRTP: Media Path Key Agreement
                         * for Unicast Secure RTP", "ZRTP utilizes normal
                         * RTP/AVP (Audio-Visual Profile) profiles", "[t]he
                         * Secure RTP/AVP (SAVP) profile MAY be used in
                         * subsequent offer/answer exchanges after a successful
                         * ZRTP exchange has resulted in an SRTP session, or if
                         * it is known that the other endpoint supports this
                         * profile" and "[o]ther profiles MAY also be used."
                         */
                        updateMediaDescriptionForZrtp(mediaType, md);
                        if (SrtpControl.RTP_SAVP.equals(proto)
                                || SrtpControl.RTP_SAVPF.equals(proto))
                        {
                            /*
                             * According to Ingo Bauersachs, SDES "[b]asically
                             * requires SAVP per RFC."
                             */
                            updateMediaDescriptionForSDes(mediaType, md, null);
                        }
                        if (SrtpControl.RTP_SAVPF.equals(proto))
                        {
                            /*
                             * draft-ietf-rtcweb-rtp-usage-09 "Web Real-Time
                             * Communication (WebRTC): Media Transport and Use
                             * of RTP"
                             */
                            updateMediaDescriptionForDtls(mediaType, md, null);
                        }
                    }
                    mediaDescs.add(md);
                }
            }
        }
        if(mediaDescs.isEmpty())
        {
            ProtocolProviderServiceSipImpl.throwOperationFailedException(
                    "We couldn't find any active Audio/Video devices and "
                        + "couldn't create a call",
                    OperationFailedException.GENERAL_ERROR,
                    null,
                    logger);
        }
        return mediaDescs;
    }
private List < MediaDescription > createMediaDescriptions ( ) throws OperationFailedException { Vector < MediaDescription > mediaDescs = new Vector < MediaDescription > ( ) ; QualityPreset sendQualityPreset = null ; QualityPreset receiveQualityPreset = null ; if ( qualityControls != null ) { sendQualityPreset = qualityControls . getRemoteReceivePreset ( ) ; receiveQualityPreset = qualityControls . getRemoteSendMaxPreset ( ) ; } for ( MediaType mediaType : new MediaType [ ] { MediaType . AUDIO , MediaType . VIDEO } ) { MediaDevice dev = getDefaultDevice ( mediaType ) ; if ( ! isDeviceActive ( dev , sendQualityPreset , receiveQualityPreset ) ) { logger . warn ( "No active device for " + mediaType . toString ( ) + " was found!" ) ; continue ; } MediaDirection direction = dev . getDirection ( ) . and ( getDirectionUserPreference ( mediaType ) ) ; if ( isLocallyOnHold ( ) ) direction = direction . and ( MediaDirection . SENDONLY ) ; if ( direction != MediaDirection . INACTIVE ) { for ( String proto : getRtpTransports ( ) ) { /*
                     * If we start an audio-only call and re-INVITE the remote
                     * peer for desktop sharing/streaming later on, we will have
                     * effectively switched from the webcam to the
                     * display/screen. It seems beneficial in such a scenario to
                     * not have a send quality preset unless we actually intend
                     * to send video.
                     */ QualityPreset effectiveSendQualityPreset = direction . allowsSending ( ) ? sendQualityPreset : null ; MediaDescription md = createMediaDescription ( proto , getLocallySupportedFormats ( dev , effectiveSendQualityPreset , receiveQualityPreset ) , getTransportManager ( ) . getStreamConnector ( mediaType ) , direction , dev . getSupportedExtensions ( ) ) ; try { switch ( mediaType ) { case AUDIO : /*
                             * Let the remote peer know that we support RTCP XR
                             * in general and VoIP Metrics Report Block in
                             * particular.
                             */ String rtcpxr = md . getAttribute ( RTCPExtendedReport . SDP_ATTRIBUTE ) ; if ( rtcpxr == null ) { md . setAttribute ( RTCPExtendedReport . SDP_ATTRIBUTE , RTCPExtendedReport . VoIPMetricsReportBlock . SDP_PARAMETER ) ; } int ptimeSetting = SipActivator . getConfigurationService ( ) . getInt ( "net.java.sip.communicator.impl.protocol" + ".sip.PTIME_VALUE" , 20 ) ; if ( ptimeSetting != 20 ) { md . setAttribute ( "ptime" , String . valueOf ( ptimeSetting ) ) ; } break ; case VIDEO : if ( receiveQualityPreset != null ) { int frameRate = ( int ) receiveQualityPreset . getFameRate ( ) ; if ( frameRate > 0 ) { md . setAttribute ( "framerate" , String . valueOf ( frameRate ) ) ; } } break ; default : break ; } } catch ( SdpException e ) { } if ( DtlsControl . UDP_TLS_RTP_SAVP . equals ( proto ) || DtlsControl . UDP_TLS_RTP_SAVPF . equals ( proto ) ) { /*
                         * RFC 5764 "Datagram Transport Layer Security (DTLS)
                         * Extension to Establish Keys for the Secure Real-time
                         * Transport Protocol (SRTP)"
                         */ updateMediaDescriptionForDtls ( mediaType , md , null ) ; } else { /*
                         * According to RFC 6189 "ZRTP: Media Path Key Agreement
                         * for Unicast Secure RTP", "ZRTP utilizes normal
                         * RTP/AVP (Audio-Visual Profile) profiles", "[t]he
                         * Secure RTP/AVP (SAVP) profile MAY be used in
                         * subsequent offer/answer exchanges after a successful
                         * ZRTP exchange has resulted in an SRTP session, or if
                         * it is known that the other endpoint supports this
                         * profile" and "[o]ther profiles MAY also be used."
                         */ updateMediaDescriptionForZrtp ( mediaType , md ) ; if ( SrtpControl . RTP_SAVP . equals ( proto ) || SrtpControl . RTP_SAVPF . equals ( proto ) ) { /*
                             * According to Ingo Bauersachs, SDES "[b]asically
                             * requires SAVP per RFC."
                             */ updateMediaDescriptionForSDes ( mediaType , md , null ) ; } if ( SrtpControl . RTP_SAVPF . equals ( proto ) ) { /*
                             * draft-ietf-rtcweb-rtp-usage-09 "Web Real-Time
                             * Communication (WebRTC): Media Transport and Use
                             * of RTP"
                             */ updateMediaDescriptionForDtls ( mediaType , md , null ) ; } } mediaDescs . add ( md ) ; } } } if ( mediaDescs . isEmpty ( ) ) { ProtocolProviderServiceSipImpl . throwOperationFailedException ( "We couldn't find any active Audio/Video devices and " + "couldn't create a call" , OperationFailedException . GENERAL_ERROR , null , logger ) ; } return mediaDescs ; }
Creates a <tt>Vector</tt> containing the <tt>MediaDescription</tt>s of
 streams that this handler is prepared to initiate depending on available
 <tt>MediaDevice</tt>s and local on-hold and video transmission
 preferences.
Creates a <tt > Vector< / tt > containing the <tt > MediaDescription< / tt > s of streams that this handler is prepared to initiate depending on available <tt > MediaDevice< / tt > s and local on - hold and video transmission preferences .
//Audio Media Description // the one we will send is the one the other part has announced as // receive // the one we want to receive is the setting that remote can send // the default value is 20ms // If we have a video preset, let's send info about // the desired frame rate. // doing only int frame rate for now // do nothing in case of error. //fail if all devices were inactive