896762f538fcbd6802a8b398b185660d4a831621
[reactos.git] / reactos / dll / directx / wine / quartz / filtergraph.c
1 /* DirectShow FilterGraph object (QUARTZ.DLL)
2 *
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2004 Christian Costa
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <config.h>
22 #include <stdarg.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "shlwapi.h"
31 #include "dshow.h"
32 #include <wine/debug.h>
33 #include "quartz_private.h"
34 #include "ole2.h"
35 #include "olectl.h"
36 #include <strmif.h>
37 #include "vfwmsgs.h"
38 #include "evcode.h"
39 #include <wine/unicode.h>
40
41
42 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
43
44 typedef struct {
45 HWND hWnd; /* Target window */
46 UINT msg; /* User window message */
47 LONG_PTR instance; /* User data */
48 int disabled; /* Disabled messages posting */
49 } WndNotify;
50
51 typedef struct {
52 LONG lEventCode; /* Event code */
53 LONG_PTR lParam1; /* Param1 */
54 LONG_PTR lParam2; /* Param2 */
55 } Event;
56
57 /* messages ring implementation for queuing events (taken from winmm) */
58 #define EVENTS_RING_BUFFER_INCREMENT 64
59 typedef struct {
60 Event* messages;
61 int ring_buffer_size;
62 int msg_tosave;
63 int msg_toget;
64 CRITICAL_SECTION msg_crst;
65 HANDLE msg_event; /* Signaled for no empty queue */
66 } EventsQueue;
67
68 static int EventsQueue_Init(EventsQueue* omr)
69 {
70 omr->msg_toget = 0;
71 omr->msg_tosave = 0;
72 omr->msg_event = CreateEventW(NULL, TRUE, FALSE, NULL);
73 omr->ring_buffer_size = EVENTS_RING_BUFFER_INCREMENT;
74 omr->messages = CoTaskMemAlloc(omr->ring_buffer_size * sizeof(Event));
75 ZeroMemory(omr->messages, omr->ring_buffer_size * sizeof(Event));
76
77 InitializeCriticalSection(&omr->msg_crst);
78 omr->msg_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": EventsQueue.msg_crst");
79 return TRUE;
80 }
81
82 static int EventsQueue_Destroy(EventsQueue* omr)
83 {
84 CloseHandle(omr->msg_event);
85 CoTaskMemFree(omr->messages);
86 omr->msg_crst.DebugInfo->Spare[0] = 0;
87 DeleteCriticalSection(&omr->msg_crst);
88 return TRUE;
89 }
90
91 static int EventsQueue_PutEvent(EventsQueue* omr, const Event* evt)
92 {
93 EnterCriticalSection(&omr->msg_crst);
94 if (omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size))
95 {
96 int old_ring_buffer_size = omr->ring_buffer_size;
97 omr->ring_buffer_size += EVENTS_RING_BUFFER_INCREMENT;
98 TRACE("omr->ring_buffer_size=%d\n",omr->ring_buffer_size);
99 omr->messages = CoTaskMemRealloc(omr->messages, omr->ring_buffer_size * sizeof(Event));
100 /* Now we need to rearrange the ring buffer so that the new
101 buffers just allocated are in between omr->msg_tosave and
102 omr->msg_toget.
103 */
104 if (omr->msg_tosave < omr->msg_toget)
105 {
106 memmove(&(omr->messages[omr->msg_toget + EVENTS_RING_BUFFER_INCREMENT]),
107 &(omr->messages[omr->msg_toget]),
108 sizeof(Event)*(old_ring_buffer_size - omr->msg_toget)
109 );
110 omr->msg_toget += EVENTS_RING_BUFFER_INCREMENT;
111 }
112 }
113 omr->messages[omr->msg_tosave] = *evt;
114 SetEvent(omr->msg_event);
115 omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
116 LeaveCriticalSection(&omr->msg_crst);
117 return TRUE;
118 }
119
120 static int EventsQueue_GetEvent(EventsQueue* omr, Event* evt, LONG msTimeOut)
121 {
122 if (WaitForSingleObject(omr->msg_event, msTimeOut) != WAIT_OBJECT_0)
123 return FALSE;
124
125 EnterCriticalSection(&omr->msg_crst);
126
127 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
128 {
129 LeaveCriticalSection(&omr->msg_crst);
130 return FALSE;
131 }
132
133 *evt = omr->messages[omr->msg_toget];
134 omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
135
136 /* Mark the buffer as empty if needed */
137 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
138 ResetEvent(omr->msg_event);
139
140 LeaveCriticalSection(&omr->msg_crst);
141 return TRUE;
142 }
143
144 #define MAX_ITF_CACHE_ENTRIES 3
145 typedef struct _ITF_CACHE_ENTRY {
146 const IID* riid;
147 IBaseFilter* filter;
148 IUnknown* iface;
149 } ITF_CACHE_ENTRY;
150
151 typedef struct _IFilterGraphImpl {
152 IUnknown IUnknown_inner;
153 IFilterGraph2 IFilterGraph2_iface;
154 IMediaControl IMediaControl_iface;
155 IMediaSeeking IMediaSeeking_iface;
156 IBasicAudio IBasicAudio_iface;
157 IBasicVideo2 IBasicVideo2_iface;
158 IVideoWindow IVideoWindow_iface;
159 IMediaEventEx IMediaEventEx_iface;
160 IMediaFilter IMediaFilter_iface;
161 IMediaEventSink IMediaEventSink_iface;
162 IGraphConfig IGraphConfig_iface;
163 IMediaPosition IMediaPosition_iface;
164 IObjectWithSite IObjectWithSite_iface;
165 IGraphVersion IGraphVersion_iface;
166 /* IAMGraphStreams */
167 /* IAMStats */
168 /* IFilterChain */
169 /* IFilterMapper2 */
170 /* IQueueCommand */
171 /* IRegisterServiceProvider */
172 /* IResourceMananger */
173 /* IServiceProvider */
174 /* IVideoFrameStep */
175
176 IUnknown *outer_unk;
177 LONG ref;
178 IUnknown *punkFilterMapper2;
179 IFilterMapper2 * pFilterMapper2;
180 IBaseFilter ** ppFiltersInGraph;
181 LPWSTR * pFilterNames;
182 ULONG nFilters;
183 int filterCapacity;
184 LONG nameIndex;
185 IReferenceClock *refClock;
186 IBaseFilter *refClockProvider;
187 EventsQueue evqueue;
188 HANDLE hEventCompletion;
189 int CompletionStatus;
190 WndNotify notif;
191 int nRenderers;
192 int EcCompleteCount;
193 int HandleEcComplete;
194 int HandleEcRepaint;
195 int HandleEcClockChanged;
196 OAFilterState state;
197 CRITICAL_SECTION cs;
198 ITF_CACHE_ENTRY ItfCacheEntries[MAX_ITF_CACHE_ENTRIES];
199 int nItfCacheEntries;
200 BOOL defaultclock;
201 GUID timeformatseek;
202 REFERENCE_TIME start_time;
203 REFERENCE_TIME pause_time;
204 LONGLONG stop_position;
205 LONG recursioncount;
206 IUnknown *pSite;
207 LONG version;
208 } IFilterGraphImpl;
209
210 static inline IFilterGraphImpl *impl_from_IUnknown(IUnknown *iface)
211 {
212 return CONTAINING_RECORD(iface, IFilterGraphImpl, IUnknown_inner);
213 }
214
215 static HRESULT WINAPI FilterGraphInner_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObj)
216 {
217 IFilterGraphImpl *This = impl_from_IUnknown(iface);
218 TRACE("(%p)->(%s (%p), %p)\n", This, debugstr_guid(riid), riid, ppvObj);
219
220 if (IsEqualGUID(&IID_IUnknown, riid)) {
221 *ppvObj = &This->IUnknown_inner;
222 TRACE(" returning IUnknown interface (%p)\n", *ppvObj);
223 } else if (IsEqualGUID(&IID_IFilterGraph, riid) ||
224 IsEqualGUID(&IID_IFilterGraph2, riid) ||
225 IsEqualGUID(&IID_IGraphBuilder, riid)) {
226 *ppvObj = &This->IFilterGraph2_iface;
227 TRACE(" returning IGraphBuilder interface (%p)\n", *ppvObj);
228 } else if (IsEqualGUID(&IID_IMediaControl, riid)) {
229 *ppvObj = &This->IMediaControl_iface;
230 TRACE(" returning IMediaControl interface (%p)\n", *ppvObj);
231 } else if (IsEqualGUID(&IID_IMediaSeeking, riid)) {
232 *ppvObj = &This->IMediaSeeking_iface;
233 TRACE(" returning IMediaSeeking interface (%p)\n", *ppvObj);
234 } else if (IsEqualGUID(&IID_IBasicAudio, riid)) {
235 *ppvObj = &This->IBasicAudio_iface;
236 TRACE(" returning IBasicAudio interface (%p)\n", *ppvObj);
237 } else if (IsEqualGUID(&IID_IBasicVideo, riid) ||
238 IsEqualGUID(&IID_IBasicVideo2, riid)) {
239 *ppvObj = &This->IBasicVideo2_iface;
240 TRACE(" returning IBasicVideo2 interface (%p)\n", *ppvObj);
241 } else if (IsEqualGUID(&IID_IVideoWindow, riid)) {
242 *ppvObj = &This->IVideoWindow_iface;
243 TRACE(" returning IVideoWindow interface (%p)\n", *ppvObj);
244 } else if (IsEqualGUID(&IID_IMediaEvent, riid) ||
245 IsEqualGUID(&IID_IMediaEventEx, riid)) {
246 *ppvObj = &This->IMediaEventEx_iface;
247 TRACE(" returning IMediaEvent(Ex) interface (%p)\n", *ppvObj);
248 } else if (IsEqualGUID(&IID_IMediaFilter, riid) ||
249 IsEqualGUID(&IID_IPersist, riid)) {
250 *ppvObj = &This->IMediaFilter_iface;
251 TRACE(" returning IMediaFilter interface (%p)\n", *ppvObj);
252 } else if (IsEqualGUID(&IID_IMediaEventSink, riid)) {
253 *ppvObj = &This->IMediaEventSink_iface;
254 TRACE(" returning IMediaEventSink interface (%p)\n", *ppvObj);
255 } else if (IsEqualGUID(&IID_IGraphConfig, riid)) {
256 *ppvObj = &This->IGraphConfig_iface;
257 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
258 } else if (IsEqualGUID(&IID_IMediaPosition, riid)) {
259 *ppvObj = &This->IMediaPosition_iface;
260 TRACE(" returning IMediaPosition interface (%p)\n", *ppvObj);
261 } else if (IsEqualGUID(&IID_IObjectWithSite, riid)) {
262 *ppvObj = &This->IObjectWithSite_iface;
263 TRACE(" returning IObjectWithSite interface (%p)\n", *ppvObj);
264 } else if (IsEqualGUID(&IID_IFilterMapper, riid)) {
265 TRACE(" requesting IFilterMapper interface from aggregated filtermapper (%p)\n", *ppvObj);
266 return IUnknown_QueryInterface(This->punkFilterMapper2, riid, ppvObj);
267 } else if (IsEqualGUID(&IID_IFilterMapper2, riid)) {
268 *ppvObj = This->pFilterMapper2;
269 TRACE(" returning IFilterMapper2 interface from aggregated filtermapper (%p)\n", *ppvObj);
270 } else if (IsEqualGUID(&IID_IFilterMapper3, riid)) {
271 *ppvObj = This->pFilterMapper2;
272 TRACE(" returning IFilterMapper3 interface from aggregated filtermapper (%p)\n", *ppvObj);
273 } else if (IsEqualGUID(&IID_IGraphVersion, riid)) {
274 *ppvObj = &This->IGraphConfig_iface;
275 TRACE(" returning IGraphConfig interface (%p)\n", *ppvObj);
276 } else {
277 *ppvObj = NULL;
278 FIXME("unknown interface %s\n", debugstr_guid(riid));
279 return E_NOINTERFACE;
280 }
281
282 IUnknown_AddRef((IUnknown *)*ppvObj);
283 return S_OK;
284 }
285
286 static ULONG WINAPI FilterGraphInner_AddRef(IUnknown *iface)
287 {
288 IFilterGraphImpl *This = impl_from_IUnknown(iface);
289 ULONG ref = InterlockedIncrement(&This->ref);
290
291 TRACE("(%p)->(): new ref = %d\n", This, ref);
292
293 return ref;
294 }
295
296 static ULONG WINAPI FilterGraphInner_Release(IUnknown *iface)
297 {
298 IFilterGraphImpl *This = impl_from_IUnknown(iface);
299 ULONG ref = InterlockedDecrement(&This->ref);
300
301 TRACE("(%p)->(): new ref = %d\n", This, ref);
302
303 if (ref == 0) {
304 int i;
305
306 This->ref = 1; /* guard against reentrancy (aggregation). */
307
308 IMediaControl_Stop(&This->IMediaControl_iface);
309
310 while (This->nFilters)
311 IFilterGraph2_RemoveFilter(&This->IFilterGraph2_iface, This->ppFiltersInGraph[0]);
312
313 if (This->refClock)
314 IReferenceClock_Release(This->refClock);
315
316 for (i = 0; i < This->nItfCacheEntries; i++)
317 {
318 if (This->ItfCacheEntries[i].iface)
319 IUnknown_Release(This->ItfCacheEntries[i].iface);
320 }
321
322 /* AddRef on controlling IUnknown, to compensate for Release of cached IFilterMapper2 */
323 IUnknown_AddRef(This->outer_unk);
324 IFilterMapper2_Release(This->pFilterMapper2);
325 IUnknown_Release(This->punkFilterMapper2);
326
327 if (This->pSite) IUnknown_Release(This->pSite);
328
329 CloseHandle(This->hEventCompletion);
330 EventsQueue_Destroy(&This->evqueue);
331 This->cs.DebugInfo->Spare[0] = 0;
332 DeleteCriticalSection(&This->cs);
333 CoTaskMemFree(This->ppFiltersInGraph);
334 CoTaskMemFree(This->pFilterNames);
335 CoTaskMemFree(This);
336 }
337 return ref;
338 }
339
340 static inline IFilterGraphImpl *impl_from_IFilterGraph2(IFilterGraph2 *iface)
341 {
342 return CONTAINING_RECORD(iface, IFilterGraphImpl, IFilterGraph2_iface);
343 }
344
345 static HRESULT WINAPI FilterGraph2_QueryInterface(IFilterGraph2 *iface, REFIID riid, void **ppvObj)
346 {
347 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
348
349 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
350
351 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
352 }
353
354 static ULONG WINAPI FilterGraph2_AddRef(IFilterGraph2 *iface)
355 {
356 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
357
358 TRACE("(%p/%p)->()\n", This, iface);
359
360 return IUnknown_AddRef(This->outer_unk);
361 }
362
363 static ULONG WINAPI FilterGraph2_Release(IFilterGraph2 *iface)
364 {
365 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
366
367 TRACE("(%p/%p)->()\n", This, iface);
368
369 return IUnknown_Release(This->outer_unk);
370 }
371
372 /*** IFilterGraph methods ***/
373 static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface, IBaseFilter *pFilter,
374 LPCWSTR pName)
375 {
376 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
377 HRESULT hr;
378 int i,j;
379 WCHAR* wszFilterName = NULL;
380 int duplicate_name = FALSE;
381
382 TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
383
384 if (!pFilter)
385 return E_POINTER;
386
387 wszFilterName = CoTaskMemAlloc( (pName ? strlenW(pName) + 6 : 5) * sizeof(WCHAR) );
388
389 if (pName)
390 {
391 /* Check if name already exists */
392 for(i = 0; i < This->nFilters; i++)
393 if (!strcmpW(This->pFilterNames[i], pName))
394 {
395 duplicate_name = TRUE;
396 break;
397 }
398 }
399
400 /* If no name given or name already existing, generate one */
401 if (!pName || duplicate_name)
402 {
403 static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
404 static const WCHAR wszFmt2[] = {'%','0','4','d',0};
405
406 for (j = 0; j < 10000 ; j++)
407 {
408 /* Create name */
409 if (pName)
410 sprintfW(wszFilterName, wszFmt1, pName, This->nameIndex);
411 else
412 sprintfW(wszFilterName, wszFmt2, This->nameIndex);
413 TRACE("Generated name %s\n", debugstr_w(wszFilterName));
414
415 /* Check if the generated name already exists */
416 for(i = 0; i < This->nFilters; i++)
417 if (!strcmpW(This->pFilterNames[i], wszFilterName))
418 break;
419
420 /* Compute next index and exit if generated name is suitable */
421 if (This->nameIndex++ == 10000)
422 This->nameIndex = 1;
423 if (i == This->nFilters)
424 break;
425 }
426 /* Unable to find a suitable name */
427 if (j == 10000)
428 {
429 CoTaskMemFree(wszFilterName);
430 return VFW_E_DUPLICATE_NAME;
431 }
432 }
433 else
434 memcpy(wszFilterName, pName, (strlenW(pName) + 1) * sizeof(WCHAR));
435
436 if (This->nFilters + 1 > This->filterCapacity)
437 {
438 int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
439 IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
440 LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
441 memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
442 memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
443 if (This->filterCapacity)
444 {
445 CoTaskMemFree(This->ppFiltersInGraph);
446 CoTaskMemFree(This->pFilterNames);
447 }
448 This->ppFiltersInGraph = ppNewFilters;
449 This->pFilterNames = pNewNames;
450 This->filterCapacity = newCapacity;
451 }
452
453 hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)This, wszFilterName);
454
455 if (SUCCEEDED(hr))
456 {
457 IBaseFilter_AddRef(pFilter);
458 This->ppFiltersInGraph[This->nFilters] = pFilter;
459 This->pFilterNames[This->nFilters] = wszFilterName;
460 This->nFilters++;
461 This->version++;
462 IBaseFilter_SetSyncSource(pFilter, This->refClock);
463 }
464 else
465 CoTaskMemFree(wszFilterName);
466
467 if (SUCCEEDED(hr) && duplicate_name)
468 return VFW_S_DUPLICATE_NAME;
469
470 return hr;
471 }
472
473 static HRESULT WINAPI FilterGraph2_RemoveFilter(IFilterGraph2 *iface, IBaseFilter *pFilter)
474 {
475 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
476 int i;
477 HRESULT hr = E_FAIL;
478
479 TRACE("(%p/%p)->(%p)\n", This, iface, pFilter);
480
481 /* FIXME: check graph is stopped */
482
483 for (i = 0; i < This->nFilters; i++)
484 {
485 if (This->ppFiltersInGraph[i] == pFilter)
486 {
487 IEnumPins *penumpins = NULL;
488 FILTER_STATE state;
489
490 if (This->defaultclock && This->refClockProvider == pFilter)
491 {
492 IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, NULL);
493 This->defaultclock = 1;
494 }
495
496 TRACE("Removing filter %s\n", debugstr_w(This->pFilterNames[i]));
497 IBaseFilter_GetState(pFilter, 0, &state);
498 if (state == State_Running)
499 IBaseFilter_Pause(pFilter);
500 if (state != State_Stopped)
501 IBaseFilter_Stop(pFilter);
502
503 hr = IBaseFilter_EnumPins(pFilter, &penumpins);
504 if (SUCCEEDED(hr)) {
505 IPin *ppin;
506 while(IEnumPins_Next(penumpins, 1, &ppin, NULL) == S_OK)
507 {
508 IPin *victim = NULL;
509 HRESULT h;
510 IPin_ConnectedTo(ppin, &victim);
511 if (victim)
512 {
513 h = IPin_Disconnect(victim);
514 TRACE("Disconnect other side: %08x\n", h);
515 if (h == VFW_E_NOT_STOPPED)
516 {
517 PIN_INFO pinfo;
518 IPin_QueryPinInfo(victim, &pinfo);
519
520 IBaseFilter_GetState(pinfo.pFilter, 0, &state);
521 if (state == State_Running)
522 IBaseFilter_Pause(pinfo.pFilter);
523 IBaseFilter_Stop(pinfo.pFilter);
524 IBaseFilter_Release(pinfo.pFilter);
525 h = IPin_Disconnect(victim);
526 TRACE("Disconnect retry: %08x\n", h);
527 }
528 IPin_Release(victim);
529 }
530 h = IPin_Disconnect(ppin);
531 TRACE("Disconnect 2: %08x\n", h);
532
533 IPin_Release(ppin);
534 }
535 IEnumPins_Release(penumpins);
536 }
537
538 hr = IBaseFilter_JoinFilterGraph(pFilter, NULL, This->pFilterNames[i]);
539 if (SUCCEEDED(hr))
540 {
541 IBaseFilter_SetSyncSource(pFilter, NULL);
542 IBaseFilter_Release(pFilter);
543 CoTaskMemFree(This->pFilterNames[i]);
544 memmove(This->ppFiltersInGraph+i, This->ppFiltersInGraph+i+1, sizeof(IBaseFilter*)*(This->nFilters - 1 - i));
545 memmove(This->pFilterNames+i, This->pFilterNames+i+1, sizeof(LPWSTR)*(This->nFilters - 1 - i));
546 This->nFilters--;
547 This->version++;
548 /* Invalidate interfaces in the cache */
549 for (i = 0; i < This->nItfCacheEntries; i++)
550 if (pFilter == This->ItfCacheEntries[i].filter)
551 {
552 IUnknown_Release(This->ItfCacheEntries[i].iface);
553 This->ItfCacheEntries[i].iface = NULL;
554 This->ItfCacheEntries[i].filter = NULL;
555 }
556 return S_OK;
557 }
558 break;
559 }
560 }
561
562 return hr; /* FIXME: check this error code */
563 }
564
565 static HRESULT WINAPI FilterGraph2_EnumFilters(IFilterGraph2 *iface, IEnumFilters **ppEnum)
566 {
567 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
568
569 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
570
571 return IEnumFiltersImpl_Construct(&This->IGraphVersion_iface, &This->ppFiltersInGraph, &This->nFilters, ppEnum);
572 }
573
574 static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface, LPCWSTR pName,
575 IBaseFilter **ppFilter)
576 {
577 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
578 int i;
579
580 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_w(pName), pName, ppFilter);
581
582 if (!ppFilter)
583 return E_POINTER;
584
585 for (i = 0; i < This->nFilters; i++)
586 {
587 if (!strcmpW(pName, This->pFilterNames[i]))
588 {
589 *ppFilter = This->ppFiltersInGraph[i];
590 IBaseFilter_AddRef(*ppFilter);
591 return S_OK;
592 }
593 }
594
595 *ppFilter = NULL;
596 return VFW_E_NOT_FOUND;
597 }
598
599 /* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
600 * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
601 */
602 static HRESULT CheckCircularConnection(IFilterGraphImpl *This, IPin *out, IPin *in)
603 {
604 #if 1
605 HRESULT hr;
606 PIN_INFO info_out, info_in;
607
608 hr = IPin_QueryPinInfo(out, &info_out);
609 if (FAILED(hr))
610 return hr;
611 if (info_out.dir != PINDIR_OUTPUT)
612 {
613 IBaseFilter_Release(info_out.pFilter);
614 return E_UNEXPECTED;
615 }
616
617 hr = IPin_QueryPinInfo(in, &info_in);
618 if (SUCCEEDED(hr))
619 IBaseFilter_Release(info_in.pFilter);
620 if (FAILED(hr))
621 goto out;
622 if (info_in.dir != PINDIR_INPUT)
623 {
624 hr = E_UNEXPECTED;
625 goto out;
626 }
627
628 if (info_out.pFilter == info_in.pFilter)
629 hr = VFW_E_CIRCULAR_GRAPH;
630 else
631 {
632 IEnumPins *enumpins;
633 IPin *test;
634
635 hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
636 if (FAILED(hr))
637 goto out;
638
639 IEnumPins_Reset(enumpins);
640 while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
641 {
642 PIN_DIRECTION dir = PINDIR_OUTPUT;
643 IPin_QueryDirection(test, &dir);
644 if (dir == PINDIR_INPUT)
645 {
646 IPin *victim = NULL;
647 IPin_ConnectedTo(test, &victim);
648 if (victim)
649 {
650 hr = CheckCircularConnection(This, victim, in);
651 IPin_Release(victim);
652 if (FAILED(hr))
653 {
654 IPin_Release(test);
655 break;
656 }
657 }
658 }
659 IPin_Release(test);
660 }
661 IEnumPins_Release(enumpins);
662 }
663
664 out:
665 IBaseFilter_Release(info_out.pFilter);
666 if (FAILED(hr))
667 ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
668 return hr;
669 #else
670 /* Debugging filtergraphs not enabled */
671 return S_OK;
672 #endif
673 }
674
675
676 /* NOTE: despite the implication, it doesn't matter which
677 * way round you put in the input and output pins */
678 static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppinIn, IPin *ppinOut,
679 const AM_MEDIA_TYPE *pmt)
680 {
681 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
682 PIN_DIRECTION dir;
683 HRESULT hr;
684
685 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, ppinIn, ppinOut, pmt);
686
687 /* FIXME: check pins are in graph */
688
689 if (TRACE_ON(quartz))
690 {
691 PIN_INFO PinInfo;
692
693 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
694 if (FAILED(hr))
695 return hr;
696
697 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
698 IBaseFilter_Release(PinInfo.pFilter);
699
700 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
701 if (FAILED(hr))
702 return hr;
703
704 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
705 IBaseFilter_Release(PinInfo.pFilter);
706 }
707
708 hr = IPin_QueryDirection(ppinIn, &dir);
709 if (SUCCEEDED(hr))
710 {
711 if (dir == PINDIR_INPUT)
712 {
713 hr = CheckCircularConnection(This, ppinOut, ppinIn);
714 if (SUCCEEDED(hr))
715 hr = IPin_Connect(ppinOut, ppinIn, pmt);
716 }
717 else
718 {
719 hr = CheckCircularConnection(This, ppinIn, ppinOut);
720 if (SUCCEEDED(hr))
721 hr = IPin_Connect(ppinIn, ppinOut, pmt);
722 }
723 }
724
725 return hr;
726 }
727
728 static HRESULT WINAPI FilterGraph2_Reconnect(IFilterGraph2 *iface, IPin *ppin)
729 {
730 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
731 IPin *pConnectedTo = NULL;
732 HRESULT hr;
733 PIN_DIRECTION pindir;
734
735 IPin_QueryDirection(ppin, &pindir);
736 hr = IPin_ConnectedTo(ppin, &pConnectedTo);
737 if (FAILED(hr)) {
738 TRACE("Querying connected to failed: %x\n", hr);
739 return hr;
740 }
741 IPin_Disconnect(ppin);
742 IPin_Disconnect(pConnectedTo);
743 if (pindir == PINDIR_INPUT)
744 hr = IPin_Connect(pConnectedTo, ppin, NULL);
745 else
746 hr = IPin_Connect(ppin, pConnectedTo, NULL);
747 IPin_Release(pConnectedTo);
748 if (FAILED(hr))
749 WARN("Reconnecting pins failed, pins are not connected now..\n");
750 TRACE("(%p->%p) -- %p %p -> %x\n", iface, This, ppin, pConnectedTo, hr);
751 return hr;
752 }
753
754 static HRESULT WINAPI FilterGraph2_Disconnect(IFilterGraph2 *iface, IPin *ppin)
755 {
756 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
757
758 TRACE("(%p/%p)->(%p)\n", This, iface, ppin);
759
760 if (!ppin)
761 return E_POINTER;
762
763 return IPin_Disconnect(ppin);
764 }
765
766 static HRESULT WINAPI FilterGraph2_SetDefaultSyncSource(IFilterGraph2 *iface)
767 {
768 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
769 IReferenceClock *pClock = NULL;
770 HRESULT hr = S_OK;
771 int i;
772
773 TRACE("(%p/%p)->() live sources not handled properly!\n", iface, This);
774
775 EnterCriticalSection(&This->cs);
776
777 for (i = 0; i < This->nFilters; ++i)
778 {
779 DWORD miscflags;
780 IAMFilterMiscFlags *flags = NULL;
781 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IAMFilterMiscFlags, (void**)&flags);
782 if (!flags)
783 continue;
784 miscflags = IAMFilterMiscFlags_GetMiscFlags(flags);
785 IAMFilterMiscFlags_Release(flags);
786 if (miscflags == AM_FILTER_MISC_FLAGS_IS_RENDERER)
787 IBaseFilter_QueryInterface(This->ppFiltersInGraph[i], &IID_IReferenceClock, (void**)&pClock);
788 if (pClock)
789 break;
790 }
791
792 if (!pClock)
793 {
794 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&pClock);
795 This->refClockProvider = NULL;
796 }
797 else
798 This->refClockProvider = This->ppFiltersInGraph[i];
799
800 if (SUCCEEDED(hr))
801 {
802 hr = IMediaFilter_SetSyncSource(&This->IMediaFilter_iface, pClock);
803 This->defaultclock = TRUE;
804 IReferenceClock_Release(pClock);
805 }
806 LeaveCriticalSection(&This->cs);
807
808 return hr;
809 }
810
811 static HRESULT GetFilterInfo(IMoniker* pMoniker, VARIANT* pvar)
812 {
813 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
814 IPropertyBag * pPropBagCat = NULL;
815 HRESULT hr;
816
817 VariantInit(pvar);
818
819 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
820
821 if (SUCCEEDED(hr))
822 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL);
823
824 if (SUCCEEDED(hr))
825 TRACE("Moniker = %s\n", debugstr_w(V_UNION(pvar, bstrVal)));
826
827 if (pPropBagCat)
828 IPropertyBag_Release(pPropBagCat);
829
830 return hr;
831 }
832
833 static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPin*** pppins, ULONG* pnb)
834 {
835 HRESULT hr;
836 ULONG nb = 0;
837
838 TRACE("(%p, %p, %p, %p)\n", pfilter, pinputpin, pppins, pnb);
839 hr = IPin_QueryInternalConnections(pinputpin, NULL, &nb);
840 if (hr == S_OK) {
841 /* Rendered input */
842 } else if (hr == S_FALSE) {
843 *pppins = CoTaskMemAlloc(sizeof(IPin*)*nb);
844 hr = IPin_QueryInternalConnections(pinputpin, *pppins, &nb);
845 if (hr != S_OK) {
846 WARN("Error (%x)\n", hr);
847 }
848 } else if (hr == E_NOTIMPL) {
849 /* Input connected to all outputs */
850 IEnumPins* penumpins;
851 IPin* ppin;
852 int i = 0;
853 TRACE("E_NOTIMPL\n");
854 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
855 if (FAILED(hr)) {
856 WARN("filter Enumpins failed (%x)\n", hr);
857 return hr;
858 }
859 i = 0;
860 /* Count output pins */
861 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
862 PIN_DIRECTION pindir;
863 IPin_QueryDirection(ppin, &pindir);
864 if (pindir == PINDIR_OUTPUT)
865 i++;
866 IPin_Release(ppin);
867 }
868 *pppins = CoTaskMemAlloc(sizeof(IPin*)*i);
869 /* Retrieve output pins */
870 IEnumPins_Reset(penumpins);
871 i = 0;
872 while(IEnumPins_Next(penumpins, 1, &ppin, &nb) == S_OK) {
873 PIN_DIRECTION pindir;
874 IPin_QueryDirection(ppin, &pindir);
875 if (pindir == PINDIR_OUTPUT)
876 (*pppins)[i++] = ppin;
877 else
878 IPin_Release(ppin);
879 }
880 IEnumPins_Release(penumpins);
881 nb = i;
882 if (FAILED(hr)) {
883 WARN("Next failed (%x)\n", hr);
884 return hr;
885 }
886 } else if (FAILED(hr)) {
887 WARN("Cannot get internal connection (%x)\n", hr);
888 return hr;
889 }
890
891 *pnb = nb;
892 return S_OK;
893 }
894
895 /*** IGraphBuilder methods ***/
896 static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn)
897 {
898 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
899 HRESULT hr;
900 AM_MEDIA_TYPE* mt = NULL;
901 IEnumMediaTypes* penummt = NULL;
902 ULONG nbmt;
903 IEnumPins* penumpins;
904 IEnumMoniker* pEnumMoniker;
905 GUID tab[2];
906 ULONG nb = 0;
907 IMoniker* pMoniker;
908 ULONG pin;
909 PIN_INFO PinInfo;
910 CLSID FilterCLSID;
911 PIN_DIRECTION dir;
912 unsigned int i = 0;
913
914 TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
915
916 if (TRACE_ON(quartz))
917 {
918 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
919 if (FAILED(hr))
920 return hr;
921
922 TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
923 IBaseFilter_Release(PinInfo.pFilter);
924
925 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
926 if (FAILED(hr))
927 return hr;
928
929 TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
930 IBaseFilter_Release(PinInfo.pFilter);
931 }
932
933 EnterCriticalSection(&This->cs);
934 ++This->recursioncount;
935 if (This->recursioncount >= 5)
936 {
937 WARN("Recursion count has reached %d\n", This->recursioncount);
938 hr = VFW_E_CANNOT_CONNECT;
939 goto out;
940 }
941
942 hr = IPin_QueryDirection(ppinOut, &dir);
943 if (FAILED(hr))
944 goto out;
945
946 if (dir == PINDIR_INPUT)
947 {
948 IPin *temp;
949
950 temp = ppinIn;
951 ppinIn = ppinOut;
952 ppinOut = temp;
953 }
954
955 hr = CheckCircularConnection(This, ppinOut, ppinIn);
956 if (FAILED(hr))
957 goto out;
958
959 /* Try direct connection first */
960 hr = IPin_Connect(ppinOut, ppinIn, NULL);
961 if (SUCCEEDED(hr))
962 goto out;
963
964 TRACE("Direct connection failed, trying to render using extra filters\n");
965
966 hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
967 if (FAILED(hr))
968 goto out;
969
970 hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
971 IBaseFilter_Release(PinInfo.pFilter);
972 if (FAILED(hr))
973 goto out;
974
975 /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream
976 * filter to the minor mediatype of input pin of the renderer */
977 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
978 if (FAILED(hr))
979 {
980 WARN("EnumMediaTypes (%x)\n", hr);
981 goto out;
982 }
983
984 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
985 if (FAILED(hr)) {
986 WARN("IEnumMediaTypes_Next (%x)\n", hr);
987 goto out;
988 }
989
990 if (!nbmt)
991 {
992 WARN("No media type found!\n");
993 hr = VFW_E_INVALIDMEDIATYPE;
994 goto out;
995 }
996 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
997 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
998
999 /* Try to find a suitable filter that can connect to the pin to render */
1000 tab[0] = mt->majortype;
1001 tab[1] = mt->subtype;
1002 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1003 if (FAILED(hr)) {
1004 WARN("Unable to enum filters (%x)\n", hr);
1005 goto out;
1006 }
1007
1008 hr = VFW_E_CANNOT_RENDER;
1009 while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1010 {
1011 VARIANT var;
1012 GUID clsid;
1013 IPin** ppins = NULL;
1014 IPin* ppinfilter = NULL;
1015 IBaseFilter* pfilter = NULL;
1016 IAMGraphBuilderCallback *callback = NULL;
1017
1018 hr = GetFilterInfo(pMoniker, &var);
1019 if (FAILED(hr)) {
1020 WARN("Unable to retrieve filter info (%x)\n", hr);
1021 goto error;
1022 }
1023
1024 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1025 IMoniker_Release(pMoniker);
1026 if (FAILED(hr)) {
1027 WARN("Unable to create filter (%x), trying next one\n", hr);
1028 goto error;
1029 }
1030
1031 hr = IBaseFilter_GetClassID(pfilter, &clsid);
1032 if (FAILED(hr))
1033 {
1034 IBaseFilter_Release(pfilter);
1035 goto error;
1036 }
1037
1038 if (IsEqualGUID(&clsid, &FilterCLSID)) {
1039 /* Skip filter (same as the one the output pin belongs to) */
1040 IBaseFilter_Release(pfilter);
1041 goto error;
1042 }
1043
1044 if (This->pSite)
1045 {
1046 IUnknown_QueryInterface(This->pSite, &IID_IAMGraphBuilderCallback, (LPVOID*)&callback);
1047 if (callback)
1048 {
1049 HRESULT rc;
1050 rc = IAMGraphBuilderCallback_SelectedFilter(callback, pMoniker);
1051 if (FAILED(rc))
1052 {
1053 TRACE("Filter rejected by IAMGraphBuilderCallback_SelectedFilter\n");
1054 IAMGraphBuilderCallback_Release(callback);
1055 goto error;
1056 }
1057 }
1058 }
1059
1060 if (callback)
1061 {
1062 HRESULT rc;
1063 rc = IAMGraphBuilderCallback_CreatedFilter(callback, pfilter);
1064 IAMGraphBuilderCallback_Release(callback);
1065 if (FAILED(rc))
1066 {
1067 IBaseFilter_Release(pfilter);
1068 pfilter = NULL;
1069 TRACE("Filter rejected by IAMGraphBuilderCallback_CreatedFilter\n");
1070 goto error;
1071 }
1072 }
1073
1074 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1075 if (FAILED(hr)) {
1076 WARN("Unable to add filter (%x)\n", hr);
1077 IBaseFilter_Release(pfilter);
1078 pfilter = NULL;
1079 goto error;
1080 }
1081
1082 VariantClear(&var);
1083
1084 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1085 if (FAILED(hr)) {
1086 WARN("Enumpins (%x)\n", hr);
1087 goto error;
1088 }
1089
1090 hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin);
1091 IEnumPins_Release(penumpins);
1092
1093 if (FAILED(hr)) {
1094 WARN("Obtaining next pin: (%x)\n", hr);
1095 goto error;
1096 }
1097 if (pin == 0) {
1098 WARN("Cannot use this filter: no pins\n");
1099 goto error;
1100 }
1101
1102 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1103 if (FAILED(hr)) {
1104 TRACE("Cannot connect to filter (%x), trying next one\n", hr);
1105 goto error;
1106 }
1107 TRACE("Successfully connected to filter, follow chain...\n");
1108
1109 /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */
1110 hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb);
1111
1112 if (SUCCEEDED(hr)) {
1113 if (nb == 0) {
1114 IPin_Disconnect(ppinfilter);
1115 IPin_Disconnect(ppinOut);
1116 goto error;
1117 }
1118 TRACE("pins to consider: %d\n", nb);
1119 for(i = 0; i < nb; i++)
1120 {
1121 LPWSTR pinname = NULL;
1122
1123 TRACE("Processing pin %u\n", i);
1124
1125 hr = IPin_QueryId(ppins[i], &pinname);
1126 if (SUCCEEDED(hr))
1127 {
1128 if (pinname[0] == '~')
1129 {
1130 TRACE("Pinname=%s, skipping\n", debugstr_w(pinname));
1131 hr = E_FAIL;
1132 }
1133 else
1134 hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn);
1135 CoTaskMemFree(pinname);
1136 }
1137
1138 if (FAILED(hr)) {
1139 TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr);
1140 }
1141 IPin_Release(ppins[i]);
1142 if (SUCCEEDED(hr)) break;
1143 }
1144 while (++i < nb) IPin_Release(ppins[i]);
1145 CoTaskMemFree(ppins);
1146 IPin_Release(ppinfilter);
1147 IBaseFilter_Release(pfilter);
1148 if (FAILED(hr))
1149 {
1150 IPin_Disconnect(ppinfilter);
1151 IPin_Disconnect(ppinOut);
1152 IFilterGraph2_RemoveFilter(iface, pfilter);
1153 continue;
1154 }
1155 break;
1156 }
1157
1158 error:
1159 VariantClear(&var);
1160 if (ppinfilter) IPin_Release(ppinfilter);
1161 if (pfilter) {
1162 IFilterGraph2_RemoveFilter(iface, pfilter);
1163 IBaseFilter_Release(pfilter);
1164 }
1165 while (++i < nb) IPin_Release(ppins[i]);
1166 CoTaskMemFree(ppins);
1167 }
1168
1169 out:
1170 if (penummt)
1171 IEnumMediaTypes_Release(penummt);
1172 if (mt)
1173 DeleteMediaType(mt);
1174 --This->recursioncount;
1175 LeaveCriticalSection(&This->cs);
1176 TRACE("--> %08x\n", hr);
1177 return SUCCEEDED(hr) ? S_OK : hr;
1178 }
1179
1180 static HRESULT FilterGraph2_RenderRecurse(IFilterGraphImpl *This, IPin *ppinOut)
1181 {
1182 /* This pin has been connected now, try to call render on all pins that aren't connected */
1183 IPin *to = NULL;
1184 PIN_INFO info;
1185 IEnumPins *enumpins = NULL;
1186 BOOL renderany = FALSE;
1187 BOOL renderall = TRUE;
1188
1189 IPin_QueryPinInfo(ppinOut, &info);
1190
1191 IBaseFilter_EnumPins(info.pFilter, &enumpins);
1192 /* Don't need to hold a reference, IEnumPins does */
1193 IBaseFilter_Release(info.pFilter);
1194
1195 IEnumPins_Reset(enumpins);
1196 while (IEnumPins_Next(enumpins, 1, &to, NULL) == S_OK)
1197 {
1198 PIN_DIRECTION dir = PINDIR_INPUT;
1199
1200 IPin_QueryDirection(to, &dir);
1201
1202 if (dir == PINDIR_OUTPUT)
1203 {
1204 IPin *out = NULL;
1205
1206 IPin_ConnectedTo(to, &out);
1207 if (!out)
1208 {
1209 HRESULT hr;
1210 hr = IFilterGraph2_Render(&This->IFilterGraph2_iface, to);
1211 if (SUCCEEDED(hr))
1212 renderany = TRUE;
1213 else
1214 renderall = FALSE;
1215 }
1216 else
1217 IPin_Release(out);
1218 }
1219
1220 IPin_Release(to);
1221 }
1222
1223 IEnumPins_Release(enumpins);
1224
1225 if (renderall)
1226 return S_OK;
1227
1228 if (renderany)
1229 return VFW_S_PARTIAL_RENDER;
1230
1231 return VFW_E_CANNOT_RENDER;
1232 }
1233
1234 /* Ogg hates me if I create a direct rendering method
1235 *
1236 * It can only connect to a pin properly once, so use a recursive method that does
1237 *
1238 * +----+ --- (PIN 1) (Render is called on this pin)
1239 * | |
1240 * +----+ --- (PIN 2)
1241 *
1242 * Enumerate possible renderers that EXACTLY match the requested type
1243 *
1244 * If none is available, try to add intermediate filters that can connect to the input pin
1245 * then call Render on that intermediate pin's output pins
1246 * if it succeeds: Render returns success, if it doesn't, the intermediate filter is removed,
1247 * and another filter that can connect to the input pin is tried
1248 * if we run out of filters that can, give up and return VFW_E_CANNOT_RENDER
1249 * It's recursive, but fun!
1250 */
1251
1252 static HRESULT WINAPI FilterGraph2_Render(IFilterGraph2 *iface, IPin *ppinOut)
1253 {
1254 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1255 IEnumMediaTypes* penummt;
1256 AM_MEDIA_TYPE* mt;
1257 ULONG nbmt;
1258 HRESULT hr;
1259
1260 IEnumMoniker* pEnumMoniker;
1261 GUID tab[4];
1262 ULONG nb;
1263 IMoniker* pMoniker;
1264 INT x;
1265
1266 TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
1267
1268 if (TRACE_ON(quartz))
1269 {
1270 PIN_INFO PinInfo;
1271
1272 hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
1273 if (FAILED(hr))
1274 return hr;
1275
1276 TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
1277 IBaseFilter_Release(PinInfo.pFilter);
1278 }
1279
1280 /* Try to find out if there is a renderer for the specified subtype already, and use that
1281 */
1282 EnterCriticalSection(&This->cs);
1283 for (x = 0; x < This->nFilters; ++x)
1284 {
1285 IEnumPins *enumpins = NULL;
1286 IPin *pin = NULL;
1287
1288 hr = IBaseFilter_EnumPins(This->ppFiltersInGraph[x], &enumpins);
1289
1290 if (FAILED(hr) || !enumpins)
1291 continue;
1292
1293 IEnumPins_Reset(enumpins);
1294 while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK)
1295 {
1296 IPin *to = NULL;
1297 PIN_DIRECTION dir = PINDIR_OUTPUT;
1298
1299 IPin_QueryDirection(pin, &dir);
1300 if (dir != PINDIR_INPUT)
1301 {
1302 IPin_Release(pin);
1303 continue;
1304 }
1305 IPin_ConnectedTo(pin, &to);
1306
1307 if (to == NULL)
1308 {
1309 hr = FilterGraph2_ConnectDirect(iface, ppinOut, pin, NULL);
1310 if (SUCCEEDED(hr))
1311 {
1312 TRACE("Connected successfully %p/%p, %08x look if we should render more!\n", ppinOut, pin, hr);
1313 IPin_Release(pin);
1314
1315 hr = FilterGraph2_RenderRecurse(This, pin);
1316 if (FAILED(hr))
1317 {
1318 IPin_Disconnect(ppinOut);
1319 IPin_Disconnect(pin);
1320 continue;
1321 }
1322 IEnumPins_Release(enumpins);
1323 LeaveCriticalSection(&This->cs);
1324 return hr;
1325 }
1326 WARN("Could not connect!\n");
1327 }
1328 else
1329 IPin_Release(to);
1330
1331 IPin_Release(pin);
1332 }
1333 IEnumPins_Release(enumpins);
1334 }
1335
1336 LeaveCriticalSection(&This->cs);
1337
1338 hr = IPin_EnumMediaTypes(ppinOut, &penummt);
1339 if (FAILED(hr)) {
1340 WARN("EnumMediaTypes (%x)\n", hr);
1341 return hr;
1342 }
1343
1344 IEnumMediaTypes_Reset(penummt);
1345
1346 /* Looks like no existing renderer of the kind exists
1347 * Try adding new ones
1348 */
1349 tab[0] = tab[1] = GUID_NULL;
1350 while (SUCCEEDED(hr))
1351 {
1352 hr = IEnumMediaTypes_Next(penummt, 1, &mt, &nbmt);
1353 if (FAILED(hr)) {
1354 WARN("IEnumMediaTypes_Next (%x)\n", hr);
1355 break;
1356 }
1357 if (!nbmt)
1358 {
1359 hr = VFW_E_CANNOT_RENDER;
1360 break;
1361 }
1362 else
1363 {
1364 TRACE("MajorType %s\n", debugstr_guid(&mt->majortype));
1365 TRACE("SubType %s\n", debugstr_guid(&mt->subtype));
1366
1367 /* Only enumerate once, this doesn't account for all previous ones, but this should be enough nonetheless */
1368 if (IsEqualIID(&tab[0], &mt->majortype) && IsEqualIID(&tab[1], &mt->subtype))
1369 {
1370 DeleteMediaType(mt);
1371 continue;
1372 }
1373
1374 /* Try to find a suitable renderer with the same media type */
1375 tab[0] = mt->majortype;
1376 tab[1] = mt->subtype;
1377 hr = IFilterMapper2_EnumMatchingFilters(This->pFilterMapper2, &pEnumMoniker, 0, FALSE, MERIT_UNLIKELY, TRUE, 1, tab, NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL);
1378 if (FAILED(hr))
1379 {
1380 WARN("Unable to enum filters (%x)\n", hr);
1381 break;
1382 }
1383 }
1384 hr = E_FAIL;
1385
1386 while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK)
1387 {
1388 VARIANT var;
1389 IPin* ppinfilter;
1390 IBaseFilter* pfilter = NULL;
1391 IEnumPins* penumpins = NULL;
1392 ULONG pin;
1393
1394 hr = GetFilterInfo(pMoniker, &var);
1395 if (FAILED(hr)) {
1396 WARN("Unable to retrieve filter info (%x)\n", hr);
1397 goto error;
1398 }
1399
1400 hr = IMoniker_BindToObject(pMoniker, NULL, NULL, &IID_IBaseFilter, (LPVOID*)&pfilter);
1401 IMoniker_Release(pMoniker);
1402 if (FAILED(hr))
1403 {
1404 WARN("Unable to create filter (%x), trying next one\n", hr);
1405 goto error;
1406 }
1407
1408 hr = IFilterGraph2_AddFilter(iface, pfilter, V_UNION(&var, bstrVal));
1409 if (FAILED(hr)) {
1410 WARN("Unable to add filter (%x)\n", hr);
1411 IBaseFilter_Release(pfilter);
1412 pfilter = NULL;
1413 goto error;
1414 }
1415
1416 hr = IBaseFilter_EnumPins(pfilter, &penumpins);
1417 if (FAILED(hr)) {
1418 WARN("Splitter Enumpins (%x)\n", hr);
1419 goto error;
1420 }
1421
1422 while ((hr = IEnumPins_Next(penumpins, 1, &ppinfilter, &pin)) == S_OK)
1423 {
1424 PIN_DIRECTION dir;
1425
1426 if (pin == 0) {
1427 WARN("No Pin\n");
1428 hr = E_FAIL;
1429 goto error;
1430 }
1431
1432 hr = IPin_QueryDirection(ppinfilter, &dir);
1433 if (FAILED(hr)) {
1434 IPin_Release(ppinfilter);
1435 WARN("QueryDirection failed (%x)\n", hr);
1436 goto error;
1437 }
1438 if (dir != PINDIR_INPUT) {
1439 IPin_Release(ppinfilter);
1440 continue; /* Wrong direction */
1441 }
1442
1443 /* Connect the pin to the "Renderer" */
1444 hr = IPin_Connect(ppinOut, ppinfilter, NULL);
1445 IPin_Release(ppinfilter);
1446
1447 if (FAILED(hr)) {
1448 WARN("Unable to connect %s to renderer (%x)\n", debugstr_w(V_UNION(&var, bstrVal)), hr);
1449 goto error;
1450 }
1451 TRACE("Connected, recursing %s\n", debugstr_w(V_UNION(&var, bstrVal)));
1452
1453 VariantClear(&var);
1454
1455 hr = FilterGraph2_RenderRecurse(This, ppinfilter);
1456 if (FAILED(hr)) {
1457 WARN("Unable to connect recursively (%x)\n", hr);
1458 goto error;
1459 }
1460 IBaseFilter_Release(pfilter);
1461 break;
1462 }
1463 if (SUCCEEDED(hr)) {
1464 IEnumPins_Release(penumpins);
1465 break; /* out of IEnumMoniker_Next loop */
1466 }
1467
1468 /* IEnumPins_Next failed, all other failure case caught by goto error */
1469 WARN("IEnumPins_Next (%x)\n", hr);
1470 /* goto error */
1471
1472 error:
1473 VariantClear(&var);
1474 if (penumpins)
1475 IEnumPins_Release(penumpins);
1476 if (pfilter) {
1477 IFilterGraph2_RemoveFilter(iface, pfilter);
1478 IBaseFilter_Release(pfilter);
1479 }
1480 if (SUCCEEDED(hr)) DebugBreak();
1481 }
1482
1483 IEnumMoniker_Release(pEnumMoniker);
1484 if (nbmt)
1485 DeleteMediaType(mt);
1486 if (SUCCEEDED(hr))
1487 break;
1488 hr = S_OK;
1489 }
1490
1491 IEnumMediaTypes_Release(penummt);
1492 return hr;
1493 }
1494
1495 static HRESULT WINAPI FilterGraph2_RenderFile(IFilterGraph2 *iface, LPCWSTR lpcwstrFile,
1496 LPCWSTR lpcwstrPlayList)
1497 {
1498 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1499 static const WCHAR string[] = {'R','e','a','d','e','r',0};
1500 IBaseFilter* preader = NULL;
1501 IPin* ppinreader = NULL;
1502 IEnumPins* penumpins = NULL;
1503 HRESULT hr;
1504 BOOL partial = FALSE;
1505 HRESULT any = FALSE;
1506
1507 TRACE("(%p/%p)->(%s, %s)\n", This, iface, debugstr_w(lpcwstrFile), debugstr_w(lpcwstrPlayList));
1508
1509 if (lpcwstrPlayList != NULL)
1510 return E_INVALIDARG;
1511
1512 hr = IFilterGraph2_AddSourceFilter(iface, lpcwstrFile, string, &preader);
1513 if (FAILED(hr))
1514 return hr;
1515
1516 if (SUCCEEDED(hr))
1517 hr = IBaseFilter_EnumPins(preader, &penumpins);
1518 if (SUCCEEDED(hr))
1519 {
1520 while (IEnumPins_Next(penumpins, 1, &ppinreader, NULL) == S_OK)
1521 {
1522 PIN_DIRECTION dir;
1523
1524 IPin_QueryDirection(ppinreader, &dir);
1525 if (dir == PINDIR_OUTPUT)
1526 {
1527 INT i;
1528
1529 hr = IFilterGraph2_Render(iface, ppinreader);
1530 TRACE("Render %08x\n", hr);
1531
1532 for (i = 0; i < This->nFilters; ++i)
1533 TRACE("Filters in chain: %s\n", debugstr_w(This->pFilterNames[i]));
1534
1535 if (SUCCEEDED(hr))
1536 any = TRUE;
1537 if (hr != S_OK)
1538 partial = TRUE;
1539 }
1540 IPin_Release(ppinreader);
1541 }
1542 IEnumPins_Release(penumpins);
1543
1544 if (!any)
1545 hr = VFW_E_CANNOT_RENDER;
1546 else if (partial)
1547 hr = VFW_S_PARTIAL_RENDER;
1548 else
1549 hr = S_OK;
1550 }
1551 IBaseFilter_Release(preader);
1552
1553 TRACE("--> %08x\n", hr);
1554 return hr;
1555 }
1556
1557 static HRESULT CreateFilterInstanceAndLoadFile(GUID* clsid, LPCOLESTR pszFileName, IBaseFilter **filter)
1558 {
1559 IFileSourceFilter *source = NULL;
1560 HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1561 TRACE("CLSID: %s\n", debugstr_guid(clsid));
1562 if (FAILED(hr))
1563 return hr;
1564
1565 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID*)&source);
1566 if (FAILED(hr))
1567 {
1568 IBaseFilter_Release(*filter);
1569 return hr;
1570 }
1571
1572 /* Load the file in the file source filter */
1573 hr = IFileSourceFilter_Load(source, pszFileName, NULL);
1574 IFileSourceFilter_Release(source);
1575 if (FAILED(hr)) {
1576 WARN("Load (%x)\n", hr);
1577 IBaseFilter_Release(*filter);
1578 return hr;
1579 }
1580
1581 return hr;
1582 }
1583
1584 /* Some filters implement their own asynchronous reader (Theoretically they all should, try to load it first */
1585 static HRESULT GetFileSourceFilter(LPCOLESTR pszFileName, IBaseFilter **filter)
1586 {
1587 HRESULT hr;
1588 GUID clsid;
1589 IAsyncReader * pReader = NULL;
1590 IFileSourceFilter* pSource = NULL;
1591 IPin * pOutputPin = NULL;
1592 static const WCHAR wszOutputPinName[] = { 'O','u','t','p','u','t',0 };
1593
1594 /* Try to find a match without reading the file first */
1595 hr = GetClassMediaFile(NULL, pszFileName, NULL, NULL, &clsid);
1596
1597 if (!hr)
1598 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1599
1600 /* Now create a AyncReader instance, to check for signature bytes in the file */
1601 hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)filter);
1602 if (FAILED(hr))
1603 return hr;
1604
1605 hr = IBaseFilter_QueryInterface(*filter, &IID_IFileSourceFilter, (LPVOID *)&pSource);
1606 if (FAILED(hr))
1607 {
1608 IBaseFilter_Release(*filter);
1609 return hr;
1610 }
1611
1612 hr = IFileSourceFilter_Load(pSource, pszFileName, NULL);
1613 IFileSourceFilter_Release(pSource);
1614 if (FAILED(hr))
1615 {
1616 IBaseFilter_Release(*filter);
1617 return hr;
1618 }
1619
1620 hr = IBaseFilter_FindPin(*filter, wszOutputPinName, &pOutputPin);
1621 if (FAILED(hr))
1622 {
1623 IBaseFilter_Release(*filter);
1624 return hr;
1625 }
1626
1627 hr = IPin_QueryInterface(pOutputPin, &IID_IAsyncReader, (LPVOID *)&pReader);
1628 IPin_Release(pOutputPin);
1629 if (FAILED(hr))
1630 {
1631 IBaseFilter_Release(*filter);
1632 return hr;
1633 }
1634
1635 /* Try again find a match */
1636 hr = GetClassMediaFile(pReader, pszFileName, NULL, NULL, &clsid);
1637 IAsyncReader_Release(pReader);
1638
1639 if (!hr)
1640 {
1641 /* Release the AsyncReader filter and create the matching one */
1642 IBaseFilter_Release(*filter);
1643 return CreateFilterInstanceAndLoadFile(&clsid, pszFileName, filter);
1644 }
1645
1646 /* Return the AsyncReader filter */
1647 return S_OK;
1648 }
1649
1650 static HRESULT WINAPI FilterGraph2_AddSourceFilter(IFilterGraph2 *iface, LPCWSTR lpcwstrFileName,
1651 LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1652 {
1653 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1654 HRESULT hr;
1655 IBaseFilter* preader;
1656 IFileSourceFilter* pfile = NULL;
1657 AM_MEDIA_TYPE mt;
1658 WCHAR* filename;
1659
1660 TRACE("(%p/%p)->(%s, %s, %p)\n", This, iface, debugstr_w(lpcwstrFileName), debugstr_w(lpcwstrFilterName), ppFilter);
1661
1662 /* Try from file name first, then fall back to default asynchronous reader */
1663 hr = GetFileSourceFilter(lpcwstrFileName, &preader);
1664 if (FAILED(hr)) {
1665 WARN("Unable to create file source filter (%x)\n", hr);
1666 return hr;
1667 }
1668
1669 hr = IFilterGraph2_AddFilter(iface, preader, lpcwstrFilterName);
1670 if (FAILED(hr)) {
1671 WARN("Unable add filter (%x)\n", hr);
1672 IBaseFilter_Release(preader);
1673 return hr;
1674 }
1675
1676 hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, (LPVOID*)&pfile);
1677 if (FAILED(hr)) {
1678 WARN("Unable to get IFileSourceInterface (%x)\n", hr);
1679 goto error;
1680 }
1681
1682 /* The file has been already loaded */
1683 IFileSourceFilter_GetCurFile(pfile, &filename, &mt);
1684 if (FAILED(hr)) {
1685 WARN("GetCurFile (%x)\n", hr);
1686 goto error;
1687 }
1688
1689 TRACE("File %s\n", debugstr_w(filename));
1690 TRACE("MajorType %s\n", debugstr_guid(&mt.majortype));
1691 TRACE("SubType %s\n", debugstr_guid(&mt.subtype));
1692
1693 if (ppFilter)
1694 *ppFilter = preader;
1695 IFileSourceFilter_Release(pfile);
1696
1697 return S_OK;
1698
1699 error:
1700 if (pfile)
1701 IFileSourceFilter_Release(pfile);
1702 IFilterGraph2_RemoveFilter(iface, preader);
1703 IBaseFilter_Release(preader);
1704
1705 return hr;
1706 }
1707
1708 static HRESULT WINAPI FilterGraph2_SetLogFile(IFilterGraph2 *iface, DWORD_PTR hFile)
1709 {
1710 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1711
1712 TRACE("(%p/%p)->(%08x): stub !!!\n", This, iface, (DWORD) hFile);
1713
1714 return S_OK;
1715 }
1716
1717 static HRESULT WINAPI FilterGraph2_Abort(IFilterGraph2 *iface)
1718 {
1719 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1720
1721 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1722
1723 return S_OK;
1724 }
1725
1726 static HRESULT WINAPI FilterGraph2_ShouldOperationContinue(IFilterGraph2 *iface)
1727 {
1728 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1729
1730 TRACE("(%p/%p)->(): stub !!!\n", This, iface);
1731
1732 return S_OK;
1733 }
1734
1735 /*** IFilterGraph2 methods ***/
1736 static HRESULT WINAPI FilterGraph2_AddSourceFilterForMoniker(IFilterGraph2 *iface,
1737 IMoniker *pMoniker, IBindCtx *pCtx, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)
1738 {
1739 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1740
1741 TRACE("(%p/%p)->(%p %p %s %p): stub !!!\n", This, iface, pMoniker, pCtx, debugstr_w(lpcwstrFilterName), ppFilter);
1742
1743 return S_OK;
1744 }
1745
1746 static HRESULT WINAPI FilterGraph2_ReconnectEx(IFilterGraph2 *iface, IPin *ppin,
1747 const AM_MEDIA_TYPE *pmt)
1748 {
1749 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1750
1751 TRACE("(%p/%p)->(%p %p): stub !!!\n", This, iface, ppin, pmt);
1752
1753 return S_OK;
1754 }
1755
1756 static HRESULT WINAPI FilterGraph2_RenderEx(IFilterGraph2 *iface, IPin *pPinOut, DWORD dwFlags,
1757 DWORD *pvContext)
1758 {
1759 IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
1760
1761 TRACE("(%p/%p)->(%p %08x %p): stub !!!\n", This, iface, pPinOut, dwFlags, pvContext);
1762
1763 return S_OK;
1764 }
1765
1766
1767 static const IFilterGraph2Vtbl IFilterGraph2_VTable =
1768 {
1769 FilterGraph2_QueryInterface,
1770 FilterGraph2_AddRef,
1771 FilterGraph2_Release,
1772 FilterGraph2_AddFilter,
1773 FilterGraph2_RemoveFilter,
1774 FilterGraph2_EnumFilters,
1775 FilterGraph2_FindFilterByName,
1776 FilterGraph2_ConnectDirect,
1777 FilterGraph2_Reconnect,
1778 FilterGraph2_Disconnect,
1779 FilterGraph2_SetDefaultSyncSource,
1780 FilterGraph2_Connect,
1781 FilterGraph2_Render,
1782 FilterGraph2_RenderFile,
1783 FilterGraph2_AddSourceFilter,
1784 FilterGraph2_SetLogFile,
1785 FilterGraph2_Abort,
1786 FilterGraph2_ShouldOperationContinue,
1787 FilterGraph2_AddSourceFilterForMoniker,
1788 FilterGraph2_ReconnectEx,
1789 FilterGraph2_RenderEx
1790 };
1791
1792 static inline IFilterGraphImpl *impl_from_IMediaControl(IMediaControl *iface)
1793 {
1794 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaControl_iface);
1795 }
1796
1797 static HRESULT WINAPI MediaControl_QueryInterface(IMediaControl *iface, REFIID riid, void **ppvObj)
1798 {
1799 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1800
1801 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
1802
1803 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
1804 }
1805
1806 static ULONG WINAPI MediaControl_AddRef(IMediaControl *iface)
1807 {
1808 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1809
1810 TRACE("(%p/%p)->()\n", This, iface);
1811
1812 return IUnknown_AddRef(This->outer_unk);
1813 }
1814
1815 static ULONG WINAPI MediaControl_Release(IMediaControl *iface)
1816 {
1817 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1818
1819 TRACE("(%p/%p)->()\n", This, iface);
1820
1821 return IUnknown_Release(This->outer_unk);
1822
1823 }
1824
1825 /*** IDispatch methods ***/
1826 static HRESULT WINAPI MediaControl_GetTypeInfoCount(IMediaControl *iface, UINT *pctinfo)
1827 {
1828 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1829
1830 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
1831
1832 return S_OK;
1833 }
1834
1835 static HRESULT WINAPI MediaControl_GetTypeInfo(IMediaControl *iface, UINT iTInfo, LCID lcid,
1836 ITypeInfo **ppTInfo)
1837 {
1838 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1839
1840 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
1841
1842 return S_OK;
1843 }
1844
1845 static HRESULT WINAPI MediaControl_GetIDsOfNames(IMediaControl *iface, REFIID riid,
1846 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1847 {
1848 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1849
1850 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
1851
1852 return S_OK;
1853 }
1854
1855 static HRESULT WINAPI MediaControl_Invoke(IMediaControl *iface, DISPID dispIdMember, REFIID riid,
1856 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
1857 UINT *puArgErr)
1858 {
1859 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
1860
1861 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
1862
1863 return S_OK;
1864 }
1865
1866 typedef HRESULT(WINAPI *fnFoundFilter)(IBaseFilter *, DWORD_PTR data);
1867
1868 static HRESULT ExploreGraph(IFilterGraphImpl* pGraph, IPin* pOutputPin, fnFoundFilter FoundFilter, DWORD_PTR data)
1869 {
1870 HRESULT hr;
1871 IPin* pInputPin;
1872 IPin** ppPins;
1873 ULONG nb;
1874 ULONG i;
1875 PIN_INFO PinInfo;
1876
1877 TRACE("%p %p\n", pGraph, pOutputPin);
1878 PinInfo.pFilter = NULL;
1879
1880 hr = IPin_ConnectedTo(pOutputPin, &pInputPin);
1881
1882 if (SUCCEEDED(hr))
1883 {
1884 hr = IPin_QueryPinInfo(pInputPin, &PinInfo);
1885 if (SUCCEEDED(hr))
1886 hr = GetInternalConnections(PinInfo.pFilter, pInputPin, &ppPins, &nb);
1887 IPin_Release(pInputPin);
1888 }
1889
1890 if (SUCCEEDED(hr))
1891 {
1892 if (nb == 0)
1893 {
1894 TRACE("Reached a renderer\n");
1895 /* Count renderers for end of stream notification */
1896 pGraph->nRenderers++;
1897 }
1898 else
1899 {
1900 for(i = 0; i < nb; i++)
1901 {
1902 /* Explore the graph downstream from this pin
1903 * FIXME: We should prevent exploring from a pin more than once. This can happens when
1904 * several input pins are connected to the same output (a MUX for instance). */
1905 ExploreGraph(pGraph, ppPins[i], FoundFilter, data);
1906 IPin_Release(ppPins[i]);
1907 }
1908
1909 CoTaskMemFree(ppPins);
1910 }
1911 TRACE("Doing stuff with filter %p\n", PinInfo.pFilter);
1912
1913 FoundFilter(PinInfo.pFilter, data);
1914 }
1915
1916 if (PinInfo.pFilter) IBaseFilter_Release(PinInfo.pFilter);
1917 return hr;
1918 }
1919
1920 static HRESULT WINAPI SendRun(IBaseFilter *pFilter, DWORD_PTR data)
1921 {
1922 REFERENCE_TIME time = *(REFERENCE_TIME*)data;
1923 return IBaseFilter_Run(pFilter, time);
1924 }
1925
1926 static HRESULT WINAPI SendPause(IBaseFilter *pFilter, DWORD_PTR data)
1927 {
1928 return IBaseFilter_Pause(pFilter);
1929 }
1930
1931 static HRESULT WINAPI SendStop(IBaseFilter *pFilter, DWORD_PTR data)
1932 {
1933 return IBaseFilter_Stop(pFilter);
1934 }
1935
1936 static HRESULT WINAPI SendGetState(IBaseFilter *pFilter, DWORD_PTR data)
1937 {
1938 FILTER_STATE state;
1939 DWORD time_end = data;
1940 DWORD time_now = GetTickCount();
1941 LONG wait;
1942
1943 if (time_end == INFINITE)
1944 {
1945 wait = INFINITE;
1946 }
1947 else if (time_end > time_now)
1948 {
1949 wait = time_end - time_now;
1950 }
1951 else
1952 wait = 0;
1953
1954 return IBaseFilter_GetState(pFilter, wait, &state);
1955 }
1956
1957
1958 static HRESULT SendFilterMessage(IFilterGraphImpl *This, fnFoundFilter FoundFilter, DWORD_PTR data)
1959 {
1960 int i;
1961 IBaseFilter* pfilter;
1962 IEnumPins* pEnum;
1963 HRESULT hr;
1964 IPin* pPin;
1965 DWORD dummy;
1966 PIN_DIRECTION dir;
1967
1968 TRACE("(%p)->()\n", This);
1969
1970 /* Explorer the graph from source filters to renderers, determine renderers
1971 * number and run filters from renderers to source filters */
1972 This->nRenderers = 0;
1973 ResetEvent(This->hEventCompletion);
1974
1975 for(i = 0; i < This->nFilters; i++)
1976 {
1977 BOOL source = TRUE;
1978 pfilter = This->ppFiltersInGraph[i];
1979 hr = IBaseFilter_EnumPins(pfilter, &pEnum);
1980 if (hr != S_OK)
1981 {
1982 WARN("Enum pins failed %x\n", hr);
1983 continue;
1984 }
1985 /* Check if it is a source filter */
1986 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
1987 {
1988 IPin_QueryDirection(pPin, &dir);
1989 IPin_Release(pPin);
1990 if (dir == PINDIR_INPUT)
1991 {
1992 source = FALSE;
1993 break;
1994 }
1995 }
1996 if (source)
1997 {
1998 TRACE("Found a source filter %p\n", pfilter);
1999 IEnumPins_Reset(pEnum);
2000 while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
2001 {
2002 /* Explore the graph downstream from this pin */
2003 ExploreGraph(This, pPin, FoundFilter, data);
2004 IPin_Release(pPin);
2005 }
2006 FoundFilter(pfilter, data);
2007 }
2008 IEnumPins_Release(pEnum);
2009 }
2010
2011 return S_FALSE;
2012 }
2013
2014 /*** IMediaControl methods ***/
2015 static HRESULT WINAPI MediaControl_Run(IMediaControl *iface)
2016 {
2017 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2018
2019 TRACE("(%p/%p)->()\n", This, iface);
2020
2021 EnterCriticalSection(&This->cs);
2022 if (This->state == State_Running)
2023 goto out;
2024 This->EcCompleteCount = 0;
2025
2026 if (This->defaultclock && !This->refClock)
2027 IFilterGraph2_SetDefaultSyncSource(&This->IFilterGraph2_iface);
2028
2029 if (This->refClock)
2030 {
2031 REFERENCE_TIME now;
2032 IReferenceClock_GetTime(This->refClock, &now);
2033 if (This->state == State_Stopped)
2034 This->start_time = now + 500000;
2035 else if (This->pause_time >= 0)
2036 This->start_time += now - This->pause_time;
2037 else
2038 This->start_time = now;
2039 }
2040 else This->start_time = 0;
2041
2042 SendFilterMessage(This, SendRun, (DWORD_PTR)&This->start_time);
2043 This->state = State_Running;
2044 out:
2045 LeaveCriticalSection(&This->cs);
2046 return S_FALSE;
2047 }
2048
2049 static HRESULT WINAPI MediaControl_Pause(IMediaControl *iface)
2050 {
2051 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2052
2053 TRACE("(%p/%p)->()\n", This, iface);
2054
2055 EnterCriticalSection(&This->cs);
2056 if (This->state == State_Paused)
2057 goto out;
2058
2059 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2060 IReferenceClock_GetTime(This->refClock, &This->pause_time);
2061 else
2062 This->pause_time = -1;
2063
2064 SendFilterMessage(This, SendPause, 0);
2065 This->state = State_Paused;
2066 out:
2067 LeaveCriticalSection(&This->cs);
2068 return S_FALSE;
2069 }
2070
2071 static HRESULT WINAPI MediaControl_Stop(IMediaControl *iface)
2072 {
2073 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2074
2075 TRACE("(%p/%p)->()\n", This, iface);
2076
2077 if (This->state == State_Stopped) return S_OK;
2078
2079 EnterCriticalSection(&This->cs);
2080 if (This->state == State_Running) SendFilterMessage(This, SendPause, 0);
2081 SendFilterMessage(This, SendStop, 0);
2082 This->state = State_Stopped;
2083 LeaveCriticalSection(&This->cs);
2084 return S_OK;
2085 }
2086
2087 static HRESULT WINAPI MediaControl_GetState(IMediaControl *iface, LONG msTimeout,
2088 OAFilterState *pfs)
2089 {
2090 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2091 DWORD end;
2092
2093 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pfs);
2094
2095 if (!pfs)
2096 return E_POINTER;
2097
2098 EnterCriticalSection(&This->cs);
2099
2100 *pfs = This->state;
2101 if (msTimeout > 0)
2102 {
2103 end = GetTickCount() + msTimeout;
2104 }
2105 else if (msTimeout < 0)
2106 {
2107 end = INFINITE;
2108 }
2109 else
2110 {
2111 end = 0;
2112 }
2113 if (end)
2114 SendFilterMessage(This, SendGetState, end);
2115
2116 LeaveCriticalSection(&This->cs);
2117
2118 return S_OK;
2119 }
2120
2121 static HRESULT WINAPI MediaControl_RenderFile(IMediaControl *iface, BSTR strFilename)
2122 {
2123 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2124
2125 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strFilename), strFilename);
2126
2127 return IFilterGraph2_RenderFile(&This->IFilterGraph2_iface, strFilename, NULL);
2128 }
2129
2130 static HRESULT WINAPI MediaControl_AddSourceFilter(IMediaControl *iface, BSTR strFilename,
2131 IDispatch **ppUnk)
2132 {
2133 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2134
2135 FIXME("(%p/%p)->(%s (%p), %p): stub !!!\n", This, iface, debugstr_w(strFilename), strFilename, ppUnk);
2136
2137 return S_OK;
2138 }
2139
2140 static HRESULT WINAPI MediaControl_get_FilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2141 {
2142 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2143
2144 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2145
2146 return S_OK;
2147 }
2148
2149 static HRESULT WINAPI MediaControl_get_RegFilterCollection(IMediaControl *iface, IDispatch **ppUnk)
2150 {
2151 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2152
2153 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, ppUnk);
2154
2155 return S_OK;
2156 }
2157
2158 static HRESULT WINAPI MediaControl_StopWhenReady(IMediaControl *iface)
2159 {
2160 IFilterGraphImpl *This = impl_from_IMediaControl(iface);
2161
2162 FIXME("(%p/%p)->(): stub !!!\n", This, iface);
2163
2164 return S_OK;
2165 }
2166
2167
2168 static const IMediaControlVtbl IMediaControl_VTable =
2169 {
2170 MediaControl_QueryInterface,
2171 MediaControl_AddRef,
2172 MediaControl_Release,
2173 MediaControl_GetTypeInfoCount,
2174 MediaControl_GetTypeInfo,
2175 MediaControl_GetIDsOfNames,
2176 MediaControl_Invoke,
2177 MediaControl_Run,
2178 MediaControl_Pause,
2179 MediaControl_Stop,
2180 MediaControl_GetState,
2181 MediaControl_RenderFile,
2182 MediaControl_AddSourceFilter,
2183 MediaControl_get_FilterCollection,
2184 MediaControl_get_RegFilterCollection,
2185 MediaControl_StopWhenReady
2186 };
2187
2188 static inline IFilterGraphImpl *impl_from_IMediaSeeking(IMediaSeeking *iface)
2189 {
2190 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaSeeking_iface);
2191 }
2192
2193 static HRESULT WINAPI MediaSeeking_QueryInterface(IMediaSeeking *iface, REFIID riid, void **ppvObj)
2194 {
2195 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2196
2197 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2198
2199 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2200 }
2201
2202 static ULONG WINAPI MediaSeeking_AddRef(IMediaSeeking *iface)
2203 {
2204 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2205
2206 TRACE("(%p/%p)->()\n", This, iface);
2207
2208 return IUnknown_AddRef(This->outer_unk);
2209 }
2210
2211 static ULONG WINAPI MediaSeeking_Release(IMediaSeeking *iface)
2212 {
2213 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2214
2215 TRACE("(%p/%p)->()\n", This, iface);
2216
2217 return IUnknown_Release(This->outer_unk);
2218 }
2219
2220 typedef HRESULT (WINAPI *fnFoundSeek)(IFilterGraphImpl *This, IMediaSeeking*, DWORD_PTR arg);
2221
2222 static HRESULT all_renderers_seek(IFilterGraphImpl *This, fnFoundSeek FoundSeek, DWORD_PTR arg) {
2223 BOOL allnotimpl = TRUE;
2224 int i;
2225 HRESULT hr, hr_return = S_OK;
2226
2227 TRACE("(%p)->(%p %08lx)\n", This, FoundSeek, arg);
2228 /* Send a message to all renderers, they are responsible for broadcasting it further */
2229
2230 for(i = 0; i < This->nFilters; i++)
2231 {
2232 IMediaSeeking *seek = NULL;
2233 IBaseFilter* pfilter = This->ppFiltersInGraph[i];
2234 IAMFilterMiscFlags *flags = NULL;
2235 ULONG filterflags;
2236 IBaseFilter_QueryInterface(pfilter, &IID_IAMFilterMiscFlags, (void**)&flags);
2237 if (!flags)
2238 continue;
2239 filterflags = IAMFilterMiscFlags_GetMiscFlags(flags);
2240 IAMFilterMiscFlags_Release(flags);
2241 if (filterflags != AM_FILTER_MISC_FLAGS_IS_RENDERER)
2242 continue;
2243
2244 IBaseFilter_QueryInterface(pfilter, &IID_IMediaSeeking, (void**)&seek);
2245 if (!seek)
2246 continue;
2247 hr = FoundSeek(This, seek, arg);
2248 IMediaSeeking_Release(seek);
2249 if (hr_return != E_NOTIMPL)
2250 allnotimpl = FALSE;
2251 if (hr_return == S_OK || (FAILED(hr) && hr != E_NOTIMPL && SUCCEEDED(hr_return)))
2252 hr_return = hr;
2253 }
2254
2255 if (allnotimpl)
2256 return E_NOTIMPL;
2257 return hr_return;
2258 }
2259
2260 static HRESULT WINAPI FoundCapabilities(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pcaps)
2261 {
2262 HRESULT hr;
2263 DWORD caps = 0;
2264
2265 hr = IMediaSeeking_GetCapabilities(seek, &caps);
2266 if (FAILED(hr))
2267 return hr;
2268
2269 /* Only add common capabilities everything supports */
2270 *(DWORD*)pcaps &= caps;
2271
2272 return hr;
2273 }
2274
2275 /*** IMediaSeeking methods ***/
2276 static HRESULT WINAPI MediaSeeking_GetCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2277 {
2278 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2279 HRESULT hr;
2280
2281 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2282
2283 if (!pCapabilities)
2284 return E_POINTER;
2285
2286 EnterCriticalSection(&This->cs);
2287 *pCapabilities = 0xffffffff;
2288
2289 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2290 LeaveCriticalSection(&This->cs);
2291
2292 return hr;
2293 }
2294
2295 static HRESULT WINAPI MediaSeeking_CheckCapabilities(IMediaSeeking *iface, DWORD *pCapabilities)
2296 {
2297 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2298 DWORD originalcaps;
2299 HRESULT hr;
2300
2301 TRACE("(%p/%p)->(%p)\n", This, iface, pCapabilities);
2302
2303 if (!pCapabilities)
2304 return E_POINTER;
2305
2306 EnterCriticalSection(&This->cs);
2307 originalcaps = *pCapabilities;
2308 hr = all_renderers_seek(This, FoundCapabilities, (DWORD_PTR)pCapabilities);
2309 LeaveCriticalSection(&This->cs);
2310
2311 if (FAILED(hr))
2312 return hr;
2313
2314 if (!*pCapabilities)
2315 return E_FAIL;
2316 if (*pCapabilities != originalcaps)
2317 return S_FALSE;
2318 return S_OK;
2319 }
2320
2321 static HRESULT WINAPI MediaSeeking_IsFormatSupported(IMediaSeeking *iface, const GUID *pFormat)
2322 {
2323 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2324
2325 if (!pFormat)
2326 return E_POINTER;
2327
2328 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2329
2330 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2331 {
2332 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2333 return S_FALSE;
2334 }
2335
2336 return S_OK;
2337 }
2338
2339 static HRESULT WINAPI MediaSeeking_QueryPreferredFormat(IMediaSeeking *iface, GUID *pFormat)
2340 {
2341 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2342
2343 if (!pFormat)
2344 return E_POINTER;
2345
2346 FIXME("(%p/%p)->(%p): semi-stub !!!\n", This, iface, pFormat);
2347 memcpy(pFormat, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
2348
2349 return S_OK;
2350 }
2351
2352 static HRESULT WINAPI MediaSeeking_GetTimeFormat(IMediaSeeking *iface, GUID *pFormat)
2353 {
2354 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2355
2356 if (!pFormat)
2357 return E_POINTER;
2358
2359 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2360 memcpy(pFormat, &This->timeformatseek, sizeof(GUID));
2361
2362 return S_OK;
2363 }
2364
2365 static HRESULT WINAPI MediaSeeking_IsUsingTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2366 {
2367 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2368
2369 TRACE("(%p/%p)->(%p)\n", This, iface, pFormat);
2370 if (!pFormat)
2371 return E_POINTER;
2372
2373 if (memcmp(pFormat, &This->timeformatseek, sizeof(GUID)))
2374 return S_FALSE;
2375
2376 return S_OK;
2377 }
2378
2379 static HRESULT WINAPI MediaSeeking_SetTimeFormat(IMediaSeeking *iface, const GUID *pFormat)
2380 {
2381 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2382
2383 if (!pFormat)
2384 return E_POINTER;
2385
2386 TRACE("(%p/%p)->(%s)\n", This, iface, debugstr_guid(pFormat));
2387
2388 if (This->state != State_Stopped)
2389 return VFW_E_WRONG_STATE;
2390
2391 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, pFormat))
2392 {
2393 FIXME("Unhandled time format %s\n", debugstr_guid(pFormat));
2394 return E_INVALIDARG;
2395 }
2396
2397 return S_OK;
2398 }
2399
2400 static HRESULT WINAPI FoundDuration(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pduration)
2401 {
2402 HRESULT hr;
2403 LONGLONG duration = 0, *pdur = (LONGLONG*)pduration;
2404
2405 hr = IMediaSeeking_GetDuration(seek, &duration);
2406 if (FAILED(hr))
2407 return hr;
2408
2409 if (*pdur < duration)
2410 *pdur = duration;
2411 return hr;
2412 }
2413
2414 static HRESULT WINAPI MediaSeeking_GetDuration(IMediaSeeking *iface, LONGLONG *pDuration)
2415 {
2416 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2417 HRESULT hr;
2418
2419 TRACE("(%p/%p)->(%p)\n", This, iface, pDuration);
2420
2421 if (!pDuration)
2422 return E_POINTER;
2423
2424 EnterCriticalSection(&This->cs);
2425 *pDuration = 0;
2426 hr = all_renderers_seek(This, FoundDuration, (DWORD_PTR)pDuration);
2427 LeaveCriticalSection(&This->cs);
2428
2429 TRACE("--->%08x\n", hr);
2430 return hr;
2431 }
2432
2433 static HRESULT WINAPI MediaSeeking_GetStopPosition(IMediaSeeking *iface, LONGLONG *pStop)
2434 {
2435 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2436 HRESULT hr = S_OK;
2437
2438 TRACE("(%p/%p)->(%p)\n", This, iface, pStop);
2439
2440 if (!pStop)
2441 return E_POINTER;
2442
2443 EnterCriticalSection(&This->cs);
2444 if (This->stop_position < 0)
2445 /* Stop position not set, use duration instead */
2446 hr = IMediaSeeking_GetDuration(iface, pStop);
2447 else
2448 *pStop = This->stop_position;
2449 LeaveCriticalSection(&This->cs);
2450
2451 return hr;
2452 }
2453
2454 static HRESULT WINAPI MediaSeeking_GetCurrentPosition(IMediaSeeking *iface, LONGLONG *pCurrent)
2455 {
2456 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2457 LONGLONG time = 0;
2458
2459 if (!pCurrent)
2460 return E_POINTER;
2461
2462 EnterCriticalSection(&This->cs);
2463 if (This->state == State_Running && This->refClock && This->start_time >= 0)
2464 {
2465 IReferenceClock_GetTime(This->refClock, &time);
2466 if (time)
2467 time -= This->start_time;
2468 }
2469 if (This->pause_time > 0)
2470 time += This->pause_time;
2471 *pCurrent = time;
2472 LeaveCriticalSection(&This->cs);
2473
2474 TRACE("Time: %u.%03u\n", (DWORD)(*pCurrent / 10000000), (DWORD)((*pCurrent / 10000)%1000));
2475
2476 return S_OK;
2477 }
2478
2479 static HRESULT WINAPI MediaSeeking_ConvertTimeFormat(IMediaSeeking *iface, LONGLONG *pTarget,
2480 const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat)
2481 {
2482 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2483
2484 FIXME("(%p/%p)->(%p, %p, 0x%s, %p): stub !!!\n", This, iface, pTarget,
2485 pTargetFormat, wine_dbgstr_longlong(Source), pSourceFormat);
2486
2487 return S_OK;
2488 }
2489
2490 struct pos_args {
2491 LONGLONG* current, *stop;
2492 DWORD curflags, stopflags;
2493 };
2494
2495 static HRESULT WINAPI found_setposition(IFilterGraphImpl *This, IMediaSeeking *seek, DWORD_PTR pargs)
2496 {
2497 struct pos_args *args = (void*)pargs;
2498
2499 return IMediaSeeking_SetPositions(seek, args->current, args->curflags, args->stop, args->stopflags);
2500 }
2501
2502 static HRESULT WINAPI MediaSeeking_SetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2503 DWORD dwCurrentFlags, LONGLONG *pStop, DWORD dwStopFlags)
2504 {
2505 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2506 HRESULT hr = S_OK;
2507 FILTER_STATE state;
2508 struct pos_args args;
2509
2510 TRACE("(%p/%p)->(%p, %08x, %p, %08x)\n", This, iface, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
2511
2512 EnterCriticalSection(&This->cs);
2513 state = This->state;
2514 TRACE("State: %s\n", state == State_Running ? "Running" : (state == State_Paused ? "Paused" : (state == State_Stopped ? "Stopped" : "UNKNOWN")));
2515
2516 if ((dwCurrentFlags & 0x7) != AM_SEEKING_AbsolutePositioning &&
2517 (dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2518 FIXME("Adjust method %x not handled yet!\n", dwCurrentFlags & 0x7);
2519
2520 if ((dwStopFlags & 0x7) == AM_SEEKING_AbsolutePositioning)
2521 This->stop_position = *pStop;
2522 else if ((dwStopFlags & 0x7) != AM_SEEKING_NoPositioning)
2523 FIXME("Stop position not handled yet!\n");
2524
2525 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2526 IMediaControl_Pause(&This->IMediaControl_iface);
2527 args.current = pCurrent;
2528 args.stop = pStop;
2529 args.curflags = dwCurrentFlags;
2530 args.stopflags = dwStopFlags;
2531 hr = all_renderers_seek(This, found_setposition, (DWORD_PTR)&args);
2532
2533 if ((dwCurrentFlags & 0x7) != AM_SEEKING_NoPositioning)
2534 This->pause_time = This->start_time = -1;
2535 if (state == State_Running && !(dwCurrentFlags & AM_SEEKING_NoFlush))
2536 IMediaControl_Run(&This->IMediaControl_iface);
2537 LeaveCriticalSection(&This->cs);
2538
2539 return hr;
2540 }
2541
2542 static HRESULT WINAPI MediaSeeking_GetPositions(IMediaSeeking *iface, LONGLONG *pCurrent,
2543 LONGLONG *pStop)
2544 {
2545 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2546 HRESULT hr;
2547
2548 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pCurrent, pStop);
2549 hr = IMediaSeeking_GetCurrentPosition(iface, pCurrent);
2550 if (SUCCEEDED(hr))
2551 hr = IMediaSeeking_GetStopPosition(iface, pStop);
2552
2553 return hr;
2554 }
2555
2556 static HRESULT WINAPI MediaSeeking_GetAvailable(IMediaSeeking *iface, LONGLONG *pEarliest,
2557 LONGLONG *pLatest)
2558 {
2559 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2560
2561 FIXME("(%p/%p)->(%p, %p): stub !!!\n", This, iface, pEarliest, pLatest);
2562
2563 return S_OK;
2564 }
2565
2566 static HRESULT WINAPI MediaSeeking_SetRate(IMediaSeeking *iface, double dRate)
2567 {
2568 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2569
2570 FIXME("(%p/%p)->(%f): stub !!!\n", This, iface, dRate);
2571
2572 return S_OK;
2573 }
2574
2575 static HRESULT WINAPI MediaSeeking_GetRate(IMediaSeeking *iface, double *pdRate)
2576 {
2577 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2578
2579 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pdRate);
2580
2581 return S_OK;
2582 }
2583
2584 static HRESULT WINAPI MediaSeeking_GetPreroll(IMediaSeeking *iface, LONGLONG *pllPreroll)
2585 {
2586 IFilterGraphImpl *This = impl_from_IMediaSeeking(iface);
2587
2588 FIXME("(%p/%p)->(%p): stub !!!\n", This, iface, pllPreroll);
2589
2590 return S_OK;
2591 }
2592
2593
2594 static const IMediaSeekingVtbl IMediaSeeking_VTable =
2595 {
2596 MediaSeeking_QueryInterface,
2597 MediaSeeking_AddRef,
2598 MediaSeeking_Release,
2599 MediaSeeking_GetCapabilities,
2600 MediaSeeking_CheckCapabilities,
2601 MediaSeeking_IsFormatSupported,
2602 MediaSeeking_QueryPreferredFormat,
2603 MediaSeeking_GetTimeFormat,
2604 MediaSeeking_IsUsingTimeFormat,
2605 MediaSeeking_SetTimeFormat,
2606 MediaSeeking_GetDuration,
2607 MediaSeeking_GetStopPosition,
2608 MediaSeeking_GetCurrentPosition,
2609 MediaSeeking_ConvertTimeFormat,
2610 MediaSeeking_SetPositions,
2611 MediaSeeking_GetPositions,
2612 MediaSeeking_GetAvailable,
2613 MediaSeeking_SetRate,
2614 MediaSeeking_GetRate,
2615 MediaSeeking_GetPreroll
2616 };
2617
2618 static inline IFilterGraphImpl *impl_from_IMediaPosition(IMediaPosition *iface)
2619 {
2620 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaPosition_iface);
2621 }
2622
2623 /*** IUnknown methods ***/
2624 static HRESULT WINAPI MediaPosition_QueryInterface(IMediaPosition* iface, REFIID riid, void** ppvObj)
2625 {
2626 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2627
2628 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2629
2630 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2631 }
2632
2633 static ULONG WINAPI MediaPosition_AddRef(IMediaPosition *iface)
2634 {
2635 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2636
2637 TRACE("(%p/%p)->()\n", This, iface);
2638
2639 return IUnknown_AddRef(This->outer_unk);
2640 }
2641
2642 static ULONG WINAPI MediaPosition_Release(IMediaPosition *iface)
2643 {
2644 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2645
2646 TRACE("(%p/%p)->()\n", This, iface);
2647
2648 return IUnknown_Release(This->outer_unk);
2649 }
2650
2651 /*** IDispatch methods ***/
2652 static HRESULT WINAPI MediaPosition_GetTypeInfoCount(IMediaPosition *iface, UINT* pctinfo)
2653 {
2654 FIXME("(%p) stub!\n", iface);
2655 return E_NOTIMPL;
2656 }
2657
2658 static HRESULT WINAPI MediaPosition_GetTypeInfo(IMediaPosition *iface, UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
2659 {
2660 FIXME("(%p) stub!\n", iface);
2661 return E_NOTIMPL;
2662 }
2663
2664 static HRESULT WINAPI MediaPosition_GetIDsOfNames(IMediaPosition* iface, REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
2665 {
2666 FIXME("(%p) stub!\n", iface);
2667 return E_NOTIMPL;
2668 }
2669
2670 static HRESULT WINAPI MediaPosition_Invoke(IMediaPosition* iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
2671 {
2672 FIXME("(%p) stub!\n", iface);
2673 return E_NOTIMPL;
2674 }
2675
2676 static HRESULT ConvertFromREFTIME(IMediaSeeking *seek, REFTIME time_in, LONGLONG *time_out)
2677 {
2678 GUID time_format;
2679 HRESULT hr;
2680
2681 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2682 if (FAILED(hr))
2683 return hr;
2684 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2685 {
2686 FIXME("Unsupported time format.\n");
2687 return E_NOTIMPL;
2688 }
2689
2690 *time_out = (LONGLONG) (time_in * 10000000); /* convert from 1 second intervals to 100 ns intervals */
2691 return S_OK;
2692 }
2693
2694 static HRESULT ConvertToREFTIME(IMediaSeeking *seek, LONGLONG time_in, REFTIME *time_out)
2695 {
2696 GUID time_format;
2697 HRESULT hr;
2698
2699 hr = MediaSeeking_GetTimeFormat(seek, &time_format);
2700 if (FAILED(hr))
2701 return hr;
2702 if (!IsEqualGUID(&TIME_FORMAT_MEDIA_TIME, &time_format))
2703 {
2704 FIXME("Unsupported time format.\n");
2705 return E_NOTIMPL;
2706 }
2707
2708 *time_out = (REFTIME)time_in / 10000000; /* convert from 100 ns intervals to 1 second intervals */
2709 return S_OK;
2710 }
2711
2712 /*** IMediaPosition methods ***/
2713 static HRESULT WINAPI MediaPosition_get_Duration(IMediaPosition * iface, REFTIME *plength)
2714 {
2715 LONGLONG duration;
2716 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2717 HRESULT hr = IMediaSeeking_GetDuration(&This->IMediaSeeking_iface, &duration);
2718 if (FAILED(hr))
2719 return hr;
2720 return ConvertToREFTIME(&This->IMediaSeeking_iface, duration, plength);
2721 }
2722
2723 static HRESULT WINAPI MediaPosition_put_CurrentPosition(IMediaPosition * iface, REFTIME llTime)
2724 {
2725 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2726 LONGLONG reftime;
2727 HRESULT hr;
2728
2729 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2730 if (FAILED(hr))
2731 return hr;
2732 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, &reftime,
2733 AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
2734 }
2735
2736 static HRESULT WINAPI MediaPosition_get_CurrentPosition(IMediaPosition * iface, REFTIME *pllTime)
2737 {
2738 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2739 LONGLONG pos;
2740 HRESULT hr;
2741
2742 hr = IMediaSeeking_GetCurrentPosition(&This->IMediaSeeking_iface, &pos);
2743 if (FAILED(hr))
2744 return hr;
2745 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2746 }
2747
2748 static HRESULT WINAPI MediaPosition_get_StopTime(IMediaPosition * iface, REFTIME *pllTime)
2749 {
2750 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2751 LONGLONG pos;
2752 HRESULT hr = IMediaSeeking_GetStopPosition(&This->IMediaSeeking_iface, &pos);
2753 if (FAILED(hr))
2754 return hr;
2755 return ConvertToREFTIME(&This->IMediaSeeking_iface, pos, pllTime);
2756 }
2757
2758 static HRESULT WINAPI MediaPosition_put_StopTime(IMediaPosition * iface, REFTIME llTime)
2759 {
2760 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2761 LONGLONG reftime;
2762 HRESULT hr;
2763
2764 hr = ConvertFromREFTIME(&This->IMediaSeeking_iface, llTime, &reftime);
2765 if (FAILED(hr))
2766 return hr;
2767 return IMediaSeeking_SetPositions(&This->IMediaSeeking_iface, NULL, AM_SEEKING_NoPositioning,
2768 &reftime, AM_SEEKING_AbsolutePositioning);
2769 }
2770
2771 static HRESULT WINAPI MediaPosition_get_PrerollTime(IMediaPosition * iface, REFTIME *pllTime)
2772 {
2773 FIXME("(%p)->(%p) stub!\n", iface, pllTime);
2774 return E_NOTIMPL;
2775 }
2776
2777 static HRESULT WINAPI MediaPosition_put_PrerollTime(IMediaPosition * iface, REFTIME llTime)
2778 {
2779 FIXME("(%p)->(%f) stub!\n", iface, llTime);
2780 return E_NOTIMPL;
2781 }
2782
2783 static HRESULT WINAPI MediaPosition_put_Rate(IMediaPosition * iface, double dRate)
2784 {
2785 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2786 return IMediaSeeking_SetRate(&This->IMediaSeeking_iface, dRate);
2787 }
2788
2789 static HRESULT WINAPI MediaPosition_get_Rate(IMediaPosition * iface, double *pdRate)
2790 {
2791 IFilterGraphImpl *This = impl_from_IMediaPosition( iface );
2792 return IMediaSeeking_GetRate(&This->IMediaSeeking_iface, pdRate);
2793 }
2794
2795 static HRESULT WINAPI MediaPosition_CanSeekForward(IMediaPosition * iface, LONG *pCanSeekForward)
2796 {
2797 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekForward);
2798 return E_NOTIMPL;
2799 }
2800
2801 static HRESULT WINAPI MediaPosition_CanSeekBackward(IMediaPosition * iface, LONG *pCanSeekBackward)
2802 {
2803 FIXME("(%p)->(%p) stub!\n", iface, pCanSeekBackward);
2804 return E_NOTIMPL;
2805 }
2806
2807
2808 static const IMediaPositionVtbl IMediaPosition_VTable =
2809 {
2810 MediaPosition_QueryInterface,
2811 MediaPosition_AddRef,
2812 MediaPosition_Release,
2813 MediaPosition_GetTypeInfoCount,
2814 MediaPosition_GetTypeInfo,
2815 MediaPosition_GetIDsOfNames,
2816 MediaPosition_Invoke,
2817 MediaPosition_get_Duration,
2818 MediaPosition_put_CurrentPosition,
2819 MediaPosition_get_CurrentPosition,
2820 MediaPosition_get_StopTime,
2821 MediaPosition_put_StopTime,
2822 MediaPosition_get_PrerollTime,
2823 MediaPosition_put_PrerollTime,
2824 MediaPosition_put_Rate,
2825 MediaPosition_get_Rate,
2826 MediaPosition_CanSeekForward,
2827 MediaPosition_CanSeekBackward
2828 };
2829
2830 static inline IFilterGraphImpl *impl_from_IObjectWithSite(IObjectWithSite *iface)
2831 {
2832 return CONTAINING_RECORD(iface, IFilterGraphImpl, IObjectWithSite_iface);
2833 }
2834
2835 /*** IUnknown methods ***/
2836 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite* iface, REFIID riid, void** ppvObj)
2837 {
2838 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2839
2840 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2841
2842 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2843 }
2844
2845 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
2846 {
2847 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2848
2849 TRACE("(%p/%p)->()\n", This, iface);
2850
2851 return IUnknown_AddRef(This->outer_unk);
2852 }
2853
2854 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
2855 {
2856 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2857
2858 TRACE("(%p/%p)->()\n", This, iface);
2859
2860 return IUnknown_Release(This->outer_unk);
2861 }
2862
2863 /*** IObjectWithSite methods ***/
2864
2865 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
2866 {
2867 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2868
2869 TRACE("(%p/%p)->()\n", This, iface);
2870 if (This->pSite) IUnknown_Release(This->pSite);
2871 This->pSite = pUnkSite;
2872 IUnknown_AddRef(This->pSite);
2873 return S_OK;
2874 }
2875
2876 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, PVOID *ppvSite)
2877 {
2878 IFilterGraphImpl *This = impl_from_IObjectWithSite( iface );
2879
2880 TRACE("(%p/%p)->(%s)\n", This, iface,debugstr_guid(riid));
2881
2882 *ppvSite = NULL;
2883 if (!This->pSite)
2884 return E_FAIL;
2885 else
2886 return IUnknown_QueryInterface(This->pSite, riid, ppvSite);
2887 }
2888
2889 static const IObjectWithSiteVtbl IObjectWithSite_VTable =
2890 {
2891 ObjectWithSite_QueryInterface,
2892 ObjectWithSite_AddRef,
2893 ObjectWithSite_Release,
2894 ObjectWithSite_SetSite,
2895 ObjectWithSite_GetSite,
2896 };
2897
2898 static HRESULT GetTargetInterface(IFilterGraphImpl* pGraph, REFIID riid, LPVOID* ppvObj)
2899 {
2900 HRESULT hr = E_NOINTERFACE;
2901 int i;
2902 int entry;
2903
2904 /* Check if the interface type is already registered */
2905 for (entry = 0; entry < pGraph->nItfCacheEntries; entry++)
2906 if (riid == pGraph->ItfCacheEntries[entry].riid)
2907 {
2908 if (pGraph->ItfCacheEntries[entry].iface)
2909 {
2910 /* Return the interface if available */
2911 *ppvObj = pGraph->ItfCacheEntries[entry].iface;
2912 return S_OK;
2913 }
2914 break;
2915 }
2916
2917 if (entry >= MAX_ITF_CACHE_ENTRIES)
2918 {
2919 FIXME("Not enough space to store interface in the cache\n");
2920 return E_OUTOFMEMORY;
2921 }
2922
2923 /* Find a filter supporting the requested interface */
2924 for (i = 0; i < pGraph->nFilters; i++)
2925 {
2926 hr = IBaseFilter_QueryInterface(pGraph->ppFiltersInGraph[i], riid, ppvObj);
2927 if (hr == S_OK)
2928 {
2929 pGraph->ItfCacheEntries[entry].riid = riid;
2930 pGraph->ItfCacheEntries[entry].filter = pGraph->ppFiltersInGraph[i];
2931 pGraph->ItfCacheEntries[entry].iface = *ppvObj;
2932 if (entry >= pGraph->nItfCacheEntries)
2933 pGraph->nItfCacheEntries++;
2934 return S_OK;
2935 }
2936 if (hr != E_NOINTERFACE)
2937 return hr;
2938 }
2939
2940 return hr;
2941 }
2942
2943 static inline IFilterGraphImpl *impl_from_IBasicAudio(IBasicAudio *iface)
2944 {
2945 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicAudio_iface);
2946 }
2947
2948 static HRESULT WINAPI BasicAudio_QueryInterface(IBasicAudio *iface, REFIID riid, void **ppvObj)
2949 {
2950 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2951
2952 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
2953
2954 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
2955 }
2956
2957 static ULONG WINAPI BasicAudio_AddRef(IBasicAudio *iface)
2958 {
2959 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2960
2961 TRACE("(%p/%p)->()\n", This, iface);
2962
2963 return IUnknown_AddRef(This->outer_unk);
2964 }
2965
2966 static ULONG WINAPI BasicAudio_Release(IBasicAudio *iface)
2967 {
2968 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2969
2970 TRACE("(%p/%p)->()\n", This, iface);
2971
2972 return IUnknown_Release(This->outer_unk);
2973 }
2974
2975 /*** IDispatch methods ***/
2976 static HRESULT WINAPI BasicAudio_GetTypeInfoCount(IBasicAudio *iface, UINT *pctinfo)
2977 {
2978 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
2979 IBasicAudio* pBasicAudio;
2980 HRESULT hr;
2981
2982 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
2983
2984 EnterCriticalSection(&This->cs);
2985
2986 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
2987
2988 if (hr == S_OK)
2989 hr = IBasicAudio_GetTypeInfoCount(pBasicAudio, pctinfo);
2990
2991 LeaveCriticalSection(&This->cs);
2992
2993 return hr;
2994 }
2995
2996 static HRESULT WINAPI BasicAudio_GetTypeInfo(IBasicAudio *iface, UINT iTInfo, LCID lcid,
2997 ITypeInfo **ppTInfo)
2998 {
2999 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3000 IBasicAudio* pBasicAudio;
3001 HRESULT hr;
3002
3003 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3004
3005 EnterCriticalSection(&This->cs);
3006
3007 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3008
3009 if (hr == S_OK)
3010 hr = IBasicAudio_GetTypeInfo(pBasicAudio, iTInfo, lcid, ppTInfo);
3011
3012 LeaveCriticalSection(&This->cs);
3013
3014 return hr;
3015 }
3016
3017 static HRESULT WINAPI BasicAudio_GetIDsOfNames(IBasicAudio *iface, REFIID riid, LPOLESTR *rgszNames,
3018 UINT cNames, LCID lcid, DISPID *rgDispId)
3019 {
3020 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3021 IBasicAudio* pBasicAudio;
3022 HRESULT hr;
3023
3024 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3025
3026 EnterCriticalSection(&This->cs);
3027
3028 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3029
3030 if (hr == S_OK)
3031 hr = IBasicAudio_GetIDsOfNames(pBasicAudio, riid, rgszNames, cNames, lcid, rgDispId);
3032
3033 LeaveCriticalSection(&This->cs);
3034
3035 return hr;
3036 }
3037
3038 static HRESULT WINAPI BasicAudio_Invoke(IBasicAudio *iface, DISPID dispIdMember, REFIID riid,
3039 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3040 UINT *puArgErr)
3041 {
3042 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3043 IBasicAudio* pBasicAudio;
3044 HRESULT hr;
3045
3046 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3047
3048 EnterCriticalSection(&This->cs);
3049
3050 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3051
3052 if (hr == S_OK)
3053 hr = IBasicAudio_Invoke(pBasicAudio, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3054
3055 LeaveCriticalSection(&This->cs);
3056
3057 return hr;
3058 }
3059
3060 /*** IBasicAudio methods ***/
3061 static HRESULT WINAPI BasicAudio_put_Volume(IBasicAudio *iface, LONG lVolume)
3062 {
3063 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3064 IBasicAudio* pBasicAudio;
3065 HRESULT hr;
3066
3067 TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
3068
3069 EnterCriticalSection(&This->cs);
3070
3071 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3072
3073 if (hr == S_OK)
3074 hr = IBasicAudio_put_Volume(pBasicAudio, lVolume);
3075
3076 LeaveCriticalSection(&This->cs);
3077
3078 return hr;
3079 }
3080
3081 static HRESULT WINAPI BasicAudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
3082 {
3083 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3084 IBasicAudio* pBasicAudio;
3085 HRESULT hr;
3086
3087 TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
3088
3089 EnterCriticalSection(&This->cs);
3090
3091 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3092
3093 if (hr == S_OK)
3094 hr = IBasicAudio_get_Volume(pBasicAudio, plVolume);
3095
3096 LeaveCriticalSection(&This->cs);
3097
3098 return hr;
3099 }
3100
3101 static HRESULT WINAPI BasicAudio_put_Balance(IBasicAudio *iface, LONG lBalance)
3102 {
3103 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3104 IBasicAudio* pBasicAudio;
3105 HRESULT hr;
3106
3107 TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
3108
3109 EnterCriticalSection(&This->cs);
3110
3111 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3112
3113 if (hr == S_OK)
3114 hr = IBasicAudio_put_Balance(pBasicAudio, lBalance);
3115
3116 LeaveCriticalSection(&This->cs);
3117
3118 return hr;
3119 }
3120
3121 static HRESULT WINAPI BasicAudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
3122 {
3123 IFilterGraphImpl *This = impl_from_IBasicAudio(iface);
3124 IBasicAudio* pBasicAudio;
3125 HRESULT hr;
3126
3127 TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
3128
3129 EnterCriticalSection(&This->cs);
3130
3131 hr = GetTargetInterface(This, &IID_IBasicAudio, (LPVOID*)&pBasicAudio);
3132
3133 if (hr == S_OK)
3134 hr = IBasicAudio_get_Balance(pBasicAudio, plBalance);
3135
3136 LeaveCriticalSection(&This->cs);
3137
3138 return hr;
3139 }
3140
3141 static const IBasicAudioVtbl IBasicAudio_VTable =
3142 {
3143 BasicAudio_QueryInterface,
3144 BasicAudio_AddRef,
3145 BasicAudio_Release,
3146 BasicAudio_GetTypeInfoCount,
3147 BasicAudio_GetTypeInfo,
3148 BasicAudio_GetIDsOfNames,
3149 BasicAudio_Invoke,
3150 BasicAudio_put_Volume,
3151 BasicAudio_get_Volume,
3152 BasicAudio_put_Balance,
3153 BasicAudio_get_Balance
3154 };
3155
3156 static inline IFilterGraphImpl *impl_from_IBasicVideo2(IBasicVideo2 *iface)
3157 {
3158 return CONTAINING_RECORD(iface, IFilterGraphImpl, IBasicVideo2_iface);
3159 }
3160
3161 static HRESULT WINAPI BasicVideo_QueryInterface(IBasicVideo2 *iface, REFIID riid, void **ppvObj)
3162 {
3163 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3164
3165 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3166
3167 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3168 }
3169
3170 static ULONG WINAPI BasicVideo_AddRef(IBasicVideo2 *iface)
3171 {
3172 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3173
3174 TRACE("(%p/%p)->()\n", This, iface);
3175
3176 return IUnknown_AddRef(This->outer_unk);
3177 }
3178
3179 static ULONG WINAPI BasicVideo_Release(IBasicVideo2 *iface)
3180 {
3181 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3182
3183 TRACE("(%p/%p)->()\n", This, iface);
3184
3185 return IUnknown_Release(This->outer_unk);
3186 }
3187
3188 /*** IDispatch methods ***/
3189 static HRESULT WINAPI BasicVideo_GetTypeInfoCount(IBasicVideo2 *iface, UINT *pctinfo)
3190 {
3191 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3192 IBasicVideo *pBasicVideo;
3193 HRESULT hr;
3194
3195 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
3196
3197 EnterCriticalSection(&This->cs);
3198
3199 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3200
3201 if (hr == S_OK)
3202 hr = IBasicVideo_GetTypeInfoCount(pBasicVideo, pctinfo);
3203
3204 LeaveCriticalSection(&This->cs);
3205
3206 return hr;
3207 }
3208
3209 static HRESULT WINAPI BasicVideo_GetTypeInfo(IBasicVideo2 *iface, UINT iTInfo, LCID lcid,
3210 ITypeInfo **ppTInfo)
3211 {
3212 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3213 IBasicVideo *pBasicVideo;
3214 HRESULT hr;
3215
3216 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
3217
3218 EnterCriticalSection(&This->cs);
3219
3220 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3221
3222 if (hr == S_OK)
3223 hr = IBasicVideo_GetTypeInfo(pBasicVideo, iTInfo, lcid, ppTInfo);
3224
3225 LeaveCriticalSection(&This->cs);
3226
3227 return hr;
3228 }
3229
3230 static HRESULT WINAPI BasicVideo_GetIDsOfNames(IBasicVideo2 *iface, REFIID riid,
3231 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
3232 {
3233 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3234 IBasicVideo *pBasicVideo;
3235 HRESULT hr;
3236
3237 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
3238
3239 EnterCriticalSection(&This->cs);
3240
3241 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3242
3243 if (hr == S_OK)
3244 hr = IBasicVideo_GetIDsOfNames(pBasicVideo, riid, rgszNames, cNames, lcid, rgDispId);
3245
3246 LeaveCriticalSection(&This->cs);
3247
3248 return hr;
3249 }
3250
3251 static HRESULT WINAPI BasicVideo_Invoke(IBasicVideo2 *iface, DISPID dispIdMember, REFIID riid,
3252 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
3253 UINT *puArgErr)
3254 {
3255 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3256 IBasicVideo *pBasicVideo;
3257 HRESULT hr;
3258
3259 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3260
3261 EnterCriticalSection(&This->cs);
3262
3263 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3264
3265 if (hr == S_OK)
3266 hr = IBasicVideo_Invoke(pBasicVideo, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
3267
3268 LeaveCriticalSection(&This->cs);
3269
3270 return hr;
3271 }
3272
3273 /*** IBasicVideo methods ***/
3274 static HRESULT WINAPI BasicVideo_get_AvgTimePerFrame(IBasicVideo2 *iface, REFTIME *pAvgTimePerFrame)
3275 {
3276 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3277 IBasicVideo *pBasicVideo;
3278 HRESULT hr;
3279
3280 TRACE("(%p/%p)->(%p)\n", This, iface, pAvgTimePerFrame);
3281
3282 EnterCriticalSection(&This->cs);
3283
3284 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3285
3286 if (hr == S_OK)
3287 hr = IBasicVideo_get_AvgTimePerFrame(pBasicVideo, pAvgTimePerFrame);
3288
3289 LeaveCriticalSection(&This->cs);
3290
3291 return hr;
3292 }
3293
3294 static HRESULT WINAPI BasicVideo_get_BitRate(IBasicVideo2 *iface, LONG *pBitRate)
3295 {
3296 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3297 IBasicVideo *pBasicVideo;
3298 HRESULT hr;
3299
3300 TRACE("(%p/%p)->(%p)\n", This, iface, pBitRate);
3301
3302 EnterCriticalSection(&This->cs);
3303
3304 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3305
3306 if (hr == S_OK)
3307 hr = IBasicVideo_get_BitRate(pBasicVideo, pBitRate);
3308
3309 LeaveCriticalSection(&This->cs);
3310
3311 return hr;
3312 }
3313
3314 static HRESULT WINAPI BasicVideo_get_BitErrorRate(IBasicVideo2 *iface, LONG *pBitErrorRate)
3315 {
3316 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3317 IBasicVideo *pBasicVideo;
3318 HRESULT hr;
3319
3320 TRACE("(%p/%p)->(%p)\n", This, iface, pBitErrorRate);
3321
3322 EnterCriticalSection(&This->cs);
3323
3324 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3325
3326 if (hr == S_OK)
3327 hr = IBasicVideo_get_BitErrorRate(pBasicVideo, pBitErrorRate);
3328
3329 LeaveCriticalSection(&This->cs);
3330
3331 return hr;
3332 }
3333
3334 static HRESULT WINAPI BasicVideo_get_VideoWidth(IBasicVideo2 *iface, LONG *pVideoWidth)
3335 {
3336 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3337 IBasicVideo *pBasicVideo;
3338 HRESULT hr;
3339
3340 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoWidth);
3341
3342 EnterCriticalSection(&This->cs);
3343
3344 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3345
3346 if (hr == S_OK)
3347 hr = IBasicVideo_get_VideoWidth(pBasicVideo, pVideoWidth);
3348
3349 LeaveCriticalSection(&This->cs);
3350
3351 return hr;
3352 }
3353
3354 static HRESULT WINAPI BasicVideo_get_VideoHeight(IBasicVideo2 *iface, LONG *pVideoHeight)
3355 {
3356 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3357 IBasicVideo *pBasicVideo;
3358 HRESULT hr;
3359
3360 TRACE("(%p/%p)->(%p)\n", This, iface, pVideoHeight);
3361
3362 EnterCriticalSection(&This->cs);
3363
3364 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3365
3366 if (hr == S_OK)
3367 hr = IBasicVideo_get_VideoHeight(pBasicVideo, pVideoHeight);
3368
3369 LeaveCriticalSection(&This->cs);
3370
3371 return hr;
3372 }
3373
3374 static HRESULT WINAPI BasicVideo_put_SourceLeft(IBasicVideo2 *iface, LONG SourceLeft)
3375 {
3376 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3377 IBasicVideo *pBasicVideo;
3378 HRESULT hr;
3379
3380 TRACE("(%p/%p)->(%d)\n", This, iface, SourceLeft);
3381
3382 EnterCriticalSection(&This->cs);
3383
3384 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3385
3386 if (hr == S_OK)
3387 hr = IBasicVideo_put_SourceLeft(pBasicVideo, SourceLeft);
3388
3389 LeaveCriticalSection(&This->cs);
3390
3391 return hr;
3392 }
3393
3394 static HRESULT WINAPI BasicVideo_get_SourceLeft(IBasicVideo2 *iface, LONG *pSourceLeft)
3395 {
3396 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3397 IBasicVideo *pBasicVideo;
3398 HRESULT hr;
3399
3400 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceLeft);
3401
3402 EnterCriticalSection(&This->cs);
3403
3404 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3405
3406 if (hr == S_OK)
3407 hr = IBasicVideo_get_SourceLeft(pBasicVideo, pSourceLeft);
3408
3409 LeaveCriticalSection(&This->cs);
3410
3411 return hr;
3412 }
3413
3414 static HRESULT WINAPI BasicVideo_put_SourceWidth(IBasicVideo2 *iface, LONG SourceWidth)
3415 {
3416 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3417 IBasicVideo *pBasicVideo;
3418 HRESULT hr;
3419
3420 TRACE("(%p/%p)->(%d)\n", This, iface, SourceWidth);
3421
3422 EnterCriticalSection(&This->cs);
3423
3424 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3425
3426 if (hr == S_OK)
3427 hr = IBasicVideo_put_SourceWidth(pBasicVideo, SourceWidth);
3428
3429 LeaveCriticalSection(&This->cs);
3430
3431 return hr;
3432 }
3433
3434 static HRESULT WINAPI BasicVideo_get_SourceWidth(IBasicVideo2 *iface, LONG *pSourceWidth)
3435 {
3436 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3437 IBasicVideo *pBasicVideo;
3438 HRESULT hr;
3439
3440 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceWidth);
3441
3442 EnterCriticalSection(&This->cs);
3443
3444 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3445
3446 if (hr == S_OK)
3447 hr = IBasicVideo_get_SourceWidth(pBasicVideo, pSourceWidth);
3448
3449 LeaveCriticalSection(&This->cs);
3450
3451 return hr;
3452 }
3453
3454 static HRESULT WINAPI BasicVideo_put_SourceTop(IBasicVideo2 *iface, LONG SourceTop)
3455 {
3456 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3457 IBasicVideo *pBasicVideo;
3458 HRESULT hr;
3459
3460 TRACE("(%p/%p)->(%d)\n", This, iface, SourceTop);
3461
3462 EnterCriticalSection(&This->cs);
3463
3464 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3465
3466 if (hr == S_OK)
3467 hr = IBasicVideo_put_SourceTop(pBasicVideo, SourceTop);
3468
3469 LeaveCriticalSection(&This->cs);
3470
3471 return hr;
3472 }
3473
3474 static HRESULT WINAPI BasicVideo_get_SourceTop(IBasicVideo2 *iface, LONG *pSourceTop)
3475 {
3476 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3477 IBasicVideo *pBasicVideo;
3478 HRESULT hr;
3479
3480 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceTop);
3481
3482 EnterCriticalSection(&This->cs);
3483
3484 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3485
3486 if (hr == S_OK)
3487 hr = IBasicVideo_get_SourceTop(pBasicVideo, pSourceTop);
3488
3489 LeaveCriticalSection(&This->cs);
3490
3491 return hr;
3492 }
3493
3494 static HRESULT WINAPI BasicVideo_put_SourceHeight(IBasicVideo2 *iface, LONG SourceHeight)
3495 {
3496 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3497 IBasicVideo *pBasicVideo;
3498 HRESULT hr;
3499
3500 TRACE("(%p/%p)->(%d)\n", This, iface, SourceHeight);
3501
3502 EnterCriticalSection(&This->cs);
3503
3504 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3505
3506 if (hr == S_OK)
3507 hr = IBasicVideo_put_SourceHeight(pBasicVideo, SourceHeight);
3508
3509 LeaveCriticalSection(&This->cs);
3510
3511 return hr;
3512 }
3513
3514 static HRESULT WINAPI BasicVideo_get_SourceHeight(IBasicVideo2 *iface, LONG *pSourceHeight)
3515 {
3516 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3517 IBasicVideo *pBasicVideo;
3518 HRESULT hr;
3519
3520 TRACE("(%p/%p)->(%p)\n", This, iface, pSourceHeight);
3521
3522 EnterCriticalSection(&This->cs);
3523
3524 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3525
3526 if (hr == S_OK)
3527 hr = IBasicVideo_get_SourceHeight(pBasicVideo, pSourceHeight);
3528
3529 LeaveCriticalSection(&This->cs);
3530
3531 return hr;
3532 }
3533
3534 static HRESULT WINAPI BasicVideo_put_DestinationLeft(IBasicVideo2 *iface, LONG DestinationLeft)
3535 {
3536 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3537 IBasicVideo *pBasicVideo;
3538 HRESULT hr;
3539
3540 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationLeft);
3541
3542 EnterCriticalSection(&This->cs);
3543
3544 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3545
3546 if (hr == S_OK)
3547 hr = IBasicVideo_put_DestinationLeft(pBasicVideo, DestinationLeft);
3548
3549 LeaveCriticalSection(&This->cs);
3550
3551 return hr;
3552 }
3553
3554 static HRESULT WINAPI BasicVideo_get_DestinationLeft(IBasicVideo2 *iface, LONG *pDestinationLeft)
3555 {
3556 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3557 IBasicVideo *pBasicVideo;
3558 HRESULT hr;
3559
3560 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationLeft);
3561
3562 EnterCriticalSection(&This->cs);
3563
3564 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3565
3566 if (hr == S_OK)
3567 hr = IBasicVideo_get_DestinationLeft(pBasicVideo, pDestinationLeft);
3568
3569 LeaveCriticalSection(&This->cs);
3570
3571 return hr;
3572 }
3573
3574 static HRESULT WINAPI BasicVideo_put_DestinationWidth(IBasicVideo2 *iface, LONG DestinationWidth)
3575 {
3576 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3577 IBasicVideo *pBasicVideo;
3578 HRESULT hr;
3579
3580 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationWidth);
3581
3582 EnterCriticalSection(&This->cs);
3583
3584 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3585
3586 if (hr == S_OK)
3587 hr = IBasicVideo_put_DestinationWidth(pBasicVideo, DestinationWidth);
3588
3589 LeaveCriticalSection(&This->cs);
3590
3591 return hr;
3592 }
3593
3594 static HRESULT WINAPI BasicVideo_get_DestinationWidth(IBasicVideo2 *iface, LONG *pDestinationWidth)
3595 {
3596 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3597 IBasicVideo *pBasicVideo;
3598 HRESULT hr;
3599
3600 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationWidth);
3601
3602 EnterCriticalSection(&This->cs);
3603
3604 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3605
3606 if (hr == S_OK)
3607 hr = IBasicVideo_get_DestinationWidth(pBasicVideo, pDestinationWidth);
3608
3609 LeaveCriticalSection(&This->cs);
3610
3611 return hr;
3612 }
3613
3614 static HRESULT WINAPI BasicVideo_put_DestinationTop(IBasicVideo2 *iface, LONG DestinationTop)
3615 {
3616 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3617 IBasicVideo *pBasicVideo;
3618 HRESULT hr;
3619
3620 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationTop);
3621
3622 EnterCriticalSection(&This->cs);
3623
3624 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3625
3626 if (hr == S_OK)
3627 hr = IBasicVideo_put_DestinationTop(pBasicVideo, DestinationTop);
3628
3629 LeaveCriticalSection(&This->cs);
3630
3631 return hr;
3632 }
3633
3634 static HRESULT WINAPI BasicVideo_get_DestinationTop(IBasicVideo2 *iface, LONG *pDestinationTop)
3635 {
3636 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3637 IBasicVideo *pBasicVideo;
3638 HRESULT hr;
3639
3640 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationTop);
3641
3642 EnterCriticalSection(&This->cs);
3643
3644 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3645
3646 if (hr == S_OK)
3647 hr = IBasicVideo_get_DestinationTop(pBasicVideo, pDestinationTop);
3648
3649 LeaveCriticalSection(&This->cs);
3650
3651 return hr;
3652 }
3653
3654 static HRESULT WINAPI BasicVideo_put_DestinationHeight(IBasicVideo2 *iface, LONG DestinationHeight)
3655 {
3656 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3657 IBasicVideo *pBasicVideo;
3658 HRESULT hr;
3659
3660 TRACE("(%p/%p)->(%d)\n", This, iface, DestinationHeight);
3661
3662 EnterCriticalSection(&This->cs);
3663
3664 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3665
3666 if (hr == S_OK)
3667 hr = IBasicVideo_put_DestinationHeight(pBasicVideo, DestinationHeight);
3668
3669 LeaveCriticalSection(&This->cs);
3670
3671 return hr;
3672 }
3673
3674 static HRESULT WINAPI BasicVideo_get_DestinationHeight(IBasicVideo2 *iface,
3675 LONG *pDestinationHeight)
3676 {
3677 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3678 IBasicVideo *pBasicVideo;
3679 HRESULT hr;
3680
3681 TRACE("(%p/%p)->(%p)\n", This, iface, pDestinationHeight);
3682
3683 EnterCriticalSection(&This->cs);
3684
3685 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3686
3687 if (hr == S_OK)
3688 hr = IBasicVideo_get_DestinationHeight(pBasicVideo, pDestinationHeight);
3689
3690 LeaveCriticalSection(&This->cs);
3691
3692 return hr;
3693 }
3694
3695 static HRESULT WINAPI BasicVideo_SetSourcePosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3696 LONG Width, LONG Height)
3697 {
3698 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3699 IBasicVideo *pBasicVideo;
3700 HRESULT hr;
3701
3702 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3703
3704 EnterCriticalSection(&This->cs);
3705
3706 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3707
3708 if (hr == S_OK)
3709 hr = IBasicVideo_SetSourcePosition(pBasicVideo, Left, Top, Width, Height);
3710
3711 LeaveCriticalSection(&This->cs);
3712
3713 return hr;
3714 }
3715
3716 static HRESULT WINAPI BasicVideo_GetSourcePosition(IBasicVideo2 *iface, LONG *pLeft, LONG *pTop,
3717 LONG *pWidth, LONG *pHeight)
3718 {
3719 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3720 IBasicVideo *pBasicVideo;
3721 HRESULT hr;
3722
3723 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3724
3725 EnterCriticalSection(&This->cs);
3726
3727 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3728
3729 if (hr == S_OK)
3730 hr = IBasicVideo_GetSourcePosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3731
3732 LeaveCriticalSection(&This->cs);
3733
3734 return hr;
3735 }
3736
3737 static HRESULT WINAPI BasicVideo_SetDefaultSourcePosition(IBasicVideo2 *iface)
3738 {
3739 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3740 IBasicVideo *pBasicVideo;
3741 HRESULT hr;
3742
3743 TRACE("(%p/%p)->()\n", This, iface);
3744
3745 EnterCriticalSection(&This->cs);
3746
3747 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3748
3749 if (hr == S_OK)
3750 hr = IBasicVideo_SetDefaultSourcePosition(pBasicVideo);
3751
3752 LeaveCriticalSection(&This->cs);
3753
3754 return hr;
3755 }
3756
3757 static HRESULT WINAPI BasicVideo_SetDestinationPosition(IBasicVideo2 *iface, LONG Left, LONG Top,
3758 LONG Width, LONG Height)
3759 {
3760 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3761 IBasicVideo *pBasicVideo;
3762 HRESULT hr;
3763
3764 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
3765
3766 EnterCriticalSection(&This->cs);
3767
3768 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3769
3770 if (hr == S_OK)
3771 hr = IBasicVideo_SetDestinationPosition(pBasicVideo, Left, Top, Width, Height);
3772
3773 LeaveCriticalSection(&This->cs);
3774
3775 return hr;
3776 }
3777
3778 static HRESULT WINAPI BasicVideo_GetDestinationPosition(IBasicVideo2 *iface, LONG *pLeft,
3779 LONG *pTop, LONG *pWidth, LONG *pHeight)
3780 {
3781 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3782 IBasicVideo *pBasicVideo;
3783 HRESULT hr;
3784
3785 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
3786
3787 EnterCriticalSection(&This->cs);
3788
3789 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3790
3791 if (hr == S_OK)
3792 hr = IBasicVideo_GetDestinationPosition(pBasicVideo, pLeft, pTop, pWidth, pHeight);
3793
3794 LeaveCriticalSection(&This->cs);
3795
3796 return hr;
3797 }
3798
3799 static HRESULT WINAPI BasicVideo_SetDefaultDestinationPosition(IBasicVideo2 *iface)
3800 {
3801 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3802 IBasicVideo *pBasicVideo;
3803 HRESULT hr;
3804
3805 TRACE("(%p/%p)->()\n", This, iface);
3806
3807 EnterCriticalSection(&This->cs);
3808
3809 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3810
3811 if (hr == S_OK)
3812 hr = IBasicVideo_SetDefaultDestinationPosition(pBasicVideo);
3813
3814 LeaveCriticalSection(&This->cs);
3815
3816 return hr;
3817 }
3818
3819 static HRESULT WINAPI BasicVideo_GetVideoSize(IBasicVideo2 *iface, LONG *pWidth, LONG *pHeight)
3820 {
3821 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3822 IBasicVideo *pBasicVideo;
3823 HRESULT hr;
3824
3825 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
3826
3827 EnterCriticalSection(&This->cs);
3828
3829 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3830
3831 if (hr == S_OK)
3832 hr = IBasicVideo_GetVideoSize(pBasicVideo, pWidth, pHeight);
3833
3834 LeaveCriticalSection(&This->cs);
3835
3836 return hr;
3837 }
3838
3839 static HRESULT WINAPI BasicVideo_GetVideoPaletteEntries(IBasicVideo2 *iface, LONG StartIndex,
3840 LONG Entries, LONG *pRetrieved, LONG *pPalette)
3841 {
3842 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3843 IBasicVideo *pBasicVideo;
3844 HRESULT hr;
3845
3846 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This, iface, StartIndex, Entries, pRetrieved, pPalette);
3847
3848 EnterCriticalSection(&This->cs);
3849
3850 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3851
3852 if (hr == S_OK)
3853 hr = IBasicVideo_GetVideoPaletteEntries(pBasicVideo, StartIndex, Entries, pRetrieved, pPalette);
3854
3855 LeaveCriticalSection(&This->cs);
3856
3857 return hr;
3858 }
3859
3860 static HRESULT WINAPI BasicVideo_GetCurrentImage(IBasicVideo2 *iface, LONG *pBufferSize,
3861 LONG *pDIBImage)
3862 {
3863 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3864 IBasicVideo *pBasicVideo;
3865 HRESULT hr;
3866
3867 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pBufferSize, pDIBImage);
3868
3869 EnterCriticalSection(&This->cs);
3870
3871 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3872
3873 if (hr == S_OK)
3874 hr = IBasicVideo_GetCurrentImage(pBasicVideo, pBufferSize, pDIBImage);
3875
3876 LeaveCriticalSection(&This->cs);
3877
3878 return hr;
3879 }
3880
3881 static HRESULT WINAPI BasicVideo_IsUsingDefaultSource(IBasicVideo2 *iface)
3882 {
3883 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3884 IBasicVideo *pBasicVideo;
3885 HRESULT hr;
3886
3887 TRACE("(%p/%p)->()\n", This, iface);
3888
3889 EnterCriticalSection(&This->cs);
3890
3891 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3892
3893 if (hr == S_OK)
3894 hr = IBasicVideo_IsUsingDefaultSource(pBasicVideo);
3895
3896 LeaveCriticalSection(&This->cs);
3897
3898 return hr;
3899 }
3900
3901 static HRESULT WINAPI BasicVideo_IsUsingDefaultDestination(IBasicVideo2 *iface)
3902 {
3903 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3904 IBasicVideo *pBasicVideo;
3905 HRESULT hr;
3906
3907 TRACE("(%p/%p)->()\n", This, iface);
3908
3909 EnterCriticalSection(&This->cs);
3910
3911 hr = GetTargetInterface(This, &IID_IBasicVideo, (LPVOID*)&pBasicVideo);
3912
3913 if (hr == S_OK)
3914 hr = IBasicVideo_IsUsingDefaultDestination(pBasicVideo);
3915
3916 LeaveCriticalSection(&This->cs);
3917
3918 return hr;
3919 }
3920
3921 static HRESULT WINAPI BasicVideo2_GetPreferredAspectRatio(IBasicVideo2 *iface, LONG *plAspectX,
3922 LONG *plAspectY)
3923 {
3924 IFilterGraphImpl *This = impl_from_IBasicVideo2(iface);
3925 IBasicVideo2 *pBasicVideo2;
3926 HRESULT hr;
3927
3928 TRACE("(%p/%p)->()\n", This, iface);
3929
3930 EnterCriticalSection(&This->cs);
3931
3932 hr = GetTargetInterface(This, &IID_IBasicVideo2, (LPVOID*)&pBasicVideo2);
3933
3934 if (hr == S_OK)
3935 hr = BasicVideo2_GetPreferredAspectRatio(iface, plAspectX, plAspectY);
3936
3937 LeaveCriticalSection(&This->cs);
3938
3939 return hr;
3940 }
3941
3942 static const IBasicVideo2Vtbl IBasicVideo_VTable =
3943 {
3944 BasicVideo_QueryInterface,
3945 BasicVideo_AddRef,
3946 BasicVideo_Release,
3947 BasicVideo_GetTypeInfoCount,
3948 BasicVideo_GetTypeInfo,
3949 BasicVideo_GetIDsOfNames,
3950 BasicVideo_Invoke,
3951 BasicVideo_get_AvgTimePerFrame,
3952 BasicVideo_get_BitRate,
3953 BasicVideo_get_BitErrorRate,
3954 BasicVideo_get_VideoWidth,
3955 BasicVideo_get_VideoHeight,
3956 BasicVideo_put_SourceLeft,
3957 BasicVideo_get_SourceLeft,
3958 BasicVideo_put_SourceWidth,
3959 BasicVideo_get_SourceWidth,
3960 BasicVideo_put_SourceTop,
3961 BasicVideo_get_SourceTop,
3962 BasicVideo_put_SourceHeight,
3963 BasicVideo_get_SourceHeight,
3964 BasicVideo_put_DestinationLeft,
3965 BasicVideo_get_DestinationLeft,
3966 BasicVideo_put_DestinationWidth,
3967 BasicVideo_get_DestinationWidth,
3968 BasicVideo_put_DestinationTop,
3969 BasicVideo_get_DestinationTop,
3970 BasicVideo_put_DestinationHeight,
3971 BasicVideo_get_DestinationHeight,
3972 BasicVideo_SetSourcePosition,
3973 BasicVideo_GetSourcePosition,
3974 BasicVideo_SetDefaultSourcePosition,
3975 BasicVideo_SetDestinationPosition,
3976 BasicVideo_GetDestinationPosition,
3977 BasicVideo_SetDefaultDestinationPosition,
3978 BasicVideo_GetVideoSize,
3979 BasicVideo_GetVideoPaletteEntries,
3980 BasicVideo_GetCurrentImage,
3981 BasicVideo_IsUsingDefaultSource,
3982 BasicVideo_IsUsingDefaultDestination,
3983 BasicVideo2_GetPreferredAspectRatio
3984 };
3985
3986 static inline IFilterGraphImpl *impl_from_IVideoWindow(IVideoWindow *iface)
3987 {
3988 return CONTAINING_RECORD(iface, IFilterGraphImpl, IVideoWindow_iface);
3989 }
3990
3991 static HRESULT WINAPI VideoWindow_QueryInterface(IVideoWindow *iface, REFIID riid, void **ppvObj)
3992 {
3993 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
3994
3995 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
3996
3997 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
3998 }
3999
4000 static ULONG WINAPI VideoWindow_AddRef(IVideoWindow *iface)
4001 {
4002 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4003
4004 TRACE("(%p/%p)->()\n", This, iface);
4005
4006 return IUnknown_AddRef(This->outer_unk);
4007 }
4008
4009 static ULONG WINAPI VideoWindow_Release(IVideoWindow *iface)
4010 {
4011 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4012
4013 TRACE("(%p/%p)->()\n", This, iface);
4014
4015 return IUnknown_Release(This->outer_unk);
4016 }
4017
4018 /*** IDispatch methods ***/
4019 static HRESULT WINAPI VideoWindow_GetTypeInfoCount(IVideoWindow *iface, UINT *pctinfo)
4020 {
4021 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4022 IVideoWindow *pVideoWindow;
4023 HRESULT hr;
4024
4025 TRACE("(%p/%p)->(%p)\n", This, iface, pctinfo);
4026
4027 EnterCriticalSection(&This->cs);
4028
4029 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4030
4031 if (hr == S_OK)
4032 hr = IVideoWindow_GetTypeInfoCount(pVideoWindow, pctinfo);
4033
4034 LeaveCriticalSection(&This->cs);
4035
4036 return hr;
4037 }
4038
4039 static HRESULT WINAPI VideoWindow_GetTypeInfo(IVideoWindow *iface, UINT iTInfo, LCID lcid,
4040 ITypeInfo **ppTInfo)
4041 {
4042 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4043 IVideoWindow *pVideoWindow;
4044 HRESULT hr;
4045
4046 TRACE("(%p/%p)->(%d, %d, %p)\n", This, iface, iTInfo, lcid, ppTInfo);
4047
4048 EnterCriticalSection(&This->cs);
4049
4050 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4051
4052 if (hr == S_OK)
4053 hr = IVideoWindow_GetTypeInfo(pVideoWindow, iTInfo, lcid, ppTInfo);
4054
4055 LeaveCriticalSection(&This->cs);
4056
4057 return hr;
4058 }
4059
4060 static HRESULT WINAPI VideoWindow_GetIDsOfNames(IVideoWindow *iface, REFIID riid,
4061 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4062 {
4063 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4064 IVideoWindow *pVideoWindow;
4065 HRESULT hr;
4066
4067 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p)\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
4068
4069 EnterCriticalSection(&This->cs);
4070
4071 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4072
4073 if (hr == S_OK)
4074 hr = IVideoWindow_GetIDsOfNames(pVideoWindow, riid, rgszNames, cNames, lcid, rgDispId);
4075
4076 LeaveCriticalSection(&This->cs);
4077
4078 return hr;
4079 }
4080
4081 static HRESULT WINAPI VideoWindow_Invoke(IVideoWindow *iface, DISPID dispIdMember, REFIID riid,
4082 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
4083 UINT*puArgErr)
4084 {
4085 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4086 IVideoWindow *pVideoWindow;
4087 HRESULT hr;
4088
4089 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p)\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4090
4091 EnterCriticalSection(&This->cs);
4092
4093 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4094
4095 if (hr == S_OK)
4096 hr = IVideoWindow_Invoke(pVideoWindow, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
4097
4098 LeaveCriticalSection(&This->cs);
4099
4100 return hr;
4101 }
4102
4103
4104 /*** IVideoWindow methods ***/
4105 static HRESULT WINAPI VideoWindow_put_Caption(IVideoWindow *iface, BSTR strCaption)
4106 {
4107 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4108 IVideoWindow *pVideoWindow;
4109 HRESULT hr;
4110
4111 TRACE("(%p/%p)->(%s (%p))\n", This, iface, debugstr_w(strCaption), strCaption);
4112
4113 EnterCriticalSection(&This->cs);
4114
4115 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4116
4117 if (hr == S_OK)
4118 hr = IVideoWindow_put_Caption(pVideoWindow, strCaption);
4119
4120 LeaveCriticalSection(&This->cs);
4121
4122 return hr;
4123 }
4124
4125 static HRESULT WINAPI VideoWindow_get_Caption(IVideoWindow *iface, BSTR *strCaption)
4126 {
4127 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4128 IVideoWindow *pVideoWindow;
4129 HRESULT hr;
4130
4131 TRACE("(%p/%p)->(%p)\n", This, iface, strCaption);
4132
4133 EnterCriticalSection(&This->cs);
4134
4135 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4136
4137 if (hr == S_OK)
4138 hr = IVideoWindow_get_Caption(pVideoWindow, strCaption);
4139
4140 LeaveCriticalSection(&This->cs);
4141
4142 return hr;
4143 }
4144
4145 static HRESULT WINAPI VideoWindow_put_WindowStyle(IVideoWindow *iface, LONG WindowStyle)
4146 {
4147 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4148 IVideoWindow *pVideoWindow;
4149 HRESULT hr;
4150
4151 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyle);
4152
4153 EnterCriticalSection(&This->cs);
4154
4155 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4156
4157 if (hr == S_OK)
4158 hr = IVideoWindow_put_WindowStyle(pVideoWindow, WindowStyle);
4159
4160 LeaveCriticalSection(&This->cs);
4161
4162 return hr;
4163 }
4164
4165 static HRESULT WINAPI VideoWindow_get_WindowStyle(IVideoWindow *iface, LONG *WindowStyle)
4166 {
4167 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4168 IVideoWindow *pVideoWindow;
4169 HRESULT hr;
4170
4171 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyle);
4172
4173 EnterCriticalSection(&This->cs);
4174
4175 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4176
4177 if (hr == S_OK)
4178 hr = IVideoWindow_get_WindowStyle(pVideoWindow, WindowStyle);
4179
4180 LeaveCriticalSection(&This->cs);
4181
4182 return hr;
4183 }
4184
4185 static HRESULT WINAPI VideoWindow_put_WindowStyleEx(IVideoWindow *iface, LONG WindowStyleEx)
4186 {
4187 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4188 IVideoWindow *pVideoWindow;
4189 HRESULT hr;
4190
4191 TRACE("(%p/%p)->(%d)\n", This, iface, WindowStyleEx);
4192
4193 EnterCriticalSection(&This->cs);
4194
4195 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4196
4197 if (hr == S_OK)
4198 hr = IVideoWindow_put_WindowStyleEx(pVideoWindow, WindowStyleEx);
4199
4200 LeaveCriticalSection(&This->cs);
4201
4202 return hr;
4203 }
4204
4205 static HRESULT WINAPI VideoWindow_get_WindowStyleEx(IVideoWindow *iface, LONG *WindowStyleEx)
4206 {
4207 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4208 IVideoWindow *pVideoWindow;
4209 HRESULT hr;
4210
4211 TRACE("(%p/%p)->(%p)\n", This, iface, WindowStyleEx);
4212
4213 EnterCriticalSection(&This->cs);
4214
4215 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4216
4217 if (hr == S_OK)
4218 hr = IVideoWindow_get_WindowStyleEx(pVideoWindow, WindowStyleEx);
4219
4220 LeaveCriticalSection(&This->cs);
4221
4222 return hr;
4223 }
4224
4225 static HRESULT WINAPI VideoWindow_put_AutoShow(IVideoWindow *iface, LONG AutoShow)
4226 {
4227 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4228 IVideoWindow *pVideoWindow;
4229 HRESULT hr;
4230
4231 TRACE("(%p/%p)->(%d)\n", This, iface, AutoShow);
4232
4233 EnterCriticalSection(&This->cs);
4234
4235 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4236
4237 if (hr == S_OK)
4238 hr = IVideoWindow_put_AutoShow(pVideoWindow, AutoShow);
4239
4240 LeaveCriticalSection(&This->cs);
4241
4242 return hr;
4243 }
4244
4245 static HRESULT WINAPI VideoWindow_get_AutoShow(IVideoWindow *iface, LONG *AutoShow)
4246 {
4247 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4248 IVideoWindow *pVideoWindow;
4249 HRESULT hr;
4250
4251 TRACE("(%p/%p)->(%p)\n", This, iface, AutoShow);
4252
4253 EnterCriticalSection(&This->cs);
4254
4255 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4256
4257 if (hr == S_OK)
4258 hr = IVideoWindow_get_AutoShow(pVideoWindow, AutoShow);
4259
4260 LeaveCriticalSection(&This->cs);
4261
4262 return hr;
4263 }
4264
4265 static HRESULT WINAPI VideoWindow_put_WindowState(IVideoWindow *iface, LONG WindowState)
4266 {
4267 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4268 IVideoWindow *pVideoWindow;
4269 HRESULT hr;
4270
4271 TRACE("(%p/%p)->(%d)\n", This, iface, WindowState);
4272
4273 EnterCriticalSection(&This->cs);
4274
4275 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4276
4277 if (hr == S_OK)
4278 hr = IVideoWindow_put_WindowState(pVideoWindow, WindowState);
4279
4280 LeaveCriticalSection(&This->cs);
4281
4282 return hr;
4283 }
4284
4285 static HRESULT WINAPI VideoWindow_get_WindowState(IVideoWindow *iface, LONG *WindowState)
4286 {
4287 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4288 IVideoWindow *pVideoWindow;
4289 HRESULT hr;
4290
4291 TRACE("(%p/%p)->(%p)\n", This, iface, WindowState);
4292
4293 EnterCriticalSection(&This->cs);
4294
4295 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4296
4297 if (hr == S_OK)
4298 hr = IVideoWindow_get_WindowState(pVideoWindow, WindowState);
4299
4300 LeaveCriticalSection(&This->cs);
4301
4302 return hr;
4303 }
4304
4305 static HRESULT WINAPI VideoWindow_put_BackgroundPalette(IVideoWindow *iface, LONG BackgroundPalette)
4306 {
4307 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4308 IVideoWindow *pVideoWindow;
4309 HRESULT hr;
4310
4311 TRACE("(%p/%p)->(%d)\n", This, iface, BackgroundPalette);
4312
4313 EnterCriticalSection(&This->cs);
4314
4315 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4316
4317 if (hr == S_OK)
4318 hr = IVideoWindow_put_BackgroundPalette(pVideoWindow, BackgroundPalette);
4319
4320 LeaveCriticalSection(&This->cs);
4321
4322 return hr;
4323 }
4324
4325 static HRESULT WINAPI VideoWindow_get_BackgroundPalette(IVideoWindow *iface,
4326 LONG *pBackgroundPalette)
4327 {
4328 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4329 IVideoWindow *pVideoWindow;
4330 HRESULT hr;
4331
4332 TRACE("(%p/%p)->(%p)\n", This, iface, pBackgroundPalette);
4333
4334 EnterCriticalSection(&This->cs);
4335
4336 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4337
4338 if (hr == S_OK)
4339 hr = IVideoWindow_get_BackgroundPalette(pVideoWindow, pBackgroundPalette);
4340
4341 LeaveCriticalSection(&This->cs);
4342
4343 return hr;
4344 }
4345
4346 static HRESULT WINAPI VideoWindow_put_Visible(IVideoWindow *iface, LONG Visible)
4347 {
4348 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4349 IVideoWindow *pVideoWindow;
4350 HRESULT hr;
4351
4352 TRACE("(%p/%p)->(%d)\n", This, iface, Visible);
4353
4354 EnterCriticalSection(&This->cs);
4355
4356 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4357
4358 if (hr == S_OK)
4359 hr = IVideoWindow_put_Visible(pVideoWindow, Visible);
4360
4361 LeaveCriticalSection(&This->cs);
4362
4363 return hr;
4364 }
4365
4366 static HRESULT WINAPI VideoWindow_get_Visible(IVideoWindow *iface, LONG *pVisible)
4367 {
4368 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4369 IVideoWindow *pVideoWindow;
4370 HRESULT hr;
4371
4372 TRACE("(%p/%p)->(%p)\n", This, iface, pVisible);
4373
4374 EnterCriticalSection(&This->cs);
4375
4376 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4377
4378 if (hr == S_OK)
4379 hr = IVideoWindow_get_Visible(pVideoWindow, pVisible);
4380
4381 LeaveCriticalSection(&This->cs);
4382
4383 return hr;
4384 }
4385
4386 static HRESULT WINAPI VideoWindow_put_Left(IVideoWindow *iface, LONG Left)
4387 {
4388 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4389 IVideoWindow *pVideoWindow;
4390 HRESULT hr;
4391
4392 TRACE("(%p/%p)->(%d)\n", This, iface, Left);
4393
4394 EnterCriticalSection(&This->cs);
4395
4396 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4397
4398 if (hr == S_OK)
4399 hr = IVideoWindow_put_Left(pVideoWindow, Left);
4400
4401 LeaveCriticalSection(&This->cs);
4402
4403 return hr;
4404 }
4405
4406 static HRESULT WINAPI VideoWindow_get_Left(IVideoWindow *iface, LONG *pLeft)
4407 {
4408 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4409 IVideoWindow *pVideoWindow;
4410 HRESULT hr;
4411
4412 TRACE("(%p/%p)->(%p)\n", This, iface, pLeft);
4413
4414 EnterCriticalSection(&This->cs);
4415
4416 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4417
4418 if (hr == S_OK)
4419 hr = IVideoWindow_get_Left(pVideoWindow, pLeft);
4420
4421 LeaveCriticalSection(&This->cs);
4422
4423 return hr;
4424 }
4425
4426 static HRESULT WINAPI VideoWindow_put_Width(IVideoWindow *iface, LONG Width)
4427 {
4428 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4429 IVideoWindow *pVideoWindow;
4430 HRESULT hr;
4431
4432 TRACE("(%p/%p)->(%d)\n", This, iface, Width);
4433
4434 EnterCriticalSection(&This->cs);
4435
4436 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4437
4438 if (hr == S_OK)
4439 hr = IVideoWindow_put_Width(pVideoWindow, Width);
4440
4441 LeaveCriticalSection(&This->cs);
4442
4443 return hr;
4444 }
4445
4446 static HRESULT WINAPI VideoWindow_get_Width(IVideoWindow *iface, LONG *pWidth)
4447 {
4448 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4449 IVideoWindow *pVideoWindow;
4450 HRESULT hr;
4451
4452 TRACE("(%p/%p)->(%p)\n", This, iface, pWidth);
4453
4454 EnterCriticalSection(&This->cs);
4455
4456 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4457
4458 if (hr == S_OK)
4459 hr = IVideoWindow_get_Width(pVideoWindow, pWidth);
4460
4461 LeaveCriticalSection(&This->cs);
4462
4463 return hr;
4464 }
4465
4466 static HRESULT WINAPI VideoWindow_put_Top(IVideoWindow *iface, LONG Top)
4467 {
4468 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4469 IVideoWindow *pVideoWindow;
4470 HRESULT hr;
4471
4472 TRACE("(%p/%p)->(%d)\n", This, iface, Top);
4473
4474 EnterCriticalSection(&This->cs);
4475
4476 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4477
4478 if (hr == S_OK)
4479 hr = IVideoWindow_put_Top(pVideoWindow, Top);
4480
4481 LeaveCriticalSection(&This->cs);
4482
4483 return hr;
4484 }
4485
4486 static HRESULT WINAPI VideoWindow_get_Top(IVideoWindow *iface, LONG *pTop)
4487 {
4488 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4489 IVideoWindow *pVideoWindow;
4490 HRESULT hr;
4491
4492 TRACE("(%p/%p)->(%p)\n", This, iface, pTop);
4493
4494 EnterCriticalSection(&This->cs);
4495
4496 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4497
4498 if (hr == S_OK)
4499 hr = IVideoWindow_get_Top(pVideoWindow, pTop);
4500
4501 LeaveCriticalSection(&This->cs);
4502
4503 return hr;
4504 }
4505
4506 static HRESULT WINAPI VideoWindow_put_Height(IVideoWindow *iface, LONG Height)
4507 {
4508 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4509 IVideoWindow *pVideoWindow;
4510 HRESULT hr;
4511
4512 TRACE("(%p/%p)->(%d)\n", This, iface, Height);
4513
4514 EnterCriticalSection(&This->cs);
4515
4516 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4517
4518 if (hr == S_OK)
4519 hr = IVideoWindow_put_Height(pVideoWindow, Height);
4520
4521 LeaveCriticalSection(&This->cs);
4522
4523 return hr;
4524 }
4525
4526 static HRESULT WINAPI VideoWindow_get_Height(IVideoWindow *iface, LONG *pHeight)
4527 {
4528 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4529 IVideoWindow *pVideoWindow;
4530 HRESULT hr;
4531
4532 TRACE("(%p/%p)->(%p)\n", This, iface, pHeight);
4533
4534 EnterCriticalSection(&This->cs);
4535
4536 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4537
4538 if (hr == S_OK)
4539 hr = IVideoWindow_get_Height(pVideoWindow, pHeight);
4540
4541 LeaveCriticalSection(&This->cs);
4542
4543 return hr;
4544 }
4545
4546 static HRESULT WINAPI VideoWindow_put_Owner(IVideoWindow *iface, OAHWND Owner)
4547 {
4548 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4549 IVideoWindow *pVideoWindow;
4550 HRESULT hr;
4551
4552 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Owner);
4553
4554 EnterCriticalSection(&This->cs);
4555
4556 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4557
4558 if (hr == S_OK)
4559 hr = IVideoWindow_put_Owner(pVideoWindow, Owner);
4560
4561 LeaveCriticalSection(&This->cs);
4562
4563 return hr;
4564 }
4565
4566 static HRESULT WINAPI VideoWindow_get_Owner(IVideoWindow *iface, OAHWND *Owner)
4567 {
4568 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4569 IVideoWindow *pVideoWindow;
4570 HRESULT hr;
4571
4572 TRACE("(%p/%p)->(%p)\n", This, iface, Owner);
4573
4574 EnterCriticalSection(&This->cs);
4575
4576 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4577
4578 if (hr == S_OK)
4579 hr = IVideoWindow_get_Owner(pVideoWindow, Owner);
4580
4581 LeaveCriticalSection(&This->cs);
4582
4583 return hr;
4584 }
4585
4586 static HRESULT WINAPI VideoWindow_put_MessageDrain(IVideoWindow *iface, OAHWND Drain)
4587 {
4588 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4589 IVideoWindow *pVideoWindow;
4590 HRESULT hr;
4591
4592 TRACE("(%p/%p)->(%08x)\n", This, iface, (DWORD) Drain);
4593
4594 EnterCriticalSection(&This->cs);
4595
4596 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4597
4598 if (hr == S_OK)
4599 hr = IVideoWindow_put_MessageDrain(pVideoWindow, Drain);
4600
4601 LeaveCriticalSection(&This->cs);
4602
4603 return hr;
4604 }
4605
4606 static HRESULT WINAPI VideoWindow_get_MessageDrain(IVideoWindow *iface, OAHWND *Drain)
4607 {
4608 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4609 IVideoWindow *pVideoWindow;
4610 HRESULT hr;
4611
4612 TRACE("(%p/%p)->(%p)\n", This, iface, Drain);
4613
4614 EnterCriticalSection(&This->cs);
4615
4616 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4617
4618 if (hr == S_OK)
4619 hr = IVideoWindow_get_MessageDrain(pVideoWindow, Drain);
4620
4621 LeaveCriticalSection(&This->cs);
4622
4623 return hr;
4624 }
4625
4626 static HRESULT WINAPI VideoWindow_get_BorderColor(IVideoWindow *iface, LONG *Color)
4627 {
4628 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4629 IVideoWindow *pVideoWindow;
4630 HRESULT hr;
4631
4632 TRACE("(%p/%p)->(%p)\n", This, iface, Color);
4633
4634 EnterCriticalSection(&This->cs);
4635
4636 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4637
4638 if (hr == S_OK)
4639 hr = IVideoWindow_get_BorderColor(pVideoWindow, Color);
4640
4641 LeaveCriticalSection(&This->cs);
4642
4643 return hr;
4644 }
4645
4646 static HRESULT WINAPI VideoWindow_put_BorderColor(IVideoWindow *iface, LONG Color)
4647 {
4648 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4649 IVideoWindow *pVideoWindow;
4650 HRESULT hr;
4651
4652 TRACE("(%p/%p)->(%d)\n", This, iface, Color);
4653
4654 EnterCriticalSection(&This->cs);
4655
4656 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4657
4658 if (hr == S_OK)
4659 hr = IVideoWindow_put_BorderColor(pVideoWindow, Color);
4660
4661 LeaveCriticalSection(&This->cs);
4662
4663 return hr;
4664 }
4665
4666 static HRESULT WINAPI VideoWindow_get_FullScreenMode(IVideoWindow *iface, LONG *FullScreenMode)
4667 {
4668 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4669 IVideoWindow *pVideoWindow;
4670 HRESULT hr;
4671
4672 TRACE("(%p/%p)->(%p)\n", This, iface, FullScreenMode);
4673
4674 EnterCriticalSection(&This->cs);
4675
4676 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4677
4678 if (hr == S_OK)
4679 hr = IVideoWindow_get_FullScreenMode(pVideoWindow, FullScreenMode);
4680
4681 LeaveCriticalSection(&This->cs);
4682
4683 return hr;
4684 }
4685
4686 static HRESULT WINAPI VideoWindow_put_FullScreenMode(IVideoWindow *iface, LONG FullScreenMode)
4687 {
4688 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4689 IVideoWindow *pVideoWindow;
4690 HRESULT hr;
4691
4692 TRACE("(%p/%p)->(%d)\n", This, iface, FullScreenMode);
4693
4694 EnterCriticalSection(&This->cs);
4695
4696 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4697
4698 if (hr == S_OK)
4699 hr = IVideoWindow_put_FullScreenMode(pVideoWindow, FullScreenMode);
4700
4701 LeaveCriticalSection(&This->cs);
4702
4703 return hr;
4704 }
4705
4706 static HRESULT WINAPI VideoWindow_SetWindowForeground(IVideoWindow *iface, LONG Focus)
4707 {
4708 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4709 IVideoWindow *pVideoWindow;
4710 HRESULT hr;
4711
4712 TRACE("(%p/%p)->(%d)\n", This, iface, Focus);
4713
4714 EnterCriticalSection(&This->cs);
4715
4716 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4717
4718 if (hr == S_OK)
4719 hr = IVideoWindow_SetWindowForeground(pVideoWindow, Focus);
4720
4721 LeaveCriticalSection(&This->cs);
4722
4723 return hr;
4724 }
4725
4726 static HRESULT WINAPI VideoWindow_NotifyOwnerMessage(IVideoWindow *iface, OAHWND hwnd, LONG uMsg,
4727 LONG_PTR wParam, LONG_PTR lParam)
4728 {
4729 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4730 IVideoWindow *pVideoWindow;
4731 HRESULT hr;
4732
4733 TRACE("(%p/%p)->(%08lx, %d, %08lx, %08lx)\n", This, iface, hwnd, uMsg, wParam, lParam);
4734
4735 EnterCriticalSection(&This->cs);
4736
4737 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4738
4739 if (hr == S_OK)
4740 hr = IVideoWindow_NotifyOwnerMessage(pVideoWindow, hwnd, uMsg, wParam, lParam);
4741
4742 LeaveCriticalSection(&This->cs);
4743
4744 return hr;
4745 }
4746
4747 static HRESULT WINAPI VideoWindow_SetWindowPosition(IVideoWindow *iface, LONG Left, LONG Top,
4748 LONG Width, LONG Height)
4749 {
4750 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4751 IVideoWindow *pVideoWindow;
4752 HRESULT hr;
4753
4754 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This, iface, Left, Top, Width, Height);
4755
4756 EnterCriticalSection(&This->cs);
4757
4758 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4759
4760 if (hr == S_OK)
4761 hr = IVideoWindow_SetWindowPosition(pVideoWindow, Left, Top, Width, Height);
4762
4763 LeaveCriticalSection(&This->cs);
4764
4765 return hr;
4766 }
4767
4768 static HRESULT WINAPI VideoWindow_GetWindowPosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4769 LONG *pWidth, LONG *pHeight)
4770 {
4771 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4772 IVideoWindow *pVideoWindow;
4773 HRESULT hr;
4774
4775 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4776
4777 EnterCriticalSection(&This->cs);
4778
4779 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4780
4781 if (hr == S_OK)
4782 hr = IVideoWindow_GetWindowPosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4783
4784 LeaveCriticalSection(&This->cs);
4785
4786 return hr;
4787 }
4788
4789 static HRESULT WINAPI VideoWindow_GetMinIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4790 LONG *pHeight)
4791 {
4792 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4793 IVideoWindow *pVideoWindow;
4794 HRESULT hr;
4795
4796 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4797
4798 EnterCriticalSection(&This->cs);
4799
4800 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4801
4802 if (hr == S_OK)
4803 hr = IVideoWindow_GetMinIdealImageSize(pVideoWindow, pWidth, pHeight);
4804
4805 LeaveCriticalSection(&This->cs);
4806
4807 return hr;
4808 }
4809
4810 static HRESULT WINAPI VideoWindow_GetMaxIdealImageSize(IVideoWindow *iface, LONG *pWidth,
4811 LONG *pHeight)
4812 {
4813 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4814 IVideoWindow *pVideoWindow;
4815 HRESULT hr;
4816
4817 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pWidth, pHeight);
4818
4819 EnterCriticalSection(&This->cs);
4820
4821 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4822
4823 if (hr == S_OK)
4824 hr = IVideoWindow_GetMaxIdealImageSize(pVideoWindow, pWidth, pHeight);
4825
4826 LeaveCriticalSection(&This->cs);
4827
4828 return hr;
4829 }
4830
4831 static HRESULT WINAPI VideoWindow_GetRestorePosition(IVideoWindow *iface, LONG *pLeft, LONG *pTop,
4832 LONG *pWidth, LONG *pHeight)
4833 {
4834 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4835 IVideoWindow *pVideoWindow;
4836 HRESULT hr;
4837
4838 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This, iface, pLeft, pTop, pWidth, pHeight);
4839
4840 EnterCriticalSection(&This->cs);
4841
4842 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4843
4844 if (hr == S_OK)
4845 hr = IVideoWindow_GetRestorePosition(pVideoWindow, pLeft, pTop, pWidth, pHeight);
4846
4847 LeaveCriticalSection(&This->cs);
4848
4849 return hr;
4850 }
4851
4852 static HRESULT WINAPI VideoWindow_HideCursor(IVideoWindow *iface, LONG HideCursor)
4853 {
4854 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4855 IVideoWindow *pVideoWindow;
4856 HRESULT hr;
4857
4858 TRACE("(%p/%p)->(%d)\n", This, iface, HideCursor);
4859
4860 EnterCriticalSection(&This->cs);
4861
4862 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4863
4864 if (hr == S_OK)
4865 hr = IVideoWindow_HideCursor(pVideoWindow, HideCursor);
4866
4867 LeaveCriticalSection(&This->cs);
4868
4869 return hr;
4870 }
4871
4872 static HRESULT WINAPI VideoWindow_IsCursorHidden(IVideoWindow *iface, LONG *CursorHidden)
4873 {
4874 IFilterGraphImpl *This = impl_from_IVideoWindow(iface);
4875 IVideoWindow *pVideoWindow;
4876 HRESULT hr;
4877
4878 TRACE("(%p/%p)->(%p)\n", This, iface, CursorHidden);
4879
4880 EnterCriticalSection(&This->cs);
4881
4882 hr = GetTargetInterface(This, &IID_IVideoWindow, (LPVOID*)&pVideoWindow);
4883
4884 if (hr == S_OK)
4885 hr = IVideoWindow_IsCursorHidden(pVideoWindow, CursorHidden);
4886
4887 LeaveCriticalSection(&This->cs);
4888
4889 return hr;
4890 }
4891
4892
4893 static const IVideoWindowVtbl IVideoWindow_VTable =
4894 {
4895 VideoWindow_QueryInterface,
4896 VideoWindow_AddRef,
4897 VideoWindow_Release,
4898 VideoWindow_GetTypeInfoCount,
4899 VideoWindow_GetTypeInfo,
4900 VideoWindow_GetIDsOfNames,
4901 VideoWindow_Invoke,
4902 VideoWindow_put_Caption,
4903 VideoWindow_get_Caption,
4904 VideoWindow_put_WindowStyle,
4905 VideoWindow_get_WindowStyle,
4906 VideoWindow_put_WindowStyleEx,
4907 VideoWindow_get_WindowStyleEx,
4908 VideoWindow_put_AutoShow,
4909 VideoWindow_get_AutoShow,
4910 VideoWindow_put_WindowState,
4911 VideoWindow_get_WindowState,
4912 VideoWindow_put_BackgroundPalette,
4913 VideoWindow_get_BackgroundPalette,
4914 VideoWindow_put_Visible,
4915 VideoWindow_get_Visible,
4916 VideoWindow_put_Left,
4917 VideoWindow_get_Left,
4918 VideoWindow_put_Width,
4919 VideoWindow_get_Width,
4920 VideoWindow_put_Top,
4921 VideoWindow_get_Top,
4922 VideoWindow_put_Height,
4923 VideoWindow_get_Height,
4924 VideoWindow_put_Owner,
4925 VideoWindow_get_Owner,
4926 VideoWindow_put_MessageDrain,
4927 VideoWindow_get_MessageDrain,
4928 VideoWindow_get_BorderColor,
4929 VideoWindow_put_BorderColor,
4930 VideoWindow_get_FullScreenMode,
4931 VideoWindow_put_FullScreenMode,
4932 VideoWindow_SetWindowForeground,
4933 VideoWindow_NotifyOwnerMessage,
4934 VideoWindow_SetWindowPosition,
4935 VideoWindow_GetWindowPosition,
4936 VideoWindow_GetMinIdealImageSize,
4937 VideoWindow_GetMaxIdealImageSize,
4938 VideoWindow_GetRestorePosition,
4939 VideoWindow_HideCursor,
4940 VideoWindow_IsCursorHidden
4941 };
4942
4943 static inline IFilterGraphImpl *impl_from_IMediaEventEx(IMediaEventEx *iface)
4944 {
4945 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventEx_iface);
4946 }
4947
4948 static HRESULT WINAPI MediaEvent_QueryInterface(IMediaEventEx *iface, REFIID riid, void **ppvObj)
4949 {
4950 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4951
4952 TRACE("(%p/%p)->(%s (%p), %p)\n", This, iface, debugstr_guid(riid), riid, ppvObj);
4953
4954 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
4955 }
4956
4957 static ULONG WINAPI MediaEvent_AddRef(IMediaEventEx *iface)
4958 {
4959 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4960
4961 TRACE("(%p/%p)->()\n", This, iface);
4962
4963 return IUnknown_AddRef(This->outer_unk);
4964 }
4965
4966 static ULONG WINAPI MediaEvent_Release(IMediaEventEx *iface)
4967 {
4968 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4969
4970 TRACE("(%p/%p)->()\n", This, iface);
4971
4972 return IUnknown_Release(This->outer_unk);
4973 }
4974
4975 /*** IDispatch methods ***/
4976 static HRESULT WINAPI MediaEvent_GetTypeInfoCount(IMediaEventEx *iface, UINT *pctinfo)
4977 {
4978 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4979
4980 TRACE("(%p/%p)->(%p): stub !!!\n", This, iface, pctinfo);
4981
4982 return S_OK;
4983 }
4984
4985 static HRESULT WINAPI MediaEvent_GetTypeInfo(IMediaEventEx *iface, UINT iTInfo, LCID lcid,
4986 ITypeInfo **ppTInfo)
4987 {
4988 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4989
4990 TRACE("(%p/%p)->(%d, %d, %p): stub !!!\n", This, iface, iTInfo, lcid, ppTInfo);
4991
4992 return S_OK;
4993 }
4994
4995 static HRESULT WINAPI MediaEvent_GetIDsOfNames(IMediaEventEx *iface, REFIID riid,
4996 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4997 {
4998 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
4999
5000 TRACE("(%p/%p)->(%s (%p), %p, %d, %d, %p): stub !!!\n", This, iface, debugstr_guid(riid), riid, rgszNames, cNames, lcid, rgDispId);
5001
5002 return S_OK;
5003 }
5004
5005 static HRESULT WINAPI MediaEvent_Invoke(IMediaEventEx *iface, DISPID dispIdMember, REFIID riid,
5006 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo,
5007 UINT *puArgErr)
5008 {
5009 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5010
5011 TRACE("(%p/%p)->(%d, %s (%p), %d, %04x, %p, %p, %p, %p): stub !!!\n", This, iface, dispIdMember, debugstr_guid(riid), riid, lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
5012
5013 return S_OK;
5014 }
5015
5016 /*** IMediaEvent methods ***/
5017 static HRESULT WINAPI MediaEvent_GetEventHandle(IMediaEventEx *iface, OAEVENT *hEvent)
5018 {
5019 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5020
5021 TRACE("(%p/%p)->(%p)\n", This, iface, hEvent);
5022
5023 *hEvent = (OAEVENT)This->evqueue.msg_event;
5024
5025 return S_OK;
5026 }
5027
5028 static HRESULT WINAPI MediaEvent_GetEvent(IMediaEventEx *iface, LONG *lEventCode, LONG_PTR *lParam1,
5029 LONG_PTR *lParam2, LONG msTimeout)
5030 {
5031 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5032 Event evt;
5033
5034 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", This, iface, lEventCode, lParam1, lParam2, msTimeout);
5035
5036 if (EventsQueue_GetEvent(&This->evqueue, &evt, msTimeout))
5037 {
5038 *lEventCode = evt.lEventCode;
5039 *lParam1 = evt.lParam1;
5040 *lParam2 = evt.lParam2;
5041 return S_OK;
5042 }
5043
5044 *lEventCode = 0;
5045 return E_ABORT;
5046 }
5047
5048 static HRESULT WINAPI MediaEvent_WaitForCompletion(IMediaEventEx *iface, LONG msTimeout,
5049 LONG *pEvCode)
5050 {
5051 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5052
5053 TRACE("(%p/%p)->(%d, %p)\n", This, iface, msTimeout, pEvCode);
5054
5055 if (This->state != State_Running)
5056 return VFW_E_WRONG_STATE;
5057
5058 if (WaitForSingleObject(This->hEventCompletion, msTimeout) == WAIT_OBJECT_0)
5059 {
5060 *pEvCode = This->CompletionStatus;
5061 return S_OK;
5062 }
5063
5064 *pEvCode = 0;
5065 return E_ABORT;
5066 }
5067
5068 static HRESULT WINAPI MediaEvent_CancelDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5069 {
5070 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5071
5072 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5073
5074 if (lEvCode == EC_COMPLETE)
5075 This->HandleEcComplete = FALSE;
5076 else if (lEvCode == EC_REPAINT)
5077 This->HandleEcRepaint = FALSE;
5078 else if (lEvCode == EC_CLOCK_CHANGED)
5079 This->HandleEcClockChanged = FALSE;
5080 else
5081 return S_FALSE;
5082
5083 return S_OK;
5084 }
5085
5086 static HRESULT WINAPI MediaEvent_RestoreDefaultHandling(IMediaEventEx *iface, LONG lEvCode)
5087 {
5088 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5089
5090 TRACE("(%p/%p)->(%d)\n", This, iface, lEvCode);
5091
5092 if (lEvCode == EC_COMPLETE)
5093 This->HandleEcComplete = TRUE;
5094 else if (lEvCode == EC_REPAINT)
5095 This->HandleEcRepaint = TRUE;
5096 else if (lEvCode == EC_CLOCK_CHANGED)
5097 This->HandleEcClockChanged = TRUE;
5098 else
5099 return S_FALSE;
5100
5101 return S_OK;
5102 }
5103
5104 static HRESULT WINAPI MediaEvent_FreeEventParams(IMediaEventEx *iface, LONG lEvCode,
5105 LONG_PTR lParam1, LONG_PTR lParam2)
5106 {
5107 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5108
5109 TRACE("(%p/%p)->(%d, %08lx, %08lx): stub !!!\n", This, iface, lEvCode, lParam1, lParam2);
5110
5111 return S_OK;
5112 }
5113
5114 /*** IMediaEventEx methods ***/
5115 static HRESULT WINAPI MediaEvent_SetNotifyWindow(IMediaEventEx *iface, OAHWND hwnd, LONG lMsg,
5116 LONG_PTR lInstanceData)
5117 {
5118 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5119
5120 TRACE("(%p/%p)->(%08lx, %d, %08lx)\n", This, iface, hwnd, lMsg, lInstanceData);
5121
5122 This->notif.hWnd = (HWND)hwnd;
5123 This->notif.msg = lMsg;
5124 This->notif.instance = lInstanceData;
5125
5126 return S_OK;
5127 }
5128
5129 static HRESULT WINAPI MediaEvent_SetNotifyFlags(IMediaEventEx *iface, LONG lNoNotifyFlags)
5130 {
5131 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5132
5133 TRACE("(%p/%p)->(%d)\n", This, iface, lNoNotifyFlags);
5134
5135 if ((lNoNotifyFlags != 0) && (lNoNotifyFlags != 1))
5136 return E_INVALIDARG;
5137
5138 This->notif.disabled = lNoNotifyFlags;
5139
5140 return S_OK;
5141 }
5142
5143 static HRESULT WINAPI MediaEvent_GetNotifyFlags(IMediaEventEx *iface, LONG *lplNoNotifyFlags)
5144 {
5145 IFilterGraphImpl *This = impl_from_IMediaEventEx(iface);
5146
5147 TRACE("(%p/%p)->(%p)\n", This, iface, lplNoNotifyFlags);
5148
5149 if (!lplNoNotifyFlags)
5150 return E_POINTER;
5151
5152 *lplNoNotifyFlags = This->notif.disabled;
5153
5154 return S_OK;
5155 }
5156
5157
5158 static const IMediaEventExVtbl IMediaEventEx_VTable =
5159 {
5160 MediaEvent_QueryInterface,
5161 MediaEvent_AddRef,
5162 MediaEvent_Release,
5163 MediaEvent_GetTypeInfoCount,
5164 MediaEvent_GetTypeInfo,
5165 MediaEvent_GetIDsOfNames,
5166 MediaEvent_Invoke,
5167 MediaEvent_GetEventHandle,
5168 MediaEvent_GetEvent,
5169 MediaEvent_WaitForCompletion,
5170 MediaEvent_CancelDefaultHandling,
5171 MediaEvent_RestoreDefaultHandling,
5172 MediaEvent_FreeEventParams,
5173 MediaEvent_SetNotifyWindow,
5174 MediaEvent_SetNotifyFlags,
5175 MediaEvent_GetNotifyFlags
5176 };
5177
5178
5179 static inline IFilterGraphImpl *impl_from_IMediaFilter(IMediaFilter *iface)
5180 {
5181 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaFilter_iface);
5182 }
5183
5184 static HRESULT WINAPI MediaFilter_QueryInterface(IMediaFilter *iface, REFIID riid, void **ppv)
5185 {
5186 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5187
5188 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5189 }
5190
5191 static ULONG WINAPI MediaFilter_AddRef(IMediaFilter *iface)
5192 {
5193 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5194
5195 return IUnknown_AddRef(This->outer_unk);
5196 }
5197
5198 static ULONG WINAPI MediaFilter_Release(IMediaFilter *iface)
5199 {
5200 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5201
5202 return IUnknown_Release(This->outer_unk);
5203 }
5204
5205 static HRESULT WINAPI MediaFilter_GetClassID(IMediaFilter *iface, CLSID * pClassID)
5206 {
5207 FIXME("(%p): stub\n", pClassID);
5208
5209 return E_NOTIMPL;
5210 }
5211
5212 static HRESULT WINAPI MediaFilter_Stop(IMediaFilter *iface)
5213 {
5214 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5215
5216 return MediaControl_Stop(&This->IMediaControl_iface);
5217 }
5218
5219 static HRESULT WINAPI MediaFilter_Pause(IMediaFilter *iface)
5220 {
5221 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5222
5223 return MediaControl_Pause(&This->IMediaControl_iface);
5224 }
5225
5226 static HRESULT WINAPI MediaFilter_Run(IMediaFilter *iface, REFERENCE_TIME tStart)
5227 {
5228 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5229
5230 if (tStart)
5231 FIXME("Run called with non-null tStart: %x%08x\n",
5232 (int)(tStart>>32), (int)tStart);
5233
5234 return MediaControl_Run(&This->IMediaControl_iface);
5235 }
5236
5237 static HRESULT WINAPI MediaFilter_GetState(IMediaFilter *iface, DWORD dwMsTimeout,
5238 FILTER_STATE *pState)
5239 {
5240 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5241
5242 return MediaControl_GetState(&This->IMediaControl_iface, dwMsTimeout, (OAFilterState*)pState);
5243 }
5244
5245 static HRESULT WINAPI MediaFilter_SetSyncSource(IMediaFilter *iface, IReferenceClock *pClock)
5246 {
5247 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5248 HRESULT hr = S_OK;
5249 int i;
5250
5251 TRACE("(%p/%p)->(%p)\n", iface, This, pClock);
5252
5253 EnterCriticalSection(&This->cs);
5254 {
5255 for (i = 0;i < This->nFilters;i++)
5256 {
5257 hr = IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], pClock);
5258 if (FAILED(hr))
5259 break;
5260 }
5261
5262 if (FAILED(hr))
5263 {
5264 for(;i >= 0;i--)
5265 IBaseFilter_SetSyncSource(This->ppFiltersInGraph[i], This->refClock);
5266 }
5267 else
5268 {
5269 if (This->refClock)
5270 IReferenceClock_Release(This->refClock);
5271 This->refClock = pClock;
5272 if (This->refClock)
5273 IReferenceClock_AddRef(This->refClock);
5274 This->defaultclock = FALSE;
5275
5276 if (This->HandleEcClockChanged)
5277 {
5278 IMediaEventSink *pEventSink;
5279 HRESULT eshr;
5280
5281 eshr = IMediaFilter_QueryInterface(iface, &IID_IMediaEventSink, (LPVOID)&pEventSink);
5282 if (SUCCEEDED(eshr))
5283 {
5284 IMediaEventSink_Notify(pEventSink, EC_CLOCK_CHANGED, 0, 0);
5285 IMediaEventSink_Release(pEventSink);
5286 }
5287 }
5288 }
5289 }
5290 LeaveCriticalSection(&This->cs);
5291
5292 return hr;
5293 }
5294
5295 static HRESULT WINAPI MediaFilter_GetSyncSource(IMediaFilter *iface, IReferenceClock **ppClock)
5296 {
5297 IFilterGraphImpl *This = impl_from_IMediaFilter(iface);
5298
5299 TRACE("(%p/%p)->(%p)\n", iface, This, ppClock);
5300
5301 if (!ppClock)
5302 return E_POINTER;
5303
5304 EnterCriticalSection(&This->cs);
5305 {
5306 *ppClock = This->refClock;
5307 if (*ppClock)
5308 IReferenceClock_AddRef(*ppClock);
5309 }
5310 LeaveCriticalSection(&This->cs);
5311
5312 return S_OK;
5313 }
5314
5315 static const IMediaFilterVtbl IMediaFilter_VTable =
5316 {
5317 MediaFilter_QueryInterface,
5318 MediaFilter_AddRef,
5319 MediaFilter_Release,
5320 MediaFilter_GetClassID,
5321 MediaFilter_Stop,
5322 MediaFilter_Pause,
5323 MediaFilter_Run,
5324 MediaFilter_GetState,
5325 MediaFilter_SetSyncSource,
5326 MediaFilter_GetSyncSource
5327 };
5328
5329 static inline IFilterGraphImpl *impl_from_IMediaEventSink(IMediaEventSink *iface)
5330 {
5331 return CONTAINING_RECORD(iface, IFilterGraphImpl, IMediaEventSink_iface);
5332 }
5333
5334 static HRESULT WINAPI MediaEventSink_QueryInterface(IMediaEventSink *iface, REFIID riid, void **ppv)
5335 {
5336 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5337
5338 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5339 }
5340
5341 static ULONG WINAPI MediaEventSink_AddRef(IMediaEventSink *iface)
5342 {
5343 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5344
5345 return IUnknown_AddRef(This->outer_unk);
5346 }
5347
5348 static ULONG WINAPI MediaEventSink_Release(IMediaEventSink *iface)
5349 {
5350 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5351
5352 return IUnknown_Release(This->outer_unk);
5353 }
5354
5355 static HRESULT WINAPI MediaEventSink_Notify(IMediaEventSink *iface, LONG EventCode,
5356 LONG_PTR EventParam1, LONG_PTR EventParam2)
5357 {
5358 IFilterGraphImpl *This = impl_from_IMediaEventSink(iface);
5359 Event evt;
5360
5361 TRACE("(%p/%p)->(%d, %ld, %ld)\n", This, iface, EventCode, EventParam1, EventParam2);
5362
5363 /* We need thread safety here, let's use the events queue's one */
5364 EnterCriticalSection(&This->evqueue.msg_crst);
5365
5366 if ((EventCode == EC_COMPLETE) && This->HandleEcComplete)
5367 {
5368 TRACE("Process EC_COMPLETE notification\n");
5369 if (++This->EcCompleteCount == This->nRenderers)
5370 {
5371 evt.lEventCode = EC_COMPLETE;
5372 evt.lParam1 = S_OK;
5373 evt.lParam2 = 0;
5374 TRACE("Send EC_COMPLETE to app\n");
5375 EventsQueue_PutEvent(&This->evqueue, &evt);
5376 if (!This->notif.disabled && This->notif.hWnd)
5377 {
5378 TRACE("Send Window message\n");
5379 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5380 }
5381 This->CompletionStatus = EC_COMPLETE;
5382 SetEvent(This->hEventCompletion);
5383 }
5384 }
5385 else if ((EventCode == EC_REPAINT) && This->HandleEcRepaint)
5386 {
5387 /* FIXME: Not handled yet */
5388 }
5389 else
5390 {
5391 evt.lEventCode = EventCode;
5392 evt.lParam1 = EventParam1;
5393 evt.lParam2 = EventParam2;
5394 EventsQueue_PutEvent(&This->evqueue, &evt);
5395 if (!This->notif.disabled && This->notif.hWnd)
5396 PostMessageW(This->notif.hWnd, This->notif.msg, 0, This->notif.instance);
5397 }
5398
5399 LeaveCriticalSection(&This->evqueue.msg_crst);
5400 return S_OK;
5401 }
5402
5403 static const IMediaEventSinkVtbl IMediaEventSink_VTable =
5404 {
5405 MediaEventSink_QueryInterface,
5406 MediaEventSink_AddRef,
5407 MediaEventSink_Release,
5408 MediaEventSink_Notify
5409 };
5410
5411 static inline IFilterGraphImpl *impl_from_IGraphConfig(IGraphConfig *iface)
5412 {
5413 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphConfig_iface);
5414 }
5415
5416 static HRESULT WINAPI GraphConfig_QueryInterface(IGraphConfig *iface, REFIID riid, void **ppv)
5417 {
5418 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5419
5420 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5421 }
5422
5423 static ULONG WINAPI GraphConfig_AddRef(IGraphConfig *iface)
5424 {
5425 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5426
5427 return IUnknown_AddRef(This->outer_unk);
5428 }
5429
5430 static ULONG WINAPI GraphConfig_Release(IGraphConfig *iface)
5431 {
5432 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5433
5434 return IUnknown_Release(This->outer_unk);
5435 }
5436
5437 static HRESULT WINAPI GraphConfig_Reconnect(IGraphConfig *iface, IPin *pOutputPin, IPin *pInputPin,
5438 const AM_MEDIA_TYPE *pmtFirstConnection, IBaseFilter *pUsingFilter, HANDLE hAbortEvent,
5439 DWORD dwFlags)
5440 {
5441 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5442
5443 FIXME("(%p)->(%p, %p, %p, %p, %p, %x): stub!\n", This, pOutputPin, pInputPin, pmtFirstConnection, pUsingFilter, hAbortEvent, dwFlags);
5444
5445 return E_NOTIMPL;
5446 }
5447
5448 static HRESULT WINAPI GraphConfig_Reconfigure(IGraphConfig *iface, IGraphConfigCallback *pCallback,
5449 void *pvContext, DWORD dwFlags, HANDLE hAbortEvent)
5450 {
5451 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5452 HRESULT hr;
5453
5454 WARN("(%p)->(%p, %p, %x, %p): partial stub!\n", This, pCallback, pvContext, dwFlags, hAbortEvent);
5455
5456 if (hAbortEvent)
5457 FIXME("The parameter hAbortEvent is not handled!\n");
5458
5459 EnterCriticalSection(&This->cs);
5460
5461 hr = IGraphConfigCallback_Reconfigure(pCallback, pvContext, dwFlags);
5462
5463 LeaveCriticalSection(&This->cs);
5464
5465 return hr;
5466 }
5467
5468 static HRESULT WINAPI GraphConfig_AddFilterToCache(IGraphConfig *iface, IBaseFilter *pFilter)
5469 {
5470 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5471
5472 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5473
5474 return E_NOTIMPL;
5475 }
5476
5477 static HRESULT WINAPI GraphConfig_EnumCacheFilter(IGraphConfig *iface, IEnumFilters **pEnum)
5478 {
5479 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5480
5481 FIXME("(%p)->(%p): stub!\n", This, pEnum);
5482
5483 return E_NOTIMPL;
5484 }
5485
5486 static HRESULT WINAPI GraphConfig_RemoveFilterFromCache(IGraphConfig *iface, IBaseFilter *pFilter)
5487 {
5488 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5489
5490 FIXME("(%p)->(%p): stub!\n", This, pFilter);
5491
5492 return E_NOTIMPL;
5493 }
5494
5495 static HRESULT WINAPI GraphConfig_GetStartTime(IGraphConfig *iface, REFERENCE_TIME *prtStart)
5496 {
5497 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5498
5499 FIXME("(%p)->(%p): stub!\n", This, prtStart);
5500
5501 return E_NOTIMPL;
5502 }
5503
5504 static HRESULT WINAPI GraphConfig_PushThroughData(IGraphConfig *iface, IPin *pOutputPin,
5505 IPinConnection *pConnection, HANDLE hEventAbort)
5506 {
5507 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5508
5509 FIXME("(%p)->(%p, %p, %p): stub!\n", This, pOutputPin, pConnection, hEventAbort);
5510
5511 return E_NOTIMPL;
5512 }
5513
5514 static HRESULT WINAPI GraphConfig_SetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5515 DWORD dwFlags)
5516 {
5517 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5518
5519 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5520
5521 return E_NOTIMPL;
5522 }
5523
5524 static HRESULT WINAPI GraphConfig_GetFilterFlags(IGraphConfig *iface, IBaseFilter *pFilter,
5525 DWORD *dwFlags)
5526 {
5527 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5528
5529 FIXME("(%p)->(%p, %p): stub!\n", This, pFilter, dwFlags);
5530
5531 return E_NOTIMPL;
5532 }
5533
5534 static HRESULT WINAPI GraphConfig_RemoveFilterEx(IGraphConfig *iface, IBaseFilter *pFilter,
5535 DWORD dwFlags)
5536 {
5537 IFilterGraphImpl *This = impl_from_IGraphConfig(iface);
5538
5539 FIXME("(%p)->(%p, %x): stub!\n", This, pFilter, dwFlags);
5540
5541 return E_NOTIMPL;
5542 }
5543
5544 static const IGraphConfigVtbl IGraphConfig_VTable =
5545 {
5546 GraphConfig_QueryInterface,
5547 GraphConfig_AddRef,
5548 GraphConfig_Release,
5549 GraphConfig_Reconnect,
5550 GraphConfig_Reconfigure,
5551 GraphConfig_AddFilterToCache,
5552 GraphConfig_EnumCacheFilter,
5553 GraphConfig_RemoveFilterFromCache,
5554 GraphConfig_GetStartTime,
5555 GraphConfig_PushThroughData,
5556 GraphConfig_SetFilterFlags,
5557 GraphConfig_GetFilterFlags,
5558 GraphConfig_RemoveFilterEx
5559 };
5560
5561 static inline IFilterGraphImpl *impl_from_IGraphVersion(IGraphVersion *iface)
5562 {
5563 return CONTAINING_RECORD(iface, IFilterGraphImpl, IGraphVersion_iface);
5564 }
5565
5566 static HRESULT WINAPI GraphVersion_QueryInterface(IGraphVersion *iface, REFIID riid, void **ppv)
5567 {
5568 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5569
5570 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
5571 }
5572
5573 static ULONG WINAPI GraphVersion_AddRef(IGraphVersion *iface)
5574 {
5575 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5576
5577 return IUnknown_AddRef(This->outer_unk);
5578 }
5579
5580 static ULONG WINAPI GraphVersion_Release(IGraphVersion *iface)
5581 {
5582 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5583
5584 return IUnknown_Release(This->outer_unk);
5585 }
5586
5587 static HRESULT WINAPI GraphVersion_QueryVersion(IGraphVersion *iface, LONG *pVersion)
5588 {
5589 IFilterGraphImpl *This = impl_from_IGraphVersion(iface);
5590
5591 if(!pVersion)
5592 return E_POINTER;
5593
5594 TRACE("(%p)->(%p): current version %i\n", This, pVersion, This->version);
5595
5596 *pVersion = This->version;
5597 return S_OK;
5598 }
5599
5600 static const IGraphVersionVtbl IGraphVersion_VTable =
5601 {
5602 GraphVersion_QueryInterface,
5603 GraphVersion_AddRef,
5604 GraphVersion_Release,
5605 GraphVersion_QueryVersion,
5606 };
5607
5608 static const IUnknownVtbl IInner_VTable =
5609 {
5610 FilterGraphInner_QueryInterface,
5611 FilterGraphInner_AddRef,
5612 FilterGraphInner_Release
5613 };
5614
5615 /* This is the only function that actually creates a FilterGraph class... */
5616 HRESULT FilterGraph_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5617 {
5618 IFilterGraphImpl *fimpl;
5619 HRESULT hr;
5620
5621 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
5622
5623 *ppObj = NULL;
5624
5625 fimpl = CoTaskMemAlloc(sizeof(*fimpl));
5626 fimpl->defaultclock = TRUE;
5627 fimpl->IUnknown_inner.lpVtbl = &IInner_VTable;
5628 fimpl->IFilterGraph2_iface.lpVtbl = &IFilterGraph2_VTable;
5629 fimpl->IMediaControl_iface.lpVtbl = &IMediaControl_VTable;
5630 fimpl->IMediaSeeking_iface.lpVtbl = &IMediaSeeking_VTable;
5631 fimpl->IBasicAudio_iface.lpVtbl = &IBasicAudio_VTable;
5632 fimpl->IBasicVideo2_iface.lpVtbl = &IBasicVideo_VTable;
5633 fimpl->IVideoWindow_iface.lpVtbl = &IVideoWindow_VTable;
5634 fimpl->IMediaEventEx_iface.lpVtbl = &IMediaEventEx_VTable;
5635 fimpl->IMediaFilter_iface.lpVtbl = &IMediaFilter_VTable;
5636 fimpl->IMediaEventSink_iface.lpVtbl = &IMediaEventSink_VTable;
5637 fimpl->IGraphConfig_iface.lpVtbl = &IGraphConfig_VTable;
5638 fimpl->IMediaPosition_iface.lpVtbl = &IMediaPosition_VTable;
5639 fimpl->IObjectWithSite_iface.lpVtbl = &IObjectWithSite_VTable;
5640 fimpl->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
5641 fimpl->ref = 1;
5642 fimpl->ppFiltersInGraph = NULL;
5643 fimpl->pFilterNames = NULL;
5644 fimpl->nFilters = 0;
5645 fimpl->filterCapacity = 0;
5646 fimpl->nameIndex = 1;
5647 fimpl->refClock = NULL;
5648 fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
5649 fimpl->HandleEcComplete = TRUE;
5650 fimpl->HandleEcRepaint = TRUE;
5651 fimpl->HandleEcClockChanged = TRUE;
5652 fimpl->notif.hWnd = 0;
5653 fimpl->notif.disabled = FALSE;
5654 fimpl->nRenderers = 0;
5655 fimpl->EcCompleteCount = 0;
5656 fimpl->refClockProvider = NULL;
5657 fimpl->state = State_Stopped;
5658 fimpl->pSite = NULL;
5659 EventsQueue_Init(&fimpl->evqueue);
5660 InitializeCriticalSection(&fimpl->cs);
5661 fimpl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IFilterGraphImpl.cs");
5662 fimpl->nItfCacheEntries = 0;
5663 memcpy(&fimpl->timeformatseek, &TIME_FORMAT_MEDIA_TIME, sizeof(GUID));
5664 fimpl->start_time = fimpl->pause_time = 0;
5665 fimpl->stop_position = -1;
5666 fimpl->punkFilterMapper2 = NULL;
5667 fimpl->recursioncount = 0;
5668 fimpl->version = 0;
5669
5670 if (pUnkOuter)
5671 fimpl->outer_unk = pUnkOuter;
5672 else
5673 fimpl->outer_unk = &fimpl->IUnknown_inner;
5674
5675 /* create Filtermapper aggregated. */
5676 hr = CoCreateInstance(&CLSID_FilterMapper2, fimpl->outer_unk, CLSCTX_INPROC_SERVER,
5677 &IID_IUnknown, (void**)&fimpl->punkFilterMapper2);
5678
5679 if (SUCCEEDED(hr))
5680 hr = IUnknown_QueryInterface(fimpl->punkFilterMapper2, &IID_IFilterMapper2,
5681 (void**)&fimpl->pFilterMapper2);
5682
5683 if (SUCCEEDED(hr))
5684 /* Release controlling IUnknown - compensate refcount increase from caching IFilterMapper2 interface. */
5685 IUnknown_Release(fimpl->outer_unk);
5686
5687 if (FAILED(hr)) {
5688 ERR("Unable to create filter mapper (%x)\n", hr);
5689 if (fimpl->punkFilterMapper2) IUnknown_Release(fimpl->punkFilterMapper2);
5690 CloseHandle(fimpl->hEventCompletion);
5691 EventsQueue_Destroy(&fimpl->evqueue);
5692 fimpl->cs.DebugInfo->Spare[0] = 0;
5693 DeleteCriticalSection(&fimpl->cs);
5694 CoTaskMemFree(fimpl);
5695 return hr;
5696 }
5697
5698 *ppObj = &fimpl->IUnknown_inner;
5699 return S_OK;
5700 }
5701
5702 HRESULT FilterGraphNoThread_create(IUnknown *pUnkOuter, LPVOID *ppObj)
5703 {
5704 FIXME("CLSID_FilterGraphNoThread partially implemented - Forwarding to CLSID_FilterGraph\n");
5705 return FilterGraph_create(pUnkOuter, ppObj);
5706 }