Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mf/sar.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/dlls/mf/sar.c b/dlls/mf/sar.c index d14a903eea..da1bd9b216 100644 --- a/dlls/mf/sar.c +++ b/dlls/mf/sar.c @@ -612,6 +612,7 @@ static HRESULT WINAPI audio_renderer_clock_sink_OnClockPause(IMFClockStateSink * static HRESULT WINAPI audio_renderer_clock_sink_OnClockRestart(IMFClockStateSink *iface, MFTIME systime) { struct audio_renderer *renderer = impl_from_IMFClockStateSink(iface); + BOOL preroll = FALSE; HRESULT hr = S_OK;
TRACE("%p, %s.\n", iface, debugstr_time(systime)); @@ -619,7 +620,7 @@ static HRESULT WINAPI audio_renderer_clock_sink_OnClockRestart(IMFClockStateSink EnterCriticalSection(&renderer->cs); if (renderer->audio_client) { - if (renderer->state == STREAM_STATE_PAUSED) + if ((preroll = (renderer->state != STREAM_STATE_RUNNING))) { if (FAILED(hr = IAudioClient_Start(renderer->audio_client))) WARN("Failed to start audio client, hr %#x.\n", hr); @@ -630,6 +631,9 @@ static HRESULT WINAPI audio_renderer_clock_sink_OnClockRestart(IMFClockStateSink hr = MF_E_NOT_INITIALIZED;
IMFMediaEventQueue_QueueEventParamVar(renderer->stream_event_queue, MEStreamSinkStarted, &GUID_NULL, hr, NULL); + if (preroll) + audio_renderer_preroll(renderer); + LeaveCriticalSection(&renderer->cs);
return hr;
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mf/sar.c | 103 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 86 insertions(+), 17 deletions(-)
diff --git a/dlls/mf/sar.c b/dlls/mf/sar.c index da1bd9b216..83d50b7f0b 100644 --- a/dlls/mf/sar.c +++ b/dlls/mf/sar.c @@ -58,6 +58,7 @@ struct audio_renderer IMFMediaType *current_media_type; IMMDevice *device; IAudioClient *audio_client; + IAudioStreamVolume *stream_volume; HANDLE buffer_ready_event; enum stream_state state; BOOL is_shut_down; @@ -161,6 +162,16 @@ static ULONG WINAPI audio_renderer_sink_AddRef(IMFMediaSink *iface) return refcount; }
+static void audio_renderer_release_audio_client(struct audio_renderer *renderer) +{ + if (renderer->audio_client) + IAudioClient_Release(renderer->audio_client); + renderer->audio_client = NULL; + if (renderer->stream_volume) + IAudioStreamVolume_Release(renderer->stream_volume); + renderer->stream_volume = NULL; +} + static ULONG WINAPI audio_renderer_sink_Release(IMFMediaSink *iface) { struct audio_renderer *renderer = impl_from_IMFMediaSink(iface); @@ -183,8 +194,7 @@ static ULONG WINAPI audio_renderer_sink_Release(IMFMediaSink *iface) if (renderer->current_media_type) IMFMediaType_Release(renderer->current_media_type); CloseHandle(renderer->buffer_ready_event); - if (renderer->audio_client) - IAudioClient_Release(renderer->audio_client); + audio_renderer_release_audio_client(renderer); DeleteCriticalSection(&renderer->cs); heap_free(renderer); } @@ -812,38 +822,94 @@ static ULONG WINAPI audio_renderer_stream_volume_Release(IMFAudioStreamVolume *i
static HRESULT WINAPI audio_renderer_stream_volume_GetChannelCount(IMFAudioStreamVolume *iface, UINT32 *count) { - FIXME("%p, %p.\n", iface, count); + struct audio_renderer *renderer = impl_from_IMFAudioStreamVolume(iface); + HRESULT hr = S_OK;
- return E_NOTIMPL; + TRACE("%p, %p.\n", iface, count); + + if (!count) + return E_POINTER; + + *count = 0; + + EnterCriticalSection(&renderer->cs); + if (renderer->stream_volume) + hr = IAudioStreamVolume_GetChannelCount(renderer->stream_volume, count); + LeaveCriticalSection(&renderer->cs); + + return hr; }
static HRESULT WINAPI audio_renderer_stream_volume_SetChannelVolume(IMFAudioStreamVolume *iface, UINT32 index, float level) { - FIXME("%p, %u, %f.\n", iface, index, level); + struct audio_renderer *renderer = impl_from_IMFAudioStreamVolume(iface); + HRESULT hr = S_OK;
- return E_NOTIMPL; + TRACE("%p, %u, %f.\n", iface, index, level); + + EnterCriticalSection(&renderer->cs); + if (renderer->stream_volume) + hr = IAudioStreamVolume_SetChannelVolume(renderer->stream_volume, index, level); + LeaveCriticalSection(&renderer->cs); + + return hr; }
static HRESULT WINAPI audio_renderer_stream_volume_GetChannelVolume(IMFAudioStreamVolume *iface, UINT32 index, float *level) { - FIXME("%p, %u, %p.\n", iface, index, level); + struct audio_renderer *renderer = impl_from_IMFAudioStreamVolume(iface); + HRESULT hr = S_OK;
- return E_NOTIMPL; + TRACE("%p, %u, %p.\n", iface, index, level); + + if (!level) + return E_POINTER; + + *level = 0.0f; + + EnterCriticalSection(&renderer->cs); + if (renderer->stream_volume) + hr = IAudioStreamVolume_GetChannelVolume(renderer->stream_volume, index, level); + LeaveCriticalSection(&renderer->cs); + + return hr; }
static HRESULT WINAPI audio_renderer_stream_volume_SetAllVolumes(IMFAudioStreamVolume *iface, UINT32 count, const float *volumes) { - FIXME("%p, %u, %p.\n", iface, count, volumes); + struct audio_renderer *renderer = impl_from_IMFAudioStreamVolume(iface); + HRESULT hr = S_OK;
- return E_NOTIMPL; + TRACE("%p, %u, %p.\n", iface, count, volumes); + + EnterCriticalSection(&renderer->cs); + if (renderer->stream_volume) + hr = IAudioStreamVolume_SetAllVolumes(renderer->stream_volume, count, volumes); + LeaveCriticalSection(&renderer->cs); + + return hr; }
static HRESULT WINAPI audio_renderer_stream_volume_GetAllVolumes(IMFAudioStreamVolume *iface, UINT32 count, float *volumes) { - FIXME("%p, %u, %p.\n", iface, count, volumes); + struct audio_renderer *renderer = impl_from_IMFAudioStreamVolume(iface); + HRESULT hr = S_OK;
- return E_NOTIMPL; + TRACE("%p, %u, %p.\n", iface, count, volumes); + + if (!volumes) + return E_POINTER; + + if (count) + memset(volumes, 0, sizeof(*volumes) * count); + + EnterCriticalSection(&renderer->cs); + if (renderer->stream_volume) + hr = IAudioStreamVolume_GetAllVolumes(renderer->stream_volume, count, volumes); + LeaveCriticalSection(&renderer->cs); + + return hr; }
static const IMFAudioStreamVolumeVtbl audio_renderer_stream_volume_vtbl = @@ -1229,11 +1295,7 @@ static HRESULT audio_renderer_create_audio_client(struct audio_renderer *rendere WAVEFORMATEX *wfx; HRESULT hr;
- if (renderer->audio_client) - { - IAudioClient_Release(renderer->audio_client); - renderer->audio_client = NULL; - } + audio_renderer_release_audio_client(renderer);
hr = IMMDevice_Activate(renderer->device, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void **)&renderer->audio_client); @@ -1261,6 +1323,13 @@ static HRESULT audio_renderer_create_audio_client(struct audio_renderer *rendere return hr; }
+ if (FAILED(hr = IAudioClient_GetService(renderer->audio_client, &IID_IAudioStreamVolume, + (void **)&renderer->stream_volume))) + { + WARN("Failed to get stream volume control, hr %#x.\n", hr); + return hr; + } + if (FAILED(hr = IAudioClient_SetEventHandle(renderer->audio_client, renderer->buffer_ready_event))) { WARN("Failed to set event handle, hr %#x.\n", hr);
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mf/sar.c | 68 ++++++++++++++++++++++++++++++++++++++++------ dlls/mf/tests/mf.c | 25 +++++++++++++++-- 2 files changed, 82 insertions(+), 11 deletions(-)
diff --git a/dlls/mf/sar.c b/dlls/mf/sar.c index 83d50b7f0b..86a0c2f36e 100644 --- a/dlls/mf/sar.c +++ b/dlls/mf/sar.c @@ -59,6 +59,7 @@ struct audio_renderer IMMDevice *device; IAudioClient *audio_client; IAudioStreamVolume *stream_volume; + ISimpleAudioVolume *audio_volume; HANDLE buffer_ready_event; enum stream_state state; BOOL is_shut_down; @@ -170,6 +171,9 @@ static void audio_renderer_release_audio_client(struct audio_renderer *renderer) if (renderer->stream_volume) IAudioStreamVolume_Release(renderer->stream_volume); renderer->stream_volume = NULL; + if (renderer->audio_volume) + ISimpleAudioVolume_Release(renderer->audio_volume); + renderer->audio_volume = NULL; }
static ULONG WINAPI audio_renderer_sink_Release(IMFMediaSink *iface) @@ -754,30 +758,72 @@ static ULONG WINAPI audio_renderer_simple_volume_Release(IMFSimpleAudioVolume *i
static HRESULT WINAPI audio_renderer_simple_volume_SetMasterVolume(IMFSimpleAudioVolume *iface, float level) { - FIXME("%p, %f.\n", iface, level); + struct audio_renderer *renderer = impl_from_IMFSimpleAudioVolume(iface); + HRESULT hr = S_OK;
- return E_NOTIMPL; + TRACE("%p, %f.\n", iface, level); + + EnterCriticalSection(&renderer->cs); + if (renderer->audio_volume) + hr = ISimpleAudioVolume_SetMasterVolume(renderer->audio_volume, level, NULL); + LeaveCriticalSection(&renderer->cs); + + return hr; }
static HRESULT WINAPI audio_renderer_simple_volume_GetMasterVolume(IMFSimpleAudioVolume *iface, float *level) { - FIXME("%p, %p.\n", iface, level); + struct audio_renderer *renderer = impl_from_IMFSimpleAudioVolume(iface); + HRESULT hr = S_OK;
- return E_NOTIMPL; + TRACE("%p, %p.\n", iface, level); + + if (!level) + return E_POINTER; + + *level = 0.0f; + + EnterCriticalSection(&renderer->cs); + if (renderer->audio_volume) + hr = ISimpleAudioVolume_GetMasterVolume(renderer->audio_volume, level); + LeaveCriticalSection(&renderer->cs); + + return hr; }
static HRESULT WINAPI audio_renderer_simple_volume_SetMute(IMFSimpleAudioVolume *iface, BOOL mute) { - FIXME("%p, %d.\n", iface, mute); + struct audio_renderer *renderer = impl_from_IMFSimpleAudioVolume(iface); + HRESULT hr = S_OK;
- return E_NOTIMPL; + TRACE("%p, %d.\n", iface, mute); + + EnterCriticalSection(&renderer->cs); + if (renderer->audio_volume) + hr = ISimpleAudioVolume_SetMute(renderer->audio_volume, mute, NULL); + LeaveCriticalSection(&renderer->cs); + + return hr; }
static HRESULT WINAPI audio_renderer_simple_volume_GetMute(IMFSimpleAudioVolume *iface, BOOL *mute) { - FIXME("%p, %p.\n", iface, mute); + struct audio_renderer *renderer = impl_from_IMFSimpleAudioVolume(iface); + HRESULT hr = S_OK;
- return E_NOTIMPL; + TRACE("%p, %p.\n", iface, mute); + + if (!mute) + return E_POINTER; + + *mute = FALSE; + + EnterCriticalSection(&renderer->cs); + if (renderer->audio_volume) + hr = ISimpleAudioVolume_GetMute(renderer->audio_volume, mute); + LeaveCriticalSection(&renderer->cs); + + return hr; }
static const IMFSimpleAudioVolumeVtbl audio_renderer_simple_volume_vtbl = @@ -1330,6 +1376,12 @@ static HRESULT audio_renderer_create_audio_client(struct audio_renderer *rendere return hr; }
+ if (FAILED(hr = IAudioClient_GetService(renderer->audio_client, &IID_ISimpleAudioVolume, (void **)&renderer->audio_volume))) + { + WARN("Failed to get audio volume control, hr %#x.\n", hr); + return hr; + } + if (FAILED(hr = IAudioClient_SetEventHandle(renderer->audio_client, renderer->buffer_ready_event))) { WARN("Failed to set event handle, hr %#x.\n", hr); diff --git a/dlls/mf/tests/mf.c b/dlls/mf/tests/mf.c index 675bc0a443..62e70954f0 100644 --- a/dlls/mf/tests/mf.c +++ b/dlls/mf/tests/mf.c @@ -2726,6 +2726,7 @@ static void test_sar(void) IMFMediaTypeHandler *handler, *handler2; IMFPresentationTimeSource *time_source; IMFSimpleAudioVolume *simple_volume; + IMFAudioStreamVolume *stream_volume; IMFClockStateSink *state_sink; IMFMediaSink *sink, *sink2; IMFStreamSink *stream_sink; @@ -2817,6 +2818,15 @@ if (SUCCEEDED(hr)) hr = IMFClockStateSink_OnClockStart(state_sink, 0, 0); ok(hr == MF_E_NOT_INITIALIZED, "Unexpected hr %#x.\n", hr);
+ hr = IMFClockStateSink_OnClockPause(state_sink, 0); + ok(hr == MF_E_INVALID_STATE_TRANSITION, "Unexpected hr %#x.\n", hr); + + hr = IMFClockStateSink_OnClockStop(state_sink, 0); + ok(hr == MF_E_NOT_INITIALIZED, "Unexpected hr %#x.\n", hr); + + hr = IMFClockStateSink_OnClockRestart(state_sink, 0); + ok(hr == MF_E_NOT_INITIALIZED, "Unexpected hr %#x.\n", hr); + IMFClockStateSink_Release(state_sink);
hr = IMFMediaSink_SetPresentationClock(sink, NULL); @@ -2979,6 +2989,9 @@ todo_wine hr = IMFClockStateSink_OnClockRestart(state_sink, 0); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
+ hr = IMFClockStateSink_OnClockStop(state_sink, 0); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + IMFClockStateSink_Release(state_sink);
IMFStreamSink_Release(stream_sink); @@ -2988,14 +3001,20 @@ todo_wine ok(hr == S_OK, "Failed to get interface, hr %#x.\n", hr);
hr = IMFSimpleAudioVolume_GetMute(simple_volume, &mute); -todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
IMFSimpleAudioVolume_Release(simple_volume);
- hr = MFGetService((IUnknown *)sink, &MR_STREAM_VOLUME_SERVICE, &IID_IMFAudioStreamVolume, (void **)&unk); + hr = MFGetService((IUnknown *)sink, &MR_STREAM_VOLUME_SERVICE, &IID_IMFAudioStreamVolume, (void **)&stream_volume); ok(hr == S_OK, "Failed to get interface, hr %#x.\n", hr); - IUnknown_Release(unk); + + hr = IMFAudioStreamVolume_GetChannelCount(stream_volume, &count); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IMFAudioStreamVolume_GetChannelCount(stream_volume, NULL); + ok(hr == E_POINTER, "Unexpected hr %#x.\n", hr); + + IMFAudioStreamVolume_Release(stream_volume);
hr = MFGetService((IUnknown *)sink, &MR_AUDIO_POLICY_SERVICE, &IID_IMFAudioPolicy, (void **)&unk); todo_wine
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mf/sar.c | 8 +++++++- dlls/mf/tests/mf.c | 1 - 2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/dlls/mf/sar.c b/dlls/mf/sar.c index 86a0c2f36e..bb3eba7eee 100644 --- a/dlls/mf/sar.c +++ b/dlls/mf/sar.c @@ -1569,7 +1569,13 @@ failed:
static void sar_shutdown_object(void *user_context, IUnknown *obj) { - /* FIXME: shut down sink */ + IMFMediaSink *sink; + + if (SUCCEEDED(IUnknown_QueryInterface(obj, &IID_IMFMediaSink, (void **)&sink))) + { + IMFMediaSink_Shutdown(sink); + IMFMediaSink_Release(sink); + } }
static void sar_free_private(void *user_context) diff --git a/dlls/mf/tests/mf.c b/dlls/mf/tests/mf.c index 62e70954f0..bf62f62f72 100644 --- a/dlls/mf/tests/mf.c +++ b/dlls/mf/tests/mf.c @@ -3079,7 +3079,6 @@ todo_wine ok(hr == S_OK, "Failed to shut down, hr %#x.\n", hr);
hr = IMFMediaSink_GetCharacteristics(sink, &flags); -todo_wine ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#x.\n", hr);
IMFMediaSink_Release(sink);
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mf/samplegrabber.c | 371 +++++++++++++++++----------------------- dlls/mf/tests/mf.c | 3 - 2 files changed, 156 insertions(+), 218 deletions(-)
diff --git a/dlls/mf/samplegrabber.c b/dlls/mf/samplegrabber.c index 062e8ea173..bd5859d4f4 100644 --- a/dlls/mf/samplegrabber.c +++ b/dlls/mf/samplegrabber.c @@ -58,37 +58,29 @@ struct scheduled_item } u; };
-struct sample_grabber_stream -{ - IMFStreamSink IMFStreamSink_iface; - IMFMediaTypeHandler IMFMediaTypeHandler_iface; - IMFAsyncCallback timer_callback; - LONG refcount; - struct sample_grabber *sink; - IMFMediaEventQueue *event_queue; - IMFAttributes *sample_attributes; - enum sink_state state; - struct list items; - IUnknown *cancel_key; - CRITICAL_SECTION cs; -}; - struct sample_grabber { IMFMediaSink IMFMediaSink_iface; IMFClockStateSink IMFClockStateSink_iface; IMFMediaEventGenerator IMFMediaEventGenerator_iface; + IMFStreamSink IMFStreamSink_iface; + IMFMediaTypeHandler IMFMediaTypeHandler_iface; + IMFAsyncCallback timer_callback; LONG refcount; IMFSampleGrabberSinkCallback *callback; IMFSampleGrabberSinkCallback2 *callback2; IMFMediaType *media_type; BOOL is_shut_down; - struct sample_grabber_stream *stream; IMFMediaEventQueue *event_queue; + IMFMediaEventQueue *stream_event_queue; IMFPresentationClock *clock; IMFTimer *timer; + IMFAttributes *sample_attributes; + struct list items; + IUnknown *cancel_key; UINT32 ignore_clock; UINT64 sample_time_offset; + enum sink_state state; CRITICAL_SECTION cs; };
@@ -127,35 +119,35 @@ static struct sample_grabber *impl_from_IMFMediaEventGenerator(IMFMediaEventGene return CONTAINING_RECORD(iface, struct sample_grabber, IMFMediaEventGenerator_iface); }
-static struct sample_grabber_stream *impl_from_IMFStreamSink(IMFStreamSink *iface) +static struct sample_grabber *impl_from_IMFStreamSink(IMFStreamSink *iface) { - return CONTAINING_RECORD(iface, struct sample_grabber_stream, IMFStreamSink_iface); + return CONTAINING_RECORD(iface, struct sample_grabber, IMFStreamSink_iface); }
-static struct sample_grabber_stream *impl_from_IMFMediaTypeHandler(IMFMediaTypeHandler *iface) +static struct sample_grabber *impl_from_IMFMediaTypeHandler(IMFMediaTypeHandler *iface) { - return CONTAINING_RECORD(iface, struct sample_grabber_stream, IMFMediaTypeHandler_iface); + return CONTAINING_RECORD(iface, struct sample_grabber, IMFMediaTypeHandler_iface); }
-static struct sample_grabber_stream *impl_from_IMFAsyncCallback(IMFAsyncCallback *iface) +static struct sample_grabber *impl_from_IMFAsyncCallback(IMFAsyncCallback *iface) { - return CONTAINING_RECORD(iface, struct sample_grabber_stream, timer_callback); + return CONTAINING_RECORD(iface, struct sample_grabber, timer_callback); }
static HRESULT WINAPI sample_grabber_stream_QueryInterface(IMFStreamSink *iface, REFIID riid, void **obj) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
if (IsEqualIID(riid, &IID_IMFStreamSink) || IsEqualIID(riid, &IID_IUnknown)) { - *obj = &stream->IMFStreamSink_iface; + *obj = &grabber->IMFStreamSink_iface; } else if (IsEqualIID(riid, &IID_IMFMediaTypeHandler)) { - *obj = &stream->IMFMediaTypeHandler_iface; + *obj = &grabber->IMFMediaTypeHandler_iface; } else { @@ -171,12 +163,8 @@ static HRESULT WINAPI sample_grabber_stream_QueryInterface(IMFStreamSink *iface,
static ULONG WINAPI sample_grabber_stream_AddRef(IMFStreamSink *iface) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); - ULONG refcount = InterlockedIncrement(&stream->refcount); - - TRACE("%p, refcount %u.\n", iface, refcount); - - return refcount; + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface); + return IMFMediaSink_AddRef(&grabber->IMFMediaSink_iface); }
static void stream_release_pending_item(struct scheduled_item *item) @@ -196,101 +184,71 @@ static void stream_release_pending_item(struct scheduled_item *item)
static ULONG WINAPI sample_grabber_stream_Release(IMFStreamSink *iface) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); - ULONG refcount = InterlockedDecrement(&stream->refcount); - struct scheduled_item *item, *next_item; - - TRACE("%p, refcount %u.\n", iface, refcount); - - if (!refcount) - { - if (stream->sink) - { - IMFMediaSink_Release(&stream->sink->IMFMediaSink_iface); - if (stream->sink->timer && stream->cancel_key) - IMFTimer_CancelTimer(stream->sink->timer, stream->cancel_key); - } - if (stream->cancel_key) - IUnknown_Release(stream->cancel_key); - if (stream->event_queue) - { - IMFMediaEventQueue_Shutdown(stream->event_queue); - IMFMediaEventQueue_Release(stream->event_queue); - } - if (stream->sample_attributes) - IMFAttributes_Release(stream->sample_attributes); - LIST_FOR_EACH_ENTRY_SAFE(item, next_item, &stream->items, struct scheduled_item, entry) - { - stream_release_pending_item(item); - } - DeleteCriticalSection(&stream->cs); - heap_free(stream); - } - - return refcount; + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface); + return IMFMediaSink_Release(&grabber->IMFMediaSink_iface); }
static HRESULT WINAPI sample_grabber_stream_GetEvent(IMFStreamSink *iface, DWORD flags, IMFMediaEvent **event) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
TRACE("%p, %#x, %p.\n", iface, flags, event);
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
- return IMFMediaEventQueue_GetEvent(stream->event_queue, flags, event); + return IMFMediaEventQueue_GetEvent(grabber->stream_event_queue, flags, event); }
static HRESULT WINAPI sample_grabber_stream_BeginGetEvent(IMFStreamSink *iface, IMFAsyncCallback *callback, IUnknown *state) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
TRACE("%p, %p, %p.\n", iface, callback, state);
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
- return IMFMediaEventQueue_BeginGetEvent(stream->event_queue, callback, state); + return IMFMediaEventQueue_BeginGetEvent(grabber->stream_event_queue, callback, state); }
static HRESULT WINAPI sample_grabber_stream_EndGetEvent(IMFStreamSink *iface, IMFAsyncResult *result, IMFMediaEvent **event) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
TRACE("%p, %p, %p.\n", iface, result, event);
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
- return IMFMediaEventQueue_EndGetEvent(stream->event_queue, result, event); + return IMFMediaEventQueue_EndGetEvent(grabber->stream_event_queue, result, event); }
static HRESULT WINAPI sample_grabber_stream_QueueEvent(IMFStreamSink *iface, MediaEventType event_type, REFGUID ext_type, HRESULT hr, const PROPVARIANT *value) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
TRACE("%p, %u, %s, %#x, %p.\n", iface, event_type, debugstr_guid(ext_type), hr, value);
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
- return IMFMediaEventQueue_QueueEventParamVar(stream->event_queue, event_type, ext_type, hr, value); + return IMFMediaEventQueue_QueueEventParamVar(grabber->stream_event_queue, event_type, ext_type, hr, value); }
static HRESULT WINAPI sample_grabber_stream_GetMediaSink(IMFStreamSink *iface, IMFMediaSink **sink) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
TRACE("%p, %p.\n", iface, sink);
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
- *sink = &stream->sink->IMFMediaSink_iface; + *sink = &grabber->IMFMediaSink_iface; IMFMediaSink_AddRef(*sink);
return S_OK; @@ -298,11 +256,11 @@ static HRESULT WINAPI sample_grabber_stream_GetMediaSink(IMFStreamSink *iface, I
static HRESULT WINAPI sample_grabber_stream_GetIdentifier(IMFStreamSink *iface, DWORD *identifier) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
TRACE("%p, %p.\n", iface, identifier);
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
*identifier = 0; @@ -312,17 +270,17 @@ static HRESULT WINAPI sample_grabber_stream_GetIdentifier(IMFStreamSink *iface,
static HRESULT WINAPI sample_grabber_stream_GetMediaTypeHandler(IMFStreamSink *iface, IMFMediaTypeHandler **handler) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
TRACE("%p, %p.\n", iface, handler);
if (!handler) return E_POINTER;
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
- *handler = &stream->IMFMediaTypeHandler_iface; + *handler = &grabber->IMFMediaTypeHandler_iface; IMFMediaTypeHandler_AddRef(*handler);
return S_OK; @@ -361,10 +319,10 @@ static HRESULT sample_grabber_report_sample(struct sample_grabber *grabber, IMFS
if (grabber->callback2) { - hr = IMFSample_CopyAllItems(sample, grabber->stream->sample_attributes); + hr = IMFSample_CopyAllItems(sample, grabber->sample_attributes); if (SUCCEEDED(hr)) hr = IMFSampleGrabberSinkCallback2_OnProcessSampleEx(grabber->callback2, &major_type, flags, - sample_time, sample_duration, data, size, grabber->stream->sample_attributes); + sample_time, sample_duration, data, size, grabber->sample_attributes); } else hr = IMFSampleGrabberSinkCallback_OnProcessSample(grabber->callback, &major_type, flags, sample_time, @@ -378,33 +336,33 @@ static HRESULT sample_grabber_report_sample(struct sample_grabber *grabber, IMFS return hr; }
-static HRESULT stream_schedule_sample(struct sample_grabber_stream *stream, struct scheduled_item *item) +static HRESULT stream_schedule_sample(struct sample_grabber *grabber, struct scheduled_item *item) { LONGLONG sampletime; HRESULT hr;
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
if (FAILED(hr = IMFSample_GetSampleTime(item->u.sample, &sampletime))) return hr;
- if (stream->cancel_key) + if (grabber->cancel_key) { - IUnknown_Release(stream->cancel_key); - stream->cancel_key = NULL; + IUnknown_Release(grabber->cancel_key); + grabber->cancel_key = NULL; }
- if (FAILED(hr = IMFTimer_SetTimer(stream->sink->timer, 0, sampletime - stream->sink->sample_time_offset, - &stream->timer_callback, NULL, &stream->cancel_key))) + if (FAILED(hr = IMFTimer_SetTimer(grabber->timer, 0, sampletime - grabber->sample_time_offset, + &grabber->timer_callback, NULL, &grabber->cancel_key))) { - stream->cancel_key = NULL; + grabber->cancel_key = NULL; }
return hr; }
-static HRESULT stream_queue_sample(struct sample_grabber_stream *stream, IMFSample *sample) +static HRESULT stream_queue_sample(struct sample_grabber *grabber, IMFSample *sample) { struct scheduled_item *item; LONGLONG sampletime; @@ -420,25 +378,25 @@ static HRESULT stream_queue_sample(struct sample_grabber_stream *stream, IMFSamp item->u.sample = sample; IMFSample_AddRef(item->u.sample); list_init(&item->entry); - if (list_empty(&stream->items)) - hr = stream_schedule_sample(stream, item); + if (list_empty(&grabber->items)) + hr = stream_schedule_sample(grabber, item);
if (SUCCEEDED(hr)) - list_add_tail(&stream->items, &item->entry); + list_add_tail(&grabber->items, &item->entry); else stream_release_pending_item(item);
return hr; }
-static void sample_grabber_stream_request_sample(struct sample_grabber_stream *stream) +static void sample_grabber_stream_request_sample(struct sample_grabber *grabber) { - IMFStreamSink_QueueEvent(&stream->IMFStreamSink_iface, MEStreamSinkRequestSample, &GUID_NULL, S_OK, NULL); + IMFStreamSink_QueueEvent(&grabber->IMFStreamSink_iface, MEStreamSinkRequestSample, &GUID_NULL, S_OK, NULL); }
static HRESULT WINAPI sample_grabber_stream_ProcessSample(IMFStreamSink *iface, IMFSample *sample) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface); BOOL sample_delivered; LONGLONG sampletime; HRESULT hr = S_OK; @@ -448,50 +406,50 @@ static HRESULT WINAPI sample_grabber_stream_ProcessSample(IMFStreamSink *iface, if (!sample) return S_OK;
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
- EnterCriticalSection(&stream->cs); + EnterCriticalSection(&grabber->cs);
- if (stream->state == SINK_STATE_RUNNING) + if (grabber->state == SINK_STATE_RUNNING) { hr = IMFSample_GetSampleTime(sample, &sampletime);
if (SUCCEEDED(hr)) { - if (stream->sink->ignore_clock) + if (grabber->ignore_clock) { /* OnProcessSample() could return error code, which has to be propagated but isn't a blocker. Use additional flag indicating that user callback was called at all. */ - hr = sample_grabber_report_sample(stream->sink, sample, &sample_delivered); + hr = sample_grabber_report_sample(grabber, sample, &sample_delivered); if (sample_delivered) - sample_grabber_stream_request_sample(stream); + sample_grabber_stream_request_sample(grabber); } else - hr = stream_queue_sample(stream, sample); + hr = stream_queue_sample(grabber, sample); } }
- LeaveCriticalSection(&stream->cs); + LeaveCriticalSection(&grabber->cs);
return hr; }
-static void sample_grabber_stream_report_marker(struct sample_grabber_stream *stream, const PROPVARIANT *context, +static void sample_grabber_stream_report_marker(struct sample_grabber *grabber, const PROPVARIANT *context, HRESULT hr) { - IMFStreamSink_QueueEvent(&stream->IMFStreamSink_iface, MEStreamSinkMarker, &GUID_NULL, hr, context); + IMFStreamSink_QueueEvent(&grabber->IMFStreamSink_iface, MEStreamSinkMarker, &GUID_NULL, hr, context); }
-static HRESULT stream_place_marker(struct sample_grabber_stream *stream, MFSTREAMSINK_MARKER_TYPE marker_type, +static HRESULT stream_place_marker(struct sample_grabber *grabber, MFSTREAMSINK_MARKER_TYPE marker_type, const PROPVARIANT *context_value) { struct scheduled_item *item; HRESULT hr;
- if (list_empty(&stream->items)) + if (list_empty(&grabber->items)) { - sample_grabber_stream_report_marker(stream, context_value, S_OK); + sample_grabber_stream_report_marker(grabber, context_value, S_OK); return S_OK; }
@@ -503,7 +461,7 @@ static HRESULT stream_place_marker(struct sample_grabber_stream *stream, MFSTREA list_init(&item->entry); hr = PropVariantCopy(&item->u.marker.context, context_value); if (SUCCEEDED(hr)) - list_add_tail(&stream->items, &item->entry); + list_add_tail(&grabber->items, &item->entry); else stream_release_pending_item(item);
@@ -513,37 +471,37 @@ static HRESULT stream_place_marker(struct sample_grabber_stream *stream, MFSTREA static HRESULT WINAPI sample_grabber_stream_PlaceMarker(IMFStreamSink *iface, MFSTREAMSINK_MARKER_TYPE marker_type, const PROPVARIANT *marker_value, const PROPVARIANT *context_value) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface); HRESULT hr = S_OK;
TRACE("%p, %d, %p, %p.\n", iface, marker_type, marker_value, context_value);
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
- EnterCriticalSection(&stream->cs); + EnterCriticalSection(&grabber->cs);
- if (stream->state == SINK_STATE_RUNNING) - hr = stream_place_marker(stream, marker_type, context_value); + if (grabber->state == SINK_STATE_RUNNING) + hr = stream_place_marker(grabber, marker_type, context_value);
- LeaveCriticalSection(&stream->cs); + LeaveCriticalSection(&grabber->cs);
return hr; }
static HRESULT WINAPI sample_grabber_stream_Flush(IMFStreamSink *iface) { - struct sample_grabber_stream *stream = impl_from_IMFStreamSink(iface); + struct sample_grabber *grabber = impl_from_IMFStreamSink(iface); struct scheduled_item *item, *next_item;
TRACE("%p.\n", iface);
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
- EnterCriticalSection(&stream->cs); + EnterCriticalSection(&grabber->cs);
- LIST_FOR_EACH_ENTRY_SAFE(item, next_item, &stream->items, struct scheduled_item, entry) + LIST_FOR_EACH_ENTRY_SAFE(item, next_item, &grabber->items, struct scheduled_item, entry) { /* Samples are discarded, markers are processed immediately. */ switch (item->type) @@ -551,14 +509,14 @@ static HRESULT WINAPI sample_grabber_stream_Flush(IMFStreamSink *iface) case ITEM_TYPE_SAMPLE: break; case ITEM_TYPE_MARKER: - sample_grabber_stream_report_marker(stream, &item->u.marker.context, E_ABORT); + sample_grabber_stream_report_marker(grabber, &item->u.marker.context, E_ABORT); break; }
stream_release_pending_item(item); }
- LeaveCriticalSection(&stream->cs); + LeaveCriticalSection(&grabber->cs);
return S_OK; } @@ -583,34 +541,34 @@ static const IMFStreamSinkVtbl sample_grabber_stream_vtbl = static HRESULT WINAPI sample_grabber_stream_type_handler_QueryInterface(IMFMediaTypeHandler *iface, REFIID riid, void **obj) { - struct sample_grabber_stream *stream = impl_from_IMFMediaTypeHandler(iface); - return IMFStreamSink_QueryInterface(&stream->IMFStreamSink_iface, riid, obj); + struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface); + return IMFStreamSink_QueryInterface(&grabber->IMFStreamSink_iface, riid, obj); }
static ULONG WINAPI sample_grabber_stream_type_handler_AddRef(IMFMediaTypeHandler *iface) { - struct sample_grabber_stream *stream = impl_from_IMFMediaTypeHandler(iface); - return IMFStreamSink_AddRef(&stream->IMFStreamSink_iface); + struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface); + return IMFStreamSink_AddRef(&grabber->IMFStreamSink_iface); }
static ULONG WINAPI sample_grabber_stream_type_handler_Release(IMFMediaTypeHandler *iface) { - struct sample_grabber_stream *stream = impl_from_IMFMediaTypeHandler(iface); - return IMFStreamSink_Release(&stream->IMFStreamSink_iface); + struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface); + return IMFStreamSink_Release(&grabber->IMFStreamSink_iface); }
-static HRESULT sample_grabber_stream_is_media_type_supported(struct sample_grabber_stream *stream, IMFMediaType *in_type) +static HRESULT sample_grabber_stream_is_media_type_supported(struct sample_grabber *grabber, IMFMediaType *in_type) { const DWORD supported_flags = MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES; DWORD flags;
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
if (!in_type) return E_POINTER;
- if (IMFMediaType_IsEqual(stream->sink->media_type, in_type, &flags) == S_OK) + if (IMFMediaType_IsEqual(grabber->media_type, in_type, &flags) == S_OK) return S_OK;
return (flags & supported_flags) == supported_flags ? S_OK : MF_E_INVALIDMEDIATYPE; @@ -619,11 +577,11 @@ static HRESULT sample_grabber_stream_is_media_type_supported(struct sample_grabb static HRESULT WINAPI sample_grabber_stream_type_handler_IsMediaTypeSupported(IMFMediaTypeHandler *iface, IMFMediaType *in_type, IMFMediaType **out_type) { - struct sample_grabber_stream *stream = impl_from_IMFMediaTypeHandler(iface); + struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface);
TRACE("%p, %p, %p.\n", iface, in_type, out_type);
- return sample_grabber_stream_is_media_type_supported(stream, in_type); + return sample_grabber_stream_is_media_type_supported(grabber, in_type); }
static HRESULT WINAPI sample_grabber_stream_type_handler_GetMediaTypeCount(IMFMediaTypeHandler *iface, DWORD *count) @@ -652,17 +610,17 @@ static HRESULT WINAPI sample_grabber_stream_type_handler_GetMediaTypeByIndex(IMF static HRESULT WINAPI sample_grabber_stream_type_handler_SetCurrentMediaType(IMFMediaTypeHandler *iface, IMFMediaType *media_type) { - struct sample_grabber_stream *stream = impl_from_IMFMediaTypeHandler(iface); + struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface); HRESULT hr;
TRACE("%p, %p.\n", iface, media_type);
- if (FAILED(hr = sample_grabber_stream_is_media_type_supported(stream, media_type))) + if (FAILED(hr = sample_grabber_stream_is_media_type_supported(grabber, media_type))) return hr;
- IMFMediaType_Release(stream->sink->media_type); - stream->sink->media_type = media_type; - IMFMediaType_AddRef(stream->sink->media_type); + IMFMediaType_Release(grabber->media_type); + grabber->media_type = media_type; + IMFMediaType_AddRef(grabber->media_type);
return S_OK; } @@ -670,17 +628,17 @@ static HRESULT WINAPI sample_grabber_stream_type_handler_SetCurrentMediaType(IMF static HRESULT WINAPI sample_grabber_stream_type_handler_GetCurrentMediaType(IMFMediaTypeHandler *iface, IMFMediaType **media_type) { - struct sample_grabber_stream *stream = impl_from_IMFMediaTypeHandler(iface); + struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface);
TRACE("%p, %p.\n", iface, media_type);
if (!media_type) return E_POINTER;
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
- *media_type = stream->sink->media_type; + *media_type = grabber->media_type; IMFMediaType_AddRef(*media_type);
return S_OK; @@ -688,17 +646,17 @@ static HRESULT WINAPI sample_grabber_stream_type_handler_GetCurrentMediaType(IMF
static HRESULT WINAPI sample_grabber_stream_type_handler_GetMajorType(IMFMediaTypeHandler *iface, GUID *type) { - struct sample_grabber_stream *stream = impl_from_IMFMediaTypeHandler(iface); + struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface);
TRACE("%p, %p.\n", iface, type);
if (!type) return E_POINTER;
- if (!stream->sink) + if (grabber->is_shut_down) return MF_E_STREAMSINK_REMOVED;
- return IMFMediaType_GetMajorType(stream->sink->media_type, type); + return IMFMediaType_GetMajorType(grabber->media_type, type); }
static const IMFMediaTypeHandlerVtbl sample_grabber_stream_type_handler_vtbl = @@ -731,14 +689,14 @@ static HRESULT WINAPI sample_grabber_stream_timer_callback_QueryInterface(IMFAsy
static ULONG WINAPI sample_grabber_stream_timer_callback_AddRef(IMFAsyncCallback *iface) { - struct sample_grabber_stream *stream = impl_from_IMFAsyncCallback(iface); - return IMFStreamSink_AddRef(&stream->IMFStreamSink_iface); + struct sample_grabber *grabber = impl_from_IMFAsyncCallback(iface); + return IMFStreamSink_AddRef(&grabber->IMFStreamSink_iface); }
static ULONG WINAPI sample_grabber_stream_timer_callback_Release(IMFAsyncCallback *iface) { - struct sample_grabber_stream *stream = impl_from_IMFAsyncCallback(iface); - return IMFStreamSink_Release(&stream->IMFStreamSink_iface); + struct sample_grabber *grabber = impl_from_IMFAsyncCallback(iface); + return IMFStreamSink_Release(&grabber->IMFStreamSink_iface); }
static HRESULT WINAPI sample_grabber_stream_timer_callback_GetParameters(IMFAsyncCallback *iface, DWORD *flags, @@ -747,12 +705,12 @@ static HRESULT WINAPI sample_grabber_stream_timer_callback_GetParameters(IMFAsyn return E_NOTIMPL; }
-static struct scheduled_item *stream_get_next_item(struct sample_grabber_stream *stream) +static struct scheduled_item *stream_get_next_item(struct sample_grabber *grabber) { struct scheduled_item *item = NULL; struct list *e;
- if ((e = list_head(&stream->items))) + if ((e = list_head(&grabber->items))) item = LIST_ENTRY(e, struct scheduled_item, entry);
return item; @@ -760,43 +718,43 @@ static struct scheduled_item *stream_get_next_item(struct sample_grabber_stream
static HRESULT WINAPI sample_grabber_stream_timer_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result) { - struct sample_grabber_stream *stream = impl_from_IMFAsyncCallback(iface); + struct sample_grabber *grabber = impl_from_IMFAsyncCallback(iface); struct scheduled_item *item; BOOL sample_delivered; HRESULT hr;
- EnterCriticalSection(&stream->cs); + EnterCriticalSection(&grabber->cs);
/* Report and schedule next. */ - if (stream->sink && (item = stream_get_next_item(stream))) + if (!grabber->is_shut_down && (item = stream_get_next_item(grabber))) { while (item) { switch (item->type) { case ITEM_TYPE_SAMPLE: - if (FAILED(hr = sample_grabber_report_sample(stream->sink, item->u.sample, &sample_delivered))) + if (FAILED(hr = sample_grabber_report_sample(grabber, item->u.sample, &sample_delivered))) WARN("Failed to report a sample, hr %#x.\n", hr); stream_release_pending_item(item); - item = stream_get_next_item(stream); + item = stream_get_next_item(grabber); if (item && item->type == ITEM_TYPE_SAMPLE) { - if (FAILED(hr = stream_schedule_sample(stream, item))) + if (FAILED(hr = stream_schedule_sample(grabber, item))) WARN("Failed to schedule a sample, hr %#x.\n", hr); - sample_grabber_stream_request_sample(stream); + sample_grabber_stream_request_sample(grabber); item = NULL; } break; case ITEM_TYPE_MARKER: - sample_grabber_stream_report_marker(stream, &item->u.marker.context, S_OK); + sample_grabber_stream_report_marker(grabber, &item->u.marker.context, S_OK); stream_release_pending_item(item); - item = stream_get_next_item(stream); + item = stream_get_next_item(grabber); break; } } }
- LeaveCriticalSection(&stream->cs); + LeaveCriticalSection(&grabber->cs);
return S_OK; } @@ -855,6 +813,7 @@ static ULONG WINAPI sample_grabber_sink_Release(IMFMediaSink *iface) { struct sample_grabber *grabber = impl_from_IMFMediaSink(iface); ULONG refcount = InterlockedDecrement(&grabber->refcount); + struct scheduled_item *item, *next_item;
TRACE("%p, refcount %u.\n", iface, refcount);
@@ -870,7 +829,24 @@ static ULONG WINAPI sample_grabber_sink_Release(IMFMediaSink *iface) if (grabber->clock) IMFPresentationClock_Release(grabber->clock); if (grabber->timer) + { + if (grabber->cancel_key) + IMFTimer_CancelTimer(grabber->timer, grabber->cancel_key); IMFTimer_Release(grabber->timer); + } + if (grabber->cancel_key) + IUnknown_Release(grabber->cancel_key); + if (grabber->stream_event_queue) + { + IMFMediaEventQueue_Shutdown(grabber->stream_event_queue); + IMFMediaEventQueue_Release(grabber->stream_event_queue); + } + if (grabber->sample_attributes) + IMFAttributes_Release(grabber->sample_attributes); + LIST_FOR_EACH_ENTRY_SAFE(item, next_item, &grabber->items, struct scheduled_item, entry) + { + stream_release_pending_item(item); + } DeleteCriticalSection(&grabber->cs); heap_free(grabber); } @@ -946,7 +922,7 @@ static HRESULT WINAPI sample_grabber_sink_GetStreamSinkByIndex(IMFMediaSink *ifa hr = MF_E_INVALIDINDEX; else { - *stream = &grabber->stream->IMFStreamSink_iface; + *stream = &grabber->IMFStreamSink_iface; IMFStreamSink_AddRef(*stream); }
@@ -971,7 +947,7 @@ static HRESULT WINAPI sample_grabber_sink_GetStreamSinkById(IMFMediaSink *iface, hr = MF_E_INVALIDSTREAMNUMBER; else { - *stream = &grabber->stream->IMFStreamSink_iface; + *stream = &grabber->IMFStreamSink_iface; IMFStreamSink_AddRef(*stream); }
@@ -1059,15 +1035,7 @@ static HRESULT WINAPI sample_grabber_sink_Shutdown(IMFMediaSink *iface) grabber->is_shut_down = TRUE; if (SUCCEEDED(hr = IMFSampleGrabberSinkCallback_OnShutdown(sample_grabber_get_callback(grabber)))) { - /* Detach stream. */ - IMFMediaSink_Release(&grabber->stream->sink->IMFMediaSink_iface); - EnterCriticalSection(&grabber->stream->cs); - grabber->stream->sink = NULL; - IMFMediaEventQueue_Shutdown(grabber->stream->event_queue); - LeaveCriticalSection(&grabber->stream->cs); - IMFStreamSink_Release(&grabber->stream->IMFStreamSink_iface); - grabber->stream = NULL; - + IMFMediaEventQueue_Shutdown(grabber->stream_event_queue); IMFMediaEventQueue_Shutdown(grabber->event_queue); } LeaveCriticalSection(&grabber->cs); @@ -1121,9 +1089,9 @@ static void sample_grabber_set_state(struct sample_grabber *grabber, enum sink_s
EnterCriticalSection(&grabber->cs);
- if (grabber->stream) + if (!grabber->is_shut_down) { - switch (grabber->stream->state) + switch (grabber->state) { case SINK_STATE_STOPPED: set_state = state == SINK_STATE_RUNNING; @@ -1137,14 +1105,14 @@ static void sample_grabber_set_state(struct sample_grabber *grabber, enum sink_s
if (set_state) { - grabber->stream->state = state; + grabber->state = state; if (state == SINK_STATE_RUNNING) { /* Every transition to running state sends a bunch requests to build up initial queue. */ for (i = 0; i < 4; ++i) - sample_grabber_stream_request_sample(grabber->stream); + sample_grabber_stream_request_sample(grabber); } - IMFStreamSink_QueueEvent(&grabber->stream->IMFStreamSink_iface, events[state], &GUID_NULL, S_OK, NULL); + IMFStreamSink_QueueEvent(&grabber->IMFStreamSink_iface, events[state], &GUID_NULL, S_OK, NULL); } }
@@ -1282,40 +1250,6 @@ static const IMFClockStateSinkVtbl sample_grabber_clock_sink_vtbl = sample_grabber_clock_sink_OnClockSetRate, };
-static HRESULT sample_grabber_create_stream(struct sample_grabber *sink, struct sample_grabber_stream **stream) -{ - struct sample_grabber_stream *object; - HRESULT hr; - - object = heap_alloc_zero(sizeof(*object)); - if (!object) - return E_OUTOFMEMORY; - - object->IMFStreamSink_iface.lpVtbl = &sample_grabber_stream_vtbl; - object->IMFMediaTypeHandler_iface.lpVtbl = &sample_grabber_stream_type_handler_vtbl; - object->timer_callback.lpVtbl = &sample_grabber_stream_timer_callback_vtbl; - object->refcount = 1; - object->sink = sink; - IMFMediaSink_AddRef(&object->sink->IMFMediaSink_iface); - list_init(&object->items); - InitializeCriticalSection(&object->cs); - - if (FAILED(hr = MFCreateEventQueue(&object->event_queue))) - goto failed; - - if (FAILED(hr = MFCreateAttributes(&object->sample_attributes, 0))) - goto failed; - - *stream = object; - - return S_OK; - -failed: - IMFStreamSink_Release(&object->IMFStreamSink_iface); - - return hr; -} - static HRESULT sample_grabber_create_object(IMFAttributes *attributes, void *user_context, IUnknown **obj) { struct sample_grabber_activate_context *context = user_context; @@ -1339,6 +1273,9 @@ static HRESULT sample_grabber_create_object(IMFAttributes *attributes, void *use object->IMFMediaSink_iface.lpVtbl = &sample_grabber_sink_vtbl; object->IMFClockStateSink_iface.lpVtbl = &sample_grabber_clock_sink_vtbl; object->IMFMediaEventGenerator_iface.lpVtbl = &sample_grabber_sink_events_vtbl; + object->IMFStreamSink_iface.lpVtbl = &sample_grabber_stream_vtbl; + object->IMFMediaTypeHandler_iface.lpVtbl = &sample_grabber_stream_type_handler_vtbl; + object->timer_callback.lpVtbl = &sample_grabber_stream_timer_callback_vtbl; object->refcount = 1; if (FAILED(IMFSampleGrabberSinkCallback_QueryInterface(context->callback, &IID_IMFSampleGrabberSinkCallback2, (void **)&object->callback2))) @@ -1350,9 +1287,13 @@ static HRESULT sample_grabber_create_object(IMFAttributes *attributes, void *use IMFMediaType_AddRef(object->media_type); IMFAttributes_GetUINT32(attributes, &MF_SAMPLEGRABBERSINK_IGNORE_CLOCK, &object->ignore_clock); IMFAttributes_GetUINT64(attributes, &MF_SAMPLEGRABBERSINK_SAMPLE_TIME_OFFSET, &object->sample_time_offset); + list_init(&object->items); InitializeCriticalSection(&object->cs);
- if (FAILED(hr = sample_grabber_create_stream(object, &object->stream))) + if (FAILED(hr = MFCreateEventQueue(&object->stream_event_queue))) + goto failed; + + if (FAILED(hr = MFCreateAttributes(&object->sample_attributes, 0))) goto failed;
if (FAILED(hr = MFCreateEventQueue(&object->event_queue))) diff --git a/dlls/mf/tests/mf.c b/dlls/mf/tests/mf.c index bf62f62f72..9e6b45e2f6 100644 --- a/dlls/mf/tests/mf.c +++ b/dlls/mf/tests/mf.c @@ -2025,11 +2025,8 @@ static void test_sample_grabber(void) ok(hr == S_OK, "Failed to get stream count, hr %#x.\n", hr); ok(count == 1, "Unexpected stream count %u.\n", count);
- EXPECT_REF(sink, 3); hr = IMFMediaSink_GetStreamSinkByIndex(sink, 0, &stream); ok(hr == S_OK, "Failed to get sink stream, hr %#x.\n", hr); - EXPECT_REF(sink, 3); - EXPECT_REF(stream, 2);
hr = IMFStreamSink_GetIdentifier(stream, &id); ok(hr == S_OK, "Failed to get stream id, hr %#x.\n", hr);
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mf/samplegrabber.c | 48 +++++++++++++++++++++++------------------ dlls/mf/tests/mf.c | 5 +++-- 2 files changed, 30 insertions(+), 23 deletions(-)
diff --git a/dlls/mf/samplegrabber.c b/dlls/mf/samplegrabber.c index bd5859d4f4..1919ce6220 100644 --- a/dlls/mf/samplegrabber.c +++ b/dlls/mf/samplegrabber.c @@ -956,6 +956,31 @@ static HRESULT WINAPI sample_grabber_sink_GetStreamSinkById(IMFMediaSink *iface, return hr; }
+static void sample_grabber_set_presentation_clock(struct sample_grabber *grabber, IMFPresentationClock *clock) +{ + if (grabber->clock) + { + IMFPresentationClock_RemoveClockStateSink(grabber->clock, &grabber->IMFClockStateSink_iface); + IMFPresentationClock_Release(grabber->clock); + if (grabber->timer) + { + IMFTimer_Release(grabber->timer); + grabber->timer = NULL; + } + } + grabber->clock = clock; + if (grabber->clock) + { + IMFPresentationClock_AddRef(grabber->clock); + IMFPresentationClock_AddClockStateSink(grabber->clock, &grabber->IMFClockStateSink_iface); + if (FAILED(IMFPresentationClock_QueryInterface(grabber->clock, &IID_IMFTimer, (void **)&grabber->timer))) + { + WARN("Failed to get IMFTimer interface.\n"); + grabber->timer = NULL; + } + } +} + static HRESULT WINAPI sample_grabber_sink_SetPresentationClock(IMFMediaSink *iface, IMFPresentationClock *clock) { struct sample_grabber *grabber = impl_from_IMFMediaSink(iface); @@ -968,27 +993,7 @@ static HRESULT WINAPI sample_grabber_sink_SetPresentationClock(IMFMediaSink *ifa if (SUCCEEDED(hr = IMFSampleGrabberSinkCallback_OnSetPresentationClock(sample_grabber_get_callback(grabber), clock))) { - if (grabber->clock) - { - IMFPresentationClock_RemoveClockStateSink(grabber->clock, &grabber->IMFClockStateSink_iface); - IMFPresentationClock_Release(grabber->clock); - if (grabber->timer) - { - IMFTimer_Release(grabber->timer); - grabber->timer = NULL; - } - } - grabber->clock = clock; - if (grabber->clock) - { - IMFPresentationClock_AddRef(grabber->clock); - IMFPresentationClock_AddClockStateSink(grabber->clock, &grabber->IMFClockStateSink_iface); - if (FAILED(IMFPresentationClock_QueryInterface(grabber->clock, &IID_IMFTimer, (void **)&grabber->timer))) - { - WARN("Failed to get IMFTimer interface.\n"); - grabber->timer = NULL; - } - } + sample_grabber_set_presentation_clock(grabber, clock); }
LeaveCriticalSection(&grabber->cs); @@ -1035,6 +1040,7 @@ static HRESULT WINAPI sample_grabber_sink_Shutdown(IMFMediaSink *iface) grabber->is_shut_down = TRUE; 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); } diff --git a/dlls/mf/tests/mf.c b/dlls/mf/tests/mf.c index 9e6b45e2f6..ae9f58a4bc 100644 --- a/dlls/mf/tests/mf.c +++ b/dlls/mf/tests/mf.c @@ -2102,8 +2102,6 @@ static void test_sample_grabber(void) ok(hr == S_OK, "Failed to set time source, hr %#x.\n", hr); IMFPresentationTimeSource_Release(time_source);
- IMFPresentationClock_Release(clock); - hr = IMFMediaSink_GetCharacteristics(sink, &flags); ok(hr == S_OK, "Failed to get sink flags, hr %#x.\n", hr);
@@ -2221,8 +2219,10 @@ static void test_sample_grabber(void) hr = IMFStreamSink_GetEvent(stream, MF_EVENT_FLAG_NO_WAIT, &event); ok(hr == MF_E_NO_EVENTS_AVAILABLE, "Unexpected hr %#x.\n", hr);
+ EXPECT_REF(clock, 3); hr = IMFMediaSink_Shutdown(sink); ok(hr == S_OK, "Failed to shut down, hr %#x.\n", hr); + EXPECT_REF(clock, 1);
hr = IMFMediaEventGenerator_GetEvent(eg, MF_EVENT_FLAG_NO_WAIT, &event); ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#x.\n", hr); @@ -2355,6 +2355,7 @@ static void test_sample_grabber(void) IMFActivate_Release(activate);
IMFMediaType_Release(media_type); + IMFPresentationClock_Release(clock);
hr = MFShutdown(); ok(hr == S_OK, "Failed to shut down, hr %#x.\n", hr);