Sophie

Sophie

distrib > Fedora > 14 > i386 > by-pkgid > 598246a3099b0106d22dd5249478d3b7 > files > 29

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: ccrtptest.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>ccrtptest.cpp</h1><div class="fragment"><pre class="fragment"><span class="comment">// test ccRTP functionality</span>
<span class="comment">// Copyright (C) 2004 Federico Montesino Pouzols &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>PacketsPattern
{
<span class="keyword">public</span>:
        <span class="keyword">inline</span> <span class="keyword">const</span> InetHostAddress&amp;
        getDestinationAddress()<span class="keyword"> const</span>
<span class="keyword">        </span>{ <span class="keywordflow">return</span> destinationAddress; }

        <span class="keyword">inline</span> <span class="keyword">const</span> tpport_t
        getDestinationPort()<span class="keyword"> const</span>
<span class="keyword">        </span>{ <span class="keywordflow">return</span> destinationPort; }

        uint32
        getPacketsNumber()<span class="keyword"> const</span>
<span class="keyword">        </span>{ <span class="keywordflow">return</span> packetsNumber; }

        <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*
        getPacketData(uint32 i)
        { <span class="keywordflow">return</span> data; }
        
        <span class="keyword">const</span> <span class="keywordtype">size_t</span>
        getPacketSize(uint32 i)
        { <span class="keywordflow">return</span> packetsSize; }

<span class="keyword">private</span>:
        <span class="keyword">static</span> <span class="keyword">const</span> InetHostAddress destinationAddress;
        <span class="keyword">static</span> <span class="keyword">const</span> uint16 destinationPort = 34566;
        <span class="keyword">static</span> <span class="keyword">const</span> uint32 packetsNumber = 100;
        <span class="keyword">static</span> <span class="keyword">const</span> uint32 packetsSize = 100;
        <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data[65535];
};

<span class="keyword">const</span> InetHostAddress PacketsPattern::destinationAddress = 
InetHostAddress(<span class="stringliteral">"localhost"</span>);
<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> PacketsPattern::data[65535];

PacketsPattern pattern;

<span class="keyword">class</span>
Test
{
<span class="keyword">public</span>:
        <span class="keyword">virtual</span> <span class="keywordtype">int</span>
        doTest() = 0;
};

<span class="keyword">class</span>
SendPacketTransmissionTest : <span class="keyword">public</span> Test, <span class="keyword">public</span> Thread, <span class="keyword">public</span> TimerPort
{
<span class="keyword">public</span>:
        <span class="keywordtype">void</span>
        run()
        {
                doTest();
        }

        <span class="keywordtype">int</span> doTest()
        {
                <span class="comment">// should be valid?</span>
                <span class="comment">//RTPSession tx();</span>
                <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> tx(InetHostAddress(<span class="stringliteral">"localhost"</span>));
                tx.setSchedulingTimeout(10000);
                tx.setExpireTimeout(1000000);
                
                tx.startRunning();
                
                tx.setPayloadFormat(<a name="_a1"></a><a class="code" href="class_static_payload_format.html" title="Static payload format objects.">StaticPayloadFormat</a>(<a name="a2"></a><a class="code" href="group__payload.html#gg7644623ce29b8ca519d7e3f276b6ddc6095b083465fe4d6597ba586e0116022c" title="ITU-T G.711. mu-law audio 8 Khz (RFC 1890).">sptPCMU</a>));
                <span class="keywordflow">if</span> ( !tx.addDestination(pattern.getDestinationAddress(),
                                        pattern.getDestinationPort()) ) {
                <span class="keywordflow">return</span> 1;
                }
                
                <span class="comment">// 50 packets per second (packet duration of 20ms)</span>
                uint32 period = 20;
                uint16 inc = tx.getCurrentRTPClockRate()/50;
                TimerPort::setTimer(period);
                <span class="keywordflow">for</span> ( uint32 i = 0; i &lt; pattern.getPacketsNumber(); i++ ) {
                        tx.putData(i*inc,
                                   pattern.getPacketData(i),
                                   pattern.getPacketSize(i));
                        Thread::sleep(TimerPort::getTimer());
                        TimerPort::incTimer(period);
                }
                <span class="keywordflow">return</span> 0;
        }
};


<span class="keyword">class</span>
RecvPacketTransmissionTest : <span class="keyword">public</span> Test, <span class="keyword">public</span> Thread
{
<span class="keyword">public</span>:
        <span class="keywordtype">void</span>
        run()
        {
                doTest();
        }

        <span class="keywordtype">int</span>
        doTest()
        {               
                <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> rx(pattern.getDestinationAddress(),
                              pattern.getDestinationPort());

                rx.setSchedulingTimeout(10000);
                rx.setExpireTimeout(1000000);
                
                rx.startRunning();
                rx.setPayloadFormat(<a class="code" href="class_static_payload_format.html" title="Static payload format objects.">StaticPayloadFormat</a>(<a class="code" href="group__payload.html#gg7644623ce29b8ca519d7e3f276b6ddc6095b083465fe4d6597ba586e0116022c" title="ITU-T G.711. mu-law audio 8 Khz (RFC 1890).">sptPCMU</a>));
                <span class="comment">// arbitrary number of loops</span>
                <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; 500 ; i++ ) {
                        <span class="keyword">const</span> <a name="_a3"></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 = rx.<a name="a4"></a><a class="code" href="class_app_data_unit.html#be15787e1cc84dd03b0769a5546d7a38" title="Get data as it is received in RTP packets (i.e.">getData</a>(rx.getFirstTimestamp())) ) {

                                <span class="keyword">delete</span> adu;
                        }
                        Thread::sleep(7);
                }
                <span class="keywordflow">return</span> 0;
        }
};

