2 Star 0 Fork 0

mirrors_chromium_googlesource/webmdshow

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vp8encoderproppage.cc 31.80 KB
一键复制 编辑 原始数据 按行查看 历史
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573
#include <strmif.h>
#include <string>
#include "vp8encoderidl.h"
#include "vp8encoderproppage.h"
#include "resource.h"
#include <new>
#include <cassert>
#include <sstream>
#include <windowsx.h>
#ifdef _DEBUG
#include "odbgstream.h"
using std::endl;
using std::hex;
using std::dec;
#endif
using std::wstring;
using std::wistringstream;
using std::wostringstream;
extern HMODULE g_hModule;
namespace VP8EncoderLib
{
extern const CLSID CLSID_PropPage = { //ED311102-5211-11DF-94AF-0026B977EEAA
0xED311102,
0x5211,
0x11DF,
{0x94, 0xAF, 0x00, 0x26, 0xB9, 0x77, 0xEE, 0xAA}
};
HRESULT CreatePropPage(
IClassFactory* pClassFactory,
IUnknown* pOuter,
const IID& iid,
void** ppv)
{
if (ppv == 0)
return E_POINTER;
*ppv = 0;
if (pOuter)
return CLASS_E_NOAGGREGATION;
PropPage* const p = new (std::nothrow) PropPage(pClassFactory);
if (p == 0)
return E_OUTOFMEMORY;
assert(p->m_cRef == 1);
IPropertyPage* const pUnk = static_cast<IPropertyPage*>(p);
const HRESULT hr = pUnk->QueryInterface(iid, ppv);
const ULONG n = pUnk->Release();
n;
return hr;
}
PropPage::PropPage(IClassFactory* pClassFactory) :
m_pClassFactory(pClassFactory),
m_cRef(1), //see PropPageCreateInstance
m_pSite(0),
m_pVPX(0),
m_hWnd(0),
m_bDirty(false)
{
m_pClassFactory->LockServer(TRUE);
#ifdef _DEBUG
wodbgstream os;
os << "PropPage::ctor" << endl;
#endif
}
PropPage::~PropPage()
{
#ifdef _DEBUG
wodbgstream os;
os << "PropPage::dtor" << endl;
#endif
assert(m_pSite == 0);
assert(m_pVPX == 0);
assert(m_hWnd == 0);
m_pClassFactory->LockServer(FALSE);
}
HRESULT PropPage::QueryInterface(
const IID& iid,
void** ppv)
{
if (ppv == 0)
return E_POINTER;
IUnknown*& pUnk = reinterpret_cast<IUnknown*&>(*ppv);
if (iid == __uuidof(IUnknown))
{
pUnk = static_cast<IPropertyPage*>(this); //must be non-delegating
}
else if (iid == __uuidof(IPropertyPage))
{
pUnk = static_cast<IPropertyPage*>(this);
}
else
{
pUnk = 0;
return E_NOINTERFACE;
}
pUnk->AddRef();
return S_OK;
}
ULONG PropPage::AddRef()
{
return InterlockedIncrement(&m_cRef);
}
ULONG PropPage::Release()
{
if (LONG n = InterlockedDecrement(&m_cRef))
return n;
SetPageSite(0);
SetObjects(0, 0);
delete this;
return 0;
}
HRESULT PropPage::SetPageSite(IPropertyPageSite* pSite)
{
if (pSite)
{
if (m_pSite)
return E_UNEXPECTED;
m_pSite = pSite;
m_pSite->AddRef();
}
else if (m_pSite)
{
m_pSite->Release();
m_pSite = 0;
}
return S_OK;
}
HRESULT PropPage::Activate(HWND hWndParent, LPCRECT prc, BOOL /* fModal */ )
{
#if 0 //def _DEBUG
wodbgstream os;
os << "activate" << endl;
#endif
if (m_pVPX == 0) //SetObjects hasn't been called yet
return E_UNEXPECTED;
if (m_hWnd)
return E_UNEXPECTED;
const HWND hWnd = CreateDialogParam(
g_hModule,
MAKEINTRESOURCE(IDD_PROPPAGE_VP8ENCODER),
hWndParent,
&PropPage::DialogProc,
reinterpret_cast<LPARAM>(this));
if (hWnd == 0)
{
const DWORD e = GetLastError();
return HRESULT_FROM_WIN32(e);
}
InitializeEndUsage(hWnd);
InitializeKeyframeMode(hWnd);
InitializeEncoderKind(hWnd);
Initialize(hWnd);
m_hWnd = hWnd;
Move(prc);
return Show(SW_SHOWNORMAL);
}
void PropPage::ErrorMessage(const wchar_t* msg) const
{
MessageBox(m_hWnd, msg, L"Error", MB_OK);
}
void PropPage::InitializeEndUsage(HWND hWnd)
{
const HWND hCtrl = GetDlgItem(hWnd, IDC_END_USAGE);
assert(hCtrl);
int idx = ComboBox_AddString(hCtrl, L"");
assert(idx == 0);
idx = ComboBox_AddString(hCtrl, L"VBR");
assert(idx == 1);
idx = ComboBox_AddString(hCtrl, L"CBR");
assert(idx == 2);
}
void PropPage::InitializeKeyframeMode(HWND hWnd)
{
const HWND hCtrl = GetDlgItem(hWnd, IDC_KEYFRAME_MODE);
assert(hCtrl);
int idx = ComboBox_AddString(hCtrl, L"");
assert(idx == 0);
idx = ComboBox_AddString(hCtrl, L"Disabled");
assert(idx == 1);
idx = ComboBox_AddString(hCtrl, L"Auto");
assert(idx == 2);
}
void PropPage::InitializeEncoderKind(HWND hWnd)
{
const HWND hCtrl = GetDlgItem(hWnd, IDC_ENCODER_KIND);
assert(hCtrl);
int idx = ComboBox_AddString(hCtrl, L"VP8");
assert(idx == 0);
idx = ComboBox_AddString(hCtrl, L"VP9");
assert(idx == 1);
}
void PropPage::Initialize(HWND hWnd)
{
GetDeadline(hWnd);
GetThreadCount(hWnd);
GetErrorResilient(hWnd);
GetDropframeThreshold(hWnd);
GetResizeAllowed(hWnd);
GetResizeUpThreshold(hWnd);
GetResizeDownThreshold(hWnd);
GetEndUsage(hWnd);
GetLagInFrames(hWnd);
GetTokenPartitions(hWnd);
GetTargetBitrate(hWnd);
GetMinQuantizer(hWnd);
GetMaxQuantizer(hWnd);
GetUndershootPct(hWnd);
GetOvershootPct(hWnd);
GetDecoderBufferSize(hWnd);
GetDecoderBufferInitialSize(hWnd);
GetDecoderBufferOptimalSize(hWnd);
GetKeyframeMode(hWnd);
GetKeyframeMinInterval(hWnd);
GetKeyframeMaxInterval(hWnd);
GetEncoderKind(hWnd);
}
HRESULT PropPage::Deactivate()
{
#if 0
wodbgstream os;
os << "deactivate" << endl;
#endif
if (m_hWnd == 0)
return E_UNEXPECTED;
//Set CONTROLPARENT back to false before destroying this dlg.
LONG dwStyle = GetWindowLong(m_hWnd, GWL_EXSTYLE);
dwStyle &= ~WS_EX_CONTROLPARENT;
const HWND hWnd = m_hWnd;
m_hWnd = 0;
SetWindowLong(hWnd, GWL_EXSTYLE, dwStyle);
m_hWnd = hWnd;
//OnDeactivate
BOOL b = DestroyWindow(m_hWnd);
b;
m_hWnd = 0;
return S_OK;
}
HRESULT PropPage::GetPageInfo(PROPPAGEINFO* pInfo)
{
#if 0
wodbgstream os;
os << "getpageinfo" << endl;
#endif
assert(m_hWnd == 0);
if (pInfo == 0)
return E_POINTER;
PROPPAGEINFO& info = *pInfo;
info.cb = sizeof info;
const wchar_t title[] = L"VP8 Encoder Properties";
const size_t len = 1 + wcslen(title);
const size_t cb = len * sizeof(wchar_t);
info.pszTitle = (wchar_t*)CoTaskMemAlloc(cb);
if (info.pszTitle)
{
const errno_t e = wcscpy_s(info.pszTitle, len, title);
e;
assert(e == 0);
}
info.pszDocString = 0;
info.pszHelpFile = 0;
info.dwHelpContext = 0;
const HWND hWnd = CreateDialogParam(
g_hModule,
MAKEINTRESOURCE(IDD_PROPPAGE_VP8ENCODER),
GetDesktopWindow(),
&PropPage::DialogProc,
0);
if (hWnd == 0)
{
const DWORD e = GetLastError();
return HRESULT_FROM_WIN32(e);
}
RECT rc;
BOOL b = GetWindowRect(hWnd, &rc);
if (!b)
{
const DWORD e = GetLastError();
return HRESULT_FROM_WIN32(e);
}
SIZE& size = info.size;
size.cx = rc.right - rc.left;
size.cy = rc.bottom - rc.top;
b = DestroyWindow(hWnd);
return S_OK;
}
HRESULT PropPage::SetObjects(ULONG n, IUnknown** ppUnk)
{
if (n == 0)
{
if (m_pVPX)
{
m_pVPX->Release();
m_pVPX = 0;
}
return S_OK;
}
if (m_pVPX)
return E_UNEXPECTED;
if (ppUnk == 0)
return E_INVALIDARG;
IUnknown** const ppUnk_end = ppUnk + n;
while (ppUnk != ppUnk_end)
{
IUnknown* const pUnk = *ppUnk++;
if (pUnk == 0)
return E_INVALIDARG;
const HRESULT hr = pUnk->QueryInterface(&m_pVPX);
if (SUCCEEDED(hr))
{
assert(m_pVPX);
//TODO: some init here will probably be req'd
return S_OK;
}
}
return E_NOINTERFACE;
}
HRESULT PropPage::Show(UINT nCmdShow)
{
if (m_hWnd == 0)
return E_UNEXPECTED;
switch (nCmdShow)
{
case SW_SHOW:
case SW_SHOWNORMAL:
case SW_HIDE:
break;
default:
return E_INVALIDARG;
}
BOOL b = ShowWindow(m_hWnd, nCmdShow);
b = InvalidateRect(m_hWnd, 0, TRUE);
return S_OK;
}
HRESULT PropPage::Move(LPCRECT prc)
{
if (m_hWnd == 0)
return E_UNEXPECTED;
if (prc == 0)
return E_INVALIDARG;
const RECT& rc = *prc;
const LONG x = rc.left;
const LONG y = rc.top;
const LONG w = rc.right - rc.left;
const LONG h = rc.bottom - rc.top;
const BOOL b = MoveWindow(m_hWnd, x, y, w, h, TRUE);
b;
return S_OK;
}
HRESULT PropPage::IsPageDirty()
{
#if 0
wodbgstream os;
os << "ispagedirty" << endl;
#endif
return m_bDirty ? S_OK : S_FALSE;
}
HRESULT PropPage::Apply()
{
#if 0
wodbgstream os;
os << "apply" << endl;
#endif
if (m_pVPX == 0)
return E_UNEXPECTED;
if (m_pSite == 0)
return E_UNEXPECTED;
if (!m_bDirty)
return S_OK;
SetDeadline();
SetThreadCount();
SetErrorResilient();
SetDropframeThreshold();
SetResizeAllowed();
SetResizeUpThreshold();
SetResizeDownThreshold();
SetEndUsage();
SetLagInFrames();
SetTokenPartitions();
SetTargetBitrate();
SetMinQuantizer();
SetMaxQuantizer();
SetUndershootPct();
SetOvershootPct();
SetDecoderBufferSize();
SetDecoderBufferInitialSize();
SetDecoderBufferOptimalSize();
SetKeyframeMode();
SetKeyframeMinInterval();
SetKeyframeMaxInterval();
SetEncoderKind();
m_bDirty = false;
const HRESULT hr = m_pVPX->ApplySettings();
if (FAILED(hr))
{
ErrorMessage(L"ApplySettings failed.");
return S_OK; //?
}
return S_OK;
}
HRESULT PropPage::Help(LPCOLESTR)
{
return E_NOTIMPL;
}
HRESULT PropPage::TranslateAccelerator(MSG*)
{
return E_NOTIMPL;
}
INT_PTR PropPage::DialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
//wodbgstream os;
//os << "DlgProc: msg=0x" << hex << msg << dec << endl;
if (msg == WM_INITDIALOG)
{
SetLastError(0);
SetWindowLongPtr(hWnd, DWLP_USER, lParam);
const DWORD e = GetLastError();
e;
assert(e == 0);
return TRUE;
}
SetLastError(0);
const LONG_PTR ptr = GetWindowLongPtr(hWnd, DWLP_USER);
const DWORD e = GetLastError();
e;
assert(e == 0);
if (ptr == 0)
return FALSE;
PropPage* const pPage = reinterpret_cast<PropPage*>(ptr);
if (pPage->m_hWnd == 0)
return FALSE;
assert(pPage->m_hWnd == hWnd);
switch (msg)
{
case WM_STYLECHANGING:
{
if (wParam == GWL_EXSTYLE)
{
STYLESTRUCT* const p = reinterpret_cast<STYLESTRUCT*>(lParam);
assert(p);
p->styleNew |= WS_EX_CONTROLPARENT;
}
return FALSE;
}
case WM_COMMAND:
return pPage->OnCommand(wParam, lParam);
default:
return FALSE;
}
}
INT_PTR PropPage::OnCommand(WPARAM wParam, LPARAM)
{
const WORD code = HIWORD(wParam);
const WORD id = LOWORD(wParam);
//#define EN_SETFOCUS 0x0100
//#define EN_KILLFOCUS 0x0200
//#define EN_CHANGE 0x0300
//#define EN_UPDATE 0x0400
//#define EN_ERRSPACE 0x0500
//#define EN_MAXTEXT 0x0501
//#define EN_HSCROLL 0x0601
//#define EN_VSCROLL 0x0602
#if 0
wodbgstream os;
os << "OnCommand: code=0x" << hex << code << dec << " id=" << id << endl;
#endif
//#define CBN_ERRSPACE (-1)
//#define CBN_SELCHANGE 1
//#define CBN_DBLCLK 2
//#define CBN_SETFOCUS 3
//#define CBN_KILLFOCUS 4
//#define CBN_EDITCHANGE 5
//#define CBN_EDITUPDATE 6
//#define CBN_DROPDOWN 7
//#define CBN_CLOSEUP 8
//#define CBN_SELENDOK 9
//#define CBN_SELENDCANCEL 10
//if (code == EN_CHANGE)
// os << "EN_CHANGE" << endl;
//#define BN_CLICKED 0
//#define BN_PAINT 1
//#define BN_HILITE 2
//#define BN_UNHILITE 3
//#define BN_DISABLE 4
//#define BN_DOUBLECLICKED 5
//#if(WINVER >= 0x0400)
//#define BN_PUSHED BN_HILITE
//#define BN_UNPUSHED BN_UNHILITE
//#define BN_DBLCLK BN_DOUBLECLICKED
//#define BN_SETFOCUS 6
//#define BN_KILLFOCUS 7
switch (code)
{
case CBN_SELCHANGE:
case EN_CHANGE:
#if 0 //def _DEBUG
os << "OnCommand: code=0x" << hex << code << dec
<< " id=" << id
<< " CHANGE"
<< endl;
#endif
m_bDirty = true;
if (m_pSite)
m_pSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
return TRUE;
case BN_CLICKED:
if (id == IDC_CLEAR)
{
Clear();
return TRUE;
}
if (id == IDC_RELOAD)
{
Reload();
return TRUE;
}
if (id == IDC_RESET)
{
Reset();
return TRUE;
}
return FALSE;
default:
return FALSE;
}
}
HRESULT PropPage::Clear()
{
const HWND hWnd = m_hWnd;
m_hWnd = 0;
SetText(hWnd, IDC_DEADLINE);
SetText(hWnd, IDC_THREADCOUNT);
SetText(hWnd, IDC_ERROR_RESILIENT);
SetText(hWnd, IDC_DROPFRAME_THRESHOLD);
ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_END_USAGE), 0);
SetText(hWnd, IDC_LAG_IN_FRAMES);
SetText(hWnd, IDC_TOKEN_PARTITIONS);
SetText(hWnd, IDC_TARGET_BITRATE);
SetText(hWnd, IDC_MIN_QUANTIZER);
SetText(hWnd, IDC_MAX_QUANTIZER);
SetText(hWnd, IDC_UNDERSHOOT_PCT);
SetText(hWnd, IDC_OVERSHOOT_PCT);
SetText(hWnd, IDC_RESIZE_ALLOWED);
SetText(hWnd, IDC_RESIZE_UP_THRESHOLD);
SetText(hWnd, IDC_RESIZE_DOWN_THRESHOLD);
SetText(hWnd, IDC_DECODER_BUFFER_SIZE);
SetText(hWnd, IDC_DECODER_BUFFER_INITIAL_SIZE);
SetText(hWnd, IDC_DECODER_BUFFER_OPTIMAL_SIZE);
ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_KEYFRAME_MODE), 0);
SetText(hWnd, IDC_KEYFRAME_MIN_INTERVAL);
SetText(hWnd, IDC_KEYFRAME_MAX_INTERVAL);
ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_ENCODER_KIND), 0); //VP8
m_hWnd = hWnd;
m_bDirty = false;
if (m_pSite)
m_pSite->OnStatusChange(PROPPAGESTATUS_CLEAN);
return S_OK;
}
HRESULT PropPage::Reload()
{
const HWND hWnd = m_hWnd;
m_hWnd = 0;
Initialize(hWnd);
m_hWnd = hWnd;
m_bDirty = false;
if (m_pSite)
m_pSite->OnStatusChange(PROPPAGESTATUS_CLEAN);
return S_OK;
}
HRESULT PropPage::Reset()
{
assert(m_pVPX);
HRESULT hr = m_pVPX->ResetSettings();
if (FAILED(hr))
{
ErrorMessage(L"Unable to reset settings.");
return hr;
}
const HWND hWnd = m_hWnd;
m_hWnd = 0;
Initialize(hWnd);
m_hWnd = hWnd;
m_bDirty = false;
if (m_pSite)
m_pSite->OnStatusChange(PROPPAGESTATUS_CLEAN);
return S_OK;
}
DWORD PropPage::SetText(HWND hWnd, int id)
{
const BOOL b = ::SetDlgItemText(hWnd, id, 0);
if (b)
return 0; //SUCCESS
return GetLastError();
}
DWORD PropPage::SetText(HWND hWnd, int id, const std::wstring& str)
{
const BOOL b = ::SetDlgItemText(hWnd, id, str.c_str());
if (b)
return 0; //SUCCESS
return GetLastError();
}
DWORD PropPage::GetText(int id, std::wstring& str) const
{
int count = 64;
for (;;)
{
const size_t size = count * sizeof(wchar_t);
wchar_t* buf = (wchar_t*)_malloca(size);
const UINT result = ::GetDlgItemText(m_hWnd, id, buf, count);
if (result == 0)
{
if (DWORD e = GetLastError())
return e;
}
if ((result + 1) >= UINT(count))
{
count *= 2;
continue;
}
for (;;) //strip leading whitespace
{
if (*buf == L'\0')
{
str.clear();
return 0;
}
if (*buf == L' ')
{
++buf;
continue;
}
if (iswcntrl(*buf))
{
++buf;
continue;
}
str = buf;
break;
}
for (;;) //strip trailing whitespace
{
const wstring::size_type len = str.length();
assert(len > 0);
const wstring::size_type off = len - 1;
const wchar_t c = str[off];
if ((c == L' ') || iswcntrl(c))
{
str.erase(off, 1);
continue;
}
return 0;
}
}
}
HRESULT PropPage::SetIntValue(
pfnSetValue SetValue,
int code,
const wchar_t* name)
{
wstring text;
const DWORD e = GetText(code, text);
if (e)
{
wstring msg = L"Unable to get ";
msg += name;
msg += L" value from edit control.";
ErrorMessage(msg.c_str());
return S_FALSE;
}
//TODO: we could interpret empty text to mean "set to default value",
//which is exact what it means when the dialog box is first initialized.
if (text.empty())
return S_OK;
wistringstream is(text);
int val;
if (!(is >> val) || !is.eof())
{
wstring msg = L"Bad ";
msg += name;
msg += L" value.";
ErrorMessage(msg.c_str());
return S_FALSE;
}
//As above, we could interpret this to mean "set to default".
if (val < 0) //treat as nonce values
return S_OK;
assert(m_pVPX);
HRESULT hr = (m_pVPX->*SetValue)(val);
if (FAILED(hr))
{
wstring msg = L"Unable to set ";
msg += name;
msg += L" value on filter.";
ErrorMessage(msg.c_str());
return S_FALSE;
}
return S_OK;
}
HRESULT PropPage::GetIntValue(
HWND hWnd,
pfnGetValue GetValue,
int code,
const wchar_t* name)
{
int val;
assert(m_pVPX);
HRESULT hr = (m_pVPX->*GetValue)(&val);
if (FAILED(hr))
{
wstring text = L"Unable to get ";
text += name;
text += L" value from filter.";
ErrorMessage(text.c_str());
return hr;
}
wostringstream os;
if (val >= 0)
os << val;
const DWORD e = SetText(hWnd, code, os.str());
if (e == 0)
return S_OK;
wstring text = L"Unable to set value for ";
text += name;
text += L" edit control.";
ErrorMessage(text.c_str());
return E_FAIL;
}
HRESULT PropPage::GetDeadline(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetDeadline,
IDC_DEADLINE,
L"deadline");
}
HRESULT PropPage::SetDeadline()
{
return SetIntValue(
&IVP8Encoder::SetDeadline,
IDC_DEADLINE,
L"deadline");
}
HRESULT PropPage::GetThreadCount(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetThreadCount,
IDC_THREADCOUNT,
L"thread count");
}
HRESULT PropPage::SetThreadCount()
{
return SetIntValue(
&IVP8Encoder::SetThreadCount,
IDC_THREADCOUNT,
L"thread count");
}
HRESULT PropPage::SetErrorResilient()
{
return SetIntValue(
&IVP8Encoder::SetErrorResilient,
IDC_ERROR_RESILIENT,
L"error resilient");
}
HRESULT PropPage::GetErrorResilient(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetErrorResilient,
IDC_ERROR_RESILIENT,
L"error resilient");
}
HRESULT PropPage::SetDropframeThreshold()
{
return SetIntValue(
&IVP8Encoder::SetDropframeThreshold,
IDC_DROPFRAME_THRESHOLD,
L"dropframe threshold");
}
HRESULT PropPage::GetDropframeThreshold(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetDropframeThreshold,
IDC_DROPFRAME_THRESHOLD,
L"dropframe threshold");
}
HRESULT PropPage::SetResizeAllowed()
{
return SetIntValue(
&IVP8Encoder::SetResizeAllowed,
IDC_RESIZE_ALLOWED,
L"resize allowed");
}
HRESULT PropPage::GetResizeAllowed(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetResizeAllowed,
IDC_RESIZE_ALLOWED,
L"resize allowed");
}
HRESULT PropPage::SetResizeUpThreshold()
{
return SetIntValue(
&IVP8Encoder::SetResizeUpThreshold,
IDC_RESIZE_UP_THRESHOLD,
L"resize up threshold");
}
HRESULT PropPage::GetResizeUpThreshold(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetResizeUpThreshold,
IDC_RESIZE_UP_THRESHOLD,
L"resize up threshold");
}
HRESULT PropPage::SetResizeDownThreshold()
{
return SetIntValue(
&IVP8Encoder::SetResizeDownThreshold,
IDC_RESIZE_DOWN_THRESHOLD,
L"resize down threshold");
}
HRESULT PropPage::GetResizeDownThreshold(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetResizeDownThreshold,
IDC_RESIZE_DOWN_THRESHOLD,
L"resize down threshold");
}
HRESULT PropPage::GetEndUsage(HWND hWnd)
{
VP8EndUsage val;
assert(m_pVPX);
HRESULT hr = m_pVPX->GetEndUsage(&val);
if (FAILED(hr))
{
ErrorMessage(L"Unable to get end usage value from filter.");
return hr;
}
int idx;
switch (val)
{
case kEndUsageDefault:
default:
idx = 0;
break;
case kEndUsageVBR:
idx = 1;
break;
case kEndUsageCBR:
idx = 2;
break;
}
const HWND hCtrl = GetDlgItem(hWnd, IDC_END_USAGE);
assert(hCtrl);
const int result = ComboBox_SetCurSel(hCtrl, idx);
if (result >= 0)
return S_OK;
ErrorMessage(L"Unable to set value for end usage combo box.");
return S_OK;
}
HRESULT PropPage::SetEndUsage()
{
const HWND hCtrl = GetDlgItem(m_hWnd, IDC_END_USAGE);
assert(hCtrl);
const int idx = ComboBox_GetCurSel(hCtrl);
assert(idx >= 0);
assert(idx <= 2);
VP8EndUsage val;
switch (idx)
{
case 0:
default:
//val = kEndUsageDefault;
//break;
return S_OK;
case 1:
val = kEndUsageVBR;
break;
case 2:
val = kEndUsageCBR;
break;
}
assert(m_pVPX);
HRESULT hr = m_pVPX->SetEndUsage(val);
if (FAILED(hr))
{
ErrorMessage(L"Unable to set end usage value on filter.");
return S_FALSE;
}
return S_OK;
}
HRESULT PropPage::GetLagInFrames(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetLagInFrames,
IDC_LAG_IN_FRAMES,
L"lag in frames");
}
HRESULT PropPage::SetLagInFrames()
{
return SetIntValue(
&IVP8Encoder::SetLagInFrames,
IDC_LAG_IN_FRAMES,
L"lag in frames");
}
HRESULT PropPage::GetTokenPartitions(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetTokenPartitions,
IDC_TOKEN_PARTITIONS,
L"token partitions");
}
HRESULT PropPage::SetTokenPartitions()
{
return SetIntValue(
&IVP8Encoder::SetTokenPartitions,
IDC_TOKEN_PARTITIONS,
L"token partitions");
}
HRESULT PropPage::GetTargetBitrate(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetTargetBitrate,
IDC_TARGET_BITRATE,
L"target bitrate");
}
HRESULT PropPage::SetTargetBitrate()
{
return SetIntValue(
&IVP8Encoder::SetTargetBitrate,
IDC_TARGET_BITRATE,
L"target bitrate");
}
HRESULT PropPage::GetMinQuantizer(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetMinQuantizer,
IDC_MIN_QUANTIZER,
L"min quantizer");
}
HRESULT PropPage::SetMinQuantizer()
{
return SetIntValue(
&IVP8Encoder::SetMinQuantizer,
IDC_MIN_QUANTIZER,
L"min quantizer");
}
HRESULT PropPage::GetMaxQuantizer(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetMaxQuantizer,
IDC_MAX_QUANTIZER,
L"min quantizer");
}
HRESULT PropPage::SetMaxQuantizer()
{
return SetIntValue(
&IVP8Encoder::SetMaxQuantizer,
IDC_MAX_QUANTIZER,
L"max quantizer");
}
HRESULT PropPage::GetUndershootPct(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetUndershootPct,
IDC_UNDERSHOOT_PCT,
L"undershoot pct");
}
HRESULT PropPage::SetUndershootPct()
{
return SetIntValue(
&IVP8Encoder::SetUndershootPct,
IDC_UNDERSHOOT_PCT,
L"undershoot pct");
}
HRESULT PropPage::GetOvershootPct(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetOvershootPct,
IDC_OVERSHOOT_PCT,
L"overshoot pct");
}
HRESULT PropPage::SetOvershootPct()
{
return SetIntValue(
&IVP8Encoder::SetOvershootPct,
IDC_OVERSHOOT_PCT,
L"overshoot pct");
}
HRESULT PropPage::GetDecoderBufferSize(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetDecoderBufferSize,
IDC_DECODER_BUFFER_SIZE,
L"decoder buffer size");
}
HRESULT PropPage::SetDecoderBufferSize()
{
return SetIntValue(
&IVP8Encoder::SetDecoderBufferSize,
IDC_DECODER_BUFFER_SIZE,
L"decoder buffer size");
}
HRESULT PropPage::GetDecoderBufferInitialSize(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetDecoderBufferInitialSize,
IDC_DECODER_BUFFER_INITIAL_SIZE,
L"decoder buffer initial size");
}
HRESULT PropPage::SetDecoderBufferInitialSize()
{
return SetIntValue(
&IVP8Encoder::SetDecoderBufferInitialSize,
IDC_DECODER_BUFFER_INITIAL_SIZE,
L"decoder buffer initial size");
}
HRESULT PropPage::GetDecoderBufferOptimalSize(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetDecoderBufferOptimalSize,
IDC_DECODER_BUFFER_OPTIMAL_SIZE,
L"decoder buffer optimal size");
}
HRESULT PropPage::SetDecoderBufferOptimalSize()
{
return SetIntValue(
&IVP8Encoder::SetDecoderBufferOptimalSize,
IDC_DECODER_BUFFER_OPTIMAL_SIZE,
L"decoder buffer optimal size");
}
HRESULT PropPage::GetKeyframeMode(HWND hWnd)
{
VP8KeyframeMode val;
assert(m_pVPX);
HRESULT hr = m_pVPX->GetKeyframeMode(&val);
if (FAILED(hr))
{
ErrorMessage(L"Unable to get keyframe mode value from filter.");
return hr;
}
int idx;
switch (val)
{
case kKeyframeModeDefault:
default:
idx = 0;
break;
case kKeyframeModeDisabled:
idx = 1;
break;
case kKeyframeModeAuto:
idx = 2;
break;
}
const HWND hCtrl = GetDlgItem(hWnd, IDC_KEYFRAME_MODE);
assert(hCtrl);
const int result = ComboBox_SetCurSel(hCtrl, idx);
if (result >= 0)
return S_OK;
ErrorMessage(L"Unable to set value for keyframe mode combo box.");
return S_OK;
}
HRESULT PropPage::SetKeyframeMode()
{
const HWND hCtrl = GetDlgItem(m_hWnd, IDC_KEYFRAME_MODE);
assert(hCtrl);
const int idx = ComboBox_GetCurSel(hCtrl);
assert(idx >= 0);
assert(idx <= 2);
VP8KeyframeMode val;
switch (idx)
{
case 0:
default:
//val = kKeyframeModeDefault;
//break;
return S_OK;
case 1:
val = kKeyframeModeDisabled;
break;
case 2:
val = kKeyframeModeAuto;
break;
}
assert(m_pVPX);
HRESULT hr = m_pVPX->SetKeyframeMode(val);
if (FAILED(hr))
{
ErrorMessage(L"Unable to set keyframe mode on filter.");
return S_FALSE;
}
return S_OK;
}
HRESULT PropPage::GetKeyframeMinInterval(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetKeyframeMinInterval,
IDC_KEYFRAME_MIN_INTERVAL,
L"keyframe min interval");
}
HRESULT PropPage::SetKeyframeMinInterval()
{
return SetIntValue(
&IVP8Encoder::SetKeyframeMinInterval,
IDC_KEYFRAME_MIN_INTERVAL,
L"keyframe min interval");
}
HRESULT PropPage::GetKeyframeMaxInterval(HWND hWnd)
{
return GetIntValue(
hWnd,
&IVP8Encoder::GetKeyframeMaxInterval,
IDC_KEYFRAME_MAX_INTERVAL,
L"keyframe max interval");
}
HRESULT PropPage::SetKeyframeMaxInterval()
{
return SetIntValue(
&IVP8Encoder::SetKeyframeMaxInterval,
IDC_KEYFRAME_MAX_INTERVAL,
L"keyframe max interval");
}
HRESULT PropPage::GetEncoderKind(HWND hWnd)
{
VPXEncoderKind val;
assert(m_pVPX);
HRESULT hr = m_pVPX->GetEncoderKind(&val);
if (FAILED(hr))
{
ErrorMessage(L"Unable to get encoder kind value from filter.");
return hr;
}
int idx;
switch (val)
{
case kVP8Encoder:
default:
idx = 0;
break;
case kVP9Encoder:
idx = 1;
break;
}
const HWND hCtrl = GetDlgItem(hWnd, IDC_ENCODER_KIND);
assert(hCtrl);
const int result = ComboBox_SetCurSel(hCtrl, idx);
if (result >= 0)
return S_OK;
ErrorMessage(L"Unable to set value for encoder kind combo box.");
return S_OK;
}
HRESULT PropPage::SetEncoderKind()
{
const HWND hCtrl = GetDlgItem(m_hWnd, IDC_ENCODER_KIND);
assert(hCtrl);
const int idx = ComboBox_GetCurSel(hCtrl);
assert(idx >= 0);
assert(idx <= 1);
VPXEncoderKind val;
switch (idx)
{
case 0:
default:
val = kVP8Encoder;
break;
case 1:
val = kVP9Encoder;
break;
}
assert(m_pVPX);
HRESULT hr = m_pVPX->SetEncoderKind(val);
if (FAILED(hr))
{
ErrorMessage(L"Unable to set encoder kind value on filter.");
return S_FALSE;
}
return S_OK;
}
} //end namespace VP8EncoderLib
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_chromium_googlesource/webmdshow.git
git@gitee.com:mirrors_chromium_googlesource/webmdshow.git
mirrors_chromium_googlesource
webmdshow
webmdshow
main

搜索帮助