mf: Merge sample grabber sink and stream instances.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
693bdc63d4
commit
a0035b848e
|
@ -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)))
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue