Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1371 lines
42 KiB

  1. //------------------------------------------------------------------------------
  2. // File: WXDebug.cpp
  3. //
  4. // Desc: DirectShow base classes - implements ActiveX system debugging
  5. // facilities.
  6. //
  7. // Copyright (c) 1992-2001 Microsoft Corporation. All rights reserved.
  8. //------------------------------------------------------------------------------
  9. #define _WINDLL
  10. #include <streams.h>
  11. #include <stdarg.h>
  12. #include <stdio.h>
  13. #ifdef DEBUG
  14. #ifdef UNICODE
  15. #ifndef _UNICODE
  16. #define _UNICODE
  17. #endif // _UNICODE
  18. #endif // UNICODE
  19. #endif // DEBUG
  20. #include <tchar.h>
  21. #ifdef DEBUG
  22. // The Win32 wsprintf() function writes a maximum of 1024 characters to it's output buffer.
  23. // See the documentation for wsprintf()'s lpOut parameter for more information.
  24. const INT iDEBUGINFO = 1024; // Used to format strings
  25. /* For every module and executable we store a debugging level for each of
  26. the five categories (eg LOG_ERROR and LOG_TIMING). This makes it easy
  27. to isolate and debug individual modules without seeing everybody elses
  28. spurious debug output. The keys are stored in the registry under the
  29. HKEY_LOCAL_MACHINE\SOFTWARE\Debug\<Module Name>\<KeyName> key values
  30. NOTE these must be in the same order as their enumeration definition */
  31. TCHAR *pKeyNames[] = {
  32. TEXT("TIMING"), // Timing and performance measurements
  33. TEXT("TRACE"), // General step point call tracing
  34. TEXT("MEMORY"), // Memory and object allocation/destruction
  35. TEXT("LOCKING"), // Locking/unlocking of critical sections
  36. TEXT("ERROR"), // Debug error notification
  37. TEXT("CUSTOM1"),
  38. TEXT("CUSTOM2"),
  39. TEXT("CUSTOM3"),
  40. TEXT("CUSTOM4"),
  41. TEXT("CUSTOM5")
  42. };
  43. const TCHAR CAutoTrace::_szEntering[] = TEXT("Entering: %s");
  44. const TCHAR CAutoTrace::_szLeaving[] = TEXT("Leaving: %s");
  45. const INT iMAXLEVELS = NUMELMS(pKeyNames); // Maximum debug categories
  46. HINSTANCE m_hInst; // Module instance handle
  47. TCHAR m_ModuleName[iDEBUGINFO]; // Cut down module name
  48. DWORD m_Levels[iMAXLEVELS]; // Debug level per category
  49. CRITICAL_SECTION m_CSDebug; // Controls access to list
  50. DWORD m_dwNextCookie; // Next active object ID
  51. ObjectDesc *pListHead = NULL; // First active object
  52. DWORD m_dwObjectCount; // Active object count
  53. BOOL m_bInit = FALSE; // Have we been initialised
  54. HANDLE m_hOutput = INVALID_HANDLE_VALUE; // Optional output written here
  55. DWORD dwWaitTimeout = INFINITE; // Default timeout value
  56. DWORD dwTimeOffset; // Time of first DbgLog call
  57. bool g_fUseKASSERT = false; // don't create messagebox
  58. bool g_fDbgInDllEntryPoint = false;
  59. bool g_fAutoRefreshLevels = false;
  60. const TCHAR *pBaseKey = TEXT("SOFTWARE\\Debug");
  61. const TCHAR *pGlobalKey = TEXT("GLOBAL");
  62. static CHAR *pUnknownName = "UNKNOWN";
  63. TCHAR *TimeoutName = TEXT("TIMEOUT");
  64. /* This sets the instance handle that the debug library uses to find
  65. the module's file name from the Win32 GetModuleFileName function */
  66. void WINAPI DbgInitialise(HINSTANCE hInst)
  67. {
  68. InitializeCriticalSection(&m_CSDebug);
  69. m_bInit = TRUE;
  70. m_hInst = hInst;
  71. DbgInitModuleName();
  72. if (GetProfileInt(m_ModuleName, TEXT("BreakOnLoad"), 0))
  73. DebugBreak();
  74. DbgInitModuleSettings(false);
  75. DbgInitGlobalSettings(true);
  76. dwTimeOffset = timeGetTime();
  77. }
  78. /* This is called to clear up any resources the debug library uses - at the
  79. moment we delete our critical section and the object list. The values we
  80. retrieve from the registry are all done during initialisation but we don't
  81. go looking for update notifications while we are running, if the values
  82. are changed then the application has to be restarted to pick them up */
  83. void WINAPI DbgTerminate()
  84. {
  85. if (m_hOutput != INVALID_HANDLE_VALUE) {
  86. EXECUTE_ASSERT(CloseHandle(m_hOutput));
  87. m_hOutput = INVALID_HANDLE_VALUE;
  88. }
  89. DeleteCriticalSection(&m_CSDebug);
  90. m_bInit = FALSE;
  91. }
  92. /* This is called by DbgInitLogLevels to read the debug settings
  93. for each logging category for this module from the registry */
  94. void WINAPI DbgInitKeyLevels(HKEY hKey, bool fTakeMax)
  95. {
  96. LONG lReturn; // Create key return value
  97. LONG lKeyPos; // Current key category
  98. DWORD dwKeySize; // Size of the key value
  99. DWORD dwKeyType; // Receives it's type
  100. DWORD dwKeyValue; // This fields value
  101. /* Try and read a value for each key position in turn */
  102. for (lKeyPos = 0;lKeyPos < iMAXLEVELS;lKeyPos++) {
  103. dwKeySize = sizeof(DWORD);
  104. lReturn = RegQueryValueEx(
  105. hKey, // Handle to an open key
  106. pKeyNames[lKeyPos], // Subkey name derivation
  107. NULL, // Reserved field
  108. &dwKeyType, // Returns the field type
  109. (LPBYTE) &dwKeyValue, // Returns the field's value
  110. &dwKeySize ); // Number of bytes transferred
  111. /* If either the key was not available or it was not a DWORD value
  112. then we ensure only the high priority debug logging is output
  113. but we try and update the field to a zero filled DWORD value */
  114. if (lReturn != ERROR_SUCCESS || dwKeyType != REG_DWORD) {
  115. dwKeyValue = 0;
  116. lReturn = RegSetValueEx(
  117. hKey, // Handle of an open key
  118. pKeyNames[lKeyPos], // Address of subkey name
  119. (DWORD) 0, // Reserved field
  120. REG_DWORD, // Type of the key field
  121. (PBYTE) &dwKeyValue, // Value for the field
  122. sizeof(DWORD)); // Size of the field buffer
  123. if (lReturn != ERROR_SUCCESS) {
  124. DbgLog((LOG_ERROR,0,TEXT("Could not create subkey %s"),pKeyNames[lKeyPos]));
  125. dwKeyValue = 0;
  126. }
  127. }
  128. if(fTakeMax)
  129. {
  130. m_Levels[lKeyPos] = max(dwKeyValue,m_Levels[lKeyPos]);
  131. }
  132. else
  133. {
  134. if((m_Levels[lKeyPos] & LOG_FORCIBLY_SET) == 0) {
  135. m_Levels[lKeyPos] = dwKeyValue;
  136. }
  137. }
  138. }
  139. /* Read the timeout value for catching hangs */
  140. dwKeySize = sizeof(DWORD);
  141. lReturn = RegQueryValueEx(
  142. hKey, // Handle to an open key
  143. TimeoutName, // Subkey name derivation
  144. NULL, // Reserved field
  145. &dwKeyType, // Returns the field type
  146. (LPBYTE) &dwWaitTimeout, // Returns the field's value
  147. &dwKeySize ); // Number of bytes transferred
  148. /* If either the key was not available or it was not a DWORD value
  149. then we ensure only the high priority debug logging is output
  150. but we try and update the field to a zero filled DWORD value */
  151. if (lReturn != ERROR_SUCCESS || dwKeyType != REG_DWORD) {
  152. dwWaitTimeout = INFINITE;
  153. lReturn = RegSetValueEx(
  154. hKey, // Handle of an open key
  155. TimeoutName, // Address of subkey name
  156. (DWORD) 0, // Reserved field
  157. REG_DWORD, // Type of the key field
  158. (PBYTE) &dwWaitTimeout, // Value for the field
  159. sizeof(DWORD)); // Size of the field buffer
  160. if (lReturn != ERROR_SUCCESS) {
  161. DbgLog((LOG_ERROR,0,TEXT("Could not create subkey %s"),pKeyNames[lKeyPos]));
  162. dwWaitTimeout = INFINITE;
  163. }
  164. }
  165. }
  166. void WINAPI DbgOutString(LPCTSTR psz)
  167. {
  168. if (m_hOutput != INVALID_HANDLE_VALUE) {
  169. UINT cb = lstrlen(psz);
  170. DWORD dw;
  171. #ifdef UNICODE
  172. CHAR szDest[2048];
  173. WideCharToMultiByte(CP_ACP, 0, psz, -1, szDest, NUMELMS(szDest), 0, 0);
  174. WriteFile (m_hOutput, szDest, cb, &dw, NULL);
  175. #else
  176. WriteFile (m_hOutput, psz, cb, &dw, NULL);
  177. #endif
  178. } else {
  179. OutputDebugString (psz);
  180. }
  181. }
  182. /* Called by DbgInitGlobalSettings to setup alternate logging destinations
  183. */
  184. void WINAPI DbgInitLogTo (
  185. HKEY hKey)
  186. {
  187. LONG lReturn;
  188. DWORD dwKeyType;
  189. DWORD dwKeySize;
  190. TCHAR szFile[MAX_PATH] = {0};
  191. static const TCHAR cszKey[] = TEXT("LogToFile");
  192. dwKeySize = MAX_PATH;
  193. lReturn = RegQueryValueEx(
  194. hKey, // Handle to an open key
  195. cszKey, // Subkey name derivation
  196. NULL, // Reserved field
  197. &dwKeyType, // Returns the field type
  198. (LPBYTE) szFile, // Returns the field's value
  199. &dwKeySize); // Number of bytes transferred
  200. // create an empty key if it does not already exist
  201. //
  202. if (lReturn != ERROR_SUCCESS || dwKeyType != REG_SZ)
  203. {
  204. dwKeySize = sizeof(TCHAR);
  205. lReturn = RegSetValueEx(
  206. hKey, // Handle of an open key
  207. cszKey, // Address of subkey name
  208. (DWORD) 0, // Reserved field
  209. REG_SZ, // Type of the key field
  210. (PBYTE)szFile, // Value for the field
  211. dwKeySize); // Size of the field buffer
  212. }
  213. // if an output-to was specified. try to open it.
  214. //
  215. if (m_hOutput != INVALID_HANDLE_VALUE) {
  216. EXECUTE_ASSERT(CloseHandle (m_hOutput));
  217. m_hOutput = INVALID_HANDLE_VALUE;
  218. }
  219. if (szFile[0] != 0)
  220. {
  221. if (!lstrcmpi(szFile, TEXT("Console"))) {
  222. m_hOutput = GetStdHandle (STD_OUTPUT_HANDLE);
  223. if (m_hOutput == INVALID_HANDLE_VALUE) {
  224. AllocConsole ();
  225. m_hOutput = GetStdHandle (STD_OUTPUT_HANDLE);
  226. }
  227. SetConsoleTitle (TEXT("ActiveX Debug Output"));
  228. } else if (szFile[0] &&
  229. lstrcmpi(szFile, TEXT("Debug")) &&
  230. lstrcmpi(szFile, TEXT("Debugger")) &&
  231. lstrcmpi(szFile, TEXT("Deb")))
  232. {
  233. m_hOutput = CreateFile(szFile, GENERIC_WRITE,
  234. FILE_SHARE_READ,
  235. NULL, OPEN_ALWAYS,
  236. FILE_ATTRIBUTE_NORMAL,
  237. NULL);
  238. if (INVALID_HANDLE_VALUE != m_hOutput)
  239. {
  240. static const TCHAR cszBar[] = TEXT("\r\n\r\n=====DbgInitialize()=====\r\n\r\n");
  241. SetFilePointer (m_hOutput, 0, NULL, FILE_END);
  242. DbgOutString (cszBar);
  243. }
  244. }
  245. }
  246. }
  247. /* This is called by DbgInitLogLevels to read the global debug settings for
  248. each logging category for this module from the registry. Normally each
  249. module has it's own values set for it's different debug categories but
  250. setting the global SOFTWARE\Debug\Global applies them to ALL modules */
  251. void WINAPI DbgInitGlobalSettings(bool fTakeMax)
  252. {
  253. LONG lReturn; // Create key return value
  254. TCHAR szInfo[iDEBUGINFO]; // Constructs key names
  255. HKEY hGlobalKey; // Global override key
  256. /* Construct the global base key name */
  257. wsprintf(szInfo,TEXT("%s\\%s"),pBaseKey,pGlobalKey);
  258. /* Create or open the key for this module */
  259. lReturn = RegCreateKeyEx(HKEY_LOCAL_MACHINE, // Handle of an open key
  260. szInfo, // Address of subkey name
  261. (DWORD) 0, // Reserved value
  262. NULL, // Address of class name
  263. (DWORD) 0, // Special options flags
  264. KEY_ALL_ACCESS, // Desired security access
  265. NULL, // Key security descriptor
  266. &hGlobalKey, // Opened handle buffer
  267. NULL); // What really happened
  268. if (lReturn != ERROR_SUCCESS) {
  269. DbgLog((LOG_ERROR,0,TEXT("Could not access GLOBAL module key")));
  270. return;
  271. }
  272. DbgInitKeyLevels(hGlobalKey, fTakeMax);
  273. RegCloseKey(hGlobalKey);
  274. }
  275. /* This sets the debugging log levels for the different categories. We start
  276. by opening (or creating if not already available) the SOFTWARE\Debug key
  277. that all these settings live under. We then look at the global values
  278. set under SOFTWARE\Debug\Global which apply on top of the individual
  279. module settings. We then load the individual module registry settings */
  280. void WINAPI DbgInitModuleSettings(bool fTakeMax)
  281. {
  282. LONG lReturn; // Create key return value
  283. TCHAR szInfo[iDEBUGINFO]; // Constructs key names
  284. HKEY hModuleKey; // Module key handle
  285. /* Construct the base key name */
  286. wsprintf(szInfo,TEXT("%s\\%s"),pBaseKey,m_ModuleName);
  287. /* Create or open the key for this module */
  288. lReturn = RegCreateKeyEx(HKEY_LOCAL_MACHINE, // Handle of an open key
  289. szInfo, // Address of subkey name
  290. (DWORD) 0, // Reserved value
  291. NULL, // Address of class name
  292. (DWORD) 0, // Special options flags
  293. KEY_ALL_ACCESS, // Desired security access
  294. NULL, // Key security descriptor
  295. &hModuleKey, // Opened handle buffer
  296. NULL); // What really happened
  297. if (lReturn != ERROR_SUCCESS) {
  298. DbgLog((LOG_ERROR,0,TEXT("Could not access module key")));
  299. return;
  300. }
  301. DbgInitLogTo(hModuleKey);
  302. DbgInitKeyLevels(hModuleKey, fTakeMax);
  303. RegCloseKey(hModuleKey);
  304. }
  305. /* Initialise the module file name */
  306. void WINAPI DbgInitModuleName()
  307. {
  308. TCHAR FullName[iDEBUGINFO]; // Load the full path and module name
  309. TCHAR *pName; // Searches from the end for a backslash
  310. GetModuleFileName(m_hInst,FullName,iDEBUGINFO);
  311. pName = _tcsrchr(FullName,'\\');
  312. if (pName == NULL) {
  313. pName = FullName;
  314. } else {
  315. pName++;
  316. }
  317. lstrcpy(m_ModuleName,pName);
  318. }
  319. struct MsgBoxMsg
  320. {
  321. HWND hwnd;
  322. TCHAR *szTitle;
  323. TCHAR *szMessage;
  324. DWORD dwFlags;
  325. INT iResult;
  326. };
  327. //
  328. // create a thread to call MessageBox(). calling MessageBox() on
  329. // random threads at bad times can confuse the host (eg IE).
  330. //
  331. DWORD WINAPI MsgBoxThread(
  332. LPVOID lpParameter // thread data
  333. )
  334. {
  335. MsgBoxMsg *pmsg = (MsgBoxMsg *)lpParameter;
  336. pmsg->iResult = MessageBox(
  337. pmsg->hwnd,
  338. pmsg->szTitle,
  339. pmsg->szMessage,
  340. pmsg->dwFlags);
  341. return 0;
  342. }
  343. INT MessageBoxOtherThread(
  344. HWND hwnd,
  345. TCHAR *szTitle,
  346. TCHAR *szMessage,
  347. DWORD dwFlags)
  348. {
  349. if(g_fDbgInDllEntryPoint)
  350. {
  351. // can't wait on another thread because we have the loader
  352. // lock held in the dll entry point.
  353. return MessageBox(hwnd, szTitle, szMessage, dwFlags);
  354. }
  355. else
  356. {
  357. MsgBoxMsg msg = {hwnd, szTitle, szMessage, dwFlags, 0};
  358. DWORD dwid;
  359. HANDLE hThread = CreateThread(
  360. 0, // security
  361. 0, // stack size
  362. MsgBoxThread,
  363. (void *)&msg, // arg
  364. 0, // flags
  365. &dwid);
  366. if(hThread)
  367. {
  368. WaitForSingleObject(hThread, INFINITE);
  369. CloseHandle(hThread);
  370. return msg.iResult;
  371. }
  372. // break into debugger on failure.
  373. return IDCANCEL;
  374. }
  375. }
  376. /* Displays a message box if the condition evaluated to FALSE */
  377. void WINAPI DbgAssert(const TCHAR *pCondition,const TCHAR *pFileName,INT iLine)
  378. {
  379. if(g_fUseKASSERT)
  380. {
  381. DbgKernelAssert(pCondition, pFileName, iLine);
  382. }
  383. else
  384. {
  385. TCHAR szInfo[iDEBUGINFO];
  386. wsprintf(szInfo, TEXT("%s \nAt line %d of %s\nContinue? (Cancel to debug)"),
  387. pCondition, iLine, pFileName);
  388. INT MsgId = MessageBoxOtherThread(NULL,szInfo,TEXT("ASSERT Failed"),
  389. MB_SYSTEMMODAL |
  390. MB_ICONHAND |
  391. MB_YESNOCANCEL |
  392. MB_SETFOREGROUND);
  393. switch (MsgId)
  394. {
  395. case IDNO: /* Kill the application */
  396. FatalAppExit(FALSE, TEXT("Application terminated"));
  397. break;
  398. case IDCANCEL: /* Break into the debugger */
  399. DebugBreak();
  400. break;
  401. case IDYES: /* Ignore assertion continue execution */
  402. break;
  403. }
  404. }
  405. }
  406. /* Displays a message box at a break point */
  407. void WINAPI DbgBreakPoint(const TCHAR *pCondition,const TCHAR *pFileName,INT iLine)
  408. {
  409. if(g_fUseKASSERT)
  410. {
  411. DbgKernelAssert(pCondition, pFileName, iLine);
  412. }
  413. else
  414. {
  415. TCHAR szInfo[iDEBUGINFO];
  416. wsprintf(szInfo, TEXT("%s \nAt line %d of %s\nContinue? (Cancel to debug)"),
  417. pCondition, iLine, pFileName);
  418. INT MsgId = MessageBoxOtherThread(NULL,szInfo,TEXT("Hard coded break point"),
  419. MB_SYSTEMMODAL |
  420. MB_ICONHAND |
  421. MB_YESNOCANCEL |
  422. MB_SETFOREGROUND);
  423. switch (MsgId)
  424. {
  425. case IDNO: /* Kill the application */
  426. FatalAppExit(FALSE, TEXT("Application terminated"));
  427. break;
  428. case IDCANCEL: /* Break into the debugger */
  429. DebugBreak();
  430. break;
  431. case IDYES: /* Ignore break point continue execution */
  432. break;
  433. }
  434. }
  435. }
  436. void WINAPI DbgBreakPoint(const TCHAR *pFileName,INT iLine,const TCHAR* szFormatString,...)
  437. {
  438. // A debug break point message can have at most 2000 characters if
  439. // ANSI or UNICODE characters are being used. A debug break point message
  440. // can have between 1000 and 2000 double byte characters in it. If a
  441. // particular message needs more characters, then the value of this constant
  442. // should be increased.
  443. const DWORD MAX_BREAK_POINT_MESSAGE_SIZE = 2000;
  444. TCHAR szBreakPointMessage[MAX_BREAK_POINT_MESSAGE_SIZE];
  445. const DWORD MAX_CHARS_IN_BREAK_POINT_MESSAGE = sizeof(szBreakPointMessage) / sizeof(TCHAR);
  446. va_list va;
  447. va_start( va, szFormatString );
  448. int nReturnValue = _vsntprintf( szBreakPointMessage, MAX_CHARS_IN_BREAK_POINT_MESSAGE, szFormatString, va );
  449. va_end(va);
  450. // _vsnprintf() returns -1 if an error occurs.
  451. if( -1 == nReturnValue ) {
  452. DbgBreak( "ERROR in DbgBreakPoint(). The variable length debug message could not be displayed because _vsnprintf() failed." );
  453. return;
  454. }
  455. ::DbgBreakPoint( szBreakPointMessage, pFileName, iLine );
  456. }
  457. /* When we initialised the library we stored in the m_Levels array the current
  458. debug output level for this module for each of the five categories. When
  459. some debug logging is sent to us it can be sent with a combination of the
  460. categories (if it is applicable to many for example) in which case we map
  461. the type's categories into their current debug levels and see if any of
  462. them can be accepted. The function looks at each bit position in turn from
  463. the input type field and then compares it's debug level with the modules.
  464. A level of 0 means that output is always sent to the debugger. This is
  465. due to producing output if the input level is <= m_Levels.
  466. */
  467. BOOL WINAPI DbgCheckModuleLevel(DWORD Type,DWORD Level)
  468. {
  469. if(g_fAutoRefreshLevels)
  470. {
  471. // re-read the registry every second. We cannot use RegNotify() to
  472. // notice registry changes because it's not available on win9x.
  473. static g_dwLastRefresh = 0;
  474. DWORD dwTime = timeGetTime();
  475. if(dwTime - g_dwLastRefresh > 1000) {
  476. g_dwLastRefresh = dwTime;
  477. // there's a race condition: multiple threads could update the
  478. // values. plus read and write not synchronized. no harm
  479. // though.
  480. DbgInitModuleSettings(false);
  481. }
  482. }
  483. DWORD Mask = 0x01;
  484. // If no valid bits are set return FALSE
  485. if ((Type & ((1<<iMAXLEVELS)-1))) {
  486. // speed up unconditional output.
  487. if (0==Level)
  488. return(TRUE);
  489. for (LONG lKeyPos = 0;lKeyPos < iMAXLEVELS;lKeyPos++) {
  490. if (Type & Mask) {
  491. if (Level <= (m_Levels[lKeyPos] & ~LOG_FORCIBLY_SET)) {
  492. return TRUE;
  493. }
  494. }
  495. Mask <<= 1;
  496. }
  497. }
  498. return FALSE;
  499. }
  500. /* Set debug levels to a given value */
  501. void WINAPI DbgSetModuleLevel(DWORD Type, DWORD Level)
  502. {
  503. DWORD Mask = 0x01;
  504. for (LONG lKeyPos = 0;lKeyPos < iMAXLEVELS;lKeyPos++) {
  505. if (Type & Mask) {
  506. m_Levels[lKeyPos] = Level | LOG_FORCIBLY_SET;
  507. }
  508. Mask <<= 1;
  509. }
  510. }
  511. /* whether to check registry values periodically. this isn't turned
  512. automatically because of the potential performance hit. */
  513. void WINAPI DbgSetAutoRefreshLevels(bool fAuto)
  514. {
  515. g_fAutoRefreshLevels = fAuto;
  516. }
  517. #ifdef UNICODE
  518. //
  519. // warning -- this function is implemented twice for ansi applications
  520. // linking to the unicode library
  521. //
  522. void WINAPI DbgLogInfo(DWORD Type,DWORD Level,const CHAR *pFormat,...)
  523. {
  524. /* Check the current level for this type combination */
  525. BOOL bAccept = DbgCheckModuleLevel(Type,Level);
  526. if (bAccept == FALSE) {
  527. return;
  528. }
  529. TCHAR szInfo[2000];
  530. /* Format the variable length parameter list */
  531. va_list va;
  532. va_start(va, pFormat);
  533. lstrcpy(szInfo,m_ModuleName);
  534. wsprintf(szInfo + lstrlen(szInfo),
  535. TEXT("(tid %x) %8d : "),
  536. GetCurrentThreadId(), timeGetTime() - dwTimeOffset);
  537. CHAR szInfoA[2000];
  538. WideCharToMultiByte(CP_ACP, 0, szInfo, -1, szInfoA, NUMELMS(szInfoA), 0, 0);
  539. wvsprintfA(szInfoA + lstrlenA(szInfoA), pFormat, va);
  540. lstrcatA(szInfoA, "\r\n");
  541. WCHAR wszOutString[2000];
  542. MultiByteToWideChar(CP_ACP, 0, szInfoA, -1, wszOutString, NUMELMS(wszOutString));
  543. DbgOutString(wszOutString);
  544. va_end(va);
  545. }
  546. void DbgAssert(const CHAR *pCondition,const CHAR *pFileName,INT iLine)
  547. {
  548. if(g_fUseKASSERT)
  549. {
  550. DbgKernelAssert(pCondition, pFileName, iLine);
  551. }
  552. else
  553. {
  554. TCHAR szInfo[iDEBUGINFO];
  555. wsprintf(szInfo, TEXT("%hs \nAt line %d of %hs\nContinue? (Cancel to debug)"),
  556. pCondition, iLine, pFileName);
  557. INT MsgId = MessageBoxOtherThread(NULL,szInfo,TEXT("ASSERT Failed"),
  558. MB_SYSTEMMODAL |
  559. MB_ICONHAND |
  560. MB_YESNOCANCEL |
  561. MB_SETFOREGROUND);
  562. switch (MsgId)
  563. {
  564. case IDNO: /* Kill the application */
  565. FatalAppExit(FALSE, TEXT("Application terminated"));
  566. break;
  567. case IDCANCEL: /* Break into the debugger */
  568. DebugBreak();
  569. break;
  570. case IDYES: /* Ignore assertion continue execution */
  571. break;
  572. }
  573. }
  574. }
  575. /* Displays a message box at a break point */
  576. void WINAPI DbgBreakPoint(const CHAR *pCondition,const CHAR *pFileName,INT iLine)
  577. {
  578. if(g_fUseKASSERT)
  579. {
  580. DbgKernelAssert(pCondition, pFileName, iLine);
  581. }
  582. else
  583. {
  584. TCHAR szInfo[iDEBUGINFO];
  585. wsprintf(szInfo, TEXT("%hs \nAt line %d of %hs\nContinue? (Cancel to debug)"),
  586. pCondition, iLine, pFileName);
  587. INT MsgId = MessageBoxOtherThread(NULL,szInfo,TEXT("Hard coded break point"),
  588. MB_SYSTEMMODAL |
  589. MB_ICONHAND |
  590. MB_YESNOCANCEL |
  591. MB_SETFOREGROUND);
  592. switch (MsgId)
  593. {
  594. case IDNO: /* Kill the application */
  595. FatalAppExit(FALSE, TEXT("Application terminated"));
  596. break;
  597. case IDCANCEL: /* Break into the debugger */
  598. DebugBreak();
  599. break;
  600. case IDYES: /* Ignore break point continue execution */
  601. break;
  602. }
  603. }
  604. }
  605. void WINAPI DbgKernelAssert(const CHAR *pCondition,const CHAR *pFileName,INT iLine)
  606. {
  607. DbgLog((LOG_ERROR,0,TEXT("Assertion FAILED (%hs) at line %d in file %hs"),
  608. pCondition, iLine, pFileName));
  609. DebugBreak();
  610. }
  611. #endif
  612. /* Print a formatted string to the debugger prefixed with this module's name
  613. Because the COMBASE classes are linked statically every module loaded will
  614. have their own copy of this code. It therefore helps if the module name is
  615. included on the output so that the offending code can be easily found */
  616. //
  617. // warning -- this function is implemented twice for ansi applications
  618. // linking to the unicode library
  619. //
  620. void WINAPI DbgLogInfo(DWORD Type,DWORD Level,const TCHAR *pFormat,...)
  621. {
  622. /* Check the current level for this type combination */
  623. BOOL bAccept = DbgCheckModuleLevel(Type,Level);
  624. if (bAccept == FALSE) {
  625. return;
  626. }
  627. TCHAR szInfo[2000];
  628. /* Format the variable length parameter list */
  629. va_list va;
  630. va_start(va, pFormat);
  631. lstrcpy(szInfo,m_ModuleName);
  632. wsprintf(szInfo + lstrlen(szInfo),
  633. TEXT("(tid %x) %8d : "),
  634. GetCurrentThreadId(), timeGetTime() - dwTimeOffset);
  635. _vstprintf(szInfo + lstrlen(szInfo), pFormat, va);
  636. lstrcat(szInfo, TEXT("\r\n"));
  637. DbgOutString(szInfo);
  638. va_end(va);
  639. }
  640. /* If we are executing as a pure kernel filter we cannot display message
  641. boxes to the user, this provides an alternative which puts the error
  642. condition on the debugger output with a suitable eye catching message */
  643. void WINAPI DbgKernelAssert(const TCHAR *pCondition,const TCHAR *pFileName,INT iLine)
  644. {
  645. DbgLog((LOG_ERROR,0,TEXT("Assertion FAILED (%s) at line %d in file %s"),
  646. pCondition, iLine, pFileName));
  647. DebugBreak();
  648. }
  649. /* Each time we create an object derived from CBaseObject the constructor will
  650. call us to register the creation of the new object. We are passed a string
  651. description which we store away. We return a cookie that the constructor
  652. uses to identify the object when it is destroyed later on. We update the
  653. total number of active objects in the DLL mainly for debugging purposes */
  654. DWORD WINAPI DbgRegisterObjectCreation(const CHAR *szObjectName,
  655. const WCHAR *wszObjectName)
  656. {
  657. /* If this fires you have a mixed DEBUG/RETAIL build */
  658. ASSERT(!!szObjectName ^ !!wszObjectName);
  659. /* Create a place holder for this object description */
  660. ObjectDesc *pObject = new ObjectDesc;
  661. ASSERT(pObject);
  662. /* It is valid to pass a NULL object name */
  663. if (pObject == NULL) {
  664. return FALSE;
  665. }
  666. /* Check we have been initialised - we may not be initialised when we are
  667. being pulled in from an executable which has globally defined objects
  668. as they are created by the C++ run time before WinMain is called */
  669. if (m_bInit == FALSE) {
  670. DbgInitialise(GetModuleHandle(NULL));
  671. }
  672. /* Grab the list critical section */
  673. EnterCriticalSection(&m_CSDebug);
  674. /* If no name then default to UNKNOWN */
  675. if (!szObjectName && !wszObjectName) {
  676. szObjectName = pUnknownName;
  677. }
  678. /* Put the new description at the head of the list */
  679. pObject->m_szName = szObjectName;
  680. pObject->m_wszName = wszObjectName;
  681. pObject->m_dwCookie = ++m_dwNextCookie;
  682. pObject->m_pNext = pListHead;
  683. pListHead = pObject;
  684. m_dwObjectCount++;
  685. DWORD ObjectCookie = pObject->m_dwCookie;
  686. ASSERT(ObjectCookie);
  687. if(wszObjectName) {
  688. DbgLog((LOG_MEMORY,2,TEXT("Object created %d (%ls) %d Active"),
  689. pObject->m_dwCookie, wszObjectName, m_dwObjectCount));
  690. } else {
  691. DbgLog((LOG_MEMORY,2,TEXT("Object created %d (%hs) %d Active"),
  692. pObject->m_dwCookie, szObjectName, m_dwObjectCount));
  693. }
  694. LeaveCriticalSection(&m_CSDebug);
  695. return ObjectCookie;
  696. }
  697. /* This is called by the CBaseObject destructor when an object is about to be
  698. destroyed, we are passed the cookie we returned during construction that
  699. identifies this object. We scan the object list for a matching cookie and
  700. remove the object if successful. We also update the active object count */
  701. BOOL WINAPI DbgRegisterObjectDestruction(DWORD dwCookie)
  702. {
  703. /* Grab the list critical section */
  704. EnterCriticalSection(&m_CSDebug);
  705. ObjectDesc *pObject = pListHead;
  706. ObjectDesc *pPrevious = NULL;
  707. /* Scan the object list looking for a cookie match */
  708. while (pObject) {
  709. if (pObject->m_dwCookie == dwCookie) {
  710. break;
  711. }
  712. pPrevious = pObject;
  713. pObject = pObject->m_pNext;
  714. }
  715. if (pObject == NULL) {
  716. DbgBreak("Apparently destroying a bogus object");
  717. LeaveCriticalSection(&m_CSDebug);
  718. return FALSE;
  719. }
  720. /* Is the object at the head of the list */
  721. if (pPrevious == NULL) {
  722. pListHead = pObject->m_pNext;
  723. } else {
  724. pPrevious->m_pNext = pObject->m_pNext;
  725. }
  726. /* Delete the object and update the housekeeping information */
  727. m_dwObjectCount--;
  728. if(pObject->m_wszName) {
  729. DbgLog((LOG_MEMORY,2,TEXT("Object destroyed %d (%ls) %d Active"),
  730. pObject->m_dwCookie, pObject->m_wszName, m_dwObjectCount));
  731. } else {
  732. DbgLog((LOG_MEMORY,2,TEXT("Object destroyed %d (%hs) %d Active"),
  733. pObject->m_dwCookie, pObject->m_szName, m_dwObjectCount));
  734. }
  735. delete pObject;
  736. LeaveCriticalSection(&m_CSDebug);
  737. return TRUE;
  738. }
  739. /* This runs through the active object list displaying their details */
  740. void WINAPI DbgDumpObjectRegister()
  741. {
  742. TCHAR szInfo[iDEBUGINFO];
  743. /* Grab the list critical section */
  744. EnterCriticalSection(&m_CSDebug);
  745. ObjectDesc *pObject = pListHead;
  746. /* Scan the object list displaying the name and cookie */
  747. DbgLog((LOG_MEMORY,2,TEXT("")));
  748. DbgLog((LOG_MEMORY,2,TEXT(" ID Object Description")));
  749. DbgLog((LOG_MEMORY,2,TEXT("")));
  750. while (pObject) {
  751. if(pObject->m_wszName) {
  752. wsprintf(szInfo,TEXT("%5d (%8x) %30ls"),pObject->m_dwCookie, &pObject, pObject->m_wszName);
  753. } else {
  754. wsprintf(szInfo,TEXT("%5d (%8x) %30hs"),pObject->m_dwCookie, &pObject, pObject->m_szName);
  755. }
  756. DbgLog((LOG_MEMORY,2,szInfo));
  757. pObject = pObject->m_pNext;
  758. }
  759. wsprintf(szInfo,TEXT("Total object count %5d"),m_dwObjectCount);
  760. DbgLog((LOG_MEMORY,2,TEXT("")));
  761. DbgLog((LOG_MEMORY,1,szInfo));
  762. LeaveCriticalSection(&m_CSDebug);
  763. }
  764. /* Debug infinite wait stuff */
  765. DWORD WINAPI DbgWaitForSingleObject(HANDLE h)
  766. {
  767. DWORD dwWaitResult;
  768. do {
  769. dwWaitResult = WaitForSingleObject(h, dwWaitTimeout);
  770. ASSERT(dwWaitResult == WAIT_OBJECT_0);
  771. } while (dwWaitResult == WAIT_TIMEOUT);
  772. return dwWaitResult;
  773. }
  774. DWORD WINAPI DbgWaitForMultipleObjects(DWORD nCount,
  775. CONST HANDLE *lpHandles,
  776. BOOL bWaitAll)
  777. {
  778. DWORD dwWaitResult;
  779. do {
  780. dwWaitResult = WaitForMultipleObjects(nCount,
  781. lpHandles,
  782. bWaitAll,
  783. dwWaitTimeout);
  784. ASSERT((DWORD)(dwWaitResult - WAIT_OBJECT_0) < MAXIMUM_WAIT_OBJECTS);
  785. } while (dwWaitResult == WAIT_TIMEOUT);
  786. return dwWaitResult;
  787. }
  788. void WINAPI DbgSetWaitTimeout(DWORD dwTimeout)
  789. {
  790. dwWaitTimeout = dwTimeout;
  791. }
  792. #endif /* DEBUG */
  793. #ifdef _OBJBASE_H_
  794. /* Stuff for printing out our GUID names */
  795. GUID_STRING_ENTRY g_GuidNames[] = {
  796. #define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  797. { #name, { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } },
  798. #include <uuids.h>
  799. };
  800. CGuidNameList GuidNames;
  801. int g_cGuidNames = sizeof(g_GuidNames) / sizeof(g_GuidNames[0]);
  802. char *CGuidNameList::operator [] (const GUID &guid)
  803. {
  804. for (int i = 0; i < g_cGuidNames; i++) {
  805. if (g_GuidNames[i].guid == guid) {
  806. return g_GuidNames[i].szName;
  807. }
  808. }
  809. if (guid == GUID_NULL) {
  810. return "GUID_NULL";
  811. }
  812. // !!! add something to print FOURCC guids?
  813. // shouldn't this print the hex CLSID?
  814. return "Unknown GUID Name";
  815. }
  816. #endif /* _OBJBASE_H_ */
  817. /* CDisp class - display our data types */
  818. // clashes with REFERENCE_TIME
  819. CDisp::CDisp(LONGLONG ll, int Format)
  820. {
  821. // note: this could be combined with CDisp(LONGLONG) by
  822. // introducing a default format of CDISP_REFTIME
  823. LARGE_INTEGER li;
  824. li.QuadPart = ll;
  825. switch (Format) {
  826. case CDISP_DEC:
  827. {
  828. TCHAR temp[20];
  829. int pos=20;
  830. temp[--pos] = 0;
  831. int digit;
  832. // always output at least one digit
  833. do {
  834. // Get the rightmost digit - we only need the low word
  835. digit = li.LowPart % 10;
  836. li.QuadPart /= 10;
  837. temp[--pos] = (TCHAR) digit+L'0';
  838. } while (li.QuadPart);
  839. wsprintf(m_String, TEXT("%s"), temp+pos);
  840. break;
  841. }
  842. case CDISP_HEX:
  843. default:
  844. wsprintf(m_String, TEXT("0x%X%8.8X"), li.HighPart, li.LowPart);
  845. }
  846. };
  847. CDisp::CDisp(REFCLSID clsid)
  848. {
  849. WCHAR strClass[CHARS_IN_GUID+1];
  850. StringFromGUID2(clsid, strClass, sizeof(strClass) / sizeof(strClass[0]));
  851. ASSERT(sizeof(m_String)/sizeof(m_String[0]) >= CHARS_IN_GUID+1);
  852. wsprintf(m_String, TEXT("%ls"), strClass);
  853. };
  854. #ifdef __STREAMS__
  855. /* Display stuff */
  856. CDisp::CDisp(CRefTime llTime)
  857. {
  858. LPTSTR lpsz = m_String;
  859. LONGLONG llDiv;
  860. if (llTime < 0) {
  861. llTime = -llTime;
  862. lpsz += wsprintf(lpsz, TEXT("-"));
  863. }
  864. llDiv = (LONGLONG)24 * 3600 * 10000000;
  865. if (llTime >= llDiv) {
  866. lpsz += wsprintf(lpsz, TEXT("%d days "), (LONG)(llTime / llDiv));
  867. llTime = llTime % llDiv;
  868. }
  869. llDiv = (LONGLONG)3600 * 10000000;
  870. if (llTime >= llDiv) {
  871. lpsz += wsprintf(lpsz, TEXT("%d hrs "), (LONG)(llTime / llDiv));
  872. llTime = llTime % llDiv;
  873. }
  874. llDiv = (LONGLONG)60 * 10000000;
  875. if (llTime >= llDiv) {
  876. lpsz += wsprintf(lpsz, TEXT("%d mins "), (LONG)(llTime / llDiv));
  877. llTime = llTime % llDiv;
  878. }
  879. wsprintf(lpsz, TEXT("%d.%3.3d sec"),
  880. (LONG)llTime / 10000000,
  881. (LONG)((llTime % 10000000) / 10000));
  882. };
  883. #endif // __STREAMS__
  884. /* Display pin */
  885. CDisp::CDisp(IPin *pPin)
  886. {
  887. PIN_INFO pi;
  888. TCHAR str[MAX_PIN_NAME];
  889. CLSID clsid;
  890. if (pPin) {
  891. pPin->QueryPinInfo(&pi);
  892. pi.pFilter->GetClassID(&clsid);
  893. QueryPinInfoReleaseFilter(pi);
  894. #ifndef UNICODE
  895. WideCharToMultiByte(GetACP(), 0, pi.achName, lstrlenW(pi.achName) + 1,
  896. str, MAX_PIN_NAME, NULL, NULL);
  897. #else
  898. lstrcpy(str, pi.achName);
  899. #endif
  900. } else {
  901. lstrcpy(str, TEXT("NULL IPin"));
  902. }
  903. m_pString = (PTCHAR) new TCHAR[lstrlen(str)+64];
  904. if (!m_pString) {
  905. return;
  906. }
  907. wsprintf(m_pString, TEXT("%hs(%s)"), GuidNames[clsid], str);
  908. }
  909. /* Display filter or pin */
  910. CDisp::CDisp(IUnknown *pUnk)
  911. {
  912. IBaseFilter *pf;
  913. HRESULT hr = pUnk->QueryInterface(IID_IBaseFilter, (void **)&pf);
  914. if(SUCCEEDED(hr))
  915. {
  916. FILTER_INFO fi;
  917. hr = pf->QueryFilterInfo(&fi);
  918. if(SUCCEEDED(hr))
  919. {
  920. QueryFilterInfoReleaseGraph(fi);
  921. m_pString = new TCHAR[lstrlenW(fi.achName) + 1];
  922. if(m_pString)
  923. {
  924. wsprintf(m_pString, TEXT("%ls"), fi.achName);
  925. }
  926. }
  927. pf->Release();
  928. return;
  929. }
  930. IPin *pp;
  931. hr = pUnk->QueryInterface(IID_IPin, (void **)&pp);
  932. if(SUCCEEDED(hr))
  933. {
  934. CDisp::CDisp(pp);
  935. pp->Release();
  936. return;
  937. }
  938. }
  939. CDisp::~CDisp()
  940. {
  941. }
  942. CDispBasic::~CDispBasic()
  943. {
  944. if (m_pString != m_String) {
  945. delete [] m_pString;
  946. }
  947. }
  948. CDisp::CDisp(double d)
  949. {
  950. #ifdef DEBUG
  951. _stprintf(m_String, TEXT("%.16g"), d);
  952. #else
  953. wsprintf(m_String, TEXT("%d.%03d"), (int) d, (int) ((d - (int) d) * 1000));
  954. #endif
  955. }
  956. /* If built for debug this will display the media type details. We convert the
  957. major and subtypes into strings and also ask the base classes for a string
  958. description of the subtype, so MEDIASUBTYPE_RGB565 becomes RGB 565 16 bit
  959. We also display the fields in the BITMAPINFOHEADER structure, this should
  960. succeed as we do not accept input types unless the format is big enough */
  961. #ifdef DEBUG
  962. void WINAPI DisplayType(LPTSTR label, const AM_MEDIA_TYPE *pmtIn)
  963. {
  964. /* Dump the GUID types and a short description */
  965. DbgLog((LOG_TRACE,5,TEXT("")));
  966. DbgLog((LOG_TRACE,2,TEXT("%s M type %s S type %s"), label,
  967. GuidNames[pmtIn->majortype],
  968. GuidNames[pmtIn->subtype]));
  969. DbgLog((LOG_TRACE,5,TEXT("Subtype description %s"),GetSubtypeName(&pmtIn->subtype)));
  970. /* Dump the generic media types */
  971. if (pmtIn->bTemporalCompression) {
  972. DbgLog((LOG_TRACE,5,TEXT("Temporally compressed")));
  973. } else {
  974. DbgLog((LOG_TRACE,5,TEXT("Not temporally compressed")));
  975. }
  976. if (pmtIn->bFixedSizeSamples) {
  977. DbgLog((LOG_TRACE,5,TEXT("Sample size %d"),pmtIn->lSampleSize));
  978. } else {
  979. DbgLog((LOG_TRACE,5,TEXT("Variable size samples")));
  980. }
  981. if (pmtIn->formattype == FORMAT_VideoInfo) {
  982. /* Dump the contents of the BITMAPINFOHEADER structure */
  983. BITMAPINFOHEADER *pbmi = HEADER(pmtIn->pbFormat);
  984. VIDEOINFOHEADER *pVideoInfo = (VIDEOINFOHEADER *)pmtIn->pbFormat;
  985. DbgLog((LOG_TRACE,5,TEXT("Source rectangle (Left %d Top %d Right %d Bottom %d)"),
  986. pVideoInfo->rcSource.left,
  987. pVideoInfo->rcSource.top,
  988. pVideoInfo->rcSource.right,
  989. pVideoInfo->rcSource.bottom));
  990. DbgLog((LOG_TRACE,5,TEXT("Target rectangle (Left %d Top %d Right %d Bottom %d)"),
  991. pVideoInfo->rcTarget.left,
  992. pVideoInfo->rcTarget.top,
  993. pVideoInfo->rcTarget.right,
  994. pVideoInfo->rcTarget.bottom));
  995. DbgLog((LOG_TRACE,5,TEXT("Size of BITMAPINFO structure %d"),pbmi->biSize));
  996. if (pbmi->biCompression < 256) {
  997. DbgLog((LOG_TRACE,2,TEXT("%dx%dx%d bit (%d)"),
  998. pbmi->biWidth, pbmi->biHeight,
  999. pbmi->biBitCount, pbmi->biCompression));
  1000. } else {
  1001. DbgLog((LOG_TRACE,2,TEXT("%dx%dx%d bit '%4.4hs'"),
  1002. pbmi->biWidth, pbmi->biHeight,
  1003. pbmi->biBitCount, &pbmi->biCompression));
  1004. }
  1005. DbgLog((LOG_TRACE,2,TEXT("Image size %d"),pbmi->biSizeImage));
  1006. DbgLog((LOG_TRACE,5,TEXT("Planes %d"),pbmi->biPlanes));
  1007. DbgLog((LOG_TRACE,5,TEXT("X Pels per metre %d"),pbmi->biXPelsPerMeter));
  1008. DbgLog((LOG_TRACE,5,TEXT("Y Pels per metre %d"),pbmi->biYPelsPerMeter));
  1009. DbgLog((LOG_TRACE,5,TEXT("Colours used %d"),pbmi->biClrUsed));
  1010. } else if (pmtIn->majortype == MEDIATYPE_Audio) {
  1011. DbgLog((LOG_TRACE,2,TEXT(" Format type %hs"),
  1012. GuidNames[pmtIn->formattype]));
  1013. DbgLog((LOG_TRACE,2,TEXT(" Subtype %hs"),
  1014. GuidNames[pmtIn->subtype]));
  1015. if ((pmtIn->subtype != MEDIASUBTYPE_MPEG1Packet)
  1016. && (pmtIn->cbFormat >= sizeof(PCMWAVEFORMAT)))
  1017. {
  1018. /* Dump the contents of the WAVEFORMATEX type-specific format structure */
  1019. WAVEFORMATEX *pwfx = (WAVEFORMATEX *) pmtIn->pbFormat;
  1020. DbgLog((LOG_TRACE,2,TEXT("wFormatTag %u"), pwfx->wFormatTag));
  1021. DbgLog((LOG_TRACE,2,TEXT("nChannels %u"), pwfx->nChannels));
  1022. DbgLog((LOG_TRACE,2,TEXT("nSamplesPerSec %lu"), pwfx->nSamplesPerSec));
  1023. DbgLog((LOG_TRACE,2,TEXT("nAvgBytesPerSec %lu"), pwfx->nAvgBytesPerSec));
  1024. DbgLog((LOG_TRACE,2,TEXT("nBlockAlign %u"), pwfx->nBlockAlign));
  1025. DbgLog((LOG_TRACE,2,TEXT("wBitsPerSample %u"), pwfx->wBitsPerSample));
  1026. /* PCM uses a WAVEFORMAT and does not have the extra size field */
  1027. if (pmtIn->cbFormat >= sizeof(WAVEFORMATEX)) {
  1028. DbgLog((LOG_TRACE,2,TEXT("cbSize %u"), pwfx->cbSize));
  1029. }
  1030. } else {
  1031. }
  1032. } else {
  1033. DbgLog((LOG_TRACE,2,TEXT(" Format type %hs"),
  1034. GuidNames[pmtIn->formattype]));
  1035. // !!!! should add code to dump wave format, others
  1036. }
  1037. }
  1038. void WINAPI DumpGraph(IFilterGraph *pGraph, DWORD dwLevel)
  1039. {
  1040. if( !pGraph )
  1041. {
  1042. return;
  1043. }
  1044. IEnumFilters *pFilters;
  1045. DbgLog((LOG_TRACE,dwLevel,TEXT("DumpGraph [%x]"), pGraph));
  1046. if (FAILED(pGraph->EnumFilters(&pFilters))) {
  1047. DbgLog((LOG_TRACE,dwLevel,TEXT("EnumFilters failed!")));
  1048. }
  1049. IBaseFilter *pFilter;
  1050. ULONG n;
  1051. while (pFilters->Next(1, &pFilter, &n) == S_OK) {
  1052. FILTER_INFO info;
  1053. if (FAILED(pFilter->QueryFilterInfo(&info))) {
  1054. DbgLog((LOG_TRACE,dwLevel,TEXT(" Filter [%x] -- failed QueryFilterInfo"), pFilter));
  1055. } else {
  1056. QueryFilterInfoReleaseGraph(info);
  1057. // !!! should QueryVendorInfo here!
  1058. DbgLog((LOG_TRACE,dwLevel,TEXT(" Filter [%x] '%ls'"), pFilter, info.achName));
  1059. IEnumPins *pins;
  1060. if (FAILED(pFilter->EnumPins(&pins))) {
  1061. DbgLog((LOG_TRACE,dwLevel,TEXT("EnumPins failed!")));
  1062. } else {
  1063. IPin *pPin;
  1064. while (pins->Next(1, &pPin, &n) == S_OK) {
  1065. PIN_INFO info;
  1066. if (FAILED(pPin->QueryPinInfo(&info))) {
  1067. DbgLog((LOG_TRACE,dwLevel,TEXT(" Pin [%x] -- failed QueryPinInfo"), pPin));
  1068. } else {
  1069. QueryPinInfoReleaseFilter(info);
  1070. IPin *pPinConnected = NULL;
  1071. HRESULT hr = pPin->ConnectedTo(&pPinConnected);
  1072. if (pPinConnected) {
  1073. DbgLog((LOG_TRACE,dwLevel,TEXT(" Pin [%x] '%ls' [%sput]")
  1074. TEXT(" Connected to pin [%x]"),
  1075. pPin, info.achName,
  1076. info.dir == PINDIR_INPUT ? TEXT("In") : TEXT("Out"),
  1077. pPinConnected));
  1078. pPinConnected->Release();
  1079. // perhaps we should really dump the type both ways as a sanity
  1080. // check?
  1081. if (info.dir == PINDIR_OUTPUT) {
  1082. AM_MEDIA_TYPE mt;
  1083. hr = pPin->ConnectionMediaType(&mt);
  1084. if (SUCCEEDED(hr)) {
  1085. DisplayType(TEXT("Connection type"), &mt);
  1086. FreeMediaType(mt);
  1087. }
  1088. }
  1089. } else {
  1090. DbgLog((LOG_TRACE,dwLevel,
  1091. TEXT(" Pin [%x] '%ls' [%sput]"),
  1092. pPin, info.achName,
  1093. info.dir == PINDIR_INPUT ? TEXT("In") : TEXT("Out")));
  1094. }
  1095. }
  1096. pPin->Release();
  1097. }
  1098. pins->Release();
  1099. }
  1100. }
  1101. pFilter->Release();
  1102. }
  1103. pFilters->Release();
  1104. }
  1105. #endif