<span class="keyword">class</span>
MiscTest : <span class="keyword">public</span> Test, <span class="keyword">public</span> Thread, <span class="keyword">public</span> TimerPort
{
        <span class="keywordtype">void</span>
        run()
        {
                doTest();
        }

        <span class="keywordtype">int</span>
        doTest()
        {
                <span class="keyword">const</span> uint32 NSESSIONS = 10;
                <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> rx(pattern.getDestinationAddress(),pattern.getDestinationPort());
                <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> **tx = <span class="keyword">new</span> <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>* [NSESSIONS];
                <span class="keywordflow">for</span> ( uint32 i = 0; i &lt; NSESSIONS; i++ ) {
                        tx[i] = <span class="keyword">new</span> <a name="a5"></a><a class="code" href="group__sessions.html#g24e16f350c9ae0c1e2a3f5d6a6dad9f9" title="Uses two pairs of sockets for RTP data and RTCP transmission/reception.">RTPSession</a>(InetHostAddress(<span class="stringliteral">"localhost"</span>));
                }
                <span class="keywordflow">for</span> ( uint32 i = 0; i  &lt; NSESSIONS; i++) {
                        tx[i]-&gt;setSchedulingTimeout(10000);
                        tx[i]-&gt;setExpireTimeout(1000000);
                        tx[i]-&gt;setPayloadFormat(<a class="code" href="class_static_payload_format.html" title="Static payload format objects.">StaticPayloadFormat</a>(<a class="code" href="group__payload.html#gg7644623ce29b8ca519d7e3f276b6ddc6095b083465fe4d6597ba586e0116022c" title="ITU-T G.711. mu-law audio 8 Khz (RFC 1890).">sptPCMU</a>));
                        <span class="keywordflow">if</span> ( !tx[i]-&gt;addDestination(pattern.getDestinationAddress(),
                                                    pattern.getDestinationPort()) ) {
                                <span class="keywordflow">return</span> 1;
                        }
                }

                rx.setPayloadFormat(<a class="code" href="class_static_payload_format.html" title="Static payload format objects.">StaticPayloadFormat</a>(<a class="code" href="group__payload.html#gg7644623ce29b8ca519d7e3f276b6ddc6095b083465fe4d6597ba586e0116022c" title="ITU-T G.711. mu-law audio 8 Khz (RFC 1890).">sptPCMU</a>));
                rx.setSchedulingTimeout(5000);
                rx.setExpireTimeout(10000000); <span class="comment">// 10 seconds!</span>
                rx.startRunning();

                <span class="keywordflow">for</span> ( uint32 i = 0; i  &lt; NSESSIONS; i++) {
                        tx[i]-&gt;startRunning();
                }
                uint32 period = 20;
                TimerPort::setTimer(period);
                <span class="keywordflow">for</span> ( uint32 i = 0; i &lt; pattern.getPacketsNumber(); i++ ) {
                        <span class="keywordflow">if</span> ( i == 70 ) {
                                <a name="_a6"></a><a class="code" href="class_r_t_p_application.html" title="An RTP application, holding identifying RTCP SDES item values.">RTPApplication</a> &amp;app = <a name="a7"></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>();
                                app.<a name="a8"></a><a class="code" href="class_r_t_p_application.html#8f508dc361e2127b6ce494af67ca41c6">setSDESItem</a>(<a name="a9"></a><a class="code" href="group__rtcppacket.html#ggf6d38e5ccbbcdf2a24ebbd4fc5b4eeac56818aeaa2d578ab0055a59b8d8d28f9" title="Canonical end-point identifier.">SDESItemTypeCNAME</a>,<span class="stringliteral">"foo@bar"</span>);
                        }
                        <span class="keywordflow">for</span> ( uint32 s = 0; s  &lt; NSESSIONS; s++) {
                        <span class="comment">// 50 packets per second (packet duration of 20ms)</span>
                                uint16 inc = 
                                        tx[s]-&gt;getCurrentRTPClockRate()/50;
                                tx[s]-&gt;putData(i*inc,
                                               pattern.getPacketData(i),
                                               pattern.getPacketSize(i));
                        }
                        Thread::sleep(TimerPort::getTimer());
                        TimerPort::incTimer(period);
                }

                Thread::sleep(5000);
                <span class="keywordflow">for</span> ( uint32 i = 0; i &lt; NSESSIONS; i++ ) {
                        <span class="keyword">delete</span> tx[i];
                }
                RTPSession::SyncSourcesIterator it;
                cout &lt;&lt; <span class="stringliteral">"Sources of synchronization:"</span> &lt;&lt; endl;
                <span class="keywordflow">for</span> (it = rx.begin() ; it != rx.end(); it++) {
                        <span class="keyword">const</span> <a name="_a10"></a><a class="code" href="class_sync_source.html" title="Synchronization source in an RTP session.">SyncSource</a> &amp;s = *it;
                        cout &lt;&lt; s.<a name="a11"></a><a class="code" href="class_sync_source.html#67da73d6d3aedc50fc4493857871143b">getID</a>();
                        <span class="keywordflow">if</span> ( s.<a name="a12"></a><a class="code" href="class_sync_source.html#4611a2bc6c86e27d79945ad26a1e8e31" title="Whether this source sends RTP data packets.">isSender</a>() ) 
                                cout &lt;&lt; <span class="stringliteral">" (sender) "</span>;
                        cout &lt;&lt; s.<a name="a13"></a><a class="code" href="class_sync_source.html#9f92cbd6190fecc9bba3a54217b0d00a">getNetworkAddress</a>() &lt;&lt; <span class="stringliteral">":"</span> &lt;&lt;
                                s.<a name="a14"></a><a class="code" href="class_sync_source.html#56536e209e445a4f130e3e42a41bd027">getControlTransportPort</a>() &lt;&lt; <span class="stringliteral">"/"</span> &lt;&lt;
                                s.<a name="a15"></a><a class="code" href="class_sync_source.html#d8646f90825758d06c9f63a13be9b58c">getDataTransportPort</a>();
                        <a name="_a16"></a><a class="code" href="class_participant.html" title="A class of objects representing remote participants (RTP applications) in a multimedia...">Participant</a> *p = s.<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>();
                        cout &lt;&lt; <span class="stringliteral">" ("</span> &lt;&lt; 
                                p-&gt;<a name="a18"></a><a class="code" href="class_participant.html#09080be78b19740b978800a1ec51bc3e" title="Get the value of an SDES item.">getSDESItem</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;
                }
                <a class="code" href="class_r_t_p_application.html" title="An RTP application, holding identifying RTCP SDES item values.">RTPApplication</a> &amp;app = <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="_a19"></a><a class="code" href="class_r_t_p_application_1_1_participants_iterator.html" title="Iterator through the list of participants in this session.">RTPApplication::ParticipantsIterator</a> ai;
                cout &lt;&lt; <span class="stringliteral">"Participants:"</span> &lt;&lt; endl;
                <span class="keywordflow">for</span> ( ai = app.<a name="a20"></a><a class="code" href="class_r_t_p_application.html#8b50b594ea5e44690c95fde779b0a698">begin</a>(); ai != app.<a name="a21"></a><a class="code" href="class_r_t_p_application.html#6d08c520e5dd2409206f196f6d5ca2a1">end</a>(); ai++ ) {
                        <span class="keyword">const</span> <a class="code" href="class_participant.html" title="A class of objects representing remote participants (RTP applications) in a multimedia...">Participant</a> &amp;p = *ai;
                        cout &lt;&lt; p.<a class="code" href="class_participant.html#09080be78b19740b978800a1ec51bc3e" title="Get the value of an SDES item.">getSDESItem</a>(<a class="code" href="group__rtcppacket.html#ggf6d38e5ccbbcdf2a24ebbd4fc5b4eeac56818aeaa2d578ab0055a59b8d8d28f9" title="Canonical end-point identifier.">SDESItemTypeCNAME</a>) &lt;&lt; endl;
                        <span class="comment">//cout &lt;&lt; p.getPRIVPrefix();</span>
                }
                <span class="keyword">delete</span> tx;
                <span class="keywordflow">return</span> 0;
        }
};

<span class="comment">// class TestPacketHeaders { }</span>
<span class="comment">// header extension</span>

<span class="comment">// class TestRTCPTransmission { }</span>

<span class="comment">// class TestMiscellaneous { }</span>

<span class="comment">// Things that should be tested:</span>
<span class="comment">// extreme values (0 - big) for putData</span>
<span class="comment">// segmentation (setMaxSendSegmentSize())</span>
<span class="comment">// performance: packets/second (depending on packet size and # of participants)</span>
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
{
        <span class="keywordtype">int</span> result = 0;
        <span class="keywordtype">bool</span> send = <span class="keyword">false</span>;
        <span class="keywordtype">bool</span> recv = <span class="keyword">false</span>;

        RecvPacketTransmissionTest *rx;
        SendPacketTransmissionTest *tx;

        <span class="comment">// accept as parameter if must run as --send or --recv</span>

        <span class="comment">// run several tests in parallel threads</span>
        <span class="keywordflow">if</span> ( send ) {
                tx = <span class="keyword">new</span> SendPacketTransmissionTest();
                tx-&gt;start();
                tx-&gt;join();
        } <span class="keywordflow">else</span>  <span class="keywordflow">if</span> ( recv ) {
                rx = <span class="keyword">new</span> RecvPacketTransmissionTest();
                rx-&gt;start();
                rx-&gt;join();
        } <span class="keywordflow">else</span> {
                MiscTest m;
                m.start();
                m.join();
        }
        exit(result);
}

</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>