Sophie

Sophie

distrib > Fedora > 13 > x86_64 > by-pkgid > 598246a3099b0106d22dd5249478d3b7 > files > 254

ccrtp-devel-1.7.1-2.fc12.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>ccRTP: rtplisten.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.9 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>rtplisten.cpp</h1><div class="fragment"><pre class="fragment"><span class="comment">// rtplisten</span>
<span class="comment">// Listen for RTP packets.</span>
<span class="comment">// Copyright (C) 2001,2002,2003,2004 Federico Montesino &lt;fedemp@altern.org&gt;</span>
<span class="comment">//  </span>
<span class="comment">// This program is free software; you can redistribute it and/or modify</span>
<span class="comment">// it under the terms of the GNU General Public License as published by</span>
<span class="comment">// the Free Software Foundation; either version 2 of the License, or</span>
<span class="comment">// (at your option) any later version.</span>
<span class="comment">//  </span>
<span class="comment">// This program is distributed in the hope that it will be useful,</span>
<span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment">// GNU General Public License for more details.</span>
<span class="comment">//  </span>
<span class="comment">// You should have received a copy of the GNU General Public License</span>
<span class="comment">// along with this program; if not, write to the Free Software</span>
<span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>

<span class="preprocessor">#include &lt;cstdlib&gt;</span>
<span class="preprocessor">#include &lt;<a class="code" href="rtp_8h.html" title="Generic and audio/video profile specific RTP interface of ccRTP.">ccrtp/rtp.h</a>&gt;</span>

<span class="preprocessor">#ifdef  CCXX_NAMESPACES</span>
<span class="preprocessor"></span><span class="keyword">using namespace </span>ost;
<span class="keyword">using namespace </span>std;
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="keyword">class </span>Listener: <a name="_a0"></a><a class="code" href="class_single_thread_r_t_p_session.html" title="This template class adds the threading aspect to the RTPSessionBase template in one...">RTPSession</a> {
<span class="keyword">public</span>:
        Listener(InetMcastAddress&amp; ima, tpport_t port):
                <a name="a1"></a><a class="code" href="group__sessions.html#g24e16f350c9ae0c1e2a3f5d6a6dad9f9" title="Uses two pairs of sockets for RTP data and RTCP transmission/reception.">RTPSession</a>(ima,port)
        { }

        Listener(InetHostAddress&amp; ia, tpport_t port):
                <a class="code" href="group__sessions.html#g24e16f350c9ae0c1e2a3f5d6a6dad9f9" title="Uses two pairs of sockets for RTP data and RTCP transmission/reception.">RTPSession</a>(ia,port)
        { }

        <span class="keywordtype">void</span> listen()
        {
                cout &lt;&lt; <span class="stringliteral">"My SSRC identifier is: "</span> 
                     &lt;&lt; hex &lt;&lt; (int)getLocalSSRC() &lt;&lt; endl;

                <a name="a2"></a><a class="code" href="group__sources.html#g206420a8423d0c261e9bfc5a388a9534" title="Get the RTPApplication object for the &amp;quot;default&amp;quot; application (the only one...">defaultApplication</a>().<a name="a3"></a><a class="code" href="class_r_t_p_application.html#8f508dc361e2127b6ce494af67ca41c6">setSDESItem</a>(<a name="a4"></a><a class="code" href="group__rtcppacket.html#ggf6d38e5ccbbcdf2a24ebbd4fc5b4eeac34f49dfe99b37116fd6459c6b20435f2" title="Application or tool.">SDESItemTypeTOOL</a>,
                                                 <span class="stringliteral">"rtplisten demo app."</span>);
                setExpireTimeout(1000000);

                setPayloadFormat(<a name="_a5"></a><a class="code" href="class_static_payload_format.html" title="Static payload format objects.">StaticPayloadFormat</a>(<a name="a6"></a><a class="code" href="group__payload.html#gg7644623ce29b8ca519d7e3f276b6ddc6095b083465fe4d6597ba586e0116022c" title="ITU-T G.711. mu-law audio 8 Khz (RFC 1890).">sptPCMU</a>));
                <a name="a7"></a><a class="code" href="class_single_thread_r_t_p_session.html#e861fb5d15be69ea35da87ee41ad6b0b" title="Activate stack and start service thread.">startRunning</a>();
                <span class="keywordflow">for</span> (;;) {
                        <span class="keyword">const</span> <a name="_a8"></a><a class="code" href="class_app_data_unit.html" title="Interface (envelope) to data received over RTP packets.">AppDataUnit</a>* adu;
                        <span class="keywordflow">while</span> ( (adu = getData(getFirstTimestamp())) ) {
                                cerr &lt;&lt; <span class="stringliteral">"I got an app. data unit - "</span>
                                     &lt;&lt; adu-&gt;<a name="a9"></a><a class="code" href="class_app_data_unit.html#f41ffb3a12208e4ec9f6aa1b1180eedd">getSize</a>()
                                     &lt;&lt; <span class="stringliteral">" payload octets ("</span>
                                     &lt;&lt; <span class="stringliteral">"pt "</span> &lt;&lt; (int)adu-&gt;<a name="a10"></a><a class="code" href="class_app_data_unit.html#49592f6dd8c651597f78cf58f13464ab">getType</a>()
                                     &lt;&lt; <span class="stringliteral">") from "</span>
                                     &lt;&lt; hex &lt;&lt; (int)adu-&gt;<a name="a11"></a><a class="code" href="class_app_data_unit.html#be3507d58bdbd17c57846f3679d5f2d1">getSource</a>().<a name="a12"></a><a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>() 
                                     &lt;&lt; <span class="stringliteral">"@"</span> &lt;&lt; dec &lt;&lt;
                                        adu-&gt;<a class="code" href="class_app_data_unit.html#be3507d58bdbd17c57846f3679d5f2d1">getSource</a>().<a name="a13"></a><a class="code" href="class_sync_source.html#9f92cbd6190fecc9bba3a54217b0d00a">getNetworkAddress</a>()
                                     &lt;&lt; <span class="stringliteral">":"</span> 
                                     &lt;&lt; adu-&gt;<a class="code" href="class_app_data_unit.html#be3507d58bdbd17c57846f3679d5f2d1">getSource</a>().<a name="a14"></a><a class="code" href="class_sync_source.html#d8646f90825758d06c9f63a13be9b58c">getDataTransportPort</a>()
                                     &lt;&lt; endl;
                                <span class="keyword">delete</span> adu;
                        }
                        Thread::sleep(7);
                }
        }

        <span class="comment">// redefined from IncomingDataQueue</span>
        <span class="keywordtype">void</span> onNewSyncSource(<span class="keyword">const</span> <a name="_a15"></a><a class="code" href="class_sync_source.html" title="Synchronization source in an RTP session.">SyncSource</a>&amp; src)
        {
                cout &lt;&lt; <span class="stringliteral">"* New synchronization source: "</span> &lt;&lt;
                     hex &lt;&lt; (int)src.<a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>() &lt;&lt; endl;
        }

        <span class="comment">// redefined from QueueRTCPManager</span>
        <span class="keywordtype">void</span>
        onGotSR(<a class="code" href="class_sync_source.html" title="Synchronization source in an RTP session.">SyncSource</a>&amp; source, SendReport&amp; SR, uint8 blocks)
        {
                RTPSession::onGotSR(source,SR,blocks);
                cout &lt;&lt; <span class="stringliteral">"I got an SR RTCP report from "</span>
                     &lt;&lt; hex &lt;&lt; (int)source.<a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>() &lt;&lt; <span class="stringliteral">"@"</span>
                     &lt;&lt; dec
                     &lt;&lt; source.<a class="code" href="class_sync_source.html#9f92cbd6190fecc9bba3a54217b0d00a">getNetworkAddress</a>() &lt;&lt; <span class="stringliteral">":"</span> 
                     &lt;&lt; source.<a name="a16"></a><a class="code" href="class_sync_source.html#56536e209e445a4f130e3e42a41bd027">getControlTransportPort</a>() &lt;&lt; endl;
        }

        <span class="comment">// redefined from QueueRTCPManager</span>
        <span class="keywordtype">void</span>
        onGotRR(<a class="code" href="class_sync_source.html" title="Synchronization source in an RTP session.">SyncSource</a>&amp; source, RecvReport&amp; RR, uint8 blocks)
        {
                RTPSession::onGotRR(source,RR,blocks);
                cout &lt;&lt; <span class="stringliteral">"I got an RR RTCP report from "</span>
                     &lt;&lt; hex &lt;&lt; (int)source.<a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>() &lt;&lt; <span class="stringliteral">"@"</span>
                     &lt;&lt; dec
                     &lt;&lt; source.<a class="code" href="class_sync_source.html#9f92cbd6190fecc9bba3a54217b0d00a">getNetworkAddress</a>() &lt;&lt; <span class="stringliteral">":"</span> 
                     &lt;&lt; source.<a class="code" href="class_sync_source.html#56536e209e445a4f130e3e42a41bd027">getControlTransportPort</a>() &lt;&lt; endl;
        }

        <span class="comment">// redefined from QueueRTCPManager</span>
        <span class="keywordtype">bool</span>
        onGotSDESChunk(<a class="code" href="class_sync_source.html" title="Synchronization source in an RTP session.">SyncSource</a>&amp; source, SDESChunk&amp; chunk, <span class="keywordtype">size_t</span> len)
        { 
                <span class="keywordtype">bool</span> result = RTPSession::onGotSDESChunk(source,chunk,len);
                cout &lt;&lt; <span class="stringliteral">"I got a SDES chunk from "</span>
                     &lt;&lt; hex &lt;&lt; (int)source.<a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>() &lt;&lt; <span class="stringliteral">"@"</span> 
                     &lt;&lt; dec
                     &lt;&lt; source.<a class="code" href="class_sync_source.html#9f92cbd6190fecc9bba3a54217b0d00a">getNetworkAddress</a>() &lt;&lt; <span class="stringliteral">":"</span> 
                     &lt;&lt; source.<a class="code" href="class_sync_source.html#56536e209e445a4f130e3e42a41bd027">getControlTransportPort</a>()
                     &lt;&lt; <span class="stringliteral">" ("</span> 
                     &lt;&lt; source.<a name="a17"></a><a class="code" href="class_sync_source.html#2be8658512af88c5a25f2786d7024d37" title="Get the participant this synchronization source is asociated to.">getParticipant</a>()-&gt;<a name="a18"></a><a class="code" href="class_participant.html#09080be78b19740b978800a1ec51bc3e" title="Get the value of an SDES item.">getSDESItem</a>(<a name="a19"></a><a class="code" href="group__rtcppacket.html#ggf6d38e5ccbbcdf2a24ebbd4fc5b4eeac56818aeaa2d578ab0055a59b8d8d28f9" title="Canonical end-point identifier.">SDESItemTypeCNAME</a>)
                     &lt;&lt; <span class="stringliteral">") "</span> &lt;&lt; endl;
                <span class="keywordflow">return</span> result;
        }
        
        <span class="keywordtype">void</span>
        onGotGoodbye(<span class="keyword">const</span> <a class="code" href="class_sync_source.html" title="Synchronization source in an RTP session.">SyncSource</a>&amp; source, <span class="keyword">const</span> std::string&amp; reason)
        { 
                cout &lt;&lt; <span class="stringliteral">"I got a Goodbye packet from "</span>
                     &lt;&lt; hex &lt;&lt; (int)source.<a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>() &lt;&lt; <span class="stringliteral">"@"</span> 
                     &lt;&lt; dec
                     &lt;&lt; source.<a class="code" href="class_sync_source.html#9f92cbd6190fecc9bba3a54217b0d00a">getNetworkAddress</a>() &lt;&lt; <span class="stringliteral">":"</span> 
                     &lt;&lt; source.<a class="code" href="class_sync_source.html#56536e209e445a4f130e3e42a41bd027">getControlTransportPort</a>() &lt;&lt; endl;
                cout &lt;&lt; <span class="stringliteral">"   Goodbye reason: \""</span> &lt;&lt; reason &lt;&lt; <span class="stringliteral">"\""</span> &lt;&lt; endl;
        }
};

<span class="keywordtype">int</span>
main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
{
        cout &lt;&lt; <span class="stringliteral">"rtplisten"</span> &lt;&lt; endl;

        <span class="keywordflow">if</span> (argc != 3) { 
                cerr &lt;&lt; <span class="stringliteral">"Syntax: "</span> &lt;&lt; <span class="stringliteral">" ip port"</span> &lt;&lt; endl;
                exit(1);
        }

        InetMcastAddress ima;
        <span class="keywordflow">try</span> {
                ima = InetMcastAddress(argv[1]);
        } <span class="keywordflow">catch</span> (...) { }

        Listener *foo;
        tpport_t port = atoi(argv[2]);
        <span class="keywordflow">if</span> ( ima.isInetAddress() ) {
                foo = <span class="keyword">new</span> Listener(ima,port);
                cout &lt;&lt; <span class="stringliteral">"Listening on multicast address "</span> &lt;&lt; ima &lt;&lt; <span class="stringliteral">":"</span> &lt;&lt; 
                        port &lt;&lt; endl;
        } <span class="keywordflow">else</span> {
                InetHostAddress ia(argv[1]);
                foo = <span class="keyword">new</span> Listener(ia,atoi(argv[2]));
                cout &lt;&lt; <span class="stringliteral">"Listening on unicast address "</span> &lt;&lt; ia &lt;&lt; <span class="stringliteral">":"</span> &lt;&lt;
                        port &lt;&lt; endl;
        }
        cout &lt;&lt; <span class="stringliteral">"Press Ctrl-C to finish."</span> &lt;&lt; endl;
        foo-&gt;listen();
        <span class="keyword">delete</span> foo;
        <span class="keywordflow">return</span> 0;
}

</pre></div> </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jul 24 21:42:25 2009 for ccRTP by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>