📄 listcodecpropsdlg.cpp
字号:
for (DWORD i = 0; i < cFormats; i++)
{
hr = mCodecInfo3->GetCodecFormatDesc(WMMEDIATYPE_Audio, inCodecIndex, i, NULL, NULL, &cchForamtDesc);
if (FAILED(hr))
{
return hr;
}
pwszFormatDesc = new WCHAR[cchForamtDesc];
if (pwszFormatDesc == NULL)
{
return E_OUTOFMEMORY;
}
IWMStreamConfig * pStreamConfig = NULL;
hr = mCodecInfo3->GetCodecFormatDesc(WMMEDIATYPE_Audio, inCodecIndex, i, &pStreamConfig, pwszFormatDesc, &cchForamtDesc);
if (FAILED(hr))
{
delete[] pwszFormatDesc;
return hr;
}
// Save pStreamConfig to the list for later using...
mStreamConfigList.AddTail(pStreamConfig);
// Add format description to the combo box
char szName[1024];
WideCharToMultiByte(CP_ACP, 0, pwszFormatDesc, -1, szName, 1024, NULL, NULL);
int itemIndex = mComboFormatDesc.AddString(szName);
DWORD itemData = vbrSettings | i;
mComboFormatDesc.SetItemData(itemIndex, itemData);
// Clean up for the next iteration.
delete[] pwszFormatDesc;
pwszFormatDesc = NULL;
cchForamtDesc = 0;
}
return S_OK;
}
void CListCodecPropsDlg::ReflectCodecProperties(void)
{
if (mCodecInfo3 == NULL)
{
return;
}
// Get the selected codec name
int index = mListBoxCodecName.GetCurSel();
if (LB_ERR != index)
{
DWORD itemData = mListBoxCodecName.GetItemData(index);
DWORD codecIndex = itemData & CodecIndexMask;
GUID codecType = (itemData & AudioCodecMask) ? WMMEDIATYPE_Audio : WMMEDIATYPE_Video;
WMT_ATTR_DATATYPE dataType;
CString strTemp;
DWORD dwValue = 0;
DWORD dSize = sizeof(DWORD);
HRESULT hr = mCodecInfo3->GetCodecProp(codecType, codecIndex,
g_wszComplexityMax, &dataType, (BYTE*) &dwValue, &dSize);
if (SUCCEEDED(hr))
{
strTemp.Format("%d", dwValue);
mEditCodecComplexityMax.SetWindowText(strTemp);
}
else
{
mEditCodecComplexityMax.SetWindowText(" X");
}
dSize = sizeof(DWORD);
hr = mCodecInfo3->GetCodecProp(codecType, codecIndex,
g_wszComplexityOffline, &dataType, (BYTE*) &dwValue, &dSize);
if (SUCCEEDED(hr))
{
strTemp.Format("%d", dwValue);
mEditCodecComplexityOffline.SetWindowText(strTemp);
}
else
{
mEditCodecComplexityOffline.SetWindowText(" X");
}
dSize = sizeof(DWORD);
hr = mCodecInfo3->GetCodecProp(codecType, codecIndex,
g_wszComplexityLive, &dataType, (BYTE*) &dwValue, &dSize);
if (SUCCEEDED(hr))
{
strTemp.Format("%d", dwValue);
mEditCodecComplexityLive.SetWindowText(strTemp);
}
else
{
mEditCodecComplexityLive.SetWindowText(" X");
}
dSize = sizeof(DWORD);
hr = mCodecInfo3->GetCodecProp(codecType, codecIndex,
g_wszIsVBRSupported, &dataType, (BYTE*) &dwValue, &dSize);
if (SUCCEEDED(hr))
{
mEditCodecVBRSupported.SetWindowText(dwValue ? "TRUE" : "FALSE");
}
else
{
mEditCodecVBRSupported.SetWindowText(" X");
}
}
}
void CListCodecPropsDlg::ReflectCodecCurrentSettings(void)
{
// Get the selected codec name
int index = mListBoxCodecName.GetCurSel();
if (LB_ERR != index)
{
DWORD itemData = mListBoxCodecName.GetItemData(index);
DWORD codecIndex = itemData & CodecIndexMask;
GUID codecType = (itemData & AudioCodecMask) ? WMMEDIATYPE_Audio : WMMEDIATYPE_Video;
BOOL isVBR = FALSE;
DWORD passes = 1;
HRESULT hr = GetCodecVBRSettings(codecType, codecIndex, isVBR, passes);
if (SUCCEEDED(hr))
{
CString strTemp = isVBR ? "TRUE" : "FALSE";
mEditCodecIsVBR.SetWindowText(strTemp);
strTemp.Format("%d", passes);
mEditCodecPasses.SetWindowText(strTemp);
}
else
{
mEditCodecIsVBR.SetWindowText(" X");
mEditCodecPasses.SetWindowText(" X");
}
}
}
void CListCodecPropsDlg::ReflectFormatProperties(void)
{
if (mCodecInfo3 == NULL)
{
return;
}
// First, get the selected codec
int index = mListBoxCodecName.GetCurSel();
DWORD itemData = mListBoxCodecName.GetItemData(index);
DWORD codecIndex = itemData & CodecIndexMask;
GUID codecType = (itemData & AudioCodecMask) ? WMMEDIATYPE_Audio : WMMEDIATYPE_Video;
// Get the selected format desc
index = mComboFormatDesc.GetCurSel();
if (CB_ERR != index)
{
DWORD itemData = mComboFormatDesc.GetItemData(index);
BOOL isVBR = (itemData & CodecIsVBRMask) ? TRUE : FALSE;
DWORD passes = (itemData & CodecPassesMask) >> 16;
DWORD formatIndex = itemData & FormatIndexMask;
// Settings on the codec
SetCodecVBRSettings(codecType, codecIndex, isVBR, passes);
WMT_ATTR_DATATYPE dataType;
DWORD dwValue = 0;
DWORD dSize = sizeof(DWORD);
HRESULT hr = mCodecInfo3->GetCodecFormatProp(codecType, codecIndex, formatIndex,
g_wszSpeechCaps, &dataType, (BYTE*) &dwValue, &dSize);
if (SUCCEEDED(hr))
{
if (dwValue == WMT_MS_CLASS_MUSIC)
{
mEditFormatSpeechCaps.SetWindowText("Music");
}
else if (dwValue == WMT_MS_CLASS_SPEECH)
{
mEditFormatSpeechCaps.SetWindowText("Speech");
}
else if (dwValue == WMT_MS_CLASS_MIXED)
{
mEditFormatSpeechCaps.SetWindowText("Mixed");
}
else
{
mEditFormatSpeechCaps.SetWindowText("Unknown");
}
}
else
{
mEditFormatSpeechCaps.SetWindowText(" X");
}
}
}
void CListCodecPropsDlg::ReflectFormatDetails(void)
{
// Get the selected format desc
int index = mComboFormatDesc.GetCurSel();
if (CB_ERR != index)
{
POSITION pos = mStreamConfigList.GetHeadPosition();
while (pos && --index >= 0)
{
mStreamConfigList.GetNext(pos);
}
IWMStreamConfig * pConfig = NULL;
if (pos)
{
pConfig = (IWMStreamConfig*) mStreamConfigList.GetAt(pos);
if (pConfig)
{
ReflectStreamConfig(pConfig);
}
}
}
}
void CListCodecPropsDlg::ReflectStreamConfig(IWMStreamConfig * pConfig)
{
CString strTemp;
DWORD dwValue = 0;
HRESULT hr = pConfig->GetBitrate(&dwValue);
if (SUCCEEDED(hr))
{
strTemp.Format("%d", dwValue);
mEditFormatBitrate.SetWindowText(strTemp);
}
else
{
mEditFormatBitrate.SetWindowText(" X");
}
hr = pConfig->GetBufferWindow(&dwValue);
if (SUCCEEDED(hr))
{
strTemp.Format("%d", dwValue);
mEditFormatBufferWindow.SetWindowText(strTemp);
}
else
{
mEditFormatBufferWindow.SetWindowText(" X");
}
}
// Enables VBR with the specified number of passes, or disables it.
HRESULT CListCodecPropsDlg::SetCodecVBRSettings(REFGUID inCodecType,
DWORD inCodecIndex,
BOOL inIsVBR,
DWORD inVBRPasses)
{
HRESULT hr = NOERROR;
do
{
// Configure the codec to use or not use VBR as requested
hr = mCodecInfo3->SetCodecEnumerationSetting(inCodecType, inCodecIndex,
g_wszVBREnabled, WMT_TYPE_BOOL, (BYTE*) &inIsVBR, sizeof(BOOL));
if (FAILED(hr))
{
// If VBR is requested, then it's a problem, but otherwise the codec may just not support VBR
if ((!inIsVBR) && (NS_E_UNSUPPORTED_PROPERTY == hr))
{
hr = S_OK;
}
else
{
break;
}
}
if (inIsVBR)
{
hr = mCodecInfo3->SetCodecEnumerationSetting(inCodecType, inCodecIndex,
g_wszNumPasses, WMT_TYPE_DWORD, (BYTE*) &inVBRPasses, sizeof(DWORD));
if (FAILED(hr))
{
break;
}
}
}
while (FALSE);
return hr;
}
HRESULT CListCodecPropsDlg::GetCodecVBRSettings(REFGUID inCodecType,
DWORD inCodecIndex,
BOOL& outIsVBR,
DWORD& outVBRPasses)
{
WMT_ATTR_DATATYPE dataType;
DWORD dwValue = 0;
DWORD dSize = sizeof(DWORD);
HRESULT hr = mCodecInfo3->GetCodecEnumerationSetting(inCodecType, inCodecIndex,
g_wszVBREnabled, &dataType, (BYTE*) &dwValue, &dSize);
if (SUCCEEDED(hr))
{
outIsVBR = (BOOL) dwValue;
// If VBR, get the number of pass
if (outIsVBR)
{
dSize = sizeof(DWORD);
hr = mCodecInfo3->GetCodecEnumerationSetting(inCodecType, inCodecIndex,
g_wszNumPasses, &dataType, (BYTE*) &dwValue, &dSize);
outVBRPasses = dwValue;
}
else
{
outVBRPasses = 0;
}
return S_OK;
}
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -