From 9cb55ea30d57fe9c775db259733f8b5a58a8e0a5 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Tue, 5 Nov 2019 14:09:44 +0300 Subject: [PATCH] mfreadwrite: Return earlier on ReadSample() is stream is deselected. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/mfreadwrite/main.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/dlls/mfreadwrite/main.c b/dlls/mfreadwrite/main.c index 9fa1445a8f9..f24de690bc3 100644 --- a/dlls/mfreadwrite/main.c +++ b/dlls/mfreadwrite/main.c @@ -591,10 +591,20 @@ static ULONG WINAPI src_reader_Release(IMFSourceReader *iface) return refcount; } +static HRESULT source_reader_get_stream_selection(const struct source_reader *reader, DWORD index, BOOL *selected) +{ + IMFStreamDescriptor *sd; + + if (FAILED(IMFPresentationDescriptor_GetStreamDescriptorByIndex(reader->descriptor, index, selected, &sd))) + return MF_E_INVALIDSTREAMNUMBER; + IMFStreamDescriptor_Release(sd); + + return S_OK; +} + static HRESULT WINAPI src_reader_GetStreamSelection(IMFSourceReader *iface, DWORD index, BOOL *selected) { struct source_reader *reader = impl_from_IMFSourceReader(iface); - IMFStreamDescriptor *sd; TRACE("%p, %#x, %p.\n", iface, index, selected); @@ -610,11 +620,7 @@ static HRESULT WINAPI src_reader_GetStreamSelection(IMFSourceReader *iface, DWOR ; } - if (FAILED(IMFPresentationDescriptor_GetStreamDescriptorByIndex(reader->descriptor, index, selected, &sd))) - return MF_E_INVALIDSTREAMNUMBER; - IMFStreamDescriptor_Release(sd); - - return S_OK; + return source_reader_get_stream_selection(reader, index, selected); } static HRESULT WINAPI src_reader_SetStreamSelection(IMFSourceReader *iface, DWORD index, BOOL selected) @@ -820,6 +826,7 @@ static HRESULT source_reader_read_sample(struct source_reader *reader, DWORD ind struct media_stream *stream; DWORD stream_index; HRESULT hr = S_OK; + BOOL selected; if (!stream_flags || !sample) return E_POINTER; @@ -841,12 +848,16 @@ static HRESULT source_reader_read_sample(struct source_reader *reader, DWORD ind stream_index = index; } - if (stream_index >= reader->stream_count) + /* Can't read from deselected streams. */ + if (SUCCEEDED(hr = source_reader_get_stream_selection(reader, stream_index, &selected)) && !selected) + hr = MF_E_INVALIDREQUEST; + + if (FAILED(hr)) { *stream_flags = MF_SOURCE_READERF_ERROR; if (actual_index) *actual_index = index; - return MF_E_INVALIDSTREAMNUMBER; + return hr; } if (actual_index)