I am establishing Peer-Peer real time voice communication for ad hoc network using JMF framework. I have used two threads namely: Receiver and Sender at each peer. Receiver thread is for receiving the real-time audio data and sender thread is for transmitting real-time data between the peers.

It is working fine with two peers at one hop distance but I want to relay the RTP streams between two peers which are at two hops distance, like if a,b and c are three peers and they are connected in a fashion like a->b->c(Here, a is connected to b and so as b to c but a is not connected to c) and I want to relay the rtp stream between a to c via b.

Is their any way to do it in JAVA or JMF or any other library?

\ Receiver thread

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);
    }
}

}

\Sender Thread

    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

There are 0 best solutions below