Commit f72f1ff9 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

mfplat/tests: Get source events in async mode.

Fixes test crashes on Windows 7, that happen on synchronous GetEvent(). Signed-off-by: 's avatarNikolay Sivov <nsivov@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 4b362d01
......@@ -191,6 +191,7 @@ struct test_callback
IMFAsyncCallback IMFAsyncCallback_iface;
HANDLE event;
DWORD param;
IMFMediaEvent *media_event;
};
static struct test_callback *impl_from_IMFAsyncCallback(IMFAsyncCallback *iface)
......@@ -420,38 +421,77 @@ static const IMFAsyncCallbackVtbl test_create_from_file_handler_callback_vtbl =
test_create_from_file_handler_callback_Invoke,
};
static HRESULT WINAPI source_events_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
{
struct test_callback *callback = impl_from_IMFAsyncCallback(iface);
IMFMediaEventGenerator *generator;
HRESULT hr;
ok(!!result, "Unexpected result object.\n");
generator = (IMFMediaEventGenerator *)IMFAsyncResult_GetStateNoAddRef(result);
hr = IMFMediaEventGenerator_EndGetEvent(generator, result, &callback->media_event);
ok(hr == S_OK, "Failed to create an object, hr %#x.\n", hr);
SetEvent(callback->event);
return S_OK;
}
static const IMFAsyncCallbackVtbl events_callback_vtbl =
{
testcallback_QueryInterface,
testcallback_AddRef,
testcallback_Release,
testcallback_GetParameters,
source_events_callback_Invoke,
};
static BOOL get_event(IMFMediaEventGenerator *generator, MediaEventType expected_event_type, PROPVARIANT *value)
{
struct test_callback callback = { 0 };
MediaEventType event_type;
HRESULT hr, event_status;
IMFMediaEvent *event;
BOOL ret = FALSE;
HRESULT hr;
hr = IMFMediaEventGenerator_GetEvent(generator, 0, &event);
ok(hr == S_OK, "Failed to get event, hr %#x.\n", hr);
callback.IMFAsyncCallback_iface.lpVtbl = &events_callback_vtbl;
callback.event = CreateEventA(NULL, FALSE, FALSE, NULL);
hr = IMFMediaEvent_GetStatus(event, &event_status);
ok(hr == S_OK, "Failed to get status code, hr %#x.\n", hr);
ok(event_status == S_OK, "Unexpected event status code %#x.\n", event_status);
for (;;)
{
hr = IMFMediaEventGenerator_BeginGetEvent(generator, &callback.IMFAsyncCallback_iface,
(IUnknown *)generator);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
hr = IMFMediaEvent_GetType(event, &event_type);
ok(hr == S_OK, "Failed to event type, hr %#x.\n", hr);
ok(event_type == expected_event_type, "Unexpected event type %u, expected %u.\n", event_type, expected_event_type);
if (WaitForSingleObject(callback.event, 1000) == WAIT_TIMEOUT)
{
ok(0, "timeout\n");
break;
}
if (event_type != expected_event_type)
{
IMFMediaEvent_Release(event);
return FALSE;
}
Sleep(10);
if (value)
{
hr = IMFMediaEvent_GetValue(event, value);
ok(hr == S_OK, "Failed to get value of event, hr %#x.\n", hr);
hr = IMFMediaEvent_GetType(callback.media_event, &event_type);
ok(hr == S_OK, "Failed to event type, hr %#x.\n", hr);
if ((ret = (event_type == expected_event_type)))
{
if (value)
{
hr = IMFMediaEvent_GetValue(callback.media_event, value);
ok(hr == S_OK, "Failed to get value of event, hr %#x.\n", hr);
}
break;
}
}
IMFMediaEvent_Release(event);
CloseHandle(callback.event);
if (callback.media_event)
IMFMediaEvent_Release(callback.media_event);
return TRUE;
return ret;
}
static void test_source_resolver(void)
......@@ -612,14 +652,13 @@ todo_wine
hr = IMFMediaSource_Start(mediasource, descriptor, &GUID_NULL, &var);
ok(hr == S_OK, "Failed to start media source, hr %#x.\n", hr);
get_event((IMFMediaEventGenerator *)mediasource, MENewStream, &var);
ok(var.vt == VT_UNKNOWN, "Unexpected value type %u from MENewStream event.\n", var.vt);
video_stream = (IMFMediaStream *)var.punkVal;
get_event((IMFMediaEventGenerator *)mediasource, MESourceStarted, NULL);
video_stream = NULL;
if (get_event((IMFMediaEventGenerator *)mediasource, MENewStream, &var))
{
ok(var.vt == VT_UNKNOWN, "Unexpected value type.\n");
video_stream = (IMFMediaStream *)var.punkVal;
}
/* Request samples, our file is 10 frames at 25fps */
get_event((IMFMediaEventGenerator *)video_stream, MEStreamStarted, NULL);
sample_count = 10;
for (i = 0; i < sample_count; ++i)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment