From: Brendan McGrath <bmcgrath@codeweavers.com> --- dlls/mf/tests/mf.c | 136 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/dlls/mf/tests/mf.c b/dlls/mf/tests/mf.c index d8b22012aab..03fb9037134 100644 --- a/dlls/mf/tests/mf.c +++ b/dlls/mf/tests/mf.c @@ -6646,6 +6646,142 @@ if (time_source) ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(time == 0, "Unexpected time %I64d.\n", time); + /* Test preroll start when duration is provided */ + hr = IMFMediaSinkPreroll_NotifyPreroll(preroll, 0); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + /* We should now get two sample requests */ + hr = gen_wait_media_event_until_blocking((IMFMediaEventGenerator*)stream, callback, MEStreamSinkRequestSample, 1000, &propvar); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + PropVariantClear(&propvar); + + hr = gen_wait_media_event_until_blocking((IMFMediaEventGenerator*)stream, callback, MEStreamSinkRequestSample, 1000, &propvar); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + PropVariantClear(&propvar); + + /* Provide one sample. Note that duration is set */ + sample = create_audio_sample(samples_per_second, 100000); + hr = IMFSample_SetSampleTime(sample, 0); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = IMFSample_SetSampleDuration(sample, 100000); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IMFStreamSink_ProcessSample(stream, sample); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + IMFSample_Release(sample); + + /* But no MEStreamSinkPrerolled will be provided until we provide at least 200ms of data */ + hr = gen_wait_media_event_until_blocking((IMFMediaEventGenerator*)stream, callback, MEStreamSinkPrerolled, 100, &propvar); + ok(hr == WAIT_TIMEOUT, "Unexpected hr %#lx.\n", hr); + PropVariantClear(&propvar); + + /* Provide second sample */ + sample = create_audio_sample(samples_per_second, 100000); + hr = IMFSample_SetSampleTime(sample, 100000); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = IMFSample_SetSampleDuration(sample, 100000); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IMFStreamSink_ProcessSample(stream, sample); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + IMFSample_Release(sample); + + /* A third sample is requested only after the first two have been delivered */ + hr = gen_wait_media_event_until_blocking((IMFMediaEventGenerator*)stream, callback, MEStreamSinkRequestSample, 1000, &propvar); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + PropVariantClear(&propvar); + + /* But we still don't get the pre-roll event. Not until we provide 200ms of data */ + hr = gen_wait_media_event_until_blocking((IMFMediaEventGenerator*)stream, callback, MEStreamSinkPrerolled, 100, &propvar); + ok(hr == WAIT_TIMEOUT, "Unexpected hr %#lx.\n", hr); + PropVariantClear(&propvar); + + /* Confirm a start prior to pre-roll completion will fail */ + hr = IMFPresentationClock_Start(clock, 0); + ok(hr == MF_E_STATE_TRANSITION_PENDING, "Unexpected hr %#lx.\n", hr); + + /* Complete the pre-roll, we still need 180ms of duration. We'll send an 80ms sample and four 25ms. + * A new sample will be requested after each is provided; but for the last */ + + sample = create_audio_sample(samples_per_second, 800000); + hr = IMFSample_SetSampleTime(sample, 200000); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = IMFSample_SetSampleDuration(sample, 800000); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IMFStreamSink_ProcessSample(stream, sample); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + IMFSample_Release(sample); + + time = 1000000; + for (i = 0; i < 4; i++) + { + const LONGLONG duration = 250000; + hr = gen_wait_media_event_until_blocking((IMFMediaEventGenerator*)stream, callback, MEStreamSinkRequestSample, 1000, &propvar); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + PropVariantClear(&propvar); + + sample = create_audio_sample(samples_per_second, duration); + hr = IMFSample_SetSampleTime(sample, time); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = IMFSample_SetSampleDuration(sample, duration); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IMFStreamSink_ProcessSample(stream, sample); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + IMFSample_Release(sample); + + time += duration; + } + + /* A new sample is not requested if duration is provided and the total duration of samples buffered is 200ms or more + * Instead there is a preroll event */ + hr = gen_wait_media_event_until_blocking((IMFMediaEventGenerator*)stream, callback, MEStreamSinkPrerolled, 1000, &propvar); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + PropVariantClear(&propvar); + + /* Check clock time before start */ + hr = IMFPresentationClock_GetTime(clock, &time); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + ok(time == 0, "Unexpected time %I64d.\n", time); + + /* Start clock */ + hr = IMFPresentationClock_Start(clock, 0); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + /* On start, the 200ms worth of samples will be consumed. A new sample is requested for each sample consumed. In this case, it is seven. */ + for (i = 0; i < 7; i++) + { + hr = gen_wait_media_event_until_blocking((IMFMediaEventGenerator*)stream, callback, MEStreamSinkRequestSample, 1000, &propvar); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + PropVariantClear(&propvar); + } + + /* Check clock time */ + time = 0; + for (i = 0; i < 100 && time < 2000000; i++) + { + IMFPresentationClock_GetTime(clock, &time); + Sleep(50); + } + + /* Clock time will halt at exactly 2000000 as this is the total duration of all the provided samples */ + ok(time == 2000000, "Unexpected time %I64d.\n", time); + + /* Stop clock */ + hr = IMFPresentationClock_Stop(clock); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + /* Get stop event */ + hr = gen_wait_media_event_until_blocking((IMFMediaEventGenerator*)stream, callback, MEStreamSinkStopped, 1000, &propvar); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + PropVariantClear(&propvar); + + /* Time should now be zero */ + hr = IMFPresentationClock_GetTime(clock, &time); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + ok(time == 0, "Unexpected time %I64d.\n", time); + IMFMediaSinkPreroll_Release(preroll); IMFPresentationTimeSource_Release(time_source); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9979