From 9d7f98ee7f3b078df8fafaa3b3b7b59b81492d53 Mon Sep 17 00:00:00 2001 From: Derek Lesho Date: Fri, 30 Oct 2020 18:18:27 +0300 Subject: [PATCH] mfreadwrite: Abort ReadSample when unable to request any samples. Signed-off-by: Derek Lesho Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/mfreadwrite/reader.c | 13 ++++++++++--- dlls/mfreadwrite/tests/mfplat.c | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/dlls/mfreadwrite/reader.c b/dlls/mfreadwrite/reader.c index 96a82b798ab..cc1b29a2b6a 100644 --- a/dlls/mfreadwrite/reader.c +++ b/dlls/mfreadwrite/reader.c @@ -439,7 +439,8 @@ static HRESULT source_reader_new_stream_handler(struct source_reader *reader, IM } if (reader->streams[i].requests) - source_reader_request_sample(reader, &reader->streams[i]); + if (FAILED(source_reader_request_sample(reader, &reader->streams[i]))) + WakeAllConditionVariable(&reader->sample_event); } break; } @@ -1780,10 +1781,16 @@ static HRESULT source_reader_read_sample(struct source_reader *reader, DWORD ind stream->requests++; if (FAILED(hr = source_reader_request_sample(reader, stream))) WARN("Failed to request a sample, hr %#x.\n", hr); + if (stream->stream && !(stream->flags & STREAM_FLAG_SAMPLE_REQUESTED)) + { + *stream_flags = MF_SOURCE_READERF_ERROR; + *timestamp = 0; + break; + } SleepConditionVariableCS(&reader->sample_event, &reader->cs, INFINITE); } - - source_reader_get_read_result(reader, stream, flags, &hr, actual_index, stream_flags, + if (SUCCEEDED(hr)) + source_reader_get_read_result(reader, stream, flags, &hr, actual_index, stream_flags, timestamp, sample); } } diff --git a/dlls/mfreadwrite/tests/mfplat.c b/dlls/mfreadwrite/tests/mfplat.c index cfe68cb6736..0e5053f905f 100644 --- a/dlls/mfreadwrite/tests/mfplat.c +++ b/dlls/mfreadwrite/tests/mfplat.c @@ -158,6 +158,8 @@ static HRESULT WINAPI test_media_stream_GetStreamDescriptor(IMFMediaStream *ifac return S_OK; } +static BOOL fail_request_sample; + static HRESULT WINAPI test_media_stream_RequestSample(IMFMediaStream *iface, IUnknown *token) { struct test_media_stream *stream = impl_from_IMFMediaStream(iface); @@ -165,6 +167,9 @@ static HRESULT WINAPI test_media_stream_RequestSample(IMFMediaStream *iface, IUn IMFSample *sample; HRESULT hr; + if (fail_request_sample) + return E_NOTIMPL; + hr = MFCreateSample(&sample); ok(hr == S_OK, "Failed to create a sample, hr %#x.\n", hr); hr = IMFSample_SetSampleTime(sample, 123); @@ -977,6 +982,27 @@ static void test_source_reader_from_media_source(void) ok(hr == MF_E_NOTACCEPTING, "Unexpected hr %#x.\n", hr); IMFSourceReader_Release(reader); + IMFMediaSource_Release(source); + + /* RequestSample failure. */ + source = create_test_source(); + ok(!!source, "Failed to create test source.\n"); + + fail_request_sample = TRUE; + + hr = MFCreateSourceReaderFromMediaSource(source, NULL, &reader); + ok(hr == S_OK, "Failed to create source reader, hr %#x.\n", hr); + + hr = IMFSourceReader_SetStreamSelection(reader, 0, TRUE); + ok(hr == S_OK, "Failed to select a stream, hr %#x.\n", hr); + + hr = IMFSourceReader_ReadSample(reader, 0, 0, &actual_index, &stream_flags, ×tamp, &sample); + ok(hr == E_NOTIMPL, "Unexpected ReadSample result, hr %#x.\n", hr); + + IMFSourceReader_Release(reader); + IMFMediaSource_Release(source); + + fail_request_sample = FALSE; } START_TEST(mfplat)