2019-05-06 12:52:13 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Nikolay Sivov for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
2020-11-19 13:21:40 +01:00
|
|
|
#include <float.h>
|
|
|
|
|
2019-05-06 12:52:13 +02:00
|
|
|
#include "mfidl.h"
|
|
|
|
#include "mf_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2019-06-06 15:18:35 +02:00
|
|
|
#include "wine/list.h"
|
2019-05-06 12:52:13 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
|
|
|
|
|
2019-05-30 13:46:13 +02:00
|
|
|
enum sink_state
|
|
|
|
{
|
|
|
|
SINK_STATE_STOPPED = 0,
|
2021-06-03 14:43:14 +02:00
|
|
|
SINK_STATE_PAUSED,
|
2019-05-30 13:46:13 +02:00
|
|
|
SINK_STATE_RUNNING,
|
|
|
|
};
|
|
|
|
|
2019-05-27 16:07:37 +02:00
|
|
|
struct sample_grabber;
|
|
|
|
|
2019-06-07 15:08:59 +02:00
|
|
|
enum scheduled_item_type
|
|
|
|
{
|
|
|
|
ITEM_TYPE_SAMPLE,
|
|
|
|
ITEM_TYPE_MARKER,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct scheduled_item
|
2019-06-06 15:18:35 +02:00
|
|
|
{
|
|
|
|
struct list entry;
|
2019-06-07 15:08:59 +02:00
|
|
|
enum scheduled_item_type type;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
IMFSample *sample;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
MFSTREAMSINK_MARKER_TYPE type;
|
|
|
|
PROPVARIANT context;
|
|
|
|
} marker;
|
|
|
|
} u;
|
2019-06-06 15:18:35 +02:00
|
|
|
};
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
struct sample_grabber
|
|
|
|
{
|
|
|
|
IMFMediaSink IMFMediaSink_iface;
|
2019-05-20 14:22:30 +02:00
|
|
|
IMFClockStateSink IMFClockStateSink_iface;
|
2019-05-20 14:22:32 +02:00
|
|
|
IMFMediaEventGenerator IMFMediaEventGenerator_iface;
|
2020-11-19 13:21:40 +01:00
|
|
|
IMFGetService IMFGetService_iface;
|
|
|
|
IMFRateSupport IMFRateSupport_iface;
|
2020-04-22 15:32:13 +02:00
|
|
|
IMFStreamSink IMFStreamSink_iface;
|
|
|
|
IMFMediaTypeHandler IMFMediaTypeHandler_iface;
|
|
|
|
IMFAsyncCallback timer_callback;
|
2019-05-20 14:22:28 +02:00
|
|
|
LONG refcount;
|
|
|
|
IMFSampleGrabberSinkCallback *callback;
|
2019-06-11 14:40:04 +02:00
|
|
|
IMFSampleGrabberSinkCallback2 *callback2;
|
2019-05-20 14:22:28 +02:00
|
|
|
IMFMediaType *media_type;
|
2020-11-26 10:42:31 +01:00
|
|
|
IMFMediaType *current_media_type;
|
2019-05-20 14:22:28 +02:00
|
|
|
BOOL is_shut_down;
|
2019-05-20 14:22:32 +02:00
|
|
|
IMFMediaEventQueue *event_queue;
|
2020-04-22 15:32:13 +02:00
|
|
|
IMFMediaEventQueue *stream_event_queue;
|
2019-05-28 14:08:28 +02:00
|
|
|
IMFPresentationClock *clock;
|
2019-06-06 15:18:35 +02:00
|
|
|
IMFTimer *timer;
|
2020-04-22 15:32:13 +02:00
|
|
|
IMFAttributes *sample_attributes;
|
|
|
|
struct list items;
|
|
|
|
IUnknown *cancel_key;
|
2019-05-30 13:46:15 +02:00
|
|
|
UINT32 ignore_clock;
|
2019-06-06 15:18:35 +02:00
|
|
|
UINT64 sample_time_offset;
|
2020-04-22 15:32:13 +02:00
|
|
|
enum sink_state state;
|
2019-05-20 14:22:28 +02:00
|
|
|
CRITICAL_SECTION cs;
|
|
|
|
};
|
|
|
|
|
2019-06-11 14:40:04 +02:00
|
|
|
static IMFSampleGrabberSinkCallback *sample_grabber_get_callback(const struct sample_grabber *sink)
|
|
|
|
{
|
|
|
|
return sink->callback2 ? (IMFSampleGrabberSinkCallback *)sink->callback2 : sink->callback;
|
|
|
|
}
|
|
|
|
|
2019-05-06 12:52:13 +02:00
|
|
|
struct sample_grabber_activate_context
|
|
|
|
{
|
|
|
|
IMFMediaType *media_type;
|
|
|
|
IMFSampleGrabberSinkCallback *callback;
|
2020-03-11 12:19:41 +01:00
|
|
|
BOOL shut_down;
|
2019-05-06 12:52:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void sample_grabber_free_private(void *user_context)
|
|
|
|
{
|
|
|
|
struct sample_grabber_activate_context *context = user_context;
|
|
|
|
IMFMediaType_Release(context->media_type);
|
|
|
|
IMFSampleGrabberSinkCallback_Release(context->callback);
|
2021-06-17 12:33:51 +02:00
|
|
|
free(context);
|
2019-05-06 12:52:13 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
static struct sample_grabber *impl_from_IMFMediaSink(IMFMediaSink *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, IMFMediaSink_iface);
|
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:30 +02:00
|
|
|
static struct sample_grabber *impl_from_IMFClockStateSink(IMFClockStateSink *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, IMFClockStateSink_iface);
|
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:32 +02:00
|
|
|
static struct sample_grabber *impl_from_IMFMediaEventGenerator(IMFMediaEventGenerator *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, IMFMediaEventGenerator_iface);
|
|
|
|
}
|
|
|
|
|
2020-11-19 13:21:40 +01:00
|
|
|
static struct sample_grabber *impl_from_IMFGetService(IMFGetService *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, IMFGetService_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sample_grabber *impl_from_IMFRateSupport(IMFRateSupport *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, IMFRateSupport_iface);
|
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
static struct sample_grabber *impl_from_IMFStreamSink(IMFStreamSink *iface)
|
2019-05-20 14:22:28 +02:00
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, IMFStreamSink_iface);
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
static struct sample_grabber *impl_from_IMFMediaTypeHandler(IMFMediaTypeHandler *iface)
|
2019-05-20 14:22:29 +02:00
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, IMFMediaTypeHandler_iface);
|
2019-05-20 14:22:29 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
static struct sample_grabber *impl_from_IMFAsyncCallback(IMFAsyncCallback *iface)
|
2019-06-06 15:18:35 +02:00
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, timer_callback);
|
2019-06-06 15:18:35 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_stream_QueryInterface(IMFStreamSink *iface, REFIID riid, void **obj)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
2019-05-20 14:22:28 +02:00
|
|
|
|
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IMFStreamSink) ||
|
2020-04-23 14:03:18 +02:00
|
|
|
IsEqualIID(riid, &IID_IMFMediaEventGenerator) ||
|
2019-05-20 14:22:28 +02:00
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
*obj = &grabber->IMFStreamSink_iface;
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
2019-05-20 14:22:29 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFMediaTypeHandler))
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
*obj = &grabber->IMFMediaTypeHandler_iface;
|
2019-05-20 14:22:29 +02:00
|
|
|
}
|
2019-05-20 14:22:28 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Unsupported %s.\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*obj);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_stream_AddRef(IMFStreamSink *iface)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
|
|
|
return IMFMediaSink_AddRef(&grabber->IMFMediaSink_iface);
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
2019-06-07 15:09:00 +02:00
|
|
|
static void stream_release_pending_item(struct scheduled_item *item)
|
2019-06-06 15:18:35 +02:00
|
|
|
{
|
2019-06-07 15:08:59 +02:00
|
|
|
list_remove(&item->entry);
|
|
|
|
switch (item->type)
|
|
|
|
{
|
|
|
|
case ITEM_TYPE_SAMPLE:
|
|
|
|
IMFSample_Release(item->u.sample);
|
|
|
|
break;
|
|
|
|
case ITEM_TYPE_MARKER:
|
|
|
|
PropVariantClear(&item->u.marker.context);
|
|
|
|
break;
|
|
|
|
}
|
2021-06-17 12:33:51 +02:00
|
|
|
free(item);
|
2019-06-06 15:18:35 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
static ULONG WINAPI sample_grabber_stream_Release(IMFStreamSink *iface)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
|
|
|
return IMFMediaSink_Release(&grabber->IMFMediaSink_iface);
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_GetEvent(IMFStreamSink *iface, DWORD flags, IMFMediaEvent **event)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
2019-05-20 14:22:28 +02:00
|
|
|
|
2019-05-20 14:22:31 +02:00
|
|
|
TRACE("%p, %#x, %p.\n", iface, flags, event);
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2020-03-11 12:19:40 +01:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
return IMFMediaEventQueue_GetEvent(grabber->stream_event_queue, flags, event);
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_BeginGetEvent(IMFStreamSink *iface, IMFAsyncCallback *callback,
|
|
|
|
IUnknown *state)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
2019-05-20 14:22:28 +02:00
|
|
|
|
2019-05-20 14:22:31 +02:00
|
|
|
TRACE("%p, %p, %p.\n", iface, callback, state);
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2020-03-11 12:19:40 +01:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
return IMFMediaEventQueue_BeginGetEvent(grabber->stream_event_queue, callback, state);
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_EndGetEvent(IMFStreamSink *iface, IMFAsyncResult *result,
|
|
|
|
IMFMediaEvent **event)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
2019-05-20 14:22:28 +02:00
|
|
|
|
2019-05-20 14:22:31 +02:00
|
|
|
TRACE("%p, %p, %p.\n", iface, result, event);
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2020-03-11 12:19:40 +01:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
return IMFMediaEventQueue_EndGetEvent(grabber->stream_event_queue, result, event);
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_QueueEvent(IMFStreamSink *iface, MediaEventType event_type,
|
|
|
|
REFGUID ext_type, HRESULT hr, const PROPVARIANT *value)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
2019-05-20 14:22:28 +02:00
|
|
|
|
2019-05-20 14:22:31 +02:00
|
|
|
TRACE("%p, %u, %s, %#x, %p.\n", iface, event_type, debugstr_guid(ext_type), hr, value);
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2020-03-11 12:19:40 +01:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
return IMFMediaEventQueue_QueueEventParamVar(grabber->stream_event_queue, event_type, ext_type, hr, value);
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_GetMediaSink(IMFStreamSink *iface, IMFMediaSink **sink)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
2019-05-20 14:22:28 +02:00
|
|
|
|
|
|
|
TRACE("%p, %p.\n", iface, sink);
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2019-05-28 14:08:29 +02:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
*sink = &grabber->IMFMediaSink_iface;
|
2019-05-20 14:22:28 +02:00
|
|
|
IMFMediaSink_AddRef(*sink);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_GetIdentifier(IMFStreamSink *iface, DWORD *identifier)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
2019-05-28 14:08:29 +02:00
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
TRACE("%p, %p.\n", iface, identifier);
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2019-05-28 14:08:29 +02:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
*identifier = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_GetMediaTypeHandler(IMFStreamSink *iface, IMFMediaTypeHandler **handler)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
2019-05-20 14:22:28 +02:00
|
|
|
|
2019-05-20 14:22:29 +02:00
|
|
|
TRACE("%p, %p.\n", iface, handler);
|
|
|
|
|
2019-05-28 14:08:29 +02:00
|
|
|
if (!handler)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2019-05-28 14:08:29 +02:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
*handler = &grabber->IMFMediaTypeHandler_iface;
|
2019-05-20 14:22:29 +02:00
|
|
|
IMFMediaTypeHandler_AddRef(*handler);
|
|
|
|
|
|
|
|
return S_OK;
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
2020-02-21 11:16:52 +01:00
|
|
|
static HRESULT sample_grabber_report_sample(struct sample_grabber *grabber, IMFSample *sample, BOOL *sample_delivered)
|
2019-05-30 13:46:15 +02:00
|
|
|
{
|
|
|
|
LONGLONG sample_time, sample_duration = 0;
|
|
|
|
IMFMediaBuffer *buffer;
|
|
|
|
DWORD flags, size;
|
|
|
|
GUID major_type;
|
|
|
|
BYTE *data;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2020-02-21 11:16:52 +01:00
|
|
|
*sample_delivered = FALSE;
|
|
|
|
|
2019-05-30 13:46:15 +02:00
|
|
|
hr = IMFMediaType_GetMajorType(grabber->media_type, &major_type);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMFSample_GetSampleTime(sample, &sample_time);
|
|
|
|
|
|
|
|
if (FAILED(IMFSample_GetSampleDuration(sample, &sample_duration)))
|
|
|
|
sample_duration = 0;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMFSample_GetSampleFlags(sample, &flags);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (FAILED(IMFSample_ConvertToContiguousBuffer(sample, &buffer)))
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = IMFMediaBuffer_Lock(buffer, &data, NULL, &size)))
|
|
|
|
{
|
2020-02-21 11:16:52 +01:00
|
|
|
*sample_delivered = TRUE;
|
|
|
|
|
2019-06-11 14:40:04 +02:00
|
|
|
if (grabber->callback2)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
hr = IMFSample_CopyAllItems(sample, grabber->sample_attributes);
|
2019-06-11 14:40:04 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMFSampleGrabberSinkCallback2_OnProcessSampleEx(grabber->callback2, &major_type, flags,
|
2020-04-22 15:32:13 +02:00
|
|
|
sample_time, sample_duration, data, size, grabber->sample_attributes);
|
2019-06-11 14:40:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = IMFSampleGrabberSinkCallback_OnProcessSample(grabber->callback, &major_type, flags, sample_time,
|
|
|
|
sample_duration, data, size);
|
2019-05-30 13:46:15 +02:00
|
|
|
IMFMediaBuffer_Unlock(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMFMediaBuffer_Release(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
static HRESULT stream_schedule_sample(struct sample_grabber *grabber, struct scheduled_item *item)
|
2019-06-06 15:18:35 +02:00
|
|
|
{
|
|
|
|
LONGLONG sampletime;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2019-06-06 15:18:35 +02:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2019-06-07 15:08:59 +02:00
|
|
|
if (FAILED(hr = IMFSample_GetSampleTime(item->u.sample, &sampletime)))
|
2019-06-06 15:18:35 +02:00
|
|
|
return hr;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->cancel_key)
|
2019-06-06 15:18:35 +02:00
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
IUnknown_Release(grabber->cancel_key);
|
|
|
|
grabber->cancel_key = NULL;
|
2019-06-06 15:18:35 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (FAILED(hr = IMFTimer_SetTimer(grabber->timer, 0, sampletime - grabber->sample_time_offset,
|
|
|
|
&grabber->timer_callback, NULL, &grabber->cancel_key)))
|
2019-06-06 15:18:35 +02:00
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
grabber->cancel_key = NULL;
|
2019-06-06 15:18:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
static HRESULT stream_queue_sample(struct sample_grabber *grabber, IMFSample *sample)
|
2019-06-06 15:18:35 +02:00
|
|
|
{
|
2019-06-07 15:08:59 +02:00
|
|
|
struct scheduled_item *item;
|
2019-06-06 15:18:35 +02:00
|
|
|
LONGLONG sampletime;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (FAILED(hr = IMFSample_GetSampleTime(sample, &sampletime)))
|
|
|
|
return hr;
|
|
|
|
|
2021-06-17 12:33:51 +02:00
|
|
|
if (!(item = calloc(1, sizeof(*item))))
|
2019-06-06 15:18:35 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2019-06-07 15:08:59 +02:00
|
|
|
item->type = ITEM_TYPE_SAMPLE;
|
|
|
|
item->u.sample = sample;
|
|
|
|
IMFSample_AddRef(item->u.sample);
|
|
|
|
list_init(&item->entry);
|
2020-04-22 15:32:13 +02:00
|
|
|
if (list_empty(&grabber->items))
|
|
|
|
hr = stream_schedule_sample(grabber, item);
|
2019-06-06 15:18:35 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2020-04-22 15:32:13 +02:00
|
|
|
list_add_tail(&grabber->items, &item->entry);
|
2019-06-06 15:18:35 +02:00
|
|
|
else
|
2019-06-07 15:09:00 +02:00
|
|
|
stream_release_pending_item(item);
|
2019-06-06 15:18:35 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
static void sample_grabber_stream_request_sample(struct sample_grabber *grabber)
|
2020-02-21 11:16:52 +01:00
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
IMFStreamSink_QueueEvent(&grabber->IMFStreamSink_iface, MEStreamSinkRequestSample, &GUID_NULL, S_OK, NULL);
|
2020-02-21 11:16:52 +01:00
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_stream_ProcessSample(IMFStreamSink *iface, IMFSample *sample)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
2020-02-21 11:16:52 +01:00
|
|
|
BOOL sample_delivered;
|
2019-05-30 13:46:15 +02:00
|
|
|
LONGLONG sampletime;
|
|
|
|
HRESULT hr = S_OK;
|
2019-05-20 14:22:28 +02:00
|
|
|
|
2019-05-30 13:46:15 +02:00
|
|
|
TRACE("%p, %p.\n", iface, sample);
|
|
|
|
|
|
|
|
if (!sample)
|
|
|
|
return S_OK;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
EnterCriticalSection(&grabber->cs);
|
2019-05-30 13:46:15 +02:00
|
|
|
|
2020-05-15 17:32:55 +02:00
|
|
|
if (grabber->is_shut_down)
|
|
|
|
hr = MF_E_STREAMSINK_REMOVED;
|
|
|
|
else if (grabber->state == SINK_STATE_RUNNING)
|
2019-05-30 13:46:15 +02:00
|
|
|
{
|
|
|
|
hr = IMFSample_GetSampleTime(sample, &sampletime);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->ignore_clock)
|
2020-02-21 11:16:52 +01:00
|
|
|
{
|
|
|
|
/* 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. */
|
2020-04-22 15:32:13 +02:00
|
|
|
hr = sample_grabber_report_sample(grabber, sample, &sample_delivered);
|
2020-02-21 11:16:52 +01:00
|
|
|
if (sample_delivered)
|
2020-04-22 15:32:13 +02:00
|
|
|
sample_grabber_stream_request_sample(grabber);
|
2020-02-21 11:16:52 +01:00
|
|
|
}
|
2019-05-30 13:46:15 +02:00
|
|
|
else
|
2020-04-22 15:32:13 +02:00
|
|
|
hr = stream_queue_sample(grabber, sample);
|
2019-05-30 13:46:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
LeaveCriticalSection(&grabber->cs);
|
2019-05-30 13:46:15 +02:00
|
|
|
|
|
|
|
return hr;
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
static void sample_grabber_stream_report_marker(struct sample_grabber *grabber, const PROPVARIANT *context,
|
2019-06-07 15:08:59 +02:00
|
|
|
HRESULT hr)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
IMFStreamSink_QueueEvent(&grabber->IMFStreamSink_iface, MEStreamSinkMarker, &GUID_NULL, hr, context);
|
2019-06-07 15:08:59 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
static HRESULT stream_place_marker(struct sample_grabber *grabber, MFSTREAMSINK_MARKER_TYPE marker_type,
|
2019-06-07 15:08:59 +02:00
|
|
|
const PROPVARIANT *context_value)
|
|
|
|
{
|
|
|
|
struct scheduled_item *item;
|
2020-04-24 16:47:03 +02:00
|
|
|
HRESULT hr = S_OK;
|
2019-06-07 15:08:59 +02:00
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (list_empty(&grabber->items))
|
2019-06-07 15:08:59 +02:00
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
sample_grabber_stream_report_marker(grabber, context_value, S_OK);
|
2019-06-07 15:08:59 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-06-17 12:33:51 +02:00
|
|
|
if (!(item = calloc(1, sizeof(*item))))
|
2019-06-07 15:08:59 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
item->type = ITEM_TYPE_MARKER;
|
|
|
|
item->u.marker.type = marker_type;
|
|
|
|
list_init(&item->entry);
|
2020-04-24 16:47:03 +02:00
|
|
|
PropVariantInit(&item->u.marker.context);
|
|
|
|
if (context_value)
|
|
|
|
hr = PropVariantCopy(&item->u.marker.context, context_value);
|
2019-06-07 15:08:59 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2020-04-22 15:32:13 +02:00
|
|
|
list_add_tail(&grabber->items, &item->entry);
|
2019-06-07 15:08:59 +02:00
|
|
|
else
|
2019-06-07 15:09:00 +02:00
|
|
|
stream_release_pending_item(item);
|
2019-06-07 15:08:59 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_stream_PlaceMarker(IMFStreamSink *iface, MFSTREAMSINK_MARKER_TYPE marker_type,
|
|
|
|
const PROPVARIANT *marker_value, const PROPVARIANT *context_value)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
2019-06-07 15:08:59 +02:00
|
|
|
HRESULT hr = S_OK;
|
2019-05-20 14:22:28 +02:00
|
|
|
|
2019-06-07 15:08:59 +02:00
|
|
|
TRACE("%p, %d, %p, %p.\n", iface, marker_type, marker_value, context_value);
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
EnterCriticalSection(&grabber->cs);
|
2019-06-07 15:08:59 +02:00
|
|
|
|
2020-05-15 17:32:55 +02:00
|
|
|
if (grabber->is_shut_down)
|
|
|
|
hr = MF_E_STREAMSINK_REMOVED;
|
|
|
|
else if (grabber->state == SINK_STATE_RUNNING)
|
2020-04-22 15:32:13 +02:00
|
|
|
hr = stream_place_marker(grabber, marker_type, context_value);
|
2019-06-07 15:08:59 +02:00
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
LeaveCriticalSection(&grabber->cs);
|
2019-06-07 15:08:59 +02:00
|
|
|
|
|
|
|
return hr;
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_Flush(IMFStreamSink *iface)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFStreamSink(iface);
|
2019-06-07 15:09:00 +02:00
|
|
|
struct scheduled_item *item, *next_item;
|
2019-05-20 14:22:28 +02:00
|
|
|
|
2019-06-07 15:09:00 +02:00
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2019-06-07 15:09:00 +02:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
EnterCriticalSection(&grabber->cs);
|
2019-06-07 15:09:00 +02:00
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(item, next_item, &grabber->items, struct scheduled_item, entry)
|
2019-06-07 15:09:00 +02:00
|
|
|
{
|
|
|
|
/* Samples are discarded, markers are processed immediately. */
|
|
|
|
switch (item->type)
|
|
|
|
{
|
|
|
|
case ITEM_TYPE_SAMPLE:
|
|
|
|
break;
|
|
|
|
case ITEM_TYPE_MARKER:
|
2020-04-22 15:32:13 +02:00
|
|
|
sample_grabber_stream_report_marker(grabber, &item->u.marker.context, E_ABORT);
|
2019-06-07 15:09:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream_release_pending_item(item);
|
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
LeaveCriticalSection(&grabber->cs);
|
2019-06-07 15:09:00 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFStreamSinkVtbl sample_grabber_stream_vtbl =
|
|
|
|
{
|
|
|
|
sample_grabber_stream_QueryInterface,
|
|
|
|
sample_grabber_stream_AddRef,
|
|
|
|
sample_grabber_stream_Release,
|
|
|
|
sample_grabber_stream_GetEvent,
|
|
|
|
sample_grabber_stream_BeginGetEvent,
|
|
|
|
sample_grabber_stream_EndGetEvent,
|
|
|
|
sample_grabber_stream_QueueEvent,
|
|
|
|
sample_grabber_stream_GetMediaSink,
|
|
|
|
sample_grabber_stream_GetIdentifier,
|
|
|
|
sample_grabber_stream_GetMediaTypeHandler,
|
|
|
|
sample_grabber_stream_ProcessSample,
|
|
|
|
sample_grabber_stream_PlaceMarker,
|
|
|
|
sample_grabber_stream_Flush,
|
|
|
|
};
|
|
|
|
|
2019-05-20 14:22:29 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_stream_type_handler_QueryInterface(IMFMediaTypeHandler *iface, REFIID riid,
|
|
|
|
void **obj)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface);
|
|
|
|
return IMFStreamSink_QueryInterface(&grabber->IMFStreamSink_iface, riid, obj);
|
2019-05-20 14:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_stream_type_handler_AddRef(IMFMediaTypeHandler *iface)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface);
|
|
|
|
return IMFStreamSink_AddRef(&grabber->IMFStreamSink_iface);
|
2019-05-20 14:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_stream_type_handler_Release(IMFMediaTypeHandler *iface)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface);
|
|
|
|
return IMFStreamSink_Release(&grabber->IMFStreamSink_iface);
|
2019-05-20 14:22:29 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
static HRESULT sample_grabber_stream_is_media_type_supported(struct sample_grabber *grabber, IMFMediaType *in_type)
|
2019-05-20 14:22:29 +02:00
|
|
|
{
|
2020-11-26 10:42:31 +01:00
|
|
|
const DWORD supported_flags = MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES |
|
|
|
|
MF_MEDIATYPE_EQUAL_FORMAT_DATA;
|
2019-05-27 16:07:37 +02:00
|
|
|
DWORD flags;
|
2019-05-20 14:22:29 +02:00
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2019-05-28 14:08:29 +02:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2019-05-27 16:07:37 +02:00
|
|
|
if (!in_type)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (IMFMediaType_IsEqual(grabber->media_type, in_type, &flags) == S_OK)
|
2019-05-27 16:07:37 +02:00
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
return (flags & supported_flags) == supported_flags ? S_OK : MF_E_INVALIDMEDIATYPE;
|
2019-05-20 14:22:29 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 13:51:57 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_stream_type_handler_IsMediaTypeSupported(IMFMediaTypeHandler *iface,
|
|
|
|
IMFMediaType *in_type, IMFMediaType **out_type)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface);
|
2020-04-16 13:51:57 +02:00
|
|
|
|
|
|
|
TRACE("%p, %p, %p.\n", iface, in_type, out_type);
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
return sample_grabber_stream_is_media_type_supported(grabber, in_type);
|
2020-04-16 13:51:57 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:29 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_stream_type_handler_GetMediaTypeCount(IMFMediaTypeHandler *iface, DWORD *count)
|
|
|
|
{
|
2019-05-27 16:07:37 +02:00
|
|
|
TRACE("%p, %p.\n", iface, count);
|
2019-05-20 14:22:29 +02:00
|
|
|
|
2019-05-27 16:07:37 +02:00
|
|
|
if (!count)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*count = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
2019-05-20 14:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_type_handler_GetMediaTypeByIndex(IMFMediaTypeHandler *iface, DWORD index,
|
2019-05-27 16:07:37 +02:00
|
|
|
IMFMediaType **media_type)
|
2019-05-20 14:22:29 +02:00
|
|
|
{
|
2019-05-27 16:07:37 +02:00
|
|
|
TRACE("%p, %u, %p.\n", iface, index, media_type);
|
2019-05-20 14:22:29 +02:00
|
|
|
|
2019-05-27 16:07:37 +02:00
|
|
|
if (!media_type)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
return MF_E_NO_MORE_TYPES;
|
2019-05-20 14:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_type_handler_SetCurrentMediaType(IMFMediaTypeHandler *iface,
|
2019-05-27 16:07:37 +02:00
|
|
|
IMFMediaType *media_type)
|
2019-05-20 14:22:29 +02:00
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface);
|
2020-04-16 13:51:57 +02:00
|
|
|
HRESULT hr;
|
2019-05-20 14:22:29 +02:00
|
|
|
|
2019-05-27 16:07:37 +02:00
|
|
|
TRACE("%p, %p.\n", iface, media_type);
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (FAILED(hr = sample_grabber_stream_is_media_type_supported(grabber, media_type)))
|
2020-04-16 13:51:57 +02:00
|
|
|
return hr;
|
2019-05-28 14:08:29 +02:00
|
|
|
|
2020-11-26 10:42:31 +01:00
|
|
|
IMFMediaType_Release(grabber->current_media_type);
|
|
|
|
grabber->current_media_type = media_type;
|
|
|
|
IMFMediaType_AddRef(grabber->current_media_type);
|
2019-05-27 16:07:37 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2019-05-20 14:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_type_handler_GetCurrentMediaType(IMFMediaTypeHandler *iface,
|
2019-05-28 14:08:29 +02:00
|
|
|
IMFMediaType **media_type)
|
2019-05-20 14:22:29 +02:00
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface);
|
2019-05-20 14:22:29 +02:00
|
|
|
|
2019-05-28 14:08:29 +02:00
|
|
|
TRACE("%p, %p.\n", iface, media_type);
|
2019-05-27 16:07:37 +02:00
|
|
|
|
2019-05-28 14:08:29 +02:00
|
|
|
if (!media_type)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2019-05-28 14:08:29 +02:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2020-11-26 10:42:31 +01:00
|
|
|
*media_type = grabber->current_media_type;
|
2019-05-28 14:08:29 +02:00
|
|
|
IMFMediaType_AddRef(*media_type);
|
2019-05-27 16:07:37 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2019-05-20 14:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_type_handler_GetMajorType(IMFMediaTypeHandler *iface, GUID *type)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaTypeHandler(iface);
|
2019-05-20 14:22:29 +02:00
|
|
|
|
2019-05-27 16:07:37 +02:00
|
|
|
TRACE("%p, %p.\n", iface, type);
|
|
|
|
|
2019-05-28 14:08:29 +02:00
|
|
|
if (!type)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (grabber->is_shut_down)
|
2019-05-28 14:08:29 +02:00
|
|
|
return MF_E_STREAMSINK_REMOVED;
|
|
|
|
|
2020-11-26 10:42:31 +01:00
|
|
|
return IMFMediaType_GetMajorType(grabber->current_media_type, type);
|
2019-05-20 14:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFMediaTypeHandlerVtbl sample_grabber_stream_type_handler_vtbl =
|
|
|
|
{
|
|
|
|
sample_grabber_stream_type_handler_QueryInterface,
|
|
|
|
sample_grabber_stream_type_handler_AddRef,
|
|
|
|
sample_grabber_stream_type_handler_Release,
|
|
|
|
sample_grabber_stream_type_handler_IsMediaTypeSupported,
|
|
|
|
sample_grabber_stream_type_handler_GetMediaTypeCount,
|
|
|
|
sample_grabber_stream_type_handler_GetMediaTypeByIndex,
|
|
|
|
sample_grabber_stream_type_handler_SetCurrentMediaType,
|
|
|
|
sample_grabber_stream_type_handler_GetCurrentMediaType,
|
|
|
|
sample_grabber_stream_type_handler_GetMajorType,
|
|
|
|
};
|
|
|
|
|
2019-06-06 15:18:35 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_stream_timer_callback_QueryInterface(IMFAsyncCallback *iface, REFIID riid,
|
|
|
|
void **obj)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, &IID_IMFAsyncCallback) || IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IMFAsyncCallback_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unsupported %s.\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_stream_timer_callback_AddRef(IMFAsyncCallback *iface)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFAsyncCallback(iface);
|
|
|
|
return IMFStreamSink_AddRef(&grabber->IMFStreamSink_iface);
|
2019-06-06 15:18:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_stream_timer_callback_Release(IMFAsyncCallback *iface)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFAsyncCallback(iface);
|
|
|
|
return IMFStreamSink_Release(&grabber->IMFStreamSink_iface);
|
2019-06-06 15:18:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_timer_callback_GetParameters(IMFAsyncCallback *iface, DWORD *flags,
|
|
|
|
DWORD *queue)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_stream_timer_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFAsyncCallback(iface);
|
2020-05-15 17:32:52 +02:00
|
|
|
BOOL sample_reported = FALSE, sample_delivered = FALSE;
|
|
|
|
struct scheduled_item *item, *item2;
|
2019-06-06 15:18:35 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
EnterCriticalSection(&grabber->cs);
|
2019-06-06 15:18:35 +02:00
|
|
|
|
2020-05-15 17:32:54 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(item, item2, &grabber->items, struct scheduled_item, entry)
|
2019-06-06 15:18:35 +02:00
|
|
|
{
|
2020-05-15 17:32:54 +02:00
|
|
|
if (item->type == ITEM_TYPE_MARKER)
|
2019-06-06 15:18:35 +02:00
|
|
|
{
|
2020-05-15 17:32:54 +02:00
|
|
|
sample_grabber_stream_report_marker(grabber, &item->u.marker.context, S_OK);
|
|
|
|
stream_release_pending_item(item);
|
|
|
|
}
|
|
|
|
else if (item->type == ITEM_TYPE_SAMPLE)
|
|
|
|
{
|
|
|
|
if (!sample_reported)
|
2020-05-15 17:32:52 +02:00
|
|
|
{
|
2020-05-15 17:32:54 +02:00
|
|
|
if (FAILED(hr = sample_grabber_report_sample(grabber, item->u.sample, &sample_delivered)))
|
|
|
|
WARN("Failed to report a sample, hr %#x.\n", hr);
|
2020-05-15 17:32:52 +02:00
|
|
|
stream_release_pending_item(item);
|
2020-05-15 17:32:54 +02:00
|
|
|
sample_reported = TRUE;
|
2020-05-15 17:32:52 +02:00
|
|
|
}
|
2020-05-15 17:32:54 +02:00
|
|
|
else
|
2019-06-07 15:08:59 +02:00
|
|
|
{
|
2020-05-15 17:32:54 +02:00
|
|
|
if (FAILED(hr = stream_schedule_sample(grabber, item)))
|
|
|
|
WARN("Failed to schedule a sample, hr %#x.\n", hr);
|
|
|
|
break;
|
2019-06-07 15:08:59 +02:00
|
|
|
}
|
2019-06-06 15:18:35 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-15 17:32:54 +02:00
|
|
|
if (sample_delivered)
|
|
|
|
sample_grabber_stream_request_sample(grabber);
|
2019-06-06 15:18:35 +02:00
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
LeaveCriticalSection(&grabber->cs);
|
2019-06-06 15:18:35 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFAsyncCallbackVtbl sample_grabber_stream_timer_callback_vtbl =
|
|
|
|
{
|
|
|
|
sample_grabber_stream_timer_callback_QueryInterface,
|
|
|
|
sample_grabber_stream_timer_callback_AddRef,
|
|
|
|
sample_grabber_stream_timer_callback_Release,
|
|
|
|
sample_grabber_stream_timer_callback_GetParameters,
|
|
|
|
sample_grabber_stream_timer_callback_Invoke,
|
|
|
|
};
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_sink_QueryInterface(IMFMediaSink *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IMFMediaSink) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = &grabber->IMFMediaSink_iface;
|
|
|
|
}
|
2019-05-20 14:22:30 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFClockStateSink))
|
|
|
|
{
|
|
|
|
*obj = &grabber->IMFClockStateSink_iface;
|
|
|
|
}
|
2019-05-20 14:22:32 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFMediaEventGenerator))
|
|
|
|
{
|
|
|
|
*obj = &grabber->IMFMediaEventGenerator_iface;
|
|
|
|
}
|
2020-11-19 13:21:40 +01:00
|
|
|
else if (IsEqualIID(riid, &IID_IMFGetService))
|
|
|
|
{
|
|
|
|
*obj = &grabber->IMFGetService_iface;
|
|
|
|
}
|
|
|
|
else if (IsEqualIID(riid, &IID_IMFRateSupport))
|
|
|
|
{
|
|
|
|
*obj = &grabber->IMFRateSupport_iface;
|
|
|
|
}
|
2019-05-20 14:22:28 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Unsupported %s.\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*obj);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_sink_AddRef(IMFMediaSink *iface)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&grabber->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2020-05-15 17:32:53 +02:00
|
|
|
static void sample_grabber_release_pending_items(struct sample_grabber *grabber)
|
|
|
|
{
|
|
|
|
struct scheduled_item *item, *next_item;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(item, next_item, &grabber->items, struct scheduled_item, entry)
|
|
|
|
{
|
|
|
|
stream_release_pending_item(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
static ULONG WINAPI sample_grabber_sink_Release(IMFMediaSink *iface)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&grabber->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2019-06-11 14:40:04 +02:00
|
|
|
if (grabber->callback)
|
|
|
|
IMFSampleGrabberSinkCallback_Release(grabber->callback);
|
|
|
|
if (grabber->callback2)
|
|
|
|
IMFSampleGrabberSinkCallback2_Release(grabber->callback2);
|
2020-11-26 10:42:31 +01:00
|
|
|
IMFMediaType_Release(grabber->current_media_type);
|
2019-05-20 14:22:28 +02:00
|
|
|
IMFMediaType_Release(grabber->media_type);
|
2019-05-20 14:22:32 +02:00
|
|
|
if (grabber->event_queue)
|
|
|
|
IMFMediaEventQueue_Release(grabber->event_queue);
|
2019-05-28 14:08:28 +02:00
|
|
|
if (grabber->clock)
|
|
|
|
IMFPresentationClock_Release(grabber->clock);
|
2019-06-06 15:18:35 +02:00
|
|
|
if (grabber->timer)
|
2020-04-22 15:32:13 +02:00
|
|
|
{
|
|
|
|
if (grabber->cancel_key)
|
|
|
|
IMFTimer_CancelTimer(grabber->timer, grabber->cancel_key);
|
2019-06-06 15:18:35 +02:00
|
|
|
IMFTimer_Release(grabber->timer);
|
2020-04-22 15:32:13 +02:00
|
|
|
}
|
|
|
|
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);
|
2020-05-15 17:32:53 +02:00
|
|
|
sample_grabber_release_pending_items(grabber);
|
2019-05-20 14:22:28 +02:00
|
|
|
DeleteCriticalSection(&grabber->cs);
|
2021-06-17 12:33:51 +02:00
|
|
|
free(grabber);
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_sink_GetCharacteristics(IMFMediaSink *iface, DWORD *flags)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p.\n", iface, flags);
|
|
|
|
|
|
|
|
if (grabber->is_shut_down)
|
|
|
|
return MF_E_SHUTDOWN;
|
|
|
|
|
|
|
|
*flags = MEDIASINK_FIXED_STREAMS;
|
2019-10-08 14:58:56 +02:00
|
|
|
if (grabber->ignore_clock)
|
|
|
|
*flags |= MEDIASINK_RATELESS;
|
2019-05-20 14:22:28 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_sink_AddStreamSink(IMFMediaSink *iface, DWORD stream_sink_id,
|
|
|
|
IMFMediaType *media_type, IMFStreamSink **stream_sink)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %#x, %p, %p.\n", iface, stream_sink_id, media_type, stream_sink);
|
|
|
|
|
|
|
|
return grabber->is_shut_down ? MF_E_SHUTDOWN : MF_E_STREAMSINKS_FIXED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_sink_RemoveStreamSink(IMFMediaSink *iface, DWORD stream_sink_id)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %#x.\n", iface, stream_sink_id);
|
|
|
|
|
|
|
|
return grabber->is_shut_down ? MF_E_SHUTDOWN : MF_E_STREAMSINKS_FIXED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_sink_GetStreamSinkCount(IMFMediaSink *iface, DWORD *count)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p.\n", iface, count);
|
|
|
|
|
|
|
|
if (grabber->is_shut_down)
|
|
|
|
return MF_E_SHUTDOWN;
|
|
|
|
|
|
|
|
*count = 1;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_sink_GetStreamSinkByIndex(IMFMediaSink *iface, DWORD index,
|
|
|
|
IMFStreamSink **stream)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE("%p, %u, %p.\n", iface, index, stream);
|
|
|
|
|
|
|
|
if (grabber->is_shut_down)
|
|
|
|
return MF_E_SHUTDOWN;
|
|
|
|
|
|
|
|
EnterCriticalSection(&grabber->cs);
|
|
|
|
|
|
|
|
if (grabber->is_shut_down)
|
|
|
|
hr = MF_E_SHUTDOWN;
|
|
|
|
else if (index > 0)
|
|
|
|
hr = MF_E_INVALIDINDEX;
|
|
|
|
else
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
*stream = &grabber->IMFStreamSink_iface;
|
2019-05-20 14:22:28 +02:00
|
|
|
IMFStreamSink_AddRef(*stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&grabber->cs);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_sink_GetStreamSinkById(IMFMediaSink *iface, DWORD stream_sink_id,
|
|
|
|
IMFStreamSink **stream)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE("%p, %#x, %p.\n", iface, stream_sink_id, stream);
|
|
|
|
|
|
|
|
EnterCriticalSection(&grabber->cs);
|
|
|
|
|
|
|
|
if (grabber->is_shut_down)
|
|
|
|
hr = MF_E_SHUTDOWN;
|
|
|
|
else if (stream_sink_id > 0)
|
|
|
|
hr = MF_E_INVALIDSTREAMNUMBER;
|
|
|
|
else
|
|
|
|
{
|
2020-04-22 15:32:13 +02:00
|
|
|
*stream = &grabber->IMFStreamSink_iface;
|
2019-05-20 14:22:28 +02:00
|
|
|
IMFStreamSink_AddRef(*stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&grabber->cs);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-04-22 15:32:14 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_sink_SetPresentationClock(IMFMediaSink *iface, IMFPresentationClock *clock)
|
2019-05-06 12:52:13 +02:00
|
|
|
{
|
2019-05-28 14:08:28 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
|
|
|
HRESULT hr;
|
2019-05-06 12:52:13 +02:00
|
|
|
|
2019-05-28 14:08:28 +02:00
|
|
|
TRACE("%p, %p.\n", iface, clock);
|
|
|
|
|
|
|
|
EnterCriticalSection(&grabber->cs);
|
|
|
|
|
2019-06-11 14:40:04 +02:00
|
|
|
if (SUCCEEDED(hr = IMFSampleGrabberSinkCallback_OnSetPresentationClock(sample_grabber_get_callback(grabber),
|
|
|
|
clock)))
|
2019-05-28 14:08:28 +02:00
|
|
|
{
|
2020-04-22 15:32:14 +02:00
|
|
|
sample_grabber_set_presentation_clock(grabber, clock);
|
2019-05-28 14:08:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&grabber->cs);
|
|
|
|
|
|
|
|
return hr;
|
2019-05-06 12:52:13 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_sink_GetPresentationClock(IMFMediaSink *iface, IMFPresentationClock **clock)
|
|
|
|
{
|
2019-05-28 14:08:28 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
|
|
|
HRESULT hr = S_OK;
|
2019-05-20 14:22:28 +02:00
|
|
|
|
2019-05-28 14:08:28 +02:00
|
|
|
TRACE("%p, %p.\n", iface, clock);
|
|
|
|
|
|
|
|
if (!clock)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
EnterCriticalSection(&grabber->cs);
|
|
|
|
|
|
|
|
if (grabber->clock)
|
|
|
|
{
|
|
|
|
*clock = grabber->clock;
|
|
|
|
IMFPresentationClock_AddRef(*clock);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = MF_E_NO_CLOCK;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&grabber->cs);
|
|
|
|
|
|
|
|
return hr;
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_sink_Shutdown(IMFMediaSink *iface)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaSink(iface);
|
2019-05-28 14:08:29 +02:00
|
|
|
HRESULT hr;
|
2019-05-20 14:22:28 +02:00
|
|
|
|
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
if (grabber->is_shut_down)
|
|
|
|
return MF_E_SHUTDOWN;
|
|
|
|
|
|
|
|
EnterCriticalSection(&grabber->cs);
|
|
|
|
grabber->is_shut_down = TRUE;
|
2020-05-15 17:32:53 +02:00
|
|
|
sample_grabber_release_pending_items(grabber);
|
2019-06-11 14:40:04 +02:00
|
|
|
if (SUCCEEDED(hr = IMFSampleGrabberSinkCallback_OnShutdown(sample_grabber_get_callback(grabber))))
|
2019-05-28 14:08:29 +02:00
|
|
|
{
|
2020-04-22 15:32:14 +02:00
|
|
|
sample_grabber_set_presentation_clock(grabber, NULL);
|
2020-04-22 15:32:13 +02:00
|
|
|
IMFMediaEventQueue_Shutdown(grabber->stream_event_queue);
|
2020-03-11 12:19:39 +01:00
|
|
|
IMFMediaEventQueue_Shutdown(grabber->event_queue);
|
2019-05-28 14:08:29 +02:00
|
|
|
}
|
2019-10-20 13:20:31 +02:00
|
|
|
LeaveCriticalSection(&grabber->cs);
|
2019-05-20 14:22:28 +02:00
|
|
|
|
2019-05-28 14:08:29 +02:00
|
|
|
return hr;
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFMediaSinkVtbl sample_grabber_sink_vtbl =
|
|
|
|
{
|
|
|
|
sample_grabber_sink_QueryInterface,
|
|
|
|
sample_grabber_sink_AddRef,
|
|
|
|
sample_grabber_sink_Release,
|
|
|
|
sample_grabber_sink_GetCharacteristics,
|
|
|
|
sample_grabber_sink_AddStreamSink,
|
|
|
|
sample_grabber_sink_RemoveStreamSink,
|
|
|
|
sample_grabber_sink_GetStreamSinkCount,
|
|
|
|
sample_grabber_sink_GetStreamSinkByIndex,
|
|
|
|
sample_grabber_sink_GetStreamSinkById,
|
|
|
|
sample_grabber_sink_SetPresentationClock,
|
|
|
|
sample_grabber_sink_GetPresentationClock,
|
|
|
|
sample_grabber_sink_Shutdown,
|
|
|
|
};
|
|
|
|
|
2019-05-20 14:22:30 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_clock_sink_QueryInterface(IMFClockStateSink *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFClockStateSink(iface);
|
|
|
|
return IMFMediaSink_QueryInterface(&grabber->IMFMediaSink_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_clock_sink_AddRef(IMFClockStateSink *iface)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFClockStateSink(iface);
|
|
|
|
return IMFMediaSink_AddRef(&grabber->IMFMediaSink_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_clock_sink_Release(IMFClockStateSink *iface)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFClockStateSink(iface);
|
|
|
|
return IMFMediaSink_Release(&grabber->IMFMediaSink_iface);
|
|
|
|
}
|
|
|
|
|
2021-06-03 14:43:14 +02:00
|
|
|
static HRESULT sample_grabber_set_state(struct sample_grabber *grabber, enum sink_state state,
|
|
|
|
MFTIME systime, LONGLONG offset)
|
2019-05-30 13:46:13 +02:00
|
|
|
{
|
|
|
|
static const DWORD events[] =
|
|
|
|
{
|
|
|
|
MEStreamSinkStopped, /* SINK_STATE_STOPPED */
|
2021-06-03 14:43:14 +02:00
|
|
|
MEStreamSinkPaused, /* SINK_STATE_PAUSED */
|
2019-05-30 13:46:13 +02:00
|
|
|
MEStreamSinkStarted, /* SINK_STATE_RUNNING */
|
|
|
|
};
|
2021-06-03 14:43:14 +02:00
|
|
|
BOOL do_callback = FALSE;
|
|
|
|
HRESULT hr = S_OK;
|
2019-06-07 15:08:58 +02:00
|
|
|
unsigned int i;
|
2019-05-30 13:46:13 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(&grabber->cs);
|
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (!grabber->is_shut_down)
|
2019-05-30 13:46:13 +02:00
|
|
|
{
|
2021-06-03 14:43:14 +02:00
|
|
|
if (state == SINK_STATE_PAUSED && grabber->state == SINK_STATE_STOPPED)
|
|
|
|
hr = MF_E_INVALID_STATE_TRANSITION;
|
|
|
|
else
|
2019-06-06 15:18:35 +02:00
|
|
|
{
|
2021-06-03 14:43:14 +02:00
|
|
|
if (state == SINK_STATE_RUNNING && grabber->state == SINK_STATE_STOPPED)
|
2019-06-07 15:08:58 +02:00
|
|
|
{
|
|
|
|
/* Every transition to running state sends a bunch requests to build up initial queue. */
|
|
|
|
for (i = 0; i < 4; ++i)
|
2020-04-22 15:32:13 +02:00
|
|
|
sample_grabber_stream_request_sample(grabber);
|
2019-06-07 15:08:58 +02:00
|
|
|
}
|
2021-06-03 14:43:14 +02:00
|
|
|
do_callback = state != grabber->state || state != SINK_STATE_PAUSED;
|
|
|
|
if (do_callback)
|
|
|
|
IMFStreamSink_QueueEvent(&grabber->IMFStreamSink_iface, events[state], &GUID_NULL, S_OK, NULL);
|
|
|
|
grabber->state = state;
|
2019-06-06 15:18:35 +02:00
|
|
|
}
|
2019-05-30 13:46:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&grabber->cs);
|
2021-06-03 14:43:14 +02:00
|
|
|
|
|
|
|
if (do_callback)
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case SINK_STATE_STOPPED:
|
|
|
|
hr = IMFSampleGrabberSinkCallback_OnClockStop(sample_grabber_get_callback(grabber), systime);
|
|
|
|
break;
|
|
|
|
case SINK_STATE_PAUSED:
|
|
|
|
hr = IMFSampleGrabberSinkCallback_OnClockPause(sample_grabber_get_callback(grabber), systime);
|
|
|
|
break;
|
|
|
|
case SINK_STATE_RUNNING:
|
|
|
|
hr = IMFSampleGrabberSinkCallback_OnClockStart(sample_grabber_get_callback(grabber), systime, offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2019-05-30 13:46:13 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:30 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_clock_sink_OnClockStart(IMFClockStateSink *iface, MFTIME systime, LONGLONG offset)
|
|
|
|
{
|
2019-05-30 13:46:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFClockStateSink(iface);
|
2019-05-20 14:22:30 +02:00
|
|
|
|
2020-03-25 13:01:23 +01:00
|
|
|
TRACE("%p, %s, %s.\n", iface, debugstr_time(systime), debugstr_time(offset));
|
2019-05-30 13:46:13 +02:00
|
|
|
|
2021-06-03 14:43:14 +02:00
|
|
|
return sample_grabber_set_state(grabber, SINK_STATE_RUNNING, systime, offset);
|
2019-05-20 14:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_clock_sink_OnClockStop(IMFClockStateSink *iface, MFTIME systime)
|
|
|
|
{
|
2019-05-30 13:46:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFClockStateSink(iface);
|
2019-05-20 14:22:30 +02:00
|
|
|
|
2020-03-25 13:01:23 +01:00
|
|
|
TRACE("%p, %s.\n", iface, debugstr_time(systime));
|
2019-05-30 13:46:13 +02:00
|
|
|
|
2021-06-03 14:43:14 +02:00
|
|
|
return sample_grabber_set_state(grabber, SINK_STATE_STOPPED, systime, 0);
|
2019-05-20 14:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_clock_sink_OnClockPause(IMFClockStateSink *iface, MFTIME systime)
|
|
|
|
{
|
2019-06-11 14:40:05 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFClockStateSink(iface);
|
|
|
|
|
2020-03-25 13:01:23 +01:00
|
|
|
TRACE("%p, %s.\n", iface, debugstr_time(systime));
|
2019-05-20 14:22:30 +02:00
|
|
|
|
2021-06-03 14:43:14 +02:00
|
|
|
return sample_grabber_set_state(grabber, SINK_STATE_PAUSED, systime, 0);
|
2019-05-20 14:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_clock_sink_OnClockRestart(IMFClockStateSink *iface, MFTIME systime)
|
|
|
|
{
|
2019-05-30 13:46:13 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFClockStateSink(iface);
|
2019-05-20 14:22:30 +02:00
|
|
|
|
2020-03-25 13:01:23 +01:00
|
|
|
TRACE("%p, %s.\n", iface, debugstr_time(systime));
|
2019-05-30 13:46:13 +02:00
|
|
|
|
2021-06-03 14:43:14 +02:00
|
|
|
return sample_grabber_set_state(grabber, SINK_STATE_RUNNING, systime, PRESENTATION_CURRENT_POSITION);
|
2019-05-20 14:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_clock_sink_OnClockSetRate(IMFClockStateSink *iface, MFTIME systime, float rate)
|
|
|
|
{
|
2019-06-11 14:40:05 +02:00
|
|
|
struct sample_grabber *grabber = impl_from_IMFClockStateSink(iface);
|
2019-05-20 14:22:30 +02:00
|
|
|
|
2020-03-25 13:01:23 +01:00
|
|
|
TRACE("%p, %s, %f.\n", iface, debugstr_time(systime), rate);
|
2019-06-11 14:40:05 +02:00
|
|
|
|
|
|
|
return IMFSampleGrabberSinkCallback_OnClockSetRate(sample_grabber_get_callback(grabber), systime, rate);
|
2019-05-20 14:22:30 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 14:22:32 +02:00
|
|
|
static HRESULT WINAPI sample_grabber_events_QueryInterface(IMFMediaEventGenerator *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaEventGenerator(iface);
|
|
|
|
return IMFMediaSink_QueryInterface(&grabber->IMFMediaSink_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_events_AddRef(IMFMediaEventGenerator *iface)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaEventGenerator(iface);
|
|
|
|
return IMFMediaSink_AddRef(&grabber->IMFMediaSink_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_events_Release(IMFMediaEventGenerator *iface)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaEventGenerator(iface);
|
|
|
|
return IMFMediaSink_Release(&grabber->IMFMediaSink_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_events_GetEvent(IMFMediaEventGenerator *iface, DWORD flags, IMFMediaEvent **event)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaEventGenerator(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %#x, %p.\n", iface, flags, event);
|
|
|
|
|
|
|
|
return IMFMediaEventQueue_GetEvent(grabber->event_queue, flags, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_events_BeginGetEvent(IMFMediaEventGenerator *iface, IMFAsyncCallback *callback,
|
|
|
|
IUnknown *state)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaEventGenerator(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p, %p.\n", iface, callback, state);
|
|
|
|
|
|
|
|
return IMFMediaEventQueue_BeginGetEvent(grabber->event_queue, callback, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_events_EndGetEvent(IMFMediaEventGenerator *iface, IMFAsyncResult *result,
|
|
|
|
IMFMediaEvent **event)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaEventGenerator(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p, %p.\n", iface, result, event);
|
|
|
|
|
|
|
|
return IMFMediaEventQueue_EndGetEvent(grabber->event_queue, result, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_events_QueueEvent(IMFMediaEventGenerator *iface, MediaEventType event_type,
|
|
|
|
REFGUID ext_type, HRESULT hr, const PROPVARIANT *value)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFMediaEventGenerator(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %u, %s, %#x, %p.\n", iface, event_type, debugstr_guid(ext_type), hr, value);
|
|
|
|
|
|
|
|
return IMFMediaEventQueue_QueueEventParamVar(grabber->event_queue, event_type, ext_type, hr, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFMediaEventGeneratorVtbl sample_grabber_sink_events_vtbl =
|
|
|
|
{
|
|
|
|
sample_grabber_events_QueryInterface,
|
|
|
|
sample_grabber_events_AddRef,
|
|
|
|
sample_grabber_events_Release,
|
|
|
|
sample_grabber_events_GetEvent,
|
|
|
|
sample_grabber_events_BeginGetEvent,
|
|
|
|
sample_grabber_events_EndGetEvent,
|
|
|
|
sample_grabber_events_QueueEvent,
|
|
|
|
};
|
|
|
|
|
2019-05-20 14:22:30 +02:00
|
|
|
static const IMFClockStateSinkVtbl sample_grabber_clock_sink_vtbl =
|
|
|
|
{
|
|
|
|
sample_grabber_clock_sink_QueryInterface,
|
|
|
|
sample_grabber_clock_sink_AddRef,
|
|
|
|
sample_grabber_clock_sink_Release,
|
|
|
|
sample_grabber_clock_sink_OnClockStart,
|
|
|
|
sample_grabber_clock_sink_OnClockStop,
|
|
|
|
sample_grabber_clock_sink_OnClockPause,
|
|
|
|
sample_grabber_clock_sink_OnClockRestart,
|
|
|
|
sample_grabber_clock_sink_OnClockSetRate,
|
|
|
|
};
|
|
|
|
|
2020-11-19 13:21:40 +01:00
|
|
|
static HRESULT WINAPI sample_grabber_getservice_QueryInterface(IMFGetService *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFGetService(iface);
|
|
|
|
return IMFMediaSink_QueryInterface(&grabber->IMFMediaSink_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_getservice_AddRef(IMFGetService *iface)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFGetService(iface);
|
|
|
|
return IMFMediaSink_AddRef(&grabber->IMFMediaSink_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_getservice_Release(IMFGetService *iface)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFGetService(iface);
|
|
|
|
return IMFMediaSink_Release(&grabber->IMFMediaSink_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_getservice_GetService(IMFGetService *iface, REFGUID service,
|
|
|
|
REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
TRACE("%p, %s, %s, %p.\n", iface, debugstr_guid(service), debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualGUID(service, &MF_RATE_CONTROL_SERVICE))
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, &IID_IMFRateSupport))
|
|
|
|
return IMFGetService_QueryInterface(iface, riid, obj);
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Unsupported service %s, riid %s.\n", debugstr_guid(service), debugstr_guid(riid));
|
|
|
|
|
|
|
|
return MF_E_UNSUPPORTED_SERVICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFGetServiceVtbl sample_grabber_getservice_vtbl =
|
|
|
|
{
|
|
|
|
sample_grabber_getservice_QueryInterface,
|
|
|
|
sample_grabber_getservice_AddRef,
|
|
|
|
sample_grabber_getservice_Release,
|
|
|
|
sample_grabber_getservice_GetService,
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_rate_support_QueryInterface(IMFRateSupport *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFRateSupport(iface);
|
|
|
|
return IMFMediaSink_QueryInterface(&grabber->IMFMediaSink_iface, riid, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_rate_support_AddRef(IMFRateSupport *iface)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFRateSupport(iface);
|
|
|
|
return IMFMediaSink_AddRef(&grabber->IMFMediaSink_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI sample_grabber_rate_support_Release(IMFRateSupport *iface)
|
|
|
|
{
|
|
|
|
struct sample_grabber *grabber = impl_from_IMFRateSupport(iface);
|
|
|
|
return IMFMediaSink_Release(&grabber->IMFMediaSink_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_rate_support_GetSlowestRate(IMFRateSupport *iface, MFRATE_DIRECTION direction,
|
|
|
|
BOOL thin, float *rate)
|
|
|
|
{
|
|
|
|
TRACE("%p, %d, %d, %p.\n", iface, direction, thin, rate);
|
|
|
|
|
|
|
|
*rate = 0.0f;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_rate_support_GetFastestRate(IMFRateSupport *iface, MFRATE_DIRECTION direction,
|
|
|
|
BOOL thin, float *rate)
|
|
|
|
{
|
|
|
|
TRACE("%p, %d, %d, %p.\n", iface, direction, thin, rate);
|
|
|
|
|
|
|
|
*rate = direction == MFRATE_REVERSE ? -FLT_MAX : FLT_MAX;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_rate_support_IsRateSupported(IMFRateSupport *iface, BOOL thin, float rate,
|
|
|
|
float *ret_rate)
|
|
|
|
{
|
|
|
|
TRACE("%p, %d, %f, %p.\n", iface, thin, rate, ret_rate);
|
|
|
|
|
|
|
|
if (ret_rate)
|
|
|
|
*ret_rate = rate;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMFRateSupportVtbl sample_grabber_rate_support_vtbl =
|
|
|
|
{
|
|
|
|
sample_grabber_rate_support_QueryInterface,
|
|
|
|
sample_grabber_rate_support_AddRef,
|
|
|
|
sample_grabber_rate_support_Release,
|
|
|
|
sample_grabber_rate_support_GetSlowestRate,
|
|
|
|
sample_grabber_rate_support_GetFastestRate,
|
|
|
|
sample_grabber_rate_support_IsRateSupported,
|
|
|
|
};
|
|
|
|
|
2019-05-20 14:22:28 +02:00
|
|
|
static HRESULT sample_grabber_create_object(IMFAttributes *attributes, void *user_context, IUnknown **obj)
|
|
|
|
{
|
|
|
|
struct sample_grabber_activate_context *context = user_context;
|
|
|
|
struct sample_grabber *object;
|
|
|
|
HRESULT hr;
|
2019-05-27 16:07:37 +02:00
|
|
|
GUID guid;
|
2019-05-20 14:22:28 +02:00
|
|
|
|
|
|
|
TRACE("%p, %p, %p.\n", attributes, user_context, obj);
|
|
|
|
|
2020-03-11 12:19:41 +01:00
|
|
|
if (context->shut_down)
|
|
|
|
return MF_E_SHUTDOWN;
|
|
|
|
|
2019-05-27 16:07:37 +02:00
|
|
|
/* At least major type is required. */
|
|
|
|
if (FAILED(IMFMediaType_GetMajorType(context->media_type, &guid)))
|
|
|
|
return MF_E_INVALIDMEDIATYPE;
|
|
|
|
|
2021-06-17 12:33:51 +02:00
|
|
|
if (!(object = calloc(1, sizeof(*object))))
|
2019-05-20 14:22:28 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->IMFMediaSink_iface.lpVtbl = &sample_grabber_sink_vtbl;
|
2019-05-20 14:22:30 +02:00
|
|
|
object->IMFClockStateSink_iface.lpVtbl = &sample_grabber_clock_sink_vtbl;
|
2019-05-20 14:22:32 +02:00
|
|
|
object->IMFMediaEventGenerator_iface.lpVtbl = &sample_grabber_sink_events_vtbl;
|
2020-11-19 13:21:40 +01:00
|
|
|
object->IMFGetService_iface.lpVtbl = &sample_grabber_getservice_vtbl;
|
|
|
|
object->IMFRateSupport_iface.lpVtbl = &sample_grabber_rate_support_vtbl;
|
2020-04-22 15:32:13 +02:00
|
|
|
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;
|
2019-05-20 14:22:28 +02:00
|
|
|
object->refcount = 1;
|
2019-06-11 14:40:04 +02:00
|
|
|
if (FAILED(IMFSampleGrabberSinkCallback_QueryInterface(context->callback, &IID_IMFSampleGrabberSinkCallback2,
|
|
|
|
(void **)&object->callback2)))
|
|
|
|
{
|
|
|
|
object->callback = context->callback;
|
|
|
|
IMFSampleGrabberSinkCallback_AddRef(object->callback);
|
|
|
|
}
|
2019-05-20 14:22:28 +02:00
|
|
|
object->media_type = context->media_type;
|
|
|
|
IMFMediaType_AddRef(object->media_type);
|
2020-11-26 10:42:31 +01:00
|
|
|
object->current_media_type = context->media_type;
|
|
|
|
IMFMediaType_AddRef(object->current_media_type);
|
2019-05-30 13:46:15 +02:00
|
|
|
IMFAttributes_GetUINT32(attributes, &MF_SAMPLEGRABBERSINK_IGNORE_CLOCK, &object->ignore_clock);
|
2019-06-06 15:18:35 +02:00
|
|
|
IMFAttributes_GetUINT64(attributes, &MF_SAMPLEGRABBERSINK_SAMPLE_TIME_OFFSET, &object->sample_time_offset);
|
2020-04-22 15:32:13 +02:00
|
|
|
list_init(&object->items);
|
2019-05-20 14:22:28 +02:00
|
|
|
InitializeCriticalSection(&object->cs);
|
2019-05-20 14:22:32 +02:00
|
|
|
|
2020-04-22 15:32:13 +02:00
|
|
|
if (FAILED(hr = MFCreateEventQueue(&object->stream_event_queue)))
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
if (FAILED(hr = MFCreateAttributes(&object->sample_attributes, 0)))
|
2019-05-20 14:22:32 +02:00
|
|
|
goto failed;
|
|
|
|
|
|
|
|
if (FAILED(hr = MFCreateEventQueue(&object->event_queue)))
|
|
|
|
goto failed;
|
2019-05-20 14:22:28 +02:00
|
|
|
|
|
|
|
*obj = (IUnknown *)&object->IMFMediaSink_iface;
|
|
|
|
|
|
|
|
TRACE("Created %p.\n", *obj);
|
|
|
|
|
|
|
|
return S_OK;
|
2019-05-20 14:22:32 +02:00
|
|
|
|
|
|
|
failed:
|
|
|
|
|
|
|
|
IMFMediaSink_Release(&object->IMFMediaSink_iface);
|
|
|
|
|
|
|
|
return hr;
|
2019-05-20 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
2020-03-11 12:19:41 +01:00
|
|
|
static void sample_grabber_shutdown_object(void *user_context, IUnknown *obj)
|
|
|
|
{
|
|
|
|
struct sample_grabber_activate_context *context = user_context;
|
|
|
|
context->shut_down = TRUE;
|
|
|
|
}
|
|
|
|
|
2019-05-06 12:52:13 +02:00
|
|
|
static const struct activate_funcs sample_grabber_activate_funcs =
|
|
|
|
{
|
|
|
|
sample_grabber_create_object,
|
2020-03-11 12:19:41 +01:00
|
|
|
sample_grabber_shutdown_object,
|
2019-05-06 12:52:13 +02:00
|
|
|
sample_grabber_free_private,
|
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* MFCreateSampleGrabberSinkActivate (mf.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI MFCreateSampleGrabberSinkActivate(IMFMediaType *media_type, IMFSampleGrabberSinkCallback *callback,
|
|
|
|
IMFActivate **activate)
|
|
|
|
{
|
|
|
|
struct sample_grabber_activate_context *context;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %p, %p.\n", media_type, callback, activate);
|
|
|
|
|
|
|
|
if (!media_type || !callback || !activate)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2021-06-17 12:33:51 +02:00
|
|
|
if (!(context = calloc(1, sizeof(*context))))
|
2019-05-06 12:52:13 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
context->media_type = media_type;
|
|
|
|
IMFMediaType_AddRef(context->media_type);
|
|
|
|
context->callback = callback;
|
|
|
|
IMFSampleGrabberSinkCallback_AddRef(context->callback);
|
|
|
|
|
|
|
|
if (FAILED(hr = create_activation_object(context, &sample_grabber_activate_funcs, activate)))
|
|
|
|
sample_grabber_free_private(context);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|