如何中继两个对等点之间的对等Ad hoc网络中的RTP(实时传输协议)流

时间:2017-03-30 17:03:26

标签: java rtp jmf

我正在使用JMF框架为ad hoc网络建立Peer-Peer实时语音通信。我使用了两个线程:每个对等端的Receiver和Sender。接收器线程用于接收实时音频数据,发送器线程用于在对等体之间传输实时数据。

它在一个跃点距离上与两个对等端正常工作但我想在两个距离之间的两个对等点之间中继RTP流,就像a,b和c一样 是三个对等体,它们以a-> b-> c的方式连接(这里,a连接到b,所以b到c但是a没有连接到c)我希望中继rtp流a到c之间通过b。

他们是否可以在JAVA或JMF或任何其他图书馆中进行此操作?

\ Receiver线程

public void run() {
    String url= "rtp://"+ip+":"+port+"/audio/16";

    MediaLocator mrl= new MediaLocator(url);
    System.out.println(mrl);
    if (mrl == null) {
        System.err.println("Can't build MRL for RTP");
        System.exit(-1);
    }

    // Create a player for this rtp session
    Player player = null;
    try {
        player = Manager.createPlayer(mrl);
    } catch (Exception e) {
        System.err.println("Error:" + e);
        System.exit(-1);
    } 

    //System.out.println(player);

    if (player != null) {
        System.out.println("Player created.");
        player.realize();
        while (player.getState() != Player.Realized){
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        player.start();
    } else {
        System.err.println("Player doesn't created.");
        System.exit(-1);
    }
}

}

\发件人帖子

    public void run() {    
    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 {

        System.out.println("hii");
        System.exit(-1); 
    }
    Processor processor = null;
    try { 
        processor = Manager.createProcessor (di.getLocator());
    } catch (Exception 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;
   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); 
        } 
    } 
    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://"+ip+":"+port+"/audio/16";
            MediaLocator m = new MediaLocator(url); 
            DataSink d = Manager.createDataSink(ds, m);
            d.open();
            d.start();
            processor.start();
        } catch (Exception e) {
            System.exit(-1);
        }     
    }    
     }

}

0 个答案:

没有答案
相关问题