Search in sources :

Example 1 with MediaDescriptor

use of org.zoolu.sdp.MediaDescriptor in project bigbluebutton by bigbluebutton.

the class SdpUtils method completeSdpNegotiation.

/**
     * Parameter "newSdp" must be the returning value from method's 
     * "makeMediaPayloadsNegotiation" execution.
     * Here the pending attributes will be negotiated as well.
     * 
     * @param newSdp
     * @param localSdp
     * @param remoteSdp
     * 
     */
public static void completeSdpNegotiation(SessionDescriptor newSdp, SessionDescriptor localSdp, SessionDescriptor remoteSdp) {
    try {
        if (newSdp.getMediaDescriptors().size() == 0) {
            // Something is wrong.
            // We should have at least a "audio" media descriptor with 
            // all audio payloads suported.
            log.error("No media descriptors after \"makeMediaPayloadsNegotiation\".");
            return;
        }
        Vector remoteDescriptors = remoteSdp.getMediaDescriptors();
        for (Enumeration descriptorsEnum = remoteDescriptors.elements(); descriptorsEnum.hasMoreElements(); ) {
            MediaDescriptor remoteDescriptor = (MediaDescriptor) descriptorsEnum.nextElement();
            MediaDescriptor localDescriptor = localSdp.getMediaDescriptor(remoteDescriptor.getMedia().getMedia());
            if (localDescriptor != null) {
                // First we make the negotiation of remote attributes with 
                // local ones to generate the new SDP "newSdp".
                Vector remoteAttributes = remoteDescriptor.getAttributes();
                for (Enumeration atributesEnum = remoteAttributes.elements(); atributesEnum.hasMoreElements(); ) {
                    AttributeField remoteAttribute = (AttributeField) atributesEnum.nextElement();
                    makeAttributeNegotiation(newSdp, localDescriptor, remoteAttribute);
                }
                // Now we add to "newSdp" all the local attributes that 
                // were not negotiated yet.
                Vector localAttributes = localDescriptor.getAttributes();
                for (Enumeration atributesEnum = localAttributes.elements(); atributesEnum.hasMoreElements(); ) {
                    AttributeField localAttribute = (AttributeField) atributesEnum.nextElement();
                    MediaDescriptor newLocalDescriptor = newSdp.getMediaDescriptor(localDescriptor.getMedia().getMedia());
                    if (isPayloadRelatedAttribute(localAttribute)) {
                        String payloadId = getPayloadIdFromAttribute(localAttribute);
                        if (findAttributeByPayloadId(localAttribute.getAttributeName(), payloadId, newLocalDescriptor) == null) {
                            newLocalDescriptor.addAttribute(localAttribute);
                        }
                    } else if (newLocalDescriptor.getAttribute(localAttribute.getAttributeName()) == null) {
                        newLocalDescriptor.addAttribute(localAttribute);
                    }
                }
            }
        }
    } catch (Exception exception) {
        log.error("Failure creating initial SDP: " + exception.toString());
    }
}
Also used : Enumeration(java.util.Enumeration) AttributeField(org.zoolu.sdp.AttributeField) MediaDescriptor(org.zoolu.sdp.MediaDescriptor) Vector(java.util.Vector)

Example 2 with MediaDescriptor

use of org.zoolu.sdp.MediaDescriptor in project bigbluebutton by bigbluebutton.

the class SdpUtils method getNegotiatedAudioCodec.

/**
     * @return Returns the audio codec to be used on current session.
     */
public static Codec getNegotiatedAudioCodec(SessionDescriptor negotiatedSDP) {
    int payloadId;
    String rtpmap;
    Codec sipCodec = null;
    MediaDescriptor md = negotiatedSDP.getMediaDescriptor(Codec.MEDIA_TYPE_AUDIO);
    rtpmap = md.getAttribute(Codec.ATTRIBUTE_RTPMAP).getAttributeValue();
    if (!rtpmap.isEmpty()) {
        payloadId = Integer.parseInt(rtpmap.substring(0, rtpmap.indexOf(" ")));
        sipCodec = CodecFactory.getInstance().getSIPAudioCodec(payloadId);
        if (sipCodec == null) {
            log.error("Negotiated codec {} not found", payloadId);
        } else {
            log.info("Found codec: payloadType={}, payloadName={}.", sipCodec.getCodecId(), sipCodec.getCodecName());
        }
    }
    return sipCodec;
}
Also used : Codec(org.red5.app.sip.codecs.Codec) MediaDescriptor(org.zoolu.sdp.MediaDescriptor)

