使用Jain API上的编解码器信息自动创建sdp消息

时间:2018-08-09 14:45:01

标签: java sip jain-sip

我想使用jain sip应用程序在Java中执行相互搜索。在注册过程中没有问题,但是由于搜索过程中的编解码器不兼容,我只是拨打电话并接听电话,但该呼叫没有声音传输。 。 SDP中存在某些编解码器信息,该信息与我发送到服务器的邀请请求相对应。我应该获取此信息并根据它进行编解码器。 而且,某些编解码器的有效载荷类型值是动态确定的。如何提取这些动态值并创建其他属性。取决于我应该做的是pcma或电话事件。

我想将PC8用于视频,将VP8用于视频。 我默认创建pcma,但是还有另一个称为电话事件的编解码器。我应该如何正确地做到这一点?

LastRow = Range("AB" & Rows.Count).End(xlUp).Offset(1, 0).Row

Range("AB" & LastRow & ":AC" & LastRow).Formula = "=Sum(AB2:AB" & LastRow - 1 & ")"

Range("AD2:AD" & LastRow - 1).Formula = "=AB2/" & Range("AB" & LastRow) & "*" & Range("AC" & LastRow).Value

    try { 
        Address toAddress = addressFactory.createAddress(GUI.getDestination());
        ToHeader toHeader = headerFactory.createToHeader(toAddress, null);
        Address fromAddress = addressFactory.createAddress(GUI.getName() + "<sip:" + GUI.getAOR() + ">");
        FromHeader fromHeader = headerFactory.createFromHeader(fromAddress, String.valueOf(tag)); 
        ViaHeader viaHeader = headerFactory.createViaHeader(sIP, iSipPort, "udp", null);
        ArrayList viaHeaders = new ArrayList();
        viaHeaders.add(viaHeader); 
        MaxForwardsHeader maxForwardsHeader = headerFactory.createMaxForwardsHeader(20);
        CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(LCseqDegeri, Request.INVITE);
        CallIdHeader callIdHeader = sipProvider.getNewCallId();
        // proxy adresi
        Address proxyAddress = addressFactory.createAddress(GUI.getDestination());
        URI requestUri = proxyAddress.getURI();

        Request request = messageFactory.createRequest(requestUri, Request.INVITE,
                callIdHeader, cSeqHeader, fromHeader, toHeader,
                viaHeaders, maxForwardsHeader);
        request.addHeader(contactHeader);

        RouteHeader routeHeader = headerFactory.createRouteHeader(proxyAddress);
        request.addHeader(routeHeader);
        // senderInfo_UAC: UAC sesli sohbet için bilgi içerir
        SdpInfo senderInfo_UAC = new SdpInfo();
        senderInfo_UAC.setIpSender(sIP);
        senderInfo_UAC.setVoicePort(GUI.getVoicePort());
        String direction = "sendrecv"; 
                  senderInfo_UAC.setDirection("sendrecv"); 
        ContentTypeHeader myContentTypeHeader = headerFactory.createContentTypeHeader("application", "sdp");
        // SDP mesajını oluştur ve bilgileri sdpOffer'in senderInfo değişkenine kaydet
        byte[] content = sdpOffer.createSdp(senderInfo_UAC);
        // SDP mesajını INVITE mesaj gövdesine kaydet
        request.setContent(content, myContentTypeHeader);
        clientTransaction = sipProvider.getNewClientTransaction(request);
        clientTransaction.sendRequest();
        GUI.Display(" sendRequest SdpInfo Send ringbacktone.wav  : " + request.toString());
        // UAC zil sesini çal
        ringClient.playRing("file:ringbacktone.wav");

    } catch (ParseException | InvalidArgumentException | SipException ex) {
        System.out.println(ex.getMessage());
    }

这时我需要输入正确的有效负载类型值和编码值,但是我无法以健康的方式创建正确的媒体fmtp值或其他必需的参数。是否可以从某个位置提取音频格式值并访问编码和pt值?如何确定这些值。我如何进行相互会议

public byte[] createSdp(SdpInfo senderInfo) {
    try {
        this.senderInfo = senderInfo;
        Version version = sdpFactory.createVersion(0);
        long ss = sdpFactory.getNtpTime(new Date());
        Origin origin = sdpFactory.createOrigin("-", ss, ss, "IN", "IP4", senderInfo.getIpSender());
        SessionName sessionName = sdpFactory.createSessionName("-");
        Connection con = sdpFactory.createConnection("IN", "IP4", senderInfo.getIpSender());
        Time time = sdpFactory.createTime();
        Vector timeVector = new Vector();
        timeVector.add(time);
        **Vector mediaDescriptionVector = new Vector();    
        int[] audioformat = new int[2];
        //audioformat[0] = senderInfo.getMediaPayloadType();
        audioformat[0] = 8;
        audioformat[1] = 101; 
        MediaDescription audioMediaDescription = sdpFactory.createMediaDescription("audio", senderInfo.getVoicePort(), 1, "RTP/AVP", audioformat);
        mediaDescriptionVector.add(audioMediaDescription); 
        String[] encoding = new String[2];
        encoding[0] = "PCMA";
        encoding[1] = "telephone-event";
        // Attribute audioAttributeDescription = sdpFactory.createAttribute("rtpmap", "PCMA/8000");
        // mediaDescriptionVector.add(audioAttributeDescription); 
        for (int i = 0; i < audioformat.length; i++) {
            Attribute rtpmap = sdpFactory.createAttribute(
                    SdpConstants.RTPMAP,
                    audioformat[i] + " " + encoding[i] + "/"
                    + senderInfo.getMediaRate());
            mediaDescriptionVector.add(rtpmap);            }
        Attribute fmtp = sdpFactory.createAttribute("fmtp", audioformat[1] + " 0-16");//0-16 1-10 abcdef
        mediaDescriptionVector.add(fmtp);    
        Attribute direction = sdpFactory.createAttribute(senderInfo.getDirection(), null);
        mediaDescriptionVector.add(direction); 
        Attribute ptime = sdpFactory.createAttribute("ptime", "20");
        mediaDescriptionVector.add(ptime);**
        // SDP mesajı oluştur
        SessionDescription sdpMessage = sdpFactory.createSessionDescription();
        sdpMessage.setVersion(version);
        sdpMessage.setOrigin(origin);
        sdpMessage.setSessionName(sessionName);
        sdpMessage.setConnection(con);
        sdpMessage.setTimeDescriptions(timeVector);
        sdpMessage.setMediaDescriptions(mediaDescriptionVector);            return sdpMessage.toString().getBytes();
    } catch (IllegalArgumentException | SdpException ex) {
        System.out.println(ex.getMessage());
    }
    return null;
}

0 个答案:

没有答案