📄 main.cpp
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <process.h>
#include <ctadef.h>
#include <adidef.h>
#include <swidef.h>
#include <mspdef.h>
#include <h324def.h>
#include "oammodule.h"
#include "boardmodule.h"
#include "swimodule.h"
#include "H324Port.h"
#include "VMPort.h"
#include "routine.h"
TH324Port H324Port[2]; //2个端口
TVMPort VMPort[2];
bool bquit = false;
unsigned __stdcall h324work( void *arg )
{
TH324Port *p = (TH324Port * )arg;
CTA_EVENT event;
while(!bquit)
{
ctaWaitEvent(p->m_quehd, &event, 1000/*timeout*/);
if(event.id == CTAEVN_WAIT_TIMEOUT)
continue;
BOOL consumed;
h324SubmitEvent(&event, &consumed);
if(consumed)
continue;
ShowEvent(&event);
switch(event.id)
{
case H324EVN_START_DONE :
if(event.value != CTA_REASON_FINISHED)
{
bquit = true; //failure
break;
}
p->SetLocalCaps();
p->SetupCall();
break;
case H324EVN_MEDIA_SETUP_DONE :
if(event.value == CTA_REASON_FINISHED)
{
//分配VMPort的简单策略
TVMPort *pVMPort = &VMPort[0];
if(event.userid > 0)
pVMPort = &VMPort[1];
//开始msp
int local = 10000 + event.userid * 4;
int remote = 60000 + pVMPort->m_userid * 4;
p->StartMSP(local, remote);
pVMPort->StartMSP(remote, local);
}
break;
case H324EVN_REMOTE_CAPABILITIES :
p->OnRemoteCap(&event);
break;
case H324EVN_LCD:
p->OnLcd(&event);
break;
case H324EVN_LOCAL_TERM_CAPS :
case H324EVN_VIDEO_FAST_UPDATE :
case H324EVN_END_SESSION :
case H324EVN_USER_INDICATION :
case H324EVN_ROUND_TRIP_DELAY :
case H324EVN_STOP_DONE :
case H324EVN_H245_INTERNAL_ERROR :
case H324EVN_CALL_SETUP_FAILED :
case H324EVN_MEDIA_SETUP_FAILED :
case H324EVN_VIDEO_CHANNEL_SETUP_FAILED :
case H324EVN_CHANNEL_CLOSED :
case H324EVN_VIDEO_OLC_TIMER_EXPIRED :
case H324EVN_END_SESSION_TIMER_EXPIRED :
case H324EVN_END_SESSION_DONE :
case H324EVN_H223_SKEW_INDICATION :
break;
case MSPEVN_CREATE_ENDPOINT_DONE:
case MSPEVN_CREATE_CHANNEL_DONE:
case MSPEVN_CONNECT_DONE:
case MSPEVN_ENABLE_CHANNEL_DONE:
case MSPEVN_SENDCOMMAND_DONE:
case MSPEVN_SENDCOMMAND_DONE | MSP_CMD_RTPFDX_H263_ENCAP_CTRL:
case MSPEVN_ENABLE_ENDPOINT_DONE:
case MSPEVN_DISABLE_ENDPOINT_DONE:
p->OnMspEvent(&event);
break;
}
ReleaseNMSEvent(&event);
}
p->FreeRes(); //释放license
_endthread();
return 0;
}
unsigned __stdcall vmwork( void *arg )
{
TVMPort *p = (TVMPort * )arg;
CTA_EVENT event;
while(!bquit)
{
ctaWaitEvent(p->m_quehd, &event, 1000/*timeout*/);
if(event.id == CTAEVN_WAIT_TIMEOUT)
continue;
BOOL consumed;
h324SubmitEvent(&event, &consumed);
if(consumed)
continue;
ShowEvent(&event);
switch(event.id)
{
case MSPEVN_CREATE_ENDPOINT_DONE:
p->OnMspEvent(&event);
break;
case ADIEVN_PLAY_BUFFER_REQ:
p->ContinuePlay(&event);
break;
case ADIEVN_PLAY_DONE:
p->OnPlayDone(&event);
break;
case ADIEVN_RECORD_STARTED:
case ADIEVN_RECORD_BUFFER_FULL:
if(event.value == ADI_RECORD_BUFFER_REQ)
p->ContinueRecord(&event);
break;
case ADIEVN_RECORD_DONE:
p->OnRecordDone(&event);
break;
}
ReleaseNMSEvent(&event);
}
_endthread();
return 0;
}
void RunDemo(int board, int timeslot, const char *cgaddress);
int main()
{
h324SetTrace( T_ALLERR, 0xFFFFFFFF );
if(h324Initialize("h324.log") != 0 )
return -1;
if( !InitCTA() )
return -1;
//自动找配置了mux的板子
for(int board = 0; board < 10; board++ )
{
int dspstream, numtrunk;
if( !TBoardModule::GetBoardInfo(board, &dspstream, &numtrunk))
continue; //not exists
char cgaddress[40]; //cg配置的IP地址
TOamModule::GetKeyword(board, "IPC.AddRoute[0].DestinationAddress", cgaddress, sizeof cgaddress);
//enum resource
char ResCount[20];
TOamModule::GetKeyword(board, "Resource.Count", ResCount, sizeof ResCount);
for(int resno = 0; resno < atoi(ResCount); resno++)
{
char buff[500];
char keyword[100];
sprintf(keyword,"Resource[%d].Definitions", resno);
TOamModule::GetKeyword(board, keyword, buff, 500);
strlwr(buff);
//如果包含"mux"字符串,则是一个mux资源定义
if(strstr(buff, "mux"))
{
//取resource[x].starttimeslot
int starttimeslot;
sprintf(keyword,"Resource[%d].StartTimeSlot", resno);
TOamModule::GetKeyword(board, keyword, buff, 50);
starttimeslot=atoi(buff);
RunDemo(board, starttimeslot, cgaddress);
return 0;
}
}
}
return 0;
}
void RunDemo(int board, int timeslot, const char *cgaddress)
{
if( 0 == H324Port[0].OpenServices(board, timeslot, 0/*userid*/, cgaddress) )
{
if( 0 == H324Port[1].OpenServices(board, timeslot+1, 1/*userid*/, cgaddress) )
{
//把2个DSP端口的时隙连起来
TSwiModule::Connect(board, timeslot, timeslot + 1);
H324Port[0].Start324Stack();
H324Port[1].Start324Stack();
VMPort[0].OpenServices(board, 100/*userid*/, cgaddress);
VMPort[1].OpenServices(board, 101/*userid*/, cgaddress);
unsigned thraddr1, thraddr2;
_beginthreadex( NULL, 0, h324work, &H324Port[0], 0, &thraddr1);
_beginthreadex( NULL, 0, h324work, &H324Port[1], 0, &thraddr2);
unsigned thraddra, thraddrb;
_beginthreadex( NULL, 0, vmwork, &VMPort[0], 0, &thraddra);
_beginthreadex( NULL, 0, vmwork, &VMPort[1], 0, &thraddrb);
//简单的键盘处理
while(!bquit)
{
if(!kbhit())
{
Sleep(100);
continue;
}
switch(getche())
{
case 27: //[ESC]
case 'Q':
case 'q':
bquit = true;
Sleep(1000);
break;
case 'P':
case 'p': //one record, other play
remove("testrecord.3gp");
VMPort[0].Record3GP("testrecord.3gp");
Sleep(1000);
VMPort[1].Play3GP("testplay.3gp");
break;
case 'S':
case 's': // stop
VMPort[0].StopRP();
VMPort[1].StopRP();
break;
case '?':
printf("\n\tp ------ play & record\n");
printf("\n\ts ------ stop rp\n");
printf("\n\tq ------ quit\n");
break;
case 13:
case 10:
printf("\n>");
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -