12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081 |
- #include <streams.h>
- #include <intsafe.h>
- #include <checkbmi.h>
- #define CheckConnected(pin,code) \
- { \
- if (pin == NULL) { \
- ASSERT(!TEXT("Pin not set")); \
- } else if (pin->IsConnected() == FALSE) { \
- return (code); \
- } \
- }
- BOOL WINAPI PossiblyEatMessage(HWND hwndDrain, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- if (hwndDrain != NULL && !InSendMessage())
- {
- switch (uMsg)
- {
- case WM_CHAR:
- case WM_DEADCHAR:
- case WM_KEYDOWN:
- case WM_KEYUP:
- case WM_LBUTTONDBLCLK:
- case WM_LBUTTONDOWN:
- case WM_LBUTTONUP:
- case WM_MBUTTONDBLCLK:
- case WM_MBUTTONDOWN:
- case WM_MBUTTONUP:
- case WM_MOUSEACTIVATE:
- case WM_MOUSEMOVE:
-
-
- case WM_NCLBUTTONDBLCLK:
- case WM_NCLBUTTONDOWN:
- case WM_NCLBUTTONUP:
- case WM_NCMBUTTONDBLCLK:
- case WM_NCMBUTTONDOWN:
- case WM_NCMBUTTONUP:
- case WM_NCMOUSEMOVE:
- case WM_NCRBUTTONDBLCLK:
- case WM_NCRBUTTONDOWN:
- case WM_NCRBUTTONUP:
- case WM_RBUTTONDBLCLK:
- case WM_RBUTTONDOWN:
- case WM_RBUTTONUP:
- case WM_SYSCHAR:
- case WM_SYSDEADCHAR:
- case WM_SYSKEYDOWN:
- case WM_SYSKEYUP:
- DbgLog((LOG_TRACE, 2, TEXT("Forwarding %x to drain")));
- PostMessage(hwndDrain, uMsg, wParam, lParam);
- return TRUE;
- }
- }
- return FALSE;
- }
- CBaseControlWindow::CBaseControlWindow(
- __inout CBaseFilter *pFilter,
- __in CCritSec *pInterfaceLock,
- __in_opt LPCTSTR pName,
- __inout_opt LPUNKNOWN pUnk,
- __inout HRESULT *phr) :
- CBaseVideoWindow(pName,pUnk),
- m_pInterfaceLock(pInterfaceLock),
- m_hwndOwner(NULL),
- m_hwndDrain(NULL),
- m_bAutoShow(TRUE),
- m_pFilter(pFilter),
- m_bCursorHidden(FALSE),
- m_pPin(NULL)
- {
- ASSERT(m_pFilter);
- ASSERT(m_pInterfaceLock);
- ASSERT(phr);
- m_BorderColour = VIDEO_COLOUR;
- }
- STDMETHODIMP CBaseControlWindow::put_Caption(__in BSTR strCaption)
- {
- CheckPointer((PVOID)strCaption,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- #ifdef UNICODE
- SetWindowText(m_hwnd, strCaption);
- #else
- CHAR Caption[CAPTION];
- WideCharToMultiByte(CP_ACP,0,strCaption,-1,Caption,CAPTION,NULL,NULL);
- SetWindowText(m_hwnd, Caption);
- #endif
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_Caption(__out BSTR *pstrCaption)
- {
- CheckPointer(pstrCaption,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- WCHAR WideCaption[CAPTION];
- #ifdef UNICODE
- GetWindowText(m_hwnd,WideCaption,CAPTION);
- #else
-
- TCHAR Caption[CAPTION];
- GetWindowText(m_hwnd,Caption,CAPTION);
- MultiByteToWideChar(CP_ACP,0,Caption,-1,WideCaption,CAPTION);
- #endif
- return WriteBSTR(pstrCaption,WideCaption);
- }
- STDMETHODIMP CBaseControlWindow::put_WindowStyleEx(long WindowStyleEx)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
-
- if (GetWindowLong(m_hwnd,GWL_EXSTYLE) & WS_EX_TOPMOST) {
- if ((WindowStyleEx & WS_EX_TOPMOST) == 0) {
- SendMessage(m_hwnd,m_ShowStageTop,(WPARAM) FALSE,(LPARAM) 0);
- }
- }
-
- if (WindowStyleEx & WS_EX_TOPMOST) {
- SendMessage(m_hwnd,m_ShowStageTop,(WPARAM) TRUE,(LPARAM) 0);
- WindowStyleEx &= (~WS_EX_TOPMOST);
- if (WindowStyleEx == 0) return NOERROR;
- }
- return DoSetWindowStyle(WindowStyleEx,GWL_EXSTYLE);
- }
- STDMETHODIMP CBaseControlWindow::get_WindowStyleEx(__out long *pWindowStyleEx)
- {
- CheckPointer(pWindowStyleEx,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- return DoGetWindowStyle(pWindowStyleEx,GWL_EXSTYLE);
- }
- STDMETHODIMP CBaseControlWindow::put_WindowStyle(long WindowStyle)
- {
-
- if ((WindowStyle & WS_DISABLED) ||
- (WindowStyle & WS_ICONIC) ||
- (WindowStyle & WS_MAXIMIZE) ||
- (WindowStyle & WS_MINIMIZE) ||
- (WindowStyle & WS_HSCROLL) ||
- (WindowStyle & WS_VSCROLL)) {
- return E_INVALIDARG;
- }
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- return DoSetWindowStyle(WindowStyle,GWL_STYLE);
- }
- STDMETHODIMP CBaseControlWindow::get_WindowStyle(__out long *pWindowStyle)
- {
- CheckPointer(pWindowStyle,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- return DoGetWindowStyle(pWindowStyle,GWL_STYLE);
- }
- HRESULT CBaseControlWindow::DoSetWindowStyle(long Style,long WindowLong)
- {
- RECT WindowRect;
-
- BOOL bVisible = IsWindowVisible(m_hwnd);
- EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
-
- SetWindowLong(m_hwnd,WindowLong,Style);
- UINT WindowFlags = SWP_SHOWWINDOW | SWP_FRAMECHANGED | SWP_NOACTIVATE;
- WindowFlags |= SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE;
-
- if (bVisible == TRUE) {
- SetWindowPos(m_hwnd,
- HWND_TOP,
- 0,0,0,0,
- WindowFlags);
- return NOERROR;
- }
-
- MoveWindow((HWND) m_hwnd,
- GetSystemMetrics(SM_CXSCREEN),
- GetSystemMetrics(SM_CYSCREEN),
- WIDTH(&WindowRect),
- HEIGHT(&WindowRect),
- TRUE);
-
- SetWindowPos(m_hwnd,
- HWND_TOP,
- 0,0,0,0,
- WindowFlags);
- ShowWindow(m_hwnd,SW_HIDE);
- if (GetParent(m_hwnd)) {
- MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
- }
- MoveWindow((HWND) m_hwnd,
- WindowRect.left,
- WindowRect.top,
- WIDTH(&WindowRect),
- HEIGHT(&WindowRect),
- TRUE);
- return NOERROR;
- }
- HRESULT CBaseControlWindow::DoGetWindowStyle(__out long *pStyle,long WindowLong)
- {
- *pStyle = GetWindowLong(m_hwnd,WindowLong);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::put_WindowState(long WindowState)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- DoShowWindow(WindowState);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_WindowState(__out long *pWindowState)
- {
- CheckPointer(pWindowState,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- ASSERT(pWindowState);
- *pWindowState = FALSE;
-
-
-
- if (IsWindowVisible(m_hwnd) == TRUE) {
-
- if (IsIconic(m_hwnd) == TRUE) {
- *pWindowState |= SW_MINIMIZE;
- }
-
- else if (IsZoomed(m_hwnd) == TRUE) {
- *pWindowState |= SW_MAXIMIZE;
- }
-
- else {
- *pWindowState |= SW_SHOW;
- }
- } else {
- *pWindowState |= SW_HIDE;
- }
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::put_BackgroundPalette(long BackgroundPalette)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cWindowLock(&m_WindowLock);
-
- if (BackgroundPalette != OATRUE) {
- if (BackgroundPalette != OAFALSE) {
- return E_INVALIDARG;
- }
- }
-
- m_bBackground = (BackgroundPalette == OATRUE ? TRUE : FALSE);
- PostMessage(m_hwnd,m_RealizePalette,0,0);
- PaintWindow(FALSE);
- return NOERROR;
- }
- STDMETHODIMP
- CBaseControlWindow::get_BackgroundPalette(__out long *pBackgroundPalette)
- {
- CheckPointer(pBackgroundPalette,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cWindowLock(&m_WindowLock);
-
- *pBackgroundPalette = (m_bBackground == TRUE ? OATRUE : OAFALSE);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::put_Visible(long Visible)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
-
- if (Visible != OATRUE) {
- if (Visible != OAFALSE) {
- return E_INVALIDARG;
- }
- }
-
- INT Mode = (Visible == OATRUE ? SW_SHOWNORMAL : SW_HIDE);
- DoShowWindow(Mode);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_Visible(__out long *pVisible)
- {
- CheckPointer(pVisible,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
-
-
-
- BOOL Mode = IsWindowVisible(m_hwnd);
- *pVisible = (Mode == TRUE ? OATRUE : OAFALSE);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::put_Left(long Left)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- BOOL bSuccess;
- RECT WindowRect;
-
- EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
- if (GetParent(m_hwnd)) {
- MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
- }
-
-
-
- WindowRect.bottom = WindowRect.bottom - WindowRect.top;
- WindowRect.right = WindowRect.right - WindowRect.left;
- UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
- bSuccess = SetWindowPos(m_hwnd,
- HWND_TOP,
- Left,
- WindowRect.top,
- WindowRect.right,
- WindowRect.bottom,
- WindowFlags);
- if (bSuccess == FALSE) {
- return E_INVALIDARG;
- }
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_Left(__out long *pLeft)
- {
- CheckPointer(pLeft,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- RECT WindowRect;
- EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
- *pLeft = WindowRect.left;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::put_Width(long Width)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- BOOL bSuccess;
- RECT WindowRect;
-
-
-
- EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
- if (GetParent(m_hwnd)) {
- MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
- }
- WindowRect.bottom = WindowRect.bottom - WindowRect.top;
- UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
-
-
-
- bSuccess = SetWindowPos(m_hwnd,
- HWND_TOP,
- WindowRect.left,
- WindowRect.top,
- Width,
- WindowRect.bottom,
- WindowFlags);
- if (bSuccess == FALSE) {
- return E_INVALIDARG;
- }
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_Width(__out long *pWidth)
- {
- CheckPointer(pWidth,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- RECT WindowRect;
- EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
- *pWidth = WindowRect.right - WindowRect.left;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::put_Top(long Top)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- BOOL bSuccess;
- RECT WindowRect;
-
- EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
- if (GetParent(m_hwnd)) {
- MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
- }
-
-
-
- WindowRect.bottom = WindowRect.bottom - WindowRect.top;
- WindowRect.right = WindowRect.right - WindowRect.left;
- UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
- bSuccess = SetWindowPos(m_hwnd,
- HWND_TOP,
- WindowRect.left,
- Top,
- WindowRect.right,
- WindowRect.bottom,
- WindowFlags);
- if (bSuccess == FALSE) {
- return E_INVALIDARG;
- }
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_Top(long *pTop)
- {
- CheckPointer(pTop,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- RECT WindowRect;
- EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
- *pTop = WindowRect.top;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::put_Height(long Height)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- BOOL bSuccess;
- RECT WindowRect;
-
-
-
- EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
- if (GetParent(m_hwnd)) {
- MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), (LPPOINT)&WindowRect, 2);
- }
- WindowRect.right = WindowRect.right - WindowRect.left;
- UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
- bSuccess = SetWindowPos(m_hwnd,
- HWND_TOP,
- WindowRect.left,
- WindowRect.top,
- WindowRect.right,
- Height,
- WindowFlags);
- if (bSuccess == FALSE) {
- return E_INVALIDARG;
- }
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_Height(__out long *pHeight)
- {
- CheckPointer(pHeight,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- RECT WindowRect;
- EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
- *pHeight = WindowRect.bottom - WindowRect.top;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::put_Owner(OAHWND Owner)
- {
-
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- m_hwndOwner = (HWND) Owner;
- HWND hwndParent = m_hwndOwner;
-
- LONG Style = GetWindowLong(m_hwnd,GWL_STYLE);
- if (Owner == NULL) {
- Style &= (~WS_CHILD);
- } else {
- Style |= (WS_CHILD);
- }
- SetWindowLong(m_hwnd,GWL_STYLE,Style);
-
- SetParent(m_hwnd,hwndParent);
- PaintWindow(TRUE);
- NOTE1("Changed parent %lx",hwndParent);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_Owner(__out OAHWND *Owner)
- {
- CheckPointer(Owner,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- *Owner = (OAHWND) m_hwndOwner;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::put_MessageDrain(OAHWND Drain)
- {
-
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- m_hwndDrain = (HWND) Drain;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_MessageDrain(__out OAHWND *Drain)
- {
- CheckPointer(Drain,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- *Drain = (OAHWND) m_hwndDrain;
- return NOERROR;
- }
- STDMETHODIMP
- CBaseControlWindow::NotifyOwnerMessage(OAHWND hwnd,
- long uMsg,
- LONG_PTR wParam,
- LONG_PTR lParam)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
-
- switch (uMsg) {
- case WM_SYSCOLORCHANGE:
- case WM_PALETTECHANGED:
- case WM_PALETTEISCHANGING:
- case WM_QUERYNEWPALETTE:
- case WM_DEVMODECHANGE:
- case WM_DISPLAYCHANGE:
- case WM_ACTIVATEAPP:
-
- if (m_hwndOwner == NULL) {
- return NOERROR;
- }
- SendMessage(m_hwnd,uMsg,(WPARAM)wParam,(LPARAM)lParam);
- break;
-
-
-
-
- case WM_MOVE:
- PostMessage(m_hwnd,WM_PAINT,0,0);
- break;
- }
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::SetWindowForeground(long Focus)
- {
-
- if (Focus != OATRUE) {
- if (Focus != OAFALSE) {
- return E_INVALIDARG;
- }
- }
-
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- BOOL bFocus = (Focus == OATRUE ? TRUE : FALSE);
- DoSetWindowForeground(bFocus);
- return NOERROR;
- }
- STDMETHODIMP
- CBaseControlWindow::SetWindowPosition(long Left,long Top,long Width,long Height)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- BOOL bSuccess;
-
- UINT WindowFlags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
- ASSERT(IsWindow(m_hwnd));
- bSuccess = SetWindowPos(m_hwnd,
- HWND_TOP,
- Left,
- Top,
- Width,
- Height,
- WindowFlags);
- ASSERT(bSuccess);
- #ifdef DEBUG
- DbgLog((LOG_TRACE, 1, TEXT("SWP failed error %d"), GetLastError()));
- #endif
- if (bSuccess == FALSE) {
- return E_INVALIDARG;
- }
- return NOERROR;
- }
- STDMETHODIMP
- CBaseControlWindow::GetWindowPosition(__out long *pLeft,__out long *pTop,__out long *pWidth,__out long *pHeight)
- {
-
- CheckPointer(pLeft,E_POINTER);
- CheckPointer(pTop,E_POINTER);
- CheckPointer(pWidth,E_POINTER);
- CheckPointer(pHeight,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- RECT WindowRect;
-
- EXECUTE_ASSERT(GetWindowRect(m_hwnd,&WindowRect));
-
- *pLeft = WindowRect.left;
- *pTop = WindowRect.top;
- *pWidth = WindowRect.right - WindowRect.left;
- *pHeight = WindowRect.bottom - WindowRect.top;
- return NOERROR;
- }
- STDMETHODIMP
- CBaseControlWindow::GetRestorePosition(__out long *pLeft,__out long *pTop,__out long *pWidth,__out long *pHeight)
- {
-
- CheckPointer(pLeft,E_POINTER);
- CheckPointer(pTop,E_POINTER);
- CheckPointer(pWidth,E_POINTER);
- CheckPointer(pHeight,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
-
- WINDOWPLACEMENT Place;
- Place.length = sizeof(WINDOWPLACEMENT);
- EXECUTE_ASSERT(GetWindowPlacement(m_hwnd,&Place));
- RECT WorkArea;
-
- if (SystemParametersInfo(SPI_GETWORKAREA,0,&WorkArea,FALSE) == TRUE) {
- if (GetParent(m_hwnd) == NULL) {
- Place.rcNormalPosition.top += WorkArea.top;
- Place.rcNormalPosition.bottom += WorkArea.top;
- Place.rcNormalPosition.left += WorkArea.left;
- Place.rcNormalPosition.right += WorkArea.left;
- }
- }
-
- *pLeft = Place.rcNormalPosition.left;
- *pTop = Place.rcNormalPosition.top;
- *pWidth = Place.rcNormalPosition.right - Place.rcNormalPosition.left;
- *pHeight = Place.rcNormalPosition.bottom - Place.rcNormalPosition.top;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_BorderColor(__out long *Color)
- {
- CheckPointer(Color,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- *Color = (long) m_BorderColour;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::put_BorderColor(long Color)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
-
- m_BorderColour = (COLORREF) Color;
- PaintWindow(TRUE);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_FullScreenMode(__out long *FullScreenMode)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CheckPointer(FullScreenMode,E_POINTER);
- return E_NOTIMPL;
- }
- STDMETHODIMP CBaseControlWindow::put_FullScreenMode(long FullScreenMode)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP CBaseControlWindow::put_AutoShow(long AutoShow)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
-
- if (AutoShow != OATRUE) {
- if (AutoShow != OAFALSE) {
- return E_INVALIDARG;
- }
- }
- m_bAutoShow = (AutoShow == OATRUE ? TRUE : FALSE);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::get_AutoShow(__out long *AutoShow)
- {
- CheckPointer(AutoShow,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- *AutoShow = (m_bAutoShow == TRUE ? OATRUE : OAFALSE);
- return NOERROR;
- }
- STDMETHODIMP
- CBaseControlWindow::GetMinIdealImageSize(__out long *pWidth,__out long *pHeight)
- {
- CheckPointer(pWidth,E_POINTER);
- CheckPointer(pHeight,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- FILTER_STATE State;
-
- m_pFilter->GetState(0,&State);
- if (State == State_Stopped) {
- return VFW_E_WRONG_STATE;
- }
- RECT DefaultRect = GetDefaultRect();
- *pWidth = WIDTH(&DefaultRect);
- *pHeight = HEIGHT(&DefaultRect);
- return NOERROR;
- }
- STDMETHODIMP
- CBaseControlWindow::GetMaxIdealImageSize(__out long *pWidth,__out long *pHeight)
- {
- CheckPointer(pWidth,E_POINTER);
- CheckPointer(pHeight,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- FILTER_STATE State;
-
- m_pFilter->GetState(0,&State);
- if (State == State_Stopped) {
- return VFW_E_WRONG_STATE;
- }
- RECT DefaultRect = GetDefaultRect();
- *pWidth = WIDTH(&DefaultRect);
- *pHeight = HEIGHT(&DefaultRect);
- return NOERROR;
- }
- STDMETHODIMP
- CBaseControlWindow::HideCursor(long HideCursor)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
-
- if (HideCursor != OATRUE) {
- if (HideCursor != OAFALSE) {
- return E_INVALIDARG;
- }
- }
- m_bCursorHidden = (HideCursor == OATRUE ? TRUE : FALSE);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlWindow::IsCursorHidden(__out long *CursorHidden)
- {
- CheckPointer(CursorHidden,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- *CursorHidden = (m_bCursorHidden == TRUE ? OATRUE : OAFALSE);
- return NOERROR;
- }
- CBaseControlVideo::CBaseControlVideo(
- __inout CBaseFilter *pFilter,
- __in CCritSec *pInterfaceLock,
- __in_opt LPCTSTR pName,
- __inout_opt LPUNKNOWN pUnk,
- __inout HRESULT *phr) :
- CBaseBasicVideo(pName,pUnk),
- m_pFilter(pFilter),
- m_pInterfaceLock(pInterfaceLock),
- m_pPin(NULL)
- {
- ASSERT(m_pFilter);
- ASSERT(m_pInterfaceLock);
- ASSERT(phr);
- }
- STDMETHODIMP CBaseControlVideo::get_AvgTimePerFrame(__out REFTIME *pAvgTimePerFrame)
- {
- CheckPointer(pAvgTimePerFrame,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
- if (pVideoInfo == NULL)
- return E_OUTOFMEMORY;
- COARefTime AvgTime(pVideoInfo->AvgTimePerFrame);
- *pAvgTimePerFrame = (REFTIME) AvgTime;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::get_BitRate(__out long *pBitRate)
- {
- CheckPointer(pBitRate,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
- if (pVideoInfo == NULL)
- return E_OUTOFMEMORY;
- *pBitRate = pVideoInfo->dwBitRate;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::get_BitErrorRate(__out long *pBitErrorRate)
- {
- CheckPointer(pBitErrorRate,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
- if (pVideoInfo == NULL)
- return E_OUTOFMEMORY;
- *pBitErrorRate = pVideoInfo->dwBitErrorRate;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::get_VideoWidth(__out long *pVideoWidth)
- {
- CheckPointer(pVideoWidth,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
- if (pVideoInfo == NULL)
- return E_OUTOFMEMORY;
- *pVideoWidth = pVideoInfo->bmiHeader.biWidth;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::get_VideoHeight(__out long *pVideoHeight)
- {
- CheckPointer(pVideoHeight,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
- if (pVideoInfo == NULL)
- return E_OUTOFMEMORY;
- *pVideoHeight = pVideoInfo->bmiHeader.biHeight;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::GetVideoPaletteEntries(long StartIndex,
- long Entries,
- __out long *pRetrieved,
- __out_ecount_part(Entries, *pRetrieved) long *pPalette)
- {
- CheckPointer(pRetrieved,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- CMediaType MediaType;
-
- VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
- if (pVideoInfo == NULL)
- return E_OUTOFMEMORY;
- BITMAPINFOHEADER *pHeader = HEADER(pVideoInfo);
-
- if (PALETTISED(pVideoInfo) == FALSE) {
- *pRetrieved = 0;
- return VFW_E_NO_PALETTE_AVAILABLE;
- }
-
- if (pPalette == NULL) {
- *pRetrieved = pHeader->biClrUsed;
- return NOERROR;
- }
-
- if (StartIndex >= (LONG) pHeader->biClrUsed || StartIndex < 0) {
- *pRetrieved = 0;
- return E_INVALIDARG;
- }
-
- LONG Available = (LONG) pHeader->biClrUsed - StartIndex;
- *pRetrieved = max(0,min(Available,Entries));
- if (*pRetrieved == 0) {
- return S_FALSE;
- }
-
- PALETTEENTRY *pEntries = (PALETTEENTRY *) pPalette;
- RGBQUAD *pColours = COLORS(pVideoInfo) + StartIndex;
- for (LONG Count = 0;Count < *pRetrieved;Count++) {
- pEntries[Count].peRed = pColours[Count].rgbRed;
- pEntries[Count].peGreen = pColours[Count].rgbGreen;
- pEntries[Count].peBlue = pColours[Count].rgbBlue;
- pEntries[Count].peFlags = 0;
- }
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::GetVideoSize(__out long *pWidth,__out long *pHeight)
- {
- CheckPointer(pWidth,E_POINTER);
- CheckPointer(pHeight,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
-
- VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
- if (pVideoInfo == NULL)
- return E_OUTOFMEMORY;
- *pWidth = pVideoInfo->bmiHeader.biWidth;
- *pHeight = pVideoInfo->bmiHeader.biHeight;
- return NOERROR;
- }
- STDMETHODIMP
- CBaseControlVideo::SetSourcePosition(long Left,long Top,long Width,long Height)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT SourceRect;
- SourceRect.left = Left;
- SourceRect.top = Top;
- SourceRect.right = Left + Width;
- SourceRect.bottom = Top + Height;
-
- HRESULT hr = CheckSourceRect(&SourceRect);
- if (FAILED(hr)) {
- return hr;
- }
-
- hr = SetSourceRect(&SourceRect);
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP
- CBaseControlVideo::GetSourcePosition(__out long *pLeft,__out long *pTop,__out long *pWidth,__out long *pHeight)
- {
-
- CheckPointer(pLeft,E_POINTER);
- CheckPointer(pTop,E_POINTER);
- CheckPointer(pWidth,E_POINTER);
- CheckPointer(pHeight,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- RECT SourceRect;
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- GetSourceRect(&SourceRect);
- *pLeft = SourceRect.left;
- *pTop = SourceRect.top;
- *pWidth = WIDTH(&SourceRect);
- *pHeight = HEIGHT(&SourceRect);
- return NOERROR;
- }
- STDMETHODIMP
- CBaseControlVideo::SetDestinationPosition(long Left,long Top,long Width,long Height)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT DestinationRect;
- DestinationRect.left = Left;
- DestinationRect.top = Top;
- DestinationRect.right = Left + Width;
- DestinationRect.bottom = Top + Height;
-
- HRESULT hr = CheckTargetRect(&DestinationRect);
- if (FAILED(hr)) {
- return hr;
- }
-
- hr = SetTargetRect(&DestinationRect);
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP
- CBaseControlVideo::GetDestinationPosition(__out long *pLeft,__out long *pTop,__out long *pWidth,__out long *pHeight)
- {
-
- CheckPointer(pLeft,E_POINTER);
- CheckPointer(pTop,E_POINTER);
- CheckPointer(pWidth,E_POINTER);
- CheckPointer(pHeight,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- RECT DestinationRect;
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- GetTargetRect(&DestinationRect);
- *pLeft = DestinationRect.left;
- *pTop = DestinationRect.top;
- *pWidth = WIDTH(&DestinationRect);
- *pHeight = HEIGHT(&DestinationRect);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::put_SourceLeft(long SourceLeft)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT SourceRect;
- GetSourceRect(&SourceRect);
- SourceRect.right = SourceLeft + WIDTH(&SourceRect);
- SourceRect.left = SourceLeft;
-
- HRESULT hr = CheckSourceRect(&SourceRect);
- if (FAILED(hr)) {
- return hr;
- }
-
- hr = SetSourceRect(&SourceRect);
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP CBaseControlVideo::get_SourceLeft(__out long *pSourceLeft)
- {
- CheckPointer(pSourceLeft,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT SourceRect;
- GetSourceRect(&SourceRect);
- *pSourceLeft = SourceRect.left;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::put_SourceWidth(long SourceWidth)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT SourceRect;
- GetSourceRect(&SourceRect);
- SourceRect.right = SourceRect.left + SourceWidth;
-
- HRESULT hr = CheckSourceRect(&SourceRect);
- if (FAILED(hr)) {
- return hr;
- }
-
- hr = SetSourceRect(&SourceRect);
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP CBaseControlVideo::get_SourceWidth(__out long *pSourceWidth)
- {
- CheckPointer(pSourceWidth,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT SourceRect;
- GetSourceRect(&SourceRect);
- *pSourceWidth = WIDTH(&SourceRect);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::put_SourceTop(long SourceTop)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT SourceRect;
- GetSourceRect(&SourceRect);
- SourceRect.bottom = SourceTop + HEIGHT(&SourceRect);
- SourceRect.top = SourceTop;
-
- HRESULT hr = CheckSourceRect(&SourceRect);
- if (FAILED(hr)) {
- return hr;
- }
-
- hr = SetSourceRect(&SourceRect);
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP CBaseControlVideo::get_SourceTop(__out long *pSourceTop)
- {
- CheckPointer(pSourceTop,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT SourceRect;
- GetSourceRect(&SourceRect);
- *pSourceTop = SourceRect.top;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::put_SourceHeight(long SourceHeight)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT SourceRect;
- GetSourceRect(&SourceRect);
- SourceRect.bottom = SourceRect.top + SourceHeight;
-
- HRESULT hr = CheckSourceRect(&SourceRect);
- if (FAILED(hr)) {
- return hr;
- }
-
- hr = SetSourceRect(&SourceRect);
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP CBaseControlVideo::get_SourceHeight(__out long *pSourceHeight)
- {
- CheckPointer(pSourceHeight,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT SourceRect;
- GetSourceRect(&SourceRect);
- *pSourceHeight = HEIGHT(&SourceRect);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::put_DestinationLeft(long DestinationLeft)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT DestinationRect;
- GetTargetRect(&DestinationRect);
- DestinationRect.right = DestinationLeft + WIDTH(&DestinationRect);
- DestinationRect.left = DestinationLeft;
-
- HRESULT hr = CheckTargetRect(&DestinationRect);
- if (FAILED(hr)) {
- return hr;
- }
-
- hr = SetTargetRect(&DestinationRect);
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP CBaseControlVideo::get_DestinationLeft(__out long *pDestinationLeft)
- {
- CheckPointer(pDestinationLeft,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT DestinationRect;
- GetTargetRect(&DestinationRect);
- *pDestinationLeft = DestinationRect.left;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::put_DestinationWidth(long DestinationWidth)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT DestinationRect;
- GetTargetRect(&DestinationRect);
- DestinationRect.right = DestinationRect.left + DestinationWidth;
-
- HRESULT hr = CheckTargetRect(&DestinationRect);
- if (FAILED(hr)) {
- return hr;
- }
-
- hr = SetTargetRect(&DestinationRect);
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP CBaseControlVideo::get_DestinationWidth(__out long *pDestinationWidth)
- {
- CheckPointer(pDestinationWidth,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT DestinationRect;
- GetTargetRect(&DestinationRect);
- *pDestinationWidth = WIDTH(&DestinationRect);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::put_DestinationTop(long DestinationTop)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT DestinationRect;
- GetTargetRect(&DestinationRect);
- DestinationRect.bottom = DestinationTop + HEIGHT(&DestinationRect);
- DestinationRect.top = DestinationTop;
-
- HRESULT hr = CheckTargetRect(&DestinationRect);
- if (FAILED(hr)) {
- return hr;
- }
-
- hr = SetTargetRect(&DestinationRect);
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP CBaseControlVideo::get_DestinationTop(__out long *pDestinationTop)
- {
- CheckPointer(pDestinationTop,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT DestinationRect;
- GetTargetRect(&DestinationRect);
- *pDestinationTop = DestinationRect.top;
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::put_DestinationHeight(long DestinationHeight)
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT DestinationRect;
- GetTargetRect(&DestinationRect);
- DestinationRect.bottom = DestinationRect.top + DestinationHeight;
-
- HRESULT hr = CheckTargetRect(&DestinationRect);
- if (FAILED(hr)) {
- return hr;
- }
-
- hr = SetTargetRect(&DestinationRect);
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP CBaseControlVideo::get_DestinationHeight(__out long *pDestinationHeight)
- {
- CheckPointer(pDestinationHeight,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- RECT DestinationRect;
- GetTargetRect(&DestinationRect);
- *pDestinationHeight = HEIGHT(&DestinationRect);
- return NOERROR;
- }
- STDMETHODIMP CBaseControlVideo::SetDefaultSourcePosition()
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- HRESULT hr = SetDefaultSourceRect();
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP CBaseControlVideo::IsUsingDefaultSource()
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- return IsDefaultSourceRect();
- }
- STDMETHODIMP CBaseControlVideo::SetDefaultDestinationPosition()
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- HRESULT hr = SetDefaultTargetRect();
- if (FAILED(hr)) {
- return hr;
- }
- return OnUpdateRectangles();
- }
- STDMETHODIMP CBaseControlVideo::IsUsingDefaultDestination()
- {
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- return IsDefaultTargetRect();
- }
- STDMETHODIMP
- CBaseControlVideo::GetCurrentImage(__inout long *pBufferSize,__out_bcount_part(*pBufferSize, *pBufferSize) long *pVideoImage)
- {
- CheckPointer(pBufferSize,E_POINTER);
- CheckConnected(m_pPin,VFW_E_NOT_CONNECTED);
- CAutoLock cInterfaceLock(m_pInterfaceLock);
- FILTER_STATE State;
-
- if (pVideoImage != NULL) {
- m_pFilter->GetState(0,&State);
- if (State != State_Paused) {
- return VFW_E_NOT_PAUSED;
- }
- return GetStaticImage(pBufferSize,pVideoImage);
- }
-
- VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
- if (pVideoInfo == NULL)
- return E_OUTOFMEMORY;
- RECT SourceRect;
- GetSourceRect(&SourceRect);
- return GetImageSize(pVideoInfo,pBufferSize,&SourceRect);
- }
- HRESULT CBaseControlVideo::GetImageSize(__in VIDEOINFOHEADER *pVideoInfo,
- __out long *pBufferSize,
- __in RECT *pSourceRect)
- {
- NOTE("Entering GetImageSize");
- ASSERT(pSourceRect);
-
- if (pSourceRect == NULL ||
- pVideoInfo == NULL ||
- pBufferSize == NULL) {
- return E_UNEXPECTED;
- }
-
- if (pVideoInfo->bmiHeader.biCompression != BI_RGB) {
- if (pVideoInfo->bmiHeader.biCompression != BI_BITFIELDS) {
- return E_INVALIDARG;
- }
- }
- ASSERT(IsRectEmpty(pSourceRect) == FALSE);
- BITMAPINFOHEADER bih;
- bih.biWidth = WIDTH(pSourceRect);
- bih.biHeight = HEIGHT(pSourceRect);
- bih.biBitCount = pVideoInfo->bmiHeader.biBitCount;
- LONG Size = DIBSIZE(bih);
- Size += GetBitmapFormatSize(HEADER(pVideoInfo)) - SIZE_PREHEADER;
- *pBufferSize = Size;
- return NOERROR;
- }
- HRESULT CBaseControlVideo::CopyImage(IMediaSample *pMediaSample,
- __in VIDEOINFOHEADER *pVideoInfo,
- __inout long *pBufferSize,
- __out_bcount_part(*pBufferSize, *pBufferSize) BYTE *pVideoImage,
- __in RECT *pSourceRect)
- {
- NOTE("Entering CopyImage");
- ASSERT(pSourceRect);
- BYTE *pCurrentImage;
-
- if (pMediaSample == NULL || pSourceRect == NULL ||
- pVideoInfo == NULL || pVideoImage == NULL ||
- pBufferSize == NULL) {
- return E_UNEXPECTED;
- }
-
- if (pVideoInfo->bmiHeader.biCompression != BI_RGB) {
- if (pVideoInfo->bmiHeader.biCompression != BI_BITFIELDS) {
- return E_INVALIDARG;
- }
- }
- if (*pBufferSize < 0) {
- return E_INVALIDARG;
- }
-
- if (pVideoInfo->bmiHeader.biSize > 4096)
- {
- return E_INVALIDARG;
- }
- ASSERT(IsRectEmpty(pSourceRect) == FALSE);
- BITMAPINFOHEADER bih;
- bih.biWidth = WIDTH(pSourceRect);
- bih.biHeight = HEIGHT(pSourceRect);
- bih.biBitCount = pVideoInfo->bmiHeader.biBitCount;
- DWORD Size = GetBitmapFormatSize(HEADER(pVideoInfo)) - SIZE_PREHEADER;
- DWORD Total;
- DWORD dwDibSize;
- if( !ValidateBitmapInfoHeader( HEADER(pVideoInfo), Size)) {
- return E_INVALIDARG;
- }
-
-
- __analysis_assume(Size >= sizeof(BITMAPINFOHEADER));
- if (FAILED(SAFE_DIBSIZE(&bih, &dwDibSize))) {
- return E_INVALIDARG;
- }
- if (FAILED(DWordAdd(Size, dwDibSize, &Total))) {
- return E_INVALIDARG;
- }
-
- if ((DWORD)*pBufferSize < Total) {
- return E_OUTOFMEMORY;
- }
-
- CopyMemory((PVOID)pVideoImage, (PVOID)&pVideoInfo->bmiHeader, Size);
- ((BITMAPINFOHEADER *)pVideoImage)->biWidth = WIDTH(pSourceRect);
- ((BITMAPINFOHEADER *)pVideoImage)->biHeight = HEIGHT(pSourceRect);
- ((BITMAPINFOHEADER *)pVideoImage)->biSizeImage = DIBSIZE(bih);
- BYTE *pImageData = pVideoImage + Size;
-
- HRESULT hr = pMediaSample->GetPointer(&pCurrentImage);
- if (FAILED(hr)) {
- return hr;
- }
-
- LONG ScanLine = (pVideoInfo->bmiHeader.biBitCount / 8) * WIDTH(pSourceRect);
- LONG LinesToSkip = pVideoInfo->bmiHeader.biHeight;
- LinesToSkip -= pSourceRect->top + HEIGHT(pSourceRect);
- pCurrentImage += LinesToSkip * DIBWIDTHBYTES(pVideoInfo->bmiHeader);
- pCurrentImage += pSourceRect->left * (pVideoInfo->bmiHeader.biBitCount / 8);
-
- for (LONG Line = 0;Line < HEIGHT(pSourceRect);Line++) {
- CopyMemory((PVOID)pImageData, (PVOID)pCurrentImage, ScanLine);
- pImageData += DIBWIDTHBYTES(*(BITMAPINFOHEADER *)pVideoImage);
- pCurrentImage += DIBWIDTHBYTES(pVideoInfo->bmiHeader);
- }
- return NOERROR;
- }
- HRESULT CBaseControlVideo::OnVideoSizeChange()
- {
-
- VIDEOINFOHEADER *pVideoInfo = GetVideoFormat();
- if (pVideoInfo == NULL)
- return E_OUTOFMEMORY;
- WORD Width = (WORD) pVideoInfo->bmiHeader.biWidth;
- WORD Height = (WORD) pVideoInfo->bmiHeader.biHeight;
- return m_pFilter->NotifyEvent(EC_VIDEO_SIZE_CHANGED,
- MAKELPARAM(Width,Height),
- MAKEWPARAM(0,0));
- }
- HRESULT CBaseControlVideo::CheckSourceRect(__in RECT *pSourceRect)
- {
- CheckPointer(pSourceRect,E_POINTER);
- LONG Width,Height;
- GetVideoSize(&Width,&Height);
-
-
- if ((pSourceRect->left >= pSourceRect->right) ||
- (pSourceRect->left < 0) ||
- (pSourceRect->top >= pSourceRect->bottom) ||
- (pSourceRect->top < 0)) {
- return E_INVALIDARG;
- }
-
- if ((pSourceRect->right > Width) ||
- (pSourceRect->bottom > Height)) {
- return E_INVALIDARG;
- }
- return NOERROR;
- }
- HRESULT CBaseControlVideo::CheckTargetRect(__in RECT *pTargetRect)
- {
-
- if (pTargetRect == NULL) {
- return E_POINTER;
- }
-
- if (pTargetRect->left > pTargetRect->right ||
- pTargetRect->top > pTargetRect->bottom) {
- return E_INVALIDARG;
- }
-
- if (WIDTH(pTargetRect) <= 0 || HEIGHT(pTargetRect) <= 0) {
- return E_INVALIDARG;
- }
- ASSERT(IsRectEmpty(pTargetRect) == FALSE);
- return NOERROR;
- }
|