Signed-off-by: Derek Lesho dlesho@codeweavers.com --- dlls/mfplat/tests/mfplat.c | 184 ++++++++++++++++++++++++++++++++++++- 1 file changed, 181 insertions(+), 3 deletions(-)
diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index d0e05650c2..43ca186236 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -350,6 +350,67 @@ static const IMFAsyncCallbackVtbl test_create_from_file_handler_callback_vtbl = test_create_from_file_handler_callback_Invoke, };
+struct expected_event +{ + HRESULT status_code; + MediaEventType type; + GUID *extended_type; +}; + +static BOOL expect_event(IMFMediaEventGenerator *gen, struct expected_event *expected, PROPVARIANT *out) +{ + HRESULT hr; + IMFMediaEvent *event; + BOOL ret = TRUE; + + hr = IMFMediaEventGenerator_GetEvent(gen, 0, &event); + ok(hr == S_OK, "Failed to get event from media source, hr %#x.\n", hr); + { + HRESULT status_code; + hr = IMFMediaEvent_GetStatus(event, &status_code); + ok (hr == S_OK, "Failed to get status code, hr %#x.\n", hr); + ok (status_code == expected->status_code, "Unexpected status code %#x, expected %#x.\n", + status_code, expected->status_code); + + if (hr != S_OK || status_code != expected->status_code) + ret = FALSE; + } + { + MediaEventType event_type; + hr = IMFMediaEvent_GetType(event, &event_type); + ok(hr == S_OK, "Failed to event type, hr %#x.\n", hr); + ok(event_type == expected->type, "Unexpected event type %u, expected %u.\n", + event_type, expected->type); + + if (hr != S_OK || event_type != expected->type) + ret = FALSE; + } + if (expected->extended_type) + { + GUID extended_type; + BOOL is_equal; + hr = IMFMediaEvent_GetExtendedType(event, &extended_type); + ok(hr == S_OK, "Failed to get extended type, hr %#x.\n", hr); + is_equal = IsEqualGUID(&extended_type, expected->extended_type); + ok(is_equal, "Unexpected extended type %s, expected %s.\n", + debugstr_guid(&extended_type), debugstr_guid(expected->extended_type)); + + if (hr != S_OK || !is_equal) + ret = FALSE; + } + if (out) + { + hr = IMFMediaEvent_GetValue(event, out); + ok (hr == S_OK, "Failed to get value of event, hr %#x.\n", hr); + + if (hr != S_OK) + ret = FALSE; + } + IMFMediaEvent_Release(event); + + return ret; +} + static void test_source_resolver(void) { static const WCHAR file_type[] = {'v','i','d','e','o','/','m','p','4',0}; @@ -361,7 +422,7 @@ static void test_source_resolver(void) IMFMediaSource *mediasource; IMFPresentationDescriptor *descriptor; IMFMediaTypeHandler *handler; - BOOL selected, do_uninit; + IMFMediaType *type; MF_OBJECT_TYPE obj_type; IMFStreamDescriptor *sd; IUnknown *cancel_cookie; @@ -370,6 +431,9 @@ static void test_source_resolver(void) HRESULT hr; WCHAR *filename; GUID guid; + PROPVARIANT empty_var; + BOOL selected, do_uninit, skip_source_tests; + ULONG refcount;
if (!pMFCreateSourceResolver) { @@ -451,13 +515,127 @@ static void test_source_resolver(void) hr = IMFMediaTypeHandler_GetMajorType(handler, &guid); todo_wine ok(hr == S_OK, "Failed to get stream major type, hr %#x.\n", hr); + if (hr == S_OK) + { + ok (IsEqualGUID(&guid, &MFMediaType_Video), "Unexpected major type %s.\n", debugstr_guid(&guid)); + + hr = IMFMediaTypeHandler_GetCurrentMediaType(handler, &type); + ok (hr == S_OK, "Failed to get current media type, hr %#x.\n", hr); + + hr = IMFMediaType_GetGUID(type, &MF_MT_SUBTYPE, &guid); + ok(hr == S_OK, "Failed to get media sub type, hr %#x.\n", hr); + ok(IsEqualGUID(&guid, &MFVideoFormat_M4S2), "Unexpected sub type %s.\n", debugstr_guid(&guid)); + + hr = IMFPresentationDescriptor_SelectStream(descriptor, 0); + ok(hr == S_OK, "Failed to select video stream, hr %#x.\n", hr); + + IMFMediaType_Release(type); + + skip_source_tests = FALSE; + } + else + { + /* skip media source tests to avoid crashing, as the media source is fake */ + skip_source_tests = TRUE; + }
IMFMediaTypeHandler_Release(handler); IMFStreamDescriptor_Release(sd);
+ if (skip_source_tests) + goto source_tests_end; + + empty_var.vt = VT_EMPTY; + hr = IMFMediaSource_Start(mediasource, descriptor, &GUID_NULL, &empty_var); + ok(hr == S_OK, "Failed to start media source, hr %#x.\n", hr); + + if (hr == S_OK) + { + static struct expected_event new_stream_event = { S_OK, MENewStream, NULL }; + static struct expected_event source_started_event = { S_OK, MESourceStarted, NULL }; + static struct expected_event end_of_presentation_event = {S_OK, MEEndOfPresentation, NULL }; + PROPVARIANT new_stream_value; + IMFMediaStream *video_stream; + + expect_event((IMFMediaEventGenerator*)mediasource, &new_stream_event, &new_stream_value); + ok(new_stream_value.vt == VT_UNKNOWN, "Unexpected value type %u from MENewStream event.\n", + new_stream_value.vt); + video_stream = (IMFMediaStream *)new_stream_value.punkVal; + expect_event((IMFMediaEventGenerator*)mediasource, &source_started_event, NULL); + + /* TODO: verify stream information */ + + /* Request samples, our file is 10 frames at 25fps */ + { + static struct expected_event stream_started_event = { S_OK, MEStreamStarted, NULL }; + static struct expected_event new_sample_event = {S_OK, MEMediaSample, NULL}; + static struct expected_event end_of_stream_event = {S_OK, MEEndOfStream, NULL}; + unsigned int i, sample_count = 10; + + expect_event((IMFMediaEventGenerator*)video_stream, &stream_started_event, NULL); + + /* request one beyond EOS, otherwise EndOfStream isn't queued */ + for (i = 0; i <= sample_count; i++) + { + hr = IMFMediaStream_RequestSample(video_stream, NULL); + if (i == sample_count) + break; + ok(hr == S_OK, "Failed to request sample %u, hr %#x.\n", i + 1, hr); + if (hr != S_OK) + break; + } + + for (i = 0; i < sample_count; i++) + { + PROPVARIANT new_sample_value; + IMFSample *sample; + DWORD buffer_count; + LONGLONG duration, time; + static const LONGLONG MILLI_TO_100_NANO = 10000; + + if (!(expect_event((IMFMediaEventGenerator*)video_stream, &new_sample_event, &new_sample_value))) + { + ok(FALSE, "Sample %u not recieved.\n", i + 1); + break; + } + ok(new_sample_value.vt == VT_UNKNOWN, "Unexpected value type %u from MEMediaSample event.\n", + new_sample_value.vt); + sample = (IMFSample *)new_sample_value.punkVal; + + hr = IMFSample_GetBufferCount(sample, &buffer_count); + ok(hr == S_OK, "Failed to get buffer count, hr %#x.\n", hr); + ok(buffer_count == 1, "Unexpected buffer count %u.\n", buffer_count); + + hr = IMFSample_GetSampleDuration(sample, &duration); + ok(hr == S_OK, "Failed to get sample duration, hr %#x.\n", hr); + ok(duration == 40 * MILLI_TO_100_NANO, "Unexpected duration %s.\n", wine_dbgstr_longlong(duration)); + + hr = IMFSample_GetSampleTime(sample, &time); + ok(hr == S_OK, "Failed to get sample time, hr %#x.\n", hr); + ok(time == i * 40 * MILLI_TO_100_NANO, "Unexpected time %s.\n", wine_dbgstr_longlong(time)); + } + + if (i == sample_count) + expect_event((IMFMediaEventGenerator*)video_stream, &end_of_stream_event, NULL); + + hr = IMFMediaStream_RequestSample(video_stream, NULL); + ok (hr == MF_E_END_OF_STREAM, "Unexpected hr %#x, expected MF_E_END_OF_STREAM.\n", hr); + } + + expect_event((IMFMediaEventGenerator*)mediasource, &end_of_presentation_event, NULL); + } + IMFPresentationDescriptor_Release(descriptor); - IMFMediaSource_Release(mediasource); - IMFByteStream_Release(stream); + IMFMediaSource_Shutdown(mediasource); + + hr = IMFMediaSource_CreatePresentationDescriptor(mediasource, NULL); + ok (hr == MF_E_SHUTDOWN, "Got 0x%08x\n", hr); + + source_tests_end: + refcount = IMFMediaSource_Release(mediasource); + ok(!refcount, "Unexpected refcount %u.\n", refcount); + refcount = IMFByteStream_Release(stream); + ok(!refcount, "Unexpected refcount %u.\n", refcount);
/* Create from URL. */ callback.event = CreateEventA(NULL, FALSE, FALSE, NULL);