www.pudn.com > IPcaptu.rar > backDlg.cpp


// backDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "back.h" 
#include "backDlg.h" 
 
#include "..\..\include\av8api.h" 
#include "..\..\include\Define.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
static CHAR	caFileName[STRSIZE] = "temp.mpg"; 
 
typedef WORD (CALLBACK *USER_CALLBACK) (HDRVR hdrvr, UINT msg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2); 
 
WORD CALLBACK _loadds MyCallBack(HDRVR hdrvr, UINT msg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2); 
 
static HMMIO hmmioInput; 
static HMMIO hmmioOutput; 
 
///////////////////////////////////////////////////////////////////////////// 
// 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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CBackDlg dialog 
 
CBackDlg::CBackDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CBackDlg::IDD, pParent), m_hVFDrv(0), m_bStream(0) 
 
{ 
	//{{AFX_DATA_INIT(CBackDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
 
 
CBackDlg::~CBackDlg() 
 
{ 
    // make sure that on destruct, OnStop() is called to  
    // stop/close/unlock.  This prevents a system crash (blue screen) 
    OnStop(); 
} 
 
 
 
void CBackDlg::DoDataExchange(CDataExchange* pDX) 
 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CBackDlg) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CBackDlg, CDialog) 
	//{{AFX_MSG_MAP(CBackDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_RECORD, OnRecord) 
	ON_BN_CLICKED(IDC_STOP, OnStop) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CBackDlg message handlers 
 
 
 
BOOL CBackDlg::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); 
	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 
	cbSystem=(CButton *)GetDlgItem(IDC_SYSTEM); 
	cbVideo=(CButton *)GetDlgItem(IDC_VIDEO); 
	cbAudio=(CButton *)GetDlgItem(IDC_AUDIO); 
	cbSystem->SetCheck(TRUE); 
 
    return TRUE;  // return TRUE  unless you set the focus to a control 
 
} 
 
 
 
void CBackDlg::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 CBackDlg::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 CBackDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CAspenApp commands 
 
WORD CALLBACK _loadds MyCallBack(HDRVR hdrvr, UINT msg, DWORD dwUser, DWORD dwParam1, DWORD dwParam2) 
{ 
DWORD		dwFlags = 0; 
 
	TRACE0("MyCallBack"); 
	switch (msg) 
	{ 
	case VF_MSGUSER_BUF_WRITE: 
	    { 
	        LONG		lRet; 
	        LPVF_BUFWRITE_STRUCT	lpBufWrite = (LPVF_BUFWRITE_STRUCT)dwParam1; 
	        lRet = mmioWrite(hmmioOutput, (LPSTR)lpBufWrite->lpBuffer, (LONG)lpBufWrite->dwBufferWrite); 
	        if (lRet == -1L) 
            { 
		        return (FALSE); 
            } 
	        break; 
	    } 
 
	case VF_MSGUSER_BUF_CREATE: 
	    { 
	        LPVF_CALLBACK_STRUCT	lpCallback = (LPVF_CALLBACK_STRUCT)dwParam1; 
 
	        if (lpCallback->wSubMsg == VF_SUBMSG_OUTPUT) 
		    { 
                dwFlags = MMIO_CREATE | MMIO_WRITE; 
                hmmioOutput = mmioOpen((LPTSTR)caFileName, (LPMMIOINFO)NULL, dwFlags); 
		    } 
	        else 
            { 
                dwFlags = MMIO_READ | MMIO_DENYWRITE; 
                hmmioInput = mmioOpen((LPTSTR)caFileName, (LPMMIOINFO)NULL, dwFlags); 
            } 
	        break; 
	    } 
 
	case VF_MSGUSER_BUF_CLOSE: 
	    { 
	        LPVF_CALLBACK_STRUCT	lpCallback = (LPVF_CALLBACK_STRUCT)dwParam1; 
 
	        if (lpCallback->wSubMsg == VF_SUBMSG_OUTPUT) 
		    { 
		        if (hmmioOutput) 
			    { 
			        mmioClose(hmmioOutput, NULL); 
			        hmmioOutput = NULL; 
			    } 
		    } 
	        else 
		    { 
		        if (hmmioInput) 
		        { 
		            mmioClose(hmmioInput, NULL); 
		            hmmioInput = NULL; 
		        } 
		    } 
	        break; 
	    } 
    } // switch 
 
	return 1; 
} 
 
 
 
VOID CBackDlg::OnRecord()  
 
{ 
    // TODO: Add your control notification handler code here 
    WORD flags; 
 
    m_hVFDrv = OpenDriver (L"av8api.dll", NULL, NULL); 
    if (!m_hVFDrv) 
    { 
        AfxMessageBox(_TEXT("Can't OpenDriver().")); 
        return ; 
    } 
 
    if (!HVFAssign(m_hVFDrv, 0)) 
    { 
        AfxMessageBox(_TEXT("Can't Assign Dev!")); 
        return ; 
    } 
 
    if (!HVFLock(m_hVFDrv, VF_CAP_ALL)) 
    { 
        AfxMessageBox(_TEXT("Can't Lock Dev!")); 
        return ; 
    } 
 
    flags = VF_FLAG_MPEG | VF_FLAG_ENCODE | VF_FLAG_OUTBUF; 
    m_bStream = static_cast 
        (HVFOpen(m_hVFDrv,  
                 flags,  
                 reinterpret_cast(MyCallBack))); 
 
    if(cbSystem->GetCheck()) 
    { 
        InitEncodeVideoVxD(); 
        InitEncodeAudioVxD(); 
    }  
 
    else  
    { 
        if(cbVideo->GetCheck()) 
        { 
            InitEncodeVideoVxD(); 
        } 
 
        else  
        { 
            InitEncodeAudioVxD(); 
        } 
    } 
 
    InitEncodeSystemVxD(); 
    if (m_bStream)  
    { 
        HVFRecord(m_hVFDrv, m_bStream, NULL, NULL); 
    } 
} // CBackDlg::OnRecord() 
 
 
 
VOID CBackDlg::OnStop()  
 
{ 
    // TODO: Add your control notification handler code here 
    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); 
        m_hVFDrv = 0; 
    } 
} // CBackDlg::OnStop() 
 
 
 
BOOL CBackDlg::InitEncodeVideoVxD(void) 
 
{ 
    DWORD dwValue; 
    WORD  wWidth, wHeight; 
 
    wWidth=352; 
    wHeight=240; 
    dwValue=MAKELONG(wWidth, wHeight); 
 
    HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_OUTPUTSIZE, dwValue); 
 
    /* SDL - also set video width and height to scale images */ 
    wWidth = (wWidth * 45) / 44; // try to maintain standard MPEG SIF aspect ratio 
    dwValue = MAKELONG(wWidth, wHeight /* [sic] */); 
    HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_INPUTSIZE, dwValue); 
 
    HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_BITRATE, BITRATE_DEFAULT); 
 
    HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_RATE, VF_FLAG_VID_25); 
 
    HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_IINTERVAL, IINTERVAL_DEFAULT); 
 
    HVFSet(m_hVFDrv, m_bStream, VF_INDEX_VID_BINTERVAL, PINTERVAL_DEFAULT); 
 
    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); 
 
    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); 
 
    return TRUE; 
} 
 
 
 
BOOL CBackDlg::InitEncodeAudioVxD(void) 
 
{ 
 	DWORD dwValue; 
 
	HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_SAMPLE, SAMPLE_RATE_DEFAULT); 
	HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_BITRATE, BIT_RATE_DEFAULT); 
 
	dwValue=VF_FLAG_AUD_MPEG;	// set to MPEG algorithm 
	dwValue=(dwValue<<16)+VF_FLAG_AUD_NONE; 
	HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_ALGORITHM, dwValue); 
	HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_MODE, MODE_DEFAULT); 
	HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_VOLUME, VOLUME_MIN); 
	HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_VOLUME, VOLUME_DEFAULT); 
	HVFSet(m_hVFDrv, m_bStream, VF_INDEX_AUD_GAIN, GAIN_DEFAULT); 
 
	return TRUE; 
} 
 
 
 
BOOL CBackDlg::InitEncodeSystemVxD(void) 
 
{ 
	if(cbSystem->GetCheck()){ 
		HVFSet(m_hVFDrv, m_bStream, VF_INDEX_STM_TYPE, VF_FLAG_MPGSYS); 
	} else { 
		if(cbVideo->GetCheck()){ 
			HVFSet(m_hVFDrv, m_bStream, VF_INDEX_STM_TYPE, VF_FLAG_MPGVID); 
		} else { 
			HVFSet(m_hVFDrv, m_bStream, VF_INDEX_STM_TYPE, VF_FLAG_MPGAUD); 
		} 
	} 
 
	HVFSet(m_hVFDrv, m_bStream, VF_INDEX_STM_ENCODEMODE, VF_FLAG_STM_NORMAL); 
	return TRUE; 
}