⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lark_rtptappui.cpp

📁 symbian平台S60_2nd_FP2_SC rtp实现
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CLark_RtpTAppUi from Lark_RtpTAppui.cpp
*  Part of  : Lark_RtpT
*  Created  : 08.10.2007 by 
*  Implementation notes:
*     Initial content was generated by Series 60 Application Wizard.
*  Version  :
*  Copyright: 
* ============================================================================
*/

// INCLUDE FILES
#include "Lark_RtpTAppui.h"
#include "Lark_RtpTDialog.h" 
#include <Lark_RtpT.rsg>
#include "Lark_RtpT.hrh"

#include <avkon.hrh>

#include <libc\sys\time.h>

#include "RtpSession.h"

// ================= MEMBER FUNCTIONS =======================
//
// ----------------------------------------------------------
// CLark_RtpTAppUi::ConstructL()
// 
// ----------------------------------------------------------
//
void CLark_RtpTAppUi::ConstructL()
    {
    BaseConstructL();

    iAppDialog = new (ELeave) CLark_RtpTDialog;
	iAppDialog->SetMopParent( this );
    iAppDialog->ExecuteLD( R_LARK_RTPT_DIALOG );
    AddToStackL( iAppDialog );
    }

// ----------------------------------------------------
// CLark_RtpTAppUi::~CLark_RtpTAppUi()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CLark_RtpTAppUi::~CLark_RtpTAppUi()
    {
    if (iAppDialog)
        {
        RemoveFromStack( iAppDialog );
        delete iAppDialog;
        }
   }

// ------------------------------------------------------------------------------
// CLark_RtpTAppUi::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
//  This function is called by the EIKON framework just before it displays
//  a menu pane. Its default implementation is empty, and by overriding it,
//  the application can set the state of menu items dynamically according
//  to the state of application data.
// ------------------------------------------------------------------------------
//
void CLark_RtpTAppUi::DynInitMenuPaneL(
    TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/)
    {
    }

// ----------------------------------------------------
// CLark_RtpTAppUi::HandleKeyEventL(
//     const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
// takes care of key event handling
// ----------------------------------------------------
//
TKeyResponse CLark_RtpTAppUi::HandleKeyEventL(
    const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
    {
    return EKeyWasNotConsumed;
    }

// ----------------------------------------------------
// CLark_RtpTAppUi::HandleCommandL(TInt aCommand)
// takes care of command handling
// ----------------------------------------------------
//
void CLark_RtpTAppUi::HandleCommandL(TInt aCommand)
    {
    switch ( aCommand )
        {
        case EEikCmdExit:
            {
            Exit();
            break;
            }
        case ELark_RtpTCmdAppTest:
            {
//			RThread iThread;
//
//			// 创建
//			if (iThread.ExitType() == EExitKill)
//			{
//				iThread.Close();// 释放句柄
//			}
//			if (iThread.Create(_L("ThreadInvalidateMicro"), (TThreadFunction)InvalidateMicro,
//					4096, KMinHeapSize, 256*KMinHeapSize, this) == KErrNone)
//			{
//				iThread.Resume(); 
//			}
//			// 终止线程,还有其他的终止方法
//			iThread.Kill(KErrNone);


      //       Send3gp();

			Receive3gp();
           break;
            }
        // TODO: Add Your command handling code here

        default:
            break;      
        }
    }


// 线程调用的函数
//static TInt InvalidateMicro(TAny *aPtr); // 声明,必须为静态或全局
//TInt CStopwatchContainer::InvalidateMicro(TAny *aPtr) // 定义
//{
//... ...
//return KErrNone;
//}


int CLark_RtpTAppUi::usleep( int useconds )
{
    sleep(useconds / 1000);
	return 0;
}

int CLark_RtpTAppUi::Send3gp()
{

//	10.11.29.43:554
#define PAYLOADSIZE 320
	
	char *host = "10.11.29.43";	
	RtpSession* stack=new RtpSession("10.11.29.43", 554, 6090, 9001, 8090,rtpPayloadPCMU,rtpPayloadPCMU,-1);
	
	stack->setApiFormat (rtpPayloadPCMU,PAYLOADSIZE);
	stack->setNetworkFormat (rtpPayloadPCMU,PAYLOADSIZE);
	
    char sendfile[30];
	strcpy(sendfile, "c:\\bySend.wma");
	FILE* fp = fopen(sendfile,"rb");
	
    char Buffer[PAYLOADSIZE];
	int nbyte ;	
	if(fp) 
	{
		while(!feof(fp))
		{
			memset(Buffer,0,sizeof(Buffer));
			nbyte =fread(Buffer,1,PAYLOADSIZE,fp);
			
			if(nbyte<= 0)
				continue;
			
			stack->transmitRaw(Buffer,nbyte);
			usleep (100);
		}
		fclose(fp);
	}
	
	// leaving session
	stack->transmitRTCPBYE();
	delete stack;
	return 0;
}

int CLark_RtpTAppUi::Receive3gp()
{
	
	char fileName[256];
	RtpSession* rtpstack;
	FILE* fp;
	
	
	strcpy(fileName,"c:\\byRec.wma");
	fp=fopen(fileName,"wb+");;
	if(fp==NULL)
	{
		CEikonEnv::Static()->AlertWin(_L("Create file failure."));
		return 0;
	}
	
	char *host = "10.11.29.43";
	rtpstack = new RtpSession("10.11.29.43", 554, 7001, 8090, 9001,rtpPayloadPCMU,rtpPayloadPCMU,5);
	
	
	RtpPacket*  rtpPack;
	RtcpPacket* rtcpPack;
	
	while(1)
	{
		usleep (10);
		if(rtpstack)
		{
			if(rtpstack->receive(&rtpPack,&rtcpPack))
			{
				if(rtpPack)
				{
					fwrite(rtpPack->getPayloadLoc(),1, rtpPack->getPayloadUsage(),fp);
					delete rtpPack;
				}
				else
				{
					fclose(fp);
					break;
				}
				if(rtcpPack)
				{
					if(rtpstack->getRtcpRecv()->findRTCP(rtcpPack,rtcpTypeBYE))
					{
						CEikonEnv::Static()->AlertWin(_L("receive rtcp bye"));
					}
					delete rtcpPack;
				}
			}
		}
	}
	return 0;
}

// End of File  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -