0 Replies - 376 Views - Last Post: 10 March 2013 - 11:31 AM Rate Topic: -----

#1 Kikokent  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-March 13

Can the audio format be changed during the RTP session in JMF?

Posted 10 March 2013 - 11:31 AM

Hi, I am implementing a program which will make the encoder changed when ABC situation appear in JMF.


Quote

Sender


// 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.5: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.exit(-1);
        }     
    } 


I can manually changed the audio format just by
AudioFormat.GSM_RTP, 8000, 8, 1
to
AudioFormat.ULAW_RTP, 8000, 8, 1
. How/ Can I modify the encoder to become adaptive changed? Sorry that, my explanation is very poor. What I mean is can I try something like this in the middle of the sender code:

if (ABC) {

         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); 
            } 
        }  
} else if (EFG) {

         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 { 

                track[i].setEnabled(false); 
            } 
        }                     
    }


Need some hints and guidelines, thanks in advanced. ^^/>"

Is This A Good Question/Topic? 0
  • +

Page 1 of 1