playView.cpp
资源名称:VC++视频传输.rar [点击查看]
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:25k
源码类别:
VC书籍
开发平台:
Visual C++
- // playView.cpp : implementation of the CPlayView class
- //
- #include "stdafx.h"
- #include "play.h"
- #include "playDoc.h"
- #include "playView.h"
- #include "MainFrm.h"
- #include "av8api.h"
- #include "Define.h"
- #include "Dos.h"
- #include "direct.h"
- #include "Afxmt.h"
- #include "Windowsx.h"
- #include "StopModeDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define BLOCKNUM 50
- #define BLOCKLEN 32768 //32k
- #define FILE_CLOSE(x) if(x) { mmioClose(x, NULL);x=NULL;}
- #define RELEASE_AV8BUFFER if(g_pBuffer) {g_pBuffer->Stop();delete g_pBuffer;g_pBuffer = NULL;}
- #define RELEASE_CVIDEOPLAY if(pVideoPlay){pVideoPlay->StopPlay();delete pVideoPlay;pVideoPlay=NULL;}
- extern CMenu PopMenu;
- BOOL m_Capture=FALSE; //是否采集
- CAV8Buffer *g_pBuffer = NULL;
- HMMIO hmmioOutput; //采集文件的句斌
- HMMIO hmmioSendOutput; //发送时保存文件的句斌
- CString CapFileName; //采集文件名
- BOOL m_FileSend=FALSE; //是否在发送文件数据
- CEvent g_eventFileStopSend; //停止发送文件标志,自动设置
- CEvent g_eventRealSend(FALSE,TRUE,NULL,NULL); //开始实时发送标志,手工设置
- CEvent g_eventClearup; //完成清除工作,可以Destory窗口标志
- HWND hWnd ;//发送数窗口的句斌
- float m_size=0.00; //采集数据大小
- CString SendFilePath="";
- #define WM_CAPTURE_STOP WM_USER+1000 //采集大小到,停止采集
- //发送组播数据
- DWORD SendData(LPWSABUF stWSABuf)
- {
- CString msg;
- DWORD cbRet;
- cbRet = 0;
- CPlayApp* pApp=(CPlayApp*)AfxGetApp();
- //向指定地址发送数据
- int status = WSASendTo (MultiSock, /* socket */
- stWSABuf, /* output buffer structure */
- 1, /* buffer count */
- &cbRet, /* number of bytes sent */
- 0, /* flags */
- (struct sockaddr FAR *)&DestAddr,/* destination address */
- sizeof(DestAddr), /* size of addr structure */
- NULL, /* overlapped structure */
- NULL); /* overlapped callback function */
- if (status == SOCKET_ERROR)
- {
- AfxMessageBox("WSASendTo() Error");
- return -1;
- }
- return cbRet;
- }
- //视频文件发送线程
- UINT FileSendThread(LPVOID pParam)
- {
- CFile hFile;
- DWORD dwFlags;
- DWORD SendLen;
- DWORD dwReadLength;
- DWORD dwBytesRead;
- int status;
- WSABUF SendBuf;
- dwReadLength=BUFSIZE;
- //分配发送缓冲区
- SendBuf.buf=(char *)malloc(BUFSIZE);
- status=hFile.Open(SendFilePath,CFile::modeRead);
- dwFlags = MMIO_CREATE | MMIO_WRITE;
- if(status==0)
- {
- //释放发送缓冲区
- free(SendBuf.buf);
- return -1;
- }
- else
- {
- while(1)
- {
- //每次读数据32k
- dwBytesRead=hFile.Read(SendBuf.buf,dwReadLength);
- if(dwBytesRead==0)
- {//发送完成
- //关闭文件
- hFile.Close();
- //释放发送缓冲区
- free(SendBuf.buf);
- AfxMessageBox("发送完成");
- break;
- }
- SendBuf.len = dwBytesRead;
- //发送数据
- SendLen=SendData(&SendBuf);
- if(::WaitForSingleObject(g_eventFileStopSend,0)==WAIT_OBJECT_0)
- {
- hFile.Close();
- free(SendBuf.buf);
- AfxMessageBox("停止发送");
- break;
- }
- Sleep(250);
- }
- }
- //文件发送标志置为FALSE
- m_FileSend=FALSE;
- return 0;
- }
- //实时视频流发送线程
- UINT RealSendThread(LPVOID pParam)
- {
- int temp;
- //发送缓冲区
- LPWSABUF RealSendBuf = (LPWSABUF)pParam;
- //开始实时发送
- g_eventRealSend.ResetEvent();
- //发送数据
- temp=SendData(RealSendBuf);
- //实时保存视频流到指定文件中
- if(hmmioSendOutput)
- mmioWrite(hmmioSendOutput, (LPSTR) RealSendBuf->buf,temp);
- free(RealSendBuf->buf);
- GlobalFreePtr(RealSendBuf);
- g_eventRealSend.SetEvent();
- return 0;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CPlayView
- IMPLEMENT_DYNCREATE(CPlayView, CView)
- BEGIN_MESSAGE_MAP(CPlayView, CView)
- //{{AFX_MSG_MAP(CPlayView)
- ON_WM_SIZE()
- ON_WM_CONTEXTMENU()
- ON_COMMAND(ID_POP_FILE_SEND, OnPopFileSend)
- ON_COMMAND(ID_POP_REAL_SEND, OnPopRealSend)
- ON_COMMAND(ID_POP_SEND_STOP, OnPopSendStop)
- ON_COMMAND(ID_CAPTURE_SAVE, OnCaptureSave)
- ON_COMMAND(ID_BEGIN_CAPTURE, OnBeginCapture)
- ON_COMMAND(ID_STOP_CAPTURE, OnStopCapture)
- ON_COMMAND(ID_OPEN_PLAYFILE, OnOpenPlayfile)
- ON_COMMAND(ID_PLAYFILE, OnPlayfile)
- ON_COMMAND(ID_FILE_STOP, OnFileStop)
- ON_COMMAND(ID_REALPLAY, OnRealplay)
- ON_COMMAND(ID_REAL_STOP, OnRealStop)
- ON_WM_TIMER()
- ON_COMMAND(ID_PAUSE_PLAY, OnPausePlay)
- ON_COMMAND(ID_RESUME_PLAY, OnResumePlay)
- ON_WM_ERASEBKGND()
- ON_COMMAND(ID_PAUSE_CAPTURE, OnPauseCapture)
- ON_COMMAND(ID_RESUME_CAPTURE, OnResumeCapture)
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_VIEW_OUTBAR_NOTIFY, OnOutbarNotify)
- ON_MESSAGE(WM_PLAYOVER,OnPlayOver)
- ON_MESSAGE(WM_READYSEND,OnReadyRealSend)
- ON_MESSAGE(WM_PREPARE_CLOSE,OnPrepareClose)
- ON_MESSAGE(WM_CAPTURE_STOP,OnCaptureStop)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPlayView construction/destruction
- //响应WM_CAPTURE_STOP消息,采集大小到,停止采集
- LRESULT CPlayView::OnCaptureStop(WPARAM wParam, LPARAM lParam)
- {
- //停止采集
- OnStopCapture();
- MessageBox("采集数量到,停止采集");
- //采集大小标志置为FALSE
- m_SizeCheck=FALSE;
- return 0;
- }
- LRESULT CPlayView::OnOutbarNotify(WPARAM wParam, LPARAM lParam)
- {
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- switch (wParam)
- {
- case NM_OB_ITEMCLICK:
- {
- int nFolder =pFrame->m_wndOutlookBar.GetSelFolder();
- int nIndex = (int)lParam;
- switch (nFolder)
- {
- case PLAY:
- {
- switch (nIndex)
- {
- case Play_Set:
- break;
- case Play_Open:
- OnOpenPlayfile();
- break;
- case Play_Begin:
- OnPlayfile();
- break;
- case Play_Pause:
- pVideoPlay->PausePlay();
- KillTimer(ID_TIMER);
- pFrame->m_wndStatusBar.SetPaneText(0,"暂停");
- break;
- case Play_Resume:
- pVideoPlay->ResumePlay();
- SetTimer(ID_TIMER,1000,NULL);
- pFrame->m_wndStatusBar.SetPaneText(0,"播放");
- break;
- case Play_Stop:
- OnFileStop();
- break;
- }
- }
- break;
- case CAPTURE: // Management folder is selected...
- {
- switch (nIndex)
- {
- case Cap_Preview:
- OnRealplay();
- break;
- case Cap_Set:
- OnCaptureSave();
- break;
- case Cap_Begin:
- OnBeginCapture();
- break;
- case Cap_Stop:
- OnStopCapture();
- break;
- }
- }
- break;
- }
- }
- }
- return 0;
- }
- LRESULT CPlayView::OnPrepareClose(WPARAM wParam, LPARAM lParam)
- {
- RELEASE_CVIDEOPLAY;
- //关闭设备
- ClearDriver();
- if(m_FileSend)
- g_eventFileStopSend.SetEvent();
- //如果在发送实时视频流,等待线程结束,释放文件句斌
- if(m_RealSend)
- ::WaitForSingleObject(g_eventRealSend,INFINITE);
- RELEASE_AV8BUFFER;
- //关闭采集文件句柄
- FILE_CLOSE(hmmioOutput);
- //关闭保存文件句柄
- FILE_CLOSE(hmmioSendOutput);
- g_eventClearup.SetEvent();
- return 0;
- }
- CPlayView::CPlayView()
- {
- // TODO: add construction code here
- pVideoPlay=NULL;
- SendCounter=0;
- hWnd=m_hWnd;
- m_hVFDrv=NULL;
- m_RealSend=FALSE;
- m_TPlayFile=FALSE;
- m_TCapture=FALSE;
- m_SizeCheck=FALSE;
- m_TimeCheck=FALSE;
- m_time=0;
- m_TimeIndex=0;
- Fname="";
- Ts=CTimeSpan(0,0,0,0);
- Pos=0;
- m_font.CreatePointFont(90, "宋体");
- }
- CPlayView::~CPlayView()
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // CPlayView drawing
- void CPlayView::OnDraw(CDC* pDC)
- {
- CPlayDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CPlayView diagnostics
- #ifdef _DEBUG
- void CPlayView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CPlayView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CPlayDoc* CPlayView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPlayDoc)));
- return (CPlayDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CPlayView message handlers
- void CPlayView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
- {
- // TODO: Add your specialized code here and/or call the base class
- CView::CalcWindowRect(lpClientRect, nAdjustType);
- }
- void CPlayView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- RECT grc;
- // TODO: Add your message handler code here
- if(pVideoPlay)
- {
- if(pVideoPlay->pivw)
- {
- GetClientRect(&grc);
- pVideoPlay->pivw->SetWindowPosition(grc.left, grc.top, grc.right, grc.bottom);
- }
- }
- }
- void CPlayView::OnContextMenu(CWnd* pWnd, CPoint point)
- {
- // TODO: Add your message handler code here
- PopMenu.GetSubMenu(0)->TrackPopupMenu(TPM_RIGHTBUTTON|TPM_LEFTALIGN,point.x,point.y,this);
- }
- //响应发送视频文件命令
- void CPlayView::OnPopFileSend()
- {
- // TODO: Add your command handler code here
- CFileDialog dlg(TRUE,NULL,NULL,NULL,"mpeg文件(*.mpg)|*.mpg|AVI文件(*.avi)|*.avi");
- dlg.m_ofn.lpstrTitle="打开多媒体文件";
- if(dlg.DoModal()==IDOK)
- {
- SendFilePath=dlg.GetPathName();
- m_FileSend=TRUE;
- //开始文件发送线程
- AfxBeginThread(FileSendThread,NULL);
- // if(!pVideoPlay)
- // {
- // pVideoPlay=new CVideoPlay(this->m_hWnd);
- // pVideoPlay->PlayFromFile(SendFilePath);
- // }
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(1,"在发送文件数据");
- }
- }
- //响应WM_READYSEND消息,启动发送线程
- LRESULT CPlayView::OnReadyRealSend(WPARAM wParam,LPARAM lParam)
- {
- LPWSABUF stWSABuf;
- stWSABuf=(LPWSABUF)GlobalAllocPtr(GHND,sizeof(WSABUF));
- stWSABuf->buf = (char *)malloc(BUFSIZE);
- if (g_pBuffer)
- g_pBuffer->PopOut ((LPSTR)stWSABuf->buf, BUFSIZE);
- stWSABuf->len = BUFSIZE;
- ::WaitForSingleObject(g_eventRealSend,INFINITE);
- AfxBeginThread(RealSendThread,stWSABuf);
- return 0;
- }
- //响应实时发送命令
- void CPlayView::OnPopRealSend()
- {
- DWORD dwFlags;
- //如果视频流缓冲区尚未建立,分配视频流缓冲区
- if (! g_pBuffer)
- g_pBuffer = new CAV8Buffer(BLOCKNUM, BLOCKLEN);
- //如果当前不在实时采集数据,启动视频采集卡采集数据
- if((!m_RealSend)&&(!m_Capture))
- {
- if(InitDriver()<0)
- return;
- }
- //打开一个本地存放文件
- dwFlags = MMIO_CREATE | MMIO_WRITE;
- hmmioSendOutput = mmioOpen("temp.mpg", (LPMMIOINFO)NULL, dwFlags);
- //实时发送标志置为TRUE
- m_RealSend=TRUE;
- //设置实时发送事件就绪
- g_eventRealSend.SetEvent();
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(1,"在发送实时数据");
- }
- void CPlayView::OnPopSendStop()
- {
- // TODO: Add your command handler code here
- if(m_FileSend)
- g_eventFileStopSend.SetEvent();
- if(m_RealSend)
- {
- if(!m_Capture)
- ClearDriver();
- RELEASE_AV8BUFFER;
- ::WaitForSingleObject(g_eventRealSend,INFINITE);//等待线程结束,释放文件句斌
- FILE_CLOSE(hmmioSendOutput);
- m_RealSend=FALSE;
- }
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(1,"停止发送");
- }
- //回调函数,实现对视频采集卡传递进来的数据流的处理
- WORD CALLBACK _loadds MyCallBack(HDRVR hdrvr, UINT msg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2)
- {
- if(msg==VF_MSGUSER_BUF_WRITE)
- {
- LONG lRet;
- MMIOINFO mmioinfoIn;
- LPVF_BUFWRITE_STRUCT lpBufWrite = (LPVF_BUFWRITE_STRUCT)dwParam1;
- //将传递进来的数据压入视频流缓冲区队列
- if (g_pBuffer)
- DWORD dwBytes = g_pBuffer->PushIn((LPSTR)lpBufWrite -> lpBuffer, (DWORD)lpBufWrite -> dwBufferWrite);
- //如果现在在采集数据,将数据写入到采集文件中
- if (m_Capture)
- if(hmmioOutput)
- {
- lRet = mmioWrite(hmmioOutput, (LPSTR)lpBufWrite -> lpBuffer, (LONG)lpBufWrite -> dwBufferWrite);
- mmioGetInfo(hmmioOutput,&mmioinfoIn, 0);
- //采集文件满,发送停止采集消息
- if(mmioinfoIn.lDiskOffset>(m_size*1024*1024))
- ::SendMessage(hWnd,WM_CAPTURE_STOP,0,0);
- }
- if (lRet == -1L)
- return (FALSE);
- }
- return 1;
- }
- int CPlayView::InitDriver()
- {
- WORD flags;
- //打开设备驱动
- m_hVFDrv = OpenDriver (L"av8api.dll", NULL, NULL);
- if (!m_hVFDrv)
- {
- MessageBox("Can't OpenDriver()");
- return -1;
- }
- //检查是否有设备驱动可用,如有,将打开的设备与驱动程序关联起来
- if (!HVFAssign(m_hVFDrv, 0))
- {
- MessageBox("没有合适的视频设备!");
- return -1;
- }
- //锁定设备
- HVFLock(m_hVFDrv, VF_CAP_ALL);
- flags = VF_FLAG_MPEG | VF_FLAG_ENCODE | VF_FLAG_OUTBUF;
- //打开流数据
- m_bStream = static_cast<BYTE> (HVFOpen(m_hVFDrv, flags,
- reinterpret_cast<unsigned long>(MyCallBack)));
- //配置流数据的编码信息
- InitEncodeVideoVxD();
- InitEncodeAudioVxD();
- //开始采集数据
- if (m_bStream)
- HVFRecord(m_hVFDrv, m_bStream, NULL, NULL);
- return 0;
- }
- void CPlayView::ClearDriver()
- {
- //将流数据的大小置为0
- m_bStream = 0;
- if (m_hVFDrv)
- {
- //停止采集数据
- HVFStop(m_hVFDrv, m_bStream);
- //关闭流数据
- HVFClose(m_hVFDrv, m_bStream);
- //释放设备
- HVFUnlock(m_hVFDrv, VF_CAP_ALL);
- //关闭设备驱动
- CloseDriver(m_hVFDrv, NULL, NULL);
- //将驱动句柄置为0
- m_hVFDrv = 0;
- //采集标志设为FALSE
- m_Capture=FALSE;
- }
- }
- //配置视频流的编码信息
- void CPlayView::InitEncodeVideoVxD()
- {
- DWORD dwValue;
- WORD wWidth, wHeight;
- wWidth = 352;
- wHeight = 288;
- dwValue = MAKELONG(wWidth, wHeight);
- //设置视频的输出大小,取MAKELONG(352, 288)
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_OUTPUTSIZE, dwValue);
- wWidth = (wWidth * 45) / 44;
- dwValue = MAKELONG(wWidth, wHeight);
- //设置视频的输入大小,取MAKELONG(360, 288)
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_INPUTSIZE, dwValue);
- //设置视频的比特率,取1152000bits/s
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_BITRATE, BITRATE_DEFAULT);
- //设置视频帧速,25帧/s
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_RATE, VF_FLAG_VID_25);
- //设置MPEG压缩的I帧间隔,取15
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_IINTERVAL, IINTERVAL_DEFAULT);
- //设置MPEG压缩的P帧间隔,取3
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_BINTERVAL, PINTERVAL_DEFAULT);
- //设置视频的制式,采用PAL制式
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_MODE, VF_FLAG_VID_PAL);
- //设置视频的输入源的类型,采用混合类型
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_SOURCE, VF_FLAG_VID_COMPOSITE);
- //设置视频的压缩算法,采用MPEG编码
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_ALGORITHM, VF_FLAG_VID_MPEG);
- //设置视频的亮度
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_BRIGHTNESS, BRIGHTNESS_DEFAULT);
- //设置视频的对比度
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_CONTRAST, CONTRAST_DEFAULT);
- //设置视频的色调
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_HUE, HUE_DEFAULT);
- //设置视频的饱和度
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_SATURATION, SATURATION_DEFAULT);
- }
- void CPlayView::DiskSpace(TCHAR sDriver)
- {//检查磁盘空间
- struct _diskfree_t diskfree;
- int nDriver =sDriver-'A'+1;
- if (_getdiskfree(nDriver, &diskfree) == 0)
- {
- FreeDiskSpace.Format("硬盘%c剩余:%luMB",sDriver,
- (DWORD)diskfree.avail_clusters *
- (DWORD)diskfree.sectors_per_cluster *
- (DWORD)diskfree.bytes_per_sector / ((DWORD)1024L*(DWORD)1024L));
- }
- else
- return;
- }
- void CPlayView::OnCaptureSave()
- {
- // TODO: Add your command handler code here
- CString strCaptureSave;
- TCHAR Driver;
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- CFileDialog FileDlg(TRUE,NULL,"temp",NULL,"mpeg文件(*.mpg)|*.mpg|AVI文件(*.avi)|*.avi");
- FileDlg.m_ofn.lpstrInitialDir="c:\temp";
- CStopModeDlg StopModeDlg;
- FileDlg.m_ofn.lpstrTitle="指定采集文件名";
- if(FileDlg.DoModal()==IDOK)
- {
- //选择采集文件
- CapFileName=FileDlg.GetPathName();
- Driver=CapFileName.GetAt(0);
- strCaptureSave.Format("采集到:%s",CapFileName);
- //检查磁盘剩余空间
- DiskSpace(Driver);
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(1,strCaptureSave);
- pFrame->m_wndStatusBar.SetPaneText(2,FreeDiskSpace);
- //选择自动停止采集方式
- if(StopModeDlg.DoModal()==IDOK)
- {
- if(StopModeDlg.m_SizeCheck)
- {//选择根据文件大小停止
- sscanf(StopModeDlg.m_size,"%f",&m_size);
- m_SizeCheck=StopModeDlg.m_SizeCheck;
- }
- if(StopModeDlg.m_TimeCheck)
- {//选择根据采集时间停止
- sscanf(StopModeDlg.m_time,"%d",&m_time);
- m_TimeCheck=StopModeDlg.m_TimeCheck;
- }
- }
- }
- }
- void CPlayView::OnBeginCapture()
- {
- // TODO: Add your command handler code here
- DWORD dwFlags = 0;
- RECT Srct,Erct,Prct;
- int width;
- UINT Sid;
- UINT SStyle;
- //如果当前不在实时发送数据而且不在采集,
- //对设备进行初始化,开始采集数据
- if((!m_RealSend)&&(!m_Capture))
- if(InitDriver()<0)
- return;
- //采集标志设为TRUE
- m_Capture=TRUE;
- LPSTR caFileName=CapFileName.GetBuffer(_MAX_PATH);
- CapFileName.ReleaseBuffer();
- dwFlags = MMIO_CREATE | MMIO_WRITE;
- //打开采集文件
- hmmioOutput = mmioOpen(caFileName, (LPMMIOINFO)NULL, dwFlags);
- //在状态栏中显示相关信息
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(0,"");
- pFrame->m_wndStatusBar.GetPaneInfo(0,Sid,SStyle,width);
- ::GetClientRect(pFrame->m_wndStatusBar.m_hWnd,&Prct);
- Srct.left=10;
- Srct.top=4;
- Srct.right=width/2-20;
- Srct.bottom=Prct.bottom-1;
- Erct.left=width/2;
- Erct.top=4;
- Erct.right=width-10;
- Erct.bottom=Prct.bottom-1;
- m_static.Create(_T("已采集(时:分:秒)"),WS_CHILD|WS_VISIBLE|SS_LEFT,
- Srct,&pFrame->m_wndStatusBar,ID_STATIC);
- m_static.SetFont(&m_font);
- m_edit.Create(ES_CENTER|WS_BORDER|WS_VISIBLE,Erct,&pFrame->m_wndStatusBar,ID_EDIT);
- m_edit.SetWindowText("00:00:00");
- //采集定时器标志设为TRUE
- m_TCapture=TRUE;
- //设定计时器
- SetTimer(ID_TIMER,1000,NULL);
- }
- void CPlayView::OnStopCapture()
- {
- //关闭计时器
- KillTimer(ID_TIMER);
- //采集定时器标志设为FALSE
- m_TCapture=FALSE;
- //如果现在不在实时发送数据,
- //停止采集数据,并关闭相关设备
- if(!m_RealSend)
- ClearDriver();
- //关闭采集文件
- FILE_CLOSE(hmmioOutput);
- Ts=CTimeSpan(0,0,0,0);
- m_static.DestroyWindow();
- m_edit.DestroyWindow();
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(0,"停止采集");
- }
- void CPlayView::OnPauseCapture()
- {
- //关闭计时器
- KillTimer(ID_TIMER);
- //采集计时器标志设为FALSE
- m_TCapture=FALSE;
- //暂停采集
- HVFPause(m_hVFDrv, m_bStream);
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(0,"暂停采集");
- }
- void CPlayView::OnResumeCapture()
- {
- // TODO: Add your command handler code here
- //继续采集
- HVFResume(m_hVFDrv, m_bStream);
- //采集计时器标志设为TRUE
- m_TCapture=TRUE;
- //设定计时器
- SetTimer(ID_TIMER,1000,NULL);
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(0,"");
- }
- void CPlayView::OnOpenPlayfile()
- {
- CString FTemp;
- CFileDialog dlg(TRUE,NULL,NULL,NULL,"mpeg文件(*.mpg)|*.mpg|AVI文件(*.avi)|*.avi");
- dlg.m_ofn.lpstrTitle="打开多媒体文件";
- //dlg.m_ofn.lpstrInitialDir="c:\Windows\Temp";
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- if(dlg.DoModal()==IDOK)
- {
- Fname=dlg.GetPathName();
- FTemp.Format("播放:%s",Fname);
- pFrame->m_wndStatusBar.SetPaneText(0,"停止");
- pFrame->m_wndStatusBar.SetPaneText(1,FTemp);
- }
- }
- void CPlayView::OnPlayfile()
- {
- // TODO: Add your command handler code here
- RECT Srct,Prct;
- int width;
- UINT Sid;
- UINT SStyle;
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- if(!pVideoPlay)
- pVideoPlay=new CVideoPlay(this->m_hWnd);
- pFrame->m_wndStatusBar.SetPaneText(0,"播放");
- pFrame->m_wndStatusBar.GetPaneInfo(0,Sid,SStyle,width);
- ::GetClientRect(pFrame->m_wndStatusBar.m_hWnd,&Srct);
- Prct.left=40;
- Prct.top=4;
- Prct.right=width;
- Prct.bottom=Srct.bottom-1;
- m_prog.Create(PBS_SMOOTH,Prct,&pFrame->m_wndStatusBar,ID_PROGRESS);
- pVideoPlay->PlayFromFile(Fname);
- m_prog.SetRange(0,(int)pVideoPlay->tLength);
- m_prog.ShowWindow(SW_SHOW);
- m_TPlayFile=TRUE;
- SetTimer(ID_TIMER,1000,NULL);
- }
- LRESULT CPlayView::OnPlayOver(WPARAM wParam,LPARAM lParam)
- {
- int status;
- status=pVideoPlay->PlayOver();
- if(status==0)
- {
- KillTimer(ID_TIMER);
- m_prog.DestroyWindow();
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(0,"停止");
- Pos=0;
- Ts=CTimeSpan(0,0,0,0);
- m_TPlayFile=FALSE;
- }
- return 0;
- }
- void CPlayView::OnFileStop()
- {
- // TODO: Add your command handler code here
- KillTimer(ID_TIMER);
- m_prog.DestroyWindow();
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(0,"停止");
- Pos=0;
- Ts=CTimeSpan(0,0,0,0);
- m_TPlayFile=FALSE;
- RELEASE_CVIDEOPLAY;
- }
- void CPlayView::OnRealplay()
- {
- // TODO: Add your command handler code here
- int i,MenuCount;
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pVideoPlay=new CVideoPlay(this->m_hWnd);
- pVideoPlay->RealPlay();
- pFrame->m_wndStatusBar.SetPaneText(0,"实时播放");
- pFrame->m_wndStatusBar.SetPaneText(1,"");
- CMenu* pSubMenu=PopMenu.GetSubMenu(0);
- MenuCount=pSubMenu->GetMenuItemCount();
- for(i=0;i<2;i++)
- pSubMenu->EnableMenuItem(i,MF_ENABLED|MF_BYPOSITION);
- }
- void CPlayView::OnRealStop()
- {
- // TODO: Add your command handler code here
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(0,"");
- RELEASE_CVIDEOPLAY;
- }
- void CPlayView::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- CTimeSpan TsAdd(1);
- Ts=TsAdd+Ts;
- if(m_TPlayFile)
- {
- CString s1 =Ts.Format("已播放:%H:%M:%S");
- Pos=Pos+1;
- m_prog.SetPos(Pos);
- CDC* pControlDC=m_prog.GetDC();
- CFont* pOldFont = (CFont*) pControlDC->SelectObject(&m_font);
- //CPen* pOldPen =(CPen*) pControlDC->SelectObject(&Wpen);
- int iOld = pControlDC->GetBkMode();
- int iOldMode = pControlDC->GetROP2();
- pControlDC->SetROP2(R2_XORPEN);
- CRect rc;
- m_prog.GetClientRect(&rc);
- pControlDC->SetBkMode(TRANSPARENT);
- m_prog.Invalidate();
- m_prog.UpdateWindow();
- pControlDC->DrawText(s1, &rc, DT_CENTER | DT_VCENTER);
- pControlDC->SelectObject(pOldFont);
- pControlDC->SetROP2(iOldMode);
- pControlDC->SetBkMode(iOld);
- m_prog.ReleaseDC(pControlDC);
- }
- if(m_TCapture)
- {
- CString s2 =Ts.Format("%H:%M:%S");
- m_edit.SetWindowText(s2);
- if(m_TimeCheck)
- {
- m_TimeIndex++;
- if(m_TimeIndex==m_time+1)
- {
- OnStopCapture();
- MessageBox("采集时间到,停止采集");
- m_TimeCheck=FALSE;
- m_TimeIndex=0;
- }
- }
- }
- CView::OnTimer(nIDEvent);
- }
- void CPlayView::OnPausePlay()
- {
- // TODO: Add your command handler code here
- pVideoPlay->PausePlay();
- KillTimer(ID_TIMER);
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(0,"暂停");
- }
- void CPlayView::OnResumePlay()
- {
- // TODO: Add your command handler code here
- pVideoPlay->ResumePlay();
- SetTimer(ID_TIMER,1000,NULL);
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- pFrame->m_wndStatusBar.SetPaneText(0,"播放");
- }
- void CPlayView::InitEncodeSystemVxD()
- {
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_STM_TYPE, VF_FLAG_MPGSYS);
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_STM_ENCODEMODE, VF_FLAG_STM_NORMAL);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyEdit
- IMPLEMENT_DYNAMIC(CMyEdit,CEdit)
- CMyEdit::CMyEdit()
- {
- m_clrFont =RGB(0 , 255 , 0) ; // yellow text
- m_clrBack=RGB(0 , 0 , 0) ; // blue background
- m_brush.CreateSolidBrush(m_clrBack);
- m_font.CreatePointFont(90, "宋体");
- }
- CMyEdit::~CMyEdit()
- {
- }
- BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
- //{{AFX_MSG_MAP(CMyEdit)
- ON_WM_CREATE()
- ON_WM_CTLCOLOR_REFLECT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyEdit message handlers
- int CMyEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CEdit::OnCreate(lpCreateStruct) == -1)
- return -1;
- // TODO: Add your specialized creation code here
- SetFont(&m_font);
- return 0;
- }
- HBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor)
- {
- // TODO: Change any attributes of the DC here
- pDC->SetTextColor (m_clrFont);
- pDC->SetBkMode(TRANSPARENT);
- return (HBRUSH)m_brush.GetSafeHandle ();
- }
- //配置音频流的编码信息
- void CPlayView::InitEncodeAudioVxD()
- {
- DWORD dwValue;
- //设置音频的采样率,取默认值44100 kHz
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_SAMPLE, SAMPLE_RATE_DEFAULT);
- //设置音频的比特率,取默认值224000bits/s
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_BITRATE, BIT_RATE_DEFAULT);
- dwValue=VF_FLAG_AUD_MPEG;
- dwValue=(dwValue<<16)+VF_FLAG_AUD_NONE;
- //设置音频的压缩算法,采用MPEG编码
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_ALGORITHM, dwValue);
- //设置音频方式,为立体声
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_MODE, MODE_DEFAULT);
- //设置音频的音量大小,取默认值100
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_VOLUME, VOLUME_DEFAULT);
- //设置音频电平,取默认值0
- HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_GAIN, GAIN_DEFAULT);
- }
- BOOL CPlayView::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
- // Create a pruple brush.
- CBrush Brush (RGB (0,0,255) );
- CBrush* pOldBrush = pDC->SelectObject(&Brush);
- CRect reClip ;
- pDC->GetClipBox(&reClip);
- pDC->PatBlt (reClip.left , reClip.top ,
- reClip.Width ( ) , reClip.Height ( ) , PATCOPY );
- pDC->SelectObject (pOldBrush );
- return TRUE;
- }