Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mfreadwrite/reader.c | 45 +++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/dlls/mfreadwrite/reader.c b/dlls/mfreadwrite/reader.c index a8df4da763..df921307e9 100644 --- a/dlls/mfreadwrite/reader.c +++ b/dlls/mfreadwrite/reader.c @@ -1658,29 +1658,46 @@ static HRESULT source_reader_read_sample(struct source_reader *reader, DWORD ind return hr; }
-static HRESULT WINAPI src_reader_ReadSample(IMFSourceReader *iface, DWORD index, DWORD flags, DWORD *actual_index, - DWORD *stream_flags, LONGLONG *timestamp, IMFSample **sample) +static HRESULT source_reader_read_sample_async(struct source_reader *reader, unsigned int index, unsigned int flags, + unsigned int *actual_index, unsigned int *stream_flags, LONGLONG *timestamp, IMFSample **sample) { - struct source_reader *reader = impl_from_IMFSourceReader(iface); struct source_reader_async_command *command; HRESULT hr;
- TRACE("%p, %#x, %#x, %p, %p, %p, %p\n", iface, index, flags, actual_index, stream_flags, timestamp, sample); + if (actual_index || stream_flags || timestamp || sample) + return E_INVALIDARG;
- if (reader->async_callback) + EnterCriticalSection(&reader->cs); + + if (reader->flags & SOURCE_READER_FLUSHING) + hr = MF_E_NOTACCEPTING; + else { - if (actual_index || stream_flags || timestamp || sample) - return E_INVALIDARG; + if (SUCCEEDED(hr = source_reader_create_async_op(SOURCE_READER_ASYNC_READ, &command))) + { + command->stream_index = index; + command->flags = flags;
- if (FAILED(hr = source_reader_create_async_op(SOURCE_READER_ASYNC_READ, &command))) - return hr; + hr = MFPutWorkItem(MFASYNC_CALLBACK_QUEUE_STANDARD, &reader->async_commands_callback, &command->IUnknown_iface); + IUnknown_Release(&command->IUnknown_iface); + } + } + + LeaveCriticalSection(&reader->cs);
- command->stream_index = index; - command->flags = flags; + return hr; +}
- hr = MFPutWorkItem(MFASYNC_CALLBACK_QUEUE_STANDARD, &reader->async_commands_callback, &command->IUnknown_iface); - IUnknown_Release(&command->IUnknown_iface); - } +static HRESULT WINAPI src_reader_ReadSample(IMFSourceReader *iface, DWORD index, DWORD flags, DWORD *actual_index, + DWORD *stream_flags, LONGLONG *timestamp, IMFSample **sample) +{ + struct source_reader *reader = impl_from_IMFSourceReader(iface); + HRESULT hr; + + TRACE("%p, %#x, %#x, %p, %p, %p, %p\n", iface, index, flags, actual_index, stream_flags, timestamp, sample); + + if (reader->async_callback) + hr = source_reader_read_sample_async(reader, index, flags, actual_index, stream_flags, timestamp, sample); else hr = source_reader_read_sample(reader, index, flags, actual_index, stream_flags, timestamp, sample);