1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474 |
- #include <streams.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <dvdmedia.h>
- #ifdef DEBUG
- #ifdef UNICODE
- #ifndef _UNICODE
- #define _UNICODE
- #endif
- #endif
- #endif
- #include <tchar.h>
- #include <strsafe.h>
- #ifdef DEBUG
- static void DisplayBITMAPINFO(const BITMAPINFOHEADER* pbmi);
- static void DisplayRECT(LPCTSTR szLabel, const RECT& rc);
- const INT iDEBUGINFO = 1024;
- const LPCTSTR pKeyNames[] = {
- TEXT("TIMING"),
- TEXT("TRACE"),
- TEXT("MEMORY"),
- TEXT("LOCKING"),
- TEXT("ERROR"),
- TEXT("CUSTOM1"),
- TEXT("CUSTOM2"),
- TEXT("CUSTOM3"),
- TEXT("CUSTOM4"),
- TEXT("CUSTOM5")
- };
- const TCHAR CAutoTrace::_szEntering[] = TEXT("->: %s");
- const TCHAR CAutoTrace::_szLeaving[] = TEXT("<-: %s");
- const INT iMAXLEVELS = NUMELMS(pKeyNames);
- HINSTANCE m_hInst;
- TCHAR m_ModuleName[iDEBUGINFO];
- DWORD m_Levels[iMAXLEVELS];
- CRITICAL_SECTION m_CSDebug;
- DWORD m_dwNextCookie;
- ObjectDesc *pListHead = NULL;
- DWORD m_dwObjectCount;
- BOOL m_bInit = FALSE;
- HANDLE m_hOutput = INVALID_HANDLE_VALUE;
- DWORD dwWaitTimeout = INFINITE;
- DWORD dwTimeOffset;
- bool g_fUseKASSERT = false;
- bool g_fDbgInDllEntryPoint = false;
- bool g_fAutoRefreshLevels = false;
- LPCTSTR pBaseKey = TEXT("SOFTWARE\\Microsoft\\DirectShow\\Debug");
- LPCTSTR pGlobalKey = TEXT("GLOBAL");
- static CHAR *pUnknownName = "UNKNOWN";
- LPCTSTR TimeoutName = TEXT("TIMEOUT");
- void WINAPI DbgInitialise(HINSTANCE hInst)
- {
- InitializeCriticalSection(&m_CSDebug);
- m_bInit = TRUE;
- m_hInst = hInst;
- DbgInitModuleName();
- if (GetProfileInt(m_ModuleName, TEXT("BreakOnLoad"), 0))
- DebugBreak();
- DbgInitModuleSettings(false);
- DbgInitGlobalSettings(true);
- dwTimeOffset = timeGetTime();
- }
- void WINAPI DbgTerminate()
- {
- if (m_hOutput != INVALID_HANDLE_VALUE) {
- EXECUTE_ASSERT(CloseHandle(m_hOutput));
- m_hOutput = INVALID_HANDLE_VALUE;
- }
- DeleteCriticalSection(&m_CSDebug);
- m_bInit = FALSE;
- }
- void WINAPI DbgInitKeyLevels(HKEY hKey, bool fTakeMax)
- {
- LONG lReturn;
- LONG lKeyPos;
- DWORD dwKeySize;
- DWORD dwKeyType;
- DWORD dwKeyValue;
-
- for (lKeyPos = 0;lKeyPos < iMAXLEVELS;lKeyPos++) {
- dwKeySize = sizeof(DWORD);
- lReturn = RegQueryValueEx(
- hKey,
- pKeyNames[lKeyPos],
- NULL,
- &dwKeyType,
- (LPBYTE) &dwKeyValue,
- &dwKeySize );
-
- if (lReturn != ERROR_SUCCESS || dwKeyType != REG_DWORD) {
- dwKeyValue = 0;
- lReturn = RegSetValueEx(
- hKey,
- pKeyNames[lKeyPos],
- (DWORD) 0,
- REG_DWORD,
- (PBYTE) &dwKeyValue,
- sizeof(DWORD));
- if (lReturn != ERROR_SUCCESS) {
- DbgLog((LOG_ERROR,1,TEXT("Could not create subkey %s"),pKeyNames[lKeyPos]));
- dwKeyValue = 0;
- }
- }
- if(fTakeMax)
- {
- m_Levels[lKeyPos] = max(dwKeyValue,m_Levels[lKeyPos]);
- }
- else
- {
- if((m_Levels[lKeyPos] & LOG_FORCIBLY_SET) == 0) {
- m_Levels[lKeyPos] = dwKeyValue;
- }
- }
- }
-
- dwKeySize = sizeof(DWORD);
- lReturn = RegQueryValueEx(
- hKey,
- TimeoutName,
- NULL,
- &dwKeyType,
- (LPBYTE) &dwWaitTimeout,
- &dwKeySize );
-
- if (lReturn != ERROR_SUCCESS || dwKeyType != REG_DWORD) {
- dwWaitTimeout = INFINITE;
- lReturn = RegSetValueEx(
- hKey,
- TimeoutName,
- (DWORD) 0,
- REG_DWORD,
- (PBYTE) &dwWaitTimeout,
- sizeof(DWORD));
- if (lReturn != ERROR_SUCCESS) {
- DbgLog((LOG_ERROR,1,TEXT("Could not create subkey %s"),pKeyNames[lKeyPos]));
- dwWaitTimeout = INFINITE;
- }
- }
- }
- void WINAPI DbgOutString(LPCTSTR psz)
- {
- if (m_hOutput != INVALID_HANDLE_VALUE) {
- UINT cb = lstrlen(psz);
- DWORD dw;
- #ifdef UNICODE
- CHAR szDest[2048];
- WideCharToMultiByte(CP_ACP, 0, psz, -1, szDest, NUMELMS(szDest), 0, 0);
- WriteFile (m_hOutput, szDest, cb, &dw, NULL);
- #else
- WriteFile (m_hOutput, psz, cb, &dw, NULL);
- #endif
- } else {
- OutputDebugString (psz);
- }
- }
- HRESULT DbgUniqueProcessName(LPCTSTR inName, LPTSTR outName)
- {
- HRESULT hr = S_OK;
- const TCHAR *pIn = inName;
- int dotPos = -1;
-
- while (*pIn && (pIn - inName) < MAX_PATH)
- {
- if ( TEXT('.') == *pIn )
- dotPos = (int)(pIn-inName);
- ++pIn;
- }
- if (*pIn)
- return E_INVALIDARG;
- DWORD dwProcessId = GetCurrentProcessId();
- if (dotPos < 0)
- {
-
- hr = StringCchPrintf(outName, MAX_PATH, TEXT("%s_%d"), inName, dwProcessId);
- }
- else
- {
- TCHAR pathAndBasename[MAX_PATH] = {0};
-
-
- hr = StringCchCopyN(pathAndBasename, MAX_PATH, inName, (size_t)dotPos);
-
- if (SUCCEEDED(hr))
- hr = StringCchPrintf(outName, MAX_PATH, TEXT("%s_%d%s"), pathAndBasename, dwProcessId, inName + dotPos);
- }
- return hr;
- }
- void WINAPI DbgInitLogTo (
- HKEY hKey)
- {
- LONG lReturn;
- DWORD dwKeyType;
- DWORD dwKeySize;
- TCHAR szFile[MAX_PATH] = {0};
- static const TCHAR cszKey[] = TEXT("LogToFile");
- dwKeySize = MAX_PATH;
- lReturn = RegQueryValueEx(
- hKey,
- cszKey,
- NULL,
- &dwKeyType,
- (LPBYTE) szFile,
- &dwKeySize);
-
-
- if (lReturn != ERROR_SUCCESS || dwKeyType != REG_SZ)
- {
- dwKeySize = sizeof(TCHAR);
- lReturn = RegSetValueEx(
- hKey,
- cszKey,
- (DWORD) 0,
- REG_SZ,
- (PBYTE)szFile,
- dwKeySize);
- }
-
-
- if (m_hOutput != INVALID_HANDLE_VALUE) {
- EXECUTE_ASSERT(CloseHandle (m_hOutput));
- m_hOutput = INVALID_HANDLE_VALUE;
- }
- if (szFile[0] != 0)
- {
- if (!lstrcmpi(szFile, TEXT("Console"))) {
- m_hOutput = GetStdHandle (STD_OUTPUT_HANDLE);
- if (m_hOutput == INVALID_HANDLE_VALUE) {
- AllocConsole ();
- m_hOutput = GetStdHandle (STD_OUTPUT_HANDLE);
- }
- SetConsoleTitle (TEXT("ActiveX Debug Output"));
- } else if (szFile[0] &&
- lstrcmpi(szFile, TEXT("Debug")) &&
- lstrcmpi(szFile, TEXT("Debugger")) &&
- lstrcmpi(szFile, TEXT("Deb")))
- {
- m_hOutput = CreateFile(szFile, GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL, OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- if (INVALID_HANDLE_VALUE == m_hOutput &&
- GetLastError() == ERROR_SHARING_VIOLATION)
- {
- TCHAR uniqueName[MAX_PATH] = {0};
- if (SUCCEEDED(DbgUniqueProcessName(szFile, uniqueName)))
- {
- m_hOutput = CreateFile(uniqueName, GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL, OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- }
- }
-
- if (INVALID_HANDLE_VALUE != m_hOutput)
- {
- static const TCHAR cszBar[] = TEXT("\r\n\r\n=====DbgInitialize()=====\r\n\r\n");
- SetFilePointer (m_hOutput, 0, NULL, FILE_END);
- DbgOutString (cszBar);
- }
- }
- }
- }
- void WINAPI DbgInitGlobalSettings(bool fTakeMax)
- {
- LONG lReturn;
- TCHAR szInfo[iDEBUGINFO];
- HKEY hGlobalKey;
-
- (void)StringCchPrintf(szInfo,NUMELMS(szInfo),TEXT("%s\\%s"),pBaseKey,pGlobalKey);
-
- lReturn = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
- szInfo,
- (DWORD) 0,
- NULL,
- (DWORD) 0,
- GENERIC_READ | GENERIC_WRITE,
- NULL,
- &hGlobalKey,
- NULL);
- if (lReturn != ERROR_SUCCESS) {
- lReturn = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
- szInfo,
- (DWORD) 0,
- NULL,
- (DWORD) 0,
- GENERIC_READ,
- NULL,
- &hGlobalKey,
- NULL);
- if (lReturn != ERROR_SUCCESS) {
- DbgLog((LOG_ERROR,1,TEXT("Could not access GLOBAL module key")));
- }
- return;
- }
- DbgInitKeyLevels(hGlobalKey, fTakeMax);
- RegCloseKey(hGlobalKey);
- }
- void WINAPI DbgInitModuleSettings(bool fTakeMax)
- {
- LONG lReturn;
- TCHAR szInfo[iDEBUGINFO];
- HKEY hModuleKey;
-
- (void)StringCchPrintf(szInfo,NUMELMS(szInfo),TEXT("%s\\%s"),pBaseKey,m_ModuleName);
-
- lReturn = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
- szInfo,
- (DWORD) 0,
- NULL,
- (DWORD) 0,
- GENERIC_READ | GENERIC_WRITE,
- NULL,
- &hModuleKey,
- NULL);
- if (lReturn != ERROR_SUCCESS) {
- lReturn = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
- szInfo,
- (DWORD) 0,
- NULL,
- (DWORD) 0,
- GENERIC_READ,
- NULL,
- &hModuleKey,
- NULL);
- if (lReturn != ERROR_SUCCESS) {
- DbgLog((LOG_ERROR,1,TEXT("Could not access module key")));
- }
- return;
- }
- DbgInitLogTo(hModuleKey);
- DbgInitKeyLevels(hModuleKey, fTakeMax);
- RegCloseKey(hModuleKey);
- }
- void WINAPI DbgInitModuleName()
- {
- TCHAR FullName[iDEBUGINFO];
- LPTSTR pName;
- GetModuleFileName(m_hInst,FullName,iDEBUGINFO);
- pName = _tcsrchr(FullName,'\\');
- if (pName == NULL) {
- pName = FullName;
- } else {
- pName++;
- }
- (void)StringCchCopy(m_ModuleName,NUMELMS(m_ModuleName), pName);
- }
- struct MsgBoxMsg
- {
- HWND hwnd;
- LPCTSTR szTitle;
- LPCTSTR szMessage;
- DWORD dwFlags;
- INT iResult;
- };
- DWORD WINAPI MsgBoxThread(
- __inout LPVOID lpParameter
- )
- {
- MsgBoxMsg *pmsg = (MsgBoxMsg *)lpParameter;
- pmsg->iResult = MessageBox(
- pmsg->hwnd,
- pmsg->szTitle,
- pmsg->szMessage,
- pmsg->dwFlags);
- return 0;
- }
- INT MessageBoxOtherThread(
- HWND hwnd,
- LPCTSTR szTitle,
- LPCTSTR szMessage,
- DWORD dwFlags)
- {
- if(g_fDbgInDllEntryPoint)
- {
-
-
-
-
- return IDCANCEL;
- }
- else
- {
- MsgBoxMsg msg = {hwnd, szTitle, szMessage, dwFlags, 0};
- DWORD dwid;
- HANDLE hThread = CreateThread(
- 0,
- 0,
- MsgBoxThread,
- (void *)&msg,
- 0,
- &dwid);
- if(hThread)
- {
- WaitForSingleObject(hThread, INFINITE);
- CloseHandle(hThread);
- return msg.iResult;
- }
-
- return IDCANCEL;
- }
- }
- void WINAPI DbgAssert(LPCTSTR pCondition,LPCTSTR pFileName,INT iLine)
- {
- if(g_fUseKASSERT)
- {
- DbgKernelAssert(pCondition, pFileName, iLine);
- }
- else
- {
- TCHAR szInfo[iDEBUGINFO];
- (void)StringCchPrintf(szInfo, NUMELMS(szInfo),TEXT("%s \nAt line %d of %s\nContinue? (Cancel to debug)"),
- pCondition, iLine, pFileName);
- INT MsgId = MessageBoxOtherThread(NULL,szInfo,TEXT("ASSERT Failed"),
- MB_SYSTEMMODAL |
- MB_ICONHAND |
- MB_YESNOCANCEL |
- MB_SETFOREGROUND);
- switch (MsgId)
- {
- case IDNO:
- FatalAppExit(FALSE, TEXT("Application terminated"));
- break;
- case IDCANCEL:
- DebugBreak();
- break;
- case IDYES:
- break;
- }
- }
- }
- void WINAPI DbgBreakPoint(LPCTSTR pCondition,LPCTSTR pFileName,INT iLine)
- {
- if(g_fUseKASSERT)
- {
- DbgKernelAssert(pCondition, pFileName, iLine);
- }
- else
- {
- TCHAR szInfo[iDEBUGINFO];
- (void)StringCchPrintf(szInfo, NUMELMS(szInfo),TEXT("%s \nAt line %d of %s\nContinue? (Cancel to debug)"),
- pCondition, iLine, pFileName);
- INT MsgId = MessageBoxOtherThread(NULL,szInfo,TEXT("Hard coded break point"),
- MB_SYSTEMMODAL |
- MB_ICONHAND |
- MB_YESNOCANCEL |
- MB_SETFOREGROUND);
- switch (MsgId)
- {
- case IDNO:
- FatalAppExit(FALSE, TEXT("Application terminated"));
- break;
- case IDCANCEL:
- DebugBreak();
- break;
- case IDYES:
- break;
- }
- }
- }
- void WINAPI DbgBreakPoint(LPCTSTR pFileName,INT iLine,__format_string LPCTSTR szFormatString,...)
- {
-
-
-
-
-
- const DWORD MAX_BREAK_POINT_MESSAGE_SIZE = 2000;
- TCHAR szBreakPointMessage[MAX_BREAK_POINT_MESSAGE_SIZE];
- va_list va;
- va_start( va, szFormatString );
- HRESULT hr = StringCchVPrintf( szBreakPointMessage, NUMELMS(szBreakPointMessage), szFormatString, va );
- va_end(va);
- if( FAILED(hr) ) {
- DbgBreak( "ERROR in DbgBreakPoint(). The variable length debug message could not be displayed because StringCchVPrintf() failed." );
- return;
- }
- ::DbgBreakPoint( szBreakPointMessage, pFileName, iLine );
- }
- BOOL WINAPI DbgCheckModuleLevel(DWORD Type,DWORD Level)
- {
- if(g_fAutoRefreshLevels)
- {
-
-
- static DWORD g_dwLastRefresh = 0;
- DWORD dwTime = timeGetTime();
- if(dwTime - g_dwLastRefresh > 1000) {
- g_dwLastRefresh = dwTime;
-
-
-
- DbgInitModuleSettings(false);
- }
- }
- DWORD Mask = 0x01;
-
- if ((Type & ((1<<iMAXLEVELS)-1))) {
-
- if (0==Level)
- return(TRUE);
-
- for (LONG lKeyPos = 0;lKeyPos < iMAXLEVELS;lKeyPos++) {
- if (Type & Mask) {
- if (Level <= (m_Levels[lKeyPos] & ~LOG_FORCIBLY_SET)) {
- return TRUE;
- }
- }
- Mask <<= 1;
- }
- }
- return FALSE;
- }
- void WINAPI DbgSetModuleLevel(DWORD Type, DWORD Level)
- {
- DWORD Mask = 0x01;
- for (LONG lKeyPos = 0;lKeyPos < iMAXLEVELS;lKeyPos++) {
- if (Type & Mask) {
- m_Levels[lKeyPos] = Level | LOG_FORCIBLY_SET;
- }
- Mask <<= 1;
- }
- }
- void WINAPI DbgSetAutoRefreshLevels(bool fAuto)
- {
- g_fAutoRefreshLevels = fAuto;
- }
- #ifdef UNICODE
- void WINAPI DbgLogInfo(DWORD Type,DWORD Level,__format_string LPCSTR pFormat,...)
- {
-
- BOOL bAccept = DbgCheckModuleLevel(Type,Level);
- if (bAccept == FALSE) {
- return;
- }
- TCHAR szInfo[2000];
-
- va_list va;
- va_start(va, pFormat);
- (void)StringCchPrintf(szInfo, NUMELMS(szInfo),
- TEXT("%s(tid %x) %8d : "),
- m_ModuleName,
- GetCurrentThreadId(), timeGetTime() - dwTimeOffset);
- CHAR szInfoA[2000];
- WideCharToMultiByte(CP_ACP, 0, szInfo, -1, szInfoA, NUMELMS(szInfoA), 0, 0);
- (void)StringCchVPrintfA(szInfoA + lstrlenA(szInfoA), NUMELMS(szInfoA) - lstrlenA(szInfoA), pFormat, va);
- (void)StringCchCatA(szInfoA, NUMELMS(szInfoA), "\r\n");
- WCHAR wszOutString[2000];
- MultiByteToWideChar(CP_ACP, 0, szInfoA, -1, wszOutString, NUMELMS(wszOutString));
- DbgOutString(wszOutString);
- va_end(va);
- }
- void WINAPI DbgAssert(LPCSTR pCondition,LPCSTR pFileName,INT iLine)
- {
- if(g_fUseKASSERT)
- {
- DbgKernelAssert(pCondition, pFileName, iLine);
- }
- else
- {
- TCHAR szInfo[iDEBUGINFO];
- (void)StringCchPrintf(szInfo, NUMELMS(szInfo), TEXT("%hs \nAt line %d of %hs\nContinue? (Cancel to debug)"),
- pCondition, iLine, pFileName);
- INT MsgId = MessageBoxOtherThread(NULL,szInfo,TEXT("ASSERT Failed"),
- MB_SYSTEMMODAL |
- MB_ICONHAND |
- MB_YESNOCANCEL |
- MB_SETFOREGROUND);
- switch (MsgId)
- {
- case IDNO:
- FatalAppExit(FALSE, TEXT("Application terminated"));
- break;
- case IDCANCEL:
- DebugBreak();
- break;
- case IDYES:
- break;
- }
- }
- }
- void WINAPI DbgBreakPoint(LPCSTR pCondition,LPCSTR pFileName,INT iLine)
- {
- if(g_fUseKASSERT)
- {
- DbgKernelAssert(pCondition, pFileName, iLine);
- }
- else
- {
- TCHAR szInfo[iDEBUGINFO];
- (void)StringCchPrintf(szInfo, NUMELMS(szInfo),TEXT("%hs \nAt line %d of %hs\nContinue? (Cancel to debug)"),
- pCondition, iLine, pFileName);
- INT MsgId = MessageBoxOtherThread(NULL,szInfo,TEXT("Hard coded break point"),
- MB_SYSTEMMODAL |
- MB_ICONHAND |
- MB_YESNOCANCEL |
- MB_SETFOREGROUND);
- switch (MsgId)
- {
- case IDNO:
- FatalAppExit(FALSE, TEXT("Application terminated"));
- break;
- case IDCANCEL:
- DebugBreak();
- break;
- case IDYES:
- break;
- }
- }
- }
- void WINAPI DbgKernelAssert(LPCSTR pCondition,LPCSTR pFileName,INT iLine)
- {
- DbgLog((LOG_ERROR,0,TEXT("Assertion FAILED (%hs) at line %d in file %hs"),
- pCondition, iLine, pFileName));
- DebugBreak();
- }
- #endif
- void WINAPI DbgLogInfo(DWORD Type,DWORD Level,LPCTSTR pFormat,...)
- {
-
- BOOL bAccept = DbgCheckModuleLevel(Type,Level);
- if (bAccept == FALSE) {
- return;
- }
- TCHAR szInfo[2000];
-
- va_list va;
- va_start(va, pFormat);
- (void)StringCchPrintf(szInfo, NUMELMS(szInfo),
- TEXT("%s(tid %x) %8d : "),
- m_ModuleName,
- GetCurrentThreadId(), timeGetTime() - dwTimeOffset);
- (void)StringCchVPrintf(szInfo + lstrlen(szInfo), NUMELMS(szInfo) - lstrlen(szInfo), pFormat, va);
- (void)StringCchCat(szInfo, NUMELMS(szInfo), TEXT("\r\n"));
- DbgOutString(szInfo);
- va_end(va);
- }
- void WINAPI DbgKernelAssert(LPCTSTR pCondition,LPCTSTR pFileName,INT iLine)
- {
- DbgLog((LOG_ERROR,0,TEXT("Assertion FAILED (%s) at line %d in file %s"),
- pCondition, iLine, pFileName));
- DebugBreak();
- }
- DWORD WINAPI DbgRegisterObjectCreation(LPCSTR szObjectName,
- LPCWSTR wszObjectName)
- {
-
- ASSERT(!!szObjectName ^ !!wszObjectName);
-
- ObjectDesc *pObject = new ObjectDesc;
- ASSERT(pObject);
-
- if (pObject == NULL) {
- return FALSE;
- }
-
- if (m_bInit == FALSE) {
- DbgInitialise(GetModuleHandle(NULL));
- }
-
- EnterCriticalSection(&m_CSDebug);
-
- if (!szObjectName && !wszObjectName) {
- szObjectName = pUnknownName;
- }
-
- pObject->m_szName = szObjectName;
- pObject->m_wszName = wszObjectName;
- pObject->m_dwCookie = ++m_dwNextCookie;
- pObject->m_pNext = pListHead;
- pListHead = pObject;
- m_dwObjectCount++;
- DWORD ObjectCookie = pObject->m_dwCookie;
- ASSERT(ObjectCookie);
- if(wszObjectName) {
- DbgLog((LOG_MEMORY,2,TEXT("Object created %d (%ls) %d Active"),
- pObject->m_dwCookie, wszObjectName, m_dwObjectCount));
- } else {
- DbgLog((LOG_MEMORY,2,TEXT("Object created %d (%hs) %d Active"),
- pObject->m_dwCookie, szObjectName, m_dwObjectCount));
- }
- LeaveCriticalSection(&m_CSDebug);
- return ObjectCookie;
- }
- BOOL WINAPI DbgRegisterObjectDestruction(DWORD dwCookie)
- {
-
- EnterCriticalSection(&m_CSDebug);
- ObjectDesc *pObject = pListHead;
- ObjectDesc *pPrevious = NULL;
-
- while (pObject) {
- if (pObject->m_dwCookie == dwCookie) {
- break;
- }
- pPrevious = pObject;
- pObject = pObject->m_pNext;
- }
- if (pObject == NULL) {
- DbgBreak("Apparently destroying a bogus object");
- LeaveCriticalSection(&m_CSDebug);
- return FALSE;
- }
-
- if (pPrevious == NULL) {
- pListHead = pObject->m_pNext;
- } else {
- pPrevious->m_pNext = pObject->m_pNext;
- }
-
- m_dwObjectCount--;
- if(pObject->m_wszName) {
- DbgLog((LOG_MEMORY,2,TEXT("Object destroyed %d (%ls) %d Active"),
- pObject->m_dwCookie, pObject->m_wszName, m_dwObjectCount));
- } else {
- DbgLog((LOG_MEMORY,2,TEXT("Object destroyed %d (%hs) %d Active"),
- pObject->m_dwCookie, pObject->m_szName, m_dwObjectCount));
- }
- delete pObject;
- LeaveCriticalSection(&m_CSDebug);
- return TRUE;
- }
- void WINAPI DbgDumpObjectRegister()
- {
- TCHAR szInfo[iDEBUGINFO];
-
- EnterCriticalSection(&m_CSDebug);
- ObjectDesc *pObject = pListHead;
-
- DbgLog((LOG_MEMORY,2,TEXT("")));
- DbgLog((LOG_MEMORY,2,TEXT(" ID Object Description")));
- DbgLog((LOG_MEMORY,2,TEXT("")));
- while (pObject) {
- if(pObject->m_wszName) {
- (void)StringCchPrintf(szInfo,NUMELMS(szInfo),TEXT("%5d (%p) %30ls"),pObject->m_dwCookie, &pObject, pObject->m_wszName);
- } else {
- (void)StringCchPrintf(szInfo,NUMELMS(szInfo),TEXT("%5d (%p) %30hs"),pObject->m_dwCookie, &pObject, pObject->m_szName);
- }
- DbgLog((LOG_MEMORY,2,szInfo));
- pObject = pObject->m_pNext;
- }
- (void)StringCchPrintf(szInfo,NUMELMS(szInfo),TEXT("Total object count %5d"),m_dwObjectCount);
- DbgLog((LOG_MEMORY,2,TEXT("")));
- DbgLog((LOG_MEMORY,1,szInfo));
- LeaveCriticalSection(&m_CSDebug);
- }
- DWORD WINAPI DbgWaitForSingleObject(HANDLE h)
- {
- DWORD dwWaitResult;
- do {
- dwWaitResult = WaitForSingleObject(h, dwWaitTimeout);
- ASSERT(dwWaitResult == WAIT_OBJECT_0);
- } while (dwWaitResult == WAIT_TIMEOUT);
- return dwWaitResult;
- }
- DWORD WINAPI DbgWaitForMultipleObjects(DWORD nCount,
- __in_ecount(nCount) CONST HANDLE *lpHandles,
- BOOL bWaitAll)
- {
- DWORD dwWaitResult;
- do {
- dwWaitResult = WaitForMultipleObjects(nCount,
- lpHandles,
- bWaitAll,
- dwWaitTimeout);
- ASSERT((DWORD)(dwWaitResult - WAIT_OBJECT_0) < MAXIMUM_WAIT_OBJECTS);
- } while (dwWaitResult == WAIT_TIMEOUT);
- return dwWaitResult;
- }
- void WINAPI DbgSetWaitTimeout(DWORD dwTimeout)
- {
- dwWaitTimeout = dwTimeout;
- }
- #endif
- #ifdef _OBJBASE_H_
-
- GUID_STRING_ENTRY g_GuidNames[] = {
- #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
- { #name, { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } },
- #include <uuids.h>
- };
- CGuidNameList GuidNames;
- int g_cGuidNames = sizeof(g_GuidNames) / sizeof(g_GuidNames[0]);
- char *CGuidNameList::operator [] (const GUID &guid)
- {
- for (int i = 0; i < g_cGuidNames; i++) {
- if (g_GuidNames[i].guid == guid) {
- return g_GuidNames[i].szName;
- }
- }
- if (guid == GUID_NULL) {
- return "GUID_NULL";
- }
-
-
-
- return "Unknown GUID Name";
- }
- #endif
- CDisp::CDisp(LONGLONG ll, int Format)
- {
-
-
- LARGE_INTEGER li;
- li.QuadPart = ll;
- switch (Format) {
- case CDISP_DEC:
- {
- TCHAR temp[20];
- int pos=20;
- temp[--pos] = 0;
- int digit;
-
- do {
-
- digit = li.LowPart % 10;
- li.QuadPart /= 10;
- temp[--pos] = (TCHAR) digit+L'0';
- } while (li.QuadPart);
- (void)StringCchCopy(m_String, NUMELMS(m_String), temp+pos);
- break;
- }
- case CDISP_HEX:
- default:
- (void)StringCchPrintf(m_String, NUMELMS(m_String), TEXT("0x%X%8.8X"), li.HighPart, li.LowPart);
- }
- };
- CDisp::CDisp(REFCLSID clsid)
- {
- #ifdef UNICODE
- (void)StringFromGUID2(clsid, m_String, NUMELMS(m_String));
- #else
- WCHAR wszTemp[50];
- (void)StringFromGUID2(clsid, wszTemp, NUMELMS(wszTemp));
- (void)StringCchPrintf(m_String, NUMELMS(m_String), TEXT("%S"), wszTemp);
- #endif
- };
- #ifdef __STREAMS__
- CDisp::CDisp(CRefTime llTime)
- {
- LONGLONG llDiv;
- if (llTime < 0) {
- llTime = -llTime;
- (void)StringCchCopy(m_String, NUMELMS(m_String), TEXT("-"));
- }
- llDiv = (LONGLONG)24 * 3600 * 10000000;
- if (llTime >= llDiv) {
- (void)StringCchPrintf(m_String + lstrlen(m_String), NUMELMS(m_String) - lstrlen(m_String), TEXT("%d days "), (LONG)(llTime / llDiv));
- llTime = llTime % llDiv;
- }
- llDiv = (LONGLONG)3600 * 10000000;
- if (llTime >= llDiv) {
- (void)StringCchPrintf(m_String + lstrlen(m_String), NUMELMS(m_String) - lstrlen(m_String), TEXT("%d hrs "), (LONG)(llTime / llDiv));
- llTime = llTime % llDiv;
- }
- llDiv = (LONGLONG)60 * 10000000;
- if (llTime >= llDiv) {
- (void)StringCchPrintf(m_String + lstrlen(m_String), NUMELMS(m_String) - lstrlen(m_String), TEXT("%d mins "), (LONG)(llTime / llDiv));
- llTime = llTime % llDiv;
- }
- (void)StringCchPrintf(m_String + lstrlen(m_String), NUMELMS(m_String) - lstrlen(m_String), TEXT("%d.%3.3d sec"),
- (LONG)llTime / 10000000,
- (LONG)((llTime % 10000000) / 10000));
- };
- #endif
- CDisp::CDisp(IPin *pPin)
- {
- PIN_INFO pi;
- TCHAR str[MAX_PIN_NAME];
- CLSID clsid;
- if (pPin) {
- pPin->QueryPinInfo(&pi);
- pi.pFilter->GetClassID(&clsid);
- QueryPinInfoReleaseFilter(pi);
- #ifndef UNICODE
- WideCharToMultiByte(GetACP(), 0, pi.achName, lstrlenW(pi.achName) + 1,
- str, MAX_PIN_NAME, NULL, NULL);
- #else
- (void)StringCchCopy(str, NUMELMS(str), pi.achName);
- #endif
- } else {
- (void)StringCchCopy(str, NUMELMS(str), TEXT("NULL IPin"));
- }
- m_pString = (PTCHAR) new TCHAR[lstrlen(str)+64];
- if (!m_pString) {
- return;
- }
- (void)StringCchPrintf(m_pString, lstrlen(str) + 64, TEXT("%hs(%s)"), GuidNames[clsid], str);
- }
- CDisp::CDisp(IUnknown *pUnk)
- {
- IBaseFilter *pf;
- HRESULT hr = pUnk->QueryInterface(IID_IBaseFilter, (void **)&pf);
- if(SUCCEEDED(hr))
- {
- FILTER_INFO fi;
- hr = pf->QueryFilterInfo(&fi);
- if(SUCCEEDED(hr))
- {
- QueryFilterInfoReleaseGraph(fi);
- size_t len = lstrlenW(fi.achName) + 1;
- m_pString = new TCHAR[len];
- if(m_pString)
- {
- #ifdef UNICODE
- (void)StringCchCopy(m_pString, len, fi.achName);
- #else
- (void)StringCchPrintf(m_pString, len, "%S", fi.achName);
- #endif
- }
- }
- pf->Release();
- return;
- }
- IPin *pp;
- hr = pUnk->QueryInterface(IID_IPin, (void **)&pp);
- if(SUCCEEDED(hr))
- {
- CDisp::CDisp(pp);
- pp->Release();
- return;
- }
- }
- CDisp::~CDisp()
- {
- }
- CDispBasic::~CDispBasic()
- {
- if (m_pString != m_String) {
- delete [] m_pString;
- }
- }
- CDisp::CDisp(double d)
- {
- (void)StringCchPrintf(m_String, NUMELMS(m_String), TEXT("%d.%03d"), (int) d, (int) ((d - (int) d) * 1000));
- }
- #ifdef DEBUG
- void WINAPI DisplayType(LPCTSTR label, const AM_MEDIA_TYPE *pmtIn)
- {
-
- DbgLog((LOG_TRACE,5,TEXT("")));
- DbgLog((LOG_TRACE,2,TEXT("%s M type %hs S type %hs"), label,
- GuidNames[pmtIn->majortype],
- GuidNames[pmtIn->subtype]));
- DbgLog((LOG_TRACE,5,TEXT("Subtype description %s"),GetSubtypeName(&pmtIn->subtype)));
-
- if (pmtIn->bTemporalCompression) {
- DbgLog((LOG_TRACE,5,TEXT("Temporally compressed")));
- } else {
- DbgLog((LOG_TRACE,5,TEXT("Not temporally compressed")));
- }
- if (pmtIn->bFixedSizeSamples) {
- DbgLog((LOG_TRACE,5,TEXT("Sample size %d"),pmtIn->lSampleSize));
- } else {
- DbgLog((LOG_TRACE,5,TEXT("Variable size samples")));
- }
- if (pmtIn->formattype == FORMAT_VideoInfo) {
- VIDEOINFOHEADER *pVideoInfo = (VIDEOINFOHEADER *)pmtIn->pbFormat;
- DisplayRECT(TEXT("Source rectangle"),pVideoInfo->rcSource);
- DisplayRECT(TEXT("Target rectangle"),pVideoInfo->rcTarget);
- DisplayBITMAPINFO(HEADER(pmtIn->pbFormat));
- } if (pmtIn->formattype == FORMAT_VideoInfo2) {
- VIDEOINFOHEADER2 *pVideoInfo2 = (VIDEOINFOHEADER2 *)pmtIn->pbFormat;
- DisplayRECT(TEXT("Source rectangle"),pVideoInfo2->rcSource);
- DisplayRECT(TEXT("Target rectangle"),pVideoInfo2->rcTarget);
- DbgLog((LOG_TRACE, 5, TEXT("Aspect Ratio: %d:%d"),
- pVideoInfo2->dwPictAspectRatioX,
- pVideoInfo2->dwPictAspectRatioY));
- DisplayBITMAPINFO(&pVideoInfo2->bmiHeader);
- } else if (pmtIn->majortype == MEDIATYPE_Audio) {
- DbgLog((LOG_TRACE,2,TEXT(" Format type %hs"),
- GuidNames[pmtIn->formattype]));
- DbgLog((LOG_TRACE,2,TEXT(" Subtype %hs"),
- GuidNames[pmtIn->subtype]));
- if ((pmtIn->subtype != MEDIASUBTYPE_MPEG1Packet)
- && (pmtIn->cbFormat >= sizeof(PCMWAVEFORMAT)))
- {
-
- WAVEFORMATEX *pwfx = (WAVEFORMATEX *) pmtIn->pbFormat;
- DbgLog((LOG_TRACE,2,TEXT("wFormatTag %u"), pwfx->wFormatTag));
- DbgLog((LOG_TRACE,2,TEXT("nChannels %u"), pwfx->nChannels));
- DbgLog((LOG_TRACE,2,TEXT("nSamplesPerSec %lu"), pwfx->nSamplesPerSec));
- DbgLog((LOG_TRACE,2,TEXT("nAvgBytesPerSec %lu"), pwfx->nAvgBytesPerSec));
- DbgLog((LOG_TRACE,2,TEXT("nBlockAlign %u"), pwfx->nBlockAlign));
- DbgLog((LOG_TRACE,2,TEXT("wBitsPerSample %u"), pwfx->wBitsPerSample));
-
- if (pmtIn->cbFormat >= sizeof(WAVEFORMATEX)) {
- DbgLog((LOG_TRACE,2,TEXT("cbSize %u"), pwfx->cbSize));
- }
- } else {
- }
- } else {
- DbgLog((LOG_TRACE,2,TEXT(" Format type %hs"),
- GuidNames[pmtIn->formattype]));
- }
- }
- void DisplayBITMAPINFO(const BITMAPINFOHEADER* pbmi)
- {
- DbgLog((LOG_TRACE,5,TEXT("Size of BITMAPINFO structure %d"),pbmi->biSize));
- if (pbmi->biCompression < 256) {
- DbgLog((LOG_TRACE,2,TEXT("%dx%dx%d bit (%d)"),
- pbmi->biWidth, pbmi->biHeight,
- pbmi->biBitCount, pbmi->biCompression));
- } else {
- DbgLog((LOG_TRACE,2,TEXT("%dx%dx%d bit '%4.4hs'"),
- pbmi->biWidth, pbmi->biHeight,
- pbmi->biBitCount, &pbmi->biCompression));
- }
- DbgLog((LOG_TRACE,2,TEXT("Image size %d"),pbmi->biSizeImage));
- DbgLog((LOG_TRACE,5,TEXT("Planes %d"),pbmi->biPlanes));
- DbgLog((LOG_TRACE,5,TEXT("X Pels per metre %d"),pbmi->biXPelsPerMeter));
- DbgLog((LOG_TRACE,5,TEXT("Y Pels per metre %d"),pbmi->biYPelsPerMeter));
- DbgLog((LOG_TRACE,5,TEXT("Colours used %d"),pbmi->biClrUsed));
- }
- void DisplayRECT(LPCTSTR szLabel, const RECT& rc)
- {
- DbgLog((LOG_TRACE,5,TEXT("%s (Left %d Top %d Right %d Bottom %d)"),
- szLabel,
- rc.left,
- rc.top,
- rc.right,
- rc.bottom));
- }
- void WINAPI DumpGraph(IFilterGraph *pGraph, DWORD dwLevel)
- {
- if( !pGraph )
- {
- return;
- }
- IEnumFilters *pFilters;
- DbgLog((LOG_TRACE,dwLevel,TEXT("DumpGraph [%x]"), pGraph));
- if (FAILED(pGraph->EnumFilters(&pFilters))) {
- DbgLog((LOG_TRACE,dwLevel,TEXT("EnumFilters failed!")));
- }
- IBaseFilter *pFilter;
- ULONG n;
- while (pFilters->Next(1, &pFilter, &n) == S_OK) {
- FILTER_INFO info;
- if (FAILED(pFilter->QueryFilterInfo(&info))) {
- DbgLog((LOG_TRACE,dwLevel,TEXT(" Filter [%p] -- failed QueryFilterInfo"), pFilter));
- } else {
- QueryFilterInfoReleaseGraph(info);
-
-
- DbgLog((LOG_TRACE,dwLevel,TEXT(" Filter [%p] '%ls'"), pFilter, info.achName));
- IEnumPins *pins;
- if (FAILED(pFilter->EnumPins(&pins))) {
- DbgLog((LOG_TRACE,dwLevel,TEXT("EnumPins failed!")));
- } else {
- IPin *pPin;
- while (pins->Next(1, &pPin, &n) == S_OK) {
- PIN_INFO pinInfo;
- if (FAILED(pPin->QueryPinInfo(&pinInfo))) {
- DbgLog((LOG_TRACE,dwLevel,TEXT(" Pin [%x] -- failed QueryPinInfo"), pPin));
- } else {
- QueryPinInfoReleaseFilter(pinInfo);
- IPin *pPinConnected = NULL;
- HRESULT hr = pPin->ConnectedTo(&pPinConnected);
- if (pPinConnected) {
- DbgLog((LOG_TRACE,dwLevel,TEXT(" Pin [%p] '%ls' [%sput]")
- TEXT(" Connected to pin [%p]"),
- pPin, pinInfo.achName,
- pinInfo.dir == PINDIR_INPUT ? TEXT("In") : TEXT("Out"),
- pPinConnected));
- pPinConnected->Release();
-
-
- if (pinInfo.dir == PINDIR_OUTPUT) {
- AM_MEDIA_TYPE mt;
- hr = pPin->ConnectionMediaType(&mt);
- if (SUCCEEDED(hr)) {
- DisplayType(TEXT("Connection type"), &mt);
- FreeMediaType(mt);
- }
- }
- } else {
- DbgLog((LOG_TRACE,dwLevel,
- TEXT(" Pin [%x] '%ls' [%sput]"),
- pPin, pinInfo.achName,
- pinInfo.dir == PINDIR_INPUT ? TEXT("In") : TEXT("Out")));
- }
- }
- pPin->Release();
- }
- pins->Release();
- }
- }
-
- pFilter->Release();
- }
- pFilters->Release();
- }
- #endif
|