Old fashion design for PC-104
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.

665 lines
16 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: DirectShowStreamMovie.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of DirectShowStreamMovie.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\Version.h"
  16. #include <Qedit.h>
  17. #include <Tchar.h>
  18. #include <stdio.h>
  19. #include "DirectShowStreamMovie.h"
  20. #include "DirectShowSampleGrabberCB.h"
  21. #include "DirectShowVideo.h"
  22. #ifdef REGISTER_FILTERGRAPH
  23. HRESULT CDirectShowStreamMovie::AddGraphToRot( IUnknown *pUnkGraph, DWORD *pdwRegister )
  24. {
  25. IMoniker * pMoniker;
  26. IRunningObjectTable *pROT;
  27. WCHAR wsz[128];
  28. HRESULT hr;
  29. if (FAILED(GetRunningObjectTable(0, &pROT)))
  30. {
  31. return E_FAIL;
  32. }
  33. _snwprintf(wsz, 128, L"FilterGraph %08x pid %08x", (DWORD_PTR)pUnkGraph,
  34. GetCurrentProcessId());
  35. hr = CreateItemMoniker(L"!", wsz, &pMoniker);
  36. if (SUCCEEDED(hr))
  37. {
  38. hr = pROT->Register(0, pUnkGraph, pMoniker, pdwRegister);
  39. pMoniker->Release();
  40. }
  41. pROT->Release();
  42. return hr;
  43. }
  44. void CDirectShowStreamMovie::RemoveGraphFromRot( DWORD pdwRegister )
  45. {
  46. IRunningObjectTable *pROT;
  47. if (SUCCEEDED(GetRunningObjectTable(0, &pROT)))
  48. {
  49. pROT->Revoke(pdwRegister);
  50. pROT->Release();
  51. }
  52. }
  53. #endif
  54. CDirectShowStreamMovie::CDirectShowStreamMovie()
  55. {
  56. m_pGraphBuilder = NULL;
  57. m_pMediaControl = NULL;
  58. m_pMediaEvent = NULL;
  59. m_pMediaSeeking = NULL;
  60. #ifdef REGISTER_FILTERGRAPH
  61. m_dwGraphRegister = 0;
  62. #endif
  63. ::CoInitializeEx( NULL, COINIT_MULTITHREADED );
  64. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDirectShowStreamMovie::CDirectShowStreamMovie") );
  65. }
  66. CDirectShowStreamMovie::~CDirectShowStreamMovie()
  67. {
  68. Destroy();
  69. ::CoUninitialize();
  70. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDirectShowStreamMovie::~CDirectShowStreamMovie") );
  71. }
  72. BOOL CDirectShowStreamMovie::Create( LPCTSTR pFileName )
  73. {
  74. Destroy();
  75. if( !CreateGraphBuilder() )
  76. return FALSE;
  77. IPin *pSourcePin = NULL;
  78. if( !CreateSourceFilter( pFileName, &pSourcePin ) )
  79. {
  80. return FALSE;
  81. }
  82. ISampleGrabber *pSampleGrabber = NULL;
  83. IPin *pGrabberInputPin = NULL;
  84. IPin *pGrabberOutputPin = NULL;
  85. if( !CreateSampleGrabber( &pSampleGrabber, &pGrabberInputPin, &pGrabberOutputPin ) )
  86. {
  87. pSourcePin->Release();
  88. return FALSE;
  89. }
  90. IPin *pNullRendererPin = NULL;
  91. if( !CreateNullRenderer( &pNullRendererPin ) )
  92. {
  93. pSourcePin->Release();
  94. pSampleGrabber->Release();
  95. pGrabberInputPin->Release();
  96. pGrabberOutputPin->Release();
  97. return FALSE;
  98. }
  99. HRESULT hr = m_pGraphBuilder->Connect( pSourcePin, pGrabberInputPin );
  100. pSourcePin->Release();
  101. pGrabberInputPin->Release();
  102. if( FAILED(hr) )
  103. {
  104. pSampleGrabber->Release();
  105. pGrabberOutputPin->Release();
  106. pNullRendererPin->Release();
  107. return FALSE;
  108. }
  109. hr = m_pGraphBuilder->Connect( pGrabberOutputPin, pNullRendererPin );
  110. pGrabberOutputPin->Release();
  111. pNullRendererPin->Release();
  112. if( FAILED(hr) )
  113. {
  114. pSampleGrabber->Release();
  115. return FALSE;
  116. }
  117. // create stream
  118. CDirectShowStream::Create( pSampleGrabber );
  119. pSampleGrabber->Release();
  120. // Run the graph to play the media file
  121. hr = m_pMediaControl->Run();
  122. if( FAILED(hr) )
  123. return FALSE;
  124. // Add our graph to the running object table, which will allow
  125. // the GraphEdit application to "spy" on our graph
  126. #ifdef REGISTER_FILTERGRAPH
  127. hr = AddGraphToRot( m_pGraphBuilder, &m_dwGraphRegister );
  128. if (FAILED(hr))
  129. m_dwGraphRegister = 0;
  130. #endif
  131. return CLgThread::Start( FALSE );
  132. }
  133. /*
  134. BOOL CDirectShowStreamMovie::Create( LPCTSTR pFileName )
  135. {
  136. Destroy();
  137. // Create the filter graph.
  138. HRESULT hr = ::CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **)&m_pGraphBuilder );
  139. if( FAILED(hr) )
  140. return FALSE;
  141. // TCHAR pName[MAX_PATH];
  142. // ::WideCharToMultiByte( CP_ACP, 0, PinInfo.achName, -1, pName, MAX_PATH, 0, 0 );
  143. WCHAR wFileName[MAX_PATH];
  144. ::MultiByteToWideChar( CP_ACP, 0, pFileName, -1, wFileName, MAX_PATH );
  145. // Have the graph builder construct its the appropriate graph automatically
  146. hr = m_pGraphBuilder->RenderFile( wFileName, NULL );
  147. if( FAILED(hr) )
  148. return FALSE;
  149. // QueryInterface for DirectShow interfaces
  150. hr = m_pGraphBuilder->QueryInterface(IID_IMediaControl, (void **)&m_pMediaControl);
  151. if( FAILED(hr) )
  152. return FALSE;
  153. hr = m_pGraphBuilder->QueryInterface(IID_IMediaEvent, (void **)&m_pMediaEvent);
  154. if( FAILED(hr) )
  155. return FALSE;
  156. hr = m_pGraphBuilder->QueryInterface(IID_IMediaSeeking, (void **)&m_pMediaSeeking);
  157. if( FAILED(hr) )
  158. return FALSE;
  159. // create grabber filter
  160. IBaseFilter *pGrabberFilter = NULL;
  161. hr = ::CoCreateInstance( CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (LPVOID *)&pGrabberFilter );
  162. if( FAILED(hr) )
  163. return FALSE;
  164. // create sample grabber
  165. ISampleGrabber *pSampleGrabber = NULL;
  166. hr = pGrabberFilter->QueryInterface( IID_ISampleGrabber, (void **)&pSampleGrabber );
  167. if( FAILED(hr) )
  168. {
  169. pGrabberFilter->Release();
  170. return FALSE;
  171. }
  172. // add grabber filter to filter graph
  173. hr = m_pGraphBuilder->AddFilter( pGrabberFilter, L"Grabber" );
  174. if( FAILED(hr) )
  175. {
  176. pGrabberFilter->Release();
  177. pSampleGrabber->Release();
  178. return FALSE;
  179. }
  180. // set video capture format
  181. AM_MEDIA_TYPE mt;
  182. ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
  183. mt.majortype = MEDIATYPE_Video;
  184. mt.subtype = MEDIASUBTYPE_RGB24;
  185. mt.formattype = FORMAT_VideoInfo;
  186. hr = pSampleGrabber->SetMediaType(&mt);
  187. if( FAILED(hr) )
  188. {
  189. pGrabberFilter->Release();
  190. pSampleGrabber->Release();
  191. return FALSE;
  192. }
  193. // Query for video interfaces
  194. IVideoWindow *pVW = NULL;
  195. hr = m_pGraphBuilder->QueryInterface(IID_IVideoWindow, (void **)&pVW);
  196. if( FAILED(hr) )
  197. return FALSE;
  198. pVW->put_Visible( OAFALSE );
  199. pVW->put_AutoShow( OAFALSE );
  200. pVW->Release();
  201. // insert grabber filter
  202. IBaseFilter *pVideoRenderer = FindVideoRenderer( m_pGraphBuilder );
  203. if( !pVideoRenderer )
  204. return FALSE;
  205. AppendGrabber( pVideoRenderer, pGrabberFilter );
  206. pVideoRenderer->Release();
  207. pGrabberFilter->Release();
  208. CDirectShowStream::Create( pSampleGrabber );
  209. pSampleGrabber->Release();
  210. // Run the graph to play the media file
  211. hr = m_pMediaControl->Run();
  212. if( FAILED(hr) )
  213. return FALSE;
  214. return CLgThread::Start( FALSE );
  215. }
  216. */
  217. void CDirectShowStreamMovie::Destroy()
  218. {
  219. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CDirectShowStreamMovie::Destroy"), _T("Started...") );
  220. #ifdef REGISTER_FILTERGRAPH
  221. // Remove filter graph from the running object table
  222. if( m_dwGraphRegister )
  223. {
  224. RemoveGraphFromRot( m_dwGraphRegister );
  225. m_dwGraphRegister = FALSE;
  226. }
  227. #endif
  228. // stop graph
  229. if( m_pMediaControl )
  230. {
  231. OAFilterState fs;
  232. while( true )
  233. {
  234. if( m_pMediaControl->Stop() != S_OK )
  235. break;
  236. if( m_pMediaControl->GetState( 1000UL, &fs ) == S_OK )
  237. {
  238. if( fs == State_Stopped )
  239. break;
  240. }
  241. }
  242. }
  243. // stop event thread
  244. CLgThread::Stop( TRUE );
  245. // stop capturing
  246. CDirectShowStream::Destroy();
  247. // relase interfaces
  248. if( m_pGraphBuilder )
  249. {
  250. m_pGraphBuilder->Release();
  251. m_pGraphBuilder = NULL;
  252. }
  253. if( m_pMediaControl )
  254. {
  255. m_pMediaControl->Release();
  256. m_pMediaControl = NULL;
  257. }
  258. if( m_pMediaEvent )
  259. {
  260. m_pMediaEvent->Release();
  261. m_pMediaEvent = NULL;
  262. }
  263. if( m_pMediaSeeking )
  264. {
  265. m_pMediaSeeking->Release();
  266. m_pMediaSeeking = NULL;
  267. }
  268. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CDirectShowStreamMovie::Destroy"), _T("Done") );
  269. }
  270. void CDirectShowStreamMovie::OnVideoSample( double SampleTime, BYTE *pBuffer, long BufferLen )
  271. {
  272. if( !m_pBitmapInfoHeader || !pBuffer )
  273. return;
  274. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDirectShowStreamMovie::OnVideoSample"), _T("Started...") );
  275. // protect
  276. CLgLocker Lock( &CLgLinkP<CDirectShowStream,CDirectShowVideo>::GetLock() );
  277. // make reference
  278. CLgArray< CLgLink<CDirectShowVideo,CDirectShowStream>* >& arrVideo = *this;
  279. // send to all
  280. for( INT i = 0; i < arrVideo.GetCount(); i++ )
  281. {
  282. CDirectShowVideo *pDirectShowVideo = *arrVideo[i];
  283. pDirectShowVideo->UpdateVideo( m_pBitmapInfoHeader, pBuffer, SampleTime );
  284. }
  285. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDirectShowStreamMovie::OnVideoSample"), _T("Done") );
  286. }
  287. DWORD CDirectShowStreamMovie::ThreadProc()
  288. {
  289. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CDirectShowStreamMovie::ThreadProc"), _T("Started...") );
  290. __try
  291. {
  292. HANDLE hMediaEvent;
  293. m_pMediaEvent->GetEventHandle( (OAEVENT*) &hMediaEvent );
  294. HANDLE pEvents[] = { CLgThread::GetThreadStopEvent(), hMediaEvent };
  295. BOOL bRun = TRUE;
  296. while( bRun )
  297. {
  298. switch( ::WaitForMultipleObjects( 2, pEvents, FALSE, INFINITE ) )
  299. {
  300. case WAIT_OBJECT_0:
  301. case WAIT_FAILED:
  302. default:
  303. bRun = FALSE;
  304. continue;
  305. case WAIT_OBJECT_0+1:
  306. break;
  307. }
  308. LONG evCode, evParam1, evParam2;
  309. // Process all queued events
  310. while(SUCCEEDED(m_pMediaEvent->GetEvent(&evCode, (LONG_PTR *) &evParam1,
  311. (LONG_PTR *) &evParam2, 0)))
  312. {
  313. // Free memory associated with callback, since we're not using it
  314. HRESULT hr = m_pMediaEvent->FreeEventParams(evCode, evParam1, evParam2);
  315. // If this is the end of the clip, reset to beginning
  316. if(EC_COMPLETE == evCode)
  317. {
  318. LONGLONG pos=0;
  319. // Reset to first frame of movie
  320. hr = m_pMediaSeeking->SetPositions(&pos, AM_SEEKING_AbsolutePositioning ,
  321. NULL, AM_SEEKING_NoPositioning);
  322. if (FAILED(hr))
  323. {
  324. // Some custom filters (like the Windows CE MIDI filter)
  325. // may not implement seeking interfaces (IMediaSeeking)
  326. // to allow seeking to the start. In that case, just stop
  327. // and restart for the same effect. This should not be
  328. // necessary in most cases.
  329. if (FAILED(hr = m_pMediaControl->Stop()))
  330. {
  331. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDirectShowStreamMovie::ThreadProc"), _T("Failed(0x%08lx) to stop media clip"), hr );
  332. break;
  333. }
  334. if (FAILED(hr = m_pMediaControl->Run()))
  335. {
  336. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDirectShowStreamMovie::ThreadProc"), _T("Failed(0x%08lx) to reset media clip"), hr);
  337. break;
  338. }
  339. }
  340. }
  341. }
  342. }
  343. }
  344. __except( EXCEPTION_EXECUTE_HANDLER )
  345. {
  346. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDirectShowStreamMovie::ThreadProc"), _T("Exception 0x%08X"), _exception_code() );
  347. }
  348. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CDirectShowStreamMovie::ThreadProc"), _T("Done") );
  349. return 0UL;
  350. }
  351. BOOL CDirectShowStreamMovie::CreateGraphBuilder()
  352. {
  353. // Create the filter graph.
  354. HRESULT hr = ::CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **)&m_pGraphBuilder );
  355. if( FAILED(hr) )
  356. return FALSE;
  357. // QueryInterface for DirectShow interfaces
  358. hr = m_pGraphBuilder->QueryInterface(IID_IMediaControl, (void **)&m_pMediaControl);
  359. if( FAILED(hr) )
  360. {
  361. return FALSE;
  362. }
  363. hr = m_pGraphBuilder->QueryInterface(IID_IMediaEvent, (void **)&m_pMediaEvent);
  364. if( FAILED(hr) )
  365. {
  366. return FALSE;
  367. }
  368. hr = m_pGraphBuilder->QueryInterface(IID_IMediaSeeking, (void **)&m_pMediaSeeking);
  369. if( FAILED(hr) )
  370. {
  371. return FALSE;
  372. }
  373. return TRUE;
  374. }
  375. BOOL CDirectShowStreamMovie::CreateSourceFilter( LPCTSTR pFileName, IPin** ppPin )
  376. {
  377. // create file async source
  378. IBaseFilter *pSourceFilter = NULL;
  379. HRESULT hr = ::CoCreateInstance( CLSID_AsyncReader, NULL, CLSCTX_INPROC, IID_IBaseFilter, (void **)&pSourceFilter );
  380. if( FAILED(hr) )
  381. return FALSE;
  382. // freate loading filter
  383. IFileSourceFilter *pFileSourceFilter = NULL;
  384. hr = pSourceFilter->QueryInterface( IID_IFileSourceFilter, (void**)&pFileSourceFilter );
  385. if( FAILED(hr) )
  386. {
  387. pSourceFilter->Release();
  388. return FALSE;
  389. }
  390. // convert name
  391. WCHAR wFileName[MAX_PATH];
  392. ::MultiByteToWideChar( CP_ACP, 0, pFileName, -1, wFileName, MAX_PATH );
  393. // load file
  394. hr = pFileSourceFilter->Load( wFileName, NULL );
  395. pFileSourceFilter->Release();
  396. if( FAILED(hr) )
  397. {
  398. pSourceFilter->Release();
  399. return FALSE;
  400. }
  401. // add source filter to graph
  402. hr = m_pGraphBuilder->AddFilter( pSourceFilter, L"FileSource" );
  403. if( FAILED(hr) )
  404. {
  405. pSourceFilter->Release();
  406. return FALSE;
  407. }
  408. // find source pin
  409. IEnumPins *pEnumPins = NULL;
  410. hr = pSourceFilter->EnumPins( &pEnumPins );
  411. pSourceFilter->Release();
  412. if( FAILED(hr) )
  413. {
  414. pSourceFilter->Release();
  415. return FALSE;
  416. }
  417. // enumerate all pins
  418. IPin *pPin = NULL;
  419. while( pEnumPins->Next( 1, &pPin, NULL ) == S_OK )
  420. {
  421. PIN_DIRECTION PinDir;
  422. hr = pPin->QueryDirection( &PinDir );
  423. if( FAILED(hr) )
  424. {
  425. pPin->Release();
  426. pPin = NULL;
  427. continue;
  428. }
  429. if( PinDir == PINDIR_OUTPUT )
  430. break;
  431. }
  432. pEnumPins->Release();
  433. pEnumPins = NULL;
  434. if( !pPin )
  435. {
  436. return FALSE;
  437. }
  438. *ppPin = pPin;
  439. return TRUE;
  440. }
  441. BOOL CDirectShowStreamMovie::CreateSampleGrabber( ISampleGrabber** ppSampleGrabber, IPin** ppInputPin, IPin** ppOutputPin )
  442. {
  443. // create grabber filter
  444. IBaseFilter *pGrabberFilter = NULL;
  445. HRESULT hr = ::CoCreateInstance( CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (LPVOID *)&pGrabberFilter );
  446. if( FAILED(hr) )
  447. {
  448. return FALSE;
  449. }
  450. // create sample grabber
  451. ISampleGrabber *pSampleGrabber = NULL;
  452. hr = pGrabberFilter->QueryInterface( IID_ISampleGrabber, (void **)&pSampleGrabber );
  453. if( FAILED(hr) )
  454. {
  455. pGrabberFilter->Release();
  456. return FALSE;
  457. }
  458. // add grabber filter to filter graph
  459. hr = m_pGraphBuilder->AddFilter( pGrabberFilter, L"Grabber" );
  460. if( FAILED(hr) )
  461. {
  462. pGrabberFilter->Release();
  463. pSampleGrabber->Release();
  464. return FALSE;
  465. }
  466. // set video capture format
  467. AM_MEDIA_TYPE mt;
  468. ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
  469. mt.majortype = MEDIATYPE_Video;
  470. mt.subtype = MEDIASUBTYPE_RGB24;
  471. mt.formattype = FORMAT_VideoInfo;
  472. hr = pSampleGrabber->SetMediaType(&mt);
  473. if( FAILED(hr) )
  474. {
  475. pGrabberFilter->Release();
  476. pSampleGrabber->Release();
  477. return FALSE;
  478. }
  479. // enumerate grabber pins
  480. IEnumPins *pEnumPins = NULL;
  481. hr = pGrabberFilter->EnumPins( &pEnumPins );
  482. pGrabberFilter->Release();
  483. if( FAILED(hr) )
  484. {
  485. pSampleGrabber->Release();
  486. return FALSE;
  487. }
  488. // find input and output
  489. IPin *pInputPin = NULL;
  490. IPin *pOutputPin = NULL;
  491. IPin *pPin = NULL;
  492. while( pEnumPins->Next( 1, &pPin, NULL ) == S_OK )
  493. {
  494. PIN_DIRECTION PinDir;
  495. hr = pPin->QueryDirection( &PinDir );
  496. if( FAILED(hr) )
  497. {
  498. pPin->Release();
  499. pPin = NULL;
  500. continue;
  501. }
  502. if( PinDir == PINDIR_INPUT )pInputPin = pPin;
  503. else pOutputPin = pPin;
  504. if( pInputPin && pOutputPin )
  505. break;
  506. }
  507. pEnumPins->Release();
  508. pEnumPins = NULL;
  509. if( !pInputPin || !pOutputPin )
  510. {
  511. pSampleGrabber->Release();
  512. if( pInputPin ) pInputPin->Release();
  513. if( pOutputPin ) pOutputPin->Release();
  514. return FALSE;
  515. }
  516. *ppSampleGrabber = pSampleGrabber;
  517. *ppInputPin = pInputPin;
  518. *ppOutputPin = pOutputPin;
  519. return TRUE;
  520. }
  521. BOOL CDirectShowStreamMovie::CreateNullRenderer( IPin** ppPin )
  522. {
  523. IBaseFilter *pNullRenderer = NULL;
  524. HRESULT hr = ::CoCreateInstance( CLSID_NullRenderer, NULL, CLSCTX_INPROC, IID_IBaseFilter, (void **)&pNullRenderer );
  525. if( FAILED(hr) )
  526. {
  527. return FALSE;
  528. }
  529. hr = m_pGraphBuilder->AddFilter( pNullRenderer, L"NullRenderer" );
  530. if( FAILED(hr) )
  531. {
  532. pNullRenderer->Release();
  533. return FALSE;
  534. }
  535. // enumerate null renderer pins
  536. IEnumPins *pEnumPins = NULL;
  537. hr = pNullRenderer->EnumPins( &pEnumPins );
  538. pNullRenderer->Release();
  539. if( FAILED(hr) )
  540. {
  541. pNullRenderer->Release();
  542. return FALSE;
  543. }
  544. IPin *pPin = NULL;
  545. while( pEnumPins->Next( 1, &pPin, NULL ) == S_OK )
  546. {
  547. PIN_DIRECTION PinDir;
  548. hr = pPin->QueryDirection( &PinDir );
  549. if( FAILED(hr) )
  550. {
  551. pPin->Release();
  552. pPin = NULL;
  553. continue;
  554. }
  555. if( PinDir == PINDIR_INPUT )
  556. break;
  557. }
  558. pEnumPins->Release();
  559. pEnumPins = NULL;
  560. if( !pPin )
  561. {
  562. return FALSE;
  563. }
  564. *ppPin = pPin;
  565. return TRUE;
  566. }