⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gvcapturedlg.cpp

📁 mysee网络直播源代码Mysee Lite是Mysee独立研发的网络视频流媒体播放系统。在应有了P2P技术和一系列先进流媒体技术之后
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
 *  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())
		{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -