Leaked source code of windows server 2003
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.

2701 lines
92 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1999-2000
  4. *
  5. * TITLE: DShowUtl.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: OrenR
  10. *
  11. * DATE: 2000/10/25
  12. *
  13. * DESCRIPTION: Provides support functions for preview graph class
  14. *
  15. *****************************************************************************/
  16. #include <precomp.h>
  17. #include <atlconv.h>
  18. #pragma hdrstop
  19. ///////////////////////////////
  20. // Constants
  21. //
  22. const UINT FIND_FLAG_BY_ENUM_POS = 1;
  23. const UINT FIND_FLAG_BY_DSHOW_ID = 2;
  24. const UINT FIND_FLAG_BY_FRIENDLY_NAME = 3;
  25. //
  26. // These are values found in the registry, specified in the
  27. // DeviceData section of the vendor's INF file.
  28. //
  29. const TCHAR* REG_VAL_PREFERRED_MEDIASUBTYPE = _T("PreferredMediaSubType");
  30. const TCHAR* REG_VAL_PREFERRED_VIDEO_WIDTH = _T("PreferredVideoWidth");
  31. const TCHAR* REG_VAL_PREFERRED_VIDEO_HEIGHT = _T("PreferredVideoHeight");
  32. const TCHAR* REG_VAL_PREFERRED_VIDEO_FRAMERATE = _T("PreferredVideoFrameRate");
  33. ///////////////////////////////
  34. // SizeVideoToWindow
  35. //
  36. // Static Fn
  37. //
  38. HRESULT CDShowUtil::SizeVideoToWindow(HWND hwnd,
  39. IVideoWindow *pVideoWindow,
  40. BOOL bStretchToFit)
  41. {
  42. DBG_FN("CDShowUtil::SizeVideoToWindow");
  43. ASSERT(hwnd != NULL);
  44. ASSERT(pVideoWindow != NULL);
  45. RECT rc = {0};
  46. HRESULT hr = S_OK;
  47. //
  48. // Check for invalid args
  49. //
  50. if ((hwnd == NULL) ||
  51. (pVideoWindow == NULL))
  52. {
  53. hr = E_POINTER;
  54. CHECK_S_OK2(hr, ("CDShowUtil::SizeVideoToWindow received NULL pointer"));
  55. return hr;
  56. }
  57. //
  58. // Try to position preview window as best we
  59. // can in the context of the containing window
  60. //
  61. ::GetClientRect(hwnd, &rc);
  62. //
  63. // First, get ideal sizes (that won't incur scaling penalty)
  64. //
  65. LONG maxWidth = 0;
  66. LONG maxHeight = 0;
  67. LONG minWidth = 0;
  68. LONG minHeight = 0;
  69. LONG nativeWidth = 0;
  70. LONG nativeHeight = 0;
  71. LONG w = rc.right - rc.left;
  72. LONG h = rc.bottom - rc.top;
  73. BOOL bDone = FALSE;
  74. //
  75. // ***NOTE***
  76. //
  77. // Little known fact (i.e. not in MSDN)
  78. // 'GetMaxIdealSize' and 'GetMinIdealSize' will FAIL if the graph is
  79. // in the stopped state. Therefore, the graph must be in the paused
  80. // or in the playing state.
  81. //
  82. hr = pVideoWindow->GetMaxIdealImageSize(&maxWidth, &maxHeight);
  83. if (FAILED(hr))
  84. {
  85. maxWidth = w;
  86. maxHeight = h;
  87. DBG_WRN(("pVideoWindow->GetMaxIdealImageSize failed. "
  88. "This is a non-fatal error, setting our max video "
  89. "width '%lu' and height '%lu' to the window's "
  90. "boundaries", maxWidth, maxHeight));
  91. }
  92. hr = pVideoWindow->GetMinIdealImageSize(&minWidth, &minHeight);
  93. if (FAILED(hr))
  94. {
  95. minWidth = w;
  96. minHeight = h;
  97. DBG_WRN(("pVideoWindow->GetMinIdealImageSize failed. "
  98. "This is a non-fatal error, setting our minimum video "
  99. "width '%lu' and height '%lu' to the window's "
  100. "boundaries", maxWidth, maxHeight));
  101. }
  102. //
  103. // Now, get nominal size of preview
  104. //
  105. if (pVideoWindow)
  106. {
  107. CComPtr<IBasicVideo> pBasicVideo;
  108. hr = pVideoWindow->QueryInterface(IID_IBasicVideo,
  109. reinterpret_cast<void **>(&pBasicVideo));
  110. CHECK_S_OK2(hr, ("pVideoWindow->QueryInterface for IBasicVideo failed"));
  111. if (SUCCEEDED(hr) && pBasicVideo)
  112. {
  113. hr = pBasicVideo->GetVideoSize( &nativeWidth, &nativeHeight );
  114. CHECK_S_OK2(hr, ("pBasicVideo->GetVideoSize() failed" ));
  115. if (FAILED(hr))
  116. {
  117. nativeWidth = nativeHeight = 0;
  118. }
  119. }
  120. }
  121. if (bStretchToFit)
  122. {
  123. nativeWidth = w;
  124. nativeHeight = h;
  125. }
  126. //
  127. // Try native size first
  128. //
  129. if (nativeWidth && nativeHeight)
  130. {
  131. if ((nativeWidth <= w) && (nativeHeight <= h))
  132. {
  133. hr = pVideoWindow->SetWindowPosition((w - nativeWidth) / 2,
  134. (h - nativeHeight) / 2,
  135. nativeWidth,
  136. nativeHeight);
  137. CHECK_S_OK2( hr, ("pVideoWindow->SetWindowPosition( "
  138. "native size )"));
  139. bDone = TRUE;
  140. }
  141. }
  142. //
  143. // Don't scale outside of min/max range so we don't incur performance hit,
  144. // also, as we scale, keep the aspect ratio of the native size
  145. //
  146. if (!bDone)
  147. {
  148. INT x = 0;
  149. INT y = 0;
  150. INT _h = h;
  151. INT _w = w;
  152. //
  153. // cap (in both directions) for no loss of performance...
  154. //
  155. if ((_w > maxWidth) && (maxWidth <= w))
  156. {
  157. _w = maxWidth;
  158. }
  159. else if ((_w < minWidth) && (minWidth <= w))
  160. {
  161. _w = minWidth;
  162. }
  163. if ((_h > maxHeight) && (maxHeight <= h))
  164. {
  165. _h = maxHeight;
  166. }
  167. else if ((_h < minHeight) && (minHeight <= h))
  168. {
  169. _h = minHeight;
  170. }
  171. //
  172. // Notice that if the client window size is 0,0 then
  173. // the video will be set to that size. We will warn the
  174. // caller below in a warning statement, but if they want
  175. // to do that I'm not going to stop them.
  176. //
  177. //
  178. // Find the smallest axis
  179. //
  180. if (h < w)
  181. {
  182. //
  183. // Space is wider than tall
  184. //
  185. if (nativeHeight)
  186. {
  187. _w = ((_h * nativeWidth) / nativeHeight);
  188. }
  189. }
  190. else
  191. {
  192. //
  193. // Space is taller than wide
  194. //
  195. if (nativeWidth)
  196. {
  197. _h = ((nativeHeight * _w) / nativeWidth);
  198. }
  199. }
  200. x = ((w - _w) / 2);
  201. y = ((h - _h) / 2);
  202. if ((_w == 0) || (_h == 0))
  203. {
  204. DBG_WRN(("WARNING: CDShowUtils::SizeVideoToWindow "
  205. "video width and/or height is 0. This will "
  206. "result in video that is not visible. This is "
  207. "because the owning window dimensions are probably 0. "
  208. "Video -> Width:'%lu', Height:'%lu', Window -> "
  209. "Top:'%lu', Bottom:'%lu', Left:'%lu', Right:'%lu'",
  210. _w, _h, rc.top, rc.bottom, rc.left, rc.right));
  211. }
  212. hr = pVideoWindow->SetWindowPosition( x, y, _w, _h );
  213. CHECK_S_OK2(hr, ("pVideoWindow->SetWindowPosition to set the "
  214. "aspect scaled size failed"));
  215. }
  216. return hr;
  217. }
  218. ///////////////////////////////
  219. // ShowVideo
  220. //
  221. // Static Fn
  222. //
  223. HRESULT CDShowUtil::ShowVideo(BOOL bShow,
  224. IVideoWindow *pVideoWindow)
  225. {
  226. DBG_FN("CDShowUtil::ShowVideo");
  227. HRESULT hr = S_OK;
  228. if (pVideoWindow == NULL)
  229. {
  230. hr = E_POINTER;
  231. CHECK_S_OK2(hr, ("CDShowUtil::ShowVideo failed to show video "
  232. "successfully"));
  233. }
  234. if (hr == S_OK)
  235. {
  236. if (bShow)
  237. {
  238. //
  239. // We were told to show the preview window therefore we will show
  240. // it.
  241. //
  242. hr = pVideoWindow->put_Visible(OATRUE);
  243. CHECK_S_OK2(hr, ("pVideoWindow->put_Visible(OATRUE)"));
  244. hr = pVideoWindow->put_AutoShow(OATRUE);
  245. CHECK_S_OK2(hr, ("pVideoWindow->put_AutoShow(OATRUE)"));
  246. }
  247. else
  248. {
  249. //
  250. // We were told to hide the preview window.
  251. //
  252. pVideoWindow->put_Visible(OAFALSE);
  253. pVideoWindow->put_AutoShow(OAFALSE);
  254. }
  255. }
  256. return hr;
  257. }
  258. ///////////////////////////////
  259. // SetVideoWindowParent
  260. //
  261. // Static Fn
  262. //
  263. HRESULT CDShowUtil::SetVideoWindowParent(HWND hwndParent,
  264. IVideoWindow *pVideoWindow,
  265. LONG *plOldWindowStyle)
  266. {
  267. DBG_FN("CDShowUtil::SetVideoRendererParent");
  268. HRESULT hr = S_OK;
  269. if (pVideoWindow == NULL)
  270. {
  271. hr = E_POINTER;
  272. CHECK_S_OK2(hr, ("CDShowUtil::SetVideoWindowParent received NULL "
  273. "Param"));
  274. }
  275. else if (hwndParent && !IsWindow(hwndParent))
  276. {
  277. hr = E_INVALIDARG;
  278. CHECK_S_OK2(hr, ("CDShowUtil::SetVideoWindowParent received invalid "
  279. "hwnd = 0x%08x", hwndParent));
  280. }
  281. if (hr == S_OK)
  282. {
  283. if (!hwndParent)
  284. {
  285. //
  286. // Okay, we are setting the preview window to NULL, which
  287. // means we are disassociating it from its parent.
  288. //
  289. //
  290. // Reseting graph preview window
  291. //
  292. hr = pVideoWindow->put_Owner(NULL);
  293. CHECK_S_OK2(hr, ("pVideoWindow->put_Owner(NULL)"));
  294. if ((plOldWindowStyle) && (*plOldWindowStyle))
  295. {
  296. hr = pVideoWindow->put_WindowStyle(*plOldWindowStyle);
  297. CHECK_S_OK2(hr, ("pVideoWindow->put_WindowStyle"
  298. "(*plOldWindowStyle)"));
  299. }
  300. }
  301. else
  302. {
  303. LONG WinStyle;
  304. HRESULT hr2;
  305. //
  306. // Okay, we are giving the preview window a new parent
  307. //
  308. // Set the owning window
  309. //
  310. hr = pVideoWindow->put_Owner(PtrToUlong(hwndParent));
  311. CHECK_S_OK2(hr, ("pVideoWindow->putOwner( hwndParent )"));
  312. //
  313. // Set the style for the preview
  314. //
  315. //
  316. // First, store the window style so that we can restore it
  317. // when we disassociate the parent from the window
  318. //
  319. hr2 = pVideoWindow->get_WindowStyle(&WinStyle);
  320. CHECK_S_OK2(hr2, ("pVideoWindow->get_WindowStyle"
  321. "( pOldWindowStyle )"));
  322. //
  323. // Set the Video Renderer window so that it will be a child of
  324. // the parent window, i.e. it does not have a border etc.
  325. //
  326. if (plOldWindowStyle)
  327. {
  328. *plOldWindowStyle = WinStyle;
  329. }
  330. WinStyle &= ~WS_OVERLAPPEDWINDOW;
  331. WinStyle &= ~WS_CLIPCHILDREN;
  332. WinStyle |= WS_CHILD;
  333. hr2 = pVideoWindow->put_WindowStyle(WinStyle);
  334. CHECK_S_OK2(hr2, ("pVideoWindow->put_WindowStyle( WinStyle )"));
  335. }
  336. }
  337. return hr;
  338. }
  339. ///////////////////////////////
  340. // GetDeviceProperty
  341. //
  342. // Static Fn
  343. //
  344. HRESULT CDShowUtil::GetDeviceProperty(IPropertyBag *pPropertyBag,
  345. LPCWSTR pwszProperty,
  346. CSimpleString *pstrProperty)
  347. {
  348. DBG_FN("CDShowUtil::GetDeviceProperty");
  349. HRESULT hr = S_OK;
  350. ASSERT(pPropertyBag != NULL);
  351. ASSERT(pwszProperty != NULL);
  352. ASSERT(pstrProperty != NULL);
  353. VARIANT VarName;
  354. if ((pPropertyBag == NULL) ||
  355. (pwszProperty == NULL) ||
  356. (pstrProperty == NULL))
  357. {
  358. hr = E_POINTER;
  359. CHECK_S_OK2(hr, ("CDShowUtil::GetDeviceProperty received a NULL "
  360. "param"));
  361. }
  362. if (SUCCEEDED(hr))
  363. {
  364. VariantInit(&VarName);
  365. VarName.vt = VT_BSTR;
  366. hr = pPropertyBag->Read(pwszProperty, &VarName, 0);
  367. }
  368. if (SUCCEEDED(hr))
  369. {
  370. *pstrProperty = CSimpleStringConvert::NaturalString(
  371. CSimpleStringWide(VarName.bstrVal));
  372. VariantClear(&VarName);
  373. }
  374. return hr;
  375. }
  376. ///////////////////////////////
  377. // GetMonikerProperty
  378. //
  379. // Static Fn
  380. //
  381. HRESULT CDShowUtil::GetMonikerProperty(IMoniker *pMoniker,
  382. LPCWSTR pwszProperty,
  383. CSimpleString *pstrProperty)
  384. {
  385. DBG_FN("CDShowUtil::GetMonikerProperty");
  386. HRESULT hr = S_OK;
  387. VARIANT VarName;
  388. CComPtr<IPropertyBag> pPropertyBag;
  389. ASSERT(pMoniker != NULL);
  390. ASSERT(pwszProperty != NULL);
  391. ASSERT(pstrProperty != NULL);
  392. if ((pMoniker == NULL) ||
  393. (pwszProperty == NULL) ||
  394. (pstrProperty == NULL))
  395. {
  396. hr = E_POINTER;
  397. CHECK_S_OK2(hr, ("CDShowUtil::GetMonikerProperty received a "
  398. "NULL param"));
  399. }
  400. hr = pMoniker->BindToStorage(0,
  401. 0,
  402. IID_IPropertyBag,
  403. (void **)&pPropertyBag);
  404. CHECK_S_OK2(hr, ("CDShowUtil::GetMonikerProperty, BindToStorage failed"));
  405. if (hr == S_OK)
  406. {
  407. hr = GetDeviceProperty(pPropertyBag,
  408. pwszProperty,
  409. pstrProperty);
  410. CHECK_S_OK2(hr, ("CDShowUtil::GetMonikerProperty, failed "
  411. "to get device property '%ls'", pwszProperty));
  412. }
  413. return hr;
  414. }
  415. ///////////////////////////////
  416. // FindDeviceGeneric
  417. //
  418. // Given the device ID, we will
  419. // find all the remaining parameters.
  420. // If a parameter is NULL, that information
  421. // is not looked up.
  422. //
  423. //
  424. // Static Fn
  425. //
  426. HRESULT CDShowUtil::FindDeviceGeneric(UINT uiFindFlag,
  427. CSimpleString *pstrDShowDeviceID,
  428. LONG *plEnumPos,
  429. CSimpleString *pstrFriendlyName,
  430. IMoniker **ppDeviceMoniker)
  431. {
  432. DBG_FN("CDShowUtil::FindDeviceGeneric");
  433. HRESULT hr = S_OK;
  434. BOOL bFound = FALSE;
  435. LONG lPosNum = 0;
  436. CComPtr<ICreateDevEnum> pCreateDevEnum;
  437. CComPtr<IEnumMoniker> pEnumMoniker;
  438. if ((uiFindFlag == FIND_FLAG_BY_ENUM_POS) && (plEnumPos == NULL))
  439. {
  440. hr = E_POINTER;
  441. CHECK_S_OK2(hr, ("CDShow::FindDeviceGeneric requesting search by enum "
  442. "pos, but plEnumPos is NULL"));
  443. }
  444. else if ((uiFindFlag == FIND_FLAG_BY_DSHOW_ID) &&
  445. (pstrDShowDeviceID == NULL))
  446. {
  447. hr = E_POINTER;
  448. CHECK_S_OK2(hr, ("CDShow::FindDeviceGeneric requesting search by "
  449. "DShow ID, but pstrDShowDeviceID is NULL"));
  450. }
  451. else if ((uiFindFlag == FIND_FLAG_BY_FRIENDLY_NAME) &&
  452. (pstrFriendlyName == NULL))
  453. {
  454. hr = E_POINTER;
  455. CHECK_S_OK2(hr, ("CDShow::FindDeviceGeneric requesting search by "
  456. "friendly name, but pstrFriendlyName is NULL"));
  457. }
  458. if (hr == S_OK)
  459. {
  460. //
  461. // Create the device enumerator
  462. //
  463. hr = CoCreateInstance(CLSID_SystemDeviceEnum,
  464. NULL,
  465. CLSCTX_INPROC_SERVER,
  466. IID_ICreateDevEnum,
  467. (void**)&pCreateDevEnum);
  468. CHECK_S_OK2(hr, ("CDShowUtil::CreateCaptureFilter failed to create "
  469. "CLSID_SystemDeviceEnum enumerator"));
  470. }
  471. if (hr == S_OK)
  472. {
  473. hr = pCreateDevEnum->CreateClassEnumerator(
  474. CLSID_VideoInputDeviceCategory,
  475. &pEnumMoniker,
  476. 0);
  477. CHECK_S_OK2(hr, ("CDShowUtil::CreateCaptureFilter failed to "
  478. "create enumerator for Video Input Device "
  479. "Category"));
  480. }
  481. //
  482. // Loop through all the devices
  483. //
  484. while ((!bFound) && (hr == S_OK))
  485. {
  486. CComPtr<IMoniker> pMoniker;
  487. CComPtr<IPropertyBag> pPropertyBag;
  488. CSimpleString strDShowDeviceID(TEXT(""));
  489. CSimpleString strFriendlyName(TEXT(""));
  490. hr = pEnumMoniker->Next(1, &pMoniker, NULL);
  491. if (hr == S_OK)
  492. {
  493. //
  494. // Get property storage for this DS device so we can get it's
  495. // device id...
  496. //
  497. hr = pMoniker->BindToStorage(0,
  498. 0,
  499. IID_IPropertyBag,
  500. (void **)&pPropertyBag);
  501. CHECK_S_OK2(hr, ("CDShowUtil::FindDeviceGeneric, failed to "
  502. "bind to storage"));
  503. }
  504. if (hr == S_OK)
  505. {
  506. hr = GetDeviceProperty(pPropertyBag,
  507. L"DevicePath",
  508. &strDShowDeviceID);
  509. CHECK_S_OK2(hr, ("Failed to get DevicePath for DShow # '%lu",
  510. lPosNum));
  511. hr = GetDeviceProperty(pPropertyBag,
  512. L"FriendlyName",
  513. &strFriendlyName);
  514. CHECK_S_OK2(hr, ("Failed to get FriendlyName for DShow # '%lu",
  515. lPosNum));
  516. }
  517. //
  518. // This is the search criteria.
  519. //
  520. switch (uiFindFlag)
  521. {
  522. case FIND_FLAG_BY_ENUM_POS:
  523. if (lPosNum == *plEnumPos)
  524. {
  525. bFound = TRUE;
  526. }
  527. break;
  528. case FIND_FLAG_BY_DSHOW_ID:
  529. if (pstrDShowDeviceID->CompareNoCase(strDShowDeviceID) == 0)
  530. {
  531. bFound = TRUE;
  532. }
  533. break;
  534. case FIND_FLAG_BY_FRIENDLY_NAME:
  535. if (pstrFriendlyName->CompareNoCase(strFriendlyName) == 0)
  536. {
  537. bFound = TRUE;
  538. }
  539. break;
  540. default:
  541. hr = E_FAIL;
  542. break;
  543. }
  544. if (bFound)
  545. {
  546. if (pstrDShowDeviceID)
  547. {
  548. pstrDShowDeviceID->Assign(strDShowDeviceID);
  549. }
  550. if (pstrFriendlyName)
  551. {
  552. pstrFriendlyName->Assign(strFriendlyName);
  553. }
  554. if (plEnumPos)
  555. {
  556. *plEnumPos = lPosNum;
  557. }
  558. if (ppDeviceMoniker)
  559. {
  560. *ppDeviceMoniker = pMoniker;
  561. (*ppDeviceMoniker)->AddRef();
  562. }
  563. }
  564. else
  565. {
  566. ++lPosNum;
  567. }
  568. }
  569. if (!bFound)
  570. {
  571. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  572. }
  573. return hr;
  574. }
  575. ///////////////////////////////
  576. // FindDeviceByEnumPos
  577. //
  578. // Static Fn
  579. //
  580. HRESULT CDShowUtil::FindDeviceByEnumPos(LONG lEnumPos,
  581. CSimpleString *pstrDShowDeviceID,
  582. CSimpleString *pstrFriendlyName,
  583. IMoniker **ppDeviceMoniker)
  584. {
  585. DBG_FN("CDShowUtil::FindDeviceByEnumPos");
  586. HRESULT hr = S_OK;
  587. if (hr == S_OK)
  588. {
  589. hr = FindDeviceGeneric(FIND_FLAG_BY_ENUM_POS,
  590. pstrDShowDeviceID,
  591. &lEnumPos,
  592. pstrFriendlyName,
  593. ppDeviceMoniker);
  594. }
  595. CHECK_S_OK2(hr, ("CDShowUtil::FindDeviceByEnumPos failed to find a "
  596. "Directshow device with an enum position "
  597. "of '%lu'", lEnumPos));
  598. return hr;
  599. }
  600. ///////////////////////////////
  601. // FindDeviceByFriendlyName
  602. //
  603. // Static Fn
  604. //
  605. HRESULT CDShowUtil::FindDeviceByFriendlyName(
  606. const CSimpleString *pstrFriendlyName,
  607. LONG *plEnumPos,
  608. CSimpleString *pstrDShowDeviceID,
  609. IMoniker **ppDeviceMoniker)
  610. {
  611. DBG_FN("CDShowUtil::FindDeviceByFriendlyName");
  612. HRESULT hr = S_OK;
  613. ASSERT(pstrFriendlyName != NULL);
  614. if (pstrFriendlyName == NULL)
  615. {
  616. hr = E_POINTER;
  617. CHECK_S_OK2(hr, ("CDShowUtil::FindDeviceByFriendlyName received a "
  618. "NULL param"));
  619. return hr;
  620. }
  621. if (hr == S_OK)
  622. {
  623. hr = FindDeviceGeneric(FIND_FLAG_BY_FRIENDLY_NAME,
  624. pstrDShowDeviceID,
  625. plEnumPos,
  626. const_cast<CSimpleString*>(pstrFriendlyName),
  627. ppDeviceMoniker);
  628. }
  629. CHECK_S_OK2(hr, ("CDShowUtil::FindDeviceByFriendlyName failed to find a "
  630. "Directshow device named '%ls'",
  631. pstrFriendlyName->String()));
  632. return hr;
  633. }
  634. ///////////////////////////////
  635. // FindDeviceByWiaID
  636. //
  637. // Static Fn
  638. //
  639. HRESULT CDShowUtil::FindDeviceByWiaID(CWiaLink *pWiaLink,
  640. const CSimpleString *pstrWiaDeviceID,
  641. CSimpleString *pstrFriendlyName,
  642. LONG *plEnumPos,
  643. CSimpleString *pstrDShowDeviceID,
  644. IMoniker **ppDeviceMoniker)
  645. {
  646. DBG_FN("CDShowUtil::FindDeviceByWiaID");
  647. HRESULT hr = S_OK;
  648. CSimpleStringWide strDShowID(TEXT(""));
  649. CComPtr<IWiaPropertyStorage> pPropStorage;
  650. ASSERT(pWiaLink != NULL);
  651. ASSERT(pstrWiaDeviceID != NULL);
  652. if ((pWiaLink == NULL) ||
  653. (pstrWiaDeviceID == NULL))
  654. {
  655. hr = E_POINTER;
  656. CHECK_S_OK2(hr, ("CDShowUtil::FindDeviceByWiaID received a NULL "
  657. "param"));
  658. return hr;
  659. }
  660. if (hr == S_OK)
  661. {
  662. hr = pWiaLink->GetDeviceStorage(&pPropStorage);
  663. }
  664. if (hr == S_OK)
  665. {
  666. hr = CWiaUtil::GetProperty(pPropStorage,
  667. WIA_DPV_DSHOW_DEVICE_PATH,
  668. &strDShowID);
  669. }
  670. if (hr == S_OK)
  671. {
  672. //
  673. // If all three of these are NULL, then there is no point searching,
  674. // we already have the DShow device ID. On the other hand, if we
  675. // want at least one of them, then we need to find the device.
  676. //
  677. if ((pstrFriendlyName != NULL) ||
  678. (plEnumPos != NULL) ||
  679. (ppDeviceMoniker != NULL))
  680. {
  681. hr = FindDeviceGeneric(
  682. FIND_FLAG_BY_DSHOW_ID,
  683. &(CSimpleStringConvert::NaturalString(strDShowID)),
  684. plEnumPos,
  685. pstrFriendlyName,
  686. ppDeviceMoniker);
  687. }
  688. if (pstrDShowDeviceID)
  689. {
  690. *pstrDShowDeviceID = strDShowID;
  691. }
  692. }
  693. CHECK_S_OK2(hr, ("CDShowUtil::FindDeviceByWiaID failed to find a "
  694. "Directshow device with a WIA device ID of '%ls'",
  695. pstrWiaDeviceID->String()));
  696. return hr;
  697. }
  698. ///////////////////////////////
  699. // CreateGraphBuilder
  700. //
  701. //
  702. // Static Fn
  703. //
  704. HRESULT CDShowUtil::CreateGraphBuilder(
  705. ICaptureGraphBuilder2 **ppCaptureGraphBuilder,
  706. IGraphBuilder **ppGraphBuilder)
  707. {
  708. DBG_FN("CDShowUtil::CreateGraphBuilder");
  709. HRESULT hr = S_OK;
  710. ASSERT(ppCaptureGraphBuilder != NULL);
  711. ASSERT(ppGraphBuilder != NULL);
  712. if ((ppCaptureGraphBuilder == NULL) ||
  713. (ppGraphBuilder == NULL))
  714. {
  715. hr = E_POINTER;
  716. CHECK_S_OK2(hr, ("CDShowUtil::CreateGraphBuilder received NULL "
  717. "params"));
  718. return hr;
  719. }
  720. if (SUCCEEDED(hr))
  721. {
  722. //
  723. // First, get a CaptureGraph builder
  724. //
  725. hr = CoCreateInstance(CLSID_CaptureGraphBuilder2,
  726. NULL,
  727. CLSCTX_INPROC_SERVER,
  728. IID_ICaptureGraphBuilder2,
  729. (void**)ppCaptureGraphBuilder);
  730. CHECK_S_OK2( hr, ("CDShowUtil::CreateGraphBuilder, failed to create "
  731. "the DShow Capture Graph Builder object"));
  732. }
  733. if (SUCCEEDED(hr))
  734. {
  735. hr = CoCreateInstance(CLSID_FilterGraph,
  736. NULL,
  737. CLSCTX_INPROC_SERVER,
  738. IID_IGraphBuilder,
  739. (void**)ppGraphBuilder);
  740. CHECK_S_OK2( hr, ("CDShowUtil::CreateGraphBuilder, failed to create "
  741. "the DShow Filter Graph Object"));
  742. }
  743. if (SUCCEEDED(hr) && (*ppCaptureGraphBuilder) && (*ppGraphBuilder))
  744. {
  745. hr = (*ppCaptureGraphBuilder)->SetFiltergraph(*ppGraphBuilder);
  746. CHECK_S_OK2( hr, ("CDShowUtil::CreateGraphBuilder, failed to set "
  747. "the capture graph builder's filter graph object"));
  748. }
  749. return hr;
  750. }
  751. ///////////////////////////////
  752. // TurnOffGraphClock
  753. //
  754. // Turn off the clock that the
  755. // graph would use so that
  756. // the graph won't drop frames
  757. // if some frames are delivered
  758. // late.
  759. //
  760. //
  761. HRESULT CDShowUtil::TurnOffGraphClock(IGraphBuilder *pGraphBuilder)
  762. {
  763. DBG_FN("CDShowUtil::TurnOffGraphClock");
  764. ASSERT(pGraphBuilder != NULL);
  765. HRESULT hr = S_OK;
  766. CComPtr<IMediaFilter> pMediaFilter;
  767. if (pGraphBuilder == NULL)
  768. {
  769. hr = E_POINTER;
  770. CHECK_S_OK2(hr, ("CDShowUtil::TurnOffGraphClock received a NULL pointer"));
  771. }
  772. if (hr == S_OK)
  773. {
  774. hr = pGraphBuilder->QueryInterface(IID_IMediaFilter, (void**) &pMediaFilter);
  775. }
  776. if (hr == S_OK)
  777. {
  778. hr = pMediaFilter->SetSyncSource(NULL);
  779. }
  780. return hr;
  781. }
  782. ///////////////////////////////
  783. // SetPreferredVideoFormat
  784. //
  785. // This builds the preview graph
  786. // based on the device ID we
  787. // pass it.
  788. //
  789. HRESULT CDShowUtil::SetPreferredVideoFormat(IPin *pCapturePin,
  790. const GUID *pPreferredSubType,
  791. LONG lPreferredWidth,
  792. LONG lPreferredHeight,
  793. CWiaVideoProperties *pVideoProperties)
  794. {
  795. ASSERT(pCapturePin != NULL);
  796. ASSERT(pPreferredSubType != NULL);
  797. ASSERT(pVideoProperties != NULL);
  798. DBG_FN("CDShowUtil::SetPreferredVideoFormat");
  799. CComPtr<IAMStreamConfig> pStreamConfig;
  800. HRESULT hr = S_OK;
  801. INT iCount = 0;
  802. INT iSize = 0;
  803. INT iIndex = 0;
  804. BOOL bDone = FALSE;
  805. BYTE *pConfig = NULL;
  806. AM_MEDIA_TYPE *pMediaType = NULL;
  807. AM_MEDIA_TYPE *pFoundType = NULL;
  808. VIDEOINFOHEADER *pVideoInfo = NULL;
  809. //
  810. // Check for invalid parameters
  811. //
  812. if ((pCapturePin == NULL) ||
  813. (pPreferredSubType == NULL) ||
  814. (pVideoProperties == NULL))
  815. {
  816. hr = E_POINTER;
  817. CHECK_S_OK2(hr, ("ERROR: CDShowUtil::SetPreferredFormat "
  818. "received a NULL param"));
  819. }
  820. //
  821. // Attempt to get the stream config interface on this pin. Not
  822. // all capture filters will allow you to configure them, so if
  823. // this fails, we will just exit the function, and the BuildPreviewGraph
  824. // function will attempt to render the graph with the default settings
  825. // of the pin.
  826. //
  827. if (hr == S_OK)
  828. {
  829. hr = pCapturePin->QueryInterface(IID_IAMStreamConfig, (void**) &pStreamConfig);
  830. }
  831. //
  832. // We can configure this pin, so lets see how many options it has.
  833. //
  834. if (hr == S_OK)
  835. {
  836. hr = pStreamConfig->GetNumberOfCapabilities(&iCount, &iSize);
  837. }
  838. //
  839. // We need to alloc memory for the GetStreamCaps function below.
  840. //
  841. if (hr == S_OK)
  842. {
  843. pConfig = new BYTE[iSize];
  844. if (pConfig == NULL)
  845. {
  846. hr = E_OUTOFMEMORY;
  847. }
  848. }
  849. while ((hr == S_OK) && (iIndex < iCount) && (!bDone))
  850. {
  851. //
  852. // Clear out the memory
  853. //
  854. ZeroMemory(pConfig, iSize);
  855. //
  856. // Get the capabilities for the stream. There are iCount options,
  857. // we will iterate searching for the best one.
  858. //
  859. hr = pStreamConfig->GetStreamCaps(iIndex, &pMediaType, pConfig);
  860. if ((hr == S_OK) && (pMediaType))
  861. {
  862. pVideoInfo = NULL;
  863. //
  864. // We successfully got the media type, check to see if it is
  865. // a VideoInfo, if not we are not interested.
  866. //
  867. if (pMediaType->formattype == FORMAT_VideoInfo)
  868. {
  869. pVideoInfo = reinterpret_cast<VIDEOINFOHEADER*>(pMediaType->pbFormat);
  870. }
  871. if (pVideoInfo)
  872. {
  873. //
  874. // Check to see if this option contains the preferred settings we
  875. // are looking for.
  876. //
  877. if ((pMediaType->subtype == *pPreferredSubType) &&
  878. (pVideoInfo->bmiHeader.biWidth == lPreferredWidth) &&
  879. (pVideoInfo->bmiHeader.biHeight == lPreferredHeight))
  880. {
  881. //
  882. // Is this our ideal media type. That is, does it have the
  883. // preferred subtype we want and the preferred width and height.
  884. // If so, then great, we can't do better than this, so exit the loop.
  885. //
  886. if (pFoundType)
  887. {
  888. DeleteMediaType(pFoundType);
  889. pFoundType = NULL;
  890. }
  891. pFoundType = pMediaType;
  892. bDone = TRUE;
  893. }
  894. else if ((pVideoInfo->bmiHeader.biWidth == lPreferredWidth) &&
  895. (pVideoInfo->bmiHeader.biHeight == lPreferredHeight))
  896. {
  897. //
  898. // Okay, we found a media type with the width and height that
  899. // we would like, but we it doesn't have our preferred subtype.
  900. // So lets hang on to this media subtype, but continue looking,
  901. // maybe we will find something better. If we don't, then
  902. // we will use this media type anyway.
  903. //
  904. if (pFoundType)
  905. {
  906. DeleteMediaType(pFoundType);
  907. pFoundType = NULL;
  908. }
  909. pFoundType = pMediaType;
  910. }
  911. else
  912. {
  913. //
  914. // This media type is not even close to what we want, so
  915. // delete it and keep looking.
  916. //
  917. //
  918. DeleteMediaType(pMediaType);
  919. pMediaType = NULL;
  920. }
  921. }
  922. else
  923. {
  924. DeleteMediaType(pMediaType);
  925. pMediaType = NULL;
  926. }
  927. }
  928. ++iIndex;
  929. }
  930. //
  931. // Set the format on the output pin if we found a good one.
  932. //
  933. if (pFoundType)
  934. {
  935. WCHAR szGUID[CHARS_IN_GUID] = {0};
  936. GUIDToString(pFoundType->subtype, szGUID, sizeof(szGUID) / sizeof(WCHAR));
  937. DBG_TRC(("CDShowUtil::SetPreferredVideoFormat, setting "
  938. "capture pin's settings to MediaSubType = '%ls', "
  939. "Video Width = %lu, Video Height = %lu",
  940. szGUID, lPreferredWidth, lPreferredHeight));
  941. hr = pStreamConfig->SetFormat(pFoundType);
  942. //
  943. // ***Pay attention***
  944. //
  945. // We set the new media type in the pVideoProperties object. If
  946. // the media type is already set, we delete it first, then set a new
  947. // one.
  948. //
  949. if (hr == S_OK)
  950. {
  951. pVideoProperties->pVideoInfoHeader = NULL;
  952. if (pVideoProperties->pMediaType)
  953. {
  954. DeleteMediaType(pVideoProperties->pMediaType);
  955. }
  956. pVideoProperties->pMediaType = pFoundType;
  957. pVideoProperties->pVideoInfoHeader = reinterpret_cast<VIDEOINFOHEADER*>(pFoundType->pbFormat);
  958. }
  959. pFoundType = NULL;
  960. }
  961. delete [] pConfig;
  962. return hr;
  963. }
  964. ///////////////////////////////
  965. // GetFrameRate
  966. //
  967. HRESULT CDShowUtil::GetFrameRate(IPin *pCapturePin,
  968. LONG *plFrameRate)
  969. {
  970. HRESULT hr = S_OK;
  971. CComPtr<IAMStreamConfig> pStreamConfig;
  972. AM_MEDIA_TYPE *pMediaType = NULL;
  973. //
  974. // Check for invalid parameters
  975. //
  976. if ((pCapturePin == NULL) ||
  977. (plFrameRate == NULL))
  978. {
  979. hr = E_POINTER;
  980. CHECK_S_OK2(hr, ("ERROR: CDShowUtil::GetFrameRate "
  981. "received a NULL param"));
  982. }
  983. //
  984. // Attempt to get the stream config interface on this pin. Not
  985. // all capture filters will allow you to configure them, so if
  986. // this fails, we will just exit the function.
  987. //
  988. if (hr == S_OK)
  989. {
  990. hr = pCapturePin->QueryInterface(IID_IAMStreamConfig, (void**) &pStreamConfig);
  991. }
  992. if (hr == S_OK)
  993. {
  994. hr = pStreamConfig->GetFormat(&pMediaType);
  995. }
  996. if (hr == S_OK)
  997. {
  998. if (pMediaType->formattype == FORMAT_VideoInfo)
  999. {
  1000. VIDEOINFOHEADER *pHdr = reinterpret_cast<VIDEOINFOHEADER*>(pMediaType->pbFormat);
  1001. *plFrameRate = (LONG) (pHdr->AvgTimePerFrame / 10000000);
  1002. }
  1003. }
  1004. if (pMediaType)
  1005. {
  1006. DeleteMediaType(pMediaType);
  1007. }
  1008. return hr;
  1009. }
  1010. ///////////////////////////////
  1011. // SetFrameRate
  1012. //
  1013. HRESULT CDShowUtil::SetFrameRate(IPin *pCapturePin,
  1014. LONG lNewFrameRate,
  1015. CWiaVideoProperties *pVideoProperties)
  1016. {
  1017. HRESULT hr = S_OK;
  1018. CComPtr<IAMStreamConfig> pStreamConfig;
  1019. //
  1020. // Check for invalid parameters
  1021. //
  1022. if (pCapturePin == NULL)
  1023. {
  1024. hr = E_POINTER;
  1025. CHECK_S_OK2(hr, ("ERROR: CDShowUtil::SetFrameRate "
  1026. "received a NULL param"));
  1027. }
  1028. //
  1029. // Attempt to get the stream config interface on this pin. Not
  1030. // all capture filters will allow you to configure them, so if
  1031. // this fails, we will just exit the function.
  1032. //
  1033. if (hr == S_OK)
  1034. {
  1035. hr = pCapturePin->QueryInterface(IID_IAMStreamConfig, (void**) &pStreamConfig);
  1036. }
  1037. if (hr == S_OK)
  1038. {
  1039. AM_MEDIA_TYPE *pMediaType = NULL;
  1040. hr = pStreamConfig->GetFormat(&pMediaType);
  1041. if (hr == S_OK)
  1042. {
  1043. if (pMediaType->formattype == FORMAT_VideoInfo)
  1044. {
  1045. VIDEOINFOHEADER *pHdr = reinterpret_cast<VIDEOINFOHEADER*>(pMediaType->pbFormat);
  1046. pHdr->AvgTimePerFrame = (LONGLONG)(10000000 / lNewFrameRate);
  1047. hr = pStreamConfig->SetFormat(pMediaType);
  1048. if (hr == S_OK)
  1049. {
  1050. if (pVideoProperties)
  1051. {
  1052. pVideoProperties->dwFrameRate = lNewFrameRate;
  1053. }
  1054. }
  1055. else
  1056. {
  1057. DBG_WRN(("CDShowUtil::SetFrameRate, failed to set frame rate, "
  1058. "hr = %08lx, this is not fatal", hr));
  1059. }
  1060. }
  1061. }
  1062. if (pMediaType)
  1063. {
  1064. DeleteMediaType(pMediaType);
  1065. }
  1066. }
  1067. return hr;
  1068. }
  1069. ///////////////////////////////
  1070. // GetVideoProperties
  1071. //
  1072. HRESULT CDShowUtil::GetVideoProperties(IBaseFilter *pCaptureFilter,
  1073. IPin *pCapturePin,
  1074. CWiaVideoProperties *pVideoProperties)
  1075. {
  1076. USES_CONVERSION;
  1077. ASSERT(pCaptureFilter != NULL);
  1078. ASSERT(pCapturePin != NULL);
  1079. ASSERT(pVideoProperties != NULL);
  1080. HRESULT hr = S_OK;
  1081. CComPtr<IAMStreamConfig> pStreamConfig;
  1082. if ((pCaptureFilter == NULL) ||
  1083. (pCapturePin == NULL) ||
  1084. (pVideoProperties == NULL))
  1085. {
  1086. hr = E_POINTER;
  1087. CHECK_S_OK2(hr, ("CDShowUtil::GetVideoProperties received a NULL pointer"));
  1088. return hr;
  1089. }
  1090. if (hr == S_OK)
  1091. {
  1092. hr = pCapturePin->QueryInterface(IID_IAMStreamConfig, (void**) &pStreamConfig);
  1093. }
  1094. //
  1095. // Get the current AM_MEDIA_TYPE. Notice that we do not call DeleteMediaType. It is
  1096. // stored in the CWiaVideoProperties and deleted when the object is freed.
  1097. //
  1098. if (hr == S_OK)
  1099. {
  1100. hr = pStreamConfig->GetFormat(&pVideoProperties->pMediaType);
  1101. if (hr == S_OK)
  1102. {
  1103. if (pVideoProperties->pMediaType->formattype == FORMAT_VideoInfo)
  1104. {
  1105. pVideoProperties->pVideoInfoHeader = reinterpret_cast<VIDEOINFOHEADER*>(pVideoProperties->pMediaType->pbFormat);
  1106. }
  1107. }
  1108. CHECK_S_OK2(hr, ("CDShowUtil::GetVideoProperties, failed to get AM_MEDIA_TYPE"));
  1109. hr = S_OK;
  1110. }
  1111. //
  1112. // Get the frame rate.
  1113. //
  1114. if (hr == S_OK)
  1115. {
  1116. pVideoProperties->dwFrameRate = (DWORD) (pVideoProperties->pVideoInfoHeader->AvgTimePerFrame / 10000000);
  1117. }
  1118. //
  1119. // Get all the picture attributes we can.
  1120. //
  1121. if (hr == S_OK)
  1122. {
  1123. HRESULT hrRange = S_OK;
  1124. HRESULT hrValue = S_OK;
  1125. CComPtr<IAMVideoProcAmp> pVideoProcAmp;
  1126. hr = pCaptureFilter->QueryInterface(IID_IAMVideoProcAmp, (void**) &pVideoProcAmp);
  1127. if (pVideoProcAmp)
  1128. {
  1129. pVideoProperties->bPictureAttributesUsed = TRUE;
  1130. //
  1131. // Brightness
  1132. //
  1133. pVideoProperties->Brightness.Name = VideoProcAmp_Brightness;
  1134. hrRange = pVideoProcAmp->GetRange(pVideoProperties->Brightness.Name,
  1135. &pVideoProperties->Brightness.lMinValue,
  1136. &pVideoProperties->Brightness.lMaxValue,
  1137. &pVideoProperties->Brightness.lIncrement,
  1138. &pVideoProperties->Brightness.lDefaultValue,
  1139. (long*) &pVideoProperties->Brightness.ValidFlags);
  1140. hrValue = pVideoProcAmp->Get(pVideoProperties->Brightness.Name,
  1141. &pVideoProperties->Brightness.lCurrentValue,
  1142. (long*) &pVideoProperties->Brightness.CurrentFlag);
  1143. if ((hrRange != S_OK) || (hrValue != S_OK))
  1144. {
  1145. pVideoProperties->Brightness.bUsed = FALSE;
  1146. }
  1147. else
  1148. {
  1149. pVideoProperties->Brightness.bUsed = TRUE;
  1150. }
  1151. //
  1152. // Contrast
  1153. //
  1154. pVideoProperties->Contrast.Name = VideoProcAmp_Contrast;
  1155. hrRange = pVideoProcAmp->GetRange(pVideoProperties->Contrast.Name,
  1156. &pVideoProperties->Contrast.lMinValue,
  1157. &pVideoProperties->Contrast.lMaxValue,
  1158. &pVideoProperties->Contrast.lIncrement,
  1159. &pVideoProperties->Contrast.lDefaultValue,
  1160. (long*) &pVideoProperties->Contrast.ValidFlags);
  1161. hrValue = pVideoProcAmp->Get(pVideoProperties->Contrast.Name,
  1162. &pVideoProperties->Contrast.lCurrentValue,
  1163. (long*) &pVideoProperties->Contrast.CurrentFlag);
  1164. if ((hrRange != S_OK) || (hrValue != S_OK))
  1165. {
  1166. pVideoProperties->Contrast.bUsed = FALSE;
  1167. }
  1168. else
  1169. {
  1170. pVideoProperties->Contrast.bUsed = TRUE;
  1171. }
  1172. //
  1173. // Hue
  1174. //
  1175. pVideoProperties->Hue.Name = VideoProcAmp_Hue;
  1176. hrRange = pVideoProcAmp->GetRange(pVideoProperties->Hue.Name,
  1177. &pVideoProperties->Hue.lMinValue,
  1178. &pVideoProperties->Hue.lMaxValue,
  1179. &pVideoProperties->Hue.lIncrement,
  1180. &pVideoProperties->Hue.lDefaultValue,
  1181. (long*) &pVideoProperties->Hue.ValidFlags);
  1182. hrValue = pVideoProcAmp->Get(pVideoProperties->Hue.Name,
  1183. &pVideoProperties->Hue.lCurrentValue,
  1184. (long*) &pVideoProperties->Hue.CurrentFlag);
  1185. if ((hrRange != S_OK) || (hrValue != S_OK))
  1186. {
  1187. pVideoProperties->Hue.bUsed = FALSE;
  1188. }
  1189. else
  1190. {
  1191. pVideoProperties->Hue.bUsed = TRUE;
  1192. }
  1193. //
  1194. // Saturation
  1195. //
  1196. pVideoProperties->Saturation.Name = VideoProcAmp_Saturation;
  1197. hrRange = pVideoProcAmp->GetRange(pVideoProperties->Saturation.Name,
  1198. &pVideoProperties->Saturation.lMinValue,
  1199. &pVideoProperties->Saturation.lMaxValue,
  1200. &pVideoProperties->Saturation.lIncrement,
  1201. &pVideoProperties->Saturation.lDefaultValue,
  1202. (long*) &pVideoProperties->Saturation.ValidFlags);
  1203. hrValue = pVideoProcAmp->Get(pVideoProperties->Saturation.Name,
  1204. &pVideoProperties->Saturation.lCurrentValue,
  1205. (long*) &pVideoProperties->Saturation.CurrentFlag);
  1206. if ((hrRange != S_OK) || (hrValue != S_OK))
  1207. {
  1208. pVideoProperties->Saturation.bUsed = FALSE;
  1209. }
  1210. else
  1211. {
  1212. pVideoProperties->Saturation.bUsed = TRUE;
  1213. }
  1214. //
  1215. // Sharpness
  1216. //
  1217. pVideoProperties->Sharpness.Name = VideoProcAmp_Sharpness;
  1218. hrRange = pVideoProcAmp->GetRange(pVideoProperties->Sharpness.Name,
  1219. &pVideoProperties->Sharpness.lMinValue,
  1220. &pVideoProperties->Sharpness.lMaxValue,
  1221. &pVideoProperties->Sharpness.lIncrement,
  1222. &pVideoProperties->Sharpness.lDefaultValue,
  1223. (long*) &pVideoProperties->Sharpness.ValidFlags);
  1224. hrValue = pVideoProcAmp->Get(pVideoProperties->Sharpness.Name,
  1225. &pVideoProperties->Sharpness.lCurrentValue,
  1226. (long*) &pVideoProperties->Sharpness.CurrentFlag);
  1227. if ((hrRange != S_OK) || (hrValue != S_OK))
  1228. {
  1229. pVideoProperties->Sharpness.bUsed = FALSE;
  1230. }
  1231. else
  1232. {
  1233. pVideoProperties->Sharpness.bUsed = TRUE;
  1234. }
  1235. //
  1236. // Gamma
  1237. //
  1238. pVideoProperties->Gamma.Name = VideoProcAmp_Gamma;
  1239. hrRange = pVideoProcAmp->GetRange(pVideoProperties->Gamma.Name,
  1240. &pVideoProperties->Gamma.lMinValue,
  1241. &pVideoProperties->Gamma.lMaxValue,
  1242. &pVideoProperties->Gamma.lIncrement,
  1243. &pVideoProperties->Gamma.lDefaultValue,
  1244. (long*) &pVideoProperties->Gamma.ValidFlags);
  1245. hrValue = pVideoProcAmp->Get(pVideoProperties->Gamma.Name,
  1246. &pVideoProperties->Gamma.lCurrentValue,
  1247. (long*) &pVideoProperties->Gamma.CurrentFlag);
  1248. if ((hrRange != S_OK) || (hrValue != S_OK))
  1249. {
  1250. pVideoProperties->Gamma.bUsed = FALSE;
  1251. }
  1252. else
  1253. {
  1254. pVideoProperties->Gamma.bUsed = TRUE;
  1255. }
  1256. //
  1257. // ColorEnable
  1258. //
  1259. pVideoProperties->ColorEnable.Name = VideoProcAmp_ColorEnable;
  1260. hrRange = pVideoProcAmp->GetRange(pVideoProperties->ColorEnable.Name,
  1261. &pVideoProperties->ColorEnable.lMinValue,
  1262. &pVideoProperties->ColorEnable.lMaxValue,
  1263. &pVideoProperties->ColorEnable.lIncrement,
  1264. &pVideoProperties->ColorEnable.lDefaultValue,
  1265. (long*) &pVideoProperties->ColorEnable.ValidFlags);
  1266. hrValue = pVideoProcAmp->Get(pVideoProperties->ColorEnable.Name,
  1267. &pVideoProperties->ColorEnable.lCurrentValue,
  1268. (long*) &pVideoProperties->ColorEnable.CurrentFlag);
  1269. if ((hrRange != S_OK) || (hrValue != S_OK))
  1270. {
  1271. pVideoProperties->ColorEnable.bUsed = FALSE;
  1272. }
  1273. else
  1274. {
  1275. pVideoProperties->ColorEnable.bUsed = TRUE;
  1276. }
  1277. //
  1278. // WhiteBalance
  1279. //
  1280. pVideoProperties->WhiteBalance.Name = VideoProcAmp_WhiteBalance;
  1281. hrRange = pVideoProcAmp->GetRange(pVideoProperties->WhiteBalance.Name,
  1282. &pVideoProperties->WhiteBalance.lMinValue,
  1283. &pVideoProperties->WhiteBalance.lMaxValue,
  1284. &pVideoProperties->WhiteBalance.lIncrement,
  1285. &pVideoProperties->WhiteBalance.lDefaultValue,
  1286. (long*) &pVideoProperties->WhiteBalance.ValidFlags);
  1287. hrValue = pVideoProcAmp->Get(pVideoProperties->WhiteBalance.Name,
  1288. &pVideoProperties->WhiteBalance.lCurrentValue,
  1289. (long*) &pVideoProperties->WhiteBalance.CurrentFlag);
  1290. if ((hrRange != S_OK) || (hrValue != S_OK))
  1291. {
  1292. pVideoProperties->WhiteBalance.bUsed = FALSE;
  1293. }
  1294. else
  1295. {
  1296. pVideoProperties->WhiteBalance.bUsed = TRUE;
  1297. }
  1298. //
  1299. // BacklightCompensation
  1300. //
  1301. pVideoProperties->BacklightCompensation.Name = VideoProcAmp_BacklightCompensation;
  1302. hrRange = pVideoProcAmp->GetRange(pVideoProperties->BacklightCompensation.Name,
  1303. &pVideoProperties->BacklightCompensation.lMinValue,
  1304. &pVideoProperties->BacklightCompensation.lMaxValue,
  1305. &pVideoProperties->BacklightCompensation.lIncrement,
  1306. &pVideoProperties->BacklightCompensation.lDefaultValue,
  1307. (long*) &pVideoProperties->BacklightCompensation.ValidFlags);
  1308. hrValue = pVideoProcAmp->Get(pVideoProperties->BacklightCompensation.Name,
  1309. &pVideoProperties->BacklightCompensation.lCurrentValue,
  1310. (long*) &pVideoProperties->BacklightCompensation.CurrentFlag);
  1311. if ((hrRange != S_OK) || (hrValue != S_OK))
  1312. {
  1313. pVideoProperties->BacklightCompensation.bUsed = FALSE;
  1314. }
  1315. else
  1316. {
  1317. pVideoProperties->BacklightCompensation.bUsed = TRUE;
  1318. }
  1319. }
  1320. else
  1321. {
  1322. pVideoProperties->bPictureAttributesUsed = FALSE;
  1323. }
  1324. hr = S_OK;
  1325. }
  1326. //
  1327. // Get all the camera attributes we can.
  1328. //
  1329. if (hr == S_OK)
  1330. {
  1331. HRESULT hrRange = S_OK;
  1332. HRESULT hrValue = S_OK;
  1333. CComPtr<IAMCameraControl> pCameraControl;
  1334. hr = pCaptureFilter->QueryInterface(IID_IAMCameraControl, (void**) &pCameraControl);
  1335. if (pCameraControl)
  1336. {
  1337. pVideoProperties->bCameraAttributesUsed = TRUE;
  1338. //
  1339. // Pan
  1340. //
  1341. pVideoProperties->Pan.Name = CameraControl_Pan;
  1342. hrRange = pCameraControl->GetRange(pVideoProperties->Pan.Name,
  1343. &pVideoProperties->Pan.lMinValue,
  1344. &pVideoProperties->Pan.lMaxValue,
  1345. &pVideoProperties->Pan.lIncrement,
  1346. &pVideoProperties->Pan.lDefaultValue,
  1347. (long*) &pVideoProperties->Pan.ValidFlags);
  1348. hrValue = pCameraControl->Get(pVideoProperties->Pan.Name,
  1349. &pVideoProperties->Pan.lCurrentValue,
  1350. (long*) &pVideoProperties->Pan.CurrentFlag);
  1351. if ((hrRange != S_OK) || (hrValue != S_OK))
  1352. {
  1353. pVideoProperties->Pan.bUsed = FALSE;
  1354. }
  1355. else
  1356. {
  1357. pVideoProperties->Pan.bUsed = TRUE;
  1358. }
  1359. //
  1360. // Tilt
  1361. //
  1362. pVideoProperties->Tilt.Name = CameraControl_Tilt;
  1363. hrRange = pCameraControl->GetRange(pVideoProperties->Tilt.Name,
  1364. &pVideoProperties->Tilt.lMinValue,
  1365. &pVideoProperties->Tilt.lMaxValue,
  1366. &pVideoProperties->Tilt.lIncrement,
  1367. &pVideoProperties->Tilt.lDefaultValue,
  1368. (long*) &pVideoProperties->Tilt.ValidFlags);
  1369. hrValue = pCameraControl->Get(pVideoProperties->Tilt.Name,
  1370. &pVideoProperties->Tilt.lCurrentValue,
  1371. (long*) &pVideoProperties->Tilt.CurrentFlag);
  1372. if ((hrRange != S_OK) || (hrValue != S_OK))
  1373. {
  1374. pVideoProperties->Tilt.bUsed = FALSE;
  1375. }
  1376. else
  1377. {
  1378. pVideoProperties->Tilt.bUsed = TRUE;
  1379. }
  1380. //
  1381. // Roll
  1382. //
  1383. pVideoProperties->Roll.Name = CameraControl_Roll;
  1384. hrRange = pCameraControl->GetRange(pVideoProperties->Roll.Name,
  1385. &pVideoProperties->Roll.lMinValue,
  1386. &pVideoProperties->Roll.lMaxValue,
  1387. &pVideoProperties->Roll.lIncrement,
  1388. &pVideoProperties->Roll.lDefaultValue,
  1389. (long*) &pVideoProperties->Roll.ValidFlags);
  1390. hrValue = pCameraControl->Get(pVideoProperties->Roll.Name,
  1391. &pVideoProperties->Roll.lCurrentValue,
  1392. (long*) &pVideoProperties->Roll.CurrentFlag);
  1393. if ((hrRange != S_OK) || (hrValue != S_OK))
  1394. {
  1395. pVideoProperties->Roll.bUsed = FALSE;
  1396. }
  1397. else
  1398. {
  1399. pVideoProperties->Roll.bUsed = TRUE;
  1400. }
  1401. //
  1402. // Zoom
  1403. //
  1404. pVideoProperties->Zoom.Name = CameraControl_Zoom;
  1405. hrRange = pCameraControl->GetRange(pVideoProperties->Zoom.Name,
  1406. &pVideoProperties->Zoom.lMinValue,
  1407. &pVideoProperties->Zoom.lMaxValue,
  1408. &pVideoProperties->Zoom.lIncrement,
  1409. &pVideoProperties->Zoom.lDefaultValue,
  1410. (long*) &pVideoProperties->Zoom.ValidFlags);
  1411. hrValue = pCameraControl->Get(pVideoProperties->Zoom.Name,
  1412. &pVideoProperties->Zoom.lCurrentValue,
  1413. (long*) &pVideoProperties->Zoom.CurrentFlag);
  1414. if ((hrRange != S_OK) || (hrValue != S_OK))
  1415. {
  1416. pVideoProperties->Zoom.bUsed = FALSE;
  1417. }
  1418. else
  1419. {
  1420. pVideoProperties->Zoom.bUsed = TRUE;
  1421. }
  1422. //
  1423. // Exposure
  1424. //
  1425. pVideoProperties->Exposure.Name = CameraControl_Exposure;
  1426. hrRange = pCameraControl->GetRange(pVideoProperties->Exposure.Name,
  1427. &pVideoProperties->Exposure.lMinValue,
  1428. &pVideoProperties->Exposure.lMaxValue,
  1429. &pVideoProperties->Exposure.lIncrement,
  1430. &pVideoProperties->Exposure.lDefaultValue,
  1431. (long*) &pVideoProperties->Exposure.ValidFlags);
  1432. hrValue = pCameraControl->Get(pVideoProperties->Exposure.Name,
  1433. &pVideoProperties->Exposure.lCurrentValue,
  1434. (long*) &pVideoProperties->Exposure.CurrentFlag);
  1435. if ((hrRange != S_OK) || (hrValue != S_OK))
  1436. {
  1437. pVideoProperties->Exposure.bUsed = FALSE;
  1438. }
  1439. else
  1440. {
  1441. pVideoProperties->Exposure.bUsed = TRUE;
  1442. }
  1443. //
  1444. // Iris
  1445. //
  1446. pVideoProperties->Iris.Name = CameraControl_Iris;
  1447. hrRange = pCameraControl->GetRange(pVideoProperties->Iris.Name,
  1448. &pVideoProperties->Iris.lMinValue,
  1449. &pVideoProperties->Iris.lMaxValue,
  1450. &pVideoProperties->Iris.lIncrement,
  1451. &pVideoProperties->Iris.lDefaultValue,
  1452. (long*) &pVideoProperties->Iris.ValidFlags);
  1453. hrValue = pCameraControl->Get(pVideoProperties->Iris.Name,
  1454. &pVideoProperties->Iris.lCurrentValue,
  1455. (long*) &pVideoProperties->Iris.CurrentFlag);
  1456. if ((hrRange != S_OK) || (hrValue != S_OK))
  1457. {
  1458. pVideoProperties->Iris.bUsed = FALSE;
  1459. }
  1460. else
  1461. {
  1462. pVideoProperties->Iris.bUsed = TRUE;
  1463. }
  1464. //
  1465. // Focus
  1466. //
  1467. pVideoProperties->Focus.Name = CameraControl_Focus;
  1468. hrRange = pCameraControl->GetRange(pVideoProperties->Focus.Name,
  1469. &pVideoProperties->Focus.lMinValue,
  1470. &pVideoProperties->Focus.lMaxValue,
  1471. &pVideoProperties->Focus.lIncrement,
  1472. &pVideoProperties->Focus.lDefaultValue,
  1473. (long*) &pVideoProperties->Focus.ValidFlags);
  1474. hrValue = pCameraControl->Get(pVideoProperties->Focus.Name,
  1475. &pVideoProperties->Focus.lCurrentValue,
  1476. (long*) &pVideoProperties->Focus.CurrentFlag);
  1477. if ((hrRange != S_OK) || (hrValue != S_OK))
  1478. {
  1479. pVideoProperties->Focus.bUsed = FALSE;
  1480. }
  1481. else
  1482. {
  1483. pVideoProperties->Focus.bUsed = TRUE;
  1484. }
  1485. }
  1486. else
  1487. {
  1488. pVideoProperties->bCameraAttributesUsed = FALSE;
  1489. }
  1490. hr = S_OK;
  1491. }
  1492. if (pVideoProperties->szWiaDeviceID[0] != 0)
  1493. {
  1494. CComPtr<IStillImage> pSti = NULL;
  1495. TCHAR szGUID[CHARS_IN_GUID + 1] = {0};
  1496. pVideoProperties->PreferredSettingsMask = 0;
  1497. hr = StiCreateInstance(_Module.GetModuleInstance(),
  1498. STI_VERSION,
  1499. &pSti,
  1500. NULL);
  1501. if (hr == S_OK)
  1502. {
  1503. DWORD dwType = REG_DWORD;
  1504. DWORD dwSize = sizeof(pVideoProperties->PreferredWidth);
  1505. hr = pSti->GetDeviceValue(T2W(pVideoProperties->szWiaDeviceID),
  1506. T2W((TCHAR*)REG_VAL_PREFERRED_VIDEO_WIDTH),
  1507. &dwType,
  1508. (BYTE*) &pVideoProperties->PreferredWidth,
  1509. &dwSize);
  1510. if (hr == S_OK)
  1511. {
  1512. dwSize = sizeof(pVideoProperties->PreferredHeight);
  1513. hr = pSti->GetDeviceValue(T2W(pVideoProperties->szWiaDeviceID),
  1514. T2W((TCHAR*) REG_VAL_PREFERRED_VIDEO_HEIGHT),
  1515. &dwType,
  1516. (BYTE*) &pVideoProperties->PreferredHeight,
  1517. &dwSize);
  1518. }
  1519. if (hr == S_OK)
  1520. {
  1521. pVideoProperties->PreferredSettingsMask |= PREFERRED_SETTING_MASK_VIDEO_WIDTH_HEIGHT;
  1522. }
  1523. hr = S_OK;
  1524. }
  1525. if (hr == S_OK)
  1526. {
  1527. DWORD dwType = REG_SZ;
  1528. DWORD dwSize = sizeof(szGUID);
  1529. hr = pSti->GetDeviceValue(T2W(pVideoProperties->szWiaDeviceID),
  1530. T2W((TCHAR*)REG_VAL_PREFERRED_MEDIASUBTYPE),
  1531. &dwType,
  1532. (BYTE*) szGUID,
  1533. &dwSize);
  1534. if (hr == S_OK)
  1535. {
  1536. CLSIDFromString(T2OLE(szGUID), &pVideoProperties->PreferredMediaSubType);
  1537. pVideoProperties->PreferredSettingsMask |= PREFERRED_SETTING_MASK_MEDIASUBTYPE;
  1538. }
  1539. hr = S_OK;
  1540. }
  1541. if (hr == S_OK)
  1542. {
  1543. DWORD dwType = REG_SZ;
  1544. DWORD dwSize = sizeof(pVideoProperties->PreferredFrameRate);
  1545. hr = pSti->GetDeviceValue(T2W(pVideoProperties->szWiaDeviceID),
  1546. T2W((TCHAR*) REG_VAL_PREFERRED_VIDEO_FRAMERATE),
  1547. &dwType,
  1548. (BYTE*) &pVideoProperties->PreferredFrameRate,
  1549. &dwSize);
  1550. if (hr == S_OK)
  1551. {
  1552. pVideoProperties->PreferredSettingsMask |= PREFERRED_SETTING_MASK_VIDEO_FRAMERATE;
  1553. }
  1554. hr = S_OK;
  1555. }
  1556. DBG_TRC(("Settings found for Device '%ls' in DeviceData section of INF file",
  1557. pVideoProperties->szWiaDeviceID));
  1558. DBG_PRT((" PreferredVideoWidth = '%lu', Is In INF and value is of type REG_DWORD? '%ls'",
  1559. pVideoProperties->PreferredWidth,
  1560. (pVideoProperties->PreferredSettingsMask &
  1561. PREFERRED_SETTING_MASK_VIDEO_WIDTH_HEIGHT) ? _T("TRUE") : _T("FALSE")));
  1562. DBG_PRT((" PreferredVideoHeight = '%lu', Is In INF and value is of type REG_DWORD? '%ls'",
  1563. pVideoProperties->PreferredHeight,
  1564. (pVideoProperties->PreferredSettingsMask &
  1565. PREFERRED_SETTING_MASK_VIDEO_WIDTH_HEIGHT) ? _T("TRUE") : _T("FALSE")));
  1566. DBG_PRT((" PreferredVideoFrameRate = '%lu', Is In INF and value is of type REG_DWORD? '%ls'",
  1567. pVideoProperties->PreferredFrameRate,
  1568. (pVideoProperties->PreferredSettingsMask &
  1569. PREFERRED_SETTING_MASK_VIDEO_FRAMERATE) ? _T("TRUE") : _T("FALSE")));
  1570. DBG_PRT((" PreferredMediaSubType = '%ls', Is In INF and value is of type REG_SZ? '%ls'",
  1571. szGUID,
  1572. (pVideoProperties->PreferredSettingsMask &
  1573. PREFERRED_SETTING_MASK_MEDIASUBTYPE) ? _T("TRUE") : _T("FALSE")));
  1574. }
  1575. return hr;
  1576. }
  1577. ///////////////////////////////
  1578. // SetPictureAttribute
  1579. //
  1580. HRESULT CDShowUtil::SetPictureAttribute(IBaseFilter *pCaptureFilter,
  1581. CWiaVideoProperties::PictureAttribute_t *pPictureAttribute,
  1582. LONG lNewValue,
  1583. VideoProcAmpFlags lNewFlag)
  1584. {
  1585. ASSERT(pCaptureFilter != NULL);
  1586. ASSERT(pPictureAttribute != NULL);
  1587. HRESULT hr = S_OK;
  1588. CComPtr<IAMVideoProcAmp> pVideoProcAmp;
  1589. if ((pCaptureFilter == NULL) ||
  1590. (pPictureAttribute == NULL))
  1591. {
  1592. hr = E_POINTER;
  1593. CHECK_S_OK2(hr, ("CDShowUtil::SetPictureAttribute, received a NULL pointer"));
  1594. return hr;
  1595. }
  1596. if (hr == S_OK)
  1597. {
  1598. hr = pCaptureFilter->QueryInterface(IID_IAMVideoProcAmp, (void**) &pVideoProcAmp);
  1599. }
  1600. if (hr == S_OK)
  1601. {
  1602. if (pPictureAttribute->bUsed)
  1603. {
  1604. //
  1605. // Attempt to set the new value for the property.
  1606. //
  1607. hr = pVideoProcAmp->Set(pPictureAttribute->Name,
  1608. lNewValue,
  1609. (long) lNewFlag);
  1610. //
  1611. // If we successfully set the new value, then get it again. We do this
  1612. // in case the capture filter decided to change the values a little upon
  1613. // setting them (it shouldn't, but each filter could act differently)
  1614. //
  1615. if (hr == S_OK)
  1616. {
  1617. hr = pVideoProcAmp->Get(pPictureAttribute->Name,
  1618. &pPictureAttribute->lCurrentValue,
  1619. (long*) &pPictureAttribute->CurrentFlag);
  1620. }
  1621. }
  1622. else
  1623. {
  1624. hr = S_FALSE;
  1625. }
  1626. }
  1627. return hr;
  1628. }
  1629. ///////////////////////////////
  1630. // SetCameraAttribute
  1631. //
  1632. HRESULT CDShowUtil::SetCameraAttribute(IBaseFilter *pCaptureFilter,
  1633. CWiaVideoProperties::CameraAttribute_t *pCameraAttribute,
  1634. LONG lNewValue,
  1635. CameraControlFlags lNewFlag)
  1636. {
  1637. ASSERT(pCaptureFilter != NULL);
  1638. ASSERT(pCameraAttribute != NULL);
  1639. HRESULT hr = S_OK;
  1640. CComPtr<IAMCameraControl> pCameraControl;
  1641. if ((pCaptureFilter == NULL) ||
  1642. (pCameraControl == NULL))
  1643. {
  1644. hr = E_POINTER;
  1645. CHECK_S_OK2(hr, ("CDShowUtil::SetCameraAttribute, received a NULL pointer"));
  1646. return hr;
  1647. }
  1648. if (hr == S_OK)
  1649. {
  1650. hr = pCaptureFilter->QueryInterface(IID_IAMCameraControl, (void**) &pCameraControl);
  1651. }
  1652. if (hr == S_OK)
  1653. {
  1654. if (pCameraAttribute->bUsed)
  1655. {
  1656. //
  1657. // Attempt to set the new value for the property.
  1658. //
  1659. hr = pCameraControl->Set(pCameraAttribute->Name,
  1660. lNewValue,
  1661. (long) lNewFlag);
  1662. //
  1663. // If we successfully set the new value, then get it again. We do this
  1664. // in case the capture filter decided to change the values a little upon
  1665. // setting them (it shouldn't, but each filter could act differently)
  1666. //
  1667. if (hr == S_OK)
  1668. {
  1669. hr = pCameraControl->Get(pCameraAttribute->Name,
  1670. &pCameraAttribute->lCurrentValue,
  1671. (long*) &pCameraAttribute->CurrentFlag);
  1672. }
  1673. }
  1674. else
  1675. {
  1676. hr = S_FALSE;
  1677. }
  1678. }
  1679. return hr;
  1680. }
  1681. ///////////////////////////////
  1682. // GetPin
  1683. //
  1684. // This function returns the first
  1685. // pin on the specified filter
  1686. // matching the requested
  1687. // pin direction
  1688. //
  1689. HRESULT CDShowUtil::GetPin(IBaseFilter *pFilter,
  1690. PIN_DIRECTION PinDirection,
  1691. IPin **ppPin)
  1692. {
  1693. HRESULT hr = S_OK;
  1694. BOOL bFound = FALSE;
  1695. ULONG ulNumFetched = 0;
  1696. PIN_DIRECTION PinDir;
  1697. CComPtr<IEnumPins> pEnum;
  1698. if ((pFilter == NULL) ||
  1699. (ppPin == NULL))
  1700. {
  1701. hr = E_POINTER;
  1702. CHECK_S_OK2(hr, ("CDShowUtil::GetPin, received a NULL param"));
  1703. return hr;
  1704. }
  1705. hr = pFilter->EnumPins(&pEnum);
  1706. if (hr == S_OK)
  1707. {
  1708. hr = pEnum->Reset();
  1709. }
  1710. while ((hr == S_OK) && (!bFound))
  1711. {
  1712. CComPtr<IPin> pPin;
  1713. hr = pEnum->Next(1, &pPin, &ulNumFetched);
  1714. if (hr == S_OK)
  1715. {
  1716. hr = pPin->QueryDirection(&PinDir);
  1717. if (hr == S_OK)
  1718. {
  1719. if (PinDir == PinDirection)
  1720. {
  1721. *ppPin = pPin;
  1722. (*ppPin)->AddRef();
  1723. bFound = TRUE;
  1724. }
  1725. }
  1726. else
  1727. {
  1728. CHECK_S_OK2(hr, ("CDShowUtil::GetPin, failed to get "
  1729. "Pin Direction, aborting find attempt"));
  1730. }
  1731. }
  1732. }
  1733. if (hr == S_FALSE)
  1734. {
  1735. hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
  1736. CHECK_S_OK2(hr, ("CDShowUtil::GetPin, failed to find "
  1737. "pin with direction %lu", PinDirection));
  1738. }
  1739. return hr;
  1740. }
  1741. ///////////////////////////////
  1742. // GUIDToString
  1743. //
  1744. // Static Fn
  1745. //
  1746. void CDShowUtil::GUIDToString(const GUID & clsid,
  1747. WCHAR* pwszGUID,
  1748. ULONG ulNumChars)
  1749. {
  1750. OLECHAR sz_clsid[CHARS_IN_GUID] = L"{Unknown}";
  1751. if (pwszGUID)
  1752. {
  1753. StringFromGUID2(clsid,
  1754. sz_clsid,
  1755. sizeof(sz_clsid)/sizeof(sz_clsid[0]));
  1756. wcsncpy(pwszGUID, sz_clsid, ulNumChars - 1);
  1757. pwszGUID[ulNumChars - 1] = '\0';
  1758. }
  1759. return;
  1760. }
  1761. ///////////////////////////////
  1762. // MyDumpVideoProperties
  1763. //
  1764. // Static Fn
  1765. //
  1766. void CDShowUtil::MyDumpVideoProperties(CWiaVideoProperties *pVideoProperties)
  1767. {
  1768. WCHAR wszMajorType[CHARS_IN_GUID + 1] = {0};
  1769. WCHAR wszSubType[CHARS_IN_GUID + 1] = {0};
  1770. WCHAR wszFormatType[CHARS_IN_GUID + 1] = {0};
  1771. if (pVideoProperties == NULL)
  1772. {
  1773. return;
  1774. }
  1775. DBG_TRC(("***Dumping Wia Video Properties***"));
  1776. GUIDToString(pVideoProperties->pMediaType->majortype, wszMajorType, sizeof(wszMajorType) / sizeof(WCHAR));
  1777. GUIDToString(pVideoProperties->pMediaType->subtype, wszSubType, sizeof(wszSubType) / sizeof(WCHAR));
  1778. GUIDToString(pVideoProperties->pMediaType->formattype, wszFormatType, sizeof(wszFormatType) / sizeof(WCHAR));
  1779. DBG_PRT(("Media Type Information:"));
  1780. DBG_PRT((" Major Type: %ls", wszMajorType));
  1781. DBG_PRT((" Sub Type: %ls", wszSubType));
  1782. DBG_PRT((" Fixed Size Samples? %d ", pVideoProperties->pMediaType->bFixedSizeSamples));
  1783. DBG_PRT((" Temporal Compression? %d ", pVideoProperties->pMediaType->bTemporalCompression));
  1784. DBG_PRT((" Sample Size: %d ", pVideoProperties->pMediaType->lSampleSize));
  1785. DBG_PRT((" Format Type: %ls ", wszFormatType));
  1786. DBG_PRT(("Video Header Information:"));
  1787. DBG_PRT((" Source Rect: Left %d, Top %d, Right %d, Bottom %d",
  1788. pVideoProperties->pVideoInfoHeader->rcSource.left,
  1789. pVideoProperties->pVideoInfoHeader->rcSource.top,
  1790. pVideoProperties->pVideoInfoHeader->rcSource.right,
  1791. pVideoProperties->pVideoInfoHeader->rcSource.bottom));
  1792. DBG_PRT((" Target Rect: Left %d, Top %d, Right %d, Bottom %d",
  1793. pVideoProperties->pVideoInfoHeader->rcTarget.left,
  1794. pVideoProperties->pVideoInfoHeader->rcTarget.top,
  1795. pVideoProperties->pVideoInfoHeader->rcTarget.right,
  1796. pVideoProperties->pVideoInfoHeader->rcTarget.bottom));
  1797. DBG_PRT((" Bit Rate: %d", pVideoProperties->pVideoInfoHeader->dwBitRate));
  1798. DBG_PRT((" Bit Error Rate: %d", pVideoProperties->pVideoInfoHeader->dwBitErrorRate));
  1799. DBG_PRT((" Frame Rate: %d", pVideoProperties->dwFrameRate));
  1800. DBG_PRT(("Bitmap Information Header:"));
  1801. DBG_PRT((" Width: %d", pVideoProperties->pVideoInfoHeader->bmiHeader.biWidth));
  1802. DBG_PRT((" Height: %d", pVideoProperties->pVideoInfoHeader->bmiHeader.biHeight));
  1803. DBG_PRT((" Planes: %d", pVideoProperties->pVideoInfoHeader->bmiHeader.biPlanes));
  1804. DBG_PRT((" Bitcount: %d", pVideoProperties->pVideoInfoHeader->bmiHeader.biBitCount));
  1805. DBG_PRT((" Compresssion: %d", pVideoProperties->pVideoInfoHeader->bmiHeader.biCompression));
  1806. DBG_PRT((" Size Image: %d", pVideoProperties->pVideoInfoHeader->bmiHeader.biSizeImage));
  1807. DBG_PRT((" XPelsPerMeter: %d", pVideoProperties->pVideoInfoHeader->bmiHeader.biXPelsPerMeter));
  1808. DBG_PRT((" YPelsPerMeter: %d", pVideoProperties->pVideoInfoHeader->bmiHeader.biYPelsPerMeter));
  1809. DBG_PRT((" ClrUsed: %d", pVideoProperties->pVideoInfoHeader->bmiHeader.biClrUsed));
  1810. DBG_PRT((" ClrImportant: %d", pVideoProperties->pVideoInfoHeader->bmiHeader.biClrImportant));
  1811. if (pVideoProperties->bPictureAttributesUsed)
  1812. {
  1813. DBG_PRT(("Picture Attributes: Available"));
  1814. DBG_PRT((" Brightness:"));
  1815. DBG_PRT((" Available: %d", pVideoProperties->Brightness.bUsed));
  1816. if (pVideoProperties->Brightness.bUsed)
  1817. {
  1818. DBG_PRT((" Current Value: %d", pVideoProperties->Brightness.lCurrentValue));
  1819. DBG_PRT((" Current Flag: %d", pVideoProperties->Brightness.CurrentFlag));
  1820. DBG_PRT((" Min Value: %d", pVideoProperties->Brightness.lMinValue));
  1821. DBG_PRT((" Max Value: %d", pVideoProperties->Brightness.lMaxValue));
  1822. DBG_PRT((" Default Value: %d", pVideoProperties->Brightness.lDefaultValue));
  1823. DBG_PRT((" Increment: %d", pVideoProperties->Brightness.lIncrement));
  1824. DBG_PRT((" Valid Flags: %d", pVideoProperties->Brightness.ValidFlags));
  1825. }
  1826. DBG_PRT((" Contrast:"));
  1827. DBG_PRT((" Available: %d", pVideoProperties->Contrast.bUsed));
  1828. if (pVideoProperties->Contrast.bUsed)
  1829. {
  1830. DBG_PRT((" Current Value: %d", pVideoProperties->Contrast.lCurrentValue));
  1831. DBG_PRT((" Current Flag: %d", pVideoProperties->Contrast.CurrentFlag));
  1832. DBG_PRT((" Min Value: %d", pVideoProperties->Contrast.lMinValue));
  1833. DBG_PRT((" Max Value: %d", pVideoProperties->Contrast.lMaxValue));
  1834. DBG_PRT((" Default Value: %d", pVideoProperties->Contrast.lDefaultValue));
  1835. DBG_PRT((" Increment: %d", pVideoProperties->Contrast.lIncrement));
  1836. DBG_PRT((" Valid Flags: %d", pVideoProperties->Contrast.ValidFlags));
  1837. }
  1838. DBG_PRT((" Hue:"));
  1839. DBG_PRT((" Available: %d", pVideoProperties->Hue.bUsed));
  1840. if (pVideoProperties->Hue.bUsed)
  1841. {
  1842. DBG_PRT((" Current Value: %d", pVideoProperties->Hue.lCurrentValue));
  1843. DBG_PRT((" Current Flag: %d", pVideoProperties->Hue.CurrentFlag));
  1844. DBG_PRT((" Min Value: %d", pVideoProperties->Hue.lMinValue));
  1845. DBG_PRT((" Max Value: %d", pVideoProperties->Hue.lMaxValue));
  1846. DBG_PRT((" Default Value: %d", pVideoProperties->Hue.lDefaultValue));
  1847. DBG_PRT((" Increment: %d", pVideoProperties->Hue.lIncrement));
  1848. DBG_PRT((" Valid Flags: %d", pVideoProperties->Hue.ValidFlags));
  1849. }
  1850. DBG_PRT((" Saturation:"));
  1851. DBG_PRT((" Available: %d", pVideoProperties->Saturation.bUsed));
  1852. if (pVideoProperties->Saturation.bUsed)
  1853. {
  1854. DBG_PRT((" Current Value: %d", pVideoProperties->Saturation.lCurrentValue));
  1855. DBG_PRT((" Current Flag: %d", pVideoProperties->Saturation.CurrentFlag));
  1856. DBG_PRT((" Min Value: %d", pVideoProperties->Saturation.lMinValue));
  1857. DBG_PRT((" Max Value: %d", pVideoProperties->Saturation.lMaxValue));
  1858. DBG_PRT((" Default Value: %d", pVideoProperties->Saturation.lDefaultValue));
  1859. DBG_PRT((" Increment: %d", pVideoProperties->Saturation.lIncrement));
  1860. DBG_PRT((" Valid Flags: %d", pVideoProperties->Saturation.ValidFlags));
  1861. }
  1862. DBG_PRT((" Sharpness:"));
  1863. DBG_PRT((" Available: %d", pVideoProperties->Sharpness.bUsed));
  1864. if (pVideoProperties->Sharpness.bUsed)
  1865. {
  1866. DBG_PRT((" Current Value: %d", pVideoProperties->Sharpness.lCurrentValue));
  1867. DBG_PRT((" Current Flag: %d", pVideoProperties->Sharpness.CurrentFlag));
  1868. DBG_PRT((" Min Value: %d", pVideoProperties->Sharpness.lMinValue));
  1869. DBG_PRT((" Max Value: %d", pVideoProperties->Sharpness.lMaxValue));
  1870. DBG_PRT((" Default Value: %d", pVideoProperties->Sharpness.lDefaultValue));
  1871. DBG_PRT((" Increment: %d", pVideoProperties->Sharpness.lIncrement));
  1872. DBG_PRT((" Valid Flags: %d", pVideoProperties->Sharpness.ValidFlags));
  1873. }
  1874. DBG_PRT((" Gamma:"));
  1875. DBG_PRT((" Available: %d", pVideoProperties->Gamma.bUsed));
  1876. if (pVideoProperties->Gamma.bUsed)
  1877. {
  1878. DBG_PRT((" Current Value: %d", pVideoProperties->Gamma.lCurrentValue));
  1879. DBG_PRT((" Current Flag: %d", pVideoProperties->Gamma.CurrentFlag));
  1880. DBG_PRT((" Min Value: %d", pVideoProperties->Gamma.lMinValue));
  1881. DBG_PRT((" Max Value: %d", pVideoProperties->Gamma.lMaxValue));
  1882. DBG_PRT((" Default Value: %d", pVideoProperties->Gamma.lDefaultValue));
  1883. DBG_PRT((" Increment: %d", pVideoProperties->Gamma.lIncrement));
  1884. DBG_PRT((" Valid Flags: %d", pVideoProperties->Gamma.ValidFlags));
  1885. }
  1886. DBG_PRT((" ColorEnable:"));
  1887. DBG_PRT((" Available: %d", pVideoProperties->ColorEnable.bUsed));
  1888. if (pVideoProperties->ColorEnable.bUsed)
  1889. {
  1890. DBG_PRT((" Current Value: %d", pVideoProperties->ColorEnable.lCurrentValue));
  1891. DBG_PRT((" Current Flag: %d", pVideoProperties->ColorEnable.CurrentFlag));
  1892. DBG_PRT((" Min Value: %d", pVideoProperties->ColorEnable.lMinValue));
  1893. DBG_PRT((" Max Value: %d", pVideoProperties->ColorEnable.lMaxValue));
  1894. DBG_PRT((" Default Value: %d", pVideoProperties->ColorEnable.lDefaultValue));
  1895. DBG_PRT((" Increment: %d", pVideoProperties->ColorEnable.lIncrement));
  1896. DBG_PRT((" Valid Flags: %d", pVideoProperties->ColorEnable.ValidFlags));
  1897. }
  1898. DBG_PRT((" WhiteBalance:"));
  1899. DBG_PRT((" Available: %d", pVideoProperties->WhiteBalance.bUsed));
  1900. if (pVideoProperties->WhiteBalance.bUsed)
  1901. {
  1902. DBG_PRT((" Current Value: %d", pVideoProperties->WhiteBalance.lCurrentValue));
  1903. DBG_PRT((" Current Flag: %d", pVideoProperties->WhiteBalance.CurrentFlag));
  1904. DBG_PRT((" Min Value: %d", pVideoProperties->WhiteBalance.lMinValue));
  1905. DBG_PRT((" Max Value: %d", pVideoProperties->WhiteBalance.lMaxValue));
  1906. DBG_PRT((" Default Value: %d", pVideoProperties->WhiteBalance.lDefaultValue));
  1907. DBG_PRT((" Increment: %d", pVideoProperties->WhiteBalance.lIncrement));
  1908. DBG_PRT((" Valid Flags: %d", pVideoProperties->WhiteBalance.ValidFlags));
  1909. }
  1910. DBG_PRT((" BacklightCompensation:"));
  1911. DBG_PRT((" Available: %d", pVideoProperties->BacklightCompensation.bUsed));
  1912. if (pVideoProperties->BacklightCompensation.bUsed)
  1913. {
  1914. DBG_PRT((" Current Value: %d", pVideoProperties->BacklightCompensation.lCurrentValue));
  1915. DBG_PRT((" Current Flag: %d", pVideoProperties->BacklightCompensation.CurrentFlag));
  1916. DBG_PRT((" Min Value: %d", pVideoProperties->BacklightCompensation.lMinValue));
  1917. DBG_PRT((" Max Value: %d", pVideoProperties->BacklightCompensation.lMaxValue));
  1918. DBG_PRT((" Default Value: %d", pVideoProperties->BacklightCompensation.lDefaultValue));
  1919. DBG_PRT((" Increment: %d", pVideoProperties->BacklightCompensation.lIncrement));
  1920. DBG_PRT((" Valid Flags: %d", pVideoProperties->BacklightCompensation.ValidFlags));
  1921. }
  1922. }
  1923. else
  1924. {
  1925. DBG_PRT(("Picture Attributes: Not Available"));
  1926. }
  1927. if (pVideoProperties->bCameraAttributesUsed)
  1928. {
  1929. DBG_PRT(("Camera Attributes: Available"));
  1930. DBG_PRT((" Pan:"));
  1931. DBG_PRT((" Available: %d", pVideoProperties->Pan.bUsed));
  1932. if (pVideoProperties->Pan.bUsed)
  1933. {
  1934. DBG_PRT((" Current Value: %d", pVideoProperties->Pan.lCurrentValue));
  1935. DBG_PRT((" Current Flag: %d", pVideoProperties->Pan.CurrentFlag));
  1936. DBG_PRT((" Min Value: %d", pVideoProperties->Pan.lMinValue));
  1937. DBG_PRT((" Max Value: %d", pVideoProperties->Pan.lMaxValue));
  1938. DBG_PRT((" Default Value: %d", pVideoProperties->Pan.lDefaultValue));
  1939. DBG_PRT((" Increment: %d", pVideoProperties->Pan.lIncrement));
  1940. DBG_PRT((" Valid Flags: %d", pVideoProperties->Pan.ValidFlags));
  1941. }
  1942. DBG_PRT((" Tilt:"));
  1943. DBG_PRT((" Available: %d", pVideoProperties->Tilt.bUsed));
  1944. if (pVideoProperties->Tilt.bUsed)
  1945. {
  1946. DBG_PRT((" Current Value: %d", pVideoProperties->Tilt.lCurrentValue));
  1947. DBG_PRT((" Current Flag: %d", pVideoProperties->Tilt.CurrentFlag));
  1948. DBG_PRT((" Min Value: %d", pVideoProperties->Tilt.lMinValue));
  1949. DBG_PRT((" Max Value: %d", pVideoProperties->Tilt.lMaxValue));
  1950. DBG_PRT((" Default Value: %d", pVideoProperties->Tilt.lDefaultValue));
  1951. DBG_PRT((" Increment: %d", pVideoProperties->Tilt.lIncrement));
  1952. DBG_PRT((" Valid Flags: %d", pVideoProperties->Tilt.ValidFlags));
  1953. }
  1954. DBG_PRT((" Roll:"));
  1955. DBG_PRT((" Available: %d", pVideoProperties->Roll.bUsed));
  1956. if (pVideoProperties->Roll.bUsed)
  1957. {
  1958. DBG_PRT((" Current Value: %d", pVideoProperties->Roll.lCurrentValue));
  1959. DBG_PRT((" Current Flag: %d", pVideoProperties->Roll.CurrentFlag));
  1960. DBG_PRT((" Min Value: %d", pVideoProperties->Roll.lMinValue));
  1961. DBG_PRT((" Max Value: %d", pVideoProperties->Roll.lMaxValue));
  1962. DBG_PRT((" Default Value: %d", pVideoProperties->Roll.lDefaultValue));
  1963. DBG_PRT((" Increment: %d", pVideoProperties->Roll.lIncrement));
  1964. DBG_PRT((" Valid Flags: %d", pVideoProperties->Roll.ValidFlags));
  1965. }
  1966. DBG_PRT((" Zoom:"));
  1967. DBG_PRT((" Available: %d", pVideoProperties->Zoom.bUsed));
  1968. if (pVideoProperties->Zoom.bUsed)
  1969. {
  1970. DBG_PRT((" Current Value: %d", pVideoProperties->Zoom.lCurrentValue));
  1971. DBG_PRT((" Current Flag: %d", pVideoProperties->Zoom.CurrentFlag));
  1972. DBG_PRT((" Min Value: %d", pVideoProperties->Zoom.lMinValue));
  1973. DBG_PRT((" Max Value: %d", pVideoProperties->Zoom.lMaxValue));
  1974. DBG_PRT((" Default Value: %d", pVideoProperties->Zoom.lDefaultValue));
  1975. DBG_PRT((" Increment: %d", pVideoProperties->Zoom.lIncrement));
  1976. DBG_PRT((" Valid Flags: %d", pVideoProperties->Zoom.ValidFlags));
  1977. }
  1978. DBG_PRT((" Exposure:"));
  1979. DBG_PRT((" Available: %d", pVideoProperties->Exposure.bUsed));
  1980. if (pVideoProperties->Exposure.bUsed)
  1981. {
  1982. DBG_PRT((" Current Value: %d", pVideoProperties->Exposure.lCurrentValue));
  1983. DBG_PRT((" Current Flag: %d", pVideoProperties->Exposure.CurrentFlag));
  1984. DBG_PRT((" Min Value: %d", pVideoProperties->Exposure.lMinValue));
  1985. DBG_PRT((" Max Value: %d", pVideoProperties->Exposure.lMaxValue));
  1986. DBG_PRT((" Default Value: %d", pVideoProperties->Exposure.lDefaultValue));
  1987. DBG_PRT((" Increment: %d", pVideoProperties->Exposure.lIncrement));
  1988. DBG_PRT((" Valid Flags: %d", pVideoProperties->Exposure.ValidFlags));
  1989. }
  1990. DBG_PRT((" Iris:"));
  1991. DBG_PRT((" Available: %d", pVideoProperties->Iris.bUsed));
  1992. if (pVideoProperties->Iris.bUsed)
  1993. {
  1994. DBG_PRT((" Current Value: %d", pVideoProperties->Iris.lCurrentValue));
  1995. DBG_PRT((" Current Flag: %d", pVideoProperties->Iris.CurrentFlag));
  1996. DBG_PRT((" Min Value: %d", pVideoProperties->Iris.lMinValue));
  1997. DBG_PRT((" Max Value: %d", pVideoProperties->Iris.lMaxValue));
  1998. DBG_PRT((" Default Value: %d", pVideoProperties->Iris.lDefaultValue));
  1999. DBG_PRT((" Increment: %d", pVideoProperties->Iris.lIncrement));
  2000. DBG_PRT((" Valid Flags: %d", pVideoProperties->Iris.ValidFlags));
  2001. }
  2002. DBG_PRT((" Focus:"));
  2003. DBG_PRT((" Available: %d", pVideoProperties->Focus.bUsed));
  2004. if (pVideoProperties->Focus.bUsed)
  2005. {
  2006. DBG_PRT((" Current Value: %d", pVideoProperties->Focus.lCurrentValue));
  2007. DBG_PRT((" Current Flag: %d", pVideoProperties->Focus.CurrentFlag));
  2008. DBG_PRT((" Min Value: %d", pVideoProperties->Focus.lMinValue));
  2009. DBG_PRT((" Max Value: %d", pVideoProperties->Focus.lMaxValue));
  2010. DBG_PRT((" Default Value: %d", pVideoProperties->Focus.lDefaultValue));
  2011. DBG_PRT((" Increment: %d", pVideoProperties->Focus.lIncrement));
  2012. DBG_PRT((" Valid Flags: %d", pVideoProperties->Focus.ValidFlags));
  2013. }
  2014. }
  2015. else
  2016. {
  2017. DBG_PRT(("Camera Attributes: Not Available"));
  2018. }
  2019. return;
  2020. }
  2021. ///////////////////////////////
  2022. // DumpCaptureMoniker
  2023. //
  2024. // Static Fn
  2025. //
  2026. void CDShowUtil::DumpCaptureMoniker(IMoniker *pCaptureDeviceMoniker)
  2027. {
  2028. HRESULT hr = S_OK;
  2029. CComPtr<IPropertyBag> pPropertyBag;
  2030. if (pCaptureDeviceMoniker == NULL)
  2031. {
  2032. return;
  2033. }
  2034. if (hr == S_OK)
  2035. {
  2036. //
  2037. // Get property storage for this DS device so we can get it's
  2038. // device id...
  2039. //
  2040. hr = pCaptureDeviceMoniker->BindToStorage(0,
  2041. 0,
  2042. IID_IPropertyBag,
  2043. (void **)&pPropertyBag);
  2044. }
  2045. if (hr == S_OK)
  2046. {
  2047. CSimpleString strTemp;
  2048. DBG_TRC(("Dumping Moniker information for Capture Device"));
  2049. GetDeviceProperty(pPropertyBag, L"FriendlyName", &strTemp);
  2050. DBG_PRT(("DShow: FriendlyName = %ls", strTemp.String()));
  2051. GetDeviceProperty(pPropertyBag, L"CLSID", &strTemp);
  2052. DBG_PRT(("DShow: CLSID = %ls", strTemp.String()));
  2053. hr = GetDeviceProperty(pPropertyBag, L"DevicePath", &strTemp);
  2054. DBG_PRT(("DShow: DevicePath = %ls", strTemp.String()));
  2055. }
  2056. return;
  2057. }
  2058. ///////////////////////////////
  2059. // MyDumpGraph
  2060. //
  2061. // Static Fn
  2062. //
  2063. void CDShowUtil::MyDumpGraph(LPCTSTR Description,
  2064. IGraphBuilder *pGraphBuilder)
  2065. {
  2066. if (pGraphBuilder == NULL)
  2067. {
  2068. return;
  2069. }
  2070. if (Description)
  2071. {
  2072. DBG_TRC(("%S", Description));
  2073. }
  2074. else
  2075. {
  2076. DBG_TRC(("*** Dumping Filter Graph ***"));
  2077. }
  2078. //
  2079. // Enum all the filters
  2080. //
  2081. CComPtr<IEnumFilters> pEnum;
  2082. UINT uiNumFilters = 0;
  2083. if ((pGraphBuilder) && (pGraphBuilder->EnumFilters(&pEnum) == S_OK))
  2084. {
  2085. pEnum->Reset();
  2086. CComPtr<IBaseFilter> pFilter;
  2087. while (S_OK == pEnum->Next(1, &pFilter, NULL))
  2088. {
  2089. ++uiNumFilters;
  2090. MyDumpFilter(pFilter);
  2091. pFilter = NULL;
  2092. }
  2093. if (uiNumFilters == 0)
  2094. {
  2095. DBG_TRC(("*** No Filters in Graph ***"));
  2096. }
  2097. }
  2098. }
  2099. ///////////////////////////////
  2100. // MyDumpFilter
  2101. //
  2102. // Static Fn
  2103. //
  2104. void CDShowUtil::MyDumpFilter(IBaseFilter * pFilter)
  2105. {
  2106. HRESULT hr = S_OK;
  2107. FILTER_INFO FilterInfo;
  2108. CLSID clsid;
  2109. if (pFilter == NULL)
  2110. {
  2111. DBG_TRC(("Invalid IBaseFilter interface pointer in MyDumpFilter"));
  2112. return;
  2113. }
  2114. FilterInfo.pGraph = NULL;
  2115. hr = pFilter->QueryFilterInfo(&FilterInfo);
  2116. if (SUCCEEDED(hr))
  2117. {
  2118. hr = pFilter->GetClassID(&clsid);
  2119. }
  2120. else
  2121. {
  2122. DBG_TRC(("Unable to get filter info"));
  2123. }
  2124. if (SUCCEEDED(hr))
  2125. {
  2126. WCHAR wszGUID[127 + 1] = {0};
  2127. GUIDToString(clsid, wszGUID, sizeof(wszGUID)/sizeof(WCHAR));
  2128. DBG_PRT(("Filter Name: '%S', GUID: '%S'",
  2129. FilterInfo.achName,
  2130. wszGUID));
  2131. if (FilterInfo.pGraph)
  2132. {
  2133. FilterInfo.pGraph->Release();
  2134. FilterInfo.pGraph = NULL;
  2135. }
  2136. MyDumpAllPins(pFilter);
  2137. }
  2138. return;
  2139. }
  2140. ///////////////////////////////
  2141. // MyDumpAllPins
  2142. //
  2143. // Static Fn
  2144. //
  2145. void CDShowUtil::MyDumpAllPins(IBaseFilter *const pFilter)
  2146. {
  2147. HRESULT hr = S_OK;
  2148. CComPtr<IPin> pPin = NULL;
  2149. ULONG ulCount = 0;
  2150. CComPtr<IEnumPins> pEnumPins = NULL;
  2151. hr = const_cast<IBaseFilter*>(pFilter)->EnumPins(&pEnumPins);
  2152. if (SUCCEEDED(hr))
  2153. {
  2154. while ((SUCCEEDED(pEnumPins->Next(1, &pPin, &ulCount))) &&
  2155. (ulCount > 0))
  2156. {
  2157. MyDumpPin(pPin);
  2158. pPin = NULL;
  2159. }
  2160. }
  2161. return;
  2162. }
  2163. ///////////////////////////////
  2164. // MyDumpPin
  2165. //
  2166. // Static Fn
  2167. //
  2168. void CDShowUtil::MyDumpPin(IPin* pPin)
  2169. {
  2170. if (pPin == NULL)
  2171. {
  2172. DBG_TRC(("Invalid IPin pointer in MyDumpPinInfo"));
  2173. return;
  2174. }
  2175. LPWSTR pin_id1 = NULL;
  2176. LPWSTR pin_id2 = NULL;
  2177. PIN_INFO pin_info1 = {0};
  2178. PIN_INFO pin_info2 = {0};
  2179. const IPin *p_connected_to = NULL;
  2180. // get the pin info for this pin.
  2181. const_cast<IPin*>(pPin)->QueryPinInfo(&pin_info1);
  2182. const_cast<IPin*>(pPin)->QueryId(&pin_id1);
  2183. (const_cast<IPin*>(pPin))->ConnectedTo(
  2184. const_cast<IPin**>(&p_connected_to));
  2185. if (p_connected_to)
  2186. {
  2187. HRESULT hr = S_OK;
  2188. FILTER_INFO filter_info = {0};
  2189. const_cast<IPin*>(p_connected_to)->QueryPinInfo(&pin_info2);
  2190. const_cast<IPin*>(p_connected_to)->QueryId(&pin_id2);
  2191. if (pin_info2.pFilter)
  2192. {
  2193. hr = pin_info2.pFilter->QueryFilterInfo(&filter_info);
  2194. if (SUCCEEDED(hr))
  2195. {
  2196. if (filter_info.pGraph)
  2197. {
  2198. filter_info.pGraph->Release();
  2199. filter_info.pGraph = NULL;
  2200. }
  2201. }
  2202. }
  2203. if (pin_info2.pFilter)
  2204. {
  2205. pin_info2.pFilter->Release();
  2206. pin_info2.pFilter = NULL;
  2207. }
  2208. const_cast<IPin*>(p_connected_to)->Release();
  2209. if (pin_info1.dir == PINDIR_OUTPUT)
  2210. {
  2211. DBG_PRT((" Pin: '%S', PinID: '%S' --> "
  2212. "Filter: '%S', Pin: '%S', PinID: '%S'",
  2213. pin_info1.achName,
  2214. pin_id1,
  2215. filter_info.achName,
  2216. pin_info2.achName,
  2217. pin_id2));
  2218. }
  2219. else
  2220. {
  2221. DBG_PRT((" Pin: '%S', PinID: '%S' <-- "
  2222. "Filter: '%S', Pin: '%S', PinID: '%S'",
  2223. pin_info1.achName,
  2224. pin_id1,
  2225. filter_info.achName,
  2226. pin_info2.achName,
  2227. pin_id2));
  2228. }
  2229. // if pin_id2 is NULL, then CoTaskMemFree is a no-op
  2230. CoTaskMemFree(pin_id2);
  2231. }
  2232. else
  2233. {
  2234. if (pin_info1.dir == PINDIR_OUTPUT)
  2235. {
  2236. DBG_PRT((" Pin: '%S', PinID: '%S' --> Not Connected",
  2237. pin_info1.achName,
  2238. pin_id1));
  2239. }
  2240. else
  2241. {
  2242. DBG_PRT((" Pin: '%S', PinID: '%S' <-- Not Connected",
  2243. pin_info1.achName,
  2244. pin_id1));
  2245. }
  2246. }
  2247. // if pin_id1 is NULL, then CoTaskMemFree is a no-op
  2248. CoTaskMemFree(pin_id1);
  2249. if (pin_info1.pFilter)
  2250. {
  2251. pin_info1.pFilter->Release();
  2252. pin_info1.pFilter = NULL;
  2253. }
  2254. return;
  2255. }