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 * Copyright (C) Hidenori TAKESHIMA <hidenori@a2.ctktv.ne.jp>
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
42 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
45 #include "quartz_private.h"
53 #define NUMELEMS(elem) (sizeof(elem)/sizeof(elem[0]))
56 static HRESULT CFilterGraph_DisconnectAllPins( IBaseFilter* pFilter )
58 IEnumPins* pEnum = NULL;
64 hr = IBaseFilter_EnumPins( pFilter, &pEnum );
74 hr = IEnumPins_Next( pEnum, 1, &pPin, &cFetched );
77 if ( hr != NOERROR || pPin == NULL || cFetched != 1 )
84 hr = IPin_ConnectedTo(pPin,&pConnTo);
85 if ( hr == NOERROR && pConnTo != NULL )
87 IPin_Disconnect(pPin);
88 IPin_Disconnect(pConnTo);
89 IPin_Release(pConnTo);
95 IEnumPins_Release( pEnum );
101 static HRESULT CFilterGraph_GraphChanged( CFilterGraph* This )
103 /* IDistributorNotify_NotifyGraphChange() */
105 IMediaEventSink_Notify(CFilterGraph_IMediaEventSink(This),
106 EC_GRAPH_CHANGED, 0, 0);
107 This->m_lGraphVersion ++;
112 /***************************************************************************
114 * CFilterGraph internal methods for IFilterGraph2::AddSourceFilter().
118 static HRESULT QUARTZ_PeekFile(
119 const WCHAR* pwszFileName,
120 BYTE* pData, DWORD cbData, DWORD* pcbRead )
126 hFile = CreateFileW( pwszFileName,
127 GENERIC_READ, FILE_SHARE_READ,
128 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL );
129 if ( hFile == INVALID_HANDLE_VALUE )
131 if ( ReadFile( hFile, pData, cbData, pcbRead, NULL ) )
133 CloseHandle( hFile );
139 static const WCHAR* skip_space(const WCHAR* pwsz)
141 if ( pwsz == NULL ) return NULL;
142 while ( *pwsz == (WCHAR)' ' ) pwsz++;
146 static const WCHAR* get_dword(const WCHAR* pwsz,DWORD* pdw)
151 if ( pwsz == NULL ) return NULL;
152 while ( *pwsz >= (WCHAR)'0' && *pwsz <= (WCHAR)'9' )
154 dw = dw * 10 + (DWORD)(*pwsz-(WCHAR)'0');
161 static int wchar_to_hex(WCHAR wch)
163 if ( wch >= (WCHAR)'0' && wch <= (WCHAR)'9' )
164 return (int)(wch - (WCHAR)'0');
165 if ( wch >= (WCHAR)'A' && wch <= (WCHAR)'F' )
166 return (int)(wch - (WCHAR)'A' + 10);
167 if ( wch >= (WCHAR)'a' && wch <= (WCHAR)'f' )
168 return (int)(wch - (WCHAR)'a' + 10);
172 static const WCHAR* get_hex(const WCHAR* pwsz,BYTE* pb)
177 if ( pwsz == NULL ) return NULL;
178 hi = wchar_to_hex(*pwsz); if ( hi < 0 ) return NULL; pwsz++;
179 lo = wchar_to_hex(*pwsz); if ( lo < 0 ) return NULL; pwsz++;
180 *pb = (BYTE)( (hi << 4) | lo );
184 static const WCHAR* skip_hex(const WCHAR* pwsz)
186 if ( pwsz == NULL ) return NULL;
189 if ( wchar_to_hex(*pwsz) < 0 )
196 static const WCHAR* next_token(const WCHAR* pwsz)
198 if ( pwsz == NULL ) return NULL;
199 pwsz = skip_space(pwsz);
200 if ( *pwsz != (WCHAR)',' ) return NULL; pwsz++;
201 return skip_space(pwsz);
205 static HRESULT QUARTZ_SourceTypeIsMatch(
206 const BYTE* pData, DWORD cbData,
207 const WCHAR* pwszTempl, DWORD cchTempl )
212 const WCHAR* pwszMask;
213 const WCHAR* pwszValue;
217 TRACE("(%p,%lu,%s,%lu)\n",pData,cbData,debugstr_w(pwszTempl),cchTempl);
219 pwszTempl = skip_space(pwszTempl);
222 pwszTempl = get_dword(pwszTempl,&dwOfs);
223 pwszTempl = next_token(pwszTempl);
224 pwszTempl = get_dword(pwszTempl,&cbLen);
225 pwszMask = pwszTempl = next_token(pwszTempl);
226 pwszTempl = skip_hex(pwszTempl);
227 pwszValue = pwszTempl = next_token(pwszTempl);
228 pwszTempl = skip_hex(pwszValue);
229 pwszTempl = skip_space(pwszTempl);
230 if ( pwszValue == NULL )
232 WARN( "parse error\n" );
236 if ( dwOfs >= cbData || ( (dwOfs+cbLen) >= cbData ) )
238 WARN( "length of given data is too short\n" );
242 for ( n = 0; n < cbLen; n++ )
244 pwszMask = get_hex(pwszMask,&bMask);
245 if ( pwszMask == NULL ) bMask = 0xff;
246 pwszValue = get_hex(pwszValue,&bValue);
247 if ( pwszValue == NULL )
249 WARN( "parse error - invalid hex data\n" );
252 if ( (pData[dwOfs+n]&bMask) != (bValue&bMask) )
254 TRACE( "not matched\n" );
259 if ( *pwszTempl == 0 )
261 pwszTempl = next_token(pwszTempl);
262 if ( pwszTempl == NULL )
264 WARN( "parse error\n" );
269 TRACE( "matched\n" );
273 static HRESULT QUARTZ_GetSourceTypeFromData(
274 const BYTE* pData, DWORD cbData,
275 GUID* pidMajor, GUID* pidSub, CLSID* pidSource )
277 HRESULT hr = S_FALSE;
281 WCHAR wszSource[128];
282 WCHAR wszSourceFilter[128];
283 WCHAR* pwszLocalBuf = NULL;
285 DWORD cbLocalBuf = 0;
295 FILETIME ftLastWrite;
296 static const WCHAR wszFmt[] = {'%','l','u',0};
298 if ( RegOpenKeyExW( HKEY_CLASSES_ROOT, QUARTZ_wszMediaType, 0, KEY_READ, &hkMajor ) == ERROR_SUCCESS )
301 while ( hr == S_FALSE )
303 cbPath = NUMELEMS(wszMajor)-1;
305 hkMajor, dwIndexMajor ++, wszMajor, &cbPath,
306 NULL, NULL, NULL, &ftLastWrite );
307 if ( lr != ERROR_SUCCESS )
309 if ( RegOpenKeyExW( hkMajor, wszMajor, 0, KEY_READ, &hkSub ) == ERROR_SUCCESS )
312 while ( hr == S_FALSE )
314 cbPath = NUMELEMS(wszSub)-1;
316 hkSub, dwIndexSub ++, wszSub, &cbPath,
317 NULL, NULL, NULL, &ftLastWrite );
318 if ( lr != ERROR_SUCCESS )
320 if ( RegOpenKeyExW( hkSub, wszSub, 0, KEY_READ, &hkSource ) == ERROR_SUCCESS )
323 while ( hr == S_FALSE )
325 wsprintfW(wszSource,wszFmt,dwIndexSource++);
326 lr = RegQueryValueExW(
327 hkSource, wszSource, NULL,
328 &dwRegType, NULL, &cbRegData );
329 if ( lr != ERROR_SUCCESS )
331 if ( cbLocalBuf < cbRegData )
333 pwszTemp = (WCHAR*)QUARTZ_ReallocMem( pwszLocalBuf, cbRegData+sizeof(WCHAR) );
334 if ( pwszTemp == NULL )
339 pwszLocalBuf = pwszTemp;
340 cbLocalBuf = cbRegData+sizeof(WCHAR);
342 cbRegData = cbLocalBuf;
343 lr = RegQueryValueExW(
344 hkSource, wszSource, NULL,
345 &dwRegType, (BYTE*)pwszLocalBuf, &cbRegData );
346 if ( lr != ERROR_SUCCESS )
349 hr = QUARTZ_SourceTypeIsMatch(
351 pwszLocalBuf, cbRegData / sizeof(WCHAR) );
354 hr = CLSIDFromString(wszMajor,pidMajor);
356 hr = CLSIDFromString(wszSub,pidSub);
359 lstrcpyW(wszSource,QUARTZ_wszSourceFilter);
360 cbRegData = NUMELEMS(wszSourceFilter)-sizeof(WCHAR);
361 lr = RegQueryValueExW(
362 hkSource, wszSource, NULL,
364 (BYTE*)wszSourceFilter, &cbRegData );
365 if ( lr == ERROR_SUCCESS )
367 hr = CLSIDFromString(wszSourceFilter,pidSource);
373 if ( hr != NOERROR && SUCCEEDED(hr) )
379 RegCloseKey( hkSource );
382 RegCloseKey( hkSub );
385 RegCloseKey( hkMajor );
388 if ( pwszLocalBuf != NULL )
389 QUARTZ_FreeMem(pwszLocalBuf);
396 /***************************************************************************
398 * CFilterGraph::IFilterGraph2 methods
402 static HRESULT WINAPI
403 IFilterGraph2_fnQueryInterface(IFilterGraph2* iface,REFIID riid,void** ppobj)
405 CFilterGraph_THIS(iface,fgraph);
407 TRACE("(%p)->()\n",This);
409 return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
413 IFilterGraph2_fnAddRef(IFilterGraph2* iface)
415 CFilterGraph_THIS(iface,fgraph);
417 TRACE("(%p)->()\n",This);
419 return IUnknown_AddRef(This->unk.punkControl);
423 IFilterGraph2_fnRelease(IFilterGraph2* iface)
425 CFilterGraph_THIS(iface,fgraph);
427 TRACE("(%p)->()\n",This);
429 return IUnknown_Release(This->unk.punkControl);
432 static HRESULT WINAPI
433 IFilterGraph2_fnAddFilter(IFilterGraph2* iface,IBaseFilter* pFilter, LPCWSTR pName)
435 CFilterGraph_THIS(iface,fgraph);
439 HRESULT hrSucceeded = S_OK;
440 QUARTZ_CompListItem* pItem;
443 TRACE( "(%p)->(%p,%s)\n",This,pFilter,debugstr_w(pName) );
445 QUARTZ_CompList_Lock( This->m_pFilterList );
447 hr = IMediaFilter_GetState(CFilterGraph_IMediaFilter(This),0,&fs);
448 if ( hr == VFW_S_STATE_INTERMEDIATE )
449 hr = VFW_E_STATE_CHANGED;
450 if ( fs != State_Stopped )
451 hr = VFW_E_NOT_STOPPED;
455 TRACE( "(%p) search the specified name.\n",This );
459 pItem = QUARTZ_CompList_SearchData(
461 pName, sizeof(WCHAR)*(lstrlenW(pName)+1) );
465 hrSucceeded = VFW_S_DUPLICATE_NAME;
467 iLen = lstrlenW(pName);
470 memcpy( info.achName, pName, sizeof(WCHAR)*iLen );
471 info.achName[iLen] = 0;
475 ZeroMemory( &info, sizeof(info) );
476 hr = IBaseFilter_QueryFilterInfo( pFilter, &info );
480 iLen = lstrlenW(info.achName);
481 pItem = QUARTZ_CompList_SearchData(
483 info.achName, sizeof(WCHAR)*(iLen+1) );
484 if ( iLen > 0 && pItem == NULL )
486 pName = info.achName;
491 /* generate modified names for this filter.. */
492 iLen = lstrlenW(info.achName);
495 info.achName[iLen++] = ' ';
497 for ( i = 0; i <= 99; i++ )
499 info.achName[iLen+0] = (i%10) + '0';
500 info.achName[iLen+1] = ((i/10)%10) + '0';
501 info.achName[iLen+2] = 0;
502 pItem = QUARTZ_CompList_SearchData(
504 info.achName, sizeof(WCHAR)*(iLen+3) );
507 pName = info.achName;
512 hr = ( pName == NULL ) ? E_FAIL : VFW_E_DUPLICATE_NAME;
516 TRACE( "(%p) add this filter - %s.\n",This,debugstr_w(pName) );
518 /* register this filter. */
519 hr = QUARTZ_CompList_AddComp(
520 This->m_pFilterList, (IUnknown*)pFilter,
521 pName, sizeof(WCHAR)*(lstrlenW(pName)+1) );
525 hr = IBaseFilter_JoinFilterGraph(pFilter,(IFilterGraph*)iface,pName);
528 EnterCriticalSection( &This->m_csClock );
529 hr = IBaseFilter_SetSyncSource( pFilter, This->m_pClock );
530 LeaveCriticalSection( &This->m_csClock );
534 IBaseFilter_JoinFilterGraph(pFilter,NULL,pName);
535 QUARTZ_CompList_RemoveComp(
536 This->m_pFilterList,(IUnknown*)pFilter);
540 hr = CFilterGraph_GraphChanged(This);
546 QUARTZ_CompList_Unlock( This->m_pFilterList );
548 TRACE( "(%p) return %08lx\n", This, hr );
553 static HRESULT WINAPI
554 IFilterGraph2_fnRemoveFilter(IFilterGraph2* iface,IBaseFilter* pFilter)
556 CFilterGraph_THIS(iface,fgraph);
557 QUARTZ_CompListItem* pItem;
559 HRESULT hr = NOERROR;
561 TRACE( "(%p)->(%p)\n",This,pFilter );
563 QUARTZ_CompList_Lock( This->m_pFilterList );
565 hr = IMediaFilter_GetState(CFilterGraph_IMediaFilter(This),0,&fs);
566 if ( hr == VFW_S_STATE_INTERMEDIATE )
567 hr = VFW_E_STATE_CHANGED;
568 if ( fs != State_Stopped )
569 hr = VFW_E_NOT_STOPPED;
573 hr = S_FALSE; /* FIXME? */
574 pItem = QUARTZ_CompList_SearchComp(
575 This->m_pFilterList, (IUnknown*)pFilter );
578 CFilterGraph_DisconnectAllPins(pFilter);
579 IBaseFilter_SetSyncSource( pFilter, NULL );
580 hr = IBaseFilter_JoinFilterGraph(
581 pFilter, NULL, QUARTZ_CompList_GetDataPtr(pItem) );
582 QUARTZ_CompList_RemoveComp(
583 This->m_pFilterList, (IUnknown*)pFilter );
586 hr = CFilterGraph_GraphChanged(This);
591 QUARTZ_CompList_Unlock( This->m_pFilterList );
596 static HRESULT WINAPI
597 IFilterGraph2_fnEnumFilters(IFilterGraph2* iface,IEnumFilters** ppEnum)
599 CFilterGraph_THIS(iface,fgraph);
602 TRACE( "(%p)->(%p)\n",This,ppEnum );
604 QUARTZ_CompList_Lock( This->m_pFilterList );
606 hr = QUARTZ_CreateEnumUnknown(
607 &IID_IEnumFilters, (void**)ppEnum, This->m_pFilterList );
609 QUARTZ_CompList_Unlock( This->m_pFilterList );
614 static HRESULT WINAPI
615 IFilterGraph2_fnFindFilterByName(IFilterGraph2* iface,LPCWSTR pName,IBaseFilter** ppFilter)
617 CFilterGraph_THIS(iface,fgraph);
618 QUARTZ_CompListItem* pItem;
621 TRACE( "(%p)->(%s,%p)\n",This,debugstr_w(pName),ppFilter );
623 if ( ppFilter == NULL )
627 QUARTZ_CompList_Lock( This->m_pFilterList );
629 pItem = QUARTZ_CompList_SearchData(
631 pName, sizeof(WCHAR)*(lstrlenW(pName)+1) );
634 *ppFilter = (IBaseFilter*)QUARTZ_CompList_GetItemPtr(pItem);
638 QUARTZ_CompList_Unlock( This->m_pFilterList );
643 static HRESULT WINAPI
644 IFilterGraph2_fnConnectDirect(IFilterGraph2* iface,IPin* pOut,IPin* pIn,const AM_MEDIA_TYPE* pmt)
646 CFilterGraph_THIS(iface,fgraph);
651 FILTER_INFO finfoOut;
655 TRACE( "(%p)->(%p,%p,%p)\n",This,pOut,pIn,pmt );
657 infoIn.pFilter = NULL;
658 infoOut.pFilter = NULL;
659 finfoIn.pGraph = NULL;
660 finfoOut.pGraph = NULL;
662 QUARTZ_CompList_Lock( This->m_pFilterList );
664 hr = IMediaFilter_GetState(CFilterGraph_IMediaFilter(This),0,&fs);
665 if ( hr == VFW_S_STATE_INTERMEDIATE )
666 hr = VFW_E_STATE_CHANGED;
667 if ( fs != State_Stopped )
668 hr = VFW_E_NOT_STOPPED;
672 hr = IPin_QueryPinInfo(pIn,&infoIn);
675 hr = IPin_QueryPinInfo(pOut,&infoOut);
678 if ( infoIn.pFilter == NULL || infoOut.pFilter == NULL ||
679 infoIn.dir != PINDIR_INPUT || infoOut.dir != PINDIR_OUTPUT )
685 hr = IBaseFilter_QueryFilterInfo(infoIn.pFilter,&finfoIn);
688 hr = IBaseFilter_QueryFilterInfo(infoOut.pFilter,&finfoOut);
691 if ( finfoIn.pGraph != ((IFilterGraph*)iface) ||
692 finfoOut.pGraph != ((IFilterGraph*)iface) )
699 hr = IPin_ConnectedTo(pIn,&pConnTo);
700 if ( hr == NOERROR && pConnTo != NULL )
702 IPin_Release(pConnTo);
703 hr = VFW_E_ALREADY_CONNECTED;
708 hr = IPin_ConnectedTo(pOut,&pConnTo);
709 if ( hr == NOERROR && pConnTo != NULL )
711 IPin_Release(pConnTo);
712 hr = VFW_E_ALREADY_CONNECTED;
716 TRACE("(%p) try to connect %p<->%p\n",This,pIn,pOut);
717 hr = IPin_Connect(pOut,pIn,pmt);
720 TRACE("(%p)->Connect(%p,%p) hr = %08lx\n",pOut,pIn,pmt,hr);
721 IPin_Disconnect(pOut);
722 IPin_Disconnect(pIn);
726 hr = CFilterGraph_GraphChanged(This);
731 QUARTZ_CompList_Unlock( This->m_pFilterList );
733 if ( infoIn.pFilter != NULL )
734 IBaseFilter_Release(infoIn.pFilter);
735 if ( infoOut.pFilter != NULL )
736 IBaseFilter_Release(infoOut.pFilter);
737 if ( finfoIn.pGraph != NULL )
738 IFilterGraph_Release(finfoIn.pGraph);
739 if ( finfoOut.pGraph != NULL )
740 IFilterGraph_Release(finfoOut.pGraph);
745 static HRESULT WINAPI
746 IFilterGraph2_fnReconnect(IFilterGraph2* iface,IPin* pPin)
748 CFilterGraph_THIS(iface,fgraph);
750 TRACE( "(%p)->(%p)\n",This,pPin );
752 return IFilterGraph2_ReconnectEx(iface,pPin,NULL);
755 static HRESULT WINAPI
756 IFilterGraph2_fnDisconnect(IFilterGraph2* iface,IPin* pPin)
758 CFilterGraph_THIS(iface,fgraph);
762 TRACE( "(%p)->(%p)\n",This,pPin );
764 QUARTZ_CompList_Lock( This->m_pFilterList );
767 hr = IPin_ConnectedTo(pPin,&pConnTo);
768 if ( hr == NOERROR && pConnTo != NULL )
770 IPin_Disconnect(pConnTo);
771 IPin_Release(pConnTo);
773 hr = IPin_Disconnect(pPin);
777 hr = CFilterGraph_GraphChanged(This);
782 QUARTZ_CompList_Unlock( This->m_pFilterList );
787 static HRESULT WINAPI
788 IFilterGraph2_fnSetDefaultSyncSource(IFilterGraph2* iface)
790 CFilterGraph_THIS(iface,fgraph);
792 IReferenceClock* pClock;
795 FIXME( "(%p)->() stub!\n", This );
797 /* FIXME - search all filters from renderer. */
799 hr = QUARTZ_CreateSystemClock( NULL, (void**)&punk );
802 hr = IUnknown_QueryInterface( punk, &IID_IReferenceClock, (void**)&pClock ); IUnknown_Release( punk );
806 hr = IMediaFilter_SetSyncSource(
807 CFilterGraph_IMediaFilter(This), pClock );
808 IReferenceClock_Release( pClock );
813 static HRESULT WINAPI
814 IFilterGraph2_fnConnect(IFilterGraph2* iface,IPin* pOut,IPin* pIn)
816 CFilterGraph_THIS(iface,fgraph);
817 IFilterMapper2* pMap2 = NULL;
818 IEnumMoniker* pEnumMon = NULL;
819 IMoniker* pMon = NULL;
820 IBaseFilter* pFilter = NULL;
821 IEnumPins* pEnumPin = NULL;
822 IPin* pPinTry = NULL;
824 PIN_DIRECTION pindir;
827 BOOL bConnected = FALSE;
828 CLSID clsidOutFilter;
833 TRACE( "(%p)->(%p,%p)\n",This,pOut,pIn );
835 /* At first, try to connect directly. */
836 hr = IFilterGraph_ConnectDirect(iface,pOut,pIn,NULL);
840 /* FIXME - try to connect indirectly. */
841 FIXME( "(%p)->(%p,%p) stub!\n",This,pOut,pIn );
844 hr = IPin_QueryPinInfo(pOut,&info);
847 if ( info.pFilter == NULL )
849 hr = IBaseFilter_GetClassID(info.pFilter,&clsidOutFilter);
850 IBaseFilter_Release(info.pFilter);
855 hr = IPin_QueryPinInfo(pIn,&info);
858 if ( info.pFilter == NULL )
860 hr = IBaseFilter_GetClassID(info.pFilter,&clsidInFilter);
861 IBaseFilter_Release(info.pFilter);
865 /* FIXME - try to connect with unused filters. */
866 /* FIXME - try to connect with cached filters. */
867 /* FIXME - enumerate transform filters and try to connect */
868 hr = CoCreateInstance(
869 &CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
870 &IID_IFilterMapper2, (void**)&pMap2 );
873 hr = IFilterMapper2_EnumMatchingFilters(
874 pMap2,&pEnumMon,0,FALSE,MERIT_DO_NOT_USE+1,
875 TRUE,0,NULL,NULL,NULL,FALSE,
876 TRUE,0,NULL,NULL,NULL);
877 IFilterMapper2_Release(pMap2);
880 TRACE("try to connect indirectly\n");
884 while ( !bConnected && hr == S_OK )
886 hr = IEnumMoniker_Next(pEnumMon,1,&pMon,&cReturned);
889 hr = IMoniker_BindToObject(pMon,NULL,NULL,&IID_IBaseFilter,(void**)&pFilter );
892 hr = IBaseFilter_GetClassID(pFilter,&clsid);
894 ( IsEqualGUID(&clsidOutFilter,&clsid) || IsEqualGUID(&clsidInFilter,&clsid) ) )
897 hr = IFilterGraph2_AddFilter(iface,pFilter,NULL);
901 hr = IBaseFilter_EnumPins(pFilter,&pEnumPin);
905 while ( !bTryConnect )
907 hr = IEnumPins_Next(pEnumPin,1,&pPinTry,&cReturned);
910 hr = IPin_QueryDirection(pPinTry,&pindir);
911 if ( hr == S_OK && pindir == PINDIR_INPUT )
913 /* try to connect directly. */
914 hr = IFilterGraph2_ConnectDirect(iface,pOut,pPinTry,NULL);
919 IPin_Release(pPinTry); pPinTry = NULL;
922 IEnumPins_Release(pEnumPin); pEnumPin = NULL;
924 TRACE("TryConnect %d\n",bTryConnect);
928 hr = IBaseFilter_EnumPins(pFilter,&pEnumPin);
931 while ( !bConnected )
933 hr = IEnumPins_Next(pEnumPin,1,&pPinTry,&cReturned);
936 hr = IPin_QueryDirection(pPinTry,&pindir);
937 if ( hr == S_OK && pindir == PINDIR_OUTPUT )
939 /* try to connect indirectly. */
940 hr = IFilterGraph2_Connect(iface,pPinTry,pIn);
945 IPin_Release(pPinTry); pPinTry = NULL;
947 IEnumPins_Release(pEnumPin); pEnumPin = NULL;
951 hr = IFilterGraph2_RemoveFilter(iface,pFilter);
953 IBaseFilter_Release(pFilter); pFilter = NULL;
957 IMoniker_Release(pMon); pMon = NULL;
959 IEnumMoniker_Release(pEnumMon); pEnumMon = NULL;
962 if ( SUCCEEDED(hr) && !bConnected )
963 hr = VFW_E_CANNOT_CONNECT;
968 static HRESULT WINAPI
969 IFilterGraph2_fnRender(IFilterGraph2* iface,IPin* pOut)
971 CFilterGraph_THIS(iface,fgraph);
973 IFilterMapper2* pMap2 = NULL;
974 IEnumMoniker* pEnumMon = NULL;
975 IMoniker* pMon = NULL;
976 IBaseFilter* pFilter = NULL;
977 IEnumPins* pEnumPin = NULL;
979 PIN_DIRECTION pindir;
980 BOOL bRendered = FALSE;
983 FIXME( "(%p)->(%p)\n",This,pOut );
985 /* FIXME - must be locked */
986 /*QUARTZ_CompList_Lock( This->m_pFilterList );*/
991 hr = CoCreateInstance(
992 &CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
993 &IID_IFilterMapper2, (void**)&pMap2 );
996 hr = IFilterMapper2_EnumMatchingFilters(
997 pMap2,&pEnumMon,0,FALSE,MERIT_DO_NOT_USE+1,
998 TRUE,0,NULL,NULL,NULL,TRUE,
999 FALSE,0,NULL,NULL,NULL);
1000 IFilterMapper2_Release(pMap2);
1003 TRACE("try to render pin\n");
1007 /* try to render pin. */
1008 while ( !bRendered && hr == S_OK )
1010 hr = IEnumMoniker_Next(pEnumMon,1,&pMon,&cReturned);
1013 hr = IMoniker_BindToObject(pMon,NULL,NULL,&IID_IBaseFilter,(void**)&pFilter );
1016 hr = IFilterGraph2_AddFilter(iface,pFilter,NULL);
1019 hr = IBaseFilter_EnumPins(pFilter,&pEnumPin);
1022 while ( !bRendered )
1024 hr = IEnumPins_Next(pEnumPin,1,&pPin,&cReturned);
1027 hr = IPin_QueryDirection(pPin,&pindir);
1028 if ( hr == S_OK && pindir == PINDIR_INPUT )
1030 /* try to connect. */
1031 hr = IFilterGraph2_Connect(iface,pOut,pPin);
1036 IPin_Release(pPin); pPin = NULL;
1038 IEnumPins_Release(pEnumPin); pEnumPin = NULL;
1041 hr = IFilterGraph2_RemoveFilter(iface,pFilter);
1043 IBaseFilter_Release(pFilter); pFilter = NULL;
1044 if ( SUCCEEDED(hr) )
1047 IMoniker_Release(pMon); pMon = NULL;
1049 IEnumMoniker_Release(pEnumMon); pEnumMon = NULL;
1054 /* successfully rendered(but may be partial now) */
1057 /* FIXME - try to render all inserted filters. */
1058 /* hr = VFW_S_PARTIAL_RENDER; */
1062 if ( SUCCEEDED(hr) )
1063 hr = VFW_E_CANNOT_RENDER;
1066 /*QUARTZ_CompList_Unlock( This->m_pFilterList );*/
1071 static HRESULT WINAPI
1072 IFilterGraph2_fnRenderFile(IFilterGraph2* iface,LPCWSTR lpFileName,LPCWSTR lpPlayList)
1074 CFilterGraph_THIS(iface,fgraph);
1076 IBaseFilter* pFilter = NULL;
1077 IEnumPins* pEnum = NULL;
1084 TRACE( "(%p)->(%s,%s)\n",This,
1085 debugstr_w(lpFileName),debugstr_w(lpPlayList) );
1087 if ( lpPlayList != NULL )
1088 return E_INVALIDARG;
1091 hr = IFilterGraph2_AddSourceFilter(iface,lpFileName,NULL,&pFilter);
1094 if ( pFilter == NULL )
1099 TRACE("(%p) source filter %p\n",This,pFilter);
1102 hr = IBaseFilter_EnumPins( pFilter, &pEnum );
1105 if ( pEnum == NULL )
1118 hr = IEnumPins_Next( pEnum, 1, &pPin, &cFetched );
1121 if ( hr != NOERROR || pPin == NULL || cFetched != 1 )
1126 hr = IPin_QueryDirection( pPin, &dir );
1127 if ( hr == NOERROR && dir == PINDIR_OUTPUT )
1130 hr = IFilterGraph2_Render( iface, pPin );
1131 if ( hr == NOERROR )
1134 IPin_Release( pPin );
1137 if ( hr == NOERROR )
1139 if ( cTryToRender > cActRender )
1140 hr = VFW_S_PARTIAL_RENDER;
1141 if ( cActRender == 0 )
1146 if ( pEnum != NULL )
1147 IEnumPins_Release( pEnum );
1148 if ( pFilter != NULL )
1149 IBaseFilter_Release( pFilter );
1154 static HRESULT WINAPI
1155 IFilterGraph2_fnAddSourceFilter(IFilterGraph2* iface,LPCWSTR lpFileName,LPCWSTR lpFilterName,IBaseFilter** ppBaseFilter)
1157 CFilterGraph_THIS(iface,fgraph);
1159 BYTE bStartData[512];
1163 IFileSourceFilter* pSource;
1165 FIXME( "(%p)->(%s,%s,%p)\n",This,
1166 debugstr_w(lpFileName),debugstr_w(lpFilterName),ppBaseFilter );
1168 if ( lpFileName == NULL || ppBaseFilter == NULL )
1170 *ppBaseFilter = NULL;
1172 hr = QUARTZ_PeekFile( lpFileName, bStartData, 512, &cbStartData );
1175 FIXME("cannot open %s (NOTE: URL is not implemented)\n", debugstr_w(lpFileName));
1178 ZeroMemory( &mt, sizeof(AM_MEDIA_TYPE) );
1179 mt.bFixedSizeSamples = 1;
1181 memcpy( &mt.majortype, &MEDIATYPE_Stream, sizeof(GUID) );
1182 memcpy( &mt.subtype, &MEDIASUBTYPE_NULL, sizeof(GUID) );
1183 memcpy( &mt.formattype, &FORMAT_None, sizeof(GUID) );
1184 hr = QUARTZ_GetSourceTypeFromData(
1185 bStartData, cbStartData,
1186 &mt.majortype, &mt.subtype, &clsidSource );
1189 ERR("QUARTZ_GetSourceTypeFromData() failed - return %08lx\n",hr);
1194 FIXME( "file %s - unknown format\n", debugstr_w(lpFileName) );
1195 return VFW_E_INVALID_FILE_FORMAT;
1198 hr = CoCreateInstance(
1199 &clsidSource, NULL, CLSCTX_INPROC_SERVER,
1200 &IID_IBaseFilter, (void**)ppBaseFilter );
1203 hr = IBaseFilter_QueryInterface(*ppBaseFilter,&IID_IFileSourceFilter,(void**)&pSource);
1204 if ( SUCCEEDED(hr) )
1206 hr = IFileSourceFilter_Load(pSource,lpFileName,&mt);
1207 IFileSourceFilter_Release(pSource);
1209 if ( SUCCEEDED(hr) )
1210 hr = IFilterGraph2_AddFilter(iface,*ppBaseFilter,lpFilterName);
1213 IBaseFilter_Release(*ppBaseFilter);
1214 *ppBaseFilter = NULL;
1221 static HRESULT WINAPI
1222 IFilterGraph2_fnSetLogFile(IFilterGraph2* iface,DWORD_PTR hFile)
1224 CFilterGraph_THIS(iface,fgraph);
1226 FIXME( "(%p)->() stub!\n", This );
1230 static HRESULT WINAPI
1231 IFilterGraph2_fnAbort(IFilterGraph2* iface)
1233 CFilterGraph_THIS(iface,fgraph);
1237 FIXME( "(%p)->() stub!\n", This );
1241 static HRESULT WINAPI
1242 IFilterGraph2_fnShouldOperationContinue(IFilterGraph2* iface)
1244 CFilterGraph_THIS(iface,fgraph);
1248 FIXME( "(%p)->() stub!\n", This );
1252 static HRESULT WINAPI
1253 IFilterGraph2_fnAddSourceFilterForMoniker(IFilterGraph2* iface,IMoniker* pMon,IBindCtx* pCtx,LPCWSTR pFilterName,IBaseFilter** ppFilter)
1255 CFilterGraph_THIS(iface,fgraph);
1257 FIXME( "(%p)->() stub!\n", This );
1261 static HRESULT WINAPI
1262 IFilterGraph2_fnReconnectEx(IFilterGraph2* iface,IPin* pPin,const AM_MEDIA_TYPE* pmt)
1264 CFilterGraph_THIS(iface,fgraph);
1267 FIXME( "(%p)->(%p,%p) stub!\n",This,pPin,pmt );
1269 /* reconnect asynchronously. */
1271 QUARTZ_CompList_Lock( This->m_pFilterList );
1272 hr = CFilterGraph_GraphChanged(This);
1273 QUARTZ_CompList_Unlock( This->m_pFilterList );
1278 static HRESULT WINAPI
1279 IFilterGraph2_fnRenderEx(IFilterGraph2* iface,IPin* pPin,DWORD dwParam1,DWORD* pdwParam2)
1281 CFilterGraph_THIS(iface,fgraph);
1284 FIXME( "(%p)->(%p,%08lx,%p) stub!\n",This,pPin,dwParam1,pdwParam2);
1291 static ICOM_VTABLE(IFilterGraph2) ifgraph =
1293 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1294 /* IUnknown fields */
1295 IFilterGraph2_fnQueryInterface,
1296 IFilterGraph2_fnAddRef,
1297 IFilterGraph2_fnRelease,
1298 /* IFilterGraph fields */
1299 IFilterGraph2_fnAddFilter,
1300 IFilterGraph2_fnRemoveFilter,
1301 IFilterGraph2_fnEnumFilters,
1302 IFilterGraph2_fnFindFilterByName,
1303 IFilterGraph2_fnConnectDirect,
1304 IFilterGraph2_fnReconnect,
1305 IFilterGraph2_fnDisconnect,
1306 IFilterGraph2_fnSetDefaultSyncSource,
1307 /* IGraphBuilder fields */
1308 IFilterGraph2_fnConnect,
1309 IFilterGraph2_fnRender,
1310 IFilterGraph2_fnRenderFile,
1311 IFilterGraph2_fnAddSourceFilter,
1312 IFilterGraph2_fnSetLogFile,
1313 IFilterGraph2_fnAbort,
1314 IFilterGraph2_fnShouldOperationContinue,
1315 /* IFilterGraph2 fields */
1316 IFilterGraph2_fnAddSourceFilterForMoniker,
1317 IFilterGraph2_fnReconnectEx,
1318 IFilterGraph2_fnRenderEx,
1321 HRESULT CFilterGraph_InitIFilterGraph2( CFilterGraph* pfg )
1323 TRACE("(%p)\n",pfg);
1324 ICOM_VTBL(&pfg->fgraph) = &ifgraph;
1326 pfg->m_pFilterList = QUARTZ_CompList_Alloc();
1327 if ( pfg->m_pFilterList == NULL )
1328 return E_OUTOFMEMORY;
1333 void CFilterGraph_UninitIFilterGraph2( CFilterGraph* pfg )
1335 QUARTZ_CompListItem* pItem;
1337 TRACE("(%p)\n",pfg);
1339 /* remove all filters... */
1342 pItem = QUARTZ_CompList_GetFirst( pfg->m_pFilterList );
1343 if ( pItem == NULL )
1345 IFilterGraph2_RemoveFilter(
1346 (IFilterGraph2*)(&pfg->fgraph),
1347 (IBaseFilter*)QUARTZ_CompList_GetItemPtr(pItem) );
1350 QUARTZ_CompList_Free( pfg->m_pFilterList );
1353 /***************************************************************************
1355 * CFilterGraph::IGraphVersion methods
1359 static HRESULT WINAPI
1360 IGraphVersion_fnQueryInterface(IGraphVersion* iface,REFIID riid,void** ppobj)
1362 CFilterGraph_THIS(iface,graphversion);
1364 TRACE("(%p)->()\n",This);
1366 return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
1370 IGraphVersion_fnAddRef(IGraphVersion* iface)
1372 CFilterGraph_THIS(iface,graphversion);
1374 TRACE("(%p)->()\n",This);
1376 return IUnknown_AddRef(This->unk.punkControl);
1380 IGraphVersion_fnRelease(IGraphVersion* iface)
1382 CFilterGraph_THIS(iface,graphversion);
1384 TRACE("(%p)->()\n",This);
1386 return IUnknown_Release(This->unk.punkControl);
1390 static HRESULT WINAPI
1391 IGraphVersion_fnQueryVersion(IGraphVersion* iface,LONG* plVersion)
1393 CFilterGraph_THIS(iface,graphversion);
1395 TRACE("(%p)->(%p)\n",This,plVersion);
1397 if ( plVersion == NULL )
1400 QUARTZ_CompList_Lock( This->m_pFilterList );
1401 *plVersion = This->m_lGraphVersion;
1402 QUARTZ_CompList_Unlock( This->m_pFilterList );
1408 static ICOM_VTABLE(IGraphVersion) igraphversion =
1410 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1411 /* IUnknown fields */
1412 IGraphVersion_fnQueryInterface,
1413 IGraphVersion_fnAddRef,
1414 IGraphVersion_fnRelease,
1415 /* IGraphVersion fields */
1416 IGraphVersion_fnQueryVersion,
1421 HRESULT CFilterGraph_InitIGraphVersion( CFilterGraph* pfg )
1423 TRACE("(%p)\n",pfg);
1424 ICOM_VTBL(&pfg->graphversion) = &igraphversion;
1426 pfg->m_lGraphVersion = 1;
1431 void CFilterGraph_UninitIGraphVersion( CFilterGraph* pfg )
1433 TRACE("(%p)\n",pfg);
1436 /***************************************************************************
1438 * CFilterGraph::IGraphConfig methods
1442 static HRESULT WINAPI
1443 IGraphConfig_fnQueryInterface(IGraphConfig* iface,REFIID riid,void** ppobj)
1445 CFilterGraph_THIS(iface,grphconf);
1447 TRACE("(%p)->()\n",This);
1449 return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
1453 IGraphConfig_fnAddRef(IGraphConfig* iface)
1455 CFilterGraph_THIS(iface,grphconf);
1457 TRACE("(%p)->()\n",This);
1459 return IUnknown_AddRef(This->unk.punkControl);
1463 IGraphConfig_fnRelease(IGraphConfig* iface)
1465 CFilterGraph_THIS(iface,grphconf);
1467 TRACE("(%p)->()\n",This);
1469 return IUnknown_Release(This->unk.punkControl);
1474 static HRESULT WINAPI
1475 IGraphConfig_fnReconnect(IGraphConfig* iface,IPin* pOut,IPin* pIn,const AM_MEDIA_TYPE* pmt,IBaseFilter* pFilter,HANDLE hAbort,DWORD dwFlags)
1477 CFilterGraph_THIS(iface,grphconf);
1479 FIXME("(%p)->() stub!\n",This);
1484 static HRESULT WINAPI
1485 IGraphConfig_fnReconfigure(IGraphConfig* iface,IGraphConfigCallback* pCallback,PVOID pvParam,DWORD dwFlags,HANDLE hAbort)
1487 CFilterGraph_THIS(iface,grphconf);
1490 FIXME("(%p)->(%p,%p,%08lx,%08x) stub!\n",This,pCallback,pvParam,dwFlags,hAbort);
1492 QUARTZ_CompList_Lock( This->m_pFilterList );
1493 EnterCriticalSection( &This->m_csGraphState );
1495 hr = IGraphConfigCallback_Reconfigure(pCallback,pvParam,dwFlags);
1497 LeaveCriticalSection( &This->m_csGraphState );
1498 QUARTZ_CompList_Unlock( This->m_pFilterList );
1503 static HRESULT WINAPI
1504 IGraphConfig_fnAddFilterToCache(IGraphConfig* iface,IBaseFilter* pFilter)
1506 CFilterGraph_THIS(iface,grphconf);
1508 FIXME("(%p)->() stub!\n",This);
1513 static HRESULT WINAPI
1514 IGraphConfig_fnEnumCacheFilter(IGraphConfig* iface,IEnumFilters** ppenum)
1516 CFilterGraph_THIS(iface,grphconf);
1518 FIXME("(%p)->() stub!\n",This);
1523 static HRESULT WINAPI
1524 IGraphConfig_fnRemoveFilterFromCache(IGraphConfig* iface,IBaseFilter* pFilter)
1526 CFilterGraph_THIS(iface,grphconf);
1528 FIXME("(%p)->() stub!\n",This);
1533 static HRESULT WINAPI
1534 IGraphConfig_fnGetStartTime(IGraphConfig* iface,REFERENCE_TIME* prt)
1536 CFilterGraph_THIS(iface,grphconf);
1538 FIXME("(%p)->() stub!\n",This);
1543 static HRESULT WINAPI
1544 IGraphConfig_fnPushThroughData(IGraphConfig* iface,IPin* pOut,IPinConnection* pConn,HANDLE hAbort)
1546 CFilterGraph_THIS(iface,grphconf);
1548 FIXME("(%p)->() stub!\n",This);
1553 static HRESULT WINAPI
1554 IGraphConfig_fnSetFilterFlags(IGraphConfig* iface,IBaseFilter* pFilter,DWORD dwFlags)
1556 CFilterGraph_THIS(iface,grphconf);
1558 FIXME("(%p)->() stub!\n",This);
1563 static HRESULT WINAPI
1564 IGraphConfig_fnGetFilterFlags(IGraphConfig* iface,IBaseFilter* pFilter,DWORD* pdwFlags)
1566 CFilterGraph_THIS(iface,grphconf);
1568 FIXME("(%p)->() stub!\n",This);
1573 static HRESULT WINAPI
1574 IGraphConfig_fnRemoveFilterEx(IGraphConfig* iface,IBaseFilter* pFilter,DWORD dwFlags)
1576 CFilterGraph_THIS(iface,grphconf);
1578 FIXME("(%p)->() stub!\n",This);
1587 static ICOM_VTABLE(IGraphConfig) igraphconfig =
1589 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1590 /* IUnknown fields */
1591 IGraphConfig_fnQueryInterface,
1592 IGraphConfig_fnAddRef,
1593 IGraphConfig_fnRelease,
1594 /* IGraphConfig fields */
1595 IGraphConfig_fnReconnect,
1596 IGraphConfig_fnReconfigure,
1597 IGraphConfig_fnAddFilterToCache,
1598 IGraphConfig_fnEnumCacheFilter,
1599 IGraphConfig_fnRemoveFilterFromCache,
1600 IGraphConfig_fnGetStartTime,
1601 IGraphConfig_fnPushThroughData,
1602 IGraphConfig_fnSetFilterFlags,
1603 IGraphConfig_fnGetFilterFlags,
1604 IGraphConfig_fnRemoveFilterEx,
1609 HRESULT CFilterGraph_InitIGraphConfig( CFilterGraph* pfg )
1611 TRACE("(%p)\n",pfg);
1612 ICOM_VTBL(&pfg->grphconf) = &igraphconfig;
1617 void CFilterGraph_UninitIGraphConfig( CFilterGraph* pfg )
1619 TRACE("(%p)\n",pfg);