Package org.zoolu.sdp

Examples of org.zoolu.sdp.AttributeField


                    rtpmapParamValue += "/" + audioCodecs[audioIndex].getSampleRate() + "/1";
                   
                    log.debug("Adding rtpmap for payload [" + payloadId +
                            "] with value = [" + rtpmapParamValue + "]." );
                   
                    audioAttributes.add(new AttributeField(Codec.ATTRIBUTE_RTPMAP, rtpmapParamValue));
                   
                    String[] codecMediaAttributes = audioCodecs[audioIndex].getCodecMediaAttributes();
                   
                    if (codecMediaAttributes != null) {                       
                        log.debug("Adding " + codecMediaAttributes.length +
                                " audio codec media attributes." );
                       
                        for (int attribIndex = 0; attribIndex < codecMediaAttributes.length; attribIndex++) {                           
                           log.debug("Adding audio media attribute [" +
                                    codecMediaAttributes[attribIndex] + "]." );
                           
                            AttributeField newAttribute = parseAttributeField(codecMediaAttributes[attribIndex]);
                           
                            if (newAttribute != null) {                               
                                audioAttributes.add(newAttribute);
                            }
                        }
                    } else {                       
                        log.warn("Audio codec has no especific media attributes." );
                    }
                }
               
                // Calculate the format list to be used on MediaDescriptor creation.
                String formatList = getFormatList(audioAttributes);
               
                for (Enumeration attributesEnum = audioAttributes.elements(); attributesEnum.hasMoreElements();) {                   
                    AttributeField audioAttribute = (AttributeField) attributesEnum.nextElement();
                   
                    if (initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_AUDIO) == null) {                       
                        log.debug("Creating audio media descriptor." );
                       
                      MediaField mf = new MediaField(Codec.MEDIA_TYPE_AUDIO, audioPort, 0, "RTP/AVP", formatList);
                        initialDescriptor.addMedia(mf, audioAttribute);
                    } else {                       
                        log.debug("Just adding attribute.");
                        initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_AUDIO).addAttribute(audioAttribute);
                    }
                }
               
                String[] commonAudioMediaAttributes = CodecFactory.getInstance().getCommonAudioMediaAttributes();
               
                if (commonAudioMediaAttributes != null) {                   
                    log.debug("Adding " + commonAudioMediaAttributes.length + " common audio media attributes." );
                   
                    for (int attribIndex = 0; attribIndex < commonAudioMediaAttributes.length; attribIndex++) {                       
                        log.debug("Adding common audio media attribute [" + commonAudioMediaAttributes[attribIndex] + "].");
                       
                        AttributeField newAttribute = parseAttributeField(commonAudioMediaAttributes[attribIndex]);
                       
                        if (newAttribute != null) {                           
                            initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_AUDIO).addAttribute( newAttribute);
                        }
                    }
                } else {                   
                    log.debug("No common audio media attributes.");
                }
            }
           
            if (videoCodecsNumber > 0) {               
                Codec[] videoCodecs = CodecFactory.getInstance().getAvailableVideoCodecs();
                Vector<AttributeField> videoAttributes = new Vector<AttributeField>();
               
                for (int videoIndex = 0; videoIndex < audioCodecsNumber; videoIndex++) {                   
                    String payloadId = String.valueOf(videoCodecs[videoIndex].getCodecId());
                    String rtpmapParamValue = payloadId;
                    rtpmapParamValue += " " + videoCodecs[videoIndex].getCodecName();
                    rtpmapParamValue += "/" + videoCodecs[videoIndex].getSampleRate() + "/1";
                   
                    log.debug("Adding rtpmap for payload [" + payloadId + "] with value = [" + rtpmapParamValue + "].");
                   
                    videoAttributes.add(new AttributeField(Codec.ATTRIBUTE_RTPMAP, rtpmapParamValue));                   
                    String[] codecMediaAttributes = videoCodecs[videoIndex].getCodecMediaAttributes();
                   
                    if (codecMediaAttributes != null) {                       
                        log.debug("Adding " + codecMediaAttributes.length + " video codec media attributes.");
                       
                        for (int attribIndex = 0; attribIndex < codecMediaAttributes.length; attribIndex++) {                           
                            log.debug("Adding video media attribute [" + codecMediaAttributes[attribIndex] + "].");
                           
                            AttributeField newAttribute = parseAttributeField(codecMediaAttributes[attribIndex]);
                           
                            if (newAttribute != null) {                               
                                videoAttributes.add(newAttribute);
                            }
                        }
                    } else {
                       log.info("Video codec has no especific media attributes.");
                    }
                }
               
                // Calculate the format list to be used on MediaDescriptor creation.
                String formatList = getFormatList(videoAttributes);
               
                for (Enumeration attributesEnum = videoAttributes.elements(); attributesEnum.hasMoreElements();) {                   
                    AttributeField videoAttribute = (AttributeField) attributesEnum.nextElement();
                   
                    if (initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_VIDEO) == null) {   
                      MediaField mf = new MediaField(Codec.MEDIA_TYPE_VIDEO, audioPort, 0, "RTP/AVP", formatList);
                        initialDescriptor.addMedia(mf, videoAttribute);
                    } else {
                        initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_VIDEO).addAttribute(videoAttribute);
                    }
                }
               
                String[] commonVideoMediaAttributes = CodecFactory.getInstance().getCommonAudioMediaAttributes();
               
                if (commonVideoMediaAttributes != null) {                   
                    log.debug("Adding " + commonVideoMediaAttributes.length + " common video media attributes.");
                   
                    for (int attribIndex = 0; attribIndex < commonVideoMediaAttributes.length; attribIndex++) {                       
                        log.debug("Adding common video media attribute [" + commonVideoMediaAttributes[attribIndex] + "]." );
                       
                        AttributeField newAttribute = parseAttributeField(commonVideoMediaAttributes[attribIndex]);
                       
                        if (newAttribute != null) {                           
                            initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_VIDEO).addAttribute(newAttribute);
                        }
                    }
View Full Code Here


        return initialDescriptor;
    }
   
   
    private static String getFormatList(Vector mediaAttributes) {       
        AttributeField mediaAttribute = null;
        String formatList = "";
       
//        log.debug("getting Format List");
       
        for (Enumeration attributeEnum = mediaAttributes.elements(); attributeEnum.hasMoreElements();) {           
            mediaAttribute = (AttributeField) attributeEnum.nextElement();
           
            if (mediaAttribute.getAttributeName().equalsIgnoreCase(Codec.ATTRIBUTE_RTPMAP)) {               
                if (!formatList.isEmpty()) {
                    formatList += " ";
                }
               
                formatList += getPayloadIdFromAttribute(mediaAttribute);
View Full Code Here

        return formatList;
    }
   
   
    private static AttributeField parseAttributeField(String codecMediaAttribute) {       
        AttributeField newAttribute = null;
       
//        log.debug("codecMediaAttribute = [" + codecMediaAttribute + "].");
       
        String attribName = codecMediaAttribute.substring(0, codecMediaAttribute.indexOf(":"));
        String attribValue = codecMediaAttribute.substring(codecMediaAttribute.indexOf(":") + 1);
       
//        log.debug("attribName = [" + attribName + "] attribValue  = [" + attribValue + "].");
       
        if ((!attribName.isEmpty()) && (!attribValue.isEmpty())) {           
            newAttribute = new AttributeField(attribName, attribValue);
        }
               
        return newAttribute;
    }
View Full Code Here

                if (localDescriptor != null) {                   
                    Vector remoteAttributes = remoteDescriptor.getAttributes(Codec.ATTRIBUTE_RTPMAP);
                    Vector<AttributeField> newSdpAttributes = new Vector<AttributeField>();
                   
                    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(),
View Full Code Here

                    // 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);
                        }
                    }
                }
            }
View Full Code Here

                        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!");
View Full Code Here

    }
   
   
    private static AttributeField findAttributeByPayloadId(String attributeName, String payloadId,
            MediaDescriptor mediaDescriptor) {
        AttributeField searchingMediaAttribute = null;
       
//        log.debug("attributeName = [" + attributeName + "], payloadId = [" + payloadId + "].");
       
        Vector mediaAttributes = mediaDescriptor.getAttributes( attributeName );
       
        for (Enumeration attributesEnum = mediaAttributes.elements(); attributesEnum.hasMoreElements();) {           
            AttributeField mediaAttribute = (AttributeField) attributesEnum.nextElement();

//            log.debug("Validating attribute with name = [" + mediaAttribute.getAttributeName() +
//                    "] and value = [" + mediaAttribute.getAttributeValue() + "].");
           
            if (getPayloadIdFromAttribute(mediaAttribute).equals(payloadId)) {               
View Full Code Here

                    rtpmapParamValue += "/" + audioCodecs[audioIndex].getSampleRate() + "/1";
                   
//                    log.debug("Adding rtpmap for payload [" + payloadId +
//                            "] with value = [" + rtpmapParamValue + "]." );
                   
                    audioAttributes.add(new AttributeField(Codec.ATTRIBUTE_RTPMAP, rtpmapParamValue));
                   
                    String[] codecMediaAttributes = audioCodecs[audioIndex].getCodecMediaAttributes();
                   
                    if (codecMediaAttributes != null) {                       
//                        log.debug("Adding " + codecMediaAttributes.length +
//                                " audio codec media attributes." );
                       
                        for (int attribIndex = 0; attribIndex < codecMediaAttributes.length; attribIndex++) {                           
//                            log.debug("Adding audio media attribute [" +
//                                    codecMediaAttributes[attribIndex] + "]." );
                           
                            AttributeField newAttribute = parseAttributeField(codecMediaAttributes[attribIndex]);
                           
                            if (newAttribute != null) {                               
                                audioAttributes.add(newAttribute);
                            }
                        }
                    } else {                       
                        log.warn("Audio codec has no especific media attributes." );
                    }
                }
               
                // Calculate the format list to be used on MediaDescriptor creation.
                String formatList = getFormatList(audioAttributes);
               
                for (Enumeration attributesEnum = audioAttributes.elements(); attributesEnum.hasMoreElements();) {                   
                    AttributeField audioAttribute = (AttributeField) attributesEnum.nextElement();
                   
                    if (initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_AUDIO) == null) {                       
//                        log.debug("Creating audio media descriptor." );
                       
                      MediaField mf = new MediaField(Codec.MEDIA_TYPE_AUDIO, audioPort, 0, "RTP/AVP", formatList);
                        initialDescriptor.addMedia(mf, audioAttribute);
                    } else {                       
//                        log.debug("Just adding attribute.");
                        initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_AUDIO).addAttribute(audioAttribute);
                    }
                }
               
                String[] commonAudioMediaAttributes = CodecFactory.getInstance().getCommonAudioMediaAttributes();
               
                if (commonAudioMediaAttributes != null) {                   
//                    log.debug("Adding " + commonAudioMediaAttributes.length + " common audio media attributes." );
                   
                    for (int attribIndex = 0; attribIndex < commonAudioMediaAttributes.length; attribIndex++) {                       
//                        log.debug("Adding common audio media attribute [" + commonAudioMediaAttributes[attribIndex] + "].");
                       
                        AttributeField newAttribute = parseAttributeField(commonAudioMediaAttributes[attribIndex]);
                       
                        if (newAttribute != null) {                           
                            initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_AUDIO).addAttribute( newAttribute);
                        }
                    }
                } else {                   
                    log.debug("No common audio media attributes.");
                }
            }
           
            if (videoCodecsNumber > 0) {               
                Codec[] videoCodecs = CodecFactory.getInstance().getAvailableVideoCodecs();
                Vector videoAttributes = new Vector();
               
                for (int videoIndex = 0; videoIndex < audioCodecsNumber; videoIndex++) {                   
                    String payloadId = String.valueOf(videoCodecs[videoIndex].getCodecId());
                    String rtpmapParamValue = payloadId;
                    rtpmapParamValue += " " + videoCodecs[videoIndex].getCodecName();
                    rtpmapParamValue += "/" + videoCodecs[videoIndex].getSampleRate() + "/1";
                   
//                    log.debug("Adding rtpmap for payload [" + payloadId + "] with value = [" + rtpmapParamValue + "].");
                   
                    videoAttributes.add(new AttributeField(Codec.ATTRIBUTE_RTPMAP, rtpmapParamValue));                   
                    String[] codecMediaAttributes = videoCodecs[videoIndex].getCodecMediaAttributes();
                   
                    if (codecMediaAttributes != null) {                       
//                        log.debug("Adding " + codecMediaAttributes.length + " video codec media attributes.");
                       
                        for (int attribIndex = 0; attribIndex < codecMediaAttributes.length; attribIndex++) {                           
//                            log.debug("Adding video media attribute [" + codecMediaAttributes[attribIndex] + "].");
                           
                            AttributeField newAttribute = parseAttributeField(codecMediaAttributes[attribIndex]);
                           
                            if (newAttribute != null) {                               
                                videoAttributes.add(newAttribute);
                            }
                        }
                    } else {
                       log.info("Video codec has no especific media attributes.");
                    }
                }
               
                // Calculate the format list to be used on MediaDescriptor creation.
                String formatList = getFormatList(videoAttributes);
               
                for (Enumeration attributesEnum = videoAttributes.elements(); attributesEnum.hasMoreElements();) {                   
                    AttributeField videoAttribute = (AttributeField) attributesEnum.nextElement();
                   
                    if (initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_VIDEO) == null) {   
                      MediaField mf = new MediaField(Codec.MEDIA_TYPE_VIDEO, audioPort, 0, "RTP/AVP", formatList);
                        initialDescriptor.addMedia(mf, videoAttribute);
                    } else {
                        initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_VIDEO).addAttribute(videoAttribute);
                    }
                }
               
                String[] commonVideoMediaAttributes = CodecFactory.getInstance().getCommonAudioMediaAttributes();
               
                if (commonVideoMediaAttributes != null) {                   
//                    log.debug("Adding " + commonVideoMediaAttributes.length + " common video media attributes.");
                   
                    for (int attribIndex = 0; attribIndex < commonVideoMediaAttributes.length; attribIndex++) {                       
//                        log.debug("Adding common video media attribute [" + commonVideoMediaAttributes[attribIndex] + "]." );
                       
                        AttributeField newAttribute = parseAttributeField(commonVideoMediaAttributes[attribIndex]);
                       
                        if (newAttribute != null) {                           
                            initialDescriptor.getMediaDescriptor(Codec.MEDIA_TYPE_VIDEO).addAttribute(newAttribute);
                        }
                    }
View Full Code Here

        return initialDescriptor;
    }
   
   
    private static String getFormatList(Vector mediaAttributes) {       
        AttributeField mediaAttribute = null;
        String formatList = "";
       
//        log.debug("getting Format List");
       
        for (Enumeration attributeEnum = mediaAttributes.elements(); attributeEnum.hasMoreElements();) {           
            mediaAttribute = (AttributeField) attributeEnum.nextElement();
           
            if (mediaAttribute.getAttributeName().equalsIgnoreCase(Codec.ATTRIBUTE_RTPMAP)) {               
                if (!formatList.isEmpty()) {
                    formatList += " ";
                }
               
                formatList += getPayloadIdFromAttribute(mediaAttribute);
View Full Code Here

        return formatList;
    }
   
   
    private static AttributeField parseAttributeField(String codecMediaAttribute) {       
        AttributeField newAttribute = null;
       
//        log.debug("codecMediaAttribute = [" + codecMediaAttribute + "].");
       
        String attribName = codecMediaAttribute.substring(0, codecMediaAttribute.indexOf(":"));
        String attribValue = codecMediaAttribute.substring(codecMediaAttribute.indexOf(":") + 1);
       
//        log.debug("attribName = [" + attribName + "] attribValue  = [" + attribValue + "].");
       
        if ((!attribName.isEmpty()) && (!attribValue.isEmpty())) {           
            newAttribute = new AttributeField(attribName, attribValue);
        }
               
        return newAttribute;
    }
View Full Code Here

TOP

Related Classes of org.zoolu.sdp.AttributeField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.