首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用(JMF)发送rtcp消息?

如何使用(JMF)发送rtcp消息?
EN

Stack Overflow用户
提问于 2013-02-21 10:30:36
回答 1查看 2.1K关注 0票数 1

我正在使用一个java应用程序来使用JAIN设置一个带有微妙语音服务器的SIP会话。然后,我通过发送一些MRCP命令(如GET_PARAMS、SET-PARAMS、定义语法和使用mrcp4j API来识别)为识别系统做好了准备。

然后使用JMF与语音服务器建立rtp & rtcp会话,发送音频进行识别。服务器已经接收到音频,但只有在收到RTCP bye后才能识别。

,但问题是我无法使用rtcp来结束rtp会话,因为我无法在JMF文档中找到这样的方法。

如果有人能在这方面给我指点,那将是很有帮助的。我已经附上了RTP会话的代码。

JMF文档的链接是这里

代码语言:javascript
运行
复制
// 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();  
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-22 13:53:09

没有这样的显式方法来使用JMF发送rtcp。但是,当您关闭SendStream时,JMF在内部发送RTCP。

请注意,关闭和停止SendStream是不同的。关闭流将移除会话,而停止SendStream只会停止数据传输。要发送RTCP,只需在发送完媒体后停止处理器并关闭SendStream。因此,要发送RTCP bye,只需将这两行添加到代码中即可。

代码语言:javascript
运行
复制
processor.stop();  //processor needs to be stopped as well before closing the sendStream
sendStream.close();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14999961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档