2 * Implementation of IFilterGraph and related interfaces
3 * + IGraphVersion, IGraphConfig
5 * FIXME - create a thread to process some methods correctly.
8 * FIXME - process Pause/Stop asynchronously and notify when completed.
11 * hidenori@a2.ctktv.ne.jp
28 #include "debugtools.h"
29 DEFAULT_DEBUG_CHANNEL(quartz);
31 #include "quartz_private.h"
39 #define NUMELEMS(elem) (sizeof(elem)/sizeof(elem[0]))
42 static HRESULT CFilterGraph_DisconnectAllPins( IBaseFilter* pFilter )
44 IEnumPins* pEnum = NULL;
50 hr = IBaseFilter_EnumPins( pFilter, &pEnum );
60 hr = IEnumPins_Next( pEnum, 1, &pPin, &cFetched );
63 if ( hr != NOERROR || pPin == NULL || cFetched != 1 )
70 hr = IPin_ConnectedTo(pPin,&pConnTo);
71 if ( hr == NOERROR && pConnTo != NULL )
73 IPin_Disconnect(pPin);
74 IPin_Disconnect(pConnTo);
75 IPin_Release(pConnTo);
81 IEnumPins_Release( pEnum );
87 static HRESULT CFilterGraph_GraphChanged( CFilterGraph* This )
89 /* IDistributorNotify_NotifyGraphChange() */
91 IMediaEventSink_Notify(CFilterGraph_IMediaEventSink(This),
92 EC_GRAPH_CHANGED, 0, 0);
93 This->m_lGraphVersion ++;
98 /***************************************************************************
100 * CFilterGraph internal methods for IFilterGraph2::AddSourceFilter().
104 static HRESULT QUARTZ_PeekFile(
105 const WCHAR* pwszFileName,
106 BYTE* pData, DWORD cbData, DWORD* pcbRead )
112 hFile = CreateFileW( pwszFileName,
113 GENERIC_READ, FILE_SHARE_READ,
114 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL );
115 if ( hFile == INVALID_HANDLE_VALUE )
117 if ( ReadFile( hFile, pData, cbData, pcbRead, NULL ) )
119 CloseHandle( hFile );
125 static const WCHAR* skip_space(const WCHAR* pwsz)
127 if ( pwsz == NULL ) return NULL;
128 while ( *pwsz == (WCHAR)' ' ) pwsz++;
132 static const WCHAR* get_dword(const WCHAR* pwsz,DWORD* pdw)
137 if ( pwsz == NULL ) return NULL;
138 while ( *pwsz >= (WCHAR)'0' && *pwsz <= (WCHAR)'9' )
140 dw = dw * 10 + (DWORD)(*pwsz-(WCHAR)'0');
147 static int wchar_to_hex(WCHAR wch)
149 if ( wch >= (WCHAR)'0' && wch <= (WCHAR)'9' )
150 return (int)(wch - (WCHAR)'0');
151 if ( wch >= (WCHAR)'A' && wch <= (WCHAR)'F' )
152 return (int)(wch - (WCHAR)'A' + 10);
153 if ( wch >= (WCHAR)'a' && wch <= (WCHAR)'f' )
154 return (int)(wch - (WCHAR)'a' + 10);
158 static const WCHAR* get_hex(const WCHAR* pwsz,BYTE* pb)
163 if ( pwsz == NULL ) return NULL;
164 hi = wchar_to_hex(*pwsz); if ( hi < 0 ) return NULL; pwsz++;
165 lo = wchar_to_hex(*pwsz); if ( lo < 0 ) return NULL; pwsz++;
166 *pb = (BYTE)( (hi << 4) | lo );
170 static const WCHAR* skip_hex(const WCHAR* pwsz)
172 if ( pwsz == NULL ) return NULL;
175 if ( wchar_to_hex(*pwsz) < 0 )
182 static const WCHAR* next_token(const WCHAR* pwsz)
184 if ( pwsz == NULL ) return NULL;
185 pwsz = skip_space(pwsz);
186 if ( *pwsz != (WCHAR)',' ) return NULL; pwsz++;
187 return skip_space(pwsz);
191 static HRESULT QUARTZ_SourceTypeIsMatch(
192 const BYTE* pData, DWORD cbData,
193 const WCHAR* pwszTempl, DWORD cchTempl )
198 const WCHAR* pwszMask;
199 const WCHAR* pwszValue;
203 TRACE("(%p,%lu,%s,%lu)\n",pData,cbData,debugstr_w(pwszTempl),cchTempl);
205 pwszTempl = skip_space(pwszTempl);
208 pwszTempl = get_dword(pwszTempl,&dwOfs);
209 pwszTempl = next_token(pwszTempl);
210 pwszTempl = get_dword(pwszTempl,&cbLen);
211 pwszMask = pwszTempl = next_token(pwszTempl);
212 pwszTempl = skip_hex(pwszTempl);
213 pwszValue = pwszTempl = next_token(pwszTempl);
214 pwszTempl = skip_hex(pwszValue);
215 pwszTempl = skip_space(pwszTempl);
216 if ( pwszValue == NULL )
218 WARN( "parse error\n" );
222 if ( dwOfs >= cbData || ( (dwOfs+cbLen) >= cbData ) )
224 WARN( "length of given data is too short\n" );
228 for ( n = 0; n < cbLen; n++ )
230 pwszMask = get_hex(pwszMask,&bMask);
231 if ( pwszMask == NULL ) bMask = 0xff;
232 pwszValue = get_hex(pwszValue,&bValue);
233 if ( pwszValue == NULL )
235 WARN( "parse error - invalid hex data\n" );
238 if ( (pData[dwOfs+n]&bMask) != (bValue&bMask) )
240 TRACE( "not matched\n" );
245 if ( *pwszTempl == 0 )
247 pwszTempl = next_token(pwszTempl);
248 if ( pwszTempl == NULL )
250 WARN( "parse error\n" );
255 TRACE( "matched\n" );
259 static HRESULT QUARTZ_GetSourceTypeFromData(
260 const BYTE* pData, DWORD cbData,
261 GUID* pidMajor, GUID* pidSub, CLSID* pidSource )
263 HRESULT hr = S_FALSE;
267 WCHAR wszSource[128];
268 WCHAR wszSourceFilter[128];
269 WCHAR* pwszLocalBuf = NULL;
271 DWORD cbLocalBuf = 0;
281 FILETIME ftLastWrite;
282 static const WCHAR wszFmt[] = {'%','l','u',0};
284 if ( RegOpenKeyExW( HKEY_CLASSES_ROOT, QUARTZ_wszMediaType, 0, KEY_READ, &hkMajor ) == ERROR_SUCCESS )
287 while ( hr == S_FALSE )
289 cbPath = NUMELEMS(wszMajor)-1;
291 hkMajor, dwIndexMajor ++, wszMajor, &cbPath,
292 NULL, NULL, NULL, &ftLastWrite );
293 if ( lr != ERROR_SUCCESS )
295 if ( RegOpenKeyExW( hkMajor, wszMajor, 0, KEY_READ, &hkSub ) == ERROR_SUCCESS )
298 while ( hr == S_FALSE )
300 cbPath = NUMELEMS(wszSub)-1;
302 hkSub, dwIndexSub ++, wszSub, &cbPath,
303 NULL, NULL, NULL, &ftLastWrite );
304 if ( lr != ERROR_SUCCESS )
306 if ( RegOpenKeyExW( hkSub, wszSub, 0, KEY_READ, &hkSource ) == ERROR_SUCCESS )
309 while ( hr == S_FALSE )
311 wsprintfW(wszSource,wszFmt,dwIndexSource++);
312 lr = RegQueryValueExW(
313 hkSource, wszSource, NULL,
314 &dwRegType, NULL, &cbRegData );
315 if ( lr != ERROR_SUCCESS )
317 if ( cbLocalBuf < cbRegData )
319 pwszTemp = (WCHAR*)QUARTZ_ReallocMem( pwszLocalBuf, cbRegData+sizeof(WCHAR) );
320 if ( pwszTemp == NULL )
325 pwszLocalBuf = pwszTemp;
326 cbLocalBuf = cbRegData+sizeof(WCHAR);
328 cbRegData = cbLocalBuf;
329 lr = RegQueryValueExW(
330 hkSource, wszSource, NULL,
331 &dwRegType, (BYTE*)pwszLocalBuf, &cbRegData );
332 if ( lr != ERROR_SUCCESS )
335 hr = QUARTZ_SourceTypeIsMatch(
337 pwszLocalBuf, cbRegData / sizeof(WCHAR) );
340 hr = CLSIDFromString(wszMajor,pidMajor);
342 hr = CLSIDFromString(wszSub,pidSub);
345 lstrcpyW(wszSource,QUARTZ_wszSourceFilter);
346 cbRegData = NUMELEMS(wszSourceFilter)-sizeof(WCHAR);
347 lr = RegQueryValueExW(
348 hkSource, wszSource, NULL,
350 (BYTE*)wszSourceFilter, &cbRegData );
351 if ( lr == ERROR_SUCCESS )
353 hr = CLSIDFromString(wszSourceFilter,pidSource);
359 if ( hr != NOERROR && SUCCEEDED(hr) )
365 RegCloseKey( hkSource );
368 RegCloseKey( hkSub );
371 RegCloseKey( hkMajor );
374 if ( pwszLocalBuf != NULL )
375 QUARTZ_FreeMem(pwszLocalBuf);
382 /***************************************************************************
384 * CFilterGraph::IFilterGraph2 methods
388 static HRESULT WINAPI
389 IFilterGraph2_fnQueryInterface(IFilterGraph2* iface,REFIID riid,void** ppobj)
391 CFilterGraph_THIS(iface,fgraph);
393 TRACE("(%p)->()\n",This);
395 return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
399 IFilterGraph2_fnAddRef(IFilterGraph2* iface)
401 CFilterGraph_THIS(iface,fgraph);
403 TRACE("(%p)->()\n",This);
405 return IUnknown_AddRef(This->unk.punkControl);
409 IFilterGraph2_fnRelease(IFilterGraph2* iface)
411 CFilterGraph_THIS(iface,fgraph);
413 TRACE("(%p)->()\n",This);
415 return IUnknown_Release(This->unk.punkControl);
418 static HRESULT WINAPI
419 IFilterGraph2_fnAddFilter(IFilterGraph2* iface,IBaseFilter* pFilter, LPCWSTR pName)
421 CFilterGraph_THIS(iface,fgraph);
425 HRESULT hrSucceeded = S_OK;
426 QUARTZ_CompListItem* pItem;
429 TRACE( "(%p)->(%p,%s)\n",This,pFilter,debugstr_w(pName) );
431 QUARTZ_CompList_Lock( This->m_pFilterList );
433 hr = IMediaFilter_GetState(CFilterGraph_IMediaFilter(This),0,&fs);
434 if ( hr == VFW_S_STATE_INTERMEDIATE )
435 hr = VFW_E_STATE_CHANGED;
436 if ( fs != State_Stopped )
437 hr = VFW_E_NOT_STOPPED;
441 TRACE( "(%p) search the specified name.\n",This );
445 pItem = QUARTZ_CompList_SearchData(
447 pName, sizeof(WCHAR)*(lstrlenW(pName)+1) );
451 hrSucceeded = VFW_S_DUPLICATE_NAME;
453 iLen = lstrlenW(pName);
456 memcpy( info.achName, pName, sizeof(WCHAR)*iLen );
457 info.achName[iLen] = 0;
461 ZeroMemory( &info, sizeof(info) );
462 hr = IBaseFilter_QueryFilterInfo( pFilter, &info );
466 iLen = lstrlenW(info.achName);
467 pItem = QUARTZ_CompList_SearchData(
469 info.achName, sizeof(WCHAR)*(iLen+1) );
470 if ( iLen > 0 && pItem == NULL )
472 pName = info.achName;
477 /* generate modified names for this filter.. */
478 iLen = lstrlenW(info.achName);
481 info.achName[iLen++] = ' ';
483 for ( i = 0; i <= 99; i++ )
485 info.achName[iLen+0] = (i%10) + '0';
486 info.achName[iLen+1] = ((i/10)%10) + '0';
487 info.achName[iLen+2] = 0;
488 pItem = QUARTZ_CompList_SearchData(
490 info.achName, sizeof(WCHAR)*(iLen+3) );
493 pName = info.achName;
498 hr = ( pName == NULL ) ? E_FAIL : VFW_E_DUPLICATE_NAME;
502 TRACE( "(%p) add this filter - %s.\n",This,debugstr_w(pName) );
504 /* register this filter. */
505 hr = QUARTZ_CompList_AddComp(
506 This->m_pFilterList, (IUnknown*)pFilter,
507 pName, sizeof(WCHAR)*(lstrlenW(pName)+1) );
511 hr = IBaseFilter_JoinFilterGraph(pFilter,(IFilterGraph*)iface,pName);
514 EnterCriticalSection( &This->m_csClock );
515 hr = IBaseFilter_SetSyncSource( pFilter, This->m_pClock );
516 LeaveCriticalSection( &This->m_csClock );
520 IBaseFilter_JoinFilterGraph(pFilter,NULL,pName);
521 QUARTZ_CompList_RemoveComp(
522 This->m_pFilterList,(IUnknown*)pFilter);
526 hr = CFilterGraph_GraphChanged(This);
532 QUARTZ_CompList_Unlock( This->m_pFilterList );
534 TRACE( "(%p) return %08lx\n", This, hr );
539 static HRESULT WINAPI
540 IFilterGraph2_fnRemoveFilter(IFilterGraph2* iface,IBaseFilter* pFilter)
542 CFilterGraph_THIS(iface,fgraph);
543 QUARTZ_CompListItem* pItem;
545 HRESULT hr = NOERROR;
547 TRACE( "(%p)->(%p)\n",This,pFilter );
549 QUARTZ_CompList_Lock( This->m_pFilterList );
551 hr = IMediaFilter_GetState(CFilterGraph_IMediaFilter(This),0,&fs);
552 if ( hr == VFW_S_STATE_INTERMEDIATE )
553 hr = VFW_E_STATE_CHANGED;
554 if ( fs != State_Stopped )
555 hr = VFW_E_NOT_STOPPED;
559 hr = S_FALSE; /* FIXME? */
560 pItem = QUARTZ_CompList_SearchComp(
561 This->m_pFilterList, (IUnknown*)pFilter );
564 CFilterGraph_DisconnectAllPins(pFilter);
565 IBaseFilter_SetSyncSource( pFilter, NULL );
566 hr = IBaseFilter_JoinFilterGraph(
567 pFilter, NULL, QUARTZ_CompList_GetDataPtr(pItem) );
568 QUARTZ_CompList_RemoveComp(
569 This->m_pFilterList, (IUnknown*)pFilter );
572 hr = CFilterGraph_GraphChanged(This);
577 QUARTZ_CompList_Unlock( This->m_pFilterList );
582 static HRESULT WINAPI
583 IFilterGraph2_fnEnumFilters(IFilterGraph2* iface,IEnumFilters** ppEnum)
585 CFilterGraph_THIS(iface,fgraph);
588 TRACE( "(%p)->(%p)\n",This,ppEnum );
590 QUARTZ_CompList_Lock( This->m_pFilterList );
592 hr = QUARTZ_CreateEnumUnknown(
593 &IID_IEnumFilters, (void**)ppEnum, This->m_pFilterList );
595 QUARTZ_CompList_Unlock( This->m_pFilterList );
600 static HRESULT WINAPI
601 IFilterGraph2_fnFindFilterByName(IFilterGraph2* iface,LPCWSTR pName,IBaseFilter** ppFilter)
603 CFilterGraph_THIS(iface,fgraph);
604 QUARTZ_CompListItem* pItem;
607 TRACE( "(%p)->(%s,%p)\n",This,debugstr_w(pName),ppFilter );
609 if ( ppFilter == NULL )
613 QUARTZ_CompList_Lock( This->m_pFilterList );
615 pItem = QUARTZ_CompList_SearchData(
617 pName, sizeof(WCHAR)*(lstrlenW(pName)+1) );
620 *ppFilter = (IBaseFilter*)QUARTZ_CompList_GetItemPtr(pItem);
624 QUARTZ_CompList_Unlock( This->m_pFilterList );
629 static HRESULT WINAPI
630 IFilterGraph2_fnConnectDirect(IFilterGraph2* iface,IPin* pOut,IPin* pIn,const AM_MEDIA_TYPE* pmt)
632 CFilterGraph_THIS(iface,fgraph);
637 FILTER_INFO finfoOut;
641 TRACE( "(%p)->(%p,%p,%p)\n",This,pOut,pIn,pmt );
643 infoIn.pFilter = NULL;
644 infoOut.pFilter = NULL;
645 finfoIn.pGraph = NULL;
646 finfoOut.pGraph = NULL;
648 QUARTZ_CompList_Lock( This->m_pFilterList );
650 hr = IMediaFilter_GetState(CFilterGraph_IMediaFilter(This),0,&fs);
651 if ( hr == VFW_S_STATE_INTERMEDIATE )
652 hr = VFW_E_STATE_CHANGED;
653 if ( fs != State_Stopped )
654 hr = VFW_E_NOT_STOPPED;
658 hr = IPin_QueryPinInfo(pIn,&infoIn);
661 hr = IPin_QueryPinInfo(pOut,&infoOut);
664 if ( infoIn.pFilter == NULL || infoOut.pFilter == NULL ||
665 infoIn.dir != PINDIR_INPUT || infoOut.dir != PINDIR_OUTPUT )
671 hr = IBaseFilter_QueryFilterInfo(infoIn.pFilter,&finfoIn);
674 hr = IBaseFilter_QueryFilterInfo(infoOut.pFilter,&finfoOut);
677 if ( finfoIn.pGraph != ((IFilterGraph*)iface) ||
678 finfoOut.pGraph != ((IFilterGraph*)iface) )
685 hr = IPin_ConnectedTo(pIn,&pConnTo);
686 if ( hr == NOERROR && pConnTo != NULL )
688 IPin_Release(pConnTo);
689 hr = VFW_E_ALREADY_CONNECTED;
694 hr = IPin_ConnectedTo(pOut,&pConnTo);
695 if ( hr == NOERROR && pConnTo != NULL )
697 IPin_Release(pConnTo);
698 hr = VFW_E_ALREADY_CONNECTED;
702 TRACE("(%p) try to connect %p<->%p\n",This,pIn,pOut);
703 hr = IPin_Connect(pOut,pIn,pmt);
706 TRACE("(%p)->Connect(%p,%p) hr = %08lx\n",pOut,pIn,pmt,hr);
707 IPin_Disconnect(pOut);
708 IPin_Disconnect(pIn);
712 hr = CFilterGraph_GraphChanged(This);
717 QUARTZ_CompList_Unlock( This->m_pFilterList );
719 if ( infoIn.pFilter != NULL )
720 IBaseFilter_Release(infoIn.pFilter);
721 if ( infoOut.pFilter != NULL )
722 IBaseFilter_Release(infoOut.pFilter);
723 if ( finfoIn.pGraph != NULL )
724 IFilterGraph_Release(finfoIn.pGraph);
725 if ( finfoOut.pGraph != NULL )
726 IFilterGraph_Release(finfoOut.pGraph);
731 static HRESULT WINAPI
732 IFilterGraph2_fnReconnect(IFilterGraph2* iface,IPin* pPin)
734 CFilterGraph_THIS(iface,fgraph);
736 TRACE( "(%p)->(%p)\n",This,pPin );
738 return IFilterGraph2_ReconnectEx(iface,pPin,NULL);
741 static HRESULT WINAPI
742 IFilterGraph2_fnDisconnect(IFilterGraph2* iface,IPin* pPin)
744 CFilterGraph_THIS(iface,fgraph);
748 TRACE( "(%p)->(%p)\n",This,pPin );
750 QUARTZ_CompList_Lock( This->m_pFilterList );
753 hr = IPin_ConnectedTo(pPin,&pConnTo);
754 if ( hr == NOERROR && pConnTo != NULL )
756 IPin_Disconnect(pConnTo);
757 IPin_Release(pConnTo);
759 hr = IPin_Disconnect(pPin);
763 hr = CFilterGraph_GraphChanged(This);
768 QUARTZ_CompList_Unlock( This->m_pFilterList );
773 static HRESULT WINAPI
774 IFilterGraph2_fnSetDefaultSyncSource(IFilterGraph2* iface)
776 CFilterGraph_THIS(iface,fgraph);
778 IReferenceClock* pClock;
781 FIXME( "(%p)->() stub!\n", This );
783 /* FIXME - search all filters from renderer. */
785 hr = QUARTZ_CreateSystemClock( NULL, (void**)&punk );
788 hr = IUnknown_QueryInterface( punk, &IID_IReferenceClock, (void**)&pClock ); IUnknown_Release( punk );
792 hr = IMediaFilter_SetSyncSource(
793 CFilterGraph_IMediaFilter(This), pClock );
794 IReferenceClock_Release( pClock );
799 static HRESULT WINAPI
800 IFilterGraph2_fnConnect(IFilterGraph2* iface,IPin* pOut,IPin* pIn)
802 CFilterGraph_THIS(iface,fgraph);
803 IFilterMapper2* pMap2 = NULL;
804 IEnumMoniker* pEnumMon = NULL;
805 IMoniker* pMon = NULL;
806 IBaseFilter* pFilter = NULL;
807 IEnumPins* pEnumPin = NULL;
808 IPin* pPinTry = NULL;
810 PIN_DIRECTION pindir;
813 BOOL bConnected = FALSE;
814 CLSID clsidOutFilter;
819 TRACE( "(%p)->(%p,%p)\n",This,pOut,pIn );
821 /* At first, try to connect directly. */
822 hr = IFilterGraph_ConnectDirect(iface,pOut,pIn,NULL);
826 /* FIXME - try to connect indirectly. */
827 FIXME( "(%p)->(%p,%p) stub!\n",This,pOut,pIn );
830 hr = IPin_QueryPinInfo(pOut,&info);
833 if ( info.pFilter == NULL )
835 hr = IBaseFilter_GetClassID(info.pFilter,&clsidOutFilter);
836 IBaseFilter_Release(info.pFilter);
841 hr = IPin_QueryPinInfo(pIn,&info);
844 if ( info.pFilter == NULL )
846 hr = IBaseFilter_GetClassID(info.pFilter,&clsidInFilter);
847 IBaseFilter_Release(info.pFilter);
851 /* FIXME - try to connect with unused filters. */
852 /* FIXME - try to connect with cached filters. */
853 /* FIXME - enumerate transform filters and try to connect */
854 hr = CoCreateInstance(
855 &CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
856 &IID_IFilterMapper2, (void**)&pMap2 );
859 hr = IFilterMapper2_EnumMatchingFilters(
860 pMap2,&pEnumMon,0,FALSE,MERIT_DO_NOT_USE+1,
861 TRUE,0,NULL,NULL,NULL,FALSE,
862 TRUE,0,NULL,NULL,NULL);
863 IFilterMapper2_Release(pMap2);
866 TRACE("try to connect indirectly\n");
870 while ( !bConnected && hr == S_OK )
872 hr = IEnumMoniker_Next(pEnumMon,1,&pMon,&cReturned);
875 hr = IMoniker_BindToObject(pMon,NULL,NULL,&IID_IBaseFilter,(void**)&pFilter );
878 hr = IBaseFilter_GetClassID(pFilter,&clsid);
880 ( IsEqualGUID(&clsidOutFilter,&clsid) || IsEqualGUID(&clsidInFilter,&clsid) ) )
883 hr = IFilterGraph2_AddFilter(iface,pFilter,NULL);
887 hr = IBaseFilter_EnumPins(pFilter,&pEnumPin);
891 while ( !bTryConnect )
893 hr = IEnumPins_Next(pEnumPin,1,&pPinTry,&cReturned);
896 hr = IPin_QueryDirection(pPinTry,&pindir);
897 if ( hr == S_OK && pindir == PINDIR_INPUT )
899 /* try to connect directly. */
900 hr = IFilterGraph2_ConnectDirect(iface,pOut,pPinTry,NULL);
905 IPin_Release(pPinTry); pPinTry = NULL;
908 IEnumPins_Release(pEnumPin); pEnumPin = NULL;
910 TRACE("TryConnect %d\n",bTryConnect);
914 hr = IBaseFilter_EnumPins(pFilter,&pEnumPin);
917 while ( !bConnected )
919 hr = IEnumPins_Next(pEnumPin,1,&pPinTry,&cReturned);
922 hr = IPin_QueryDirection(pPinTry,&pindir);
923 if ( hr == S_OK && pindir == PINDIR_OUTPUT )
925 /* try to connect indirectly. */
926 hr = IFilterGraph2_Connect(iface,pPinTry,pIn);
931 IPin_Release(pPinTry); pPinTry = NULL;
933 IEnumPins_Release(pEnumPin); pEnumPin = NULL;
937 hr = IFilterGraph2_RemoveFilter(iface,pFilter);
939 IBaseFilter_Release(pFilter); pFilter = NULL;
943 IMoniker_Release(pMon); pMon = NULL;
945 IEnumMoniker_Release(pEnumMon); pEnumMon = NULL;
948 if ( SUCCEEDED(hr) && !bConnected )
949 hr = VFW_E_CANNOT_CONNECT;
954 static HRESULT WINAPI
955 IFilterGraph2_fnRender(IFilterGraph2* iface,IPin* pOut)
957 CFilterGraph_THIS(iface,fgraph);
959 IFilterMapper2* pMap2 = NULL;
960 IEnumMoniker* pEnumMon = NULL;
961 IMoniker* pMon = NULL;
962 IBaseFilter* pFilter = NULL;
963 IEnumPins* pEnumPin = NULL;
965 PIN_DIRECTION pindir;
966 BOOL bRendered = FALSE;
969 FIXME( "(%p)->(%p)\n",This,pOut );
971 /* FIXME - must be locked */
972 /*QUARTZ_CompList_Lock( This->m_pFilterList );*/
977 hr = CoCreateInstance(
978 &CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
979 &IID_IFilterMapper2, (void**)&pMap2 );
982 hr = IFilterMapper2_EnumMatchingFilters(
983 pMap2,&pEnumMon,0,FALSE,MERIT_DO_NOT_USE+1,
984 TRUE,0,NULL,NULL,NULL,TRUE,
985 FALSE,0,NULL,NULL,NULL);
986 IFilterMapper2_Release(pMap2);
989 TRACE("try to render pin\n");
993 /* try to render pin. */
994 while ( !bRendered && hr == S_OK )
996 hr = IEnumMoniker_Next(pEnumMon,1,&pMon,&cReturned);
999 hr = IMoniker_BindToObject(pMon,NULL,NULL,&IID_IBaseFilter,(void**)&pFilter );
1002 hr = IFilterGraph2_AddFilter(iface,pFilter,NULL);
1005 hr = IBaseFilter_EnumPins(pFilter,&pEnumPin);
1008 while ( !bRendered )
1010 hr = IEnumPins_Next(pEnumPin,1,&pPin,&cReturned);
1013 hr = IPin_QueryDirection(pPin,&pindir);
1014 if ( hr == S_OK && pindir == PINDIR_INPUT )
1016 /* try to connect. */
1017 hr = IFilterGraph2_Connect(iface,pOut,pPin);
1022 IPin_Release(pPin); pPin = NULL;
1024 IEnumPins_Release(pEnumPin); pEnumPin = NULL;
1027 hr = IFilterGraph2_RemoveFilter(iface,pFilter);
1029 IBaseFilter_Release(pFilter); pFilter = NULL;
1030 if ( SUCCEEDED(hr) )
1033 IMoniker_Release(pMon); pMon = NULL;
1035 IEnumMoniker_Release(pEnumMon); pEnumMon = NULL;
1040 /* successfully rendered(but may be partial now) */
1043 /* FIXME - try to render all inserted filters. */
1044 /* hr = VFW_S_PARTIAL_RENDER; */
1048 if ( SUCCEEDED(hr) )
1049 hr = VFW_E_CANNOT_RENDER;
1052 /*QUARTZ_CompList_Unlock( This->m_pFilterList );*/
1057 static HRESULT WINAPI
1058 IFilterGraph2_fnRenderFile(IFilterGraph2* iface,LPCWSTR lpFileName,LPCWSTR lpPlayList)
1060 CFilterGraph_THIS(iface,fgraph);
1062 IBaseFilter* pFilter = NULL;
1063 IEnumPins* pEnum = NULL;
1070 TRACE( "(%p)->(%s,%s)\n",This,
1071 debugstr_w(lpFileName),debugstr_w(lpPlayList) );
1073 if ( lpPlayList != NULL )
1074 return E_INVALIDARG;
1077 hr = IFilterGraph2_AddSourceFilter(iface,lpFileName,NULL,&pFilter);
1080 if ( pFilter == NULL )
1085 TRACE("(%p) source filter %p\n",This,pFilter);
1088 hr = IBaseFilter_EnumPins( pFilter, &pEnum );
1091 if ( pEnum == NULL )
1104 hr = IEnumPins_Next( pEnum, 1, &pPin, &cFetched );
1107 if ( hr != NOERROR || pPin == NULL || cFetched != 1 )
1112 hr = IPin_QueryDirection( pPin, &dir );
1113 if ( hr == NOERROR && dir == PINDIR_OUTPUT )
1116 hr = IFilterGraph2_Render( iface, pPin );
1117 if ( hr == NOERROR )
1120 IPin_Release( pPin );
1123 if ( hr == NOERROR )
1125 if ( cTryToRender > cActRender )
1126 hr = VFW_S_PARTIAL_RENDER;
1127 if ( cActRender == 0 )
1132 if ( pEnum != NULL )
1133 IEnumPins_Release( pEnum );
1134 if ( pFilter != NULL )
1135 IBaseFilter_Release( pFilter );
1140 static HRESULT WINAPI
1141 IFilterGraph2_fnAddSourceFilter(IFilterGraph2* iface,LPCWSTR lpFileName,LPCWSTR lpFilterName,IBaseFilter** ppBaseFilter)
1143 CFilterGraph_THIS(iface,fgraph);
1145 BYTE bStartData[512];
1149 IFileSourceFilter* pSource;
1151 FIXME( "(%p)->(%s,%s,%p)\n",This,
1152 debugstr_w(lpFileName),debugstr_w(lpFilterName),ppBaseFilter );
1154 if ( lpFileName == NULL || ppBaseFilter == NULL )
1156 *ppBaseFilter = NULL;
1158 hr = QUARTZ_PeekFile( lpFileName, bStartData, 512, &cbStartData );
1161 FIXME("cannot open %s (NOTE: URL is not implemented)\n", debugstr_w(lpFileName));
1164 ZeroMemory( &mt, sizeof(AM_MEDIA_TYPE) );
1165 mt.bFixedSizeSamples = 1;
1167 memcpy( &mt.majortype, &MEDIATYPE_Stream, sizeof(GUID) );
1168 memcpy( &mt.subtype, &MEDIASUBTYPE_NULL, sizeof(GUID) );
1169 memcpy( &mt.formattype, &FORMAT_None, sizeof(GUID) );
1170 hr = QUARTZ_GetSourceTypeFromData(
1171 bStartData, cbStartData,
1172 &mt.majortype, &mt.subtype, &clsidSource );
1175 ERR("QUARTZ_GetSourceTypeFromData() failed - return %08lx\n",hr);
1180 FIXME( "file %s - unknown format\n", debugstr_w(lpFileName) );
1181 return VFW_E_INVALID_FILE_FORMAT;
1184 hr = CoCreateInstance(
1185 &clsidSource, NULL, CLSCTX_INPROC_SERVER,
1186 &IID_IBaseFilter, (void**)ppBaseFilter );
1189 hr = IBaseFilter_QueryInterface(*ppBaseFilter,&IID_IFileSourceFilter,(void**)&pSource);
1190 if ( SUCCEEDED(hr) )
1192 hr = IFileSourceFilter_Load(pSource,lpFileName,&mt);
1193 IFileSourceFilter_Release(pSource);
1195 if ( SUCCEEDED(hr) )
1196 hr = IFilterGraph2_AddFilter(iface,*ppBaseFilter,lpFilterName);
1199 IBaseFilter_Release(*ppBaseFilter);
1200 *ppBaseFilter = NULL;
1207 static HRESULT WINAPI
1208 IFilterGraph2_fnSetLogFile(IFilterGraph2* iface,DWORD_PTR hFile)
1210 CFilterGraph_THIS(iface,fgraph);
1212 FIXME( "(%p)->() stub!\n", This );
1216 static HRESULT WINAPI
1217 IFilterGraph2_fnAbort(IFilterGraph2* iface)
1219 CFilterGraph_THIS(iface,fgraph);
1223 FIXME( "(%p)->() stub!\n", This );
1227 static HRESULT WINAPI
1228 IFilterGraph2_fnShouldOperationContinue(IFilterGraph2* iface)
1230 CFilterGraph_THIS(iface,fgraph);
1234 FIXME( "(%p)->() stub!\n", This );
1238 static HRESULT WINAPI
1239 IFilterGraph2_fnAddSourceFilterForMoniker(IFilterGraph2* iface,IMoniker* pMon,IBindCtx* pCtx,LPCWSTR pFilterName,IBaseFilter** ppFilter)
1241 CFilterGraph_THIS(iface,fgraph);
1243 FIXME( "(%p)->() stub!\n", This );
1247 static HRESULT WINAPI
1248 IFilterGraph2_fnReconnectEx(IFilterGraph2* iface,IPin* pPin,const AM_MEDIA_TYPE* pmt)
1250 CFilterGraph_THIS(iface,fgraph);
1253 FIXME( "(%p)->(%p,%p) stub!\n",This,pPin,pmt );
1255 /* reconnect asynchronously. */
1257 QUARTZ_CompList_Lock( This->m_pFilterList );
1258 hr = CFilterGraph_GraphChanged(This);
1259 QUARTZ_CompList_Unlock( This->m_pFilterList );
1264 static HRESULT WINAPI
1265 IFilterGraph2_fnRenderEx(IFilterGraph2* iface,IPin* pPin,DWORD dwParam1,DWORD* pdwParam2)
1267 CFilterGraph_THIS(iface,fgraph);
1270 FIXME( "(%p)->(%p,%08lx,%p) stub!\n",This,pPin,dwParam1,pdwParam2);
1277 static ICOM_VTABLE(IFilterGraph2) ifgraph =
1279 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1280 /* IUnknown fields */
1281 IFilterGraph2_fnQueryInterface,
1282 IFilterGraph2_fnAddRef,
1283 IFilterGraph2_fnRelease,
1284 /* IFilterGraph fields */
1285 IFilterGraph2_fnAddFilter,
1286 IFilterGraph2_fnRemoveFilter,
1287 IFilterGraph2_fnEnumFilters,
1288 IFilterGraph2_fnFindFilterByName,
1289 IFilterGraph2_fnConnectDirect,
1290 IFilterGraph2_fnReconnect,
1291 IFilterGraph2_fnDisconnect,
1292 IFilterGraph2_fnSetDefaultSyncSource,
1293 /* IGraphBuilder fields */
1294 IFilterGraph2_fnConnect,
1295 IFilterGraph2_fnRender,
1296 IFilterGraph2_fnRenderFile,
1297 IFilterGraph2_fnAddSourceFilter,
1298 IFilterGraph2_fnSetLogFile,
1299 IFilterGraph2_fnAbort,
1300 IFilterGraph2_fnShouldOperationContinue,
1301 /* IFilterGraph2 fields */
1302 IFilterGraph2_fnAddSourceFilterForMoniker,
1303 IFilterGraph2_fnReconnectEx,
1304 IFilterGraph2_fnRenderEx,
1307 HRESULT CFilterGraph_InitIFilterGraph2( CFilterGraph* pfg )
1309 TRACE("(%p)\n",pfg);
1310 ICOM_VTBL(&pfg->fgraph) = &ifgraph;
1312 pfg->m_pFilterList = QUARTZ_CompList_Alloc();
1313 if ( pfg->m_pFilterList == NULL )
1314 return E_OUTOFMEMORY;
1319 void CFilterGraph_UninitIFilterGraph2( CFilterGraph* pfg )
1321 QUARTZ_CompListItem* pItem;
1323 TRACE("(%p)\n",pfg);
1325 /* remove all filters... */
1328 pItem = QUARTZ_CompList_GetFirst( pfg->m_pFilterList );
1329 if ( pItem == NULL )
1331 IFilterGraph2_RemoveFilter(
1332 (IFilterGraph2*)(&pfg->fgraph),
1333 (IBaseFilter*)QUARTZ_CompList_GetItemPtr(pItem) );
1336 QUARTZ_CompList_Free( pfg->m_pFilterList );
1339 /***************************************************************************
1341 * CFilterGraph::IGraphVersion methods
1345 static HRESULT WINAPI
1346 IGraphVersion_fnQueryInterface(IGraphVersion* iface,REFIID riid,void** ppobj)
1348 CFilterGraph_THIS(iface,graphversion);
1350 TRACE("(%p)->()\n",This);
1352 return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
1356 IGraphVersion_fnAddRef(IGraphVersion* iface)
1358 CFilterGraph_THIS(iface,graphversion);
1360 TRACE("(%p)->()\n",This);
1362 return IUnknown_AddRef(This->unk.punkControl);
1366 IGraphVersion_fnRelease(IGraphVersion* iface)
1368 CFilterGraph_THIS(iface,graphversion);
1370 TRACE("(%p)->()\n",This);
1372 return IUnknown_Release(This->unk.punkControl);
1376 static HRESULT WINAPI
1377 IGraphVersion_fnQueryVersion(IGraphVersion* iface,LONG* plVersion)
1379 CFilterGraph_THIS(iface,graphversion);
1381 TRACE("(%p)->(%p)\n",This,plVersion);
1383 if ( plVersion == NULL )
1386 QUARTZ_CompList_Lock( This->m_pFilterList );
1387 *plVersion = This->m_lGraphVersion;
1388 QUARTZ_CompList_Unlock( This->m_pFilterList );
1394 static ICOM_VTABLE(IGraphVersion) igraphversion =
1396 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1397 /* IUnknown fields */
1398 IGraphVersion_fnQueryInterface,
1399 IGraphVersion_fnAddRef,
1400 IGraphVersion_fnRelease,
1401 /* IGraphVersion fields */
1402 IGraphVersion_fnQueryVersion,
1407 HRESULT CFilterGraph_InitIGraphVersion( CFilterGraph* pfg )
1409 TRACE("(%p)\n",pfg);
1410 ICOM_VTBL(&pfg->graphversion) = &igraphversion;
1412 pfg->m_lGraphVersion = 1;
1417 void CFilterGraph_UninitIGraphVersion( CFilterGraph* pfg )
1419 TRACE("(%p)\n",pfg);
1422 /***************************************************************************
1424 * CFilterGraph::IGraphConfig methods
1428 static HRESULT WINAPI
1429 IGraphConfig_fnQueryInterface(IGraphConfig* iface,REFIID riid,void** ppobj)
1431 CFilterGraph_THIS(iface,grphconf);
1433 TRACE("(%p)->()\n",This);
1435 return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
1439 IGraphConfig_fnAddRef(IGraphConfig* iface)
1441 CFilterGraph_THIS(iface,grphconf);
1443 TRACE("(%p)->()\n",This);
1445 return IUnknown_AddRef(This->unk.punkControl);
1449 IGraphConfig_fnRelease(IGraphConfig* iface)
1451 CFilterGraph_THIS(iface,grphconf);
1453 TRACE("(%p)->()\n",This);
1455 return IUnknown_Release(This->unk.punkControl);
1460 static HRESULT WINAPI
1461 IGraphConfig_fnReconnect(IGraphConfig* iface,IPin* pOut,IPin* pIn,const AM_MEDIA_TYPE* pmt,IBaseFilter* pFilter,HANDLE hAbort,DWORD dwFlags)
1463 CFilterGraph_THIS(iface,grphconf);
1465 FIXME("(%p)->() stub!\n",This);
1470 static HRESULT WINAPI
1471 IGraphConfig_fnReconfigure(IGraphConfig* iface,IGraphConfigCallback* pCallback,PVOID pvParam,DWORD dwFlags,HANDLE hAbort)
1473 CFilterGraph_THIS(iface,grphconf);
1476 FIXME("(%p)->(%p,%p,%08lx,%08x) stub!\n",This,pCallback,pvParam,dwFlags,hAbort);
1478 QUARTZ_CompList_Lock( This->m_pFilterList );
1479 EnterCriticalSection( &This->m_csGraphState );
1481 hr = IGraphConfigCallback_Reconfigure(pCallback,pvParam,dwFlags);
1483 LeaveCriticalSection( &This->m_csGraphState );
1484 QUARTZ_CompList_Unlock( This->m_pFilterList );
1489 static HRESULT WINAPI
1490 IGraphConfig_fnAddFilterToCache(IGraphConfig* iface,IBaseFilter* pFilter)
1492 CFilterGraph_THIS(iface,grphconf);
1494 FIXME("(%p)->() stub!\n",This);
1499 static HRESULT WINAPI
1500 IGraphConfig_fnEnumCacheFilter(IGraphConfig* iface,IEnumFilters** ppenum)
1502 CFilterGraph_THIS(iface,grphconf);
1504 FIXME("(%p)->() stub!\n",This);
1509 static HRESULT WINAPI
1510 IGraphConfig_fnRemoveFilterFromCache(IGraphConfig* iface,IBaseFilter* pFilter)
1512 CFilterGraph_THIS(iface,grphconf);
1514 FIXME("(%p)->() stub!\n",This);
1519 static HRESULT WINAPI
1520 IGraphConfig_fnGetStartTime(IGraphConfig* iface,REFERENCE_TIME* prt)
1522 CFilterGraph_THIS(iface,grphconf);
1524 FIXME("(%p)->() stub!\n",This);
1529 static HRESULT WINAPI
1530 IGraphConfig_fnPushThroughData(IGraphConfig* iface,IPin* pOut,IPinConnection* pConn,HANDLE hAbort)
1532 CFilterGraph_THIS(iface,grphconf);
1534 FIXME("(%p)->() stub!\n",This);
1539 static HRESULT WINAPI
1540 IGraphConfig_fnSetFilterFlags(IGraphConfig* iface,IBaseFilter* pFilter,DWORD dwFlags)
1542 CFilterGraph_THIS(iface,grphconf);
1544 FIXME("(%p)->() stub!\n",This);
1549 static HRESULT WINAPI
1550 IGraphConfig_fnGetFilterFlags(IGraphConfig* iface,IBaseFilter* pFilter,DWORD* pdwFlags)
1552 CFilterGraph_THIS(iface,grphconf);
1554 FIXME("(%p)->() stub!\n",This);
1559 static HRESULT WINAPI
1560 IGraphConfig_fnRemoveFilterEx(IGraphConfig* iface,IBaseFilter* pFilter,DWORD dwFlags)
1562 CFilterGraph_THIS(iface,grphconf);
1564 FIXME("(%p)->() stub!\n",This);
1573 static ICOM_VTABLE(IGraphConfig) igraphconfig =
1575 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1576 /* IUnknown fields */
1577 IGraphConfig_fnQueryInterface,
1578 IGraphConfig_fnAddRef,
1579 IGraphConfig_fnRelease,
1580 /* IGraphConfig fields */
1581 IGraphConfig_fnReconnect,
1582 IGraphConfig_fnReconfigure,
1583 IGraphConfig_fnAddFilterToCache,
1584 IGraphConfig_fnEnumCacheFilter,
1585 IGraphConfig_fnRemoveFilterFromCache,
1586 IGraphConfig_fnGetStartTime,
1587 IGraphConfig_fnPushThroughData,
1588 IGraphConfig_fnSetFilterFlags,
1589 IGraphConfig_fnGetFilterFlags,
1590 IGraphConfig_fnRemoveFilterEx,
1595 HRESULT CFilterGraph_InitIGraphConfig( CFilterGraph* pfg )
1597 TRACE("(%p)\n",pfg);
1598 ICOM_VTBL(&pfg->grphconf) = &igraphconfig;
1603 void CFilterGraph_UninitIGraphConfig( CFilterGraph* pfg )
1605 TRACE("(%p)\n",pfg);