简体   繁体   中英

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

I am using a java application to set up a SIP session with nuance speech server using JAIN SIP java API. Then I prepared the system for recognition by setting it up by sending some MRCP commands like GET_PARAMS, SET-PARAMS, Define Grammar & recognize using mrcp4j API.

Then I used JMF api to set up a rtp & rtcp session with speech server to send the audio for recognition. Server has received the audio but it won't recognize until it has received a RTCP bye.

But the problem is I am not able to end the rtp session using rtcp bye as I am not able to figure out a method for that in JMF documentation .

It would be really helpful if someone could guide me on that. I have attached the code for the RTP session.

Link for JMF api documentation is here

// 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();  

Well there is no such explicit method for sending the rtcp bye using JMF. But instead JMF internally sends the RTCP bye when you close your SendStream.

Please notice that closing and stopping the SendStream is different. Closing the stream removes the session whereas stopping the SendStream only stops the data transmission. To send the RTCP bye just stop the processor and close the SendStream when you are done sending the media. So to send a RTCP bye just add these two lines to your code.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM