?? listcodecpropsdlg.cpp
字號:
// ListCodecPropsDlg.cpp : implementation file
//
/**
** Copyright (C) 2005 EnjoyView Inc., all rights reserved.
** Your View, Our Passion. Just Enjoy It!
**
** http://spaces.msn.com/members/jemylu
**
**/
/*************************************************************************/
#include "stdafx.h"
#include "ListCodecProps.h"
#include "ListCodecPropsDlg.h"
#include "safe_defs.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CListCodecPropsDlg dialog
CListCodecPropsDlg::CListCodecPropsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CListCodecPropsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CListCodecPropsDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
mProfileManager = NULL;
mCodecInfo3 = NULL;
}
void CListCodecPropsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CListCodecPropsDlg)
DDX_Control(pDX, IDC_EDIT_FORMAT_BUFFERWINDOW, mEditFormatBufferWindow);
DDX_Control(pDX, IDC_EDIT_FORMAT_BITRATE, mEditFormatBitrate);
DDX_Control(pDX, IDC_EDIT_CODEC_SUPPORT_VBR, mEditCodecVBRSupported);
DDX_Control(pDX, IDC_EDIT_CODEC_COMPLEXITY_LIVE, mEditCodecComplexityLive);
DDX_Control(pDX, IDC_EDIT_CODEC_COMPLEXITY_MAX, mEditCodecComplexityMax);
DDX_Control(pDX, IDC_EDIT_CODEC_COMPLEXITY_OFFLINE, mEditCodecComplexityOffline);
DDX_Control(pDX, IDC_EDIT_CODEC_PASSES, mEditCodecPasses);
DDX_Control(pDX, IDC_EDIT_CODEC_ISVBR, mEditCodecIsVBR);
DDX_Control(pDX, IDC_EDIT_FORMAT_SPEECHCAPS, mEditFormatSpeechCaps);
DDX_Control(pDX, IDC_COMBO_FORMAT_DESC, mComboFormatDesc);
DDX_Control(pDX, IDC_LIST_CODEC_NAME, mListBoxCodecName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CListCodecPropsDlg, CDialog)
//{{AFX_MSG_MAP(CListCodecPropsDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_LBN_SELCHANGE(IDC_LIST_CODEC_NAME, OnSelchangeListCodecName)
ON_CBN_SELCHANGE(IDC_COMBO_FORMAT_DESC, OnSelchangeComboFormatDesc)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListCodecPropsDlg message handlers
BOOL CListCodecPropsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
// Create a profile manager object
HRESULT hr = WMCreateProfileManager(&mProfileManager);
if (FAILED(hr))
{
AfxMessageBox("Failed to Create a Profile Manager.");
return FALSE;
}
// Get the IWMCodecInfo3 interface
hr = mProfileManager->QueryInterface(IID_IWMCodecInfo3, (void**) &mCodecInfo3);
if (FAILED(hr))
{
AfxMessageBox("Failed to Get the IWMCodecInfo3 Interface.");
return FALSE;
}
FillCodecNames();
ReflectCodecProperties();
if (SUCCEEDED(FillFormatDescs()))
{
ReflectCodecCurrentSettings();
ReflectFormatProperties();
ReflectFormatDetails();
}
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CListCodecPropsDlg::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 CListCodecPropsDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CListCodecPropsDlg::OnDestroy()
{
ReleaseAllStreamConfig();
SAFE_RELEASE(mProfileManager);
SAFE_RELEASE(mCodecInfo3);
CDialog::OnDestroy();
}
void CListCodecPropsDlg::ReleaseAllStreamConfig(void)
{
IWMStreamConfig * pConfig = NULL;
POSITION pos = mStreamConfigList.GetHeadPosition();
while (pos)
{
pConfig = (IWMStreamConfig*) mStreamConfigList.GetNext(pos);
SAFE_RELEASE(pConfig);
}
mStreamConfigList.RemoveAll();
}
void CListCodecPropsDlg::FillCodecNames(void)
{
mListBoxCodecName.ResetContent();
GetCodecNames(WMMEDIATYPE_Audio);
GetCodecNames(WMMEDIATYPE_Video);
// Select the first item
if (mListBoxCodecName.GetCount() > 0)
{
mListBoxCodecName.SetCurSel(0);
}
}
HRESULT CListCodecPropsDlg::GetCodecNames(REFGUID inType)
{
if (mCodecInfo3 == NULL)
{
return E_FAIL;
}
DWORD cCodecs = 0;
WCHAR* pwszCodecName = NULL;
DWORD cchCodecName = 0;
DWORD codecType = (inType == WMMEDIATYPE_Audio) ? AudioCodecMask : VideoCodecMask;
// Retrieve the number of supported codecs on the system.
HRESULT hr = mCodecInfo3->GetCodecInfoCount(inType, &cCodecs);
// Loop through all the audio codecs.
for (DWORD i = 0; i < cCodecs; i++)
{
// Get the codec name:
// First, get the size of the name.
hr = mCodecInfo3->GetCodecName(inType, i, NULL, &cchCodecName);
if (FAILED(hr))
{
TRACE("Could not get the size of the codec name.\n");
return hr;
}
// Allocate a string of the appropriate size.
pwszCodecName = new WCHAR[cchCodecName];
if (pwszCodecName == NULL)
{
TRACE("Could not allocate memory.\n");
return E_OUTOFMEMORY;
}
// Retrieve the codec name.
hr = mCodecInfo3->GetCodecName(inType, i, pwszCodecName, &cchCodecName);
if (FAILED(hr))
{
delete[] pwszCodecName;
TRACE("Could not get the codec name.\n");
return hr;
}
// Add codec name to the list box
char szName[100];
WideCharToMultiByte(CP_ACP, 0, pwszCodecName, -1, szName, 100, NULL, NULL);
int itemIndex = mListBoxCodecName.AddString(szName);
DWORD itemData = codecType | i;
mListBoxCodecName.SetItemData(itemIndex, itemData);
// Clean up for the next iteration.
delete[] pwszCodecName;
pwszCodecName = NULL;
cchCodecName = 0;
}
return S_OK;
}
void CListCodecPropsDlg::OnSelchangeListCodecName()
{
ReflectCodecProperties();
if (SUCCEEDED(FillFormatDescs()))
{
ReflectCodecCurrentSettings();
ReflectFormatProperties();
ReflectFormatDetails();
}
}
void CListCodecPropsDlg::OnSelchangeComboFormatDesc()
{
if (mCodecInfo3)
{
ReflectFormatProperties();
ReflectFormatDetails();
}
}
// Retrieves the formats supported by the specified codec.
// Each codec format is a stream configuration that is valid
// for use with the codec.
HRESULT CListCodecPropsDlg::FillFormatDescs(void)
{
if (mCodecInfo3 == NULL)
{
return E_FAIL;
}
ReleaseAllStreamConfig();
mComboFormatDesc.ResetContent();
// Get the selected codec name
int index = mListBoxCodecName.GetCurSel();
if (LB_ERR != index)
{
DWORD itemData = mListBoxCodecName.GetItemData(index);
DWORD codecIndex = itemData & CodecIndexMask;
if (itemData & AudioCodecMask)
{
// This is an audio codec
FillAudioFormatDescs(FALSE, 0, codecIndex);
FillAudioFormatDescs(TRUE, 1, codecIndex);
FillAudioFormatDescs(TRUE, 2, codecIndex);
}
else if (itemData & VideoCodecMask)
{
// This is an video codec, then do nothing here!
// Video codecs provide only a single format.
// This is because video streams have variables,
// like frame size, that are more flexible
// than the settings of an audio stream.
}
}
// Select the first item
if (mComboFormatDesc.GetCount() > 0)
{
mComboFormatDesc.SetCurSel(0);
mComboFormatDesc.EnableWindow(TRUE);
}
else
{
mComboFormatDesc.EnableWindow(FALSE);
}
return S_OK;
}
HRESULT CListCodecPropsDlg::FillAudioFormatDescs(BOOL inIsVBR, DWORD inPasses, DWORD inCodecIndex)
{
// Set the VBR settings appropriately
SetCodecVBRSettings(WMMEDIATYPE_Audio, inCodecIndex, inIsVBR, inPasses);
DWORD vbrSettings = inIsVBR ? CodecIsVBRMask : 0;
vbrSettings |= (inPasses << 16);
DWORD cFormats = 0;
WCHAR* pwszFormatDesc = NULL;
DWORD cchForamtDesc = 0;
// Retrieve the number of supported formats
HRESULT hr = mCodecInfo3->GetCodecFormatCount(WMMEDIATYPE_Audio, inCodecIndex, &cFormats);
// Loop through all the audio codecs.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -