<!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 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 <fedemp@altern.org></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 <cstdlib></span> <span class="preprocessor">#include <<a class="code" href="rtp_8h.html" title="Generic and audio/video profile specific RTP interface of ccRTP.">ccrtp/rtp.h</a>></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& 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& 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 << <span class="stringliteral">"My SSRC identifier is: "</span> << hex << (int)getLocalSSRC() << endl; <a name="a2"></a><a class="code" href="group__sources.html#g206420a8423d0c261e9bfc5a388a9534" title="Get the RTPApplication object for the &quot;default&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 << <span class="stringliteral">"I got an app. data unit - "</span> << adu-><a name="a9"></a><a class="code" href="class_app_data_unit.html#f41ffb3a12208e4ec9f6aa1b1180eedd">getSize</a>() << <span class="stringliteral">" payload octets ("</span> << <span class="stringliteral">"pt "</span> << (int)adu-><a name="a10"></a><a class="code" href="class_app_data_unit.html#49592f6dd8c651597f78cf58f13464ab">getType</a>() << <span class="stringliteral">") from "</span> << hex << (int)adu-><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>() << <span class="stringliteral">"@"</span> << dec << adu-><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>() << <span class="stringliteral">":"</span> << adu-><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>() << 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>& src) { cout << <span class="stringliteral">"* New synchronization source: "</span> << hex << (int)src.<a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>() << 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>& source, SendReport& SR, uint8 blocks) { RTPSession::onGotSR(source,SR,blocks); cout << <span class="stringliteral">"I got an SR RTCP report from "</span> << hex << (int)source.<a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>() << <span class="stringliteral">"@"</span> << dec << source.<a class="code" href="class_sync_source.html#9f92cbd6190fecc9bba3a54217b0d00a">getNetworkAddress</a>() << <span class="stringliteral">":"</span> << source.<a name="a16"></a><a class="code" href="class_sync_source.html#56536e209e445a4f130e3e42a41bd027">getControlTransportPort</a>() << 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>& source, RecvReport& RR, uint8 blocks) { RTPSession::onGotRR(source,RR,blocks); cout << <span class="stringliteral">"I got an RR RTCP report from "</span> << hex << (int)source.<a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>() << <span class="stringliteral">"@"</span> << dec << source.<a class="code" href="class_sync_source.html#9f92cbd6190fecc9bba3a54217b0d00a">getNetworkAddress</a>() << <span class="stringliteral">":"</span> << source.<a class="code" href="class_sync_source.html#56536e209e445a4f130e3e42a41bd027">getControlTransportPort</a>() << 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>& source, SDESChunk& chunk, <span class="keywordtype">size_t</span> len) { <span class="keywordtype">bool</span> result = RTPSession::onGotSDESChunk(source,chunk,len); cout << <span class="stringliteral">"I got a SDES chunk from "</span> << hex << (int)source.<a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>() << <span class="stringliteral">"@"</span> << dec << source.<a class="code" href="class_sync_source.html#9f92cbd6190fecc9bba3a54217b0d00a">getNetworkAddress</a>() << <span class="stringliteral">":"</span> << source.<a class="code" href="class_sync_source.html#56536e209e445a4f130e3e42a41bd027">getControlTransportPort</a>() << <span class="stringliteral">" ("</span> << 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>()-><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>) << <span class="stringliteral">") "</span> << 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>& source, <span class="keyword">const</span> std::string& reason) { cout << <span class="stringliteral">"I got a Goodbye packet from "</span> << hex << (int)source.<a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>() << <span class="stringliteral">"@"</span> << dec << source.<a class="code" href="class_sync_source.html#9f92cbd6190fecc9bba3a54217b0d00a">getNetworkAddress</a>() << <span class="stringliteral">":"</span> << source.<a class="code" href="class_sync_source.html#56536e209e445a4f130e3e42a41bd027">getControlTransportPort</a>() << endl; cout << <span class="stringliteral">" Goodbye reason: \""</span> << reason << <span class="stringliteral">"\""</span> << endl; } }; <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) { cout << <span class="stringliteral">"rtplisten"</span> << endl; <span class="keywordflow">if</span> (argc != 3) { cerr << <span class="stringliteral">"Syntax: "</span> << <span class="stringliteral">" ip port"</span> << 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 << <span class="stringliteral">"Listening on multicast address "</span> << ima << <span class="stringliteral">":"</span> << port << endl; } <span class="keywordflow">else</span> { InetHostAddress ia(argv[1]); foo = <span class="keyword">new</span> Listener(ia,atoi(argv[2])); cout << <span class="stringliteral">"Listening on unicast address "</span> << ia << <span class="stringliteral">":"</span> << port << endl; } cout << <span class="stringliteral">"Press Ctrl-C to finish."</span> << endl; foo->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 <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>