簡體   English   中英

如何使用Java Media Framework(JMF)發送rtcp再見消息?

[英]How to send rtcp bye message using Java Media Framework (JMF)?

我正在使用Java應用程序使用JAIN SIP Java API與nuance語音服務器建立SIP會話。 然后,我通過發送一些MRCP命令(例如GET_PARAMS,SET-PARAMS,Define Grammar和使用mrcp4j API進行識別)來設置系統,以進行識別。

然后,我使用JMF api與語音服務器建立rtp和rtcp會話,以發送音頻進行識別。 服務器已接收到音頻,但直到接收到RTCP再見后才能識別。

但是問題是我無法使用rtcp bye結束rtp會話,因為我無法在JMF文檔中找到解決該問題的方法

如果有人可以指導我,那將真的很有幫助。 我已經附上了RTP會話的代碼。

JMF api文檔的鏈接在這里

// send Audio data
// create the RTP Manager
RTPManager rtpManager = RTPManager.newInstance();

// create the local endpoint for the local interface on any local port
int port = Integer.parseInt(rtpPORT);;
SessionAddress localAddress = new SessionAddress();      
InetAddress IP = InetAddress.getByName("hydhtc284704d");
localAddress.setControlHostAddress(IP);
localAddress.setControlPort(24501);
localAddress.setDataHostAddress(IP);
localAddress.setDataPort(24500);

// initialize the RTPManager
rtpManager.initialize(localAddress);
//rtpManager.initialize(rtpConnector);

// specify the remote endpoint of this unicast session 
InetAddress ipAddress = InetAddress.getByName("hydhtc227033d");
SessionAddress remoteAddress = new SessionAddress(ipAddress, port, ipAddress, port + 1);

//System.out.println(remoteAddress);
// open the connection
rtpManager.addTarget(remoteAddress);

rtpManager.addSendStreamListener(new SendStreamListener() {
@Override
public void update(SendStreamEvent arg0) {
//System.out.println("Send Stream Event: " + arg0.getSource());
System.out.println("Number of bytes transmitted: " + arg0.getSendStream().getSourceTransmissionStats().getBytesTransmitted());
System.out.println("Sender Report: " + arg0.getSendStream().getSenderReport());
}
});

rtpManager.addReceiveStreamListener(new ReceiveStreamListener() {
@Override
public void update(ReceiveStreamEvent arg0) {
// TODO Auto-generated method stub
}
});


File audioFile = new File("C:\\Users\\Bhanu_Verma\\Desktop\\eclipse\\one.wav");
Processor processor= Manager.createProcessor(audioFile.toURI().toURL());
processor.configure();
// Block until the Processor has been configured

while (processor.getState() != processor.Configured) {
}

processor.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW_RTP));

TrackControl track[] = processor.getTrackControls();
//ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
//processor.setContentDescriptor(cd);
boolean encodingOk = false;
// Go through the tracks and try to program one of them to
// output ulaw data.

    for (int i = 0; i < track.length; i++) {
        if (!encodingOk && track[i] instanceof FormatControl) {
            if (((FormatControl)track[i]).setFormat(new AudioFormat(AudioFormat.ULAW_RTP,8000,8,1)) == null)
            {
                track[i].setEnabled(false);
            }
            else 
            {
                encodingOk = true;
            }
        }
        else 
        {
            // we could not set this track to ulaw, so disable it
            track[i].setEnabled(false);
        }
    }

    // At this point, we have determined where we can send out ulaw data or not.
    // realize the processor

    if (encodingOk) {
        processor.realize();
        // block until realized.

        while (processor.getState() != processor.Realized) {
        }

        // get the output datasource of the processor and exit if we fail
        DataSource dataOutput = processor.getDataOutput();

        // create a send stream for the output data source of a processor and start it

        SendStream sendStream = rtpManager.createSendStream(dataOutput,0);
        sendStream.start();

        System.out.println("Starting processor" + "\n");
        processor.start();


        while(processor.getState()== processor.Started)
        {
            System.out.println("Sending Audio..");
        }

        System.out.println("Processor was started and audio was sent to server");

        Wait(2000);  // waiting so that audio could be given to the server


        // close the connection if no longer needed.
        rtpManager.removeTarget(remoteAddress, "Client disconnected.");

        // call dispose at the end of the life-cycle of this RTPManager so
        // it is prepared to be garbage-collected.
        rtpManager.dispose();  

嗯,沒有使用JMF來發送rtcp bye的明確方法。 但是,當您關閉SendStream時,JMF會在內部發送RTCP再見。

請注意, 關閉和停止SendStream是不同的。 關閉流將刪除會話,而停止SendStream僅會停止數據傳輸。 要發送RTCP再見,只需在完成發送媒體后停止處理器並關閉SendStream。 因此,要發送RTCP再見,只需將這兩行添加到您的代碼中。

processor.stop();  //processor needs to be stopped as well before closing the sendStream
sendStream.close();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM