When including 'wine/port.h', include it first.
[wine] / dlls / quartz / ifgraph.c
1 /*
2  * Implementation of IFilterGraph and related interfaces
3  *      + IGraphVersion, IGraphConfig
4  *
5  * FIXME - create a thread to process some methods correctly.
6  *
7  * FIXME - ReconnectEx
8  * FIXME - process Pause/Stop asynchronously and notify when completed.
9  *
10  *
11  * hidenori@a2.ctktv.ne.jp
12  */
13
14 #include "config.h"
15
16 #include "windef.h"
17 #include "winbase.h"
18 #include "wingdi.h"
19 #include "winuser.h"
20 #include "winerror.h"
21 #include "strmif.h"
22 #include "control.h"
23 #include "uuids.h"
24 #include "vfwmsgs.h"
25 #include "evcode.h"
26
27 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(quartz);
29
30 #include "quartz_private.h"
31 #include "fgraph.h"
32 #include "enumunk.h"
33 #include "sysclock.h"
34
35
36 static HRESULT CFilterGraph_DisconnectAllPins( IBaseFilter* pFilter )
37 {
38         IEnumPins*      pEnum = NULL;
39         IPin*   pPin;
40         IPin*   pConnTo;
41         ULONG   cFetched;
42         HRESULT hr;
43
44         hr = IBaseFilter_EnumPins( pFilter, &pEnum );
45         if ( FAILED(hr) )
46                 return hr;
47         if ( pEnum == NULL )
48                 return E_FAIL;
49
50         while ( 1 )
51         {
52                 pPin = NULL;
53                 cFetched = 0;
54                 hr = IEnumPins_Next( pEnum, 1, &pPin, &cFetched );
55                 if ( FAILED(hr) )
56                         break;
57                 if ( hr != NOERROR || pPin == NULL || cFetched != 1 )
58                 {
59                         hr = NOERROR;
60                         break;
61                 }
62
63                 pConnTo = NULL;
64                 hr = IPin_ConnectedTo(pPin,&pConnTo);
65                 if ( hr == NOERROR && pConnTo != NULL )
66                 {
67                         IPin_Disconnect(pPin);
68                         IPin_Disconnect(pConnTo);
69                         IPin_Release(pConnTo);
70                 }
71
72                 IPin_Release( pPin );
73         }
74
75         IEnumPins_Release( pEnum );
76
77         return hr;
78 }
79
80
81 static HRESULT CFilterGraph_GraphChanged( CFilterGraph* This )
82 {
83         /* IDistributorNotify_NotifyGraphChange() */
84
85         IMediaEventSink_Notify(CFilterGraph_IMediaEventSink(This),
86                         EC_GRAPH_CHANGED, 0, 0);
87         This->m_lGraphVersion ++;
88
89         return NOERROR;
90 }
91
92
93 /***************************************************************************
94  *
95  *      CFilterGraph::IFilterGraph2 methods
96  *
97  */
98
99 static HRESULT WINAPI
100 IFilterGraph2_fnQueryInterface(IFilterGraph2* iface,REFIID riid,void** ppobj)
101 {
102         CFilterGraph_THIS(iface,fgraph);
103
104         TRACE("(%p)->()\n",This);
105
106         return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
107 }
108
109 static ULONG WINAPI
110 IFilterGraph2_fnAddRef(IFilterGraph2* iface)
111 {
112         CFilterGraph_THIS(iface,fgraph);
113
114         TRACE("(%p)->()\n",This);
115
116         return IUnknown_AddRef(This->unk.punkControl);
117 }
118
119 static ULONG WINAPI
120 IFilterGraph2_fnRelease(IFilterGraph2* iface)
121 {
122         CFilterGraph_THIS(iface,fgraph);
123
124         TRACE("(%p)->()\n",This);
125
126         return IUnknown_Release(This->unk.punkControl);
127 }
128
129 static HRESULT WINAPI
130 IFilterGraph2_fnAddFilter(IFilterGraph2* iface,IBaseFilter* pFilter, LPCWSTR pName)
131 {
132         CFilterGraph_THIS(iface,fgraph);
133         FILTER_STATE fs;
134         FILTER_INFO     info;
135         HRESULT hr;
136         HRESULT hrSucceeded = S_OK;
137         QUARTZ_CompListItem*    pItem;
138         int i,iLen;
139
140         TRACE( "(%p)->(%p,%s)\n",This,pFilter,debugstr_w(pName) );
141
142         QUARTZ_CompList_Lock( This->m_pFilterList );
143
144         hr = IMediaFilter_GetState(CFilterGraph_IMediaFilter(This),0,&fs);
145         if ( hr == VFW_S_STATE_INTERMEDIATE )
146                 hr = VFW_E_STATE_CHANGED;
147         if ( fs != State_Stopped )
148                 hr = VFW_E_NOT_STOPPED;
149         if ( FAILED(hr) )
150                 goto end;
151
152         TRACE( "(%p) search the specified name.\n",This );
153
154         if ( pName != NULL )
155         {
156                 pItem = QUARTZ_CompList_SearchData(
157                         This->m_pFilterList,
158                         pName, sizeof(WCHAR)*(lstrlenW(pName)+1) );
159                 if ( pItem == NULL )
160                         goto name_ok;
161
162                 hrSucceeded = VFW_S_DUPLICATE_NAME;
163
164                 iLen = lstrlenW(pName);
165                 if ( iLen > 32 )
166                         iLen = 32;
167                 memcpy( info.achName, pName, sizeof(WCHAR)*iLen );
168                 info.achName[iLen] = 0;
169         }
170         else
171         {
172                 ZeroMemory( &info, sizeof(info) );
173                 hr = IBaseFilter_QueryFilterInfo( pFilter, &info );
174                 if ( FAILED(hr) )
175                         goto end;
176
177                 iLen = lstrlenW(info.achName);
178                 pItem = QUARTZ_CompList_SearchData(
179                         This->m_pFilterList,
180                         info.achName, sizeof(WCHAR)*(iLen+1) );
181                 if ( pItem == NULL )
182                 {
183                         pName = info.achName;
184                         goto name_ok;
185                 }
186         }
187
188         /* generate modified names for this filter.. */
189         iLen = lstrlenW(info.achName);
190         if ( iLen > 32 )
191                 iLen = 32;
192         info.achName[iLen++] = ' ';
193
194         for ( i = 0; i <= 99; i++ )
195         {
196                 info.achName[iLen+0] = (i%10) + '0';
197                 info.achName[iLen+1] = ((i/10)%10) + '0';
198                 info.achName[iLen+2] = 0;
199                 pItem = QUARTZ_CompList_SearchData(
200                         This->m_pFilterList,
201                         info.achName, sizeof(WCHAR)*(iLen+3) );
202                 if ( pItem == NULL )
203                 {
204                         pName = info.achName;
205                         goto name_ok;
206                 }
207         }
208
209         hr = ( pName == NULL ) ? E_FAIL : VFW_E_DUPLICATE_NAME;
210         goto end;
211
212 name_ok:
213         TRACE( "(%p) add this filter.\n",This );
214
215         /* register this filter. */
216         hr = QUARTZ_CompList_AddComp(
217                 This->m_pFilterList, (IUnknown*)pFilter,
218                 pName, sizeof(WCHAR)*(lstrlenW(pName)+1) );
219         if ( FAILED(hr) )
220                 goto end;
221
222         hr = IBaseFilter_JoinFilterGraph(pFilter,(IFilterGraph*)iface,pName);
223         if ( SUCCEEDED(hr) )
224         {
225                 EnterCriticalSection( &This->m_csClock );
226                 hr = IBaseFilter_SetSyncSource( pFilter, This->m_pClock );
227                 LeaveCriticalSection( &This->m_csClock );
228         }
229         if ( FAILED(hr) )
230         {
231                 IBaseFilter_JoinFilterGraph(pFilter,NULL,pName);
232                 QUARTZ_CompList_RemoveComp(
233                         This->m_pFilterList,(IUnknown*)pFilter);
234                 goto end;
235         }
236
237         hr = CFilterGraph_GraphChanged(This);
238         if ( FAILED(hr) )
239                 goto end;
240
241         hr = hrSucceeded;
242 end:
243         QUARTZ_CompList_Unlock( This->m_pFilterList );
244
245         TRACE( "(%p) return %08lx\n", This, hr );
246
247         return hr;
248 }
249
250 static HRESULT WINAPI
251 IFilterGraph2_fnRemoveFilter(IFilterGraph2* iface,IBaseFilter* pFilter)
252 {
253         CFilterGraph_THIS(iface,fgraph);
254         QUARTZ_CompListItem*    pItem;
255         FILTER_STATE fs;
256         HRESULT hr = NOERROR;
257
258         TRACE( "(%p)->(%p)\n",This,pFilter );
259
260         QUARTZ_CompList_Lock( This->m_pFilterList );
261
262         hr = IMediaFilter_GetState(CFilterGraph_IMediaFilter(This),0,&fs);
263         if ( hr == VFW_S_STATE_INTERMEDIATE )
264                 hr = VFW_E_STATE_CHANGED;
265         if ( fs != State_Stopped )
266                 hr = VFW_E_NOT_STOPPED;
267         if ( FAILED(hr) )
268                 goto end;
269
270         hr = S_FALSE; /* FIXME? */
271         pItem = QUARTZ_CompList_SearchComp(
272                 This->m_pFilterList, (IUnknown*)pFilter );
273         if ( pItem != NULL )
274         {
275                 CFilterGraph_DisconnectAllPins(pFilter);
276                 IBaseFilter_SetSyncSource( pFilter, NULL );
277                 hr = IBaseFilter_JoinFilterGraph(
278                         pFilter, NULL, QUARTZ_CompList_GetDataPtr(pItem) );
279                 QUARTZ_CompList_RemoveComp(
280                         This->m_pFilterList, (IUnknown*)pFilter );
281         }
282
283         hr = CFilterGraph_GraphChanged(This);
284         if ( FAILED(hr) )
285                 goto end;
286
287 end:;
288         QUARTZ_CompList_Unlock( This->m_pFilterList );
289
290         return hr;
291 }
292
293 static HRESULT WINAPI
294 IFilterGraph2_fnEnumFilters(IFilterGraph2* iface,IEnumFilters** ppEnum)
295 {
296         CFilterGraph_THIS(iface,fgraph);
297         HRESULT hr;
298
299         TRACE( "(%p)->(%p)\n",This,ppEnum );
300
301         QUARTZ_CompList_Lock( This->m_pFilterList );
302
303         hr = QUARTZ_CreateEnumUnknown(
304                 &IID_IEnumFilters, (void**)ppEnum, This->m_pFilterList );
305
306         QUARTZ_CompList_Unlock( This->m_pFilterList );
307
308         return hr;
309 }
310
311 static HRESULT WINAPI
312 IFilterGraph2_fnFindFilterByName(IFilterGraph2* iface,LPCWSTR pName,IBaseFilter** ppFilter)
313 {
314         CFilterGraph_THIS(iface,fgraph);
315         QUARTZ_CompListItem*    pItem;
316         HRESULT hr = E_FAIL;
317
318         TRACE( "(%p)->(%s,%p)\n",This,debugstr_w(pName),ppFilter );
319
320         if ( ppFilter == NULL )
321                 return E_POINTER;
322         *ppFilter = NULL;
323
324         QUARTZ_CompList_Lock( This->m_pFilterList );
325
326         pItem = QUARTZ_CompList_SearchData(
327                 This->m_pFilterList,
328                 pName, sizeof(WCHAR)*(lstrlenW(pName)+1) );
329         if ( pItem != NULL )
330         {
331                 *ppFilter = (IBaseFilter*)QUARTZ_CompList_GetItemPtr(pItem);
332                 hr = NOERROR;
333         }
334
335         QUARTZ_CompList_Unlock( This->m_pFilterList );
336
337         return hr;
338 }
339
340 static HRESULT WINAPI
341 IFilterGraph2_fnConnectDirect(IFilterGraph2* iface,IPin* pOut,IPin* pIn,const AM_MEDIA_TYPE* pmt)
342 {
343         CFilterGraph_THIS(iface,fgraph);
344         IPin*   pConnTo;
345         PIN_INFO        infoIn;
346         PIN_INFO        infoOut;
347         FILTER_INFO     finfoIn;
348         FILTER_INFO     finfoOut;
349         FILTER_STATE    fs;
350         HRESULT hr;
351
352         TRACE( "(%p)->(%p,%p,%p)\n",This,pOut,pIn,pmt );
353
354         infoIn.pFilter = NULL;
355         infoOut.pFilter = NULL;
356         finfoIn.pGraph = NULL;
357         finfoOut.pGraph = NULL;
358
359         QUARTZ_CompList_Lock( This->m_pFilterList );
360
361         hr = IMediaFilter_GetState(CFilterGraph_IMediaFilter(This),0,&fs);
362         if ( hr == VFW_S_STATE_INTERMEDIATE )
363                 hr = VFW_E_STATE_CHANGED;
364         if ( fs != State_Stopped )
365                 hr = VFW_E_NOT_STOPPED;
366         if ( FAILED(hr) )
367                 goto end;
368
369         hr = IPin_QueryPinInfo(pIn,&infoIn);
370         if ( FAILED(hr) )
371                 goto end;
372         hr = IPin_QueryPinInfo(pOut,&infoOut);
373         if ( FAILED(hr) )
374                 goto end;
375         if ( infoIn.pFilter == NULL || infoOut.pFilter == NULL ||
376                  infoIn.dir != PINDIR_INPUT || infoOut.dir != PINDIR_OUTPUT )
377         {
378                 hr = E_FAIL;
379                 goto end;
380         }
381
382         hr = IBaseFilter_QueryFilterInfo(infoIn.pFilter,&finfoIn);
383         if ( FAILED(hr) )
384                 goto end;
385         hr = IBaseFilter_QueryFilterInfo(infoOut.pFilter,&finfoOut);
386         if ( FAILED(hr) )
387                 goto end;
388         if ( finfoIn.pGraph != ((IFilterGraph*)iface) ||
389                  finfoOut.pGraph != ((IFilterGraph*)iface) )
390         {
391                 hr = E_FAIL;
392                 goto end;
393         }
394
395         pConnTo = NULL;
396         hr = IPin_ConnectedTo(pIn,&pConnTo);
397         if ( hr == NOERROR && pConnTo != NULL )
398         {
399                 IPin_Release(pConnTo);
400                 hr = VFW_E_ALREADY_CONNECTED;
401                 goto end;
402         }
403
404         pConnTo = NULL;
405         hr = IPin_ConnectedTo(pOut,&pConnTo);
406         if ( hr == NOERROR && pConnTo != NULL )
407         {
408                 IPin_Release(pConnTo);
409                 hr = VFW_E_ALREADY_CONNECTED;
410                 goto end;
411         }
412
413         TRACE("(%p) try to connect %p<->%p\n",This,pIn,pOut);
414         hr = IPin_Connect(pOut,pIn,pmt);
415         if ( FAILED(hr) )
416         {
417                 TRACE("(%p)->Connect(%p,%p) hr = %08lx\n",pOut,pIn,pmt,hr);
418                 IPin_Disconnect(pOut);
419                 IPin_Disconnect(pIn);
420                 goto end;
421         }
422
423         hr = CFilterGraph_GraphChanged(This);
424         if ( FAILED(hr) )
425                 goto end;
426
427 end:
428         QUARTZ_CompList_Unlock( This->m_pFilterList );
429
430         if ( infoIn.pFilter != NULL )
431                 IBaseFilter_Release(infoIn.pFilter);
432         if ( infoOut.pFilter != NULL )
433                 IBaseFilter_Release(infoOut.pFilter);
434         if ( finfoIn.pGraph != NULL )
435                 IFilterGraph_Release(finfoIn.pGraph);
436         if ( finfoOut.pGraph != NULL )
437                 IFilterGraph_Release(finfoOut.pGraph);
438
439         return hr;
440 }
441
442 static HRESULT WINAPI
443 IFilterGraph2_fnReconnect(IFilterGraph2* iface,IPin* pPin)
444 {
445         CFilterGraph_THIS(iface,fgraph);
446
447         TRACE( "(%p)->(%p)\n",This,pPin );
448
449         return IFilterGraph2_ReconnectEx(iface,pPin,NULL);
450 }
451
452 static HRESULT WINAPI
453 IFilterGraph2_fnDisconnect(IFilterGraph2* iface,IPin* pPin)
454 {
455         CFilterGraph_THIS(iface,fgraph);
456         IPin* pConnTo;
457         HRESULT hr;
458
459         TRACE( "(%p)->(%p)\n",This,pPin );
460
461         QUARTZ_CompList_Lock( This->m_pFilterList );
462
463         pConnTo = NULL;
464         hr = IPin_ConnectedTo(pPin,&pConnTo);
465         if ( hr == NOERROR && pConnTo != NULL )
466         {
467                 IPin_Disconnect(pConnTo);
468                 IPin_Release(pConnTo);
469         }
470         hr = IPin_Disconnect(pPin);
471         if ( FAILED(hr) )
472                 goto end;
473
474         hr = CFilterGraph_GraphChanged(This);
475         if ( FAILED(hr) )
476                 goto end;
477
478 end:
479         QUARTZ_CompList_Unlock( This->m_pFilterList );
480
481         return hr;
482 }
483
484 static HRESULT WINAPI
485 IFilterGraph2_fnSetDefaultSyncSource(IFilterGraph2* iface)
486 {
487         CFilterGraph_THIS(iface,fgraph);
488         IUnknown* punk;
489         IReferenceClock* pClock;
490         HRESULT hr;
491
492         FIXME( "(%p)->() stub!\n", This );
493
494         /* FIXME - search all filters from renderer. */
495
496         hr = QUARTZ_CreateSystemClock( NULL, (void**)&punk );
497         if ( FAILED(hr) )
498                 return hr;
499         hr = IUnknown_QueryInterface( punk, &IID_IReferenceClock, (void**)&pClock );    IUnknown_Release( punk );
500         if ( FAILED(hr) )
501                 return hr;
502
503         hr = IMediaFilter_SetSyncSource(
504                 CFilterGraph_IMediaFilter(This), pClock );
505         IReferenceClock_Release( pClock );
506
507         return hr;
508 }
509
510 static HRESULT WINAPI
511 IFilterGraph2_fnConnect(IFilterGraph2* iface,IPin* pOut,IPin* pIn)
512 {
513         CFilterGraph_THIS(iface,fgraph);
514         HRESULT hr;
515
516         TRACE( "(%p)->(%p,%p)\n",This,pOut,pIn );
517
518         /* At first, try to connect directly. */
519         hr = IFilterGraph_ConnectDirect(iface,pOut,pIn,NULL);
520         if ( hr == NOERROR )
521                 return NOERROR;
522
523         /* FIXME - try to connect indirectly. */
524         FIXME( "(%p)->(%p,%p) stub!\n",This,pOut,pIn );
525
526
527         return E_NOTIMPL;
528 }
529
530 static HRESULT WINAPI
531 IFilterGraph2_fnRender(IFilterGraph2* iface,IPin* pOut)
532 {
533         CFilterGraph_THIS(iface,fgraph);
534
535         FIXME( "(%p)->(%p) stub!\n",This,pOut );
536         return E_NOTIMPL;
537 }
538
539 static HRESULT WINAPI
540 IFilterGraph2_fnRenderFile(IFilterGraph2* iface,LPCWSTR lpFileName,LPCWSTR lpPlayList)
541 {
542         CFilterGraph_THIS(iface,fgraph);
543         HRESULT hr;
544         IBaseFilter*    pFilter = NULL;
545         IEnumPins*      pEnum = NULL;
546         IPin*   pPin;
547         ULONG   cFetched;
548         PIN_DIRECTION   dir;
549         ULONG   cTryToRender;
550         ULONG   cActRender;
551
552         TRACE( "(%p)->(%s,%s)\n",This,
553                 debugstr_w(lpFileName),debugstr_w(lpPlayList) );
554
555         if ( lpPlayList != NULL )
556                 return E_INVALIDARG;
557
558         pFilter = NULL;
559         hr = IFilterGraph2_AddSourceFilter(iface,lpFileName,NULL,&pFilter);
560         if ( FAILED(hr) )
561                 goto end;
562         if ( pFilter == NULL )
563         {
564                 hr = E_FAIL;
565                 goto end;
566         }
567         pEnum = NULL;
568         hr = IBaseFilter_EnumPins( pFilter, &pEnum );
569         if ( FAILED(hr) )
570                 goto end;
571         if ( pEnum == NULL )
572         {
573                 hr = E_FAIL;
574                 goto end;
575         }
576
577         cTryToRender = 0;
578         cActRender = 0;
579
580         while ( 1 )
581         {
582                 pPin = NULL;
583                 cFetched = 0;
584                 hr = IEnumPins_Next( pEnum, 1, &pPin, &cFetched );
585                 if ( FAILED(hr) )
586                         goto end;
587                 if ( hr != NOERROR || pPin == NULL || cFetched != 1 )
588                 {
589                         hr = NOERROR;
590                         break;
591                 }
592                 hr = IPin_QueryDirection( pPin, &dir );
593                 if ( hr == NOERROR && dir == PINDIR_OUTPUT )
594                 {
595                         cTryToRender ++;
596                         hr = IFilterGraph2_Render( iface, pPin );
597                         if ( hr == NOERROR )
598                                 cActRender ++;
599                 }
600                 IPin_Release( pPin );
601         }
602
603         if ( hr == NOERROR )
604         {
605                 if ( cTryToRender > cActRender )
606                         hr = VFW_S_PARTIAL_RENDER;
607                 if ( cActRender == 0 )
608                         hr = E_FAIL;
609         }
610
611 end:
612         if ( pEnum != NULL )
613                 IEnumPins_Release( pEnum );
614         if ( pFilter != NULL )
615                 IBaseFilter_Release( pFilter );
616
617         return hr;
618 }
619
620 static HRESULT WINAPI
621 IFilterGraph2_fnAddSourceFilter(IFilterGraph2* iface,LPCWSTR lpFileName,LPCWSTR lpFilterName,IBaseFilter** ppBaseFilter)
622 {
623         CFilterGraph_THIS(iface,fgraph);
624
625         FIXME( "(%p)->(%s,%s,%p) stub!\n",This,
626                 debugstr_w(lpFileName),debugstr_w(lpFilterName),ppBaseFilter );
627         return E_NOTIMPL;
628 }
629
630 static HRESULT WINAPI
631 IFilterGraph2_fnSetLogFile(IFilterGraph2* iface,DWORD_PTR hFile)
632 {
633         CFilterGraph_THIS(iface,fgraph);
634
635         FIXME( "(%p)->() stub!\n", This );
636         return E_NOTIMPL;
637 }
638
639 static HRESULT WINAPI
640 IFilterGraph2_fnAbort(IFilterGraph2* iface)
641 {
642         CFilterGraph_THIS(iface,fgraph);
643
644         /* undoc. */
645
646         FIXME( "(%p)->() stub!\n", This );
647         return E_NOTIMPL;
648 }
649
650 static HRESULT WINAPI
651 IFilterGraph2_fnShouldOperationContinue(IFilterGraph2* iface)
652 {
653         CFilterGraph_THIS(iface,fgraph);
654
655         /* undoc. */
656
657         FIXME( "(%p)->() stub!\n", This );
658         return E_NOTIMPL;
659 }
660
661 static HRESULT WINAPI
662 IFilterGraph2_fnAddSourceFilterForMoniker(IFilterGraph2* iface,IMoniker* pMon,IBindCtx* pCtx,LPCWSTR pFilterName,IBaseFilter** ppFilter)
663 {
664         CFilterGraph_THIS(iface,fgraph);
665
666         FIXME( "(%p)->() stub!\n", This );
667         return E_NOTIMPL;
668 }
669
670 static HRESULT WINAPI
671 IFilterGraph2_fnReconnectEx(IFilterGraph2* iface,IPin* pPin,const AM_MEDIA_TYPE* pmt)
672 {
673         CFilterGraph_THIS(iface,fgraph);
674         HRESULT hr;
675
676         FIXME( "(%p)->(%p,%p) stub!\n",This,pPin,pmt );
677
678         /* reconnect asynchronously. */
679
680         QUARTZ_CompList_Lock( This->m_pFilterList );
681         hr = CFilterGraph_GraphChanged(This);
682         QUARTZ_CompList_Unlock( This->m_pFilterList );
683
684         return E_NOTIMPL;
685 }
686
687 static HRESULT WINAPI
688 IFilterGraph2_fnRenderEx(IFilterGraph2* iface,IPin* pPin,DWORD dwParam1,DWORD* pdwParam2)
689 {
690         CFilterGraph_THIS(iface,fgraph);
691
692         /* undoc. */
693         FIXME( "(%p)->(%p,%08lx,%p) stub!\n",This,pPin,dwParam1,pdwParam2);
694         return E_NOTIMPL;
695 }
696
697
698
699
700 static ICOM_VTABLE(IFilterGraph2) ifgraph =
701 {
702         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
703         /* IUnknown fields */
704         IFilterGraph2_fnQueryInterface,
705         IFilterGraph2_fnAddRef,
706         IFilterGraph2_fnRelease,
707         /* IFilterGraph fields */
708         IFilterGraph2_fnAddFilter,
709         IFilterGraph2_fnRemoveFilter,
710         IFilterGraph2_fnEnumFilters,
711         IFilterGraph2_fnFindFilterByName,
712         IFilterGraph2_fnConnectDirect,
713         IFilterGraph2_fnReconnect,
714         IFilterGraph2_fnDisconnect,
715         IFilterGraph2_fnSetDefaultSyncSource,
716         /* IGraphBuilder fields */
717         IFilterGraph2_fnConnect,
718         IFilterGraph2_fnRender,
719         IFilterGraph2_fnRenderFile,
720         IFilterGraph2_fnAddSourceFilter,
721         IFilterGraph2_fnSetLogFile,
722         IFilterGraph2_fnAbort,
723         IFilterGraph2_fnShouldOperationContinue,
724         /* IFilterGraph2 fields */
725         IFilterGraph2_fnAddSourceFilterForMoniker,
726         IFilterGraph2_fnReconnectEx,
727         IFilterGraph2_fnRenderEx,
728 };
729
730 HRESULT CFilterGraph_InitIFilterGraph2( CFilterGraph* pfg )
731 {
732         TRACE("(%p)\n",pfg);
733         ICOM_VTBL(&pfg->fgraph) = &ifgraph;
734
735         pfg->m_pFilterList = QUARTZ_CompList_Alloc();
736         if ( pfg->m_pFilterList == NULL )
737                 return E_OUTOFMEMORY;
738
739         return NOERROR;
740 }
741
742 void CFilterGraph_UninitIFilterGraph2( CFilterGraph* pfg )
743 {
744         QUARTZ_CompListItem*    pItem;
745
746         TRACE("(%p)\n",pfg);
747
748         /* remove all filters... */
749         while ( 1 )
750         {
751                 pItem = QUARTZ_CompList_GetFirst( pfg->m_pFilterList );
752                 if ( pItem == NULL )
753                         break;
754                 IFilterGraph2_RemoveFilter(
755                         (IFilterGraph2*)(&pfg->fgraph),
756                         (IBaseFilter*)QUARTZ_CompList_GetItemPtr(pItem) );
757         }
758
759         QUARTZ_CompList_Free( pfg->m_pFilterList );
760 }
761
762 /***************************************************************************
763  *
764  *      CFilterGraph::IGraphVersion methods
765  *
766  */
767
768 static HRESULT WINAPI
769 IGraphVersion_fnQueryInterface(IGraphVersion* iface,REFIID riid,void** ppobj)
770 {
771         CFilterGraph_THIS(iface,graphversion);
772
773         TRACE("(%p)->()\n",This);
774
775         return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
776 }
777
778 static ULONG WINAPI
779 IGraphVersion_fnAddRef(IGraphVersion* iface)
780 {
781         CFilterGraph_THIS(iface,graphversion);
782
783         TRACE("(%p)->()\n",This);
784
785         return IUnknown_AddRef(This->unk.punkControl);
786 }
787
788 static ULONG WINAPI
789 IGraphVersion_fnRelease(IGraphVersion* iface)
790 {
791         CFilterGraph_THIS(iface,graphversion);
792
793         TRACE("(%p)->()\n",This);
794
795         return IUnknown_Release(This->unk.punkControl);
796 }
797
798
799 static HRESULT WINAPI
800 IGraphVersion_fnQueryVersion(IGraphVersion* iface,LONG* plVersion)
801 {
802         CFilterGraph_THIS(iface,graphversion);
803
804         TRACE("(%p)->(%p)\n",This,plVersion);
805
806         if ( plVersion == NULL )
807                 return E_POINTER;
808
809         QUARTZ_CompList_Lock( This->m_pFilterList );
810         *plVersion = This->m_lGraphVersion;
811         QUARTZ_CompList_Unlock( This->m_pFilterList );
812
813         return NOERROR;
814 }
815
816
817 static ICOM_VTABLE(IGraphVersion) igraphversion =
818 {
819         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
820         /* IUnknown fields */
821         IGraphVersion_fnQueryInterface,
822         IGraphVersion_fnAddRef,
823         IGraphVersion_fnRelease,
824         /* IGraphVersion fields */
825         IGraphVersion_fnQueryVersion,
826 };
827
828
829
830 HRESULT CFilterGraph_InitIGraphVersion( CFilterGraph* pfg )
831 {
832         TRACE("(%p)\n",pfg);
833         ICOM_VTBL(&pfg->graphversion) = &igraphversion;
834
835         pfg->m_lGraphVersion = 1;
836
837         return NOERROR;
838 }
839
840 void CFilterGraph_UninitIGraphVersion( CFilterGraph* pfg )
841 {
842         TRACE("(%p)\n",pfg);
843 }
844
845 /***************************************************************************
846  *
847  *      CFilterGraph::IGraphConfig methods
848  *
849  */
850
851 static HRESULT WINAPI
852 IGraphConfig_fnQueryInterface(IGraphConfig* iface,REFIID riid,void** ppobj)
853 {
854         CFilterGraph_THIS(iface,grphconf);
855
856         TRACE("(%p)->()\n",This);
857
858         return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
859 }
860
861 static ULONG WINAPI
862 IGraphConfig_fnAddRef(IGraphConfig* iface)
863 {
864         CFilterGraph_THIS(iface,grphconf);
865
866         TRACE("(%p)->()\n",This);
867
868         return IUnknown_AddRef(This->unk.punkControl);
869 }
870
871 static ULONG WINAPI
872 IGraphConfig_fnRelease(IGraphConfig* iface)
873 {
874         CFilterGraph_THIS(iface,grphconf);
875
876         TRACE("(%p)->()\n",This);
877
878         return IUnknown_Release(This->unk.punkControl);
879 }
880
881
882
883 static HRESULT WINAPI
884 IGraphConfig_fnReconnect(IGraphConfig* iface,IPin* pOut,IPin* pIn,const AM_MEDIA_TYPE* pmt,IBaseFilter* pFilter,HANDLE hAbort,DWORD dwFlags)
885 {
886         CFilterGraph_THIS(iface,grphconf);
887
888         FIXME("(%p)->() stub!\n",This);
889
890         return E_NOTIMPL;
891 }
892
893 static HRESULT WINAPI
894 IGraphConfig_fnReconfigure(IGraphConfig* iface,IGraphConfigCallback* pCallback,PVOID pvParam,DWORD dwFlags,HANDLE hAbort)
895 {
896         CFilterGraph_THIS(iface,grphconf);
897         HRESULT hr;
898
899         FIXME("(%p)->(%p,%p,%08lx,%08x) stub!\n",This,pCallback,pvParam,dwFlags,hAbort);
900
901         QUARTZ_CompList_Lock( This->m_pFilterList );
902         EnterCriticalSection( &This->m_csGraphState );
903
904         hr = IGraphConfigCallback_Reconfigure(pCallback,pvParam,dwFlags);
905
906         LeaveCriticalSection( &This->m_csGraphState );
907         QUARTZ_CompList_Unlock( This->m_pFilterList );
908
909         return hr;
910 }
911
912 static HRESULT WINAPI
913 IGraphConfig_fnAddFilterToCache(IGraphConfig* iface,IBaseFilter* pFilter)
914 {
915         CFilterGraph_THIS(iface,grphconf);
916
917         FIXME("(%p)->() stub!\n",This);
918
919         return E_NOTIMPL;
920 }
921
922 static HRESULT WINAPI
923 IGraphConfig_fnEnumCacheFilter(IGraphConfig* iface,IEnumFilters** ppenum)
924 {
925         CFilterGraph_THIS(iface,grphconf);
926
927         FIXME("(%p)->() stub!\n",This);
928
929         return E_NOTIMPL;
930 }
931
932 static HRESULT WINAPI
933 IGraphConfig_fnRemoveFilterFromCache(IGraphConfig* iface,IBaseFilter* pFilter)
934 {
935         CFilterGraph_THIS(iface,grphconf);
936
937         FIXME("(%p)->() stub!\n",This);
938
939         return E_NOTIMPL;
940 }
941
942 static HRESULT WINAPI
943 IGraphConfig_fnGetStartTime(IGraphConfig* iface,REFERENCE_TIME* prt)
944 {
945         CFilterGraph_THIS(iface,grphconf);
946
947         FIXME("(%p)->() stub!\n",This);
948
949         return E_NOTIMPL;
950 }
951
952 static HRESULT WINAPI
953 IGraphConfig_fnPushThroughData(IGraphConfig* iface,IPin* pOut,IPinConnection* pConn,HANDLE hAbort)
954 {
955         CFilterGraph_THIS(iface,grphconf);
956
957         FIXME("(%p)->() stub!\n",This);
958
959         return E_NOTIMPL;
960 }
961
962 static HRESULT WINAPI
963 IGraphConfig_fnSetFilterFlags(IGraphConfig* iface,IBaseFilter* pFilter,DWORD dwFlags)
964 {
965         CFilterGraph_THIS(iface,grphconf);
966
967         FIXME("(%p)->() stub!\n",This);
968
969         return E_NOTIMPL;
970 }
971
972 static HRESULT WINAPI
973 IGraphConfig_fnGetFilterFlags(IGraphConfig* iface,IBaseFilter* pFilter,DWORD* pdwFlags)
974 {
975         CFilterGraph_THIS(iface,grphconf);
976
977         FIXME("(%p)->() stub!\n",This);
978
979         return E_NOTIMPL;
980 }
981
982 static HRESULT WINAPI
983 IGraphConfig_fnRemoveFilterEx(IGraphConfig* iface,IBaseFilter* pFilter,DWORD dwFlags)
984 {
985         CFilterGraph_THIS(iface,grphconf);
986
987         FIXME("(%p)->() stub!\n",This);
988
989         return E_NOTIMPL;
990 }
991
992
993
994
995
996 static ICOM_VTABLE(IGraphConfig) igraphconfig =
997 {
998         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
999         /* IUnknown fields */
1000         IGraphConfig_fnQueryInterface,
1001         IGraphConfig_fnAddRef,
1002         IGraphConfig_fnRelease,
1003         /* IGraphConfig fields */
1004         IGraphConfig_fnReconnect,
1005         IGraphConfig_fnReconfigure,
1006         IGraphConfig_fnAddFilterToCache,
1007         IGraphConfig_fnEnumCacheFilter,
1008         IGraphConfig_fnRemoveFilterFromCache,
1009         IGraphConfig_fnGetStartTime,
1010         IGraphConfig_fnPushThroughData,
1011         IGraphConfig_fnSetFilterFlags,
1012         IGraphConfig_fnGetFilterFlags,
1013         IGraphConfig_fnRemoveFilterEx,
1014 };
1015
1016
1017
1018 HRESULT CFilterGraph_InitIGraphConfig( CFilterGraph* pfg )
1019 {
1020         TRACE("(%p)\n",pfg);
1021         ICOM_VTBL(&pfg->grphconf) = &igraphconfig;
1022
1023         return NOERROR;
1024 }
1025
1026 void CFilterGraph_UninitIGraphConfig( CFilterGraph* pfg )
1027 {
1028         TRACE("(%p)\n",pfg);
1029 }
1030
1031