2012-04-02 71 views
6

我想使用JMF 2.1.1e以RTP格式捕获和流式传输音频。我写了一个简单的发射器,我可以发送和接收音频。但是当我在Wireshark中看到时,我将这些数据包看作是UDP。任何人都可以指出我的问题,请。为什么在使用jmf流时,它是UDP,而不是Wireshark中的RTP?

这里是我的功能负责音频捕获和传输。

public void captureAudio(){ 

    // Get the device list for ULAW 
    Vector devices = captureDevices(); 

    CaptureDeviceInfo captureDeviceInfo = null; 

    if (devices.size() > 0) { 
     //get the first device from the list and cast it as CaptureDeviceInfo 
     captureDeviceInfo = (CaptureDeviceInfo) devices.firstElement(); 
    } 
    else { 
     // exit if we could not find the relevant capturedevice. 
     System.out.println("No such device found"); 
     System.exit(-1); 
    } 


    Processor processor = null; 
    try { 
     //Create a Processor for the specified media. 
     processor = Manager.createProcessor(captureDeviceInfo.getLocator()); 
    } catch (IOException ex) { 
     System.err.println(ex); 
    } catch (NoProcessorException ex) { 
     System.err.println(ex); 
    } 
    //Prepares the Processor to be programmed. 
    //puts the Processor into the Configuring state. 
    processor.configure(); 

    //Wait till the Processor configured. 
    while (processor.getState() != Processor.Configured){ 
     try { 
      Thread.sleep(100); 
     } catch (InterruptedException e) { 
      e.printStackTrace(); 
     } 
    } 


    //Sets the output content-type for this Processor 
    processor.setContentDescriptor(CONTENT_DESCRIPTOR); 
    /** 
     ContentDescriptor CONTENT_DESCRIPTOR 
       = new ContentDescriptor(ContentDescriptor.RAW_RTP); 
     */ 

    //Gets a TrackControl for each track in the media stream. 
    TrackControl track[] = processor.getTrackControls(); 

    boolean encodingOk = false; 

    //searching through tracks to get a supported audio format track. 
    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; 
       track[i].setEnabled(encodingOk); 
       System.out.println("enc: " + i); 
      } 
     } else { 
      // we could not set this track to ULAW, so disable it 
      track[i].setEnabled(false); 
     } 
    } 

    //If we could set this track to ULAW we proceed 
    if (encodingOk){    
     processor.realize(); 
     while (processor.getState() != Processor.Realized){ 
      try { 
       Thread.sleep(100); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
     } 

     DataSource dataSource = null; 
     try { 
      dataSource = processor.getDataOutput(); 
     } catch (NotRealizedError e) { 
      e.printStackTrace(); 
     } 

     try { 

      String url= "rtp://192.168.1.99:49150/audio/1"; 
      MediaLocator m = new MediaLocator(url); 
      DataSink d = Manager.createDataSink(dataSource, m); 
      d.open(); 
      d.start(); 
      System.out.println("transmitting..."); 
      processor.start(); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

请问,如果你发现任何不正确或模糊的东西。 在此先感谢。 :)

澄清:我有C#代码RTP流式传输peice的。当我捕捉使用Wireshark的数据,我可以看到他们为RTP,但问题是,当我从JMF Wireshark的捕获数据流显示它们为UDP。而我的问题是,为什么?

我知道UDP和RTP的区别。

+0

我认为问题出在CONTENT_DESCRIPTOR上,它是raw-rtp。 – shibli049 2012-04-05 04:40:40

+0

我知道你的代码正在运行,除了你现在面临的问题。我们需要在JMF源代码中看到JMF在使用CONTENT_DESCRIPTOR时如何实现Processor类,就像Osbcure所说的那样。也许这是C#代码和Java JMF代码之间的区别。小心告诉你用于C#版本的流媒体库是什么? – ecle 2012-04-11 04:42:12

+0

@eee:C#项目使用pjsipDll,我刚刚从朋友那里拿来测试wireshark中的数据包,而我不习惯使用C#。所以,不能给你任何关于C#的更多细节。 – shibli049 2012-04-11 06:56:58

回答

5

如果我正确理解你的问题,你想知道为什么RTP包不确认为Wireshark的RTP包。根据我的经验,如果wireshark没有足够的有关RTP会话的信息,可能会出现这种情况。

例如:1)如果我嗅探一个使用RTSP或SIP和SDP设置的RTP会话,wireshark将显示检测RTP。 2)然而,在我使用本地SDP描述设置会话的另一个应用程序中,数据包显示为UDP。在第二种情况下,wireshark可以看到RTP数据包,但缺乏将它们分类为RTP的信息。由于RTP通常位于UDP之上,wireshark可以对UDP数据包进行分类,因此它们被归类为这样。仅供参考,您可以从流中选择一个您知道 RTP的数据包,然后选择“解码为”。然后从协议列表中选择合适的RTP(如果适用,则为另一个RTCP),然后wireshark将显示数据包为RTP,您将能够看到数据包信息。

我不确定这是否是您的具体情况中的原因,但也许您的JMF和C#示例之间存在信号差异?这听起来像你可能使用SIP的C#应用​​程序,没有任何JMF的?

+0

谢谢,这是我正在寻找的答案,完美的为我工作。现在wireshark将数据包识别为RTP。是的,SIP for C#和JMF都没有。 :) – shibli049 2012-04-11 10:14:01

8

RTP是应用层, UDP是传输层, 那是不一样的级别! 维基百科有助于详细解释。 所以你的数据被发送一个UDP “框架”

一个小的概述中的RTP流...

应用层:

* DHCP 
* DHCPv6 
* DNS 
* FTP 
* HTTP 
* IMAP 
* IRC 
* LDAP 
* MGCP 
* NNTP 
* BGP 
* NTP 
* POP 
* RPC 
* RTP 
* RTSP 
* RIP 
* SIP 
* SMTP 
* SNMP 
* SOCKS 
* SSH 
* Telnet 
* TLS/SSL 
* XMPP 
* (more) 

传输层

* TCP 
* UDP 
* DCCP 
* SCTP 
* RSVP 
* (more) 

互联网层

* IP 
     o IPv4 
     o IPv6 
* ICMP 
* ICMPv6 
* ECN 
* IGMP 
* IPsec 
* (more) 

链路层

* ARP/InARP 
* NDP 
* OSPF 
* Tunnels 
     o L2TP 
* PPP 
* Media access control 
     o Ethernet 
     o DSL 
     o ISDN 
     o FDDI 
* (more) 
+0

+1为你的好解释。但是,我已经知道他们。我对我的问题作了澄清。请你看看。并给我一个答案。 – shibli049 2012-04-11 04:13:14

相关问题