maxRtpSessions.cxx
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:7k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

C/C++

  1. /* ====================================================================
  2.  * The Vovida Software License, Version 1.0 
  3.  * 
  4.  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
  5.  * 
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  * 
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in
  15.  *    the documentation and/or other materials provided with the
  16.  *    distribution.
  17.  * 
  18.  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
  19.  *    and "Vovida Open Communication Application Library (VOCAL)" must
  20.  *    not be used to endorse or promote products derived from this
  21.  *    software without prior written permission. For written
  22.  *    permission, please contact vocal@vovida.org.
  23.  *
  24.  * 4. Products derived from this software may not be called "VOCAL", nor
  25.  *    may "VOCAL" appear in their name, without prior written
  26.  *    permission of Vovida Networks, Inc.
  27.  * 
  28.  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
  29.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
  31.  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
  32.  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
  33.  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
  34.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  36.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  37.  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39.  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  40.  * DAMAGE.
  41.  * 
  42.  * ====================================================================
  43.  * 
  44.  * This software consists of voluntary contributions made by Vovida
  45.  * Networks, Inc. and many individuals on behalf of Vovida Networks,
  46.  * Inc.  For more information on Vovida Networks, Inc., please see
  47.  * <http://www.vovida.org/>.
  48.  *
  49.  */
  50. // This is a test to see how many rtp session can be established 
  51. // between two linux boxes. It is based on sampleUsage.cxx
  52. static const char* const maxRtpSessions_cxx_Version =
  53.     "$Id: maxRtpSessions.cxx,v 1.3 2001/02/27 00:55:27 larryt Exp $";
  54. #include <stdlib.h>
  55. #include <unistd.h>
  56. #include <fstream>
  57. #include <stdio.h>
  58. #include "cpLog.h"
  59. #include "rtpTypes.h"
  60. #include "RtpSession.hxx"
  61. #include "TimeTracker.hxx"
  62. int main (int argc, char *argv[])
  63. {
  64.     // allocate and initialize default configuration values
  65.     // note, you may need to create two executable, each with the
  66.     // others address info
  67.     char rmtHost[256] = "vvs-softball";
  68.     int max_sessions = 100;
  69.     int rmtPort = 7000;
  70.     int lclPort = 5000;
  71.     int apSize = 160;
  72.     int npSize = 160;
  73.     TimeTracker T(cerr);
  74.     if (argc == 1)
  75.     {
  76.         cout << "Usage: ./maxRtpSessions host sessions rmt_start_port lcl_start_port" << endl;
  77.         return 0;
  78.     } 
  79.     else if (argc == 5)
  80.     {
  81.         strcpy( rmtHost, argv[1] );
  82.         max_sessions = atoi( argv[2] );
  83.         rmtPort = atoi( argv[3] );
  84.         lclPort = atoi( argv[4] );
  85.     }
  86.     else
  87.     {
  88.         printf("Enter remote hostname: ");
  89.         scanf ("%s", rmtHost);
  90.         printf("Enter number of the max rtp sessions: ");
  91.         scanf ("%d", &max_sessions);
  92.         printf("Enter remote port number: ");
  93.         scanf ("%d", &rmtPort);
  94.         printf("Enter local port number: ");
  95.         scanf ("%d", &lclPort);
  96.     }
  97.     pid_t pid;
  98.     for (int j=0; j < max_sessions; j++)
  99.     {
  100.         if ((pid = fork()) < 0)
  101.         {
  102.             cerr << "Fork failed." << endl;
  103.             return -1;
  104.         }
  105.         else if (pid == 0)
  106.         {
  107.             cout << "Get pid is: " << getpid() <<endl;
  108.             cout << "Creating rtp session " << j << endl;
  109.             T.startTime();
  110.             RtpSession* stack = new RtpSession ( rmtHost, 
  111.                                      rmtPort + 2*j, lclPort + 2*j,
  112.                                      rmtPort + 2*j + 1, lclPort + 2*j + 1, 
  113.                                      rtpPayloadPCMU, rtpPayloadPCMU, 5);
  114.             // setup logfile
  115. //            cpLogSetLabel ("maxRtpSessions");
  116.             //    cpLogSetPriority (LOG_DEBUG);
  117.         
  118.             RtpPacket* inPacket = NULL;
  119.         
  120.             char outBufferPkt[480];
  121.         
  122.             // only 5 bytes of data, but still send a big packet
  123.             strncpy (outBufferPkt, "data", 5);
  124.         
  125.             stack->setApiFormat (rtpPayloadPCMU, apSize);
  126.             stack->setNetworkFormat (rtpPayloadPCMU, npSize);
  127.         
  128.             for (int i = 0; i < 10000; i++)
  129.             {
  130.                 // receive a packet
  131.                 inPacket = stack->receive ();
  132.                 if (inPacket)
  133.                 {
  134.                     //            if (i<2)
  135.                     //                inPacket->printPacket();
  136. //                    printf( "r" );
  137.                     delete inPacket;
  138.                     inPacket = NULL;
  139.                 }
  140.                 else
  141.                 {
  142. //                    printf( "n");
  143.                 }
  144.         
  145.         
  146.                 // sleep between rcv and trans
  147.                 usleep (20*1000);  // 20 msec
  148.         
  149.                 // send a packet
  150.                 //        if (i<2)
  151.                 //           outPacket->printPacket();
  152.                 stack->transmitRaw (outBufferPkt, 160);
  153.         
  154. //                printf( "t" );
  155.         
  156.         
  157.                 // send and receive RTCP packet
  158.                 if (stack->checkIntervalRTCP())
  159.                 {
  160.                     stack->transmitRTCP();
  161. //                    printf( "T" );
  162.                 }
  163.                 if (stack->receiveRTCP() == 0 )
  164.                 {
  165. //                    printf( "R" );
  166.                 }
  167.         
  168. //                fflush(stdout);
  169.             }
  170.         
  171.             stack->transmitRTCPBYE();
  172.         
  173.             if (inPacket)
  174.             {
  175.                 delete inPacket;
  176.                 inPacket = NULL;
  177.             }
  178.         
  179.             delete stack;
  180.             stack = NULL;
  181.             T.endTime();
  182.             cout << "End rtp session " << j << endl;
  183.             return 3;
  184. //            break;
  185.         }
  186. /*
  187.         else if (pid != 0)
  188.         {
  189.             cerr << "It is still parent process." << endl;
  190.         }
  191. */
  192.     }
  193.     return 0;
  194. }