⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtpsending.html

📁 jmf指导文件参考资料
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Quadralay WebWorks Publisher 5.0.2">
<meta name="TEMPLATEBASE" content="Portable HTML">
<meta name="LASTUPDATED" content="11/23/99 11:48:11">
<title>Transmitting RTP Media Streams   </title>
</head>

<body link="#3366CC" vlink="#9999CC" text="#000000" alink="#0000CC" bgcolor="#FFFFFF"
background="images/backgrnd.gif">


<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
  <tr>
    <td><a href="JMFTOC.html">CONTENTS</a> | 
    <a href="RTPPresenting.html">PREV </a> |
    <a href="RTPExporting.html">NEXT</a> |
    <a href="JMFIX.html">INDEX</a></td>
    <td align="right"><em>JMF 2.0 API Guide</em>
  </tr>
</table>

<p><br clear="all">
</p>

<hr align="left">

<blockquote>
<div align="right">
<a name="104576"> </a><font  size="3" face="Palatino, Times New Roman, Times, serif">10 <br></font>
</div>
<div align="right">
<h2>
  <a name="107457"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Transmitting RTP Media Streams </font>
</h2>
</div>

<p>
  <a name="104601"> </a><font face="Palatino, Times New Roman, Times, serif">To transmit an RTP stream, you use a <code>Processor</code> to produce an RTP-encoded <code>DataSource</code> and construct either a<code> SessionManager </code>or<code> DataSink </code>to control the transmission. </font>
</p>


<p>
  <a name="107737"> </a><font face="Palatino, Times New Roman, Times, serif">The input to the <code>Processor</code> can be either stored or live captured data. For stored data, you can use a <code>MediaLocator</code> to identify the file when you create the <code>Processor</code>. For captured data, a capture <code>DataSource </code>is used as the input to the <code>Processor</code>, as described in <a href="JMFCapturing.html#95169">Capturing Media Data</a>. </font>
</p>


<p>
  <a name="105028"> </a><font face="Palatino, Times New Roman, Times, serif">There are two ways to transmit RTP streams:</font>
</p>

<ul>
  <li><a name="105034"> </a><font face="Palatino, Times New Roman, Times, serif">Use a <code>MediaLocator</code> that has the parameters of the RTP session to construct an RTP <code>DataSink</code> by calling <code>Manager.createDataSink</code>.</font>
  <li><a name="105064"> </a><font face="Palatino, Times New Roman, Times, serif">Use a session manager to create send streams for the content and control the transmission.</font>
</ul>

<p>
  <a name="105065"> </a><font face="Palatino, Times New Roman, Times, serif">If you use a<code> MediaLocator</code> to construct an RTP <code>DataSink</code>, you can only transmit the first stream in the <code>DataSource</code>. If you want to transmit multiple RTP streams in a session or need to monitor session statistics, you need to use the <code>SessionManager</code> directly.</font>
</p>


<p>
  <a name="105154"> </a><font face="Palatino, Times New Roman, Times, serif">Regardless of how you choose to transmit the RTP stream, you need to:</font>
</p>

<ol type="1">
  <li value="1"><a name="105145"> </a><font face="Palatino, Times New Roman, Times, serif">Create a <code>Processor</code> with a <code>DataSource</code> that represents the data you want to transmit.</font>
  <li value="2"><a name="105147"> </a><font face="Palatino, Times New Roman, Times, serif">Configure the <code>Processor</code> to output RTP-encoded data. </font>
  <li value="3"><a name="105148"> </a><font face="Palatino, Times New Roman, Times, serif">Get the output from the <code>Processor</code> as a <code>DataSource</code>.</font>
</ol>

<h4>
  <a name="105149"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Configuring the Processor</font>
</h4>


<p>
  <a name="104948"> </a><font face="Palatino, Times New Roman, Times, serif">To configure the <code>Processor </code>to generate RTP-encoded data, you set RTP-specific formats for each track and specify the output content descriptor you want. </font>
</p>


<p>
  <a name="104924"> </a><font face="Palatino, Times New Roman, Times, serif">The track formats are set by getting the <code>TrackControl</code> for each track and calling <code>setFormat</code> to specify an RTP-specific format. An RTP-specific format is selected by setting the encoding string of the format to an RTP-specific string such as "<code>AudioFormat.GSM_RTP</code>". The <code>Processor</code> attempts to load a plug-in that supports this format. If no appropriate plug-in is installed, that particular RTP format cannot be supported and an <code>UnSupportedFormatException</code> is thrown. </font>
</p>


<p>
  <a name="104966"> </a><font face="Palatino, Times New Roman, Times, serif">The output format is set with the <code>setOutputContentDescriptor</code> method. If no special multiplexing is required, the output content descriptor can be set to <code>"ContentDescriptor.RAW"</code>. Audio and video streams should not be interleaved. If the <code>Processor</code>'s tracks are of different media types, each media stream is transmitted in a separate RTP session. </font>
</p>


<h4>
  <a name="104694"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Retrieving the Processor Output</font>
</h4>


<p>
  <a name="104656"> </a><font face="Palatino, Times New Roman, Times, serif">Once the format of a <code>Processor</code>'s track has been set and the <code>Processor</code> has been realized, the output <code>DataSource</code> of the <code>Processor</code> can be retrieved. You retrieve the output of the <code>Processor</code> as a <code>DataSource</code> by calling <code>getDataOutput</code>. The returned <code>DataSource</code> can be either a <code>PushBufferDataSource</code> or a <code>PullBufferDataSource</code>, depending on the source of the data. </font>
</p>


<p>
  <a name="104810"> </a><font face="Palatino, Times New Roman, Times, serif">The output <code>DataSource</code> is connected to the <code>SessionManager</code> using the <code>createSendStream</code> method. The session manager must be initialized before you can create the send stream. </font>
</p>


<p>
  <a name="104821"> </a><font face="Palatino, Times New Roman, Times, serif">If the <code>DataSource</code> contains multiple <code>SourceStreams</code>, each <code>SourceStream</code> is sent out as a separate RTP stream, either in the same session or a different session. If the <code>DataSource</code> contains both audio and video streams, separate RTP sessions must be created for audio and video. You can also clone the <code>DataSource</code> and send the clones out as different RTP streams in either the same session or different sessions.</font>
</p>


<h4>
  <a name="106122"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Controlling the Packet Delay </font>
</h4>


<p>
  <a name="106123"> </a><font face="Palatino, Times New Roman, Times, serif">The packet delay, also known as the packetization interval, is the time represented by each RTP packet as it is transmitted over the network. The packetization interval determines the minimum end-to-end delay; longer packets introduce less header overhead but higher delay and make packet loss more noticeable. For non-interactive applications such as lectures, or for links with severe bandwidth constraints, a higher packetization delay might be appropriate. </font>
</p>


<p>
  <a name="106124"> </a><font face="Palatino, Times New Roman, Times, serif">A receiver should accept packets representing between 0 and 200 ms of audio data. (For framed audio encodings, a receiver should accept packets with 200 ms divided by the frame duration, rounded up.) This restriction allows reasonable buffer sizing for the receiver. Each packetizer codec has a default packetization interval appropriate for its encoding. </font>
</p>


<p>
  <a name="106125"> </a><font face="Palatino, Times New Roman, Times, serif">If the codec allows modification of this interval, it exports a corresponding <code>PacketSizeControl</code>. The packetization interval can be changed or set by through the <code>setPacketSize</code> method. </font>
</p>


<p>
  <a name="106126"> </a><font face="Palatino, Times New Roman, Times, serif">For video streams, a single video frame is transmitted in multiple RTP packets. The size of each packet is limited by the Maximum Transmission Unit (MTU) of the underlying network. This parameter is also set using the <code>setPacketSize</code> method of the packetizer codec's <code>PacketSizeControl</code>.</font>
</p>


<h3>
  <a name="105175"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Transmitting RTP Data With a Data Sink</font>
</h3>


<p>
  <a name="105272"> </a><font face="Palatino, Times New Roman, Times, serif">The simplest way to transmit RTP data is to construct an RTP <code>DataSink</code> using the <code>Manager.createDataSink</code> method. You pass in the output <code>DataSource </code>from the <code>Processor </code>and a <code>MediaLocator</code> that describes the RTP session to which the <code>DataSource</code> is to be streamed. (The <code>MediaLocator</code> provides the address and port of the RTP session.) </font>
</p>


<p>
  <a name="105273"> </a><font face="Palatino, Times New Roman, Times, serif">To control the transmission, you call <code>start</code> and <code>stop</code> on the <code>DataSink</code>. Only the first stream in the <code>DataSource</code> is transmitted.</font>
</p>


<p>
  <a name="105279"> </a><font face="Palatino, Times New Roman, Times, serif">In <a href="RTPSending.html#107976">Example 10-1</a>, live audio is captured and then transmitted using a <code>DataSink</code>.</font>
</p>


<a name="107973"> </a><font  size="1" face="Palatino, Times New Roman, Times, serif">

<table border="1" bordercolorlight="#FFFFFF" bordercolordark="#000000"
       cellpadding="5" cellspacing="0">
  <caption><b><i><font face="Palatino, Times New Roman, Times, serif"><a name="107976"> </a>Example 10-1:   Transmitting RTP Data using a DataSink  (1 of 2)</font></i></b></caption>
  <tr>
    <td><font face="Palatino, Times New Roman, Times, serif"><pre>
<a name="109971"> </a><code>        // First find a capture device that will capture linear audio
</code><a name="109972"> </a><code>        // data at 8bit 8Khz 
</code><a name="109973"> </a><code>        
</code><a name="109974"> </a><code>        AudioFormat format= new AudioFormat(AudioFormat.LINEAR, 
</code><a name="109975"> </a><code>                                            8000, 
</code><a name="109976"> </a><code>                                            8, 
</code><a name="109977"> </a><code>                                            1); 
</code><a name="109978"> </a>
<a name="109979"> </a><code>        Vector devices= CaptureDeviceManager.getDeviceList( format);
</code><a name="109980"> </a>
<a name="109981"> </a><code>        CaptureDeviceInfo di= null;
</code><a name="109982"> </a>
<a name="109983"> </a><code>        if (devices.size() &gt; 0) {
</code><a name="109984"> </a><code>             di = (CaptureDeviceInfo) devices.elementAt( 0);
</code><a name="109985"> </a><code>        }
</code><a name="109986"> </a><code>        else {
</code><a name="109987"> </a><code>            // exit if we could not find the relevant capturedevice. 
</code><a name="109988"> </a><code>            System.exit(-1); 
</code><a name="109989"> </a><code>        }
</code><a name="109990"> </a><code>       
</code><a name="109991"> </a><code>        // Create a processor for this capturedevice &amp; exit if we 
</code><a name="109992"> </a><code>        // cannot create it 
</code><a name="109993"> </a><code>        try { 
</code><a name="109994"> </a><code>            Processor p = Manager.createProcessor(di.getLocator()); 
</code><a name="109995"> </a><code>        } catch (IOException e) { 
</code><a name="109996"> </a><code>            System.exit(-1); 
</code><a name="109997"> </a><code>        } catch (NoProcessorException e) { 
</code><a name="109998"> </a><code>            System.exit(-1); 
</code><a name="109999"> </a><code>        } 
</code><a name="110000"> </a>
<a name="110001"> </a><code>       // configure the processor  
</code><a name="110002"> </a><code>       processor.configure(); 
</code><a name="110003"> </a><code>       
</code><a name="110004"> </a><code>       // block until it has been configured 
</code><a name="110005"> </a><code>       
</code><a name="110006"> </a><code>       processor.setContentDescriptor( 
</code><a name="110007"> </a><code>           new ContentDescriptor( ContentDescriptor.RAW));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -