📄 videocommdlg.cpp
字号:
// VideoCommDlg.cpp : implementation file
#include "stdafx.h"
#include "VideoComm.h"
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <afxmt.h>
#include <afxtempl.h>
#include <winreg.h>
#include "CPacker.h"
#include "CChannel.h"
#include "CMultiplex.h"
#include "CDemultiplex.h"
#include "CByteBuffer.h"
#include "typedef2.h"
#include "cst2.h"
#include "tab2.h"
#include "G723.h"
#include "coder2.h"
#include "decod2.h"
#include "exc2.h"
#include "util2.h"
#include "codcng2.h"
#include "deccng2.h"
#include "vad2.h"
#include "G723.h"
#include "WaveIO.h"
#include "CChannel.h"
#include "CByteBuffer.h"
#include "LoopElementBuffer.h"
#include "SafeList.h"
#include "color.h"
#include "DBitstream.h"
#include "sactable.h"
#include "sad.h"
#include "Dh263class.h"
#include "commonfunc.h"
#include "ExpandYUV411.h"
#include "h263displayer.h"
#include "CBitstream.h"
#include "sac.h"
#include "Ch263class.h"
#include "h263encoder.h"
#include "callbackfunc.h"
#include "InterfaceToBoard.h"
#include "TheInterfaceToBoard.h"
#include "configdlg.h"
#include "checkerror.h"
#include "VideoCommDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVideoCommDlg dialog
CVideoCommDlg * pVideoCommDlg;
BOOL bExpand=FALSE;
int gnReceivedBytes=0;
LPCTSTR data_Set = "Software\\sci\\SetInfo";
CSendChannel* g_pCommandSendChannel=NULL;
BOOL g_bBegin=FALSE;
/*
void VideoCapCallBack(BYTE* pbyContent,UINT nLength,LPVOID dwUserData)
{
static CVideoCommDlg* pDlg=(CVideoCommDlg*)dwUserData;
pDlg->VideoToPort(pbyContent,nLength);
}
*/
CVideoCommDlg::CVideoCommDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVideoCommDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CVideoCommDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_nPortRate = -1;
m_MyName = _T("");
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//m_nTimerID=3;
//m_nTimerElapse=500;
m_nPortRate=1;
m_nQuant=4;
m_bHaveStartVideoAudio = FALSE;
m_bBegin=FALSE;
m_bCreating=FALSE;
m_bDeleting=FALSE;
m_uFrameCount=0;
pVideoCommDlg=this;
m_pAudioDecodeBuffer=NULL;
m_pVideoDecodeBuffer=NULL;
m_pVideoCapture=NULL;
m_pG723Decoder=NULL;
m_pG723Encoder=NULL;
m_pH263Encoder=NULL;
m_pDisplay=NULL;
m_pAudioReceiveChannel=NULL;
m_pAudioSendChannel=NULL;
m_pVideoReceiveChannel=NULL;
m_pVideoSendChannel=NULL;
m_pVideoCapture=NULL;
m_pDataReceiveChannel=NULL;
m_pDataSendChannel=NULL;
m_pCommandReceiveChannel=NULL;
m_pCommandSendChannel=NULL;
m_pFileReceiveChannel=NULL;
m_pFileSendChannel=NULL;
m_pMultiplex=NULL;
m_pDemultiplex=NULL;
m_pWaveIn=NULL;
m_pWaveOut=NULL;
m_pInterfaceToBoard=NULL;
//m_pcTPortStatus = NULL;
m_nTotalAddTerminalCount = 0;
if(!CreateObject())
MessageBox("不能创建对象,请退出程序!");
//m_lpszCommSetting = "9600, n, 8, 1";//This will modify
//m_pbySaveComData = NULL;
m_nSendCommandCount = 0;
m_bHaveAnswer = FALSE;
m_nNowCommand = 0;
m_bIsSendingCommand = FALSE;
m_hFinishFileTransmit = NULL;
m_bIsWatched = FALSE;
m_bIsMulticast = FALSE;
m_byAction = MEDONOTHINGABOUTFILE;
m_bVideoCRC = FALSE;
m_bSoftAudio = TRUE;
//Get User parameter setting from registry
GetUserSetting();
}
void CVideoCommDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVideoCommDlg)
DDX_Control(pDX, IDC_INFORMATION, m_DisplayInfo);
DDX_Control(pDX, IDC_ISWATCHED, m_IsWatched);
DDX_Control(pDX, IDC_WANTWATCHOK, m_WantWatchOK);
DDX_Control(pDX, IDC_NAME, m_NameInConference);
DDX_Control(pDX, IDC_ISBROADCASTING, m_IsBroadcasting);
DDX_Control(pDX, IDC_ADDCONFERENCE, m_HaveAddConference);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVideoCommDlg, CDialog)
//{{AFX_MSG_MAP(CVideoCommDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BEGIN, OnBegin)
ON_WM_HSCROLL()
ON_WM_MOVE()
ON_BN_CLICKED(IDC_CHANGENAME, OnChangeName)
ON_LBN_SELCHANGE(IDC_NAME, OnSelChangeName)
ON_LBN_DBLCLK(IDC_NAME, OnDblClkName)
ON_BN_CLICKED(ID_ADDCONFERENCE, OnAddConference)
ON_BN_CLICKED(ID_EXITCONFERENCE, OnExitConference)
ON_BN_CLICKED(ID_BROADCAST, OnBroadcast)
ON_BN_CLICKED(ID_STOPBROADCAST, OnStopBroadcast)
ON_BN_CLICKED(ID_WATCHONE, OnWatchOne)
ON_BN_CLICKED(ID_STOPWATCHONE, OnStopWatchOne)
ON_BN_CLICKED(ID_DATA, OnData)
ON_BN_CLICKED(IDC_ADVANCED, OnAdvanced)
ON_BN_CLICKED(IDC_FILETRANSMIT, OnFileTransmit)
ON_WM_SIZE()
ON_WM_LBUTTONDOWN()
ON_WM_CANCELMODE()
ON_WM_CAPTURECHANGED()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVideoCommDlg message handlers
BOOL CVideoCommDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//only run one instance of this application
CString strTitle="电子部三十所 - 低 速 多 媒 体 终 端";
if(FindWindow(NULL,strTitle))
{
PostMessage(WM_CLOSE);
return FALSE;
}
SetWindowText(strTitle);
//sub remote screen
m_RemoteScreen.SubclassDlgItem(IDC_REMOTESCREEN,this);
//Add toolbar to dialog
// WS_VISIBLE | CCS_BOTTOM | | TBSTYLE_WRAPABLE
m_PaletteBar.Create(WS_BORDER | WS_VISIBLE | WS_CHILD
| CCS_TOP | TBSTYLE_WRAPABLE/* | TBSTYLE_TOOLTIPS*/,
CRect(0,0,0,0),this, IDB_MAINTOOLBAR);
m_PaletteBar.AutoSize();
m_ToolTip.Create(this);
CString cstrToolTip;
//CWnd *pWnd;
CRect rect;
// Setup the tooltip control for tooltips with the static controls
for (int nIndex = ID_ADDCONFERENCE; nIndex <= ID_DATA; nIndex++)
{
cstrToolTip.LoadString(nIndex);
//VERIFY(pWnd = GetDlgItem(nIndex));
//pWnd->GetWindowRect(&rect);
//ScreenToClient(&rect);
m_ToolTip.AddTool(this, (LPCTSTR)cstrToolTip);
}
m_ToolTip.Activate(TRUE);
//toolbar
//m_PaletteBar.EnableButton(ID_END, FALSE);
//m_PaletteBar.EnableButton(ID_ADDCONFERENCE, FALSE);
m_PaletteBar.EnableButton(ID_EXITCONFERENCE, FALSE);
m_PaletteBar.EnableButton(ID_BROADCAST, FALSE);
m_PaletteBar.EnableButton(ID_STOPBROADCAST, FALSE);
m_PaletteBar.EnableButton(ID_WATCHONE, FALSE);
m_PaletteBar.EnableButton(ID_STOPWATCHONE, FALSE);
//m_PaletteBar.EnableButton(ID_DATA, FALSE);
/*
//Before can push Add conference button, must push begin
GetDlgItem(IDC_COMMANDADD)->EnableWindow(FALSE);
GetDlgItem(IDC_COMMANDBROADCAST)->EnableWindow(FALSE);
GetDlgItem(IDC_COMMANDEXIT)->EnableWindow(FALSE);
GetDlgItem(IDC_COMMANDSTOP)->EnableWindow(FALSE);
GetDlgItem(IDC_COMMANDWATCHONE)->EnableWindow(FALSE);
GetDlgItem(IDC_COMMANDSTOPWATCH)->EnableWindow(FALSE);
*/
//set frame rate show
CString strFR="0.00fps";
SetDlgItemText(IDC_FR,strFR);
//set bit rate
CString strRate="0.00kbps";
SetDlgItemText(IDC_RATE,strRate);
return TRUE; // return TRUE unless you set the focus to a control
}
void CVideoCommDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CVideoCommDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CVideoCommDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//定时显示帧率和速率
void CVideoCommDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
static DWORD dwStartTime=GetTickCount();
static UINT uStartFrameCount=0;
static int nStartLen=0;
static DWORD dwFrameElapse=0;
DWORD dwEndTime;
DWORD dwElapse;
int nIncrementLen;
int nIncrementFrameCount;
float fBitRate=0.0;
float fFrameRate=0.0;
switch(nIDEvent)
{
case DISPLAY_STATUS:
//get elapse time and the increment bytes
dwEndTime=GetTickCount();
dwElapse=dwEndTime-dwStartTime;
nIncrementLen=gnReceivedBytes-nStartLen;
nIncrementFrameCount=m_uFrameCount-uStartFrameCount;
if(dwElapse>0)
{
//compute the bit rate
fBitRate=(float)nIncrementLen*8/dwElapse;
CString strBitRate;
strBitRate.Format("%2.1fkbps",fBitRate);
SetDlgItemText(IDC_RATE,strBitRate);
nStartLen=gnReceivedBytes;
//compute the frame rate
dwFrameElapse+=dwElapse;
if(nIncrementFrameCount>=15||dwFrameElapse>=1500)
{
fFrameRate=(float)(nIncrementFrameCount*1000)/dwFrameElapse;
CString strFrameRate;
strFrameRate.Format("%2.1ffps",fFrameRate);
SetDlgItemText(IDC_FR,strFrameRate);
uStartFrameCount=m_uFrameCount;
dwFrameElapse=0;
}
dwStartTime=dwEndTime;
}
CDialog::OnTimer(nIDEvent);
return;
case READDATAFROMSERIAL:
return;
case REPEATSENDCOMMAND:
m_nSendCommandCount++;
CommandCallBack(m_pbyCommandFrame, m_byCILength, FS_VALID, COMMANDFROMTOOLBAR);//Send, 0----From toolbar
//if((m_nSendCommandCount > 3) || m_bHaveAnswer)
if(m_nSendCommandCount > 3)//1999.12.06, send command 5 times for a lot of error in line
{
KillTimer(REPEATSENDCOMMAND);
if(!m_bHaveAnswer)
{
MessageBox("没有受到应答,请检查线路!");
m_PaletteBar.SetState(m_nNowCommand, TBSTATE_ENABLED);
}
m_nSendCommandCount = 0;
m_bHaveAnswer = FALSE;
m_bIsSendingCommand = FALSE;
}
return;
}
}
void CVideoCommDlg::OnDestroy()
{
if(m_bBegin)
{
KillTimer(DISPLAY_STATUS);
//OnData();
OnEnd();
}
DeleteObject();
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
//点击“开始”菜单
void CVideoCommDlg::OnBegin()
{
BeginWaitCursor();
if(m_bBegin)
{
//end communication
KillTimer(DISPLAY_STATUS);
m_pWaveIn->End();
m_pVideoCapture->EndCap();
m_pInterfaceToBoard->End();
m_pWaveOut->End();
m_pDisplay->End();
m_pFileTransmit->End();
m_bBegin=FALSE;
SetDlgItemText(IDC_BEGIN,"开始");
/*
//After ended, we cann't push this button
GetDlgItem(IDC_COMMANDADD)->EnableWindow(FALSE);
GetDlgItem(IDC_COMMANDBROADCAST)->EnableWindow(FALSE);
GetDlgItem(IDC_COMMANDEXIT)->EnableWindow(FALSE);
GetDlgItem(IDC_COMMANDSTOP)->EnableWindow(FALSE);
GetDlgItem(IDC_COMMANDWATCHONE)->EnableWindow(FALSE);
GetDlgItem(IDC_COMMANDSTOPWATCH)->EnableWindow(FALSE);
*/
EndWaitCursor();
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -