src/net/java/sip/communicator/impl/protocol/jabber/CallPeerMediaHandlerJabberImpl.java
/**
     * Process a <tt>ContentPacketExtension</tt> and initialize its
     * corresponding <tt>MediaStream</tt>.
     *
     * @param content a <tt>ContentPacketExtension</tt>
     * @param modify if it correspond to a content-modify for resolution change
     * @param masterStream whether the stream to be used as master
     * @throws OperationFailedException if we fail to handle <tt>content</tt>
     * for reasons like failing to initialize media devices or streams.
     * @throws IllegalArgumentException if there's a problem with the syntax or
     * the semantics of <tt>content</tt>. The method is synchronized in order to
     * avoid closing mediaHandler when we are currently in process of
     * initializing, configuring and starting streams and anybody interested
     * in this operation can synchronize to the mediaHandler instance to wait
     * processing to stop (method setState in CallPeer).
     */
Process a ContentPacketExtension and initialize its
corresponding MediaStream.

@param content a ContentPacketExtension
@param modify if it correspond to a content-modify for resolution change
@param masterStream whether the stream to be used as master
@throws OperationFailedException if we fail to handle content
for reasons like failing to initialize media devices or streams.
@throws IllegalArgumentException if there's a problem with the syntax or
the semantics of content. The method is synchronized in order to
avoid closing mediaHandler when we are currently in process of
initializing, configuring and starting streams and anybody interested
in this operation can synchronize to the mediaHandler instance to wait
processing to stop (method setState in CallPeer).
Process a ContentPacketExtension and initialize its corresponding MediaStream . @param content a ContentPacketExtension @param modify if it correspond to a content - modify for resolution change @param masterStream whether the stream to be used as master @throws OperationFailedException if we fail to handle content for reasons like failing to initialize media devices or streams . @throws IllegalArgumentException if there ' s a problem with the syntax or the semantics of content . The method is synchronized in order to avoid closing mediaHandler when we are currently in process of initializing configuring and starting streams and anybody interested in this operation can synchronize to the mediaHandler instance to wait processing to stop ( method setState in CallPeer ) .
private void processContent(
            ContentPacketExtension content,
            boolean modify,
            boolean masterStream)
        throws OperationFailedException,
               IllegalArgumentException
    {
        RtpDescriptionPacketExtension description
            = JingleUtils.getRtpDescription(content);
        MediaType mediaType = JingleUtils.getMediaType(content);
        TransportManagerJabberImpl transportManager = getTransportManager();
        MediaStreamTarget target = transportManager.getStreamTarget(mediaType);
        if (target == null)
            target = JingleUtils.extractDefaultTarget(content);
        if((target == null) || (target.getDataAddress().getPort() == 0))
        {
            closeStream(mediaType);
            return;
        }
        List<MediaFormat> supportedFormats = JingleUtils.extractFormats(
            description, getDynamicPayloadTypes());
        MediaDevice dev = getDefaultDevice(mediaType);
        if(!isDeviceActive(dev))
        {
            closeStream(mediaType);
            return;
        }
        MediaDirection devDirection
            = (dev == null) ? MediaDirection.INACTIVE : dev.getDirection();
        devDirection
            = devDirection.and(getDirectionUserPreference(mediaType));
        if (supportedFormats.isEmpty())
        {
            ProtocolProviderServiceJabberImpl.throwOperationFailedException(
                    "Remote party sent an invalid Jingle answer.",
                    OperationFailedException.ILLEGAL_ARGUMENT,
                    null,
                    logger);
        }
        CallJabberImpl call = getPeer().getCall();
        CallConference conference
            = (call == null) ? null : call.getConference();
        /*
         * Neither SDES nor ZRTP is supported in telephony conferences utilizing
         * the server-side technology Jitsi Videobridge yet.
         */
        if ((conference == null) || !conference.isJitsiVideobridge())
        {
            addZrtpAdvertisedEncryptions(true, description, mediaType);
            addSDesAdvertisedEncryptions(true, description, mediaType);
        }
        addDtlsAdvertisedEncryptions(true, content, mediaType, false);
        StreamConnector connector
            = transportManager.getStreamConnector(mediaType);
        MediaDirection remoteDirection
            = JingleUtils.getDirection(content, getPeer().isInitiator());
        /*
         * If we are the focus of a conference, we need to take into account the
         * other participants.
         */
        if ((conference != null) && conference.isConferenceFocus())
        {
            for (CallPeerJabberImpl peer : call.getCallPeerList())
            {
                SendersEnum senders = peer.getSenders(mediaType);
                boolean initiator = peer.isInitiator();
                if ((senders == null)
                        || (SendersEnum.both == senders)
                        || (initiator && SendersEnum.initiator == senders)
                        || (!initiator && SendersEnum.responder == senders))
                {
                    remoteDirection
                        = remoteDirection.or(MediaDirection.SENDONLY);
                }
            }
        }
        MediaDirection direction
            = devDirection.getDirectionForAnswer(remoteDirection);
        List<RTPExtension> remoteRTPExtensions
            = JingleUtils.extractRTPExtensions(
                    description,
                    getRtpExtensionsRegistry());
        List<RTPExtension> supportedExtensions
            = getExtensionsForType(mediaType);
        List<RTPExtension> rtpExtensions
            = intersectRTPExtensions(remoteRTPExtensions, supportedExtensions);
        Map<String, String> adv
            = supportedFormats.get(0).getAdvancedAttributes();
        if(adv != null)
        {
            for(Map.Entry<String, String> f : adv.entrySet())
            {
                if(f.getKey().equals("imageattr"))
                    supportQualityControls = true;
            }
        }
        if(mediaType.equals(MediaType.VIDEO) && modify)
        {
            MediaStream stream = getStream(MediaType.VIDEO);
            if(stream != null && dev != null)
            {
                List<MediaFormat> fmts = supportedFormats;
                if(!fmts.isEmpty())
                {
                    MediaFormat fmt = fmts.get(0);
                    ((VideoMediaStream)stream).updateQualityControl(
                            fmt.getAdvancedAttributes());
                }
            }
            if(qualityControls != null)
            {
                QualityPreset receiveQualityPreset
                    = qualityControls.getRemoteReceivePreset();
                QualityPreset sendQualityPreset
                    = qualityControls.getRemoteSendMaxPreset();
                supportedFormats
                    = (dev == null)
                        ? null
                        : intersectFormats(
                                supportedFormats,
                                getLocallySupportedFormats(
                                        dev,
                                        sendQualityPreset,
                                        receiveQualityPreset));
            }
        }
        initStream(
                content.getName(),
                connector,
                dev,
                supportedFormats.get(0),
                target,
                direction,
                rtpExtensions,
                masterStream);
    }
private void processContent ( ContentPacketExtension content , boolean modify , boolean masterStream ) throws OperationFailedException , IllegalArgumentException { RtpDescriptionPacketExtension description = JingleUtils . getRtpDescription ( content ) ; MediaType mediaType = JingleUtils . getMediaType ( content ) ; TransportManagerJabberImpl transportManager = getTransportManager ( ) ; MediaStreamTarget target = transportManager . getStreamTarget ( mediaType ) ; if ( target == null ) target = JingleUtils . extractDefaultTarget ( content ) ; if ( ( target == null ) || ( target . getDataAddress ( ) . getPort ( ) == 0 ) ) { closeStream ( mediaType ) ; return ; } List < MediaFormat > supportedFormats = JingleUtils . extractFormats ( description , getDynamicPayloadTypes ( ) ) ; MediaDevice dev = getDefaultDevice ( mediaType ) ; if ( ! isDeviceActive ( dev ) ) { closeStream ( mediaType ) ; return ; } MediaDirection devDirection = ( dev == null ) ? MediaDirection . INACTIVE : dev . getDirection ( ) ; devDirection = devDirection . and ( getDirectionUserPreference ( mediaType ) ) ; if ( supportedFormats . isEmpty ( ) ) { ProtocolProviderServiceJabberImpl . throwOperationFailedException ( "Remote party sent an invalid Jingle answer." , OperationFailedException . ILLEGAL_ARGUMENT , null , logger ) ; } CallJabberImpl call = getPeer ( ) . getCall ( ) ; CallConference conference = ( call == null ) ? null : call . getConference ( ) ; /*
         * Neither SDES nor ZRTP is supported in telephony conferences utilizing
         * the server-side technology Jitsi Videobridge yet.
         */ if ( ( conference == null ) || ! conference . isJitsiVideobridge ( ) ) { addZrtpAdvertisedEncryptions ( true , description , mediaType ) ; addSDesAdvertisedEncryptions ( true , description , mediaType ) ; } addDtlsAdvertisedEncryptions ( true , content , mediaType , false ) ; StreamConnector connector = transportManager . getStreamConnector ( mediaType ) ; MediaDirection remoteDirection = JingleUtils . getDirection ( content , getPeer ( ) . isInitiator ( ) ) ; /*
         * If we are the focus of a conference, we need to take into account the
         * other participants.
         */ if ( ( conference != null ) && conference . isConferenceFocus ( ) ) { for ( CallPeerJabberImpl peer : call . getCallPeerList ( ) ) { SendersEnum senders = peer . getSenders ( mediaType ) ; boolean initiator = peer . isInitiator ( ) ; if ( ( senders == null ) || ( SendersEnum . both == senders ) || ( initiator && SendersEnum . initiator == senders ) || ( ! initiator && SendersEnum . responder == senders ) ) { remoteDirection = remoteDirection . or ( MediaDirection . SENDONLY ) ; } } } MediaDirection direction = devDirection . getDirectionForAnswer ( remoteDirection ) ; List < RTPExtension > remoteRTPExtensions = JingleUtils . extractRTPExtensions ( description , getRtpExtensionsRegistry ( ) ) ; List < RTPExtension > supportedExtensions = getExtensionsForType ( mediaType ) ; List < RTPExtension > rtpExtensions = intersectRTPExtensions ( remoteRTPExtensions , supportedExtensions ) ; Map < String , String > adv = supportedFormats . get ( 0 ) . getAdvancedAttributes ( ) ; if ( adv != null ) { for ( Map . Entry < String , String > f : adv . entrySet ( ) ) { if ( f . getKey ( ) . equals ( "imageattr" ) ) supportQualityControls = true ; } } if ( mediaType . equals ( MediaType . VIDEO ) && modify ) { MediaStream stream = getStream ( MediaType . VIDEO ) ; if ( stream != null && dev != null ) { List < MediaFormat > fmts = supportedFormats ; if ( ! fmts . isEmpty ( ) ) { MediaFormat fmt = fmts . get ( 0 ) ; ( ( VideoMediaStream ) stream ) . updateQualityControl ( fmt . getAdvancedAttributes ( ) ) ; } } if ( qualityControls != null ) { QualityPreset receiveQualityPreset = qualityControls . getRemoteReceivePreset ( ) ; QualityPreset sendQualityPreset = qualityControls . getRemoteSendMaxPreset ( ) ; supportedFormats = ( dev == null ) ? null : intersectFormats ( supportedFormats , getLocallySupportedFormats ( dev , sendQualityPreset , receiveQualityPreset ) ) ; } } initStream ( content . getName ( ) , connector , dev , supportedFormats . get ( 0 ) , target , direction , rtpExtensions , masterStream ) ; }
Process a <tt>ContentPacketExtension</tt> and initialize its
 corresponding <tt>MediaStream</tt>.
Process a <tt > ContentPacketExtension< / tt > and initialize its corresponding <tt > MediaStream< / tt > .
//stream target // no target port - try next media description // Take the preference of the user with respect to streaming // mediaType into account. //remote party must have messed up our Jingle description. //throw an exception. //determine the direction that we need to announce. //check if the direction of the jingle session we have with //this peer allows us receiving media. If senders is null, //assume the default of 'both' // update the RTP extensions that we will be exchanging. // check for options from remote party and set them locally // update stream // create the corresponding stream...