qcap: Get the SmartTee filter to a minimally functional level.
[wine.git] / dlls / qcap / tests / smartteefilter.c
blob404bcb4e677378cff59606d950ab2ca4ad8cff74
1 /*
2 * SmartTeeFilter tests
4 * Copyright 2015 Damjan Jovanovic
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.
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.
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #define COBJMACROS
27 #include <dshow.h>
28 #include <guiddef.h>
29 #include <devguid.h>
30 #include <stdio.h>
32 #include "wine/strmbase.h"
33 #include "wine/test.h"
35 static HANDLE event;
37 typedef struct {
38 IBaseFilter IBaseFilter_iface;
39 LONG ref;
40 BOOL isCapture;
41 DWORD receiveThreadId;
42 IPin IPin_iface;
43 IMemInputPin IMemInputPin_iface;
44 IMemAllocator *allocator;
45 IBaseFilter *nullRenderer;
46 IPin *nullRendererPin;
47 IMemInputPin *nullRendererMemInputPin;
48 } SinkFilter;
50 typedef struct {
51 IEnumPins IEnumPins_iface;
52 LONG ref;
53 ULONG index;
54 SinkFilter *filter;
55 } SinkEnumPins;
57 static SinkEnumPins* create_SinkEnumPins(SinkFilter *filter);
59 static inline SinkFilter* impl_from_SinkFilter_IBaseFilter(IBaseFilter *iface)
61 return CONTAINING_RECORD(iface, SinkFilter, IBaseFilter_iface);
64 static inline SinkFilter* impl_from_SinkFilter_IPin(IPin *iface)
66 return CONTAINING_RECORD(iface, SinkFilter, IPin_iface);
69 static inline SinkFilter* impl_from_SinkFilter_IMemInputPin(IMemInputPin *iface)
71 return CONTAINING_RECORD(iface, SinkFilter, IMemInputPin_iface);
74 static inline SinkEnumPins* impl_from_SinkFilter_IEnumPins(IEnumPins *iface)
76 return CONTAINING_RECORD(iface, SinkEnumPins, IEnumPins_iface);
79 static HRESULT WINAPI SinkFilter_QueryInterface(IBaseFilter *iface, REFIID riid, void **ppv)
81 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
82 if(IsEqualIID(riid, &IID_IUnknown)) {
83 *ppv = &This->IBaseFilter_iface;
84 } else if(IsEqualIID(riid, &IID_IPersist)) {
85 *ppv = &This->IBaseFilter_iface;
86 } else if(IsEqualIID(riid, &IID_IMediaFilter)) {
87 *ppv = &This->IBaseFilter_iface;
88 } else if(IsEqualIID(riid, &IID_IBaseFilter)) {
89 *ppv = &This->IBaseFilter_iface;
90 } else {
91 trace("no interface for %s\n", wine_dbgstr_guid(riid));
92 *ppv = NULL;
93 return E_NOINTERFACE;
95 IUnknown_AddRef((IUnknown*)*ppv);
96 return S_OK;
99 static ULONG WINAPI SinkFilter_AddRef(IBaseFilter *iface)
101 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
102 return InterlockedIncrement(&This->ref);
105 static ULONG WINAPI SinkFilter_Release(IBaseFilter *iface)
107 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
108 ULONG ref = InterlockedDecrement(&This->ref);
109 if(!ref) {
110 if (This->allocator)
111 IMemAllocator_Release(This->allocator);
112 IMemInputPin_Release(This->nullRendererMemInputPin);
113 IPin_Release(This->nullRendererPin);
114 IBaseFilter_Release(This->nullRenderer);
115 CoTaskMemFree(This);
117 return ref;
120 static HRESULT WINAPI SinkFilter_GetClassID(IBaseFilter *iface, CLSID *pClassID)
122 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
123 return IBaseFilter_GetClassID(This->nullRenderer, pClassID);
126 static HRESULT WINAPI SinkFilter_Stop(IBaseFilter *iface)
128 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
129 return IBaseFilter_Stop(This->nullRenderer);
132 static HRESULT WINAPI SinkFilter_Pause(IBaseFilter *iface)
134 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
135 return IBaseFilter_Pause(This->nullRenderer);
138 static HRESULT WINAPI SinkFilter_Run(IBaseFilter *iface, REFERENCE_TIME tStart)
140 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
141 return IBaseFilter_Run(This->nullRenderer, tStart);
144 static HRESULT WINAPI SinkFilter_GetState(IBaseFilter *iface, DWORD dwMilliSecsTimeout, FILTER_STATE *state)
146 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
147 return IBaseFilter_GetState(This->nullRenderer, dwMilliSecsTimeout, state);
150 static HRESULT WINAPI SinkFilter_SetSyncSource(IBaseFilter *iface, IReferenceClock *pClock)
152 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
153 return IBaseFilter_SetSyncSource(This->nullRenderer, pClock);
156 static HRESULT WINAPI SinkFilter_GetSyncSource(IBaseFilter *iface, IReferenceClock **ppClock)
158 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
159 return IBaseFilter_GetSyncSource(This->nullRenderer, ppClock);
162 static HRESULT WINAPI SinkFilter_EnumPins(IBaseFilter *iface, IEnumPins **ppEnum)
164 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
165 SinkEnumPins *sinkEnumPins = create_SinkEnumPins(This);
166 if (sinkEnumPins) {
167 *ppEnum = &sinkEnumPins->IEnumPins_iface;
168 return S_OK;
170 else
171 return E_OUTOFMEMORY;
174 static HRESULT WINAPI SinkFilter_FindPin(IBaseFilter *iface, LPCWSTR id, IPin **ppPin)
176 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
177 HRESULT hr = IBaseFilter_FindPin(This->nullRenderer, id, ppPin);
178 if (SUCCEEDED(hr)) {
179 IPin_Release(*ppPin);
180 *ppPin = &This->IPin_iface;
181 IPin_AddRef(&This->IPin_iface);
183 return hr;
186 static HRESULT WINAPI SinkFilter_QueryFilterInfo(IBaseFilter *iface, FILTER_INFO *pInfo)
188 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
189 return IBaseFilter_QueryFilterInfo(This->nullRenderer, pInfo);
192 static HRESULT WINAPI SinkFilter_JoinFilterGraph(IBaseFilter *iface, IFilterGraph *pGraph, LPCWSTR pName)
194 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
195 return IBaseFilter_JoinFilterGraph(This->nullRenderer, pGraph, pName);
198 static HRESULT WINAPI SinkFilter_QueryVendorInfo(IBaseFilter *iface, LPWSTR *pVendorInfo)
200 SinkFilter *This = impl_from_SinkFilter_IBaseFilter(iface);
201 return IBaseFilter_QueryVendorInfo(This->nullRenderer, pVendorInfo);
204 static const IBaseFilterVtbl SinkFilterVtbl = {
205 SinkFilter_QueryInterface,
206 SinkFilter_AddRef,
207 SinkFilter_Release,
208 SinkFilter_GetClassID,
209 SinkFilter_Stop,
210 SinkFilter_Pause,
211 SinkFilter_Run,
212 SinkFilter_GetState,
213 SinkFilter_SetSyncSource,
214 SinkFilter_GetSyncSource,
215 SinkFilter_EnumPins,
216 SinkFilter_FindPin,
217 SinkFilter_QueryFilterInfo,
218 SinkFilter_JoinFilterGraph,
219 SinkFilter_QueryVendorInfo
222 static HRESULT WINAPI SinkEnumPins_QueryInterface(IEnumPins *iface, REFIID riid, void **ppv)
224 SinkEnumPins *This = impl_from_SinkFilter_IEnumPins(iface);
225 if(IsEqualIID(riid, &IID_IUnknown)) {
226 *ppv = &This->IEnumPins_iface;
227 } else if(IsEqualIID(riid, &IID_IEnumPins)) {
228 *ppv = &This->IEnumPins_iface;
229 } else {
230 trace("no interface for %s\n", wine_dbgstr_guid(riid));
231 *ppv = NULL;
232 return E_NOINTERFACE;
234 IUnknown_AddRef((IUnknown*)*ppv);
235 return S_OK;
238 static ULONG WINAPI SinkEnumPins_AddRef(IEnumPins *iface)
240 SinkEnumPins *This = impl_from_SinkFilter_IEnumPins(iface);
241 return InterlockedIncrement(&This->ref);
244 static ULONG WINAPI SinkEnumPins_Release(IEnumPins *iface)
246 SinkEnumPins *This = impl_from_SinkFilter_IEnumPins(iface);
247 ULONG ref;
248 ref = InterlockedDecrement(&This->ref);
249 if (ref == 0)
251 IBaseFilter_Release(&This->filter->IBaseFilter_iface);
252 CoTaskMemFree(This);
254 return ref;
257 static HRESULT WINAPI SinkEnumPins_Next(IEnumPins *iface, ULONG cPins, IPin **ppPins, ULONG *pcFetched)
259 SinkEnumPins *This = impl_from_SinkFilter_IEnumPins(iface);
260 if (!ppPins)
261 return E_POINTER;
262 if (cPins > 1 && !pcFetched)
263 return E_INVALIDARG;
264 if (pcFetched)
265 *pcFetched = 0;
266 if (cPins == 0)
267 return S_OK;
268 if (This->index == 0) {
269 ppPins[0] = &This->filter->IPin_iface;
270 IPin_AddRef(&This->filter->IPin_iface);
271 ++This->index;
272 if (pcFetched)
273 *pcFetched = 1;
274 return S_OK;
276 return S_FALSE;
279 static HRESULT WINAPI SinkEnumPins_Skip(IEnumPins *iface, ULONG cPins)
281 SinkEnumPins *This = impl_from_SinkFilter_IEnumPins(iface);
282 if (This->index + cPins >= 1)
283 return S_FALSE;
284 This->index += cPins;
285 return S_OK;
288 static HRESULT WINAPI SinkEnumPins_Reset(IEnumPins *iface)
290 SinkEnumPins *This = impl_from_SinkFilter_IEnumPins(iface);
291 This->index = 0;
292 return S_OK;
295 static HRESULT WINAPI SinkEnumPins_Clone(IEnumPins *iface, IEnumPins **ppEnum)
297 SinkEnumPins *This = impl_from_SinkFilter_IEnumPins(iface);
298 SinkEnumPins *clone = create_SinkEnumPins(This->filter);
299 if (clone == NULL)
300 return E_OUTOFMEMORY;
301 clone->index = This->index;
302 return S_OK;
305 static const IEnumPinsVtbl SinkEnumPinsVtbl = {
306 SinkEnumPins_QueryInterface,
307 SinkEnumPins_AddRef,
308 SinkEnumPins_Release,
309 SinkEnumPins_Next,
310 SinkEnumPins_Skip,
311 SinkEnumPins_Reset,
312 SinkEnumPins_Clone
315 static SinkEnumPins* create_SinkEnumPins(SinkFilter *filter)
317 SinkEnumPins *This;
318 This = CoTaskMemAlloc(sizeof(*This));
319 if (This == NULL) {
320 return NULL;
322 This->IEnumPins_iface.lpVtbl = &SinkEnumPinsVtbl;
323 This->ref = 1;
324 This->index = 0;
325 This->filter = filter;
326 IBaseFilter_AddRef(&filter->IBaseFilter_iface);
327 return This;
330 static HRESULT WINAPI SinkPin_QueryInterface(IPin *iface, REFIID riid, void **ppv)
332 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
333 if(IsEqualIID(riid, &IID_IUnknown)) {
334 *ppv = &This->IPin_iface;
335 } else if(IsEqualIID(riid, &IID_IPin)) {
336 *ppv = &This->IPin_iface;
337 } else if(IsEqualIID(riid, &IID_IMemInputPin)) {
338 *ppv = &This->IMemInputPin_iface;
339 } else {
340 trace("no interface for %s\n", wine_dbgstr_guid(riid));
341 *ppv = NULL;
342 return E_NOINTERFACE;
344 IUnknown_AddRef((IUnknown*)*ppv);
345 return S_OK;
348 static ULONG WINAPI SinkPin_AddRef(IPin *iface)
350 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
351 return IBaseFilter_AddRef(&This->IBaseFilter_iface);
354 static ULONG WINAPI SinkPin_Release(IPin *iface)
356 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
357 return IBaseFilter_Release(&This->IBaseFilter_iface);
360 static HRESULT WINAPI SinkPin_Connect(IPin *iface, IPin *pReceivePin, const AM_MEDIA_TYPE *pmt)
362 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
363 return IPin_Connect(This->nullRendererPin, pReceivePin, pmt);
366 static HRESULT WINAPI SinkPin_ReceiveConnection(IPin *iface, IPin *connector, const AM_MEDIA_TYPE *pmt)
368 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
369 return IPin_ReceiveConnection(This->nullRendererPin, connector, pmt);
372 static HRESULT WINAPI SinkPin_Disconnect(IPin *iface)
374 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
375 return IPin_Disconnect(This->nullRendererPin);
378 static HRESULT WINAPI SinkPin_ConnectedTo(IPin *iface, IPin **pPin)
380 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
381 return IPin_ConnectedTo(This->nullRendererPin, pPin);
384 static HRESULT WINAPI SinkPin_ConnectionMediaType(IPin *iface, AM_MEDIA_TYPE *pmt)
386 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
387 return IPin_ConnectionMediaType(This->nullRendererPin, pmt);
390 static HRESULT WINAPI SinkPin_QueryPinInfo(IPin *iface, PIN_INFO *pInfo)
392 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
393 HRESULT hr = IPin_QueryPinInfo(This->nullRendererPin, pInfo);
394 if (SUCCEEDED(hr)) {
395 IBaseFilter_Release(pInfo->pFilter);
396 pInfo->pFilter = &This->IBaseFilter_iface;
397 IBaseFilter_AddRef(&This->IBaseFilter_iface);
399 return hr;
402 static HRESULT WINAPI SinkPin_QueryDirection(IPin *iface, PIN_DIRECTION *pPinDir)
404 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
405 return IPin_QueryDirection(This->nullRendererPin, pPinDir);
408 static HRESULT WINAPI SinkPin_QueryId(IPin *iface, LPWSTR *id)
410 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
411 return IPin_QueryId(This->nullRendererPin, id);
414 static HRESULT WINAPI SinkPin_QueryAccept(IPin *iface, const AM_MEDIA_TYPE *pmt)
416 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
417 return IPin_QueryAccept(This->nullRendererPin, pmt);
420 static HRESULT WINAPI SinkPin_EnumMediaTypes(IPin *iface, IEnumMediaTypes **ppEnum)
422 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
423 return IPin_EnumMediaTypes(This->nullRendererPin, ppEnum);
426 static HRESULT WINAPI SinkPin_QueryInternalConnections(IPin *iface, IPin **apPin, ULONG *nPin)
428 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
429 return IPin_QueryInternalConnections(This->nullRendererPin, apPin, nPin);
432 static HRESULT WINAPI SinkPin_EndOfStream(IPin *iface)
434 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
435 return IPin_EndOfStream(This->nullRendererPin);
438 static HRESULT WINAPI SinkPin_BeginFlush(IPin *iface)
440 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
441 return IPin_BeginFlush(This->nullRendererPin);
444 static HRESULT WINAPI SinkPin_EndFlush(IPin *iface)
446 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
447 return IPin_EndFlush(This->nullRendererPin);
450 static HRESULT WINAPI SinkPin_NewSegment(IPin *iface, REFERENCE_TIME tStart,
451 REFERENCE_TIME tStop, double dRate)
453 SinkFilter *This = impl_from_SinkFilter_IPin(iface);
454 return IPin_NewSegment(This->nullRendererPin, tStart, tStop, dRate);
457 static const IPinVtbl SinkPinVtbl = {
458 SinkPin_QueryInterface,
459 SinkPin_AddRef,
460 SinkPin_Release,
461 SinkPin_Connect,
462 SinkPin_ReceiveConnection,
463 SinkPin_Disconnect,
464 SinkPin_ConnectedTo,
465 SinkPin_ConnectionMediaType,
466 SinkPin_QueryPinInfo,
467 SinkPin_QueryDirection,
468 SinkPin_QueryId,
469 SinkPin_QueryAccept,
470 SinkPin_EnumMediaTypes,
471 SinkPin_QueryInternalConnections,
472 SinkPin_EndOfStream,
473 SinkPin_BeginFlush,
474 SinkPin_EndFlush,
475 SinkPin_NewSegment
478 static HRESULT WINAPI SinkMemInputPin_QueryInterface(IMemInputPin *iface, REFIID riid, void **ppv)
480 SinkFilter *This = impl_from_SinkFilter_IMemInputPin(iface);
481 return IPin_QueryInterface(&This->IPin_iface, riid, ppv);
484 static ULONG WINAPI SinkMemInputPin_AddRef(IMemInputPin *iface)
486 SinkFilter *This = impl_from_SinkFilter_IMemInputPin(iface);
487 return IBaseFilter_AddRef(&This->IBaseFilter_iface);
490 static ULONG WINAPI SinkMemInputPin_Release(IMemInputPin *iface)
492 SinkFilter *This = impl_from_SinkFilter_IMemInputPin(iface);
493 return IBaseFilter_Release(&This->IBaseFilter_iface);
496 static HRESULT WINAPI SinkMemInputPin_GetAllocator(IMemInputPin *iface, IMemAllocator **ppAllocator)
498 SinkFilter *This = impl_from_SinkFilter_IMemInputPin(iface);
499 ok(0, "SmartTeeFilter never calls IMemInputPin_GetAllocator()\n");
500 return IMemInputPin_GetAllocator(This->nullRendererMemInputPin, ppAllocator);
503 static HRESULT WINAPI SinkMemInputPin_NotifyAllocator(IMemInputPin *iface, IMemAllocator *pAllocator,
504 BOOL bReadOnly)
506 SinkFilter *This = impl_from_SinkFilter_IMemInputPin(iface);
507 This->allocator = pAllocator;
508 IMemAllocator_AddRef(This->allocator);
509 ok(bReadOnly, "bReadOnly isn't supposed to be FALSE\n");
510 return IMemInputPin_NotifyAllocator(This->nullRendererMemInputPin, pAllocator, bReadOnly);
513 static HRESULT WINAPI SinkMemInputPin_GetAllocatorRequirements(IMemInputPin *iface,
514 ALLOCATOR_PROPERTIES *pProps)
516 SinkFilter *This = impl_from_SinkFilter_IMemInputPin(iface);
517 ok(0, "SmartTeeFilter never calls IMemInputPin_GetAllocatorRequirements()\n");
518 return IMemInputPin_GetAllocatorRequirements(This->nullRendererMemInputPin, pProps);
521 static HRESULT WINAPI SinkMemInputPin_Receive(IMemInputPin *iface, IMediaSample *pSample)
523 LONG samplesProcessed;
524 todo_wine ok(0, "SmartTeeFilter never calls IMemInputPin_Receive(), only IMemInputPin_ReceiveMultiple()\n");
525 return IMemInputPin_ReceiveMultiple(iface, &pSample, 1, &samplesProcessed);
528 static HRESULT WINAPI SinkMemInputPin_ReceiveMultiple(IMemInputPin *iface, IMediaSample **pSamples,
529 LONG nSamples, LONG *nSamplesProcessed)
531 SinkFilter *This = impl_from_SinkFilter_IMemInputPin(iface);
532 IMediaSample *pSample;
533 REFERENCE_TIME startTime, endTime;
534 HRESULT hr;
535 ok(nSamples == 1, "expected 1 sample, got %d\n", nSamples);
536 pSample = pSamples[0];
537 hr = IMediaSample_GetTime(pSample, &startTime, &endTime);
538 if (This->isCapture)
539 ok(SUCCEEDED(hr), "IMediaSample_GetTime() from Capture pin failed, hr=0x%08x\n", hr);
540 else
541 ok(hr == VFW_E_SAMPLE_TIME_NOT_SET, "IMediaSample_GetTime() from Preview pin returned hr=0x%08x\n", hr);
542 This->receiveThreadId = GetCurrentThreadId();
543 SetEvent(event);
544 return IMemInputPin_ReceiveMultiple(This->nullRendererMemInputPin, pSamples,
545 nSamples, nSamplesProcessed);
548 static HRESULT WINAPI SinkMemInputPin_ReceiveCanBlock(IMemInputPin *iface)
550 SinkFilter *This = impl_from_SinkFilter_IMemInputPin(iface);
551 return IMemInputPin_ReceiveCanBlock(This->nullRendererMemInputPin);
554 static const IMemInputPinVtbl SinkMemInputPinVtbl = {
555 SinkMemInputPin_QueryInterface,
556 SinkMemInputPin_AddRef,
557 SinkMemInputPin_Release,
558 SinkMemInputPin_GetAllocator,
559 SinkMemInputPin_NotifyAllocator,
560 SinkMemInputPin_GetAllocatorRequirements,
561 SinkMemInputPin_Receive,
562 SinkMemInputPin_ReceiveMultiple,
563 SinkMemInputPin_ReceiveCanBlock
566 static SinkFilter* create_SinkFilter(BOOL isCapture)
568 SinkFilter *This = NULL;
569 HRESULT hr;
570 This = CoTaskMemAlloc(sizeof(*This));
571 if (This) {
572 memset(This, 0, sizeof(*This));
573 This->IBaseFilter_iface.lpVtbl = &SinkFilterVtbl;
574 This->ref = 1;
575 This->isCapture = isCapture;
576 This->IPin_iface.lpVtbl = &SinkPinVtbl;
577 This->IMemInputPin_iface.lpVtbl = &SinkMemInputPinVtbl;
578 hr = CoCreateInstance(&CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER,
579 &IID_IBaseFilter, (LPVOID*)&This->nullRenderer);
580 if (SUCCEEDED(hr)) {
581 IEnumPins *enumPins = NULL;
582 hr = IBaseFilter_EnumPins(This->nullRenderer, &enumPins);
583 if (SUCCEEDED(hr)) {
584 hr = IEnumPins_Next(enumPins, 1, &This->nullRendererPin, NULL);
585 IEnumPins_Release(enumPins);
586 if (SUCCEEDED(hr)) {
587 hr = IPin_QueryInterface(This->nullRendererPin, &IID_IMemInputPin,
588 (LPVOID*)&This->nullRendererMemInputPin);
589 if (SUCCEEDED(hr))
590 return This;
591 IPin_Release(This->nullRendererPin);
594 IBaseFilter_Release(This->nullRenderer);
596 CoTaskMemFree(This);
598 return NULL;
601 typedef struct {
602 IBaseFilter IBaseFilter_iface;
603 LONG ref;
604 IPin IPin_iface;
605 CRITICAL_SECTION cs;
606 FILTER_STATE state;
607 IReferenceClock *referenceClock;
608 FILTER_INFO filterInfo;
609 AM_MEDIA_TYPE mediaType;
610 VIDEOINFOHEADER videoInfo;
611 IPin *connectedTo;
612 IMemInputPin *memInputPin;
613 IMemAllocator *allocator;
614 DWORD mediaThreadId;
615 } SourceFilter;
617 typedef struct {
618 IEnumPins IEnumPins_iface;
619 LONG ref;
620 ULONG index;
621 SourceFilter *filter;
622 } SourceEnumPins;
624 static const WCHAR sourcePinName[] = {'C','a','p','t','u','r','e',0};
626 static SourceEnumPins* create_SourceEnumPins(SourceFilter *filter);
628 static inline SourceFilter* impl_from_SourceFilter_IBaseFilter(IBaseFilter *iface)
630 return CONTAINING_RECORD(iface, SourceFilter, IBaseFilter_iface);
633 static inline SourceFilter* impl_from_SourceFilter_IPin(IPin *iface)
635 return CONTAINING_RECORD(iface, SourceFilter, IPin_iface);
638 static inline SourceEnumPins* impl_from_SourceFilter_IEnumPins(IEnumPins *iface)
640 return CONTAINING_RECORD(iface, SourceEnumPins, IEnumPins_iface);
643 static HRESULT WINAPI SourceFilter_QueryInterface(IBaseFilter *iface, REFIID riid, void **ppv)
645 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
646 if(IsEqualIID(riid, &IID_IUnknown)) {
647 *ppv = &This->IBaseFilter_iface;
648 } else if(IsEqualIID(riid, &IID_IPersist)) {
649 *ppv = &This->IBaseFilter_iface;
650 } else if(IsEqualIID(riid, &IID_IMediaFilter)) {
651 *ppv = &This->IBaseFilter_iface;
652 } else if(IsEqualIID(riid, &IID_IBaseFilter)) {
653 *ppv = &This->IBaseFilter_iface;
654 } else {
655 trace("no interface for %s\n", wine_dbgstr_guid(riid));
656 *ppv = NULL;
657 return E_NOINTERFACE;
659 IUnknown_AddRef((IUnknown*)*ppv);
660 return S_OK;
663 static ULONG WINAPI SourceFilter_AddRef(IBaseFilter *iface)
665 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
666 return InterlockedIncrement(&This->ref);
669 static ULONG WINAPI SourceFilter_Release(IBaseFilter *iface)
671 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
672 ULONG ref = InterlockedDecrement(&This->ref);
673 if(!ref) {
674 if (This->referenceClock)
675 IReferenceClock_Release(This->referenceClock);
676 if (This->connectedTo)
677 IPin_Disconnect(&This->IPin_iface);
678 DeleteCriticalSection(&This->cs);
679 CoTaskMemFree(This);
681 return ref;
684 static HRESULT WINAPI SourceFilter_GetClassID(IBaseFilter *iface, CLSID *pClassID)
686 *pClassID = CLSID_VfwCapture;
687 return S_OK;
690 static HRESULT WINAPI SourceFilter_Stop(IBaseFilter *iface)
692 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
693 EnterCriticalSection(&This->cs);
694 IMemAllocator_Decommit(This->allocator);
695 This->state = State_Stopped;
696 LeaveCriticalSection(&This->cs);
697 return S_OK;
700 static HRESULT WINAPI SourceFilter_Pause(IBaseFilter *iface)
702 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
703 EnterCriticalSection(&This->cs);
704 This->state = State_Paused;
705 LeaveCriticalSection(&This->cs);
706 return S_OK;
709 static DWORD WINAPI media_thread(LPVOID param)
711 SourceFilter *This = (SourceFilter*) param;
712 HRESULT hr;
713 IMediaSample *sample = NULL;
714 REFERENCE_TIME startTime;
715 REFERENCE_TIME endTime;
716 BYTE *buffer;
718 hr = IMemAllocator_GetBuffer(This->allocator, &sample, NULL, NULL, 0);
719 ok(SUCCEEDED(hr), "IMemAllocator_GetBuffer() failed, hr=0x%08x\n", hr);
720 if (SUCCEEDED(hr)) {
721 startTime = 10;
722 endTime = 20;
723 hr = IMediaSample_SetTime(sample, &startTime, &endTime);
724 ok(SUCCEEDED(hr), "IMediaSample_SetTime() failed, hr=0x%08x\n", hr);
725 hr = IMediaSample_SetMediaType(sample, &This->mediaType);
726 ok(SUCCEEDED(hr), "IMediaSample_SetMediaType() failed, hr=0x%08x\n", hr);
728 hr = IMediaSample_GetPointer(sample, &buffer);
729 ok(SUCCEEDED(hr), "IMediaSample_GetPointer() failed, hr=0x%08x\n", hr);
730 if (SUCCEEDED(hr)) {
731 /* 10 by 10 pixel 32 RGB */
732 int i;
733 for (i = 0; i < 100; i++)
734 buffer[4*i] = i;
737 hr = IMemInputPin_Receive(This->memInputPin, sample);
738 ok(SUCCEEDED(hr), "delivering sample to SmartTeeFilter's Input pin failed, hr=0x%08x\n", hr);
740 IMediaSample_Release(sample);
742 return 0;
745 static HRESULT WINAPI SourceFilter_Run(IBaseFilter *iface, REFERENCE_TIME tStart)
747 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
748 HRESULT hr;
749 EnterCriticalSection(&This->cs);
750 hr = IMemAllocator_Commit(This->allocator);
751 if (SUCCEEDED(hr)) {
752 HANDLE thread = CreateThread(NULL, 0, media_thread, This, 0, &This->mediaThreadId);
753 ok(thread != NULL, "couldn't create media thread, GetLastError()=%u\n", GetLastError());
754 if (thread != NULL) {
755 CloseHandle(thread);
756 This->state = State_Running;
757 } else {
758 IMemAllocator_Decommit(This->allocator);
759 hr = E_FAIL;
762 LeaveCriticalSection(&This->cs);
763 return hr;
766 static HRESULT WINAPI SourceFilter_GetState(IBaseFilter *iface, DWORD dwMilliSecsTimeout, FILTER_STATE *state)
768 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
769 EnterCriticalSection(&This->cs);
770 *state = This->state;
771 LeaveCriticalSection(&This->cs);
772 return S_OK;
775 static HRESULT WINAPI SourceFilter_SetSyncSource(IBaseFilter *iface, IReferenceClock *pClock)
777 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
778 EnterCriticalSection(&This->cs);
779 if (This->referenceClock)
780 IReferenceClock_Release(This->referenceClock);
781 This->referenceClock = pClock;
782 if (This->referenceClock)
783 IReferenceClock_AddRef(This->referenceClock);
784 LeaveCriticalSection(&This->cs);
785 return S_OK;
788 static HRESULT WINAPI SourceFilter_GetSyncSource(IBaseFilter *iface, IReferenceClock **ppClock)
790 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
791 EnterCriticalSection(&This->cs);
792 *ppClock = This->referenceClock;
793 if (This->referenceClock)
794 IReferenceClock_AddRef(This->referenceClock);
795 LeaveCriticalSection(&This->cs);
796 return S_OK;
799 static HRESULT WINAPI SourceFilter_EnumPins(IBaseFilter *iface, IEnumPins **ppEnum)
801 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
802 SourceEnumPins *sourceEnumPins = create_SourceEnumPins(This);
803 if (sourceEnumPins) {
804 *ppEnum = &sourceEnumPins->IEnumPins_iface;
805 return S_OK;
807 else
808 return E_OUTOFMEMORY;
811 static HRESULT WINAPI SourceFilter_FindPin(IBaseFilter *iface, LPCWSTR id, IPin **ppPin)
813 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
814 if (ppPin == NULL)
815 return E_POINTER;
816 *ppPin = NULL;
817 if (lstrcmpW(id, sourcePinName) == 0) {
818 *ppPin = &This->IPin_iface;
819 IPin_AddRef(&This->IPin_iface);
820 return S_OK;
822 return VFW_E_NOT_FOUND;
825 static HRESULT WINAPI SourceFilter_QueryFilterInfo(IBaseFilter *iface, FILTER_INFO *pInfo)
827 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
828 if (!pInfo)
829 return E_POINTER;
830 EnterCriticalSection(&This->cs);
831 *pInfo = This->filterInfo;
832 if (This->filterInfo.pGraph)
833 IFilterGraph_AddRef(This->filterInfo.pGraph);
834 LeaveCriticalSection(&This->cs);
835 return S_OK;
838 static HRESULT WINAPI SourceFilter_JoinFilterGraph(IBaseFilter *iface, IFilterGraph *pGraph, LPCWSTR pName)
840 SourceFilter *This = impl_from_SourceFilter_IBaseFilter(iface);
841 EnterCriticalSection(&This->cs);
842 if (pName)
843 lstrcpyW(This->filterInfo.achName, pName);
844 else
845 This->filterInfo.achName[0] = 0;
846 This->filterInfo.pGraph = pGraph;
847 LeaveCriticalSection(&This->cs);
848 return S_OK;
851 static HRESULT WINAPI SourceFilter_QueryVendorInfo(IBaseFilter *iface, LPWSTR *pVendorInfo)
853 return E_NOTIMPL;
856 static const IBaseFilterVtbl SourceFilterVtbl = {
857 SourceFilter_QueryInterface,
858 SourceFilter_AddRef,
859 SourceFilter_Release,
860 SourceFilter_GetClassID,
861 SourceFilter_Stop,
862 SourceFilter_Pause,
863 SourceFilter_Run,
864 SourceFilter_GetState,
865 SourceFilter_SetSyncSource,
866 SourceFilter_GetSyncSource,
867 SourceFilter_EnumPins,
868 SourceFilter_FindPin,
869 SourceFilter_QueryFilterInfo,
870 SourceFilter_JoinFilterGraph,
871 SourceFilter_QueryVendorInfo
874 static HRESULT WINAPI SourceEnumPins_QueryInterface(IEnumPins *iface, REFIID riid, void **ppv)
876 SourceEnumPins *This = impl_from_SourceFilter_IEnumPins(iface);
877 if(IsEqualIID(riid, &IID_IUnknown)) {
878 *ppv = &This->IEnumPins_iface;
879 } else if(IsEqualIID(riid, &IID_IEnumPins)) {
880 *ppv = &This->IEnumPins_iface;
881 } else {
882 trace("no interface for %s\n", wine_dbgstr_guid(riid));
883 *ppv = NULL;
884 return E_NOINTERFACE;
886 IUnknown_AddRef((IUnknown*)*ppv);
887 return S_OK;
890 static ULONG WINAPI SourceEnumPins_AddRef(IEnumPins *iface)
892 SourceEnumPins *This = impl_from_SourceFilter_IEnumPins(iface);
893 return InterlockedIncrement(&This->ref);
896 static ULONG WINAPI SourceEnumPins_Release(IEnumPins *iface)
898 SourceEnumPins *This = impl_from_SourceFilter_IEnumPins(iface);
899 ULONG ref;
900 ref = InterlockedDecrement(&This->ref);
901 if (ref == 0)
903 IBaseFilter_Release(&This->filter->IBaseFilter_iface);
904 CoTaskMemFree(This);
906 return ref;
909 static HRESULT WINAPI SourceEnumPins_Next(IEnumPins *iface, ULONG cPins, IPin **ppPins, ULONG *pcFetched)
911 SourceEnumPins *This = impl_from_SourceFilter_IEnumPins(iface);
912 if (!ppPins)
913 return E_POINTER;
914 if (cPins > 1 && !pcFetched)
915 return E_INVALIDARG;
916 if (pcFetched)
917 *pcFetched = 0;
918 if (cPins == 0)
919 return S_OK;
920 if (This->index == 0) {
921 ppPins[0] = &This->filter->IPin_iface;
922 IPin_AddRef(&This->filter->IPin_iface);
923 ++This->index;
924 if (pcFetched)
925 *pcFetched = 1;
926 return S_OK;
928 return S_FALSE;
931 static HRESULT WINAPI SourceEnumPins_Skip(IEnumPins *iface, ULONG cPins)
933 SourceEnumPins *This = impl_from_SourceFilter_IEnumPins(iface);
934 if (This->index + cPins >= 1)
935 return S_FALSE;
936 This->index += cPins;
937 return S_OK;
940 static HRESULT WINAPI SourceEnumPins_Reset(IEnumPins *iface)
942 SourceEnumPins *This = impl_from_SourceFilter_IEnumPins(iface);
943 This->index = 0;
944 return S_OK;
947 static HRESULT WINAPI SourceEnumPins_Clone(IEnumPins *iface, IEnumPins **ppEnum)
949 SourceEnumPins *This = impl_from_SourceFilter_IEnumPins(iface);
950 SourceEnumPins *clone = create_SourceEnumPins(This->filter);
951 if (clone == NULL)
952 return E_OUTOFMEMORY;
953 clone->index = This->index;
954 return S_OK;
957 static const IEnumPinsVtbl SourceEnumPinsVtbl = {
958 SourceEnumPins_QueryInterface,
959 SourceEnumPins_AddRef,
960 SourceEnumPins_Release,
961 SourceEnumPins_Next,
962 SourceEnumPins_Skip,
963 SourceEnumPins_Reset,
964 SourceEnumPins_Clone
967 static SourceEnumPins* create_SourceEnumPins(SourceFilter *filter)
969 SourceEnumPins *This;
970 This = CoTaskMemAlloc(sizeof(*This));
971 if (This == NULL) {
972 return NULL;
974 This->IEnumPins_iface.lpVtbl = &SourceEnumPinsVtbl;
975 This->ref = 1;
976 This->index = 0;
977 This->filter = filter;
978 IBaseFilter_AddRef(&filter->IBaseFilter_iface);
979 return This;
982 static HRESULT WINAPI SourcePin_QueryInterface(IPin *iface, REFIID riid, void **ppv)
984 SourceFilter *This = impl_from_SourceFilter_IPin(iface);
985 if(IsEqualIID(riid, &IID_IUnknown)) {
986 *ppv = &This->IPin_iface;
987 } else if(IsEqualIID(riid, &IID_IPin)) {
988 *ppv = &This->IPin_iface;
989 } else {
990 trace("no interface for %s\n", wine_dbgstr_guid(riid));
991 *ppv = NULL;
992 return E_NOINTERFACE;
994 IUnknown_AddRef((IUnknown*)*ppv);
995 return S_OK;
998 static ULONG WINAPI SourcePin_AddRef(IPin *iface)
1000 SourceFilter *This = impl_from_SourceFilter_IPin(iface);
1001 return IBaseFilter_AddRef(&This->IBaseFilter_iface);
1004 static ULONG WINAPI SourcePin_Release(IPin *iface)
1006 SourceFilter *This = impl_from_SourceFilter_IPin(iface);
1007 return IBaseFilter_Release(&This->IBaseFilter_iface);
1010 static HRESULT WINAPI SourcePin_Connect(IPin *iface, IPin *pReceivePin, const AM_MEDIA_TYPE *pmt)
1012 SourceFilter *This = impl_from_SourceFilter_IPin(iface);
1013 HRESULT hr;
1014 if (pmt && !IsEqualGUID(&pmt->majortype, &GUID_NULL) && !IsEqualGUID(&pmt->majortype, &MEDIATYPE_Video))
1015 return VFW_E_TYPE_NOT_ACCEPTED;
1016 if (pmt && !IsEqualGUID(&pmt->subtype, &GUID_NULL) && !IsEqualGUID(&pmt->subtype, &MEDIASUBTYPE_RGB32))
1017 return VFW_E_TYPE_NOT_ACCEPTED;
1018 if (pmt && !IsEqualGUID(&pmt->formattype, &GUID_NULL))
1019 return VFW_E_TYPE_NOT_ACCEPTED;
1020 hr = IPin_ReceiveConnection(pReceivePin, &This->IPin_iface, &This->mediaType);
1021 ok(SUCCEEDED(hr), "SmartTeeFilter's Input pin's IPin_ReceiveConnection() failed with 0x%08x\n", hr);
1022 if (SUCCEEDED(hr)) {
1023 EnterCriticalSection(&This->cs);
1024 hr = IPin_QueryInterface(pReceivePin, &IID_IMemInputPin, (void**)&This->memInputPin);
1025 if (SUCCEEDED(hr)) {
1026 hr = IMemInputPin_GetAllocator(This->memInputPin, &This->allocator);
1027 ok(SUCCEEDED(hr), "couldn't get allocator from SmartTeeFilter, hr=0x%08x\n", hr);
1028 if (SUCCEEDED(hr)) {
1029 ALLOCATOR_PROPERTIES requested, actual;
1030 ZeroMemory(&requested, sizeof(ALLOCATOR_PROPERTIES));
1031 IMemInputPin_GetAllocatorRequirements(This->memInputPin, &requested);
1032 if (requested.cBuffers < 3) requested.cBuffers = 3;
1033 if (requested.cbBuffer < 4096) requested.cbBuffer = 4096;
1034 if (requested.cbAlign < 1) requested.cbAlign = 1;
1035 if (requested.cbPrefix < 0) requested.cbPrefix = 0;
1036 hr = IMemAllocator_SetProperties(This->allocator, &requested, &actual);
1037 if (SUCCEEDED(hr)) {
1038 hr = IMemInputPin_NotifyAllocator(This->memInputPin, This->allocator, FALSE);
1039 if (SUCCEEDED(hr)) {
1040 This->connectedTo = pReceivePin;
1041 IPin_AddRef(pReceivePin);
1044 if (FAILED(hr)) {
1045 IMemAllocator_Release(This->allocator);
1046 This->allocator = NULL;
1049 if (FAILED(hr)) {
1050 IMemInputPin_Release(This->memInputPin);
1051 This->memInputPin = NULL;
1054 LeaveCriticalSection(&This->cs);
1056 if (FAILED(hr))
1057 IPin_Disconnect(pReceivePin);
1059 return hr;
1062 static HRESULT WINAPI SourcePin_ReceiveConnection(IPin *iface, IPin *connector, const AM_MEDIA_TYPE *pmt)
1064 return E_UNEXPECTED;
1067 static HRESULT WINAPI SourcePin_Disconnect(IPin *iface)
1069 SourceFilter *This = impl_from_SourceFilter_IPin(iface);
1070 HRESULT hr;
1071 EnterCriticalSection(&This->cs);
1072 if (This->connectedTo) {
1073 if (This->state == State_Stopped) {
1074 IMemAllocator_Release(This->allocator);
1075 This->allocator = NULL;
1076 IMemInputPin_Release(This->memInputPin);
1077 This->memInputPin = NULL;
1078 IPin_Release(This->connectedTo);
1079 This->connectedTo = NULL;
1080 hr = S_OK;
1082 else
1083 hr = VFW_E_NOT_STOPPED;
1084 } else
1085 hr = S_FALSE;
1086 LeaveCriticalSection(&This->cs);
1087 return hr;
1090 static HRESULT WINAPI SourcePin_ConnectedTo(IPin *iface, IPin **pPin)
1092 SourceFilter *This = impl_from_SourceFilter_IPin(iface);
1093 HRESULT hr;
1094 if (!pPin)
1095 return E_POINTER;
1096 EnterCriticalSection(&This->cs);
1097 if (This->connectedTo) {
1098 *pPin = This->connectedTo;
1099 IPin_AddRef(This->connectedTo);
1100 hr = S_OK;
1101 } else
1102 hr = VFW_E_NOT_CONNECTED;
1103 LeaveCriticalSection(&This->cs);
1104 return hr;
1107 static HRESULT WINAPI SourcePin_ConnectionMediaType(IPin *iface, AM_MEDIA_TYPE *pmt)
1109 SourceFilter *This = impl_from_SourceFilter_IPin(iface);
1110 HRESULT hr;
1111 if (!pmt)
1112 return E_POINTER;
1113 EnterCriticalSection(&This->cs);
1114 if (This->connectedTo) {
1115 *pmt = This->mediaType;
1116 pmt->pbFormat = CoTaskMemAlloc(sizeof(This->videoInfo));
1117 if (pmt->pbFormat) {
1118 memcpy(pmt->pbFormat, &This->videoInfo, sizeof(This->videoInfo));
1119 hr = S_OK;
1120 } else {
1121 memset(pmt, 0, sizeof(*pmt));
1122 hr = E_OUTOFMEMORY;
1124 } else {
1125 memset(pmt, 0, sizeof(*pmt));
1126 hr = VFW_E_NOT_CONNECTED;
1128 LeaveCriticalSection(&This->cs);
1129 return hr;
1132 static HRESULT WINAPI SourcePin_QueryPinInfo(IPin *iface, PIN_INFO *pInfo)
1134 SourceFilter *This = impl_from_SourceFilter_IPin(iface);
1135 if (!pInfo)
1136 return E_POINTER;
1137 lstrcpyW(pInfo->achName, sourcePinName);
1138 pInfo->dir = PINDIR_OUTPUT;
1139 pInfo->pFilter = &This->IBaseFilter_iface;
1140 IBaseFilter_AddRef(&This->IBaseFilter_iface);
1141 return S_OK;
1144 static HRESULT WINAPI SourcePin_QueryDirection(IPin *iface, PIN_DIRECTION *pPinDir)
1146 if (!pPinDir)
1147 return E_POINTER;
1148 *pPinDir = PINDIR_OUTPUT;
1149 return S_OK;
1152 static HRESULT WINAPI SourcePin_QueryId(IPin *iface, LPWSTR *id)
1154 if (!id)
1155 return E_POINTER;
1156 *id = CoTaskMemAlloc((lstrlenW(sourcePinName) + 1)*sizeof(WCHAR));
1157 if (*id) {
1158 lstrcpyW(*id, sourcePinName);
1159 return S_OK;
1161 return E_OUTOFMEMORY;
1164 static HRESULT WINAPI SourcePin_QueryAccept(IPin *iface, const AM_MEDIA_TYPE *pmt)
1166 return S_OK;
1169 static HRESULT WINAPI SourcePin_EnumMediaTypes(IPin *iface, IEnumMediaTypes **ppEnum)
1171 return VFW_E_NOT_CONNECTED;
1174 static HRESULT WINAPI SourcePin_QueryInternalConnections(IPin *iface, IPin **apPin, ULONG *nPin)
1176 return E_NOTIMPL;
1179 static HRESULT WINAPI SourcePin_EndOfStream(IPin *iface)
1181 return E_UNEXPECTED;
1184 static HRESULT WINAPI SourcePin_BeginFlush(IPin *iface)
1186 return E_UNEXPECTED;
1189 static HRESULT WINAPI SourcePin_EndFlush(IPin *iface)
1191 return E_UNEXPECTED;
1194 static HRESULT WINAPI SourcePin_NewSegment(IPin *iface, REFERENCE_TIME tStart,
1195 REFERENCE_TIME tStop, double dRate)
1197 return S_OK;
1200 static const IPinVtbl SourcePinVtbl = {
1201 SourcePin_QueryInterface,
1202 SourcePin_AddRef,
1203 SourcePin_Release,
1204 SourcePin_Connect,
1205 SourcePin_ReceiveConnection,
1206 SourcePin_Disconnect,
1207 SourcePin_ConnectedTo,
1208 SourcePin_ConnectionMediaType,
1209 SourcePin_QueryPinInfo,
1210 SourcePin_QueryDirection,
1211 SourcePin_QueryId,
1212 SourcePin_QueryAccept,
1213 SourcePin_EnumMediaTypes,
1214 SourcePin_QueryInternalConnections,
1215 SourcePin_EndOfStream,
1216 SourcePin_BeginFlush,
1217 SourcePin_EndFlush,
1218 SourcePin_NewSegment
1221 static SourceFilter* create_SourceFilter(void)
1223 SourceFilter *This = NULL;
1224 This = CoTaskMemAlloc(sizeof(*This));
1225 if (This) {
1226 memset(This, 0, sizeof(*This));
1227 This->IBaseFilter_iface.lpVtbl = &SourceFilterVtbl;
1228 This->ref = 1;
1229 This->IPin_iface.lpVtbl = &SourcePinVtbl;
1230 InitializeCriticalSection(&This->cs);
1231 This->mediaType.majortype = MEDIATYPE_Video;
1232 This->mediaType.subtype = MEDIASUBTYPE_RGB32;
1233 This->mediaType.bFixedSizeSamples = FALSE;
1234 This->mediaType.bTemporalCompression = FALSE;
1235 This->mediaType.lSampleSize = 0;
1236 This->mediaType.formattype = FORMAT_VideoInfo;
1237 This->mediaType.pUnk = NULL;
1238 This->mediaType.cbFormat = sizeof(VIDEOINFOHEADER);
1239 This->mediaType.pbFormat = (BYTE*) &This->videoInfo;
1240 This->videoInfo.dwBitRate = 1000000;
1241 This->videoInfo.dwBitErrorRate = 0;
1242 This->videoInfo.AvgTimePerFrame = 400000;
1243 This->videoInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1244 This->videoInfo.bmiHeader.biWidth = 10;
1245 This->videoInfo.bmiHeader.biHeight = 10;
1246 This->videoInfo.bmiHeader.biPlanes = 1;
1247 This->videoInfo.bmiHeader.biBitCount = 32;
1248 This->videoInfo.bmiHeader.biCompression = BI_RGB;
1249 This->videoInfo.bmiHeader.biSizeImage = 0;
1250 This->videoInfo.bmiHeader.biXPelsPerMeter = 96;
1251 This->videoInfo.bmiHeader.biYPelsPerMeter = 96;
1252 This->videoInfo.bmiHeader.biClrUsed = 0;
1253 This->videoInfo.bmiHeader.biClrImportant = 0;
1254 return This;
1256 return NULL;
1259 static BOOL has_interface(IUnknown *unknown, REFIID uuid)
1261 HRESULT hr;
1262 IUnknown *iface = NULL;
1264 hr = IUnknown_QueryInterface(unknown, uuid, (void**)&iface);
1265 if (SUCCEEDED(hr))
1267 IUnknown_Release(iface);
1268 return TRUE;
1270 else
1271 return FALSE;
1274 static void test_smart_tee_filter_in_graph(IBaseFilter *smartTeeFilter, IPin *inputPin,
1275 IPin *capturePin, IPin *previewPin)
1277 HRESULT hr;
1278 IGraphBuilder *graphBuilder = NULL;
1279 IMediaControl *mediaControl = NULL;
1280 SourceFilter *sourceFilter = NULL;
1281 SinkFilter *captureSinkFilter = NULL;
1282 SinkFilter *previewSinkFilter = NULL;
1283 DWORD endTime;
1285 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder,
1286 (LPVOID*)&graphBuilder);
1287 ok(SUCCEEDED(hr), "couldn't create graph builder, hr=0x%08x\n", hr);
1288 if (FAILED(hr))
1289 goto end;
1291 hr = IGraphBuilder_AddFilter(graphBuilder, smartTeeFilter, NULL);
1292 ok(SUCCEEDED(hr), "couldn't add smart tee filter to graph, hr=0x%08x\n", hr);
1293 if (FAILED(hr))
1294 goto end;
1296 captureSinkFilter = create_SinkFilter(TRUE);
1297 if (captureSinkFilter == NULL) {
1298 skip("couldn't create capture sink filter\n");
1299 goto end;
1301 hr = IGraphBuilder_AddFilter(graphBuilder, &captureSinkFilter->IBaseFilter_iface, NULL);
1302 if (FAILED(hr)) {
1303 skip("couldn't add capture sink filter to graph, hr=0x%08x\n", hr);
1304 goto end;
1307 previewSinkFilter = create_SinkFilter(FALSE);
1308 if (previewSinkFilter == NULL) {
1309 skip("couldn't create preview sink filter\n");
1310 goto end;
1312 hr = IGraphBuilder_AddFilter(graphBuilder, &previewSinkFilter->IBaseFilter_iface, NULL);
1313 if (FAILED(hr)) {
1314 skip("couldn't add preview sink filter to graph, hr=0x%08x\n", hr);
1315 goto end;
1318 hr = IGraphBuilder_Connect(graphBuilder, capturePin, &captureSinkFilter->IPin_iface);
1319 ok(hr == VFW_E_NOT_CONNECTED, "connecting Capture pin without first connecting Input pin returned 0x%08x\n", hr);
1320 hr = IGraphBuilder_Connect(graphBuilder, previewPin, &previewSinkFilter->IPin_iface);
1321 ok(hr == VFW_E_NOT_CONNECTED, "connecting Preview pin without first connecting Input pin returned 0x%08x\n", hr);
1323 sourceFilter = create_SourceFilter();
1324 if (sourceFilter == NULL) {
1325 skip("couldn't create source filter\n");
1326 goto end;
1328 hr = IGraphBuilder_AddFilter(graphBuilder, &sourceFilter->IBaseFilter_iface, NULL);
1329 ok(SUCCEEDED(hr), "couldn't add source filter to graph, hr=0x%08x\n", hr);
1330 if (FAILED(hr))
1331 goto end;
1333 hr = IGraphBuilder_Connect(graphBuilder, &sourceFilter->IPin_iface, inputPin);
1334 ok(SUCCEEDED(hr), "couldn't connect source filter to Input pin, hr=0x%08x\n", hr);
1335 if (FAILED(hr))
1336 goto end;
1337 hr = IGraphBuilder_Connect(graphBuilder, capturePin, &captureSinkFilter->IPin_iface);
1338 ok(SUCCEEDED(hr), "couldn't connect Capture pin to sink, hr=0x%08x\n", hr);
1339 if (FAILED(hr))
1340 goto end;
1341 hr = IGraphBuilder_Connect(graphBuilder, previewPin, &previewSinkFilter->IPin_iface);
1342 ok(SUCCEEDED(hr), "couldn't connect Preview pin to sink, hr=0x%08x\n", hr);
1343 if (FAILED(hr))
1344 goto end;
1346 ok(sourceFilter->allocator == captureSinkFilter->allocator, "input and capture allocators don't match\n");
1347 ok(sourceFilter->allocator == previewSinkFilter->allocator, "input and preview allocators don't match\n");
1349 hr = IGraphBuilder_QueryInterface(graphBuilder, &IID_IMediaControl, (void**)&mediaControl);
1350 ok(SUCCEEDED(hr), "couldn't get IMediaControl interface from IGraphBuilder, hr=0x%08x\n", hr);
1351 if (FAILED(hr))
1352 goto end;
1353 hr = IMediaControl_Run(mediaControl);
1354 ok(SUCCEEDED(hr), "IMediaControl_Run() failed, hr=0x%08x\n", hr);
1355 if (FAILED(hr))
1356 goto end;
1358 endTime = GetTickCount() + 5000;
1359 while (previewSinkFilter->receiveThreadId == 0 || captureSinkFilter->receiveThreadId == 0) {
1360 DWORD now = GetTickCount();
1361 if (now < endTime)
1362 WaitForSingleObject(event, endTime - now);
1363 else
1364 break;
1366 if (previewSinkFilter->receiveThreadId != 0 && captureSinkFilter->receiveThreadId != 0) {
1367 todo_wine ok(sourceFilter->mediaThreadId != captureSinkFilter->receiveThreadId,
1368 "sending thread should != capture receiving thread\n");
1369 todo_wine ok(sourceFilter->mediaThreadId != previewSinkFilter->receiveThreadId,
1370 "sending thread should != preview receiving thread\n");
1371 todo_wine ok(captureSinkFilter->receiveThreadId != previewSinkFilter->receiveThreadId,
1372 "capture receiving thread should != preview receiving thread");
1373 } else {
1374 ok(0, "timeout: threads did not receive sample in time\n");
1377 IMediaControl_Stop(mediaControl);
1379 end:
1380 if (mediaControl)
1381 IMediaControl_Release(mediaControl);
1382 if (graphBuilder)
1383 IGraphBuilder_Release(graphBuilder);
1384 if (sourceFilter)
1385 IBaseFilter_Release(&sourceFilter->IBaseFilter_iface);
1386 if (captureSinkFilter)
1387 IBaseFilter_Release(&captureSinkFilter->IBaseFilter_iface);
1388 if (previewSinkFilter)
1389 IBaseFilter_Release(&previewSinkFilter->IBaseFilter_iface);
1392 static void test_smart_tee_filter(void)
1394 HRESULT hr;
1395 IBaseFilter *smartTeeFilter = NULL;
1396 IEnumPins *enumPins = NULL;
1397 IPin *pin;
1398 IPin *inputPin = NULL;
1399 IPin *capturePin = NULL;
1400 IPin *previewPin = NULL;
1401 FILTER_INFO filterInfo;
1402 int pinNumber = 0;
1403 IMemInputPin *memInputPin = NULL;
1404 IEnumMediaTypes *enumMediaTypes = NULL;
1405 ULONG nPin = 0;
1407 hr = CoCreateInstance(&CLSID_SmartTee, NULL, CLSCTX_INPROC_SERVER,
1408 &IID_IBaseFilter, (void**)&smartTeeFilter);
1409 ok(SUCCEEDED(hr), "couldn't create smart tee filter, hr=0x%08x\n", hr);
1410 if (FAILED(hr))
1411 goto end;
1413 hr = IBaseFilter_QueryFilterInfo(smartTeeFilter, &filterInfo);
1414 ok(SUCCEEDED(hr), "QueryFilterInfo failed, hr=0x%08x\n", hr);
1415 if (FAILED(hr))
1416 goto end;
1418 ok(lstrlenW(filterInfo.achName) == 0,
1419 "filter's name is meant to be empty but it's %s\n", wine_dbgstr_w(filterInfo.achName));
1421 hr = IBaseFilter_EnumPins(smartTeeFilter, &enumPins);
1422 ok(SUCCEEDED(hr), "cannot enum filter pins, hr=0x%08x\n", hr);
1423 if (FAILED(hr))
1424 goto end;
1426 while (IEnumPins_Next(enumPins, 1, &pin, NULL) == S_OK)
1428 LPWSTR id = NULL;
1429 PIN_INFO pinInfo;
1430 memset(&pinInfo, 0, sizeof(pinInfo));
1431 hr = IPin_QueryPinInfo(pin, &pinInfo);
1432 ok(SUCCEEDED(hr), "QueryPinInfo failed, hr=0x%08x\n", hr);
1433 if (FAILED(hr))
1434 goto endwhile;
1436 ok(pinInfo.pFilter == smartTeeFilter, "pin's filter isn't the filter owning the pin\n");
1437 if (pinNumber == 0)
1439 static const WCHAR wszInput[] = {'I','n','p','u','t',0};
1440 ok(pinInfo.dir == PINDIR_INPUT, "pin 0 isn't an input pin\n");
1441 ok(!lstrcmpW(pinInfo.achName, wszInput), "pin 0 is called %s, not 'Input'\n", wine_dbgstr_w(pinInfo.achName));
1442 hr = IPin_QueryId(pin, &id);
1443 ok(SUCCEEDED(hr), "IPin_QueryId() failed with 0x%08x\n", hr);
1444 ok(!lstrcmpW(id, wszInput), "pin 0's id is %s, not 'Input'\n", wine_dbgstr_w(id));
1445 inputPin = pin;
1446 IPin_AddRef(inputPin);
1448 else if (pinNumber == 1)
1450 static const WCHAR wszCapture[] = {'C','a','p','t','u','r','e',0};
1451 ok(pinInfo.dir == PINDIR_OUTPUT, "pin 1 isn't an output pin\n");
1452 ok(!lstrcmpW(pinInfo.achName, wszCapture), "pin 1 is called %s, not 'Capture'\n", wine_dbgstr_w(pinInfo.achName));
1453 hr = IPin_QueryId(pin, &id);
1454 ok(SUCCEEDED(hr), "IPin_QueryId() failed with 0x%08x\n", hr);
1455 ok(!lstrcmpW(id, wszCapture), "pin 1's id is %s, not 'Capture'\n", wine_dbgstr_w(id));
1456 capturePin = pin;
1457 IPin_AddRef(capturePin);
1459 else if (pinNumber == 2)
1461 static const WCHAR wszPreview[] = {'P','r','e','v','i','e','w',0};
1462 ok(pinInfo.dir == PINDIR_OUTPUT, "pin 2 isn't an output pin\n");
1463 ok(!lstrcmpW(pinInfo.achName, wszPreview), "pin 2 is called %s, not 'Preview'\n", wine_dbgstr_w(pinInfo.achName));
1464 hr = IPin_QueryId(pin, &id);
1465 ok(SUCCEEDED(hr), "IPin_QueryId() failed with 0x%08x\n", hr);
1466 ok(!lstrcmpW(id, wszPreview), "pin 2's id is %s, not 'Preview'\n", wine_dbgstr_w(id));
1467 previewPin = pin;
1468 IPin_AddRef(previewPin);
1470 else
1471 ok(0, "pin %d isn't supposed to exist\n", pinNumber);
1473 endwhile:
1474 if (pinInfo.pFilter)
1475 IBaseFilter_Release(pinInfo.pFilter);
1476 if (id)
1477 CoTaskMemFree(id);
1478 IPin_Release(pin);
1479 pinNumber++;
1482 ok(inputPin && capturePin && previewPin, "couldn't find all pins\n");
1483 if (!(inputPin && capturePin && previewPin))
1484 goto end;
1486 ok(has_interface((IUnknown*)inputPin, &IID_IUnknown), "IUnknown should exist on the input pin\n");
1487 ok(has_interface((IUnknown*)inputPin, &IID_IMemInputPin), "IMemInputPin should exist the input pin\n");
1488 ok(!has_interface((IUnknown*)inputPin, &IID_IKsPropertySet), "IKsPropertySet shouldn't eixst on the input pin\n");
1489 ok(!has_interface((IUnknown*)inputPin, &IID_IAMStreamConfig), "IAMStreamConfig shouldn't exist on the input pin\n");
1490 ok(!has_interface((IUnknown*)inputPin, &IID_IAMStreamControl), "IAMStreamControl shouldn't exist on the input pin\n");
1491 ok(!has_interface((IUnknown*)inputPin, &IID_IPropertyBag), "IPropertyBag shouldn't exist on the input pin\n");
1492 todo_wine ok(has_interface((IUnknown*)inputPin, &IID_IQualityControl), "IQualityControl should exist on the input pin\n");
1494 ok(has_interface((IUnknown*)capturePin, &IID_IUnknown), "IUnknown should exist on the capture pin\n");
1495 ok(!has_interface((IUnknown*)capturePin, &IID_IAsyncReader), "IAsyncReader shouldn't exist on the capture pin\n");
1496 ok(!has_interface((IUnknown*)capturePin, &IID_IKsPropertySet), "IKsPropertySet shouldn't exist on the capture pin\n");
1497 ok(!has_interface((IUnknown*)capturePin, &IID_IAMStreamConfig), "IAMStreamConfig shouldn't exist on the capture pin\n");
1498 todo_wine ok(has_interface((IUnknown*)capturePin, &IID_IAMStreamControl), "IAMStreamControl should exist on the capture pin\n");
1499 ok(!has_interface((IUnknown*)capturePin, &IID_IPropertyBag), "IPropertyBag shouldn't exist on the capture pin\n");
1500 todo_wine ok(has_interface((IUnknown*)capturePin, &IID_IQualityControl), "IQualityControl should exist on the capture pin\n");
1502 ok(has_interface((IUnknown*)previewPin, &IID_IUnknown), "IUnknown should exist on the preview pin\n");
1503 ok(!has_interface((IUnknown*)previewPin, &IID_IAsyncReader), "IAsyncReader shouldn't exist on the preview pin\n");
1504 ok(!has_interface((IUnknown*)previewPin, &IID_IKsPropertySet), "IKsPropertySet shouldn't exist on the preview pin\n");
1505 ok(!has_interface((IUnknown*)previewPin, &IID_IAMStreamConfig), "IAMStreamConfig shouldn't exist on the preview pin\n");
1506 todo_wine ok(has_interface((IUnknown*)capturePin, &IID_IAMStreamControl), "IAMStreamControl should exist on the preview pin\n");
1507 ok(!has_interface((IUnknown*)previewPin, &IID_IPropertyBag), "IPropertyBag shouldn't exist on the preview pin\n");
1508 todo_wine ok(has_interface((IUnknown*)previewPin, &IID_IQualityControl), "IQualityControl should exist on the preview pin\n");
1510 hr = IPin_QueryInterface(inputPin, &IID_IMemInputPin, (void**)&memInputPin);
1511 ok(SUCCEEDED(hr), "couldn't get mem input pin, hr=0x%08x\n", hr);
1512 if (FAILED(hr))
1513 goto end;
1514 hr = IMemInputPin_ReceiveCanBlock(memInputPin);
1515 ok(hr == S_OK, "unexpected IMemInputPin_ReceiveCanBlock() = 0x%08x\n", hr);
1517 hr = IPin_EnumMediaTypes(inputPin, &enumMediaTypes);
1518 ok(SUCCEEDED(hr), "IPin_EnumMediaTypes() failed, hr=0x%08x\n", hr);
1519 if (SUCCEEDED(hr)) {
1520 AM_MEDIA_TYPE *mediaType = NULL;
1521 hr = IEnumMediaTypes_Next(enumMediaTypes, 1, &mediaType, NULL);
1522 ok(hr == S_FALSE, "the media types are non-empty\n");
1524 IEnumMediaTypes_Release(enumMediaTypes);
1525 enumMediaTypes = NULL;
1526 hr = IPin_EnumMediaTypes(capturePin, &enumMediaTypes);
1527 ok(hr == VFW_E_NOT_CONNECTED, "IPin_EnumMediaTypes() failed, hr=0x%08x\n", hr);
1528 hr = IPin_EnumMediaTypes(previewPin, &enumMediaTypes);
1529 ok(hr == VFW_E_NOT_CONNECTED, "IPin_EnumMediaTypes() failed, hr=0x%08x\n", hr);
1531 hr = IPin_QueryInternalConnections(inputPin, NULL, &nPin);
1532 ok(hr == E_NOTIMPL, "IPin_QueryInternalConnections() returned hr=0x%08x\n", hr);
1533 hr = IPin_QueryInternalConnections(capturePin, NULL, &nPin);
1534 ok(hr == E_NOTIMPL, "IPin_QueryInternalConnections() returned hr=0x%08x\n", hr);
1535 hr = IPin_QueryInternalConnections(previewPin, NULL, &nPin);
1536 ok(hr == E_NOTIMPL, "IPin_QueryInternalConnections() returned hr=0x%08x\n", hr);
1538 test_smart_tee_filter_in_graph(smartTeeFilter, inputPin, capturePin, previewPin);
1540 end:
1541 if (inputPin)
1542 IPin_Release(inputPin);
1543 if (capturePin)
1544 IPin_Release(capturePin);
1545 if (previewPin)
1546 IPin_Release(previewPin);
1547 if (smartTeeFilter)
1548 IBaseFilter_Release(smartTeeFilter);
1549 if (enumPins)
1550 IEnumPins_Release(enumPins);
1551 if (memInputPin)
1552 IMemInputPin_Release(memInputPin);
1553 if (enumMediaTypes)
1554 IEnumMediaTypes_Release(enumMediaTypes);
1557 static void test_smart_tee_filter_aggregation(void)
1559 SourceFilter *sourceFilter = create_SourceFilter();
1560 if (sourceFilter) {
1561 IUnknown *unknown = NULL;
1562 HRESULT hr = CoCreateInstance(&CLSID_SmartTee, (IUnknown*)&sourceFilter->IBaseFilter_iface,
1563 CLSCTX_INPROC_SERVER, &IID_IUnknown, (void**)&unknown);
1564 ok(SUCCEEDED(hr), "SmartTee filter doesn't support aggregation, hr=0x%08x\n", hr);
1565 if (unknown)
1566 IUnknown_Release(unknown);
1567 IBaseFilter_Release(&sourceFilter->IBaseFilter_iface);
1568 } else
1569 ok(0, "out of memory allocating SourceFilter for test\n");
1572 START_TEST(smartteefilter)
1574 if (SUCCEEDED(CoInitialize(NULL)))
1576 event = CreateEventW(NULL, FALSE, FALSE, NULL);
1577 if (event) {
1578 test_smart_tee_filter_aggregation();
1579 test_smart_tee_filter();
1580 CloseHandle(event);
1581 } else
1582 skip("CreateEvent failed, error=%u\n", GetLastError());
1584 CoUninitialize();
1586 else
1587 skip("CoInitialize failed\n");