1/* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11// BWEStandAlone.cpp : Defines the entry point for the console application. 12// 13 14#include <stdio.h> 15#include <string> 16 17#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" 18#include "webrtc/system_wrappers/interface/event_wrapper.h" 19#include "webrtc/system_wrappers/interface/trace.h" 20#include "webrtc/test/channel_transport/udp_transport.h" 21 22#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h" 23#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h" 24 25#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h" 26 27//#include "vld.h" 28 29class myTransportCB: public UdpTransportData 30{ 31public: 32 myTransportCB (RtpRtcp *rtpMod) : _rtpMod(rtpMod) {}; 33protected: 34 // Inherited from UdpTransportData 35 virtual void IncomingRTPPacket(const int8_t* incomingRtpPacket, 36 const int32_t rtpPacketLength, 37 const int8_t* fromIP, 38 const uint16_t fromPort) OVERRIDE; 39 40 virtual void IncomingRTCPPacket(const int8_t* incomingRtcpPacket, 41 const int32_t rtcpPacketLength, 42 const int8_t* fromIP, 43 const uint16_t fromPort) OVERRIDE; 44 45private: 46 RtpRtcp *_rtpMod; 47}; 48 49void myTransportCB::IncomingRTPPacket(const int8_t* incomingRtpPacket, 50 const int32_t rtpPacketLength, 51 const int8_t* fromIP, 52 const uint16_t fromPort) 53{ 54 printf("Receiving RTP from IP %s, port %u\n", fromIP, fromPort); 55 _rtpMod->IncomingPacket((uint8_t *) incomingRtpPacket, static_cast<uint16_t>(rtpPacketLength)); 56} 57 58void myTransportCB::IncomingRTCPPacket(const int8_t* incomingRtcpPacket, 59 const int32_t rtcpPacketLength, 60 const int8_t* fromIP, 61 const uint16_t fromPort) 62{ 63 printf("Receiving RTCP from IP %s, port %u\n", fromIP, fromPort); 64 _rtpMod->IncomingPacket((uint8_t *) incomingRtcpPacket, static_cast<uint16_t>(rtcpPacketLength)); 65} 66 67 68int main(int argc, char* argv[]) 69{ 70 bool isSender = false; 71 bool isReceiver = false; 72 uint16_t port; 73 std::string ip; 74 TestSenderReceiver *sendrec = new TestSenderReceiver(); 75 TestLoadGenerator *gen; 76 77 if (argc == 2) 78 { 79 // receiver only 80 isReceiver = true; 81 82 // read port 83 port = atoi(argv[1]); 84 } 85 else if (argc == 3) 86 { 87 // sender and receiver 88 isSender = true; 89 isReceiver = true; 90 91 // read IP 92 ip = argv[1]; 93 94 // read port 95 port = atoi(argv[2]); 96 } 97 98 Trace::CreateTrace(); 99 Trace::SetTraceFile("BWEStandAloneTrace.txt"); 100 Trace::set_level_filter(webrtc::kTraceAll); 101 102 sendrec->InitReceiver(port); 103 104 sendrec->Start(); 105 106 if (isSender) 107 { 108 const uint32_t startRateKbps = 1000; 109 //gen = new CBRGenerator(sendrec, 1000, 500); 110 gen = new CBRFixFRGenerator(sendrec, startRateKbps, 90000, 30, 0.2); 111 //gen = new PeriodicKeyFixFRGenerator(sendrec, startRateKbps, 90000, 30, 0.2, 7, 300); 112 //const uint16_t numFrameRates = 5; 113 //const uint8_t frameRates[numFrameRates] = {30, 15, 20, 23, 25}; 114 //gen = new CBRVarFRGenerator(sendrec, 1000, frameRates, numFrameRates, 90000, 4.0, 0.1, 0.2); 115 //gen = new CBRFrameDropGenerator(sendrec, startRateKbps, 90000, 0.2); 116 sendrec->SetLoadGenerator(gen); 117 sendrec->InitSender(startRateKbps, ip.c_str(), port); 118 gen->Start(); 119 } 120 121 while (1) 122 { 123 } 124 125 if (isSender) 126 { 127 gen->Stop(); 128 delete gen; 129 } 130 131 delete sendrec; 132 133 //uint8_t numberOfSocketThreads = 1; 134 //UdpTransport* transport = UdpTransport::Create(0, numberOfSocketThreads); 135 136 //RtpRtcp* rtp = RtpRtcp::CreateRtpRtcp(1, false); 137 //if (rtp->InitSender() != 0) 138 //{ 139 // exit(1); 140 //} 141 //if (rtp->RegisterSendTransport(transport) != 0) 142 //{ 143 // exit(1); 144 //} 145 146// transport->InitializeSendSockets("192.168.200.39", 8000); 147 //transport->InitializeSendSockets("127.0.0.1", 10000); 148 //transport->InitializeSourcePorts(8000); 149 150 151 return(0); 152 // myTransportCB *tp = new myTransportCB(rtp); 153 // transport->InitializeReceiveSockets(tp, 10000, "0.0.0.0"); 154 // transport->StartReceiving(500); 155 156 // int8_t data[100]; 157 // for (int i = 0; i < 100; data[i] = i++); 158 159 // for (int i = 0; i < 100; i++) 160 // { 161 // transport->SendRaw(data, 100, false); 162 // } 163 164 165 166 // int32_t totTime = 0; 167 // while (totTime < 10000) 168 // { 169 // transport->Process(); 170 // int32_t wTime = transport->TimeUntilNextProcess(); 171 // totTime += wTime; 172 // Sleep(wTime); 173 // } 174 175 176 //if (transport) 177 //{ 178 // // Destroy the Socket Transport module 179 // transport->StopReceiving(); 180 // transport->InitializeReceiveSockets(NULL,0);// deregister callback 181 // UdpTransport::Destroy(transport); 182 // transport = NULL; 183 // } 184 185 // if (tp) 186 // { 187 // delete tp; 188 // tp = NULL; 189 // } 190 191 // if (rtp) 192 // { 193 // RtpRtcp::DestroyRtpRtcp(rtp); 194 // rtp = NULL; 195 // } 196 197 198 //return 0; 199} 200