Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/quartz/tests/avisplit.c | 458 +++++++++++++++++++++++++++++++++++ 1 file changed, 458 insertions(+)
diff --git a/dlls/quartz/tests/avisplit.c b/dlls/quartz/tests/avisplit.c index 4af101767d6..23b7c5b9150 100644 --- a/dlls/quartz/tests/avisplit.c +++ b/dlls/quartz/tests/avisplit.c @@ -23,6 +23,7 @@ #include "dshow.h" #include "initguid.h" #include "wmcodecdsp.h" +#include "wine/strmbase.h" #include "wine/test.h"
static IBaseFilter *create_avi_splitter(void) @@ -34,6 +35,12 @@ static IBaseFilter *create_avi_splitter(void) return filter; }
+static inline BOOL compare_media_types(const AM_MEDIA_TYPE *a, const AM_MEDIA_TYPE *b) +{ + return !memcmp(a, b, offsetof(AM_MEDIA_TYPE, pbFormat)) + && !memcmp(a->pbFormat, b->pbFormat, a->cbFormat); +} + static WCHAR *load_resource(const WCHAR *name) { static WCHAR pathW[MAX_PATH]; @@ -792,6 +799,456 @@ static void test_enum_media_types(void) ok(ret, "Failed to delete file, error %u.\n", GetLastError()); }
+struct testfilter +{ + struct strmbase_filter filter; + struct strmbase_source source; + struct strmbase_sink sink; + IAsyncReader IAsyncReader_iface, *reader; + const AM_MEDIA_TYPE *mt; +}; + +static inline struct testfilter *impl_from_strmbase_filter(struct strmbase_filter *iface) +{ + return CONTAINING_RECORD(iface, struct testfilter, filter); +} + +static struct strmbase_pin *testfilter_get_pin(struct strmbase_filter *iface, unsigned int index) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface); + if (!index) + return &filter->source.pin; + else if (index == 1) + return &filter->sink.pin; + return NULL; +} + +static void testfilter_destroy(struct strmbase_filter *iface) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface); + strmbase_source_cleanup(&filter->source); + strmbase_sink_cleanup(&filter->sink); + strmbase_filter_cleanup(&filter->filter); +} + +static const struct strmbase_filter_ops testfilter_ops = +{ + .filter_get_pin = testfilter_get_pin, + .filter_destroy = testfilter_destroy, +}; + +static HRESULT testsource_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt) +{ + return S_OK; +} + +static HRESULT testsource_query_interface(struct strmbase_pin *iface, REFIID iid, void **out) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + + if (IsEqualGUID(iid, &IID_IAsyncReader)) + *out = &filter->IAsyncReader_iface; + else + return E_NOINTERFACE; + + IUnknown_AddRef((IUnknown *)*out); + return S_OK; +} + +static HRESULT WINAPI testsource_AttemptConnection(struct strmbase_source *iface, + IPin *peer, const AM_MEDIA_TYPE *mt) +{ + HRESULT hr; + + iface->pin.peer = peer; + IPin_AddRef(peer); + CopyMediaType(&iface->pin.mt, mt); + + if (FAILED(hr = IPin_ReceiveConnection(peer, &iface->pin.IPin_iface, mt))) + { + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + IPin_Release(peer); + iface->pin.peer = NULL; + FreeMediaType(&iface->pin.mt); + } + + return hr; +} + +static const struct strmbase_source_ops testsource_ops = +{ + .base.pin_query_interface = testsource_query_interface, + .base.pin_query_accept = testsource_query_accept, + .base.pin_get_media_type = strmbase_pin_get_media_type, + .pfnAttemptConnection = testsource_AttemptConnection, +}; + +static HRESULT testsink_query_interface(struct strmbase_pin *iface, REFIID iid, void **out) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + + if (IsEqualGUID(iid, &IID_IMemInputPin)) + *out = &filter->sink.IMemInputPin_iface; + else + return E_NOINTERFACE; + + IUnknown_AddRef((IUnknown *)*out); + return S_OK; +} + +static HRESULT testsink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + if (filter->mt && !compare_media_types(mt, filter->mt)) + return S_FALSE; + return S_OK; +} + +static HRESULT testsink_get_media_type(struct strmbase_pin *iface, unsigned int index, AM_MEDIA_TYPE *mt) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + if (!index && filter->mt) + { + CopyMediaType(mt, filter->mt); + return S_OK; + } + return VFW_S_NO_MORE_ITEMS; +} + +static HRESULT WINAPI testsink_Receive(struct strmbase_sink *iface, IMediaSample *sample) +{ + return S_OK; +} + +static const struct strmbase_sink_ops testsink_ops = +{ + .base.pin_query_interface = testsink_query_interface, + .base.pin_query_accept = testsink_query_accept, + .base.pin_get_media_type = testsink_get_media_type, + .pfnReceive = testsink_Receive, +}; + +static struct testfilter *impl_from_IAsyncReader(IAsyncReader *iface) +{ + return CONTAINING_RECORD(iface, struct testfilter, IAsyncReader_iface); +} + +static HRESULT WINAPI async_reader_QueryInterface(IAsyncReader *iface, REFIID iid, void **out) +{ + return IPin_QueryInterface(&impl_from_IAsyncReader(iface)->source.pin.IPin_iface, iid, out); +} + +static ULONG WINAPI async_reader_AddRef(IAsyncReader *iface) +{ + return IPin_AddRef(&impl_from_IAsyncReader(iface)->source.pin.IPin_iface); +} + +static ULONG WINAPI async_reader_Release(IAsyncReader *iface) +{ + return IPin_Release(&impl_from_IAsyncReader(iface)->source.pin.IPin_iface); +} + +static HRESULT WINAPI async_reader_RequestAllocator(IAsyncReader *iface, + IMemAllocator *preferred, ALLOCATOR_PROPERTIES *props, IMemAllocator **allocator) +{ + return IAsyncReader_RequestAllocator(impl_from_IAsyncReader(iface)->reader, preferred, props, allocator); +} + +static HRESULT WINAPI async_reader_Request(IAsyncReader *iface, IMediaSample *sample, DWORD_PTR cookie) +{ + return IAsyncReader_Request(impl_from_IAsyncReader(iface)->reader, sample, cookie); +} + +static HRESULT WINAPI async_reader_WaitForNext(IAsyncReader *iface, + DWORD timeout, IMediaSample **sample, DWORD_PTR *cookie) +{ + return IAsyncReader_WaitForNext(impl_from_IAsyncReader(iface)->reader, timeout, sample, cookie); +} + +static HRESULT WINAPI async_reader_SyncReadAligned(IAsyncReader *iface, IMediaSample *sample) +{ + return IAsyncReader_SyncReadAligned(impl_from_IAsyncReader(iface)->reader, sample); +} + +static HRESULT WINAPI async_reader_SyncRead(IAsyncReader *iface, LONGLONG position, LONG length, BYTE *buffer) +{ + return IAsyncReader_SyncRead(impl_from_IAsyncReader(iface)->reader, position, length, buffer); +} + +static HRESULT WINAPI async_reader_Length(IAsyncReader *iface, LONGLONG *total, LONGLONG *available) +{ + return IAsyncReader_Length(impl_from_IAsyncReader(iface)->reader, total, available); +} + +static HRESULT WINAPI async_reader_BeginFlush(IAsyncReader *iface) +{ + return IAsyncReader_BeginFlush(impl_from_IAsyncReader(iface)->reader); +} + +static HRESULT WINAPI async_reader_EndFlush(IAsyncReader *iface) +{ + return IAsyncReader_EndFlush(impl_from_IAsyncReader(iface)->reader); +} + +static const struct IAsyncReaderVtbl async_reader_vtbl = +{ + async_reader_QueryInterface, + async_reader_AddRef, + async_reader_Release, + async_reader_RequestAllocator, + async_reader_Request, + async_reader_WaitForNext, + async_reader_SyncReadAligned, + async_reader_SyncRead, + async_reader_Length, + async_reader_BeginFlush, + async_reader_EndFlush, +}; + +static void testfilter_init(struct testfilter *filter) +{ + static const GUID clsid = {0xabacab}; + memset(filter, 0, sizeof(*filter)); + strmbase_filter_init(&filter->filter, NULL, &clsid, &testfilter_ops); + strmbase_source_init(&filter->source, &filter->filter, L"source", &testsource_ops); + strmbase_sink_init(&filter->sink, &filter->filter, L"sink", &testsink_ops, NULL); + filter->IAsyncReader_iface.lpVtbl = &async_reader_vtbl; +} + +static void test_connect_pin(void) +{ + AM_MEDIA_TYPE req_mt = + { + .majortype = MEDIATYPE_Stream, + .subtype = MEDIASUBTYPE_Avi, + .lSampleSize = 888, + }; + IBaseFilter *filter = create_avi_splitter(), *reader; + const WCHAR *filename = load_resource(L"test.avi"); + struct testfilter testsource, testsink; + IFileSourceFilter *filesource; + AM_MEDIA_TYPE mt, *source_mt; + IPin *sink, *source, *peer; + IEnumMediaTypes *enummt; + IFilterGraph2 *graph; + HRESULT hr; + ULONG ref; + BOOL ret; + + CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, + &IID_IFilterGraph2, (void **)&graph); + testfilter_init(&testsource); + testfilter_init(&testsink); + IFilterGraph2_AddFilter(graph, &testsink.filter.IBaseFilter_iface, L"sink"); + IFilterGraph2_AddFilter(graph, &testsource.filter.IBaseFilter_iface, L"source"); + IFilterGraph2_AddFilter(graph, filter, L"splitter"); + IBaseFilter_FindPin(filter, L"input pin", &sink); + + CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, + &IID_IBaseFilter, (void **)&reader); + IBaseFilter_QueryInterface(reader, &IID_IFileSourceFilter, (void **)&filesource); + IFileSourceFilter_Load(filesource, filename, NULL); + IFileSourceFilter_Release(filesource); + IBaseFilter_FindPin(reader, L"Output", &source); + IPin_QueryInterface(source, &IID_IAsyncReader, (void **)&testsource.reader); + IPin_Release(source); + + /* Test sink connection. */ + + peer = (IPin *)0xdeadbeef; + hr = IPin_ConnectedTo(sink, &peer); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + ok(!peer, "Got peer %p.\n", peer); + + hr = IPin_ConnectionMediaType(sink, &mt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + req_mt.majortype = MEDIATYPE_Video; + hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &req_mt); + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + req_mt.majortype = MEDIATYPE_Stream; + + req_mt.subtype = MEDIASUBTYPE_RGB8; + hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &req_mt); + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + req_mt.subtype = MEDIASUBTYPE_Avi; + + hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IPin_ConnectedTo(sink, &peer); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(peer == &testsource.source.pin.IPin_iface, "Got peer %p.\n", peer); + IPin_Release(peer); + + hr = IPin_ConnectionMediaType(sink, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&mt, &req_mt), "Media types didn't match.\n"); + ok(compare_media_types(&testsource.source.pin.mt, &req_mt), "Media types didn't match.\n"); + + /* Test source connection. */ + + IBaseFilter_FindPin(filter, L"Stream 00", &source); + + peer = (IPin *)0xdeadbeef; + hr = IPin_ConnectedTo(source, &peer); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + ok(!peer, "Got peer %p.\n", peer); + + hr = IPin_ConnectionMediaType(source, &mt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + /* Exact connection. */ + + IPin_EnumMediaTypes(source, &enummt); + IEnumMediaTypes_Next(enummt, 1, &source_mt, NULL); + IEnumMediaTypes_Release(enummt); + CopyMediaType(&req_mt, source_mt); + + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IPin_ConnectedTo(source, &peer); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(peer == &testsink.sink.pin.IPin_iface, "Got peer %p.\n", peer); + IPin_Release(peer); + + hr = IPin_ConnectionMediaType(source, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&mt, &req_mt), "Media types didn't match.\n"); + ok(compare_media_types(&testsink.sink.pin.mt, &req_mt), "Media types didn't match.\n"); + + hr = IFilterGraph2_Disconnect(graph, source); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IFilterGraph2_Disconnect(graph, source); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + ok(testsink.sink.pin.peer == source, "Got peer %p.\n", testsink.sink.pin.peer); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.lSampleSize = 999; + req_mt.bTemporalCompression = req_mt.bFixedSizeSamples = TRUE; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink.sink.pin.mt, &req_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.majortype = MEDIATYPE_Stream; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + req_mt.majortype = MEDIATYPE_Video; + + req_mt.subtype = MEDIASUBTYPE_RGB32; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + req_mt.subtype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + req_mt.subtype = MEDIASUBTYPE_I420; + + /* Connection with wildcards. */ + + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink.sink.pin.mt, source_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.majortype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink.sink.pin.mt, source_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.subtype = MEDIASUBTYPE_RGB32; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + + req_mt.subtype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink.sink.pin.mt, source_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.formattype = FORMAT_None; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + + req_mt.majortype = MEDIATYPE_Video; + req_mt.subtype = MEDIASUBTYPE_I420; + req_mt.formattype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + if (hr == S_OK) + ok(compare_media_types(&testsink.sink.pin.mt, source_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.subtype = MEDIASUBTYPE_RGB32; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + + req_mt.subtype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink.sink.pin.mt, source_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.majortype = MEDIATYPE_Audio; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + + testsink.mt = &req_mt; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, NULL); + ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + + req_mt.majortype = MEDIATYPE_Video; + req_mt.subtype = MEDIASUBTYPE_I420; + req_mt.formattype = FORMAT_VideoInfo; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + IPin_Release(source); + hr = IFilterGraph2_Disconnect(graph, sink); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IFilterGraph2_Disconnect(graph, sink); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + ok(testsource.source.pin.peer == sink, "Got peer %p.\n", testsource.source.pin.peer); + IFilterGraph2_Disconnect(graph, &testsource.source.pin.IPin_iface); + + CoTaskMemFree(req_mt.pbFormat); + CoTaskMemFree(source_mt->pbFormat); + CoTaskMemFree(source_mt); + + IAsyncReader_Release(testsource.reader); + IPin_Release(sink); + ref = IFilterGraph2_Release(graph); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(reader); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(filter); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(&testsource.filter.IBaseFilter_iface); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(&testsink.filter.IBaseFilter_iface); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ret = DeleteFileW(filename); + ok(ret, "Failed to delete file, error %u.\n", GetLastError()); +} + static void test_filter_graph(void) { IFileSourceFilter *pfile = NULL; @@ -1114,6 +1571,7 @@ START_TEST(avisplit) test_enum_media_types(); test_unconnected_filter_state(); test_filter_graph(); + test_connect_pin();
CoUninitialize(); }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/quartz/tests/avisplit.c | 300 +++++++---------------------------- 1 file changed, 57 insertions(+), 243 deletions(-)
diff --git a/dlls/quartz/tests/avisplit.c b/dlls/quartz/tests/avisplit.c index 23b7c5b9150..e3c20140bc1 100644 --- a/dlls/quartz/tests/avisplit.c +++ b/dlls/quartz/tests/avisplit.c @@ -1015,6 +1015,58 @@ static void testfilter_init(struct testfilter *filter) filter->IAsyncReader_iface.lpVtbl = &async_reader_vtbl; }
+static void test_filter_state(IMediaControl *control) +{ + OAFilterState state; + HRESULT hr; + + hr = IMediaControl_GetState(control, 0, &state); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(state == State_Stopped, "Got state %u.\n", state); + + hr = IMediaControl_Pause(control); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMediaControl_GetState(control, 0, &state); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(state == State_Paused, "Got state %u.\n", state); + + hr = IMediaControl_Run(control); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMediaControl_GetState(control, 0, &state); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(state == State_Running, "Got state %u.\n", state); + + hr = IMediaControl_Pause(control); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMediaControl_GetState(control, 0, &state); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(state == State_Paused, "Got state %u.\n", state); + + hr = IMediaControl_Stop(control); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMediaControl_GetState(control, 0, &state); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(state == State_Stopped, "Got state %u.\n", state); + + hr = IMediaControl_Run(control); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMediaControl_GetState(control, 0, &state); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(state == State_Running, "Got state %u.\n", state); + + hr = IMediaControl_Stop(control); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMediaControl_GetState(control, 0, &state); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(state == State_Stopped, "Got state %u.\n", state); +} + static void test_connect_pin(void) { AM_MEDIA_TYPE req_mt = @@ -1030,6 +1082,7 @@ static void test_connect_pin(void) AM_MEDIA_TYPE mt, *source_mt; IPin *sink, *source, *peer; IEnumMediaTypes *enummt; + IMediaControl *control; IFilterGraph2 *graph; HRESULT hr; ULONG ref; @@ -1043,6 +1096,7 @@ static void test_connect_pin(void) IFilterGraph2_AddFilter(graph, &testsource.filter.IBaseFilter_iface, L"source"); IFilterGraph2_AddFilter(graph, filter, L"splitter"); IBaseFilter_FindPin(filter, L"input pin", &sink); + IFilterGraph2_QueryInterface(graph, &IID_IMediaControl, (void **)&control);
CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (void **)&reader); @@ -1108,6 +1162,8 @@ static void test_connect_pin(void) hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); ok(hr == S_OK, "Got hr %#x.\n", hr);
+ test_filter_state(control); + hr = IPin_ConnectedTo(source, &peer); ok(hr == S_OK, "Got hr %#x.\n", hr); ok(peer == &testsink.sink.pin.IPin_iface, "Got peer %p.\n", peer); @@ -1235,6 +1291,7 @@ static void test_connect_pin(void)
IAsyncReader_Release(testsource.reader); IPin_Release(sink); + IMediaControl_Release(control); ref = IFilterGraph2_Release(graph); ok(!ref, "Got outstanding refcount %d.\n", ref); ref = IBaseFilter_Release(reader); @@ -1249,248 +1306,6 @@ static void test_connect_pin(void) ok(ret, "Failed to delete file, error %u.\n", GetLastError()); }
-static void test_filter_graph(void) -{ - IFileSourceFilter *pfile = NULL; - IBaseFilter *preader = NULL, *pavi = create_avi_splitter(); - IEnumPins *enumpins = NULL; - IPin *filepin = NULL, *avipin = NULL; - HRESULT hr; - HANDLE file = NULL; - PIN_DIRECTION dir = PINDIR_OUTPUT; - char buffer[13]; - DWORD readbytes; - FILTER_STATE state; - - WCHAR *filename = load_resource(L"test.avi"); - - file = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, 0, NULL); - if (file == INVALID_HANDLE_VALUE) - { - skip("Could not read test file "%s", skipping test\n", wine_dbgstr_w(filename)); - DeleteFileW(filename); - return; - } - - memset(buffer, 0, 13); - readbytes = 12; - ReadFile(file, buffer, readbytes, &readbytes, NULL); - CloseHandle(file); - if (strncmp(buffer, "RIFF", 4) || strcmp(buffer + 8, "AVI ")) - { - skip("%s is not an avi riff file, not doing the avi splitter test\n", - wine_dbgstr_w(filename)); - DeleteFileW(filename); - return; - } - - hr = IUnknown_QueryInterface(pavi, &IID_IFileSourceFilter, - (void **)&pfile); - ok(hr == E_NOINTERFACE, - "Avi splitter returns unexpected error: %08x\n", hr); - if (pfile) - IFileSourceFilter_Release(pfile); - pfile = NULL; - - hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, - &IID_IBaseFilter, (LPVOID*)&preader); - ok(hr == S_OK, "Could not create asynchronous reader: %08x\n", hr); - if (hr != S_OK) - goto fail; - - hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter, - (void**)&pfile); - ok(hr == S_OK, "Could not get IFileSourceFilter: %08x\n", hr); - if (hr != S_OK) - goto fail; - - hr = IFileSourceFilter_Load(pfile, filename, NULL); - if (hr != S_OK) - { - trace("Could not load file: %08x\n", hr); - goto fail; - } - - hr = IBaseFilter_EnumPins(preader, &enumpins); - ok(hr == S_OK, "No enumpins: %08x\n", hr); - if (hr != S_OK) - goto fail; - - hr = IEnumPins_Next(enumpins, 1, &filepin, NULL); - ok(hr == S_OK, "No pin: %08x\n", hr); - if (hr != S_OK) - goto fail; - - IEnumPins_Release(enumpins); - enumpins = NULL; - - hr = IBaseFilter_EnumPins(pavi, &enumpins); - ok(hr == S_OK, "No enumpins: %08x\n", hr); - if (hr != S_OK) - goto fail; - - hr = IEnumPins_Next(enumpins, 1, &avipin, NULL); - ok(hr == S_OK, "No pin: %08x\n", hr); - if (hr != S_OK) - goto fail; - - hr = IPin_Connect(filepin, avipin, NULL); - ok(hr == S_OK, "Could not connect: %08x\n", hr); - if (hr != S_OK) - goto fail; - - IPin_Release(avipin); - avipin = NULL; - - IEnumPins_Reset(enumpins); - - /* Windows puts the pins in the order: Outputpins - Inputpin, - * wine does the reverse, just don't test it for now - * Hate to admit it, but windows way makes more sense - */ - while (IEnumPins_Next(enumpins, 1, &avipin, NULL) == S_OK) - { - IPin_QueryDirection(avipin, &dir); - if (dir == PINDIR_OUTPUT) - { - /* Well, connect it to a null renderer! */ - IBaseFilter *pnull = NULL; - IEnumPins *nullenum = NULL; - IPin *nullpin = NULL; - - hr = CoCreateInstance(&CLSID_NullRenderer, NULL, - CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pnull); - if (hr == REGDB_E_CLASSNOTREG) - { - win_skip("Null renderer not registered, skipping\n"); - break; - } - ok(hr == S_OK, "Could not create null renderer: %08x\n", hr); - - hr = IBaseFilter_EnumPins(pnull, &nullenum); - ok(hr == S_OK, "Failed to enum pins, hr %#x.\n", hr); - hr = IEnumPins_Next(nullenum, 1, &nullpin, NULL); - ok(hr == S_OK, "Failed to get next pin, hr %#x.\n", hr); - IEnumPins_Release(nullenum); - IPin_QueryDirection(nullpin, &dir); - - hr = IPin_Connect(avipin, nullpin, NULL); - ok(hr == S_OK, "Failed to connect output pin: %08x\n", hr); - IPin_Release(nullpin); - if (hr != S_OK) - { - IBaseFilter_Release(pnull); - break; - } - IBaseFilter_Run(pnull, 0); - } - - IPin_Release(avipin); - avipin = NULL; - } - - if (avipin) - IPin_Release(avipin); - avipin = NULL; - - if (hr != S_OK) - goto fail2; - /* At this point there is a minimalistic connected avi splitter that can - * be used for all sorts of source filter tests. However that still needs - * to be written at a later time. - * - * Interesting tests: - * - Can you disconnect an output pin while running? - * Expecting: Yes - * - Can you disconnect the pullpin while running? - * Expecting: No - * - Is the reference count incremented during playback or when connected? - * Does this happen once for every output pin? Or is there something else - * going on. - * Expecting: You tell me - */ - - IBaseFilter_Run(preader, 0); - IBaseFilter_Run(pavi, 0); - IBaseFilter_GetState(pavi, INFINITE, &state); - - IBaseFilter_Pause(pavi); - IBaseFilter_Pause(preader); - IBaseFilter_Stop(pavi); - IBaseFilter_Stop(preader); - IBaseFilter_GetState(pavi, INFINITE, &state); - IBaseFilter_GetState(preader, INFINITE, &state); - -fail2: - IEnumPins_Reset(enumpins); - while (IEnumPins_Next(enumpins, 1, &avipin, NULL) == S_OK) - { - IPin *to = NULL; - - IPin_QueryDirection(avipin, &dir); - IPin_ConnectedTo(avipin, &to); - if (to) - { - IPin_Release(to); - - if (dir == PINDIR_OUTPUT) - { - PIN_INFO info; - - hr = IPin_QueryPinInfo(to, &info); - ok(hr == S_OK, "Failed to query pin info, hr %#x.\n", hr); - - /* Release twice: Once normal, second from the - * previous while loop - */ - IBaseFilter_Stop(info.pFilter); - IPin_Disconnect(to); - IPin_Disconnect(avipin); - IBaseFilter_Release(info.pFilter); - IBaseFilter_Release(info.pFilter); - } - else - { - IPin_Disconnect(to); - IPin_Disconnect(avipin); - } - } - IPin_Release(avipin); - avipin = NULL; - } - -fail: - if (hr != S_OK) - skip("Prerequisites not matched, skipping remainder of test\n"); - if (enumpins) - IEnumPins_Release(enumpins); - - if (avipin) - IPin_Release(avipin); - if (filepin) - { - IPin *to = NULL; - - IPin_ConnectedTo(filepin, &to); - if (to) - { - IPin_Disconnect(filepin); - IPin_Disconnect(to); - } - IPin_Release(filepin); - } - - if (preader) - IBaseFilter_Release(preader); - if (pavi) - IBaseFilter_Release(pavi); - if (pfile) - IFileSourceFilter_Release(pfile); - - DeleteFileW(filename); -} - static void test_unconnected_filter_state(void) { IBaseFilter *filter = create_avi_splitter(); @@ -1570,7 +1385,6 @@ START_TEST(avisplit) test_media_types(); test_enum_media_types(); test_unconnected_filter_state(); - test_filter_graph(); test_connect_pin();
CoUninitialize();
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/quartz/tests/mpegsplit.c | 462 ++++++++++++++++++++++++++++++++++ 1 file changed, 462 insertions(+)
diff --git a/dlls/quartz/tests/mpegsplit.c b/dlls/quartz/tests/mpegsplit.c index 67dd6d312dc..d4972baa283 100644 --- a/dlls/quartz/tests/mpegsplit.c +++ b/dlls/quartz/tests/mpegsplit.c @@ -21,6 +21,7 @@ #define COBJMACROS #include "dshow.h" #include "mmreg.h" +#include "wine/strmbase.h" #include "wine/test.h"
static const GUID MEDIASUBTYPE_mp3 = {0x00000055,0x0000,0x0010,{0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}}; @@ -34,6 +35,12 @@ static IBaseFilter *create_mpeg_splitter(void) return filter; }
+static inline BOOL compare_media_types(const AM_MEDIA_TYPE *a, const AM_MEDIA_TYPE *b) +{ + return !memcmp(a, b, offsetof(AM_MEDIA_TYPE, pbFormat)) + && !memcmp(a->pbFormat, b->pbFormat, a->cbFormat); +} + static WCHAR *load_resource(const WCHAR *name) { static WCHAR pathW[MAX_PATH]; @@ -1081,6 +1088,460 @@ static void test_unconnected_filter_state(void) ok(!ref, "Got outstanding refcount %d.\n", ref); }
+struct testfilter +{ + struct strmbase_filter filter; + struct strmbase_source source; + struct strmbase_sink sink; + IAsyncReader IAsyncReader_iface, *reader; + const AM_MEDIA_TYPE *mt; +}; + +static inline struct testfilter *impl_from_strmbase_filter(struct strmbase_filter *iface) +{ + return CONTAINING_RECORD(iface, struct testfilter, filter); +} + +static struct strmbase_pin *testfilter_get_pin(struct strmbase_filter *iface, unsigned int index) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface); + if (!index) + return &filter->source.pin; + else if (index == 1) + return &filter->sink.pin; + return NULL; +} + +static void testfilter_destroy(struct strmbase_filter *iface) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface); + strmbase_source_cleanup(&filter->source); + strmbase_sink_cleanup(&filter->sink); + strmbase_filter_cleanup(&filter->filter); +} + +static const struct strmbase_filter_ops testfilter_ops = +{ + .filter_get_pin = testfilter_get_pin, + .filter_destroy = testfilter_destroy, +}; + +static HRESULT testsource_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt) +{ + return S_OK; +} + +static HRESULT testsource_query_interface(struct strmbase_pin *iface, REFIID iid, void **out) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + + if (IsEqualGUID(iid, &IID_IAsyncReader)) + *out = &filter->IAsyncReader_iface; + else + return E_NOINTERFACE; + + IUnknown_AddRef((IUnknown *)*out); + return S_OK; +} + +static HRESULT WINAPI testsource_AttemptConnection(struct strmbase_source *iface, + IPin *peer, const AM_MEDIA_TYPE *mt) +{ + HRESULT hr; + + iface->pin.peer = peer; + IPin_AddRef(peer); + CopyMediaType(&iface->pin.mt, mt); + + if (FAILED(hr = IPin_ReceiveConnection(peer, &iface->pin.IPin_iface, mt))) + { + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + IPin_Release(peer); + iface->pin.peer = NULL; + FreeMediaType(&iface->pin.mt); + } + + return hr; +} + +static const struct strmbase_source_ops testsource_ops = +{ + .base.pin_query_interface = testsource_query_interface, + .base.pin_query_accept = testsource_query_accept, + .base.pin_get_media_type = strmbase_pin_get_media_type, + .pfnAttemptConnection = testsource_AttemptConnection, +}; + +static HRESULT testsink_query_interface(struct strmbase_pin *iface, REFIID iid, void **out) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + + if (IsEqualGUID(iid, &IID_IMemInputPin)) + *out = &filter->sink.IMemInputPin_iface; + else + return E_NOINTERFACE; + + IUnknown_AddRef((IUnknown *)*out); + return S_OK; +} + +static HRESULT testsink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + if (filter->mt && !compare_media_types(mt, filter->mt)) + return S_FALSE; + return S_OK; +} + +static HRESULT testsink_get_media_type(struct strmbase_pin *iface, unsigned int index, AM_MEDIA_TYPE *mt) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + if (!index && filter->mt) + { + CopyMediaType(mt, filter->mt); + return S_OK; + } + return VFW_S_NO_MORE_ITEMS; +} + +static HRESULT WINAPI testsink_Receive(struct strmbase_sink *iface, IMediaSample *sample) +{ + return S_OK; +} + +static const struct strmbase_sink_ops testsink_ops = +{ + .base.pin_query_interface = testsink_query_interface, + .base.pin_query_accept = testsink_query_accept, + .base.pin_get_media_type = testsink_get_media_type, + .pfnReceive = testsink_Receive, +}; + +static struct testfilter *impl_from_IAsyncReader(IAsyncReader *iface) +{ + return CONTAINING_RECORD(iface, struct testfilter, IAsyncReader_iface); +} + +static HRESULT WINAPI async_reader_QueryInterface(IAsyncReader *iface, REFIID iid, void **out) +{ + return IPin_QueryInterface(&impl_from_IAsyncReader(iface)->source.pin.IPin_iface, iid, out); +} + +static ULONG WINAPI async_reader_AddRef(IAsyncReader *iface) +{ + return IPin_AddRef(&impl_from_IAsyncReader(iface)->source.pin.IPin_iface); +} + +static ULONG WINAPI async_reader_Release(IAsyncReader *iface) +{ + return IPin_Release(&impl_from_IAsyncReader(iface)->source.pin.IPin_iface); +} + +static HRESULT WINAPI async_reader_RequestAllocator(IAsyncReader *iface, + IMemAllocator *preferred, ALLOCATOR_PROPERTIES *props, IMemAllocator **allocator) +{ + return IAsyncReader_RequestAllocator(impl_from_IAsyncReader(iface)->reader, preferred, props, allocator); +} + +static HRESULT WINAPI async_reader_Request(IAsyncReader *iface, IMediaSample *sample, DWORD_PTR cookie) +{ + return IAsyncReader_Request(impl_from_IAsyncReader(iface)->reader, sample, cookie); +} + +static HRESULT WINAPI async_reader_WaitForNext(IAsyncReader *iface, + DWORD timeout, IMediaSample **sample, DWORD_PTR *cookie) +{ + return IAsyncReader_WaitForNext(impl_from_IAsyncReader(iface)->reader, timeout, sample, cookie); +} + +static HRESULT WINAPI async_reader_SyncReadAligned(IAsyncReader *iface, IMediaSample *sample) +{ + return IAsyncReader_SyncReadAligned(impl_from_IAsyncReader(iface)->reader, sample); +} + +static HRESULT WINAPI async_reader_SyncRead(IAsyncReader *iface, LONGLONG position, LONG length, BYTE *buffer) +{ + return IAsyncReader_SyncRead(impl_from_IAsyncReader(iface)->reader, position, length, buffer); +} + +static HRESULT WINAPI async_reader_Length(IAsyncReader *iface, LONGLONG *total, LONGLONG *available) +{ + return IAsyncReader_Length(impl_from_IAsyncReader(iface)->reader, total, available); +} + +static HRESULT WINAPI async_reader_BeginFlush(IAsyncReader *iface) +{ + return IAsyncReader_BeginFlush(impl_from_IAsyncReader(iface)->reader); +} + +static HRESULT WINAPI async_reader_EndFlush(IAsyncReader *iface) +{ + return IAsyncReader_EndFlush(impl_from_IAsyncReader(iface)->reader); +} + +static const struct IAsyncReaderVtbl async_reader_vtbl = +{ + async_reader_QueryInterface, + async_reader_AddRef, + async_reader_Release, + async_reader_RequestAllocator, + async_reader_Request, + async_reader_WaitForNext, + async_reader_SyncReadAligned, + async_reader_SyncRead, + async_reader_Length, + async_reader_BeginFlush, + async_reader_EndFlush, +}; + +static void testfilter_init(struct testfilter *filter) +{ + static const GUID clsid = {0xabacab}; + memset(filter, 0, sizeof(*filter)); + strmbase_filter_init(&filter->filter, NULL, &clsid, &testfilter_ops); + strmbase_source_init(&filter->source, &filter->filter, L"source", &testsource_ops); + strmbase_sink_init(&filter->sink, &filter->filter, L"sink", &testsink_ops, NULL); + filter->IAsyncReader_iface.lpVtbl = &async_reader_vtbl; +} + +static void test_connect_pin(void) +{ + AM_MEDIA_TYPE req_mt = + { + .majortype = MEDIATYPE_Stream, + .subtype = MEDIASUBTYPE_MPEG1Audio, + .lSampleSize = 888, + }; + IBaseFilter *filter = create_mpeg_splitter(), *reader; + const WCHAR *filename = load_resource(L"test.mp3"); + struct testfilter testsource, testsink; + IFileSourceFilter *filesource; + AM_MEDIA_TYPE mt, *source_mt; + IPin *sink, *source, *peer; + IEnumMediaTypes *enummt; + IMediaControl *control; + IFilterGraph2 *graph; + HRESULT hr; + ULONG ref; + BOOL ret; + + CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, + &IID_IFilterGraph2, (void **)&graph); + testfilter_init(&testsource); + testfilter_init(&testsink); + IFilterGraph2_AddFilter(graph, &testsink.filter.IBaseFilter_iface, L"sink"); + IFilterGraph2_AddFilter(graph, &testsource.filter.IBaseFilter_iface, L"source"); + IFilterGraph2_AddFilter(graph, filter, L"splitter"); + IBaseFilter_FindPin(filter, L"Input", &sink); + IFilterGraph2_QueryInterface(graph, &IID_IMediaControl, (void **)&control); + + CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, + &IID_IBaseFilter, (void **)&reader); + IBaseFilter_QueryInterface(reader, &IID_IFileSourceFilter, (void **)&filesource); + IFileSourceFilter_Load(filesource, filename, NULL); + IFileSourceFilter_Release(filesource); + IBaseFilter_FindPin(reader, L"Output", &source); + IPin_QueryInterface(source, &IID_IAsyncReader, (void **)&testsource.reader); + IPin_Release(source); + + /* Test sink connection. */ + + peer = (IPin *)0xdeadbeef; + hr = IPin_ConnectedTo(sink, &peer); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + ok(!peer, "Got peer %p.\n", peer); + + hr = IPin_ConnectionMediaType(sink, &mt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + req_mt.majortype = MEDIATYPE_Video; + hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &req_mt); + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + req_mt.majortype = MEDIATYPE_Stream; + + req_mt.subtype = MEDIASUBTYPE_RGB8; + hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &req_mt); + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + req_mt.subtype = MEDIASUBTYPE_MPEG1Audio; + + hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IPin_ConnectedTo(sink, &peer); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(peer == &testsource.source.pin.IPin_iface, "Got peer %p.\n", peer); + IPin_Release(peer); + + hr = IPin_ConnectionMediaType(sink, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&mt, &req_mt), "Media types didn't match.\n"); + ok(compare_media_types(&testsource.source.pin.mt, &req_mt), "Media types didn't match.\n"); + + /* Test source connection. */ + + IBaseFilter_FindPin(filter, L"Audio", &source); + + peer = (IPin *)0xdeadbeef; + hr = IPin_ConnectedTo(source, &peer); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + ok(!peer, "Got peer %p.\n", peer); + + hr = IPin_ConnectionMediaType(source, &mt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + /* Exact connection. */ + + IPin_EnumMediaTypes(source, &enummt); + IEnumMediaTypes_Next(enummt, 1, &source_mt, NULL); + IEnumMediaTypes_Release(enummt); + CopyMediaType(&req_mt, source_mt); + + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IPin_ConnectedTo(source, &peer); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(peer == &testsink.sink.pin.IPin_iface, "Got peer %p.\n", peer); + IPin_Release(peer); + + hr = IPin_ConnectionMediaType(source, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&mt, &req_mt), "Media types didn't match.\n"); + ok(compare_media_types(&testsink.sink.pin.mt, &req_mt), "Media types didn't match.\n"); + + hr = IFilterGraph2_Disconnect(graph, source); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IFilterGraph2_Disconnect(graph, source); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + ok(testsink.sink.pin.peer == source, "Got peer %p.\n", testsink.sink.pin.peer); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.lSampleSize = 999; + req_mt.bTemporalCompression = req_mt.bFixedSizeSamples = TRUE; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink.sink.pin.mt, &req_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.majortype = MEDIATYPE_Stream; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + req_mt.majortype = MEDIATYPE_Audio; + + req_mt.subtype = MEDIASUBTYPE_PCM; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + req_mt.subtype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + req_mt.subtype = MEDIASUBTYPE_MPEG1AudioPayload; + + /* Connection with wildcards. */ + + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink.sink.pin.mt, source_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.majortype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + if (hr == S_OK) + ok(compare_media_types(&testsink.sink.pin.mt, source_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.subtype = MEDIASUBTYPE_PCM; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + + req_mt.subtype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink.sink.pin.mt, source_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.formattype = FORMAT_None; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + + req_mt.majortype = MEDIATYPE_Audio; + req_mt.subtype = MEDIASUBTYPE_MPEG1AudioPayload; + req_mt.formattype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + if (hr == S_OK) + ok(compare_media_types(&testsink.sink.pin.mt, source_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.subtype = MEDIASUBTYPE_PCM; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + + req_mt.subtype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink.sink.pin.mt, source_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.majortype = MEDIATYPE_Stream; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + + testsink.mt = &req_mt; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, NULL); + ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + + req_mt.majortype = MEDIATYPE_Audio; + req_mt.subtype = MEDIASUBTYPE_MPEG1AudioPayload; + req_mt.formattype = FORMAT_WaveFormatEx; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, NULL); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + + IPin_Release(source); + hr = IFilterGraph2_Disconnect(graph, sink); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IFilterGraph2_Disconnect(graph, sink); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + ok(testsource.source.pin.peer == sink, "Got peer %p.\n", testsource.source.pin.peer); + IFilterGraph2_Disconnect(graph, &testsource.source.pin.IPin_iface); + + CoTaskMemFree(req_mt.pbFormat); + CoTaskMemFree(source_mt->pbFormat); + CoTaskMemFree(source_mt); + + IAsyncReader_Release(testsource.reader); + IPin_Release(sink); + IMediaControl_Release(control); + ref = IFilterGraph2_Release(graph); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(reader); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(filter); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(&testsource.filter.IBaseFilter_iface); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(&testsink.filter.IBaseFilter_iface); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ret = DeleteFileW(filename); + ok(ret, "Failed to delete file, error %u.\n", GetLastError()); +} + START_TEST(mpegsplit) { IBaseFilter *filter; @@ -1103,6 +1564,7 @@ START_TEST(mpegsplit) test_media_types(); test_enum_media_types(); test_unconnected_filter_state(); + test_connect_pin();
CoUninitialize(); }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/qedit/tests/Makefile.in | 2 +- dlls/qedit/tests/mediadet.c | 1 - dlls/qedit/tests/samplegrabber.c | 621 ++++++++++++++++++++++++++++++- 3 files changed, 612 insertions(+), 12 deletions(-)
diff --git a/dlls/qedit/tests/Makefile.in b/dlls/qedit/tests/Makefile.in index 53d95d774c0..a1020f5052d 100644 --- a/dlls/qedit/tests/Makefile.in +++ b/dlls/qedit/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = qedit.dll -IMPORTS = oleaut32 ole32 +IMPORTS = strmbase strmiids uuid oleaut32 ole32
C_SRCS = \ mediadet.c \ diff --git a/dlls/qedit/tests/mediadet.c b/dlls/qedit/tests/mediadet.c index e52ee618dd6..65f5af79c7e 100644 --- a/dlls/qedit/tests/mediadet.c +++ b/dlls/qedit/tests/mediadet.c @@ -21,7 +21,6 @@ #define COBJMACROS #define CONST_VTABLE
-#include "initguid.h" #include "ole2.h" #include "vfwmsgs.h" #include "uuids.h" diff --git a/dlls/qedit/tests/samplegrabber.c b/dlls/qedit/tests/samplegrabber.c index 545e0062b04..6404e053886 100644 --- a/dlls/qedit/tests/samplegrabber.c +++ b/dlls/qedit/tests/samplegrabber.c @@ -21,6 +21,7 @@ #define COBJMACROS #include "dshow.h" #include "qedit.h" +#include "wine/strmbase.h" #include "wine/test.h"
static IBaseFilter *create_sample_grabber(void) @@ -39,6 +40,12 @@ static ULONG get_refcount(void *iface) return IUnknown_Release(unknown); }
+static inline BOOL compare_media_types(const AM_MEDIA_TYPE *a, const AM_MEDIA_TYPE *b) +{ + return !memcmp(a, b, offsetof(AM_MEDIA_TYPE, pbFormat)) + && !memcmp(a->pbFormat, b->pbFormat, a->cbFormat); +} + #define check_interface(a, b, c) check_interface_(__LINE__, a, b, c) static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported) { @@ -446,37 +453,630 @@ static void test_aggregation(void)
static void test_media_types(void) { + BYTE format = 1; + AM_MEDIA_TYPE mt = + { + .majortype = {0x111}, + .subtype = {0x222}, + .formattype = {0x333}, + }; + AM_MEDIA_TYPE match_mt = + { + .subtype = {0x123}, + .bFixedSizeSamples = TRUE, + .bTemporalCompression = TRUE, + .lSampleSize = 456, + .formattype = {0x789}, + .cbFormat = sizeof(format), + .pbFormat = &format, + }; IBaseFilter *filter = create_sample_grabber(); IEnumMediaTypes *enummt; - AM_MEDIA_TYPE mt = {}; + ISampleGrabber *grabber; + IPin *sink, *source; HRESULT hr; ULONG ref; - IPin *pin;
- IBaseFilter_FindPin(filter, L"In", &pin); + IBaseFilter_QueryInterface(filter, &IID_ISampleGrabber, (void **)&grabber); + IBaseFilter_FindPin(filter, L"In", &sink); + IBaseFilter_FindPin(filter, L"Out", &source);
- hr = IPin_EnumMediaTypes(pin, &enummt); + hr = IPin_EnumMediaTypes(sink, &enummt); todo_wine ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); if (hr == S_OK) IEnumMediaTypes_Release(enummt);
- hr = IPin_QueryAccept(pin, &mt); + hr = IPin_EnumMediaTypes(source, &enummt); + todo_wine ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + if (hr == S_OK) IEnumMediaTypes_Release(enummt); + + hr = IPin_QueryAccept(sink, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &mt); ok(hr == S_OK, "Got hr %#x.\n", hr);
- IPin_Release(pin); + hr = ISampleGrabber_SetMediaType(grabber, &match_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr);
- IBaseFilter_FindPin(filter, L"Out", &pin); + hr = IPin_EnumMediaTypes(sink, &enummt); + todo_wine ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + if (hr == S_OK) IEnumMediaTypes_Release(enummt);
- hr = IPin_EnumMediaTypes(pin, &enummt); + hr = IPin_EnumMediaTypes(source, &enummt); todo_wine ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); if (hr == S_OK) IEnumMediaTypes_Release(enummt);
- hr = IPin_QueryAccept(pin, &mt); + hr = IPin_QueryAccept(sink, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &mt); ok(hr == S_OK, "Got hr %#x.\n", hr);
- IPin_Release(pin); + match_mt.majortype = MEDIATYPE_Video; + match_mt.subtype = GUID_NULL; + hr = ISampleGrabber_SetMediaType(grabber, &match_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(sink, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + + mt.majortype = GUID_NULL; + hr = IPin_QueryAccept(sink, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + mt.majortype = match_mt.majortype; + hr = IPin_QueryAccept(sink, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + match_mt.subtype = MEDIASUBTYPE_RGB8; + match_mt.formattype = GUID_NULL; + hr = ISampleGrabber_SetMediaType(grabber, &match_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(sink, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + + mt.subtype = GUID_NULL; + hr = IPin_QueryAccept(sink, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + mt.subtype = match_mt.subtype; + hr = IPin_QueryAccept(sink, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + match_mt.formattype = FORMAT_None; + hr = ISampleGrabber_SetMediaType(grabber, &match_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(sink, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + + mt.formattype = GUID_NULL; + hr = IPin_QueryAccept(sink, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + mt.formattype = match_mt.formattype; + hr = IPin_QueryAccept(sink, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + IPin_Release(sink); + IPin_Release(source); + ISampleGrabber_Release(grabber); + ref = IBaseFilter_Release(filter); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + +struct testfilter +{ + struct strmbase_filter filter; + struct strmbase_source source; + struct strmbase_sink sink; + const AM_MEDIA_TYPE *sink_mt; + AM_MEDIA_TYPE source_mt; +}; + +static inline struct testfilter *impl_from_strmbase_filter(struct strmbase_filter *iface) +{ + return CONTAINING_RECORD(iface, struct testfilter, filter); +} + +static struct strmbase_pin *testfilter_get_pin(struct strmbase_filter *iface, unsigned int index) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface); + if (!index) + return &filter->source.pin; + else if (index == 1) + return &filter->sink.pin; + return NULL; +} + +static void testfilter_destroy(struct strmbase_filter *iface) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface); + strmbase_source_cleanup(&filter->source); + strmbase_sink_cleanup(&filter->sink); + strmbase_filter_cleanup(&filter->filter); +} + +static const struct strmbase_filter_ops testfilter_ops = +{ + .filter_get_pin = testfilter_get_pin, + .filter_destroy = testfilter_destroy, +}; + +static HRESULT testsource_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt) +{ + return mt->bTemporalCompression ? S_OK : S_FALSE; +} + +static HRESULT testsource_get_media_type(struct strmbase_pin *iface, unsigned int index, AM_MEDIA_TYPE *mt) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + if (!index) + { + CopyMediaType(mt, &filter->source_mt); + return S_OK; + } + return VFW_S_NO_MORE_ITEMS; +} + +static void test_sink_allocator(IPin *pin) +{ + ALLOCATOR_PROPERTIES req_props = {1, 5000, 1, 0}, ret_props; + IMemAllocator *req_allocator, *ret_allocator; + IMemInputPin *input; + HRESULT hr; + + IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&input); + + hr = IMemInputPin_NotifyAllocator(input, NULL, TRUE); + todo_wine ok(hr == E_POINTER, "Got hr %#x.\n", hr); + + hr = IMemInputPin_GetAllocatorRequirements(input, &ret_props); + ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr); + + hr = IMemInputPin_GetAllocator(input, &ret_allocator); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + + if (hr == S_OK) + { + hr = IMemInputPin_NotifyAllocator(input, ret_allocator, TRUE); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IMemAllocator_Release(ret_allocator); + } + + CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER, + &IID_IMemAllocator, (void **)&req_allocator); + + hr = IMemInputPin_NotifyAllocator(input, req_allocator, TRUE); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMemInputPin_GetAllocator(input, &ret_allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(ret_allocator == req_allocator, "Allocators didn't match.\n"); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IMemAllocator_Release(ret_allocator); + + hr = IMemAllocator_SetProperties(req_allocator, &req_props, &ret_props); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMemAllocator_Commit(req_allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + IMemAllocator_Release(req_allocator); + IMemInputPin_Release(input); +} + +static HRESULT WINAPI testsource_AttemptConnection(struct strmbase_source *iface, + IPin *peer, const AM_MEDIA_TYPE *mt) +{ + HRESULT hr; + + iface->pin.peer = peer; + IPin_AddRef(peer); + CopyMediaType(&iface->pin.mt, mt); + + if (FAILED(hr = IPin_ReceiveConnection(peer, &iface->pin.IPin_iface, mt))) + { + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + IPin_Release(peer); + iface->pin.peer = NULL; + FreeMediaType(&iface->pin.mt); + } + + test_sink_allocator(peer); + + return hr; +} + +static const struct strmbase_source_ops testsource_ops = +{ + .base.pin_query_accept = testsource_query_accept, + .base.pin_get_media_type = testsource_get_media_type, + .pfnAttemptConnection = testsource_AttemptConnection, +}; + +static HRESULT testsink_query_interface(struct strmbase_pin *iface, REFIID iid, void **out) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + + if (IsEqualGUID(iid, &IID_IMemInputPin)) + *out = &filter->sink.IMemInputPin_iface; + else + return E_NOINTERFACE; + + IUnknown_AddRef((IUnknown *)*out); + return S_OK; +} + +static HRESULT testsink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + if (filter->sink_mt && !compare_media_types(mt, filter->sink_mt)) + return S_FALSE; + return S_OK; +} + +static HRESULT testsink_get_media_type(struct strmbase_pin *iface, unsigned int index, AM_MEDIA_TYPE *mt) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + if (!index && filter->sink_mt) + { + CopyMediaType(mt, filter->sink_mt); + return S_OK; + } + return VFW_S_NO_MORE_ITEMS; +} + +static HRESULT WINAPI testsink_Receive(struct strmbase_sink *iface, IMediaSample *sample) +{ + return S_OK; +} + +static const struct strmbase_sink_ops testsink_ops = +{ + .base.pin_query_interface = testsink_query_interface, + .base.pin_query_accept = testsink_query_accept, + .base.pin_get_media_type = testsink_get_media_type, + .pfnReceive = testsink_Receive, +}; + +static void testfilter_init(struct testfilter *filter) +{ + static const GUID clsid = {0xabacab}; + memset(filter, 0, sizeof(*filter)); + strmbase_filter_init(&filter->filter, NULL, &clsid, &testfilter_ops); + strmbase_source_init(&filter->source, &filter->filter, L"source", &testsource_ops); + strmbase_sink_init(&filter->sink, &filter->filter, L"sink", &testsink_ops, NULL); +} + +static void test_connect_pin(void) +{ + AM_MEDIA_TYPE req_mt = + { + .majortype = MEDIATYPE_Stream, + .subtype = MEDIASUBTYPE_Avi, + .formattype = FORMAT_None, + }; + IBaseFilter *filter = create_sample_grabber(); + struct testfilter testsource, testsink; + IPin *sink, *source, *peer; + IEnumMediaTypes *enummt; + ISampleGrabber *grabber; + AM_MEDIA_TYPE mt, *pmt; + IFilterGraph2 *graph; + HRESULT hr; + ULONG ref; + + testfilter_init(&testsource); + testfilter_init(&testsink); + CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, + &IID_IFilterGraph2, (void **)&graph); + IFilterGraph2_AddFilter(graph, &testsource.filter.IBaseFilter_iface, L"source"); + IFilterGraph2_AddFilter(graph, &testsink.filter.IBaseFilter_iface, L"sink"); + IFilterGraph2_AddFilter(graph, filter, L"sample grabber"); + IBaseFilter_FindPin(filter, L"In", &sink); + IBaseFilter_FindPin(filter, L"Out", &source); + IBaseFilter_QueryInterface(filter, &IID_ISampleGrabber, (void **)&grabber); + + testsource.source_mt.majortype = MEDIATYPE_Video; + testsource.source_mt.subtype = MEDIASUBTYPE_RGB8; + testsource.source_mt.formattype = FORMAT_VideoInfo; + + hr = ISampleGrabber_GetConnectedMediaType(grabber, &mt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + /* Test sink connection. */ + + peer = (IPin *)0xdeadbeef; + hr = IPin_ConnectedTo(sink, &peer); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + ok(!peer, "Got peer %p.\n", peer); + + hr = IPin_ConnectionMediaType(sink, &mt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IPin_ConnectedTo(sink, &peer); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(peer == &testsource.source.pin.IPin_iface, "Got peer %p.\n", peer); + IPin_Release(peer); + + hr = IPin_ConnectionMediaType(sink, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&mt, &req_mt), "Media types didn't match.\n"); + + hr = ISampleGrabber_GetConnectedMediaType(grabber, NULL); + ok(hr == E_POINTER, "Got hr %#x.\n", hr); + + hr = ISampleGrabber_GetConnectedMediaType(grabber, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&mt, &req_mt), "Media types didn't match.\n"); + + hr = IPin_EnumMediaTypes(sink, &enummt); + todo_wine ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + if (hr == S_OK) IEnumMediaTypes_Release(enummt); + hr = IPin_EnumMediaTypes(source, &enummt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IEnumMediaTypes_Next(enummt, 1, &pmt, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(compare_media_types(pmt, &testsource.source_mt), "Media types didn't match.\n"); + IEnumMediaTypes_Release(enummt); + + req_mt.majortype = MEDIATYPE_Video; + req_mt.subtype = MEDIASUBTYPE_RGB8; + req_mt.formattype = FORMAT_VideoInfo; + hr = IPin_QueryAccept(sink, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(source, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + req_mt.bTemporalCompression = TRUE; + hr = IPin_QueryAccept(source, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + memset(&mt, 0, sizeof(AM_MEDIA_TYPE)); + mt.majortype = MEDIATYPE_Midi; + hr = ISampleGrabber_SetMediaType(grabber, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IPin_QueryAccept(source, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + + req_mt.majortype = MEDIATYPE_Midi; + req_mt.bTemporalCompression = FALSE; + hr = IPin_QueryAccept(source, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + + req_mt.bTemporalCompression = TRUE; + hr = IPin_QueryAccept(source, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + memset(&mt, 0, sizeof(AM_MEDIA_TYPE)); + hr = ISampleGrabber_SetMediaType(grabber, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + /* Test source connection. */
+ peer = (IPin *)0xdeadbeef; + hr = IPin_ConnectedTo(source, &peer); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + ok(!peer, "Got peer %p.\n", peer); + + hr = IPin_ConnectionMediaType(source, &mt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + /* Exact connection. */ + + req_mt.bTemporalCompression = FALSE; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + + req_mt.bTemporalCompression = TRUE; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + + if (hr == S_OK) + { + hr = IPin_ConnectedTo(source, &peer); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(peer == &testsink.sink.pin.IPin_iface, "Got peer %p.\n", peer); + IPin_Release(peer); + + hr = IPin_ConnectionMediaType(source, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&mt, &req_mt), "Media types didn't match.\n"); + ok(compare_media_types(&testsink.sink.pin.mt, &req_mt), "Media types didn't match.\n"); + ok(compare_media_types(&testsource.source.pin.mt, &testsink.sink.pin.mt), "Media types didn't match.\n"); + + hr = IFilterGraph2_Disconnect(graph, source); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IFilterGraph2_Disconnect(graph, source); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + ok(testsink.sink.pin.peer == source, "Got peer %p.\n", testsink.sink.pin.peer); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + + /* Connection with wildcards. */ + + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, NULL); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + + testsource.source_mt.bTemporalCompression = TRUE; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(compare_media_types(&testsink.sink.pin.mt, &testsource.source_mt), "Media types didn't match.\n"); + todo_wine ok(compare_media_types(&testsource.source.pin.mt, &testsink.sink.pin.mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.majortype = GUID_NULL; + req_mt.bTemporalCompression = FALSE; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(compare_media_types(&testsink.sink.pin.mt, &testsource.source_mt), "Media types didn't match.\n"); + todo_wine ok(compare_media_types(&testsource.source.pin.mt, &testsink.sink.pin.mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.subtype = MEDIASUBTYPE_RGB32; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + + req_mt.subtype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(compare_media_types(&testsink.sink.pin.mt, &testsource.source_mt), "Media types didn't match.\n"); + todo_wine ok(compare_media_types(&testsource.source.pin.mt, &testsink.sink.pin.mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.formattype = FORMAT_None; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + + req_mt.majortype = MEDIATYPE_Video; + req_mt.subtype = MEDIASUBTYPE_RGB8; + req_mt.formattype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + ok(compare_media_types(&testsink.sink.pin.mt, &testsource.source_mt), "Media types didn't match.\n"); + ok(compare_media_types(&testsource.source.pin.mt, &testsink.sink.pin.mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + + req_mt.subtype = MEDIASUBTYPE_RGB32; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + + req_mt.subtype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(compare_media_types(&testsink.sink.pin.mt, &testsource.source_mt), "Media types didn't match.\n"); + todo_wine ok(compare_media_types(&testsource.source.pin.mt, &testsink.sink.pin.mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.majortype = MEDIATYPE_Audio; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + + testsource.source_mt.majortype = testsource.source_mt.subtype = testsource.source_mt.formattype = GUID_NULL; + req_mt.majortype = req_mt.subtype = req_mt.formattype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(compare_media_types(&testsink.sink.pin.mt, &testsource.source_mt), "Media types didn't match.\n"); + todo_wine ok(compare_media_types(&testsource.source.pin.mt, &testsink.sink.pin.mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + req_mt.majortype = MEDIATYPE_Video; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + req_mt.majortype = GUID_NULL; + + req_mt.subtype = MEDIASUBTYPE_RGB8; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + req_mt.subtype = GUID_NULL; + + req_mt.formattype = FORMAT_None; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + req_mt.formattype = GUID_NULL; + + testsink.sink_mt = &req_mt; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, NULL); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + } + + req_mt.bTemporalCompression = TRUE; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink.sink.pin.IPin_iface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink.sink.pin.mt, &req_mt), "Media types didn't match.\n"); + todo_wine ok(compare_media_types(&testsource.source.pin.mt, &testsink.sink.pin.mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink.sink.pin.IPin_iface); + + hr = IFilterGraph2_Disconnect(graph, sink); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IFilterGraph2_Disconnect(graph, sink); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + ok(testsource.source.pin.peer == sink, "Got peer %p.\n", testsource.source.pin.peer); + IFilterGraph2_Disconnect(graph, &testsource.source.pin.IPin_iface); + + peer = (IPin *)0xdeadbeef; + hr = IPin_ConnectedTo(sink, &peer); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + ok(!peer, "Got peer %p.\n", peer); + + hr = IPin_ConnectionMediaType(sink, &mt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + IPin_Release(sink); + IPin_Release(source); + ref = IFilterGraph2_Release(graph); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ISampleGrabber_Release(grabber); ref = IBaseFilter_Release(filter); ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(&testsource.filter.IBaseFilter_iface); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(&testsink.filter.IBaseFilter_iface); + ok(!ref, "Got outstanding refcount %d.\n", ref); }
START_TEST(samplegrabber) @@ -501,6 +1101,7 @@ START_TEST(samplegrabber) test_pin_info(); test_aggregation(); test_media_types(); + test_connect_pin();
CoUninitialize(); }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/qcap/tests/Makefile.in | 2 +- dlls/qcap/tests/smartteefilter.c | 521 ++++++++++++++++++++++++++++++- 2 files changed, 508 insertions(+), 15 deletions(-)
diff --git a/dlls/qcap/tests/Makefile.in b/dlls/qcap/tests/Makefile.in index 7df8e24f674..4c480d524de 100644 --- a/dlls/qcap/tests/Makefile.in +++ b/dlls/qcap/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = qcap.dll -IMPORTS = strmiids uuid oleaut32 ole32 advapi32 msvfw32 +IMPORTS = strmbase strmiids uuid oleaut32 ole32 advapi32 msvfw32
C_SRCS = \ audiorecord.c \ diff --git a/dlls/qcap/tests/smartteefilter.c b/dlls/qcap/tests/smartteefilter.c index 7a49150cc2b..c4fa3a69549 100644 --- a/dlls/qcap/tests/smartteefilter.c +++ b/dlls/qcap/tests/smartteefilter.c @@ -20,6 +20,7 @@
#define COBJMACROS #include "dshow.h" +#include "wine/strmbase.h" #include "wine/test.h"
static const WCHAR sink_id[] = {'I','n','p','u','t',0}; @@ -44,6 +45,12 @@ static ULONG get_refcount(void *iface) return IUnknown_Release(unknown); }
+static inline BOOL compare_media_types(const AM_MEDIA_TYPE *a, const AM_MEDIA_TYPE *b) +{ + return !memcmp(a, b, offsetof(AM_MEDIA_TYPE, pbFormat)) + && !memcmp(a->pbFormat, b->pbFormat, a->cbFormat); +} + #define check_interface(a, b, c) check_interface_(__LINE__, a, b, c) static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported) { @@ -2215,20 +2222,6 @@ static void test_smart_tee_filter(void) hr = IMemInputPin_ReceiveCanBlock(memInputPin); ok(hr == S_OK, "unexpected IMemInputPin_ReceiveCanBlock() = 0x%08x\n", hr);
- hr = IPin_EnumMediaTypes(inputPin, &enumMediaTypes); - ok(SUCCEEDED(hr), "IPin_EnumMediaTypes() failed, hr=0x%08x\n", hr); - if (SUCCEEDED(hr)) { - AM_MEDIA_TYPE *mediaType = NULL; - hr = IEnumMediaTypes_Next(enumMediaTypes, 1, &mediaType, NULL); - ok(hr == S_FALSE, "the media types are non-empty\n"); - } - IEnumMediaTypes_Release(enumMediaTypes); - enumMediaTypes = NULL; - hr = IPin_EnumMediaTypes(capturePin, &enumMediaTypes); - ok(hr == VFW_E_NOT_CONNECTED, "IPin_EnumMediaTypes() failed, hr=0x%08x\n", hr); - hr = IPin_EnumMediaTypes(previewPin, &enumMediaTypes); - ok(hr == VFW_E_NOT_CONNECTED, "IPin_EnumMediaTypes() failed, hr=0x%08x\n", hr); - test_smart_tee_filter_in_graph(smartTeeFilter, inputPin, capturePin, previewPin);
end: @@ -2506,6 +2499,505 @@ end: IGraphBuilder_Release(graphBuilder); }
+struct testfilter +{ + struct strmbase_filter filter; + struct strmbase_source source; + struct strmbase_sink sink; + const AM_MEDIA_TYPE *sink_mt; + AM_MEDIA_TYPE source_mt; +}; + +static inline struct testfilter *impl_from_strmbase_filter(struct strmbase_filter *iface) +{ + return CONTAINING_RECORD(iface, struct testfilter, filter); +} + +static struct strmbase_pin *testfilter_get_pin(struct strmbase_filter *iface, unsigned int index) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface); + if (!index) + return &filter->source.pin; + else if (index == 1) + return &filter->sink.pin; + return NULL; +} + +static void testfilter_destroy(struct strmbase_filter *iface) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface); + strmbase_source_cleanup(&filter->source); + strmbase_sink_cleanup(&filter->sink); + strmbase_filter_cleanup(&filter->filter); +} + +static const struct strmbase_filter_ops testfilter_ops = +{ + .filter_get_pin = testfilter_get_pin, + .filter_destroy = testfilter_destroy, +}; + +static HRESULT testsource_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt) +{ + return mt->bTemporalCompression ? S_OK : S_FALSE; +} + +static HRESULT testsource_get_media_type(struct strmbase_pin *iface, unsigned int index, AM_MEDIA_TYPE *mt) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + if (!index) + { + CopyMediaType(mt, &filter->source_mt); + return S_OK; + } + return VFW_S_NO_MORE_ITEMS; +} + +static void test_sink_allocator(IPin *pin) +{ + ALLOCATOR_PROPERTIES req_props = {1, 5000, 1, 0}, ret_props; + IMemAllocator *req_allocator, *ret_allocator; + IMemInputPin *input; + HRESULT hr; + + IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&input); + + hr = IMemInputPin_GetAllocatorRequirements(input, &ret_props); + ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr); + + hr = IMemInputPin_GetAllocator(input, &ret_allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMemInputPin_NotifyAllocator(input, ret_allocator, TRUE); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IMemAllocator_Release(ret_allocator); + + CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER, + &IID_IMemAllocator, (void **)&req_allocator); + + hr = IMemInputPin_NotifyAllocator(input, req_allocator, TRUE); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMemInputPin_GetAllocator(input, &ret_allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(ret_allocator == req_allocator, "Allocators didn't match.\n"); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IMemAllocator_Release(ret_allocator); + + hr = IMemAllocator_SetProperties(req_allocator, &req_props, &ret_props); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMemAllocator_Commit(req_allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + IMemAllocator_Release(req_allocator); + IMemInputPin_Release(input); +} + +static HRESULT WINAPI testsource_AttemptConnection(struct strmbase_source *iface, + IPin *peer, const AM_MEDIA_TYPE *mt) +{ + HRESULT hr; + + iface->pin.peer = peer; + IPin_AddRef(peer); + CopyMediaType(&iface->pin.mt, mt); + + if (FAILED(hr = IPin_ReceiveConnection(peer, &iface->pin.IPin_iface, mt))) + { + ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + IPin_Release(peer); + iface->pin.peer = NULL; + FreeMediaType(&iface->pin.mt); + } + + test_sink_allocator(peer); + + return hr; +} + +static const struct strmbase_source_ops testsource_ops = +{ + .base.pin_query_accept = testsource_query_accept, + .base.pin_get_media_type = testsource_get_media_type, + .pfnAttemptConnection = testsource_AttemptConnection, +}; + +static HRESULT testsink_query_interface(struct strmbase_pin *iface, REFIID iid, void **out) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + + if (IsEqualGUID(iid, &IID_IMemInputPin)) + *out = &filter->sink.IMemInputPin_iface; + else + return E_NOINTERFACE; + + IUnknown_AddRef((IUnknown *)*out); + return S_OK; +} + +static HRESULT testsink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + if (filter->sink_mt && !compare_media_types(mt, filter->sink_mt)) + return S_FALSE; + return S_OK; +} + +static HRESULT testsink_get_media_type(struct strmbase_pin *iface, unsigned int index, AM_MEDIA_TYPE *mt) +{ + struct testfilter *filter = impl_from_strmbase_filter(iface->filter); + if (!index && filter->sink_mt) + { + CopyMediaType(mt, filter->sink_mt); + return S_OK; + } + return VFW_S_NO_MORE_ITEMS; +} + +static HRESULT WINAPI testsink_Receive(struct strmbase_sink *iface, IMediaSample *sample) +{ + return S_OK; +} + +static const struct strmbase_sink_ops testsink_ops = +{ + .base.pin_query_interface = testsink_query_interface, + .base.pin_query_accept = testsink_query_accept, + .base.pin_get_media_type = testsink_get_media_type, + .pfnReceive = testsink_Receive, +}; + +static void testfilter_init(struct testfilter *filter) +{ + static const GUID clsid = {0xabacab}; + memset(filter, 0, sizeof(*filter)); + strmbase_filter_init(&filter->filter, NULL, &clsid, &testfilter_ops); + strmbase_source_init(&filter->source, &filter->filter, L"source", &testsource_ops); + strmbase_sink_init(&filter->sink, &filter->filter, L"sink", &testsink_ops, NULL); +} + +static void test_source_media_types(AM_MEDIA_TYPE req_mt, const AM_MEDIA_TYPE *source_mt, IPin *source) +{ + IEnumMediaTypes *enummt; + AM_MEDIA_TYPE *mts[3]; + ULONG count; + HRESULT hr; + + hr = IPin_EnumMediaTypes(source, &enummt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IEnumMediaTypes_Next(enummt, 3, mts, &count); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + todo_wine ok(count == 2, "Got %u types.\n", count); + ok(compare_media_types(mts[0], &req_mt), "Media types didn't match.\n"); + if (count > 1) + ok(compare_media_types(mts[1], source_mt), "Media types didn't match.\n"); + CoTaskMemFree(mts[0]); + if (count > 1) + CoTaskMemFree(mts[1]); + IEnumMediaTypes_Release(enummt); + + hr = IPin_QueryAccept(source, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + req_mt.lSampleSize = 2; + req_mt.bFixedSizeSamples = TRUE; + hr = IPin_QueryAccept(source, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + req_mt.cbFormat = sizeof(count); + req_mt.pbFormat = (BYTE *)&count; + hr = IPin_QueryAccept(source, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + req_mt.cbFormat = 0; + req_mt.pbFormat = NULL; + + req_mt.majortype = MEDIATYPE_Audio; + hr = IPin_QueryAccept(source, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + req_mt.majortype = GUID_NULL; + hr = IPin_QueryAccept(source, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + req_mt.majortype = MEDIATYPE_Stream; + + req_mt.subtype = MEDIASUBTYPE_PCM; + hr = IPin_QueryAccept(source, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + req_mt.subtype = GUID_NULL; + hr = IPin_QueryAccept(source, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + req_mt.subtype = MEDIASUBTYPE_Avi; + + req_mt.formattype = FORMAT_WaveFormatEx; + hr = IPin_QueryAccept(source, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + req_mt.formattype = GUID_NULL; + hr = IPin_QueryAccept(source, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + req_mt.formattype = FORMAT_None; + + req_mt.majortype = MEDIATYPE_Audio; + req_mt.subtype = MEDIASUBTYPE_PCM; + req_mt.formattype = test_iid; + req_mt.cbFormat = sizeof(count); + req_mt.pbFormat = (BYTE *)&count; + req_mt.bTemporalCompression = TRUE; + hr = IPin_QueryAccept(source, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); +} + +static void test_source_connection(AM_MEDIA_TYPE req_mt, IFilterGraph2 *graph, + struct testfilter *testsink, IPin *source) +{ + const AM_MEDIA_TYPE sink_mt = req_mt; + AM_MEDIA_TYPE mt; + HRESULT hr; + IPin *peer; + + peer = (IPin *)0xdeadbeef; + hr = IPin_ConnectedTo(source, &peer); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + ok(!peer, "Got peer %p.\n", peer); + + hr = IPin_ConnectionMediaType(source, &mt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + /* Exact connection. */ + + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IPin_ConnectedTo(source, &peer); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(peer == &testsink->sink.pin.IPin_iface, "Got peer %p.\n", peer); + IPin_Release(peer); + + hr = IPin_ConnectionMediaType(source, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&mt, &req_mt), "Media types didn't match.\n"); + ok(compare_media_types(&testsink->sink.pin.mt, &req_mt), "Media types didn't match.\n"); + + hr = IFilterGraph2_Disconnect(graph, source); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IFilterGraph2_Disconnect(graph, source); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + ok(testsink->sink.pin.peer == source, "Got peer %p.\n", testsink->sink.pin.peer); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + + req_mt.subtype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + } + req_mt.subtype = sink_mt.subtype; + + req_mt.majortype = MEDIATYPE_Audio; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + } + + /* Connection with wildcards. */ + + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink->sink.pin.mt, &sink_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + + req_mt.majortype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink->sink.pin.mt, &sink_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + + req_mt.subtype = MEDIASUBTYPE_RGB32; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, &req_mt); + ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + + req_mt.subtype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink->sink.pin.mt, &sink_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + + req_mt.formattype = FORMAT_WaveFormatEx; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + } + + req_mt = sink_mt; + req_mt.formattype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(compare_media_types(&testsink->sink.pin.mt, &sink_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + + req_mt.subtype = MEDIASUBTYPE_RGB32; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, &req_mt); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + } + + req_mt.subtype = GUID_NULL; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink->sink.pin.mt, &sink_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + + req_mt.majortype = MEDIATYPE_Audio; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, &req_mt); + ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + + testsink->sink_mt = &req_mt; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, NULL); + todo_wine ok(hr == VFW_E_NO_ACCEPTABLE_TYPES, "Got hr %#x.\n", hr); + if (hr == S_OK) + { + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + } + + req_mt = sink_mt; + req_mt.lSampleSize = 3; + hr = IFilterGraph2_ConnectDirect(graph, source, &testsink->sink.pin.IPin_iface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&testsink->sink.pin.mt, &req_mt), "Media types didn't match.\n"); + IFilterGraph2_Disconnect(graph, source); + IFilterGraph2_Disconnect(graph, &testsink->sink.pin.IPin_iface); + + testsink->sink_mt = NULL; +} + +static void test_connect_pin(void) +{ + AM_MEDIA_TYPE req_mt = + { + .majortype = MEDIATYPE_Stream, + .subtype = MEDIASUBTYPE_Avi, + .formattype = FORMAT_None, + .lSampleSize = 1, + }; + IBaseFilter *filter = create_smart_tee(); + struct testfilter testsource, testsink; + IPin *sink, *capture, *preview, *peer; + AM_MEDIA_TYPE mt, *mts[3]; + IEnumMediaTypes *enummt; + IFilterGraph2 *graph; + HRESULT hr; + ULONG ref; + + testfilter_init(&testsource); + testfilter_init(&testsink); + CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, + &IID_IFilterGraph2, (void **)&graph); + IFilterGraph2_AddFilter(graph, &testsource.filter.IBaseFilter_iface, L"source"); + IFilterGraph2_AddFilter(graph, &testsink.filter.IBaseFilter_iface, L"sink"); + IFilterGraph2_AddFilter(graph, filter, L"sample grabber"); + IBaseFilter_FindPin(filter, L"Input", &sink); + IBaseFilter_FindPin(filter, L"Capture", &capture); + IBaseFilter_FindPin(filter, L"Preview", &preview); + + testsource.source_mt.majortype = MEDIATYPE_Video; + testsource.source_mt.subtype = MEDIASUBTYPE_RGB8; + testsource.source_mt.formattype = FORMAT_VideoInfo; + + hr = IPin_EnumMediaTypes(sink, &enummt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IEnumMediaTypes_Next(enummt, 1, mts, NULL); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + IEnumMediaTypes_Release(enummt); + + hr = IPin_EnumMediaTypes(capture, &enummt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + hr = IPin_EnumMediaTypes(preview, &enummt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + hr = IPin_QueryAccept(sink, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(capture, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + hr = IPin_QueryAccept(preview, &req_mt); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + + /* Test sink connection. */ + + peer = (IPin *)0xdeadbeef; + hr = IPin_ConnectedTo(sink, &peer); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + ok(!peer, "Got peer %p.\n", peer); + + hr = IPin_ConnectionMediaType(sink, &mt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + hr = IFilterGraph2_ConnectDirect(graph, &testsource.source.pin.IPin_iface, sink, &req_mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IPin_ConnectedTo(sink, &peer); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(peer == &testsource.source.pin.IPin_iface, "Got peer %p.\n", peer); + IPin_Release(peer); + + hr = IPin_ConnectionMediaType(sink, &mt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(compare_media_types(&mt, &req_mt), "Media types didn't match.\n"); + + hr = IPin_EnumMediaTypes(sink, &enummt); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IEnumMediaTypes_Next(enummt, 1, mts, NULL); + todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); + IEnumMediaTypes_Release(enummt); + + test_source_media_types(req_mt, &testsource.source_mt, capture); + test_source_media_types(req_mt, &testsource.source_mt, preview); + test_source_connection(req_mt, graph, &testsink, capture); + test_source_connection(req_mt, graph, &testsink, preview); + + hr = IFilterGraph2_Disconnect(graph, sink); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IFilterGraph2_Disconnect(graph, sink); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + ok(testsource.source.pin.peer == sink, "Got peer %p.\n", testsource.source.pin.peer); + IFilterGraph2_Disconnect(graph, &testsource.source.pin.IPin_iface); + + peer = (IPin *)0xdeadbeef; + hr = IPin_ConnectedTo(sink, &peer); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + ok(!peer, "Got peer %p.\n", peer); + + hr = IPin_ConnectionMediaType(sink, &mt); + ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr); + + IPin_Release(sink); + IPin_Release(capture); + IPin_Release(preview); + ref = IFilterGraph2_Release(graph); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(filter); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(&testsource.filter.IBaseFilter_iface); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IBaseFilter_Release(&testsink.filter.IBaseFilter_iface); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + START_TEST(smartteefilter) { CoInitialize(NULL); @@ -2519,6 +3011,7 @@ START_TEST(smartteefilter) test_pin_info(); test_enum_media_types(); test_unconnected_filter_state(); + test_connect_pin();
test_smart_tee_filter();