00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "RTPFileStreamer.h"
00018 #include "ExampleApp.h"
00019
00020
00021
00022 CActiveConsole::CActiveConsole(MActiveConsoleNotify& aNotify):CActive(EPriorityStandard), iNotify(aNotify)
00023 {
00024 CActiveScheduler::Add(this);
00025 }
00026
00027 CActiveConsole::~CActiveConsole()
00028 {
00029 delete iConsole;
00030 Cancel();
00031 }
00032
00033 CActiveConsole* CActiveConsole::NewL(MActiveConsoleNotify& aNotify,const TDesC& aTitle,const TSize& aSize)
00034 {
00035 CActiveConsole* console = new (ELeave) CActiveConsole(aNotify);
00036 CleanupStack::PushL(console);
00037 console->ConstructL(aTitle,aSize);
00038 CleanupStack::Pop();
00039 return console;
00040 }
00041
00042 void CActiveConsole::ConstructL(const TDesC& aTitle,const TSize& aSize)
00043 {
00044 iConsole = Console::NewL(aTitle,aSize);
00045 }
00046
00047 void CActiveConsole::DoCancel()
00048 {
00049 iConsole->ReadCancel();
00050 }
00051
00052 void CActiveConsole::RequestKey()
00053 {
00054 DrawCursor();
00055 iConsole->Read(iStatus);
00056 SetActive();
00057 }
00058
00059 void CActiveConsole::DrawCursor()
00060 {
00061 iConsole->Printf(_L(">>"));
00062 }
00063
00064 void CActiveConsole::RunL()
00065 {
00066 TChar ch = iConsole->KeyCode();
00067 iNotify.KeyPressed(ch);
00068 }
00069
00070
00071 CExampleApp::CExampleApp()
00072 {
00073 }
00074
00075 CExampleApp::~CExampleApp()
00076 {
00077 delete iActiveConsole;
00078 delete iMonitorConsole;
00079 iSockServ.Close();
00080 }
00081
00082 CExampleApp* CExampleApp::NewL()
00083 {
00084 CExampleApp* thisapp = new (ELeave) CExampleApp();
00085 CleanupStack::PushL(thisapp);
00086 thisapp->ConstructL();
00087 CleanupStack::Pop();
00088 return thisapp;
00089 }
00090
00091 static TSize gMainConsole(KConsFullScreen,KConsFullScreen);
00092 static TSize gTinyConsole(40,10);
00093
00094 void CExampleApp::ConstructL()
00095 {
00096 iActiveConsole = CActiveConsole::NewL(*this,_L("Status"),gMainConsole);
00097 iMonitorConsole = CActiveConsole::NewL(*this,_L("RtpExample"),gTinyConsole);
00098 User::LeaveIfError(iSockServ.Connect());
00099 }
00100
00101 void CExampleApp::StartL()
00102 {
00103 _LIT(KTextWelcome, " ### RTP Example ### \n");
00104 iMonitorConsole->Console().Printf(KTextWelcome);
00105
00106 _LIT(KTextStartApp, "\n\n Starting the RTP application");
00107 iMonitorConsole->Console().Printf ( KTextStartApp );
00108
00109 _LIT(KTextPressAKey, "\n\n Press any key to step through the example");
00110 iMonitorConsole->Console().Printf ( KTextPressAKey );
00111 iMonitorConsole->Console().Getch ();
00112
00113 _LIT(KDAddr,"\n\n Local address: ");
00114 iMonitorConsole->Console().Printf(KDAddr);
00115 iMonitorConsole->Console().Printf(KDestAddr);
00116 iMonitorConsole->Console().Getch ();
00117 _LIT(KLPort,"\n\n Address family: ");
00118 iMonitorConsole->Console().Printf(KLPort);
00119 iMonitorConsole->Console().Printf(KLocalPort);
00120 iMonitorConsole->Console().Getch ();
00121 _LIT(KDPort,"\n\n RTP port number: ");
00122 iMonitorConsole->Console().Printf(KDPort);
00123 iMonitorConsole->Console().Printf(KDestPort);
00124 iMonitorConsole->Console().Getch ();
00125 _LIT(KSFile,"\n\n Source file name: ");
00126 iMonitorConsole->Console().Printf(KSFile);
00127 iMonitorConsole->Console().Printf(KsFileName);
00128 iMonitorConsole->Console().Getch ();
00129 _LIT(KTFile,"\n\n Target file name: ");
00130 iMonitorConsole->Console().Printf(KTFile);
00131 iMonitorConsole->Console().Printf(KdFileName);
00132 iMonitorConsole->Console().Getch ();
00133 _LIT(KBufSize,"\n\n Buffer size: ");
00134 iMonitorConsole->Console().Printf(KBufSize);
00135 iMonitorConsole->Console().Printf(KSize);
00136 iMonitorConsole->Console().Getch ();
00137
00138 TInt dport;
00139 TInt lport;
00140 TInt psize;
00141 TInetAddr daddr;
00142 TLex parser;
00143 parser.Assign(KDestPort);
00144 User::LeaveIfError(parser.Val(dport));
00145 parser.Assign(KSize);
00146 User::LeaveIfError(parser.Val(psize));
00147 parser.Assign(KLocalPort);
00148 User::LeaveIfError(parser.Val(lport));
00149
00150 RHostResolver resolver;
00151 User::LeaveIfError(resolver.Open(iSockServ,KAfInet,KProtocolInetUdp));
00152 CleanupClosePushL(resolver);
00153 TNameEntry entry;
00154 TRequestStatus status;
00155 resolver.GetByName(KDestAddr,entry,status);
00156 User::WaitForRequest(status);
00157 User::LeaveIfError(status.Int());
00158 CleanupStack::PopAndDestroy(1);
00159
00160 TSockAddr remote = entry().iAddr;
00161 remote.SetPort(dport);
00162
00163 TInt connId=KErrNotFound;
00164 iMonitorConsole->Console().Printf(_L("\n\n Sending RTP packet from %S file to %S file."),&KsFileName,&KdFileName);
00165 iMonitorConsole->Console().Getch();
00166 iStreamer = CRtpFileStreamer::NewL(iSockServ,KsFileName,KdFileName,psize,remote,lport,connId);
00167 iStreamer->SetObserver(*this);
00168 iStreamer->StartL();
00169 CActiveScheduler::Start();
00170 }
00171
00172 void CExampleApp::Stop()
00173 {
00174 if (iStreamer)
00175 {
00176 delete iStreamer;
00177 }
00178 CActiveScheduler::Stop();
00179 }
00180
00181 void CExampleApp::DrawMonitor()
00182 {
00183 iMonitorConsole->Console().Printf(_L("\n Sent: %d\n Recv: %d"),iSent,iRecv);
00184 }
00185
00186 void CExampleApp::NotifyPacketSent()
00187 {
00188 iSent++;
00189 DrawMonitor();
00190 iActiveConsole->Console().Printf(_L("s"));
00191 }
00192
00193 void CExampleApp::NotifyPacketReceived()
00194 {
00195 iRecv++;
00196 DrawMonitor();
00197 iActiveConsole->Console().Printf(_L("r"));
00198 }
00199
00200 void CExampleApp::NotifyComplete()
00201 {
00202 iMonitorConsole->Console().Printf(_L("\n\n Successfully sent %d RTP packet(s)"),iRecv);
00203 iMonitorConsole->Console().Getch();
00204
00205 _LIT(KExit,"\n\n Press any key to exit the application ");
00206 iMonitorConsole->Console().Printf(KExit);
00207 iMonitorConsole->Console().Getch();
00208
00209 if (iStreamer)
00210 {
00211 delete iStreamer;
00212 }
00213 CActiveScheduler::Stop();
00214 }
00215
00216 void CExampleApp::NotifyError()
00217 {
00218 iMonitorConsole->Console().Printf(_L("Error\n"));
00219 iMonitorConsole->Console().Getch();
00220 iActiveConsole->Console().Printf(_L("E"));
00221 }
00222
00223 void CExampleApp::KeyPressed(TChar )
00224 {
00225 }
00226
00227 void MainL()
00228 {
00229 CExampleApp* app = CExampleApp::NewL();
00230 CleanupStack::PushL(app);
00231 app->StartL();
00232 CleanupStack::PopAndDestroy(app);
00233 }
00234
00235 TInt E32Main()
00236 {
00237 __UHEAP_MARK;
00238 CTrapCleanup* cleanupStack=CTrapCleanup::New();
00239 CActiveScheduler* activescheduler=new CActiveScheduler;
00240 CActiveScheduler::Install(activescheduler);
00241
00242 TRAPD(err, MainL());
00243 _LIT(KTxtEPOC32EX,"EXAMPLES");
00244 __ASSERT_ALWAYS(!err,User::Panic(KTxtEPOC32EX,err));
00245
00246 delete activescheduler;
00247 delete cleanupStack;
00248 __UHEAP_MARKEND;
00249 return KErrNone;
00250 }