2013-03-16 2 views
0

안녕하세요, 동일한 컴퓨터에서 2 rtp 세션을 실행하는 JMF 프로젝트를 구현하고 있습니다. rtp 세션을 초기화하고 시작할 수는 있지만 그 중 하나를 중단시킬 수는 있습니다. 동일한 컴퓨터에서 2 rtp 세션을 실행하지 말고 JMF가 인터럽트/임시 세션을 보유 할 수있는 방법이 있습니까? 정보에 대한 몇 가지 코드가 있습니다.JMF에서 오디오 RT 세션을 중단하는 방법은 무엇입니까?

transmitA와 transmitB는 로컬 컴퓨터에서 LINEAR 사운드를 가져 와서 GSM_RTP 또는 ULAW_RTP로 변환하는 코드와 거의 동일합니다. 송신 포트 만 동일하지 않습니다. 마지막으로 다른 컴퓨터에 mediaLocator에 대한 데이터 연결.

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

      transmitA(); 
     } 
    }; 

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

      transmitB(); 
     } 
    }; 

조건

는 RTP 세션을 중단 동일하지 않습니다 스레드를 중단,

transmitA.start(); 
trasmitB.start(); 

while (...) { 

     if (...) { 

      //interrupt transmitA 
      transmitA.interrupt(); 
      transmitA.stop(); 

      } /*else if (...) { 
         //interrupt transmitB 
         transmitB.interrupt(); 
         transmitB.stop(); 
        }*/      
      }//notation end here 

음을 중단합니다. 인터럽트를하거나 하나의 rtp 세션을 다른 컴퓨터로 전송하는 방법은 무엇입니까? 트랙에서 뭔가 할거야? 또는 가공업자?

transmitA은()

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

고급에서 몇 가지 힌트 및 지침, 감사합니다 ^^ "

답변

0

노력과 시도 후 필요, 나는 마침내 그것을 한 ... 그냥 제거 스레드 및 직접 메서드를 사용하여, 나는 좋은 프로그래밍 실천 여부는 아니지만 잘 어떤 제안 정말 감사하게 될 것입니다 ...

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 
+0

나는 JMF 프로그래밍에별로 좋지 않지만 그것을 배우러 간다. 그것의 나의 실행 가능한 대답, 더 나은 대답 제안은 높이 평가됩니다. 감사. –