Java 如何在JMF中中断音频rtp会话?

Java 如何在JMF中中断音频rtp会话?,java,interrupt,rtp,jmf,Java,Interrupt,Rtp,Jmf,晚上好,我正在实现一个JMF项目,它在同一台计算机上运行2个rtp会话。rtp会话可以初始化和启动,但如何中断其中一个会话呢。与不在同一台计算机上运行2个rtp会话不同,JMF是否有办法中断/保持rtp会话?这些信息有一些代码 transmitA和transmitB几乎是从本地计算机获取线性声音并将其转换为GSM_RTP或ULAW_RTP的相同代码,只是传输端口不同。最后,将mediaLocator的数据链接到另一台计算机 Thread transmitA = new Thread() {

晚上好,我正在实现一个JMF项目,它在同一台计算机上运行2个rtp会话。rtp会话可以初始化和启动,但如何中断其中一个会话呢。与不在同一台计算机上运行2个rtp会话不同,JMF是否有办法中断/保持rtp会话?这些信息有一些代码

transmitA和transmitB几乎是从本地计算机获取线性声音并将其转换为GSM_RTP或ULAW_RTP的相同代码,只是传输端口不同。最后,将mediaLocator的数据链接到另一台计算机

Thread transmitA = new Thread() {
        public void run() {

            transmitA();
        }
    };

        Thread transmitB = new Thread() {
        public void run() {

            transmitB();
        }
    };
中断条件

嗯,中断线程与中断rtp会话不同。如何中断或只是使一个rtp会话传输到另一台计算机?我要在赛道上做点什么吗?还是处理器

传输()

公共无效传输(){
//首先找到一个可以捕获线性音频的捕获设备
//8位8Khz的数据
AudioFormat格式=新的AudioFormat(AudioFormat.LINEAR,
8000, 
8.
1); 
向量设备=CaptureDeviceManager.getDeviceList(格式);
CaptureDeviceInfo di=null;
如果(devices.size()>0){
di=(CaptureDeviceInfo)设备。elementAt(0);
}
否则{
//如果找不到相关的capturedevice,请退出。
系统退出(-1);
}
//为此capturedevice创建处理器&如果需要,请退出
//无法创建它
处理器=空;
试试{
processor=Manager.createProcessor(di.getLocator());
}捕获(IOE){
系统退出(-1);
}捕获(无进程异常e){
系统退出(-1);
} 
//配置处理器
processor.configure();
while(processor.getState()!=processor.Configured){
试一试{
睡眠(100);
}捕捉(中断异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
processor.setContentDescriptor(
新的ContentDescriptor(ContentDescriptor.RAW));
TrackControl track[]=处理器。getTrackControls();
布尔编码OK=false;
//浏览这些曲目,并尝试将其中一个编程为
//输出gsm数据。
对于(int i=0;i

需要一些提示和指导,感谢高级^^“

在尝试了一次又一次之后,我终于做到了。。。 只是删除了线程并直接使用该方法,我不知道这是否是一个好的编程实践,但任何建议都将非常感谢

private DataSink d = null;
private Processor processor = null;

while (...) {
   if (...) {

       //interrupt transmitA
       processor.stop();
       processor.close();
       processor.deallocate();
       processor = null;
       d.close();
       d = null;
       transmitA();

       } /*else if (...) {
                   //interrupt transmitB
                   processor.stop();
                   processor.close();
                   processor.deallocate();
                   processor = null;
                   d.close();
                   d = null;
                   transmitB.stop();
                 }*/                      
        }//notation end here

我真的不擅长JMF编程,但我将学习它。这是我可行的答案,任何更好的答案建议都将不胜感激。谢谢。
public void transmitA(){

        // First find a capture device that will capture linear audio
        // data at 8bit 8Khz 
        AudioFormat format= new AudioFormat(AudioFormat.LINEAR, 
                                            8000, 
                                            8, 
                                            1); 

        Vector devices= CaptureDeviceManager.getDeviceList( format);

        CaptureDeviceInfo di= null;

        if (devices.size() > 0) {
             di = (CaptureDeviceInfo) devices.elementAt( 0);
        }
        else {
            // exit if we could not find the relevant capturedevice. 
            System.exit(-1); 
        }

        // Create a processor for this capturedevice & exit if we 
        // cannot create it 
        Processor processor = null;
        try { 
                processor = Manager.createProcessor(di.getLocator());
        } catch (IOException e) { 
            System.exit(-1); 
        } catch (NoProcessorException e) { 
            System.exit(-1); 
        } 

       // configure the processor  
       processor.configure(); 

       while (processor.getState() != Processor.Configured){
           try {
                   Thread.sleep(100);
           } catch (InterruptedException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
           }
       }

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

       TrackControl track[] = processor.getTrackControls(); 

       boolean encodingOk = false;

       // Go through the tracks and try to program one of them to
       // output gsm data. 

        for (int i = 0; i < track.length; i++) { 
            if (!encodingOk && track[i] instanceof FormatControl) {  
                if (((FormatControl)track[i]).
                    setFormat( new AudioFormat(AudioFormat.GSM_RTP, 
                                               8000, 
                                               8, 
                                               1)) == null) {

                   track[i].setEnabled(false); 
                }
                else {
                    encodingOk = true; 
                }
            } else { 
                // we could not set this track to gsm, so disable it 
                track[i].setEnabled(false); 
            } 
        }

        // At this point, we have determined where we can send out 
        // gsm data or not. 
        // realize the processor 
        if (encodingOk) { 
            processor.realize(); 
            while (processor.getState() != Processor.Realized){
                   try {
                           Thread.sleep(100);
                   } catch (InterruptedException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                   }
            }
            // get the output datasource of the processor and exit 
            // if we fail 
            DataSource ds = null;

            try { 
                ds = processor.getDataOutput(); 
            } catch (NotRealizedError e) { 
                System.exit(-1);
            }

            // hand this datasource to manager for creating an RTP 
            // datasink our RTP datasink will multicast the audio 
            try {
                String url= "rtp://192.168.1.3:22222/audio/16";
                //String url= "rtp://224.0.0.1:22224/audio/16";
                MediaLocator m = new MediaLocator(url); 

                DataSink d = Manager.createDataSink(ds, m);
                d.open();
                d.start();
                processor.start();
            } catch (Exception e) {
                System.out.println("cannot find the receiver address!!!");
                System.exit(-1);
            }     
        } 
    }
private DataSink d = null;
private Processor processor = null;

while (...) {
   if (...) {

       //interrupt transmitA
       processor.stop();
       processor.close();
       processor.deallocate();
       processor = null;
       d.close();
       d = null;
       transmitA();

       } /*else if (...) {
                   //interrupt transmitB
                   processor.stop();
                   processor.close();
                   processor.deallocate();
                   processor = null;
                   d.close();
                   d = null;
                   transmitB.stop();
                 }*/                      
        }//notation end here