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

📄 rtppresenting.html

📁 jmf指导文件参考资料
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<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:10">
<title>Receiving and Presenting 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="RTPArchitecture.html">PREV </a> |
    <a href="RTPSending.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="104326"> </a><font  size="3" face="Palatino, Times New Roman, Times, serif">9 <br></font>
</div>
<div align="right">
<h2>
  <a name="110034"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Receiving and Presenting RTP Media Streams</font>
</h2>
</div>

<p>
  <a name="107455"> </a><font face="Palatino, Times New Roman, Times, serif">JMF <code>Players</code> and <code>Processors</code> provide the presentation, capture, and data conversion mechanisms for RTP streams. </font>
</p>


<a name="108222"> </a><font  size="1" face="Palatino, Times New Roman, Times, serif"><img src="images/RTPPresentinga.gif" height="117" width="480">
<br></font>


<a name="107448"> </a><font  size="2" face="Palatino, Times New Roman, Times, serif">Figure 9-1:   RTP reception data flow.<br></font>


<p>
  <a name="110048"> </a><font face="Palatino, Times New Roman, Times, serif">A separate player is used for each stream received by the session manager. You construct a <code>Player</code> for an RTP stream through the standard <code>Manager</code> <code>createPlayer</code> mechanism. You can either:</font>
</p>

<ul>
  <li><a name="104998"> </a><font face="Palatino, Times New Roman, Times, serif">Use a <code>MediaLocator</code> that has the parameters of the RTP session and construct a <code>Player</code> by calling <code>Manager.createPlayer(MediaLocator)</code></font>
  <li><a name="104999"> </a><font face="Palatino, Times New Roman, Times, serif">Construct a <code>Player</code> for a particular <code>ReceiveStream</code> by retrieving the <code>DataSource</code> from the stream and passing it to <code>Manager.createPlayer(DataSource</code>). </font>
</ul>

<p>
  <a name="107631"> </a><font face="Palatino, Times New Roman, Times, serif">If you use a <code>MediaLocator</code> to construct a <code>Player</code>, you can only present the first RTP stream that's detected in the session. If you want to play back multiple RTP streams in a session, you need to use the <code>SessionManager</code> directly and construct a <code>Player</code> for each <code>ReceiveStream</code>. </font>
</p>


<h3>
  <a name="107637"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Creating a Player for an RTP Session</font>
</h3>


<p>
  <a name="105158"> </a><font face="Palatino, Times New Roman, Times, serif">When you use a<code> MediaLocator</code> to construct a <code>Player</code> for an RTP session, the <code>Manager</code> creates a <code>Player</code> for the first stream detected in the session. This <code>Player</code> posts a <code>RealizeCompleteEvent</code> once data has been detected in the session. </font>
</p>


<p>
  <a name="108117"> </a><font face="Palatino, Times New Roman, Times, serif">By listening for the <code>RealizeCompleteEvent</code>, you can determine whether or not any data has arrived and if the <code>Player</code> is capable of presenting any data. Once the <code>Player</code> posts this event, you can retrieve its visual and control components. </font>
</p>


<p>
  <a name="108096"> </a><font face="Palatino, Times New Roman, Times, serif">Note:  Because a <code>Player</code> for an RTP media stream doesn't finish realizing until data is detected in the session, you shouldn't try to use <code>Manager.createRealizedPlayer</code> to construct a <code>Player</code> for an RTP media stream. No <code>Player</code> would be returned until data arrives and if no data is detected, attempting to create a <em>Realized</em> <code>Player</code> would block indefinitely. </font>
</p>


<p>
  <a name="105181"> </a><font face="Palatino, Times New Roman, Times, serif">A <code>Player</code> can export one RTP-specific control, <code>RTPControl</code>, which provides overall session statistics and can be used for registering dynamic payloads with the <code>SessionManager</code>. </font>
</p>


<a name="107724"> </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="110417"> </a>Example 9-1:   Creating a Player for an RTP session (1 of 2)</font></i></b></caption>
  <tr>
    <td><font face="Palatino, Times New Roman, Times, serif"><pre>
<a name="113392"> </a><code>       String url= "rtp://224.144.251.104:49150/audio/1";
</code><a name="113393"> </a>
<a name="113394"> </a><code>        MediaLocator mrl= new MediaLocator(url);
</code><a name="113395"> </a><code>        
</code><a name="113396"> </a><code>        if (mrl == null) {
</code><a name="113397"> </a><code>            System.err.println("Can't build MRL for RTP");
</code><a name="113398"> </a><code>            return false;
</code><a name="113399"> </a><code>        }
</code><a name="113400"> </a><code>        
</code><a name="113401"> </a><code>        // Create a player for this rtp session
</code><a name="113402"> </a><code>        try {
</code><a name="113403"> </a><code>            player = Manager.createPlayer(mrl);
</code><a name="113404"> </a><code>        } catch (NoPlayerException e) {
</code><a name="113405"> </a><code>            System.err.println("Error:" + e);
</code><a name="113406"> </a><code>            return false;
</code><a name="113407"> </a><code>        } catch (MalformedURLException e) {
</code><a name="113408"> </a><code>            System.err.println("Error:" + e);
</code><a name="113409"> </a><code>            return false;
</code><a name="113410"> </a><code>        } catch (IOException e) {
</code><a name="113411"> </a><code>            System.err.println("Error:" + e);
</code><a name="113412"> </a><code>            return false;
</code><a name="113413"> </a><code>        }
</code><a name="113414"> </a><code>        
</code><a name="113415"> </a><code>        if (player != null) {
</code><a name="112310"> </a><code>            if (this.player == null) {
</code></pre>
</font></td>
  </tr>
  <tr>
    <td><font face="Palatino, Times New Roman, Times, serif"><pre>
<a name="113424"> </a>                this.player = player;
<a name="113425"> </a>                player.addControllerListener(this);
<a name="113426"> </a>                player.realize();
<a name="113427"> </a>            }
<a name="113428"> </a>        }
</pre>
</font></td>
  </tr>
</table>



<br></font>


<h4>
  <a name="110414"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Listening for Format Changes</font>
</h4>


<p>
  <a name="107725"> </a><font face="Palatino, Times New Roman, Times, serif">When a <code>Player</code> posts a <code>FormatChangeEvent</code>, it might indicate that a payload change has occurred. <code>Players</code> constructed with a <code>MediaLocator</code> automatically process payload changes. In most cases, this processing involves constructing a new <code>Player</code> to handle the new format. Applications that present RTP media streams need to listen for <code>FormatChangeEvents</code> so that they can respond if a new <code>Player</code> is created.</font>
</p>


<p>
  <a name="107929"> </a><font face="Palatino, Times New Roman, Times, serif">When a <code>FormatChangeEvent</code> is posted, check whether or not the <code>Player</code> object's control and visual components have changed. If they have, a new <code>Player</code> has been constructed and you need to remove references to the old <code>Player </code>object's components and get the new <code>Player </code>object's<code> </code>components.</font>
</p>


<a name="110620"> </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="110850"> </a>Example 9-2:   Listening for RTP format changes  (1 of 2)</font></i></b></caption>
  <tr>
    <td><font face="Palatino, Times New Roman, Times, serif"><pre>
<a name="110743"> </a><code>    public synchronized void controllerUpdate(ControllerEvent ce) {
</code><a name="110744"> </a><code>        if (ce instanceof FormatChangeEvent) {
</code><a name="110745"> </a><code>            Dimension vSize = new Dimension(320,0);
</code><a name="110746"> </a><code>            Component oldVisualComp = visualComp;
</code><a name="110747"> </a><code>            
</code><a name="110748"> </a><code>            if ((visualComp = player.getVisualComponent()) != null) {
</code><a name="110749"> </a><code>                if (oldVisualComp != visualComp) {
</code><a name="110750"> </a><code>                    if (oldVisualComp != null) {
</code><a name="110751"> </a><code>                        oldVisualComp.remove(zoomMenu);
</code><a name="110752"> </a><code>                    }
</code><a name="110753"> </a><code>                    
</code><a name="110754"> </a><code>                    framePanel.remove(oldVisualComp);
</code><a name="110755"> </a><code>                    
</code><a name="110756"> </a><code>                    vSize = visualComp.getPreferredSize();
</code><a name="110757"> </a><code>                    vSize.width = (int)(vSize.width * defaultScale);
</code><a name="110758"> </a><code>                    vSize.height = (int)(vSize.height * defaultScale);
</code><a name="110759"> </a><code>                    
</code><a name="110760"> </a><code>                    framePanel.add(visualComp);
</code><a name="110761"> </a><code>                    
</code><a name="110762"> </a><code>                    visualComp.setBounds(0, 
</code><a name="110763"> </a><code>                                         0, 
</code><a name="110764"> </a><code>                                         vSize.width, 
</code><a name="110765"> </a><code>                                         vSize.height);
</code><a name="112796"> </a><code>                    addPopupMenu(visualComp);
</code><a name="112791"> </a><code>                }
</code></pre>
</font></td>
  </tr>
  <tr>
    <td><font face="Palatino, Times New Roman, Times, serif"><pre>
<a name="112801"> </a><code>            }
</code><a name="110846"> </a>
<a name="110802"> </a><code>            Component oldComp = controlComp;
</code><a name="110803"> </a><code>            
</code><a name="110804"> </a><code>            controlComp = player.getControlPanelComponent();
</code><a name="110805"> </a>
<a name="110806"> </a><code>            if (controlComp != null) 
</code><a name="110807"> </a><code>            {
</code><a name="110808"> </a><code>                if (oldComp != controlComp)
</code><a name="110809"> </a><code>                {
</code><a name="110810"> </a><code>                    framePanel.remove(oldComp);
</code><a name="110811"> </a><code>                    framePanel.add(controlComp);
</code><a name="110812"> </a><code>                                         
</code><a name="110813"> </a><code>                    if (controlComp != null) {
</code><a name="110814"> </a><code>                        int prefHeight = controlComp
</code><a name="110815"> </a><code>                                         .getPreferredSize()
</code><a name="110816"> </a><code>                                         .height;
</code><a name="110817"> </a><code>                        
</code><a name="110818"> </a><code>                        controlComp.setBounds(0, 
</code><a name="110819"> </a><code>                                              vSize.height,
</code><a name="110820"> </a><code>                                              vSize.width,
</code><a name="110821"> </a><code>                                              prefHeight);
</code><a name="110822"> </a><code>                    }
</code><a name="110823"> </a><code>                }
</code><a name="110824"> </a><code>            }
</code><a name="110825"> </a><code>        }
</code><a name="110826"> </a><code>    }
</code></pre>
</font></td>
  </tr>
</table>



<br></font>


<h3>
  <a name="107661"> </a><font color="#003366" face="Palatino, Times New Roman, Times, serif">Creating an RTP Player for Each New Receive Stream</font>
</h3>


<p>
  <a name="110501"> </a><font face="Palatino, Times New Roman, Times, serif">To play all of the <code>ReceiveStreams</code> in a session, you need to create a separate <code>Player</code> for each stream. When a new stream is created, the session manager posts a <code>NewReceiveStreamEvent</code>. Generally, you register as a <code>ReceiveStreamListener</code> and construct a <code>Player</code> for each new <code>ReceiveStream</code>. To construct the <code>Player</code>, you retrieve the <code>DataSource</code> from the <code>ReceiveStream</code> and pass it to <code>Manager.createPlayer</code>. </font>

⌨️ 快捷键说明

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