Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/winegstreamer/wm_asyncreader.c | 58 +++++++++++++++++++++++++---- dlls/wmvcore/tests/wmvcore.c | 21 +++++------ 2 files changed, 60 insertions(+), 19 deletions(-)
diff --git a/dlls/winegstreamer/wm_asyncreader.c b/dlls/winegstreamer/wm_asyncreader.c index 4fec89a2100..3448e156fa0 100644 --- a/dlls/winegstreamer/wm_asyncreader.c +++ b/dlls/winegstreamer/wm_asyncreader.c @@ -31,8 +31,20 @@ struct async_reader IWMReaderStreamClock IWMReaderStreamClock_iface; IWMReaderTypeNegotiation IWMReaderTypeNegotiation_iface; IReferenceClock IReferenceClock_iface; + + IWMReaderCallback *callback; + void *context; };
+static void open_stream(struct async_reader *reader, IWMReaderCallback *callback, void *context) +{ + static const DWORD zero; + + IWMReaderCallback_AddRef(reader->callback = callback); + reader->context = context; + IWMReaderCallback_OnStatus(callback, WMT_OPENED, S_OK, WMT_TYPE_DWORD, (BYTE *)&zero, context); +} + static struct async_reader *impl_from_IWMReader(IWMReader *iface) { return CONTAINING_RECORD(iface, struct async_reader, IWMReader_iface); @@ -68,9 +80,26 @@ static HRESULT WINAPI WMReader_Open(IWMReader *iface, const WCHAR *url, IWMReade
static HRESULT WINAPI WMReader_Close(IWMReader *iface) { - struct async_reader *This = impl_from_IWMReader(iface); - FIXME("(%p)\n", This); - return E_NOTIMPL; + struct async_reader *reader = impl_from_IWMReader(iface); + static const DWORD zero; + HRESULT hr; + + TRACE("reader %p.\n", reader); + + EnterCriticalSection(&reader->reader.cs); + + hr = wm_reader_close(&reader->reader); + if (reader->callback) + { + IWMReaderCallback_OnStatus(reader->callback, WMT_CLOSED, S_OK, + WMT_TYPE_DWORD, (BYTE *)&zero, reader->context); + IWMReaderCallback_Release(reader->callback); + } + reader->callback = NULL; + + LeaveCriticalSection(&reader->reader.cs); + + return hr; }
static HRESULT WINAPI WMReader_GetOutputCount(IWMReader *iface, DWORD *outputs) @@ -427,12 +456,21 @@ static HRESULT WINAPI WMReaderAdvanced2_StopBuffering(IWMReaderAdvanced6 *iface) return E_NOTIMPL; }
-static HRESULT WINAPI WMReaderAdvanced2_OpenStream(IWMReaderAdvanced6 *iface, IStream *stream, - IWMReaderCallback *callback, void *context) +static HRESULT WINAPI WMReaderAdvanced2_OpenStream(IWMReaderAdvanced6 *iface, + IStream *stream, IWMReaderCallback *callback, void *context) { - struct async_reader *This = impl_from_IWMReaderAdvanced6(iface); - FIXME("(%p)->(%p %p %p)\n", This, stream, callback, context); - return E_NOTIMPL; + struct async_reader *reader = impl_from_IWMReaderAdvanced6(iface); + HRESULT hr; + + TRACE("reader %p, stream %p, callback %p, context %p.\n", reader, stream, callback, context); + + EnterCriticalSection(&reader->reader.cs); + + if (SUCCEEDED(hr = wm_reader_open_stream(&reader->reader, stream))) + open_stream(reader, callback, context); + + LeaveCriticalSection(&reader->reader.cs); + return hr; }
static HRESULT WINAPI WMReaderAdvanced3_StopNetStreaming(IWMReaderAdvanced6 *iface) @@ -1256,6 +1294,10 @@ static void async_reader_destroy(struct wm_reader *iface) TRACE("reader %p.\n", reader);
wm_reader_close(&reader->reader); + + if (reader->callback) + IWMReaderCallback_Release(reader->callback); + wm_reader_cleanup(&reader->reader); free(reader); } diff --git a/dlls/wmvcore/tests/wmvcore.c b/dlls/wmvcore/tests/wmvcore.c index ef6aa294c48..4e40aa53dfe 100644 --- a/dlls/wmvcore/tests/wmvcore.c +++ b/dlls/wmvcore/tests/wmvcore.c @@ -1245,9 +1245,7 @@ static void test_async_reader_streaming(void) IWMReader_QueryInterface(reader, &IID_IWMReaderAdvanced2, (void **)&advanced);
hr = IWMReaderAdvanced2_OpenStream(advanced, &stream.IStream_iface, &callback.IWMReaderCallback_iface, (void **)0xdeadbeef); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - if (hr != S_OK) - goto out; + ok(hr == S_OK, "Got hr %#x.\n", hr); ok(stream.refcount > 1, "Got refcount %d.\n", stream.refcount); ok(callback.refcount > 1, "Got refcount %d.\n", callback.refcount); ret = WaitForSingleObject(callback.got_opened, 1000); @@ -1305,19 +1303,18 @@ static void test_async_reader_streaming(void) test_reader_attributes(profile);
hr = IWMReader_Close(reader); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(callback.got_closed == 1, "Got %u WMT_CLOSED callbacks.\n", callback.got_closed); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(callback.got_closed == 1, "Got %u WMT_CLOSED callbacks.\n", callback.got_closed); ok(callback.refcount == 1, "Got outstanding refcount %d.\n", callback.refcount); callback_cleanup(&callback);
-out: ok(stream.refcount == 1, "Got outstanding refcount %d.\n", stream.refcount); CloseHandle(stream.file); ret = DeleteFileW(filename); ok(ret, "Failed to delete %s, error %u.\n", debugstr_w(filename), GetLastError());
hr = IWMReader_Close(reader); - todo_wine ok(hr == NS_E_INVALID_REQUEST, "Got hr %#x.\n", hr); + ok(hr == NS_E_INVALID_REQUEST, "Got hr %#x.\n", hr);
IWMReaderAdvanced2_Release(advanced); IWMProfile_Release(profile); @@ -1358,9 +1355,7 @@ static void test_async_reader_types(void) IWMReader_QueryInterface(reader, &IID_IWMReaderAdvanced2, (void **)&advanced);
hr = IWMReaderAdvanced2_OpenStream(advanced, &stream.IStream_iface, &callback.IWMReaderCallback_iface, (void **)0xdeadbeef); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - if (hr != S_OK) - goto out; + ok(hr == S_OK, "Got hr %#x.\n", hr); ok(stream.refcount > 1, "Got refcount %d.\n", stream.refcount); ok(callback.refcount > 1, "Got refcount %d.\n", callback.refcount); ret = WaitForSingleObject(callback.got_opened, 1000); @@ -1393,6 +1388,11 @@ static void test_async_reader_types(void)
hr = IWMReader_GetOutputProps(reader, output_number, &output_props); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + if (hr != S_OK) + { + winetest_pop_context(); + continue; + }
ret_size = sizeof(mt_buffer); hr = IWMOutputMediaProps_GetMediaType(output_props, mt, &ret_size); @@ -1554,7 +1554,6 @@ static void test_async_reader_types(void) todo_wine ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); ok(output_props == (void *)0xdeadbeef, "Got output props %p.\n", output_props);
-out: IWMReaderAdvanced2_Release(advanced); IWMProfile_Release(profile); ref = IWMReader_Release(reader);