2010-02-04 01:02:59 +01:00
|
|
|
/* DirectShow Sample Grabber object (QEDIT.DLL)
|
|
|
|
*
|
|
|
|
* Copyright 2009 Paul Chitescu
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
|
|
|
|
#include "qedit_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2021-07-10 05:14:40 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
2010-02-04 01:02:59 +01:00
|
|
|
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber
|
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter filter;
|
2012-06-26 23:50:54 +02:00
|
|
|
ISampleGrabber ISampleGrabber_iface;
|
2019-11-20 03:18:00 +01:00
|
|
|
|
|
|
|
struct strmbase_source source;
|
2020-03-28 18:02:06 +01:00
|
|
|
struct strmbase_passthrough passthrough;
|
2019-11-20 03:18:00 +01:00
|
|
|
|
2019-11-20 03:18:03 +01:00
|
|
|
struct strmbase_sink sink;
|
2020-02-06 23:49:13 +01:00
|
|
|
AM_MEDIA_TYPE filter_mt;
|
2014-02-12 01:02:40 +01:00
|
|
|
IMemInputPin IMemInputPin_iface;
|
2010-02-04 01:02:59 +01:00
|
|
|
IMemAllocator *allocator;
|
2019-11-20 03:18:00 +01:00
|
|
|
|
2010-02-12 20:09:02 +01:00
|
|
|
ISampleGrabberCB *grabberIface;
|
|
|
|
LONG grabberMethod;
|
|
|
|
LONG oneShot;
|
2010-03-12 13:15:51 +01:00
|
|
|
LONG bufferLen;
|
|
|
|
void* bufferData;
|
2020-03-31 00:55:12 +02:00
|
|
|
};
|
2010-02-04 01:02:59 +01:00
|
|
|
|
2010-02-12 20:09:02 +01:00
|
|
|
enum {
|
|
|
|
OneShot_None,
|
|
|
|
OneShot_Wait,
|
|
|
|
OneShot_Past,
|
|
|
|
};
|
|
|
|
|
2020-03-31 00:55:12 +02:00
|
|
|
static struct sample_grabber *impl_from_strmbase_filter(struct strmbase_filter *iface)
|
2014-02-20 21:30:48 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, filter);
|
2014-02-20 21:30:48 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 00:55:12 +02:00
|
|
|
static struct sample_grabber *impl_from_ISampleGrabber(ISampleGrabber *iface)
|
2010-02-04 01:02:59 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, ISampleGrabber_iface);
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 00:55:12 +02:00
|
|
|
static struct sample_grabber *impl_from_IMemInputPin(IMemInputPin *iface)
|
2010-02-12 20:09:02 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, IMemInputPin_iface);
|
2010-02-12 20:09:02 +01:00
|
|
|
}
|
|
|
|
|
2010-02-04 01:02:59 +01:00
|
|
|
|
|
|
|
/* Cleanup at end of life */
|
2020-03-31 00:55:12 +02:00
|
|
|
static void SampleGrabber_cleanup(struct sample_grabber *This)
|
2010-02-04 01:02:59 +01:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
if (This->allocator)
|
|
|
|
IMemAllocator_Release(This->allocator);
|
2010-02-12 20:09:02 +01:00
|
|
|
if (This->grabberIface)
|
|
|
|
ISampleGrabberCB_Release(This->grabberIface);
|
2020-02-06 23:49:14 +01:00
|
|
|
FreeMediaType(&This->filter_mt);
|
2016-07-08 10:11:54 +02:00
|
|
|
CoTaskMemFree(This->bufferData);
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
2019-11-23 04:13:59 +01:00
|
|
|
static struct strmbase_pin *sample_grabber_get_pin(struct strmbase_filter *iface, unsigned int index)
|
2014-02-20 21:30:48 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_strmbase_filter(iface);
|
2014-02-20 21:30:48 +01:00
|
|
|
|
2019-05-24 00:06:30 +02:00
|
|
|
if (index == 0)
|
2019-11-23 04:13:59 +01:00
|
|
|
return &filter->sink.pin;
|
2019-05-24 00:06:30 +02:00
|
|
|
else if (index == 1)
|
2019-11-23 04:13:59 +01:00
|
|
|
return &filter->source.pin;
|
2019-06-11 16:42:16 +02:00
|
|
|
return NULL;
|
2014-02-20 21:30:48 +01:00
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static void sample_grabber_destroy(struct strmbase_filter *iface)
|
2019-06-05 00:54:26 +02:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_strmbase_filter(iface);
|
2019-06-05 00:54:26 +02:00
|
|
|
|
|
|
|
SampleGrabber_cleanup(filter);
|
2019-12-16 01:21:14 +01:00
|
|
|
strmbase_sink_cleanup(&filter->sink);
|
|
|
|
strmbase_source_cleanup(&filter->source);
|
2020-03-28 18:02:06 +01:00
|
|
|
strmbase_passthrough_cleanup(&filter->passthrough);
|
2019-06-05 00:54:26 +02:00
|
|
|
strmbase_filter_cleanup(&filter->filter);
|
2020-03-31 00:55:11 +02:00
|
|
|
free(filter);
|
2019-06-05 00:54:26 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static HRESULT sample_grabber_query_interface(struct strmbase_filter *iface, REFIID iid, void **out)
|
2019-06-05 00:54:26 +02:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_strmbase_filter(iface);
|
2019-06-05 00:54:26 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_ISampleGrabber))
|
|
|
|
*out = &filter->ISampleGrabber_iface;
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:29 +02:00
|
|
|
static const struct strmbase_filter_ops filter_ops =
|
|
|
|
{
|
2019-05-24 00:06:31 +02:00
|
|
|
.filter_get_pin = sample_grabber_get_pin,
|
2019-06-05 00:54:26 +02:00
|
|
|
.filter_destroy = sample_grabber_destroy,
|
|
|
|
.filter_query_interface = sample_grabber_query_interface,
|
2014-02-20 21:30:48 +01:00
|
|
|
};
|
|
|
|
|
2010-03-12 13:15:51 +01:00
|
|
|
/* Helper that buffers data and/or calls installed sample callbacks */
|
2020-03-31 00:55:12 +02:00
|
|
|
static void SampleGrabber_callback(struct sample_grabber *This, IMediaSample *sample)
|
2010-02-12 20:09:02 +01:00
|
|
|
{
|
|
|
|
double time = 0.0;
|
|
|
|
REFERENCE_TIME tStart, tEnd;
|
2010-03-12 13:15:51 +01:00
|
|
|
if (This->bufferLen >= 0) {
|
|
|
|
BYTE *data = 0;
|
2010-05-11 10:34:43 +02:00
|
|
|
LONG size = IMediaSample_GetActualDataLength(sample);
|
2010-03-12 13:15:51 +01:00
|
|
|
if (size >= 0 && SUCCEEDED(IMediaSample_GetPointer(sample, &data))) {
|
|
|
|
if (!data)
|
|
|
|
size = 0;
|
2021-01-19 04:57:19 +01:00
|
|
|
EnterCriticalSection(&This->filter.filter_cs);
|
2010-03-12 13:15:51 +01:00
|
|
|
if (This->bufferLen != size) {
|
2016-07-08 10:11:54 +02:00
|
|
|
CoTaskMemFree(This->bufferData);
|
2010-03-12 13:15:51 +01:00
|
|
|
This->bufferData = size ? CoTaskMemAlloc(size) : NULL;
|
|
|
|
This->bufferLen = size;
|
|
|
|
}
|
|
|
|
if (size)
|
|
|
|
CopyMemory(This->bufferData, data, size);
|
2021-01-19 04:57:19 +01:00
|
|
|
LeaveCriticalSection(&This->filter.filter_cs);
|
2010-03-12 13:15:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!This->grabberIface)
|
|
|
|
return;
|
2010-02-12 20:09:02 +01:00
|
|
|
if (SUCCEEDED(IMediaSample_GetTime(sample, &tStart, &tEnd)))
|
|
|
|
time = 1e-7 * tStart;
|
|
|
|
switch (This->grabberMethod) {
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
ULONG ref = IMediaSample_AddRef(sample);
|
|
|
|
ISampleGrabberCB_SampleCB(This->grabberIface, time, sample);
|
|
|
|
ref = IMediaSample_Release(sample) + 1 - ref;
|
|
|
|
if (ref)
|
|
|
|
{
|
2022-02-09 17:38:44 +01:00
|
|
|
ERR("(%p) Callback referenced sample %p by %lu\n", This, sample, ref);
|
2010-02-12 20:09:02 +01:00
|
|
|
/* ugly as hell but some apps are sooo buggy */
|
|
|
|
while (ref--)
|
|
|
|
IMediaSample_Release(sample);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
BYTE *data = 0;
|
2010-05-11 10:34:43 +02:00
|
|
|
LONG size = IMediaSample_GetActualDataLength(sample);
|
2010-02-12 20:09:02 +01:00
|
|
|
if (size && SUCCEEDED(IMediaSample_GetPointer(sample, &data)) && data)
|
|
|
|
ISampleGrabberCB_BufferCB(This->grabberIface, time, data, size);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
break;
|
|
|
|
default:
|
2022-02-09 17:38:44 +01:00
|
|
|
FIXME("Unknown method %ld.\n", This->grabberMethod);
|
2010-02-12 20:09:02 +01:00
|
|
|
/* do not bother us again */
|
|
|
|
This->grabberMethod = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-04 01:02:59 +01:00
|
|
|
/* IUnknown */
|
|
|
|
static HRESULT WINAPI
|
2012-06-26 23:50:54 +02:00
|
|
|
SampleGrabber_ISampleGrabber_QueryInterface(ISampleGrabber *iface, REFIID riid, void **ppv)
|
2010-02-04 01:02:59 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_ISampleGrabber(iface);
|
|
|
|
return IUnknown_QueryInterface(filter->filter.outer_unk, riid, ppv);
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IUnknown */
|
|
|
|
static ULONG WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_AddRef(ISampleGrabber *iface)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_ISampleGrabber(iface);
|
|
|
|
return IUnknown_AddRef(filter->filter.outer_unk);
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IUnknown */
|
|
|
|
static ULONG WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_Release(ISampleGrabber *iface)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_ISampleGrabber(iface);
|
|
|
|
return IUnknown_Release(filter->filter.outer_unk);
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ISampleGrabber */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_SetOneShot(ISampleGrabber *iface, BOOL oneShot)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *This = impl_from_ISampleGrabber(iface);
|
2010-02-12 20:09:02 +01:00
|
|
|
TRACE("(%p)->(%u)\n", This, oneShot);
|
|
|
|
This->oneShot = oneShot ? OneShot_Wait : OneShot_None;
|
|
|
|
return S_OK;
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ISampleGrabber */
|
2020-02-06 23:49:14 +01:00
|
|
|
static HRESULT WINAPI SampleGrabber_ISampleGrabber_SetMediaType(ISampleGrabber *iface, const AM_MEDIA_TYPE *mt)
|
2010-02-04 01:02:59 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_ISampleGrabber(iface);
|
2020-02-06 23:49:14 +01:00
|
|
|
|
|
|
|
TRACE("filter %p, mt %p.\n", filter, mt);
|
|
|
|
strmbase_dump_media_type(mt);
|
|
|
|
|
|
|
|
if (!mt)
|
2010-02-04 01:02:59 +01:00
|
|
|
return E_POINTER;
|
2020-02-06 23:49:14 +01:00
|
|
|
|
|
|
|
FreeMediaType(&filter->filter_mt);
|
|
|
|
CopyMediaType(&filter->filter_mt, mt);
|
2010-02-12 20:10:34 +01:00
|
|
|
return S_OK;
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ISampleGrabber */
|
|
|
|
static HRESULT WINAPI
|
2020-02-06 23:49:14 +01:00
|
|
|
SampleGrabber_ISampleGrabber_GetConnectedMediaType(ISampleGrabber *iface, AM_MEDIA_TYPE *mt)
|
2010-02-04 01:02:59 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_ISampleGrabber(iface);
|
2020-02-06 23:49:14 +01:00
|
|
|
|
|
|
|
TRACE("filter %p, mt %p.\n", filter, mt);
|
|
|
|
|
|
|
|
if (!mt)
|
2010-02-04 01:02:59 +01:00
|
|
|
return E_POINTER;
|
2020-02-06 23:49:14 +01:00
|
|
|
|
|
|
|
if (!filter->sink.pin.peer)
|
2010-02-12 20:10:34 +01:00
|
|
|
return VFW_E_NOT_CONNECTED;
|
2020-02-06 23:49:14 +01:00
|
|
|
|
2020-02-08 06:51:52 +01:00
|
|
|
CopyMediaType(mt, &filter->sink.pin.mt);
|
2010-02-12 20:10:34 +01:00
|
|
|
return S_OK;
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ISampleGrabber */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_SetBufferSamples(ISampleGrabber *iface, BOOL bufferEm)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *This = impl_from_ISampleGrabber(iface);
|
2010-03-12 13:15:51 +01:00
|
|
|
TRACE("(%p)->(%u)\n", This, bufferEm);
|
2021-01-19 04:57:19 +01:00
|
|
|
EnterCriticalSection(&This->filter.filter_cs);
|
2010-02-04 01:02:59 +01:00
|
|
|
if (bufferEm) {
|
2010-03-12 13:15:51 +01:00
|
|
|
if (This->bufferLen < 0)
|
|
|
|
This->bufferLen = 0;
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
2010-03-12 13:15:51 +01:00
|
|
|
else
|
|
|
|
This->bufferLen = -1;
|
2021-01-19 04:57:19 +01:00
|
|
|
LeaveCriticalSection(&This->filter.filter_cs);
|
2010-02-04 01:02:59 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ISampleGrabber */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_GetCurrentBuffer(ISampleGrabber *iface, LONG *bufSize, LONG *buffer)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *This = impl_from_ISampleGrabber(iface);
|
2010-03-12 13:15:51 +01:00
|
|
|
HRESULT ret = S_OK;
|
|
|
|
TRACE("(%p)->(%p, %p)\n", This, bufSize, buffer);
|
2010-02-04 01:02:59 +01:00
|
|
|
if (!bufSize)
|
|
|
|
return E_POINTER;
|
2021-01-19 04:57:19 +01:00
|
|
|
EnterCriticalSection(&This->filter.filter_cs);
|
2019-11-20 03:18:03 +01:00
|
|
|
if (!This->sink.pin.peer)
|
2010-03-12 13:15:51 +01:00
|
|
|
ret = VFW_E_NOT_CONNECTED;
|
|
|
|
else if (This->bufferLen < 0)
|
|
|
|
ret = E_INVALIDARG;
|
|
|
|
else if (This->bufferLen == 0)
|
|
|
|
ret = VFW_E_WRONG_STATE;
|
|
|
|
else {
|
|
|
|
if (buffer) {
|
|
|
|
if (*bufSize >= This->bufferLen)
|
|
|
|
CopyMemory(buffer, This->bufferData, This->bufferLen);
|
|
|
|
else
|
|
|
|
ret = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
*bufSize = This->bufferLen;
|
|
|
|
}
|
2021-01-19 04:57:19 +01:00
|
|
|
LeaveCriticalSection(&This->filter.filter_cs);
|
2010-03-12 13:15:51 +01:00
|
|
|
return ret;
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ISampleGrabber */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_GetCurrentSample(ISampleGrabber *iface, IMediaSample **sample)
|
|
|
|
{
|
2010-03-20 15:24:53 +01:00
|
|
|
/* MS doesn't implement it either, no one should call it */
|
2010-02-04 01:02:59 +01:00
|
|
|
WARN("(%p): not implemented\n", sample);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ISampleGrabber */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_SetCallback(ISampleGrabber *iface, ISampleGrabberCB *cb, LONG whichMethod)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *This = impl_from_ISampleGrabber(iface);
|
2022-02-09 17:38:44 +01:00
|
|
|
|
|
|
|
TRACE("filter %p, callback %p, method %ld.\n", This, cb, whichMethod);
|
|
|
|
|
2010-02-12 20:09:02 +01:00
|
|
|
if (This->grabberIface)
|
|
|
|
ISampleGrabberCB_Release(This->grabberIface);
|
|
|
|
This->grabberIface = cb;
|
|
|
|
This->grabberMethod = whichMethod;
|
|
|
|
if (cb)
|
|
|
|
ISampleGrabberCB_AddRef(cb);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-17 07:31:04 +02:00
|
|
|
static HRESULT WINAPI SampleGrabber_IMemInputPin_QueryInterface(IMemInputPin *iface, REFIID iid, void **out)
|
2010-02-12 20:09:02 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_IMemInputPin(iface);
|
2019-11-20 03:18:03 +01:00
|
|
|
return IPin_QueryInterface(&filter->sink.pin.IPin_iface, iid, out);
|
2010-02-12 20:09:02 +01:00
|
|
|
}
|
|
|
|
|
2019-05-17 07:31:04 +02:00
|
|
|
static ULONG WINAPI SampleGrabber_IMemInputPin_AddRef(IMemInputPin *iface)
|
2010-02-12 20:09:02 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_IMemInputPin(iface);
|
2019-11-20 03:18:03 +01:00
|
|
|
return IPin_AddRef(&filter->sink.pin.IPin_iface);
|
2010-02-12 20:09:02 +01:00
|
|
|
}
|
|
|
|
|
2019-05-17 07:31:04 +02:00
|
|
|
static ULONG WINAPI SampleGrabber_IMemInputPin_Release(IMemInputPin *iface)
|
2010-02-12 20:09:02 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_IMemInputPin(iface);
|
2019-11-20 03:18:03 +01:00
|
|
|
return IPin_Release(&filter->sink.pin.IPin_iface);
|
2010-02-12 20:09:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IMemInputPin */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_IMemInputPin_GetAllocator(IMemInputPin *iface, IMemAllocator **allocator)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *This = impl_from_IMemInputPin(iface);
|
2010-02-12 20:09:02 +01:00
|
|
|
TRACE("(%p)->(%p) allocator = %p\n", This, allocator, This->allocator);
|
|
|
|
if (!allocator)
|
|
|
|
return E_POINTER;
|
|
|
|
*allocator = This->allocator;
|
|
|
|
if (!*allocator)
|
|
|
|
return VFW_E_NO_ALLOCATOR;
|
|
|
|
IMemAllocator_AddRef(*allocator);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IMemInputPin */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_IMemInputPin_NotifyAllocator(IMemInputPin *iface, IMemAllocator *allocator, BOOL readOnly)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *This = impl_from_IMemInputPin(iface);
|
2010-02-12 20:09:02 +01:00
|
|
|
TRACE("(%p)->(%p, %u) allocator = %p\n", This, allocator, readOnly, This->allocator);
|
|
|
|
if (This->allocator == allocator)
|
|
|
|
return S_OK;
|
|
|
|
if (This->allocator)
|
|
|
|
IMemAllocator_Release(This->allocator);
|
|
|
|
This->allocator = allocator;
|
|
|
|
if (allocator)
|
|
|
|
IMemAllocator_AddRef(allocator);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IMemInputPin */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_IMemInputPin_GetAllocatorRequirements(IMemInputPin *iface, ALLOCATOR_PROPERTIES *props)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *This = impl_from_IMemInputPin(iface);
|
2010-02-12 20:09:02 +01:00
|
|
|
FIXME("(%p)->(%p): semi-stub\n", This, props);
|
|
|
|
if (!props)
|
|
|
|
return E_POINTER;
|
2019-12-16 01:21:15 +01:00
|
|
|
return This->source.pMemInputPin ? IMemInputPin_GetAllocatorRequirements(This->source.pMemInputPin, props) : E_NOTIMPL;
|
2010-02-12 20:09:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IMemInputPin */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_IMemInputPin_Receive(IMemInputPin *iface, IMediaSample *sample)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *This = impl_from_IMemInputPin(iface);
|
2010-02-12 20:09:02 +01:00
|
|
|
HRESULT hr;
|
2019-12-16 01:21:15 +01:00
|
|
|
TRACE("(%p)->(%p) output = %p, grabber = %p\n", This, sample, This->source.pMemInputPin, This->grabberIface);
|
2010-02-12 20:09:02 +01:00
|
|
|
if (!sample)
|
|
|
|
return E_POINTER;
|
2016-05-16 15:28:38 +02:00
|
|
|
if (This->oneShot == OneShot_Past)
|
2010-02-12 20:09:02 +01:00
|
|
|
return S_FALSE;
|
2010-03-12 13:15:51 +01:00
|
|
|
SampleGrabber_callback(This, sample);
|
2019-12-16 01:21:15 +01:00
|
|
|
hr = This->source.pMemInputPin ? IMemInputPin_Receive(This->source.pMemInputPin, sample) : S_OK;
|
2010-02-12 20:09:02 +01:00
|
|
|
if (This->oneShot == OneShot_Wait) {
|
|
|
|
This->oneShot = OneShot_Past;
|
|
|
|
hr = S_FALSE;
|
2019-11-20 03:18:00 +01:00
|
|
|
if (This->source.pin.peer)
|
|
|
|
IPin_EndOfStream(This->source.pin.peer);
|
2010-02-12 20:09:02 +01:00
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IMemInputPin */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_IMemInputPin_ReceiveMultiple(IMemInputPin *iface, IMediaSample **samples, LONG nSamples, LONG *nProcessed)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *This = impl_from_IMemInputPin(iface);
|
2010-03-12 13:15:51 +01:00
|
|
|
LONG idx;
|
2022-02-09 17:38:44 +01:00
|
|
|
|
|
|
|
TRACE("filter %p, samples %p, count %lu, ret_count %p.\n", This, samples, nSamples, nProcessed);
|
|
|
|
|
2010-02-12 20:09:02 +01:00
|
|
|
if (!samples || !nProcessed)
|
|
|
|
return E_POINTER;
|
2014-02-20 00:13:09 +01:00
|
|
|
if ((This->filter.state != State_Running) || (This->oneShot == OneShot_Past))
|
2010-02-12 20:09:02 +01:00
|
|
|
return S_FALSE;
|
2010-03-12 13:15:51 +01:00
|
|
|
for (idx = 0; idx < nSamples; idx++)
|
|
|
|
SampleGrabber_callback(This, samples[idx]);
|
2019-12-16 01:21:15 +01:00
|
|
|
return This->source.pMemInputPin ? IMemInputPin_ReceiveMultiple(This->source.pMemInputPin, samples, nSamples, nProcessed) : S_OK;
|
2010-02-12 20:09:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IMemInputPin */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_IMemInputPin_ReceiveCanBlock(IMemInputPin *iface)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *This = impl_from_IMemInputPin(iface);
|
2010-02-12 20:09:02 +01:00
|
|
|
TRACE("(%p)\n", This);
|
2019-12-16 01:21:15 +01:00
|
|
|
return This->source.pMemInputPin ? IMemInputPin_ReceiveCanBlock(This->source.pMemInputPin) : S_OK;
|
2010-02-12 20:09:02 +01:00
|
|
|
}
|
|
|
|
|
2010-02-04 01:02:59 +01:00
|
|
|
static const ISampleGrabberVtbl ISampleGrabber_VTable =
|
|
|
|
{
|
|
|
|
SampleGrabber_ISampleGrabber_QueryInterface,
|
|
|
|
SampleGrabber_ISampleGrabber_AddRef,
|
|
|
|
SampleGrabber_ISampleGrabber_Release,
|
|
|
|
SampleGrabber_ISampleGrabber_SetOneShot,
|
|
|
|
SampleGrabber_ISampleGrabber_SetMediaType,
|
|
|
|
SampleGrabber_ISampleGrabber_GetConnectedMediaType,
|
|
|
|
SampleGrabber_ISampleGrabber_SetBufferSamples,
|
|
|
|
SampleGrabber_ISampleGrabber_GetCurrentBuffer,
|
|
|
|
SampleGrabber_ISampleGrabber_GetCurrentSample,
|
|
|
|
SampleGrabber_ISampleGrabber_SetCallback,
|
|
|
|
};
|
|
|
|
|
2010-02-12 20:09:02 +01:00
|
|
|
static const IMemInputPinVtbl IMemInputPin_VTable =
|
|
|
|
{
|
|
|
|
SampleGrabber_IMemInputPin_QueryInterface,
|
|
|
|
SampleGrabber_IMemInputPin_AddRef,
|
|
|
|
SampleGrabber_IMemInputPin_Release,
|
|
|
|
SampleGrabber_IMemInputPin_GetAllocator,
|
|
|
|
SampleGrabber_IMemInputPin_NotifyAllocator,
|
|
|
|
SampleGrabber_IMemInputPin_GetAllocatorRequirements,
|
|
|
|
SampleGrabber_IMemInputPin_Receive,
|
|
|
|
SampleGrabber_IMemInputPin_ReceiveMultiple,
|
|
|
|
SampleGrabber_IMemInputPin_ReceiveCanBlock,
|
|
|
|
};
|
|
|
|
|
2020-03-31 00:55:12 +02:00
|
|
|
static struct sample_grabber *impl_from_sink_pin(struct strmbase_pin *iface)
|
2019-11-20 03:18:03 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, sink.pin);
|
2019-11-20 03:18:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT sample_grabber_sink_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_sink_pin(iface);
|
2019-11-20 03:18:03 +01:00
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_IMemInputPin))
|
|
|
|
*out = &filter->IMemInputPin_iface;
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-31 00:55:12 +02:00
|
|
|
static BOOL check_filter_mt(struct sample_grabber *filter, const AM_MEDIA_TYPE *mt)
|
2020-03-06 03:04:36 +01:00
|
|
|
{
|
|
|
|
if (IsEqualGUID(&filter->filter_mt.majortype, &GUID_NULL))
|
|
|
|
return TRUE;
|
|
|
|
if (!IsEqualGUID(&filter->filter_mt.majortype, &mt->majortype))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (IsEqualGUID(&filter->filter_mt.subtype, &GUID_NULL))
|
|
|
|
return TRUE;
|
|
|
|
if (!IsEqualGUID(&filter->filter_mt.subtype, &mt->subtype))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (IsEqualGUID(&filter->filter_mt.formattype, &GUID_NULL))
|
|
|
|
return TRUE;
|
|
|
|
if (!IsEqualGUID(&filter->filter_mt.formattype, &mt->formattype))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-20 03:18:03 +01:00
|
|
|
static HRESULT sample_grabber_sink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_sink_pin(iface);
|
2020-03-06 03:04:36 +01:00
|
|
|
|
|
|
|
return check_filter_mt(filter, mt) ? S_OK : S_FALSE;
|
2019-11-20 03:18:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT sample_grabber_sink_get_media_type(struct strmbase_pin *iface,
|
|
|
|
unsigned int index, AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_sink_pin(iface);
|
2020-03-06 03:04:37 +01:00
|
|
|
IEnumMediaTypes *enummt;
|
|
|
|
AM_MEDIA_TYPE *pmt;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!filter->source.pin.peer)
|
|
|
|
return VFW_E_NOT_CONNECTED;
|
2019-11-20 03:18:03 +01:00
|
|
|
|
2020-03-06 03:04:37 +01:00
|
|
|
if (FAILED(hr = IPin_EnumMediaTypes(filter->source.pin.peer, &enummt)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if ((!index || IEnumMediaTypes_Skip(enummt, index) == S_OK)
|
|
|
|
&& IEnumMediaTypes_Next(enummt, 1, &pmt, NULL) == S_OK)
|
2019-11-20 03:18:03 +01:00
|
|
|
{
|
2020-03-06 03:04:37 +01:00
|
|
|
CopyMediaType(mt, pmt);
|
|
|
|
DeleteMediaType(pmt);
|
|
|
|
IEnumMediaTypes_Release(enummt);
|
2019-11-20 03:18:03 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2020-03-06 03:04:37 +01:00
|
|
|
|
|
|
|
IEnumMediaTypes_Release(enummt);
|
2019-11-20 03:18:03 +01:00
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct strmbase_sink_ops sink_ops =
|
|
|
|
{
|
|
|
|
.base.pin_query_interface = sample_grabber_sink_query_interface,
|
|
|
|
.base.pin_query_accept = sample_grabber_sink_query_accept,
|
|
|
|
.base.pin_get_media_type = sample_grabber_sink_get_media_type,
|
2010-02-12 20:09:02 +01:00
|
|
|
};
|
|
|
|
|
2020-03-31 00:55:12 +02:00
|
|
|
static struct sample_grabber *impl_from_source_pin(struct strmbase_pin *iface)
|
2019-04-16 06:20:49 +02:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct sample_grabber, source.pin);
|
2019-11-20 03:18:00 +01:00
|
|
|
}
|
2019-04-16 06:20:49 +02:00
|
|
|
|
2019-11-20 03:18:00 +01:00
|
|
|
static HRESULT sample_grabber_source_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_source_pin(iface);
|
2019-04-16 06:20:49 +02:00
|
|
|
|
2020-03-28 18:02:06 +01:00
|
|
|
if (IsEqualGUID(iid, &IID_IMediaPosition))
|
|
|
|
*out = &filter->passthrough.IMediaPosition_iface;
|
|
|
|
else if (IsEqualGUID(iid, &IID_IMediaSeeking))
|
|
|
|
*out = &filter->passthrough.IMediaSeeking_iface;
|
2019-11-20 03:18:00 +01:00
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
2020-03-28 18:02:06 +01:00
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
2019-11-20 03:18:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT sample_grabber_source_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_source_pin(iface);
|
2020-02-08 06:51:53 +01:00
|
|
|
|
|
|
|
if (filter->sink.pin.peer && IPin_QueryAccept(filter->sink.pin.peer, mt) != S_OK)
|
|
|
|
return S_FALSE;
|
|
|
|
|
2020-03-06 03:04:36 +01:00
|
|
|
return check_filter_mt(filter, mt) ? S_OK : S_FALSE;
|
2019-11-20 03:18:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT sample_grabber_source_get_media_type(struct strmbase_pin *iface,
|
|
|
|
unsigned int index, AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_source_pin(iface);
|
2020-02-08 06:51:54 +01:00
|
|
|
IEnumMediaTypes *enummt;
|
|
|
|
AM_MEDIA_TYPE *pmt;
|
|
|
|
HRESULT hr;
|
2019-11-20 03:18:00 +01:00
|
|
|
|
2020-02-08 06:51:54 +01:00
|
|
|
if (!filter->sink.pin.peer)
|
|
|
|
return VFW_E_NOT_CONNECTED;
|
|
|
|
|
|
|
|
if (FAILED(hr = IPin_EnumMediaTypes(filter->sink.pin.peer, &enummt)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if ((!index || IEnumMediaTypes_Skip(enummt, index) == S_OK)
|
|
|
|
&& IEnumMediaTypes_Next(enummt, 1, &pmt, NULL) == S_OK)
|
2019-04-16 06:20:49 +02:00
|
|
|
{
|
2020-02-08 06:51:54 +01:00
|
|
|
CopyMediaType(mt, pmt);
|
|
|
|
DeleteMediaType(pmt);
|
|
|
|
IEnumMediaTypes_Release(enummt);
|
2019-11-20 03:18:00 +01:00
|
|
|
return S_OK;
|
2019-04-16 06:20:49 +02:00
|
|
|
}
|
2020-02-08 06:51:54 +01:00
|
|
|
|
|
|
|
IEnumMediaTypes_Release(enummt);
|
2019-11-20 03:18:00 +01:00
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
|
|
|
}
|
|
|
|
|
2020-02-08 06:51:56 +01:00
|
|
|
static inline BOOL compare_media_types(const AM_MEDIA_TYPE *a, const AM_MEDIA_TYPE *b)
|
|
|
|
{
|
|
|
|
return !memcmp(a, b, offsetof(AM_MEDIA_TYPE, pbFormat))
|
|
|
|
&& !memcmp(a->pbFormat, b->pbFormat, a->cbFormat);
|
|
|
|
}
|
|
|
|
|
2020-02-06 23:49:11 +01:00
|
|
|
static HRESULT WINAPI sample_grabber_source_DecideAllocator(struct strmbase_source *iface,
|
|
|
|
IMemInputPin *peer, IMemAllocator **allocator)
|
2019-11-20 03:18:00 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *filter = impl_from_source_pin(&iface->pin);
|
2020-02-08 06:51:56 +01:00
|
|
|
const AM_MEDIA_TYPE *mt = &iface->pin.mt;
|
|
|
|
|
|
|
|
if (!compare_media_types(mt, &filter->sink.pin.mt))
|
|
|
|
{
|
|
|
|
IFilterGraph2 *graph;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (FAILED(hr = IFilterGraph_QueryInterface(filter->filter.graph,
|
|
|
|
&IID_IFilterGraph2, (void **)&graph)))
|
|
|
|
{
|
2022-02-09 17:38:44 +01:00
|
|
|
ERR("Failed to get IFilterGraph2 interface, hr %#lx.\n", hr);
|
2020-02-08 06:51:56 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IFilterGraph2_ReconnectEx(graph, &filter->sink.pin.IPin_iface, mt);
|
|
|
|
IFilterGraph2_Release(graph);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-02-06 23:49:11 +01:00
|
|
|
return S_OK;
|
2019-04-16 06:20:49 +02:00
|
|
|
}
|
|
|
|
|
2019-11-20 03:18:00 +01:00
|
|
|
static const struct strmbase_source_ops source_ops =
|
2010-02-12 20:09:02 +01:00
|
|
|
{
|
2019-11-20 03:18:00 +01:00
|
|
|
.base.pin_query_interface = sample_grabber_source_query_interface,
|
|
|
|
.base.pin_query_accept = sample_grabber_source_query_accept,
|
|
|
|
.base.pin_get_media_type = sample_grabber_source_get_media_type,
|
2020-02-06 23:49:11 +01:00
|
|
|
.pfnAttemptConnection = BaseOutputPinImpl_AttemptConnection,
|
|
|
|
.pfnDecideAllocator = sample_grabber_source_DecideAllocator,
|
2019-11-20 03:18:00 +01:00
|
|
|
};
|
|
|
|
|
2020-03-12 03:10:09 +01:00
|
|
|
HRESULT sample_grabber_create(IUnknown *outer, IUnknown **out)
|
2010-02-04 01:02:59 +01:00
|
|
|
{
|
2020-03-31 00:55:12 +02:00
|
|
|
struct sample_grabber *object;
|
2010-02-04 01:02:59 +01:00
|
|
|
|
2020-03-31 00:55:11 +02:00
|
|
|
if (!(object = calloc(1, sizeof(*object))))
|
2010-02-04 01:02:59 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2020-03-31 00:55:11 +02:00
|
|
|
strmbase_filter_init(&object->filter, outer, &CLSID_SampleGrabber, &filter_ops);
|
|
|
|
object->ISampleGrabber_iface.lpVtbl = &ISampleGrabber_VTable;
|
|
|
|
object->IMemInputPin_iface.lpVtbl = &IMemInputPin_VTable;
|
2019-11-20 03:18:00 +01:00
|
|
|
|
2020-03-31 00:55:11 +02:00
|
|
|
strmbase_sink_init(&object->sink, &object->filter, L"In", &sink_ops, NULL);
|
2020-03-28 18:02:06 +01:00
|
|
|
|
2020-03-31 00:55:11 +02:00
|
|
|
strmbase_source_init(&object->source, &object->filter, L"Out", &source_ops);
|
|
|
|
strmbase_passthrough_init(&object->passthrough, (IUnknown *)&object->source.pin.IPin_iface);
|
|
|
|
ISeekingPassThru_Init(&object->passthrough.ISeekingPassThru_iface, FALSE,
|
|
|
|
&object->sink.pin.IPin_iface);
|
2019-11-20 03:18:00 +01:00
|
|
|
|
2020-03-31 00:55:11 +02:00
|
|
|
object->grabberMethod = -1;
|
|
|
|
object->oneShot = OneShot_None;
|
|
|
|
object->bufferLen = -1;
|
2010-02-04 01:02:59 +01:00
|
|
|
|
2020-03-31 00:55:11 +02:00
|
|
|
TRACE("Created sample grabber %p.\n", object);
|
|
|
|
*out = &object->filter.IUnknown_inner;
|
2010-02-04 01:02:59 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|