📄 videocommdlg.cpp
字号:
{
static int nPortCount = 0;
static time_t time1, time2;
double elapsed_time = 0;
CString strlhfOwn="终端 lhf 正在广播.";
CString strwhoOwn="终端 who 正在广播.";
CString strlzgOwn="终端 lzg 正在广播.";
int j=0;
int a=0;
int b=0;
BYTE i;
BYTE byFFCode = 0xff;
BYTE byTempCode=0;
static BYTE byWatchingPortNumber = 0;
CCheckError CheckError;
if(bFrameState == FS_VALID)
{
if(pFrame[0]>=1 && pFrame[0]<=31)//Is video quant, Tell all port
{
//SendPacketToAllPort
ChannelToVideoDec(pFrame,nLength);
return;
}
else
{
switch(pFrame[0])
{
case TRequestAddConference://Send
CheckError.CaculateCRC(pFrame, nLength, pFrame, &nLength);
if(m_pCommandSendChannel && (nFromWhere == COMMANDFROMTOOLBAR))
{
m_pCommandSendChannel->SendData(pFrame, nLength);
m_pCommandSendChannel->SendData(&byFFCode,1);
//m_pCommandSendChannel->SendData(pFrame, nLength);
//m_pCommandSendChannel->SendData(&byFFCode,1);
}
break;
case TGetAddConferenceAck://Receive
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
//Tell User this terminal has added conference right
m_bHaveAnswer = TRUE;
m_TPortStatus.m_bAddConference = TRUE;
m_HaveAddConference.SetCheck(1);//Check the add conference button
//After add conference, enable these button
m_PaletteBar.SetState(ID_BROADCAST, TBSTATE_ENABLED);
m_PaletteBar.SetState(ID_EXITCONFERENCE, TBSTATE_ENABLED);
m_PaletteBar.SetState(ID_DATA, TBSTATE_ENABLED);
break;
case TGetTerminalHaveAddedConference://Receive
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
//Save this port's name and number
for(i=0; i<pFrame[2]; i++)//pFrame[2] is the port name's length
{
AllTerminalName[m_nTotalAddTerminalCount][i] = (char)pFrame[3+i];//Next is the port name string
}
AllTerminalName[m_nTotalAddTerminalCount][i]='\0';
//First we see that the new name is same as old, if so, do nothing
//else, add this name
for(i=0; i<m_nTotalAddTerminalCount; i++)
{
if(strcmp(AllTerminalName[i], AllTerminalName[m_nTotalAddTerminalCount]) == 0)//Equal
return;
}
m_NameInConference.AddString(AllTerminalName[m_nTotalAddTerminalCount]);
NameNumber[m_nTotalAddTerminalCount].Name = AllTerminalName[m_nTotalAddTerminalCount];//Record this name
NameNumber[m_nTotalAddTerminalCount].Number = pFrame[1];//Is port number
m_nTotalAddTerminalCount++;
if(m_nTotalAddTerminalCount >= MAXPORTNUMBER)//The terminal number cann't more than MAXPORTNUMBER
{
MessageBox("加入的终端数目大于规定的最大数目,请重新设置!");
return;
}
//Display in userface
//----------------Do something--------------------
break;
case TRequestToken://Send
CheckError.CaculateCRC(pFrame, nLength, pFrame, &nLength);
if(m_pCommandSendChannel && (nFromWhere == COMMANDFROMTOOLBAR))
{
m_pCommandSendChannel->SendData(pFrame, nLength);
m_pCommandSendChannel->SendData(&byFFCode,1);
}
break;
case TOwnToken://Receive
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
m_bHaveAnswer = TRUE;
//Tell user this terminal own token
m_TPortStatus.m_bRequestTokenRefused=FALSE;
m_TPortStatus.m_bOwnToken = TRUE;
if(!m_bVideoCRC)
{
bPause = TRUE;
::Sleep(STARTSENDAFTERSECONDS * 1000);//waiting for some time
bPause = FALSE;
}
m_IsBroadcasting.SetCheck(1);
m_PaletteBar.SetState(ID_BROADCAST, TBSTATE_CHECKED);
m_PaletteBar.SetState(ID_STOPBROADCAST, TBSTATE_ENABLED);
break;
case TRequestTokenRefuse://Receive
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
m_bHaveAnswer = TRUE;
m_PaletteBar.SetState(ID_BROADCAST, TBSTATE_ENABLED);
//Tell user this terminal request token have been refused
m_TPortStatus.m_bRequestTokenRefused = TRUE;
m_TPortStatus.m_bOwnToken = FALSE;
//Because we send command 5 times, this dialog will display max 5 times.
//so here we judge the elapsed time, if too short(<RepeatSendCommandInternal * 2 /1000)
//we think this is the repeat command, so not display this dialog
::time(&time1);
elapsed_time = ::difftime(time1, time2);
if(elapsed_time > (RepeatSendCommandInternal * 2 /1000))
MessageBox("请求广播被拒绝,请少后再试!");
time2 = time1;//save the old time
break;
case TRequestReleaseToken://Send
CheckError.CaculateCRC(pFrame, nLength, pFrame, &nLength);
if(m_pCommandSendChannel && (nFromWhere == COMMANDFROMTOOLBAR))
{
m_pCommandSendChannel->SendData(pFrame, nLength);
m_pCommandSendChannel->SendData(&byFFCode,1);
}
break;
case TGetReleaseTokenAck://Receive
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
m_bHaveAnswer = TRUE;
//Stop video and audio send
/*
if(m_bHaveStartVideoAudio)
{
m_bHaveStartVideoAudio = FALSE;
m_pWaveIn->End();
m_pVideoCapture->EndCap();
m_pWaveOut->End();
m_pDisplay->End();
}
*/
//Tell user have released token sucessuflly
m_TPortStatus.m_bOwnToken = FALSE;
m_IsBroadcasting.SetCheck(0);
m_PaletteBar.SetState(ID_BROADCAST, TBSTATE_ENABLED);
m_PaletteBar.SetState(ID_STOPBROADCAST, TBSTATE_CHECKED);
if(!m_bVideoCRC)
{
bPause = TRUE;
::Sleep(STARTSENDAFTERSECONDS * 1000);//waiting for some time
bPause = FALSE;
}
break;
case TWantWatch://Send, pFrame[1] record this port want to watching port
CheckError.CaculateCRC(pFrame, nLength, pFrame, &nLength);
byWatchingPortNumber = pFrame[1];
//Now send ack CI
if(m_pCommandSendChannel && (nFromWhere == COMMANDFROMTOOLBAR))
{
m_pCommandSendChannel->SendData(pFrame, nLength);
m_pCommandSendChannel->SendData(&byFFCode,1);
}
break;
case TGetWantWatchAck://Receive
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
m_bHaveAnswer = TRUE;
//Tell user have the termial that it want
m_TPortStatus.m_byThisPortWatched = byWatchingPortNumber;
m_WantWatchOK.SetCheck(1);
m_PaletteBar.SetState(ID_WATCHONE, TBSTATE_CHECKED);
m_PaletteBar.SetState(ID_STOPWATCHONE, TBSTATE_ENABLED);
break;
case TGetWantWatchRefuse://Receive
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
m_bHaveAnswer = TRUE;
//Tell user have the termial that it want
m_TPortStatus.m_byThisPortWatched = WANT_WATCH_REFUSED;
MessageBox("现在你不能查看这个终端!");
break;
case TStopWatch://Send
CheckError.CaculateCRC(pFrame, nLength, pFrame, &nLength);
if(m_pCommandSendChannel && (nFromWhere == COMMANDFROMTOOLBAR))
{
m_pCommandSendChannel->SendData(pFrame, nLength);
m_pCommandSendChannel->SendData(&byFFCode,1);
}
break;
case TGetStopWatchAck://Receive
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
m_bHaveAnswer = TRUE;
//Tell user have the termial that it want
m_TPortStatus.m_byThisPortWatched = 0;
m_WantWatchOK.SetCheck(0);
m_PaletteBar.SetState(ID_WATCHONE, 0);
m_PaletteBar.SetState(ID_STOPWATCHONE, 0);
break;
case TRequestExitConference://send
CheckError.CaculateCRC(pFrame, nLength, pFrame, &nLength);
if(m_pCommandSendChannel && (nFromWhere == COMMANDFROMTOOLBAR))
{
m_pCommandSendChannel->SendData(pFrame, nLength);
m_pCommandSendChannel->SendData(&byFFCode,1);
}
break;
case TGetExitConferenceAck://receive
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
m_bHaveAnswer = TRUE;
if(m_bBegin)//Not end
OnEnd();
break;
case TSomeoneWantWatchMe://receive
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
//--------Here we can ask user that he agree--------------
//Now we start video and audio
m_bIsWatched = TRUE;
m_IsWatched.SetCheck(1);
if(!m_bVideoCRC)
{
bPause = TRUE;
::Sleep(STARTSENDAFTERSECONDS * 1000);//waiting for some time
bPause = FALSE;
}
break;
case TSomeoneStopWatchMe://receive
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
m_bIsWatched = FALSE;
m_IsWatched.SetCheck(0);
if(!m_bVideoCRC)
{
bPause = TRUE;
::Sleep(STARTSENDAFTERSECONDS * 1000);//waiting for some time
bPause = FALSE;
}
break;
case TLzgOwnToken:
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
SetDlgItemText(IDC_OWNTOKEN,strlzgOwn);
break;
case TLhfOwnToken:
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
SetDlgItemText(IDC_OWNTOKEN,strlhfOwn);
break;
case TWhoOwnToken:
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
SetDlgItemText(IDC_OWNTOKEN,strwhoOwn);
break;
case TWhoReleaseToken:
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
SetDlgItemText(IDC_OWNTOKEN,"");
break;
case TLhfReleaseToken:
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
SetDlgItemText(IDC_OWNTOKEN,"");
break;
case TLzgReleaseToken:
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
SetDlgItemText(IDC_OWNTOKEN,"");
break;
case TLzgExitConference:
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
//Save this port's name and number
for(i=0; i<pFrame[1]; i++)//pFrame[2] is the port name's length
{
AllTerminalName[m_nTotalAddTerminalCount][i] = (char)pFrame[2+i];//Next is the port name string
}
//AllTerminalName[m_nTotalAddTerminalCount][i]='\0';
j = m_NameInConference.SelectString(-1,AllTerminalName[m_nTotalAddTerminalCount]);
//j=j-1;
m_NameInConference.DeleteString(j);
break;
case TLhfExitConference:
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
for(i=0; i<pFrame[1]; i++)//pFrame[2] is the port name's length
{
AllTerminalName[m_nTotalAddTerminalCount][i] = (char)pFrame[2+i];//Next is the port name string
}
//AllTerminalName[m_nTotalAddTerminalCount][i]='\0';
a = m_NameInConference.SelectString(-1,AllTerminalName[m_nTotalAddTerminalCount]);
//a=a-1;
m_NameInConference.DeleteString(a);
break;
case TWhoExitConference:
if(!(CheckError.IsDataRigth(pFrame, nLength, pFrame, &nLength)))//not right crc
return;
//Save this port's name and number
for(i=0; i<pFrame[1]; i++)//pFrame[2] is the port name's length
{
AllTerminalName[m_nTotalAddTerminalCount][i] = (char)pFrame[2+i];//Next is the port name string
}
//AllTerminalName[m_nTotalAddTerminalCount][i]='\0';
b = m_NameInConference.SelectString(-1,AllTerminalName[m_nTotalAddTerminalCount]);
// b=b-1;
m_NameInConference.DeleteString(b);
break;
}
}
}
}
void CVideoCommDlg::OnChangeName()
{
// TODO: Add your control notification handler code here
char Name[MAXNAMELENGTH];
BYTE byLength;
UpdateData();
byLength = m_MyName.GetLength();
if(byLength > 4)
{
MessageBox("名字太长,必须小于等于4个字符!");
return;
}
for(int i=0; i<byLength; i++)
Name[i] = m_MyName[i];
m_TPortStatus.SetPortName(Name, byLength);
//Save the name to registry
HKEY hKey = NULL;
DWORD dwDisposition = 0;
long re0 = ::RegCreateKeyEx(HKEY_CURRENT_USER, data_Set, NULL,
NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&hKey, &dwDisposition);
if(re0 != ERROR_SUCCESS)//Open or create fail
MessageBox("无法打开注册表!");
else
{
//Query data about Port rate, video quant and this teminal's name
DWORD dwLength = byLength;
BYTE cUserName[MAXNAMELENGTH+1];
::CopyMemory(cUserName, Name, byLength);
cUserName[byLength] = 0;
//cUserName[byLength]=0;
long re1 = ::RegSetValueEx(hKey, "Name", NULL, REG_SZ, cUserName, dwLength);
if(re1 != ERROR_SUCCESS)
MessageBox("错误:无法写入注册表!");
//delete cUserName;
::RegCloseKey(hKey);
}
}
void CVideoCommDlg::OnSelChangeName()
{
// TODO: Add your control notification handler code here
int nUserSel = 0;
nUserSel = m_NameInConference.GetCurSel();
if(nUserSel != LB_ERR)//List box not empty
{
if(!(m_PaletteBar.IsButtonChecked(ID_WATCHONE)))
{
if(m_TPortStatus.m_bOwnToken)
{
m_PaletteBar.SetState(ID_WATCHONE, TBSTATE_ENABLED);
m_PaletteBar.SetState(ID_STOPWATCHONE, 0);
}
}
}
}
void CVideoCommDlg::OnDblClkName()
{
// TODO: Add your control notification handler code here
int nUserSel = 0;
nUserSel = m_NameInConference.GetCurSel();
if(nUserSel != LB_ERR)//List box not empty
{
if(!(m_PaletteBar.IsButtonChecked(ID_WATCHONE)))
{
if(m_TPortStatus.m_bOwnToken)//if this termnial is broadcasting
{
m_PaletteBar.SetState(ID_WATCHONE, TBSTATE_ENABLED);
m_PaletteBar.SetState(ID_STOPWATCHONE, 0);
}
}
}
}
void CVideoCommDlg::OnBarBegin()
{
BeginWaitCursor();
m_bIsMulticast = TRUE;
//DisplayInfo("正在加入会议\0", TRUE);
//begin video communication
//initialization
m_pAudioReceiveChannel->Initialize(this);
m_pVideoReceiveChannel->Initialize(this);
m_pDataReceiveChannel->Initialize(this);
m_pCommandReceiveChannel->Initialize(this);
m_pFileReceiveChannel->Initialize(this);
//加通道
m_pMultiplex->AddAChannel(m_pAudioSendChannel);
m_pDemultiplex->AddAChannel(m_pAudioReceiveChannel);
m_pMultiplex->AddAChannel(m_pVideoSendChannel);
m_pDemultiplex->AddAChannel(m_pVideoReceiveChannel);
m_pMultiplex->AddAChannel(m_pCommandSendChannel);
m_pDemultiplex->AddAChannel(m_pDataReceiveChannel);
m_pMultiplex->AddAChannel(m_pDataSendChannel);
m_pDemultiplex->AddAChannel(m_pCommandReceiveChannel);
m_pMultiplex->AddAChannel(m_pFileSendChannel);
m_pDemultiplex->AddAChannel(m_pFileReceiveChannel);
m_pG723Decoder->Initialize();
m_pG723Encoder->Initialize();
//begin the board at a specific rate
switch(m_nPortRate)
{
case 0:
m_pInterfaceToBoard->Begin(RATE_16K);break;
case 1:
m_pInterfaceToBoard->Begin(RATE_32K);break;
case 2:
m_pInterfaceToBoard->Begin(RATE_64K);break;
default:
m_pInterfaceToBoard->Begin();//begin with the default rate
}
//Start video and audio
//We don't send video and audio when starting.
//We send them only when I boradcast or someone want watch me
m_pVideoCapture->SetCapSize();//注意顺序
m_pVideoCapture->InitCap(GetDlgItem(IDC_LOCALSCREEN)->m_hWnd,this);
m_bHaveStartVideoAudio = TRUE;
m_pVideoCapture->StartCap();
m_pWaveIn->Begin((DWORD)this);
m_pWaveOut->Begin((DWORD)this);
m_pDisplay->Begin(&m_RemoteScreen);
//Display status
SetTimer(DISPLAY_STATUS,StatusInternal,NULL);
//Open or close some button
m_bBegin=TRUE;
g_bBegin=TRUE;
SetDlgItemText(IDC_BEGIN,"结束");
//After begining, we can push this button
/*
m_PaletteBar.SetState(ID_BEGIN, TBSTATE_CHECKED);
m_PaletteBar.SetState(ID_END, TBSTATE_ENABLED);
m_PaletteBar.SetState(ID_ADDCONFERENCE, TBSTATE_ENABLED);
*/
m_PaletteBar.SetState(ID_ADDCONFERENCE, TBSTATE_CHECKED);
//m_PaletteBar.SetState(ID_EXITCONFERENCE, TBSTATE_ENABLED);
EndWaitCursor();
}
void CVideoCommDlg::OnEnd()
{
BeginWaitCursor();
m_bIsMulticast = FALSE;
//end communication
KillTimer(DISPLAY_STATUS);
m_bBegin=FALSE;
g_bBegin=FALSE;
m_nSendCommandCount = 0;
SetDlgItemText(IDC_BEGIN,"开始");
//After ended, we cann't push this button
//m_PaletteBar.SetState(ID_BEGIN, TBSTATE_ENABLED);
//m_PaletteBar.SetState(ID_END, 0);
m_PaletteBar.SetState(ID_ADDCONFERENCE, TBSTATE_ENABLED);
m_PaletteBar.SetState(ID_EXITCONFERENCE, 0);
m_PaletteBar.SetState(ID_BROADCAST, 0);
m_PaletteBar.SetState(ID_STOPBROADCAST, 0);
m_PaletteBar.SetState(ID_WATCHONE, 0);
m_PaletteBar.SetState(ID_STOPWATCHONE, 0);
m_PaletteBar.SetState(ID_DATA, 0);
m_HaveAddConference.SetCheck(0);
m_IsBroadcasting.SetCheck(0);
m_IsWatched.SetCheck(0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -