From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mf/evr.c | 115 +++++++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 49 deletions(-)
diff --git a/dlls/mf/evr.c b/dlls/mf/evr.c index c9506af9143..db7053a1405 100644 --- a/dlls/mf/evr.c +++ b/dlls/mf/evr.c @@ -1432,38 +1432,43 @@ static HRESULT WINAPI video_renderer_sink_GetPresentationClock(IMFMediaSink *ifa static HRESULT WINAPI video_renderer_sink_Shutdown(IMFMediaSink *iface) { struct video_renderer *renderer = impl_from_IMFMediaSink(iface); + HRESULT hr = S_OK; size_t i;
TRACE("%p.\n", iface);
- if (renderer->flags & EVR_SHUT_DOWN) - return MF_E_SHUTDOWN; - EnterCriticalSection(&renderer->cs); - renderer->flags |= EVR_SHUT_DOWN; - /* Detach streams from the sink. */ - for (i = 0; i < renderer->stream_count; ++i) + + if (renderer->flags & EVR_SHUT_DOWN) + hr = MF_E_SHUTDOWN; + else { - struct video_stream *stream = renderer->streams[i]; + renderer->flags |= EVR_SHUT_DOWN; + /* Detach streams from the sink. */ + for (i = 0; i < renderer->stream_count; ++i) + { + struct video_stream *stream = renderer->streams[i];
- EnterCriticalSection(&stream->cs); - stream->parent = NULL; - LeaveCriticalSection(&stream->cs); + EnterCriticalSection(&stream->cs); + stream->parent = NULL; + LeaveCriticalSection(&stream->cs);
- IMFMediaEventQueue_Shutdown(stream->event_queue); - IMFStreamSink_Release(&stream->IMFStreamSink_iface); - IMFMediaSink_Release(iface); - renderer->streams[i] = NULL; + IMFMediaEventQueue_Shutdown(stream->event_queue); + IMFStreamSink_Release(&stream->IMFStreamSink_iface); + IMFMediaSink_Release(iface); + renderer->streams[i] = NULL; + } + free(renderer->streams); + renderer->stream_count = 0; + renderer->stream_size = 0; + IMFMediaEventQueue_Shutdown(renderer->event_queue); + video_renderer_set_presentation_clock(renderer, NULL); + video_renderer_release_services(renderer); } - free(renderer->streams); - renderer->stream_count = 0; - renderer->stream_size = 0; - IMFMediaEventQueue_Shutdown(renderer->event_queue); - video_renderer_set_presentation_clock(renderer, NULL); - video_renderer_release_services(renderer); + LeaveCriticalSection(&renderer->cs);
- return S_OK; + return hr; }
static const IMFMediaSinkVtbl video_renderer_sink_vtbl = @@ -1742,52 +1747,64 @@ static HRESULT video_renderer_initialize(struct video_renderer *renderer, IMFTra return hr; }
-static HRESULT WINAPI video_renderer_InitializeRenderer(IMFVideoRenderer *iface, IMFTransform *mixer, - IMFVideoPresenter *presenter) +static HRESULT video_renderer_create_mixer_and_presenter(struct video_renderer *renderer, + IMFTransform **mixer, IMFVideoPresenter **presenter) { - struct video_renderer *renderer = impl_from_IMFVideoRenderer(iface); HRESULT hr;
- TRACE("%p, %p, %p.\n", iface, mixer, presenter); - - EnterCriticalSection(&renderer->cs); - - if (renderer->flags & EVR_SHUT_DOWN) + if (*mixer) { - LeaveCriticalSection(&renderer->cs); - return MF_E_SHUTDOWN; + IMFTransform_AddRef(*mixer); } - - video_renderer_uninitialize(renderer); - - if (mixer) - IMFTransform_AddRef(mixer); - else if (FAILED(hr = video_renderer_create_mixer(NULL, &mixer))) + else if (FAILED(hr = video_renderer_create_mixer(NULL, mixer))) { WARN("Failed to create default mixer object, hr %#lx.\n", hr); - LeaveCriticalSection(&renderer->cs); return hr; }
- if (presenter) - IMFVideoPresenter_AddRef(presenter); - else if (FAILED(hr = video_renderer_create_presenter(renderer, NULL, &presenter))) + if (*presenter) + { + IMFVideoPresenter_AddRef(*presenter); + } + else if (FAILED(hr = video_renderer_create_presenter(renderer, NULL, presenter))) { WARN("Failed to create default presenter, hr %#lx.\n", hr); - LeaveCriticalSection(&renderer->cs); - IMFTransform_Release(mixer); + IMFTransform_Release(*mixer); return hr; }
- /* FIXME: check clock state */ - /* FIXME: check that streams are not initialized */ + return S_OK; +}
- hr = video_renderer_initialize(renderer, mixer, presenter); +static HRESULT WINAPI video_renderer_InitializeRenderer(IMFVideoRenderer *iface, IMFTransform *mixer, + IMFVideoPresenter *presenter) +{ + struct video_renderer *renderer = impl_from_IMFVideoRenderer(iface); + HRESULT hr;
- LeaveCriticalSection(&renderer->cs); + TRACE("%p, %p, %p.\n", iface, mixer, presenter);
- IMFTransform_Release(mixer); - IMFVideoPresenter_Release(presenter); + EnterCriticalSection(&renderer->cs); + + if (renderer->flags & EVR_SHUT_DOWN) + hr = MF_E_SHUTDOWN; + else + { + video_renderer_uninitialize(renderer); + + if (SUCCEEDED(hr = video_renderer_create_mixer_and_presenter(renderer, &mixer, &presenter))) + { + /* FIXME: check clock state */ + /* FIXME: check that streams are not initialized */ + + hr = video_renderer_initialize(renderer, mixer, presenter); + + IMFTransform_Release(mixer); + IMFVideoPresenter_Release(presenter); + } + } + + LeaveCriticalSection(&renderer->cs);
return hr; }
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mf/sar.c | 52 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-)
diff --git a/dlls/mf/sar.c b/dlls/mf/sar.c index 33040be3ed0..5504cc17472 100644 --- a/dlls/mf/sar.c +++ b/dlls/mf/sar.c @@ -451,21 +451,26 @@ static HRESULT WINAPI audio_renderer_sink_GetPresentationClock(IMFMediaSink *ifa static HRESULT WINAPI audio_renderer_sink_Shutdown(IMFMediaSink *iface) { struct audio_renderer *renderer = impl_from_IMFMediaSink(iface); + HRESULT hr = S_OK;
TRACE("%p.\n", iface);
+ EnterCriticalSection(&renderer->cs); + if (renderer->flags & SAR_SHUT_DOWN) - return MF_E_SHUTDOWN; + hr = MF_E_SHUTDOWN; + else + { + renderer->flags |= SAR_SHUT_DOWN; + IMFMediaEventQueue_Shutdown(renderer->event_queue); + IMFMediaEventQueue_Shutdown(renderer->stream_event_queue); + audio_renderer_set_presentation_clock(renderer, NULL); + audio_renderer_release_audio_client(renderer); + }
- EnterCriticalSection(&renderer->cs); - renderer->flags |= SAR_SHUT_DOWN; - IMFMediaEventQueue_Shutdown(renderer->event_queue); - IMFMediaEventQueue_Shutdown(renderer->stream_event_queue); - audio_renderer_set_presentation_clock(renderer, NULL); - audio_renderer_release_audio_client(renderer); LeaveCriticalSection(&renderer->cs);
- return S_OK; + return hr; }
static const IMFMediaSinkVtbl audio_renderer_sink_vtbl = @@ -1364,19 +1369,22 @@ static HRESULT WINAPI audio_renderer_stream_ProcessSample(IMFStreamSink *iface, if (!sample) return E_POINTER;
- if (renderer->flags & SAR_SHUT_DOWN) - return MF_E_STREAMSINK_REMOVED; - EnterCriticalSection(&renderer->cs);
- if (renderer->state == STREAM_STATE_RUNNING) - hr = stream_queue_sample(renderer, sample); - renderer->flags &= ~SAR_SAMPLE_REQUESTED; - - if (renderer->queued_frames < renderer->max_frames && renderer->state == STREAM_STATE_RUNNING) + if (renderer->flags & SAR_SHUT_DOWN) + hr = MF_E_STREAMSINK_REMOVED; + else { - IMFMediaEventQueue_QueueEventParamVar(renderer->stream_event_queue, MEStreamSinkRequestSample, &GUID_NULL, S_OK, NULL); - renderer->flags |= SAR_SAMPLE_REQUESTED; + if (renderer->state == STREAM_STATE_RUNNING) + hr = stream_queue_sample(renderer, sample); + renderer->flags &= ~SAR_SAMPLE_REQUESTED; + + if (renderer->queued_frames < renderer->max_frames && renderer->state == STREAM_STATE_RUNNING) + { + IMFMediaEventQueue_QueueEventParamVar(renderer->stream_event_queue, MEStreamSinkRequestSample, + &GUID_NULL, S_OK, NULL); + renderer->flags |= SAR_SAMPLE_REQUESTED; + } }
LeaveCriticalSection(&renderer->cs); @@ -1414,11 +1422,13 @@ static HRESULT WINAPI audio_renderer_stream_PlaceMarker(IMFStreamSink *iface, MF
TRACE("%p, %d, %p, %p.\n", iface, marker_type, marker_value, context_value);
+ EnterCriticalSection(&renderer->cs); + if (renderer->flags & SAR_SHUT_DOWN) - return MF_E_STREAMSINK_REMOVED; + hr = MF_E_STREAMSINK_REMOVED; + else + hr = stream_place_marker(renderer, marker_type, context_value);
- EnterCriticalSection(&renderer->cs); - hr = stream_place_marker(renderer, marker_type, context_value); LeaveCriticalSection(&renderer->cs);
return hr;
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mf/samplegrabber.c | 48 ++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/dlls/mf/samplegrabber.c b/dlls/mf/samplegrabber.c index f711f6d8c44..2d9f8109aca 100644 --- a/dlls/mf/samplegrabber.c +++ b/dlls/mf/samplegrabber.c @@ -507,32 +507,29 @@ static HRESULT WINAPI sample_grabber_stream_Flush(IMFStreamSink *iface) { struct sample_grabber *grabber = impl_from_IMFStreamSink(iface); struct scheduled_item *item, *next_item; + HRESULT hr = S_OK;
TRACE("%p.\n", iface);
- if (grabber->is_shut_down) - return MF_E_STREAMSINK_REMOVED; - EnterCriticalSection(&grabber->cs);
- LIST_FOR_EACH_ENTRY_SAFE(item, next_item, &grabber->items, struct scheduled_item, entry) + if (grabber->is_shut_down) + hr = MF_E_STREAMSINK_REMOVED; + else { - /* Samples are discarded, markers are processed immediately. */ - switch (item->type) + LIST_FOR_EACH_ENTRY_SAFE(item, next_item, &grabber->items, struct scheduled_item, entry) { - case ITEM_TYPE_SAMPLE: - break; - case ITEM_TYPE_MARKER: + /* Samples are discarded, markers are processed immediately. */ + if (item->type == ITEM_TYPE_MARKER) sample_grabber_stream_report_marker(grabber, &item->u.marker.context, E_ABORT); - break; - }
- stream_release_pending_item(item); + stream_release_pending_item(item); + } }
LeaveCriticalSection(&grabber->cs);
- return S_OK; + return hr; }
static const IMFStreamSinkVtbl sample_grabber_stream_vtbl = @@ -924,9 +921,6 @@ static HRESULT WINAPI sample_grabber_sink_GetStreamSinkByIndex(IMFMediaSink *ifa
TRACE("%p, %lu, %p.\n", iface, index, stream);
- if (grabber->is_shut_down) - return MF_E_SHUTDOWN; - EnterCriticalSection(&grabber->cs);
if (grabber->is_shut_down) @@ -1057,18 +1051,22 @@ static HRESULT WINAPI sample_grabber_sink_Shutdown(IMFMediaSink *iface)
TRACE("%p.\n", iface);
- if (grabber->is_shut_down) - return MF_E_SHUTDOWN; - EnterCriticalSection(&grabber->cs); - grabber->is_shut_down = TRUE; - sample_grabber_release_pending_items(grabber); - if (SUCCEEDED(hr = IMFSampleGrabberSinkCallback_OnShutdown(sample_grabber_get_callback(grabber)))) + + if (grabber->is_shut_down) + hr = MF_E_SHUTDOWN; + else { - sample_grabber_set_presentation_clock(grabber, NULL); - IMFMediaEventQueue_Shutdown(grabber->stream_event_queue); - IMFMediaEventQueue_Shutdown(grabber->event_queue); + grabber->is_shut_down = TRUE; + sample_grabber_release_pending_items(grabber); + if (SUCCEEDED(hr = IMFSampleGrabberSinkCallback_OnShutdown(sample_grabber_get_callback(grabber)))) + { + sample_grabber_set_presentation_clock(grabber, NULL); + IMFMediaEventQueue_Shutdown(grabber->stream_event_queue); + IMFMediaEventQueue_Shutdown(grabber->event_queue); + } } + LeaveCriticalSection(&grabber->cs);
return hr;