GVCaptureDlg.cpp
资源名称:p2p_vod.rar [点击查看]
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:27k
源码类别:
P2P编程
开发平台:
Visual C++
- /*
- * Openmysee
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
- //
- //xiezhouwei 2005-08-15 添加配置pin函数
- #include "stdafx.h"
- #include "GVCapture.h"
- #include "GVCaptureDlg.h"
- #include "utilities.h"
- #include "afxdlgs.h"
- #include "VideoEncParams.h"
- #include "SetV9Dlg.h"
- #include ".gvcapturedlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- CVideoEncParams g_VideoEncodingParams;
- /////////////////////////////////////////////////////////////////////////////
- // 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()
- /////////////////////////////////////////////////////////////////////////////
- // CGVCaptureDlg dialog
- CGVCaptureDlg::CGVCaptureDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CGVCaptureDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CGVCaptureDlg)
- mstrSavePath = _T("");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_grfCapture.Initialize();
- m_dwEscape = 0;
- m_bPause = FALSE;
- mpTemAudioAMT = NULL;
- ZeroMemory(mszAVIFilePath,sizeof(mszAVIFilePath));
- }
- void CGVCaptureDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CGVCaptureDlg)
- DDX_Control(pDX, IDC_CHK_OVERLAY, mchkNeedOverlay);
- DDX_Control(pDX, IDC_CHK_SAVE, mbtnSaveFile);
- DDX_Control(pDX, IDC_CHK_ONLY_AUDIO, m_chkOnlyAudio);
- DDX_Control(pDX, IDC_CHK_PREVIEW, m_chkPreview);
- DDX_Control(pDX, IDC_CMB_VIDEO_COMPRESSOR, m_comboxVideoEncoder);
- DDX_Control(pDX, IDC_CMB_VIDEO_CAPTURE, m_comboxVideoCap);
- DDX_Control(pDX, IDC_CMB_AUDIO_CAPTURE, m_comboxAudioCap);
- DDX_Control(pDX, IDC_CMB_AUDIO_COMPRESSOR, m_comboxAudioEncoder);
- DDX_Text(pDX, IDC_EDIT_SAVEPATH, mstrSavePath);
- //}}AFX_DATA_MAP
- DDX_Control(pDX, IDC_CHK_CROSSBAR, m_bChkCrossBar);
- }
- BEGIN_MESSAGE_MAP(CGVCaptureDlg, CDialog)
- //{{AFX_MSG_MAP(CGVCaptureDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_ERASEBKGND()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BTN_VIDEOCAP_CONFIG, OnBtnVideocapConfig)
- ON_BN_CLICKED(IDC_BTN_VIDEO_COMPRESSOR_CONFIG, OnBtnVideoCompressorConfig)
- ON_BN_CLICKED(IDC_BTN_AUDIO_COMPRESSOR_CONFIG, OnBtnAudioCompressorConfig)
- ON_BN_CLICKED(IDC_BTN_BEGIN_CAP, OnBtnBeginCap)
- ON_BN_CLICKED(IDC_BTN_PAUSE_CAP, OnBtnPauseCap)
- ON_BN_CLICKED(IDC_BTN_STOP_CAP, OnBtnStopCap)
- ON_BN_CLICKED(IDC_CHK_PREVIEW, OnChkPreview)
- ON_WM_TIMER()
- ON_WM_CLOSE()
- ON_CBN_SELCHANGE(IDC_CMB_AUDIO_COMPRESSOR, OnSelchangeCmbAudioCompressor)
- ON_CBN_SELCHANGE(IDC_CMB_VIDEO_CAPTURE, OnSelchangeCmbVideoCapture)
- ON_CBN_SELCHANGE(IDC_CMB_AUDIO_CAPTURE, OnCbnSelchangeCmbAudioCapture)
- ON_CBN_SELCHANGE(IDC_CMB_VIDEO_COMPRESSOR, OnSelchangeCmbVideoCompressor)
- ON_BN_CLICKED(IDC_CHK_ONLY_AUDIO, OnCheckOnlyAudio)
- ON_BN_CLICKED(IDC_BTN_SYSCOF, OnBtnSyscof)
- ON_BN_CLICKED(IDC_BTN_VIDEOCAP_INI_CONFIG, OnBtnVideocapIniConfig)
- ON_BN_CLICKED(IDC_CHK_SAVE, OnChkSave)
- ON_BN_CLICKED(IDC_BTN_SETOVERLAY, OnBtnSetoverlay)
- ON_BN_CLICKED(IDC_CHK_OVERLAY, OnChkOverlay)
- ON_BN_CLICKED(IDC_CHK_CROSSBAR, OnBnClickedChkCrossbar)
- //}}AFX_MSG_MAP
- ON_BN_CLICKED(IDC_BTN_AUDIO_CAP_CONFIG, OnBnClickedBtnAudioCapConfig)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CGVCaptureDlg message handlers
- BOOL CGVCaptureDlg::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
- //mbtnSaveFile.SetCheck(BST_CHECKED);
- m_grfCapture.EnumVideoCapDevices(m_strArrayVideoCapDevice);
- for(int i = 0; i < m_strArrayVideoCapDevice.GetSize(); i++)
- m_comboxVideoCap.AddString(m_strArrayVideoCapDevice.GetAt(i));
- //mbtnSaveFile.SetCheck(BST_CHECKED);
- m_grfCapture.EnumAudioCapDevices(m_strArrayAudioCapDevice);
- for(int i = 0; i < m_strArrayAudioCapDevice.GetSize(); i++)
- m_comboxAudioCap.AddString(m_strArrayAudioCapDevice.GetAt(i));
- m_grfCapture.EnumVideoEncoders(m_strArrayVideoEncoders);
- for(i = 0; i < m_strArrayVideoEncoders.GetSize(); i++)
- m_comboxVideoEncoder.AddString(m_strArrayVideoEncoders.GetAt(i));
- m_comboxVideoEncoder.AddString("MicroSoft Media 9 DMO");
- m_grfCapture.EnumAudioEncoders(m_strArrayAudioEncoders);
- for(i = 0; i < m_strArrayAudioEncoders.GetSize(); i++)
- m_comboxAudioEncoder.AddString(m_strArrayAudioEncoders.GetAt(i));
- //得到文件中的设置数据
- LoadFilterConfig();
- CString strCurSel;
- if (0 != m_strCurVideoEncoder.GetBuffer(0)[0])
- {
- m_comboxVideoEncoder.SelectString(-1, m_strCurVideoEncoder);
- if ("MicroSoft Media 9 DMO" == m_strCurVideoEncoder)
- {
- g_VideoEncodingParams.DefaultParams();
- }
- if(FAILED(m_grfCapture.CreateVideoEncoderFilterByName((TCHAR*)((LPCTSTR)m_strCurVideoEncoder))))
- AfxMessageBox("Cant Create filter!!");
- }
- else
- {
- m_comboxVideoEncoder.SetCurSel(0);
- if((i = m_comboxVideoEncoder.GetCurSel()) != CB_ERR)
- {
- m_comboxVideoEncoder.GetLBText(i, strCurSel);
- m_strCurVideoEncoder = strCurSel;
- if ("MicroSoft Media 9 DMO" == m_strCurVideoEncoder)
- {
- g_VideoEncodingParams.DefaultParams();
- }
- if(FAILED(m_grfCapture.CreateVideoEncoderFilterByName((TCHAR*)((LPCTSTR)strCurSel))))
- AfxMessageBox("Cant Create filter!!");
- }
- }
- if (0 != m_strCurVideoCapDevice.GetBuffer(0)[0])
- {
- m_comboxVideoCap.SelectString(-1, m_strCurVideoCapDevice.GetBuffer(0));
- if(FAILED(m_grfCapture.CreateVideoCapDeviceFilterByName((TCHAR*)((LPCTSTR)m_strCurVideoCapDevice))))
- AfxMessageBox("Cant Create filter!!");
- }
- else
- {
- m_comboxVideoCap.SetCurSel(0);
- strCurSel.Empty();
- if((i = m_comboxVideoCap.GetCurSel()) != CB_ERR)
- {
- m_comboxVideoCap.GetLBText(i, strCurSel);
- m_strCurVideoCapDevice = strCurSel;
- if(FAILED(m_grfCapture.CreateVideoCapDeviceFilterByName((TCHAR*)((LPCTSTR)strCurSel))))
- AfxMessageBox("Cant Create video capture device filter!!");
- }
- }
- if (0 != m_strCurAudioCapDevice.GetBuffer(0)[0])
- {
- m_comboxAudioCap.SelectString(-1, m_strCurAudioCapDevice.GetBuffer(0));
- if(FAILED(m_grfCapture.CreateAudioCapDeviceFilterByName((TCHAR*)((LPCTSTR)m_strCurAudioCapDevice))))
- AfxMessageBox("Cant Create audio capture device filter!!");
- }
- else
- {
- m_comboxAudioCap.SetCurSel(0);
- strCurSel.Empty();
- if((i = m_comboxAudioCap.GetCurSel()) != CB_ERR)
- {
- m_comboxAudioCap.GetLBText(i, strCurSel);
- m_strCurAudioCapDevice = strCurSel;
- if(FAILED(m_grfCapture.CreateAudioCapDeviceFilterByName((TCHAR*)((LPCTSTR)strCurSel))))
- AfxMessageBox("Cant Create audio capture device filter!!");
- }
- }
- if (0 != m_strCurAudioEncoder.GetBuffer(0)[0])
- {
- m_comboxAudioEncoder.SelectString(-1, m_strCurAudioEncoder.GetBuffer(0));
- if(FAILED(m_grfCapture.CreateAudioEncoderFilterByName((TCHAR*)((LPCTSTR)m_strCurAudioEncoder))))
- AfxMessageBox("Cant Create filter!!");
- }
- else
- {
- m_comboxAudioEncoder.SetCurSel(0);
- strCurSel.Empty();
- if((i = m_comboxAudioEncoder.GetCurSel()) != CB_ERR)
- {
- m_comboxAudioEncoder.GetLBText(i, strCurSel);
- m_strCurAudioEncoder = strCurSel;
- if(FAILED(m_grfCapture.CreateAudioEncoderFilterByName((TCHAR*)((LPCTSTR)strCurSel))))
- AfxMessageBox("Cant Create filter!!");
- }
- }
- m_grfCapture.SetCurMediaType(mpTemAudioAMT);
- mchkNeedOverlay.SetCheck(BST_UNCHECKED);
- OnChkOverlay();
- m_bChkCrossBar.SetCheck(BST_UNCHECKED);
- m_grfCapture.SetOwner(GetDlgItem(IDC_STATIC_PREVIEW)->GetSafeHwnd());
- GetDlgItem(IDC_STATIC_PREVIEW)->ModifyStyle(0, WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
- m_chkPreview.SetCheck(BST_CHECKED);
- if(m_strArrayVideoCapDevice.GetSize() == 0)
- {
- m_chkOnlyAudio.SetCheck(BST_CHECKED);
- m_comboxVideoCap.EnableWindow(FALSE);
- m_comboxVideoEncoder.EnableWindow(FALSE);
- m_chkOnlyAudio.EnableWindow(FALSE);
- }
- m_chkOnlyAudio.SetCheck(BST_UNCHECKED);
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CGVCaptureDlg::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 CGVCaptureDlg::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 CGVCaptureDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CGVCaptureDlg::OnBtnVideocapConfig()
- {
- if (0 == GetSafeHwnd())
- {
- MessageBox("父窗口句柄不能为空","错误");
- }
- if(FAILED(m_grfCapture.ConfigVideoCapDeviceByName(this->GetSafeHwnd())))
- AfxMessageBox("Cant set property for this filter!!");
- }
- void CGVCaptureDlg::OnBtnVideoCompressorConfig()
- {
- if (0 == GetSafeHwnd())
- {
- MessageBox("父窗口句柄不能为空","错误");
- }
- if ("MicroSoft Media 9 DMO" == m_strCurVideoEncoder)
- {
- CSetV9Dlg dlg;
- if(IDOK == dlg.DoModal())
- {
- if(FAILED(m_grfCapture.ConfigVideoEncoderByName(this->GetSafeHwnd())))
- AfxMessageBox("Cant set property for this filter!!");
- }
- return;
- }
- if(FAILED(m_grfCapture.ConfigVideoEncoderByName(this->GetSafeHwnd())))
- AfxMessageBox("Cant set property for this filter!!");
- }
- void CGVCaptureDlg::OnBnClickedBtnAudioCapConfig()
- {
- if (0 == GetSafeHwnd())
- {
- MessageBox("父窗口句柄不能为空","错误");
- }
- if(FAILED(m_grfCapture.ConfigAudioCapDeviceByName(this->GetSafeHwnd())))
- AfxMessageBox("Cant set property for this filter!!");
- }
- void CGVCaptureDlg::OnBtnAudioCompressorConfig()
- {
- if (0 == GetSafeHwnd())
- {
- MessageBox("父窗口句柄不能为空","错误");
- }
- if(FAILED(m_grfCapture.ConfigAudioEncoderByName(this->GetSafeHwnd())))
- AfxMessageBox("Cant set property for this filter!!");
- }
- //xiezhouwei 05-08-17 添加设置字幕按钮
- void CGVCaptureDlg::OnBtnSetoverlay()
- {
- if (FAILED(m_grfCapture.ConfigVideoOverlay(GetSafeHwnd())))
- {
- AfxMessageBox("Cant set property for this filter!!");
- }
- }
- void CGVCaptureDlg::OnChkOverlay()
- {
- if (BST_UNCHECKED == mchkNeedOverlay.GetCheck())
- {
- m_grfCapture.ReleaseUideoOverlay();
- GetDlgItem(IDC_BTN_SETOVERLAY)->EnableWindow(FALSE);
- }
- if (BST_CHECKED == mchkNeedOverlay.GetCheck())
- {
- if (FAILED(m_grfCapture.CreateUideoOverlay()))
- {
- m_grfCapture.ReleaseUideoOverlay();
- MessageBox("字幕组件加载失败","注意");
- mchkNeedOverlay.SetCheck(BST_UNCHECKED);
- return ;
- }
- GetDlgItem(IDC_BTN_SETOVERLAY)->EnableWindow(TRUE);
- }
- }
- //系统设置框
- void CGVCaptureDlg::OnBtnSyscof()
- {
- if(FAILED(m_grfCapture.ConfigSysCfg(this->GetSafeHwnd())))
- AfxMessageBox("Cant set System for this filter!!");
- }
- void CGVCaptureDlg::OnBtnBeginCap()
- {
- if(SUCCEEDED(m_grfCapture.Run()))
- {
- GetDlgItem(IDC_BTN_VIDEO_COMPRESSOR_CONFIG)->EnableWindow(FALSE);
- GetDlgItem(IDC_BTN_AUDIO_COMPRESSOR_CONFIG)->EnableWindow(FALSE);
- m_bChkCrossBar.EnableWindow(FALSE);
- m_chkOnlyAudio.EnableWindow(FALSE);
- mchkNeedOverlay.EnableWindow(FALSE);
- GetDlgItem(IDC_BTN_SETOVERLAY)->EnableWindow(FALSE);
- mbtnSaveFile.EnableWindow(FALSE);
- m_comboxVideoEncoder.EnableWindow(FALSE);
- m_comboxVideoCap.EnableWindow(FALSE);
- m_comboxAudioEncoder.EnableWindow(FALSE);
- m_dwTimer = SetTimer(100, 1000, NULL);
- }
- m_bPause = FALSE;
- }
- void CGVCaptureDlg::OnBtnPauseCap()
- {
- m_grfCapture.Pause();
- m_bPause = TRUE;
- }
- void CGVCaptureDlg::OnBtnStopCap()
- {
- KillTimer(m_dwTimer);
- m_bPause = FALSE;
- m_dwEscape = 0;
- TCHAR strTime[10];
- wsprintf(strTime, "00:00:00");
- SetDlgItemText(IDC_STATIC_TIMETOCAP, strTime);
- SetDlgItemText(IDC_STATIC_BITRATE, "0.0");
- if (SUCCEEDED(m_grfCapture.Stop()))
- {
- GetDlgItem(IDC_BTN_SYSCOF)->EnableWindow();
- GetDlgItem(IDC_BTN_VIDEOCAP_INI_CONFIG)->EnableWindow();
- GetDlgItem(IDC_BTN_VIDEOCAP_CONFIG)->EnableWindow();
- GetDlgItem(IDC_BTN_VIDEO_COMPRESSOR_CONFIG)->EnableWindow();
- GetDlgItem(IDC_BTN_AUDIO_COMPRESSOR_CONFIG)->EnableWindow();
- m_bChkCrossBar.EnableWindow();
- m_chkOnlyAudio.EnableWindow();
- mchkNeedOverlay.EnableWindow();
- if (BST_CHECKED == mchkNeedOverlay.GetCheck())
- {
- GetDlgItem(IDC_BTN_SETOVERLAY)->EnableWindow();
- }
- mbtnSaveFile.EnableWindow();
- if(FALSE == m_grfCapture.IsOnlyAudio())
- {
- m_comboxVideoEncoder.EnableWindow();
- m_comboxVideoCap.EnableWindow();
- }
- m_comboxAudioEncoder.EnableWindow();
- }
- }
- void CGVCaptureDlg::OnChkPreview()
- {
- m_grfCapture.SetPreview(!m_grfCapture.IsPreview());
- }
- void CGVCaptureDlg::OnTimer(UINT nIDEvent)
- {
- if(m_bPause)
- return;
- m_dwEscape ++;
- // change time display
- int h = m_dwEscape/3600;
- int m = (m_dwEscape%3600)/60;
- int s = (m_dwEscape%3600)%60;
- TCHAR strH[3], strM[3], strS[3];
- if(h < 10)
- wsprintf(strH, "0%d", h);
- else
- wsprintf(strH, "%d", h);
- if(m < 10)
- wsprintf(strM, "0%d", m);
- else
- wsprintf(strM, "%d", m);
- if(s < 10)
- wsprintf(strS, "0%d", s);
- else
- wsprintf(strS, "%d", s);
- TCHAR strTime[10];
- wsprintf(strTime, "%s:%s:%s", strH, strM ,strS);
- SetDlgItemText(IDC_STATIC_TIMETOCAP, strTime);
- TCHAR strDataRata[20];
- sprintf(strDataRata, "%f", m_grfCapture.GetCompressRata());
- SetDlgItemText(IDC_STATIC_BITRATE, strDataRata);
- CDialog::OnTimer(nIDEvent);
- }
- void CGVCaptureDlg::OnClose()
- {
- OnBtnStopCap();
- CDialog::OnClose();
- SaveFilterConfig();
- }
- void CGVCaptureDlg::OnCbnSelchangeCmbAudioCapture()
- {
- CString strCurSel;
- m_comboxAudioCap.GetLBText(m_comboxAudioCap.GetCurSel(), strCurSel);
- if(m_strCurAudioCapDevice == strCurSel)
- return;
- m_strCurAudioCapDevice = strCurSel;
- if(FAILED(m_grfCapture.CreateAudioCapDeviceFilterByName((TCHAR*)((LPCTSTR)strCurSel))))
- AfxMessageBox("Cant Create filter!!");
- }
- void CGVCaptureDlg::OnSelchangeCmbAudioCompressor()
- {
- CString strCurSel;
- m_comboxAudioEncoder.GetLBText(m_comboxAudioEncoder.GetCurSel(), strCurSel);
- if(m_strCurAudioEncoder == strCurSel ||((LPCTSTR)strCurSel)[0] == 0)
- {
- AfxMessageBox("当前读出字符串为空");
- return;
- }
- m_strCurAudioEncoder = strCurSel;
- if(FAILED(m_grfCapture.CreateAudioEncoderFilterByName((TCHAR*)((LPCTSTR)strCurSel))))
- AfxMessageBox("Cant Create filter!!");
- }
- void CGVCaptureDlg::OnSelchangeCmbVideoCapture()
- {
- CString strCurSel;
- m_comboxVideoCap.GetLBText(m_comboxVideoCap.GetCurSel(), strCurSel);
- if(m_strCurVideoCapDevice == strCurSel)
- return;
- m_strCurVideoCapDevice = strCurSel;
- if(FAILED(m_grfCapture.CreateVideoCapDeviceFilterByName((TCHAR*)((LPCTSTR)strCurSel))))
- AfxMessageBox("Cant Create filter!!");
- }
- void CGVCaptureDlg::OnSelchangeCmbVideoCompressor()
- {
- CString strCurSel;
- m_comboxVideoEncoder.GetLBText(m_comboxVideoEncoder.GetCurSel(), strCurSel);
- if(m_strCurVideoEncoder == strCurSel || ((LPCTSTR)strCurSel)[0] == 0)
- {
- AfxMessageBox("当前读出字符串为空");
- return;
- }
- m_strCurVideoEncoder = strCurSel;
- if ("MicroSoft Media 9 DMO" == m_strCurVideoEncoder)
- {
- g_VideoEncodingParams.DefaultParams();
- }
- if(FAILED(m_grfCapture.CreateVideoEncoderFilterByName((TCHAR*)((LPCTSTR)strCurSel))))
- AfxMessageBox("Cant Create filter!!");
- }
- void CGVCaptureDlg::OnNotifyStop()
- {
- OnBtnStopCap();
- }
- void CGVCaptureDlg::OnNotifyPlay()
- {
- OnBtnBeginCap();
- }
- void CGVCaptureDlg::OnCheckOnlyAudio()
- {
- m_grfCapture.SetOnlyAudio(!m_grfCapture.IsOnlyAudio());
- if(m_grfCapture.IsOnlyAudio())
- {
- m_comboxVideoCap.EnableWindow(FALSE);
- m_comboxVideoEncoder.EnableWindow(FALSE);
- }
- else
- {
- m_comboxVideoCap.EnableWindow(TRUE);
- m_comboxVideoEncoder.EnableWindow(TRUE);
- }
- }
- bool CGVCaptureDlg::SaveFilterConfig()
- {
- char lszTotalPath[DEF_TEMP_LENGTH];
- int result = 0;
- FILE* lpFp = NULL;
- GetTotalPath("ConfigFilter.dat", lszTotalPath);
- lpFp = fopen(lszTotalPath, "wb");
- //写m_strCurAudioCapDevice
- int liLen = strlen(m_strCurAudioCapDevice.GetBuffer(0));
- result = fwrite(&liLen, sizeof(int), 1,lpFp);
- if (1 != result)
- {
- fclose(lpFp);
- return false;
- }
- result = fwrite(m_strCurAudioCapDevice.GetBuffer(0), sizeof(char), liLen,lpFp);
- if (liLen != result)
- {
- fclose(lpFp);
- return false;
- }
- //写m_strCurAudioEncoder
- liLen = strlen(m_strCurAudioEncoder.GetBuffer(0));
- result = fwrite(&liLen, sizeof(int), 1,lpFp);
- if (1 != result)
- {
- fclose(lpFp);
- return false;
- }
- result = fwrite(m_strCurAudioEncoder.GetBuffer(0), sizeof(char), liLen,lpFp);
- if (liLen != result)
- {
- fclose(lpFp);
- return false;
- }
- //写m_strCurVideoCapDevice
- liLen = strlen(m_strCurVideoCapDevice.GetBuffer(0));
- result = fwrite(&liLen, sizeof(int), 1,lpFp);
- if (1 != result)
- {
- fclose(lpFp);
- return false;
- }
- result = fwrite(m_strCurVideoCapDevice.GetBuffer(0), sizeof(char), liLen,lpFp);
- if (liLen != result)
- {
- fclose(lpFp);
- return false;
- }
- //写m_strCurVideoEncoder
- liLen = strlen(m_strCurVideoEncoder.GetBuffer(0));
- result = fwrite(&liLen, sizeof(int), 1,lpFp);
- if (1 != result)
- {
- fclose(lpFp);
- return false;
- }
- result = fwrite(m_strCurVideoEncoder.GetBuffer(0), sizeof(char), liLen,lpFp);
- if (liLen != result)
- {
- fclose(lpFp);
- return false;
- }
- //写媒体类型
- AM_MEDIA_TYPE* lpCurAudioAMT = NULL;
- int ii = sizeof(AM_MEDIA_TYPE) + sizeof(WAVEFORMATEX);
- int iii = sizeof(AM_MEDIA_TYPE);
- if (!m_grfCapture.GetCurMediaType(&lpCurAudioAMT))
- {//如果没有,还必须将一个表示媒体类型为零的写入
- liLen = 0;
- fwrite(&liLen, sizeof(int), 1, lpFp);
- }
- //如果媒体格式不是音频则退出,这是一个保护机制。
- if (NULL != lpCurAudioAMT)
- {
- if (FORMAT_WaveFormatEx != lpCurAudioAMT->formattype)
- {
- fclose(lpFp);
- return false;
- }
- liLen = sizeof(AM_MEDIA_TYPE) + lpCurAudioAMT->cbFormat;
- result = fwrite(&liLen, sizeof(int), 1,lpFp);
- if (1 != result)
- {
- fclose(lpFp);
- return false;
- }
- result = fwrite(lpCurAudioAMT, liLen, 1,lpFp);
- if (1 != result)
- {
- fclose(lpFp);
- return false;
- }
- HeapFree(GetProcessHeap(), 0, lpCurAudioAMT);
- lpCurAudioAMT = NULL;
- }
- fclose(lpFp);
- return true;
- }
- bool CGVCaptureDlg::LoadFilterConfig()
- {
- char lszTotalPath[DEF_TEMP_LENGTH];
- int result = 0;
- FILE* lpFp = NULL;
- GetTotalPath("ConfigFilter.dat", lszTotalPath);
- lpFp = fopen(lszTotalPath, "rb");
- if (!lpFp)
- {
- return false;
- }
- //读m_strCurAudioCapDevice
- int liLen = 0;
- result = fread(&liLen, sizeof(int), 1,lpFp);
- if (1 != result)
- {
- AfxMessageBox("读取配置文件出错");
- fclose(lpFp);
- DeleteFile(lszTotalPath);
- return false;
- }
- if (liLen)
- {
- result = fread(m_strCurAudioCapDevice.GetBuffer(liLen), sizeof(char), liLen,lpFp);
- if (liLen != result)
- {
- m_strCurAudioCapDevice.ReleaseBuffer(liLen);
- AfxMessageBox("读取配置文件出错");
- fclose(lpFp);
- DeleteFile(lszTotalPath);
- return false;
- }
- m_strCurAudioCapDevice.ReleaseBuffer(liLen);
- }
- //读m_strCurAudioEncoder
- liLen = 0;
- result = fread(&liLen, sizeof(int), 1,lpFp);
- if (1 != result)
- {
- AfxMessageBox("读取配置文件出错");
- fclose(lpFp);
- DeleteFile(lszTotalPath);
- return false;
- }
- if (liLen)
- {
- result = fread(m_strCurAudioEncoder.GetBuffer(liLen), sizeof(char), liLen,lpFp);
- if (liLen != result)
- {
- m_strCurAudioEncoder.ReleaseBuffer(liLen);
- AfxMessageBox("读取配置文件出错");
- fclose(lpFp);
- DeleteFile(lszTotalPath);
- return false;
- }
- m_strCurAudioEncoder.ReleaseBuffer(liLen);
- }
- //读m_strCurVideoCapDevice
- liLen = 0;
- result = fread(&liLen, sizeof(int), 1,lpFp);
- if (1 != result)
- {
- AfxMessageBox("读取配置文件出错");
- fclose(lpFp);
- DeleteFile(lszTotalPath);
- return false;
- }
- if (liLen)
- {
- result = fread(m_strCurVideoCapDevice.GetBuffer(liLen), sizeof(char), liLen,lpFp);
- if (liLen != result)
- {
- m_strCurVideoCapDevice.ReleaseBuffer(liLen);
- AfxMessageBox("读取配置文件出错");
- fclose(lpFp);
- DeleteFile(lszTotalPath);
- return false;
- }
- m_strCurVideoCapDevice.ReleaseBuffer(liLen);
- }
- //读m_strCurVideoEncoder
- liLen = 0;
- result = fread(&liLen, sizeof(int), 1,lpFp);
- if (1 != result)
- {
- AfxMessageBox("读取配置文件出错");
- fclose(lpFp);
- DeleteFile(lszTotalPath);
- return false;
- }
- if (liLen)
- {
- result = fread(m_strCurVideoEncoder.GetBuffer(liLen), sizeof(char), liLen,lpFp);
- if (liLen != result)
- {
- m_strCurVideoEncoder.ReleaseBuffer(liLen);
- AfxMessageBox("读取配置文件出错");
- fclose(lpFp);
- DeleteFile(lszTotalPath);
- return false;
- }
- m_strCurVideoEncoder.ReleaseBuffer(liLen);
- }
- //读媒体类型
- liLen = 0;
- result = fread(&liLen, sizeof(int), 1,lpFp);
- if (1 != result)
- {
- AfxMessageBox("读取配置文件出错");
- fclose(lpFp);
- DeleteFile(lszTotalPath);
- return false;
- }
- if (liLen)//必须加,如果不加,则读出零个字节时就会返回false,此时应返回true,因为
- //只是代表没有。
- {
- //Arthur:解决m_pCurAudioAMT尽管有值为零,但是却还是分配了空间,只要有值时才给
- //mpTemAudioAMT分配空间就可。
- mpTemAudioAMT = (AM_MEDIA_TYPE *)HeapAlloc(GetProcessHeap(),
- HEAP_NO_SERIALIZE|HEAP_ZERO_MEMORY,
- sizeof(AM_MEDIA_TYPE) + sizeof(WAVEFORMATEX));
- result = fread(mpTemAudioAMT, liLen, 1,lpFp);
- if (1 != result)
- {
- HeapFree(GetProcessHeap(), 0, mpTemAudioAMT);
- mpTemAudioAMT = NULL;
- AfxMessageBox("读取配置文件出错");
- fclose(lpFp);
- DeleteFile(lszTotalPath);
- return false;
- }
- mpTemAudioAMT->pbFormat = (LPBYTE)(mpTemAudioAMT + 1);
- //如果媒体格式不是音频则退出,这是一个保护机制。
- if (FORMAT_WaveFormatEx != mpTemAudioAMT->formattype)
- {
- AfxMessageBox("读取配置文件出错");
- fclose(lpFp);
- DeleteFile(lszTotalPath);
- return false;
- }
- }
- fclose(lpFp);
- return true;
- }
- //求得完整路径
- bool CGVCaptureDlg::GetTotalPath(char *aszFileName, char *aszTotalPath)
- {
- GetModuleFileName(NULL, aszTotalPath, MAX_PATH);
- int liLengthPath = strlen(aszTotalPath);
- while (aszTotalPath[liLengthPath - 1] != '\')
- {
- --liLengthPath;
- }
- if (liLengthPath > 0)
- {
- aszTotalPath[liLengthPath] = ' ';
- if (NULL != aszFileName)
- {
- strcat(aszTotalPath, aszFileName);
- }
- return true;
- }
- return false;
- }
- //xiezhouwei 2005-08-15 添加配置pin函数
- void CGVCaptureDlg::OnBtnVideocapIniConfig()
- {
- // TODO: Add your control notification handler code here
- m_grfCapture.ShowPinSetting(m_hWnd);
- return;
- }
- void CGVCaptureDlg::OnChkSave()
- {
- char lszPath[MAX_PATH] = {0};
- UpdateData();
- if (BST_CHECKED == mbtnSaveFile.GetCheck())
- {
- GetTotalPath(NULL, lszPath);
- CFileDialog loFileDlg(FALSE, "avi" , NULL, OFN_EXPLORER|OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- "AVI Files (*.avi)|*.avi|All Files (*.*)|*.*||", NULL);
- loFileDlg.m_ofn.lStructSize = sizeof(loFileDlg.m_ofn);
- if (IDOK == loFileDlg.DoModal())
- {
- ZeroMemory(mszAVIFilePath, sizeof(mszAVIFilePath));
- strcpy(mszAVIFilePath, loFileDlg.GetPathName().GetBuffer(0));
- mstrSavePath = mszAVIFilePath;
- m_grfCapture.SetAVIFile(mszAVIFilePath);
- if (' ' == mszAVIFilePath[0])
- {
- mbtnSaveFile.SetCheck(BST_UNCHECKED);
- }
- }
- }
- else
- {
- mstrSavePath.Empty();
- }
- UpdateData(false);
- }
- BOOL CGVCaptureDlg::OnEraseBkgnd(CDC* pDC)
- {
- // Intercept background erasing for the movie window, since the
- // video renderer will keep the screen painted. Without this code,
- // your video window might get painted over with gray (the default
- // background brush) when it is obscured by another window and redrawn.
- CRect rc;
- // Get the bounding rectangle for the movie screen
- //m_VideoWindow.GetWindowRect(&rc);
- GetDlgItem(IDC_STATIC_PREVIEW)->GetWindowRect(&rc);
- ScreenToClient(&rc);
- // Exclude the clipping region occupied by our movie screen
- pDC->ExcludeClipRect(&rc);
- GetDlgItem(IDC_STATIC_PREVIEW)->GetWindowRect(&rc);
- ScreenToClient(&rc);
- pDC->ExcludeClipRect(&rc);
- // Erase the remainder of the dialog as usual
- return CDialog::OnEraseBkgnd(pDC);
- }
- //用户选择是否需要CrossBar输入
- void CGVCaptureDlg::OnBnClickedChkCrossbar()
- {
- if (BST_CHECKED == m_bChkCrossBar.GetCheck())
- {
- m_grfCapture.SetCrossBar(TRUE);
- return;
- }
- m_grfCapture.SetCrossBar(FALSE);
- }