Example 3 with MediaDescriptor

use of org.zoolu.sdp.MediaDescriptor in project bigbluebutton by bigbluebutton.

the class SdpUtils method makeAttributeNegotiation.

/**
     * Here we make the negotiation of all attributes besides "rtpmap" (
     * these are negotiated on "makeMediaPayloadsNegotiation" method).
     * 
     * @param newSdp
     * @param localMedia
     * @param remoteAttribute
     */
private static void makeAttributeNegotiation(SessionDescriptor newSdp, MediaDescriptor localMedia, AttributeField remoteAttribute) {
    try {
        if (remoteAttribute.getAttributeName().equals(Codec.ATTRIBUTE_RTPMAP)) {
            log.info("\"rtpmap\" attributes were already negotiated.");
        } else if (!isPayloadRelatedAttribute(remoteAttribute)) {
            // We do nothing with attributes that are not payload 
            // related, like: "ptime", "direction", etc.
            // For now, we consider that they don't demand negotiation.                
            log.info("Attribute is not payload related. Do not negotiate it...");
        } else {
            String payloadId = getPayloadIdFromAttribute(remoteAttribute);
            if ("".equals(payloadId)) {
                log.error("Payload id not found on attribute: Name = [" + remoteAttribute.getAttributeName() + "], Value = [" + remoteAttribute.getAttributeValue() + "].");
            } else if (findAttributeByPayloadId(Codec.ATTRIBUTE_RTPMAP, payloadId, newSdp.getMediaDescriptor(localMedia.getMedia().getMedia())) != null) {
                // We must be sure this attribute is related with a payload 
                // already present on newSdp.                    
                //                    log.debug("Payload " + payloadId + " present on newSdp.");
                AttributeField localAttribute = findAttributeByPayloadId(remoteAttribute.getAttributeName(), payloadId, localMedia);
                Codec sipCodec = CodecFactory.getInstance().getSIPAudioCodec(Integer.valueOf(payloadId));
                if (sipCodec != null) {
                    String localAttibuteValue = "";
                    if (localAttribute != null) {
                        localAttibuteValue = localAttribute.getAttributeValue();
                    } else {
                        log.info("Attribute not found on local media.");
                    }
                    String attributeValueResult = sipCodec.codecNegotiateAttribute(remoteAttribute.getAttributeName(), localAttibuteValue, remoteAttribute.getAttributeValue());
                    if ((attributeValueResult != null) && (!"".equals(attributeValueResult))) {
                        AttributeField af = new AttributeField(remoteAttribute.getAttributeName(), attributeValueResult);
                        MediaDescriptor md = newSdp.getMediaDescriptor(localMedia.getMedia().getMedia());
                        md.addAttribute(af);
                    }
                } else {
                    log.warn("Codec not found!");
                }
            }
        }
    } catch (Exception exception) {
        log.error("Failure creating initial SDP: " + exception.toString());
    }
}
Also used : Codec(org.red5.app.sip.codecs.Codec) AttributeField(org.zoolu.sdp.AttributeField) MediaDescriptor(org.zoolu.sdp.MediaDescriptor)

Example 4 with MediaDescriptor

use of org.zoolu.sdp.MediaDescriptor in project bigbluebutton by bigbluebutton.

the class SdpUtils method getNegotiatedAudioCodec.

/**
     * @return Returns the audio codec to be used on current session.
     */
public static Codec getNegotiatedAudioCodec(SessionDescriptor negotiatedSDP) {
    int payloadId;
    String rtpmap;
    Codec sipCodec = null;
    MediaDescriptor md = negotiatedSDP.getMediaDescriptor(Codec.MEDIA_TYPE_AUDIO);
    rtpmap = md.getAttribute(Codec.ATTRIBUTE_RTPMAP).getAttributeValue();
    if (!rtpmap.isEmpty()) {
        payloadId = Integer.parseInt(rtpmap.substring(0, rtpmap.indexOf(" ")));
        sipCodec = CodecFactory.getInstance().getSIPAudioCodec(payloadId);
        if (sipCodec == null) {
            log.error("Negotiated codec {} not found", payloadId);
        } else {
            log.info("Found codec: payloadType={}, payloadName={}.", sipCodec.getCodecId(), sipCodec.getCodecName());
        }
    }
    return sipCodec;
}
Also used : Codec(org.red5.app.sip.codecs.Codec) MediaDescriptor(org.zoolu.sdp.MediaDescriptor)

Example 5 with MediaDescriptor

use of org.zoolu.sdp.MediaDescriptor in project bigbluebutton by bigbluebutton.

the class SdpUtils method makeMediaPayloadsNegotiation.

/** 
     * We must validate the existence of all remote "rtpmap" attributes 
     * on local SDP.
     * If some exist, we add it to newSdp negotiated SDP result.
     * 
     * @param localSdp
     * @param remoteSdp
     * 
     * @return Returns the new local descriptor as a result of media 
     *         payloads negotiation.
     */
public static SessionDescriptor makeMediaPayloadsNegotiation(SessionDescriptor localSdp, SessionDescriptor remoteSdp) {
    log.debug("makeMediaPayloadsNegotiation");
    SessionDescriptor newSdp = null;
    try {
        newSdp = new SessionDescriptor(remoteSdp.getOrigin(), remoteSdp.getSessionName(), localSdp.getConnection(), localSdp.getTime());
        Vector remoteDescriptors = remoteSdp.getMediaDescriptors();
        for (Enumeration descriptorsEnum = remoteDescriptors.elements(); descriptorsEnum.hasMoreElements(); ) {
            MediaDescriptor remoteDescriptor = (MediaDescriptor) descriptorsEnum.nextElement();
            MediaDescriptor localDescriptor = localSdp.getMediaDescriptor(remoteDescriptor.getMedia().getMedia());
            if (localDescriptor != null) {
                Vector remoteAttributes = remoteDescriptor.getAttributes(Codec.ATTRIBUTE_RTPMAP);
                Vector newSdpAttributes = new Vector();
                for (Enumeration attributesEnum = remoteAttributes.elements(); attributesEnum.hasMoreElements(); ) {
                    AttributeField remoteAttribute = (AttributeField) attributesEnum.nextElement();
                    String payloadId = getPayloadIdFromAttribute(remoteAttribute);
                    if ("".equals(payloadId)) {
                        log.error("Payload id not found on attribute: Name = [" + remoteAttribute.getAttributeName() + "], Value = [" + remoteAttribute.getAttributeValue() + "].");
                    } else if (findAttributeByPayloadId(remoteAttribute.getAttributeName(), payloadId, localDescriptor) != null) {
                        newSdpAttributes.add(remoteAttribute);
                    }
                }
                // Calculate the format list to be used on MediaDescriptor creation.
                String formatList = getFormatList(newSdpAttributes);
                for (Enumeration attributesEnum = newSdpAttributes.elements(); attributesEnum.hasMoreElements(); ) {
                    AttributeField mediaAttribute = (AttributeField) attributesEnum.nextElement();
                    if (newSdp.getMediaDescriptors().size() == 0) {
                        MediaField mf = new MediaField(localDescriptor.getMedia().getMedia(), localDescriptor.getMedia().getPort(), 0, localDescriptor.getMedia().getTransport(), formatList);
                        newSdp.addMediaDescriptor(new MediaDescriptor(mf, localDescriptor.getConnection()));
                    }
                    newSdp.getMediaDescriptor(localDescriptor.getMedia().getMedia()).addAttribute(mediaAttribute);
                }
            }
        }
    } catch (Exception exception) {
        log.error("Failure creating initial SDP: " + exception.toString());
    }
    return newSdp;
}
Also used : Enumeration(java.util.Enumeration) SessionDescriptor(org.zoolu.sdp.SessionDescriptor) AttributeField(org.zoolu.sdp.AttributeField) MediaDescriptor(org.zoolu.sdp.MediaDescriptor) MediaField(org.zoolu.sdp.MediaField) Vector(java.util.Vector)

Aggregations

MediaDescriptor (org.zoolu.sdp.MediaDescriptor)9 AttributeField (org.zoolu.sdp.AttributeField)6 Enumeration (java.util.Enumeration)5 Vector (java.util.Vector)4 Codec (org.red5.app.sip.codecs.Codec)4 MediaField (org.zoolu.sdp.MediaField)3 SessionDescriptor (org.zoolu.sdp.SessionDescriptor)2