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"
|
2014-02-20 00:13:09 +01:00
|
|
|
#include "wine/strmbase.h"
|
2010-02-04 01:02:59 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(qedit);
|
|
|
|
|
|
|
|
/* Sample Grabber filter implementation */
|
|
|
|
typedef struct _SG_Impl {
|
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;
|
2013-02-26 14:09:42 +01:00
|
|
|
/* IMediaSeeking and IMediaPosition are implemented by ISeekingPassThru */
|
2019-11-20 03:18:00 +01:00
|
|
|
IUnknown *seekthru_unk;
|
|
|
|
|
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;
|
2010-02-04 01:02:59 +01:00
|
|
|
} SG_Impl;
|
|
|
|
|
2010-02-12 20:09:02 +01:00
|
|
|
enum {
|
|
|
|
OneShot_None,
|
|
|
|
OneShot_Wait,
|
|
|
|
OneShot_Past,
|
|
|
|
};
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static inline SG_Impl *impl_from_strmbase_filter(struct strmbase_filter *iface)
|
2014-02-20 21:30:48 +01:00
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, SG_Impl, filter);
|
|
|
|
}
|
|
|
|
|
2010-02-04 01:02:59 +01:00
|
|
|
static inline SG_Impl *impl_from_ISampleGrabber(ISampleGrabber *iface)
|
|
|
|
{
|
2012-06-26 23:50:54 +02:00
|
|
|
return CONTAINING_RECORD(iface, SG_Impl, ISampleGrabber_iface);
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
2010-02-12 20:09:02 +01:00
|
|
|
static inline SG_Impl *impl_from_IMemInputPin(IMemInputPin *iface)
|
|
|
|
{
|
2012-06-26 23:50:54 +02:00
|
|
|
return CONTAINING_RECORD(iface, SG_Impl, IMemInputPin_iface);
|
2010-02-12 20:09:02 +01:00
|
|
|
}
|
|
|
|
|
2010-02-04 01:02:59 +01:00
|
|
|
|
|
|
|
/* Cleanup at end of life */
|
|
|
|
static void SampleGrabber_cleanup(SG_Impl *This)
|
|
|
|
{
|
|
|
|
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);
|
2013-02-26 14:09:42 +01:00
|
|
|
if(This->seekthru_unk)
|
|
|
|
IUnknown_Release(This->seekthru_unk);
|
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
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
SG_Impl *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
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
SG_Impl *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);
|
2019-06-05 00:54:26 +02:00
|
|
|
strmbase_filter_cleanup(&filter->filter);
|
|
|
|
CoTaskMemFree(filter);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
SG_Impl *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 */
|
2010-02-12 20:09:02 +01:00
|
|
|
static void SampleGrabber_callback(SG_Impl *This, IMediaSample *sample)
|
|
|
|
{
|
|
|
|
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;
|
2014-02-20 00:13:09 +01:00
|
|
|
EnterCriticalSection(&This->filter.csFilter);
|
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);
|
2014-02-20 00:13:09 +01:00
|
|
|
LeaveCriticalSection(&This->filter.csFilter);
|
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)
|
|
|
|
{
|
|
|
|
ERR("(%p) Callback referenced sample %p by %u\n", This, sample, ref);
|
|
|
|
/* 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:
|
2010-05-11 10:34:43 +02:00
|
|
|
FIXME("unsupported method %d\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
|
|
|
{
|
2012-06-26 23:50:54 +02:00
|
|
|
SG_Impl *This = impl_from_ISampleGrabber(iface);
|
2019-06-05 00:54:26 +02:00
|
|
|
return IUnknown_QueryInterface(This->filter.outer_unk, riid, ppv);
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IUnknown */
|
|
|
|
static ULONG WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_AddRef(ISampleGrabber *iface)
|
|
|
|
{
|
2012-06-26 23:50:54 +02:00
|
|
|
SG_Impl *This = impl_from_ISampleGrabber(iface);
|
2019-06-05 00:54:26 +02:00
|
|
|
return IUnknown_AddRef(This->filter.outer_unk);
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IUnknown */
|
|
|
|
static ULONG WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_Release(ISampleGrabber *iface)
|
|
|
|
{
|
2012-06-26 23:50:54 +02:00
|
|
|
SG_Impl *This = impl_from_ISampleGrabber(iface);
|
2019-06-05 00:54:26 +02:00
|
|
|
return IUnknown_Release(This->filter.outer_unk);
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ISampleGrabber */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_SetOneShot(ISampleGrabber *iface, BOOL oneShot)
|
|
|
|
{
|
|
|
|
SG_Impl *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-02-06 23:49:14 +01:00
|
|
|
SG_Impl *filter = impl_from_ISampleGrabber(iface);
|
|
|
|
|
|
|
|
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-02-06 23:49:14 +01:00
|
|
|
SG_Impl *filter = impl_from_ISampleGrabber(iface);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2010-03-12 13:15:51 +01:00
|
|
|
SG_Impl *This = impl_from_ISampleGrabber(iface);
|
|
|
|
TRACE("(%p)->(%u)\n", This, bufferEm);
|
2014-02-20 00:13:09 +01:00
|
|
|
EnterCriticalSection(&This->filter.csFilter);
|
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;
|
2014-02-20 00:13:09 +01:00
|
|
|
LeaveCriticalSection(&This->filter.csFilter);
|
2010-02-04 01:02:59 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ISampleGrabber */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_GetCurrentBuffer(ISampleGrabber *iface, LONG *bufSize, LONG *buffer)
|
|
|
|
{
|
2010-03-12 13:15:51 +01:00
|
|
|
SG_Impl *This = impl_from_ISampleGrabber(iface);
|
|
|
|
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;
|
2014-02-20 00:13:09 +01:00
|
|
|
EnterCriticalSection(&This->filter.csFilter);
|
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;
|
|
|
|
}
|
2014-02-20 00:13:09 +01:00
|
|
|
LeaveCriticalSection(&This->filter.csFilter);
|
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)
|
|
|
|
{
|
|
|
|
SG_Impl *This = impl_from_ISampleGrabber(iface);
|
2010-02-12 20:09:02 +01:00
|
|
|
TRACE("(%p)->(%p, %u)\n", This, cb, whichMethod);
|
|
|
|
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
|
|
|
{
|
2019-05-17 07:31:04 +02:00
|
|
|
SG_Impl *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
|
|
|
{
|
2019-05-17 07:31:04 +02:00
|
|
|
SG_Impl *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
|
|
|
{
|
2019-05-17 07:31:04 +02:00
|
|
|
SG_Impl *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)
|
|
|
|
{
|
|
|
|
SG_Impl *This = impl_from_IMemInputPin(iface);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
SG_Impl *This = impl_from_IMemInputPin(iface);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
SG_Impl *This = impl_from_IMemInputPin(iface);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
SG_Impl *This = impl_from_IMemInputPin(iface);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
SG_Impl *This = impl_from_IMemInputPin(iface);
|
2010-03-12 13:15:51 +01:00
|
|
|
LONG idx;
|
2019-12-16 01:21:15 +01:00
|
|
|
TRACE("(%p)->(%p, %u, %p) output = %p, grabber = %p\n", This, samples, nSamples, nProcessed, This->source.pMemInputPin, This->grabberIface);
|
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)
|
|
|
|
{
|
|
|
|
SG_Impl *This = impl_from_IMemInputPin(iface);
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2019-11-20 03:18:03 +01:00
|
|
|
static inline SG_Impl *impl_from_sink_pin(struct strmbase_pin *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, SG_Impl, sink.pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT sample_grabber_sink_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
|
|
|
|
{
|
|
|
|
SG_Impl *filter = impl_from_sink_pin(iface);
|
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_IMemInputPin))
|
|
|
|
*out = &filter->IMemInputPin_iface;
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-06 03:04:36 +01:00
|
|
|
static BOOL check_filter_mt(SG_Impl *filter, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
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-06 03:04:36 +01:00
|
|
|
SG_Impl *filter = impl_from_sink_pin(iface);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
SG_Impl *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
|
|
|
};
|
|
|
|
|
2019-11-20 03:18:00 +01:00
|
|
|
static inline SG_Impl *impl_from_source_pin(struct strmbase_pin *iface)
|
2019-04-16 06:20:49 +02:00
|
|
|
{
|
2019-11-20 03:18:00 +01:00
|
|
|
return CONTAINING_RECORD(iface, SG_Impl, source.pin);
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
SG_Impl *filter = impl_from_source_pin(iface);
|
2019-04-16 06:20:49 +02:00
|
|
|
|
2019-11-20 03:18:00 +01:00
|
|
|
if (IsEqualGUID(iid, &IID_IMediaPosition) || IsEqualGUID(iid, &IID_IMediaSeeking))
|
|
|
|
return IUnknown_QueryInterface(filter->seekthru_unk, iid, out);
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT sample_grabber_source_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-02-08 06:51:53 +01:00
|
|
|
SG_Impl *filter = impl_from_source_pin(iface);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
SG_Impl *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-02-08 06:51:56 +01:00
|
|
|
SG_Impl *filter = impl_from_source_pin(&iface->pin);
|
|
|
|
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)))
|
|
|
|
{
|
|
|
|
ERR("Failed to get IFilterGraph2 interface, hr %#x.\n", hr);
|
|
|
|
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
|
|
|
{
|
|
|
|
SG_Impl* obj = NULL;
|
2013-02-26 14:09:42 +01:00
|
|
|
ISeekingPassThru *passthru;
|
|
|
|
HRESULT hr;
|
2010-02-04 01:02:59 +01:00
|
|
|
|
|
|
|
obj = CoTaskMemAlloc(sizeof(SG_Impl));
|
|
|
|
if (NULL == obj) {
|
2019-06-05 00:54:26 +02:00
|
|
|
*out = NULL;
|
2010-02-04 01:02:59 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
ZeroMemory(obj, sizeof(SG_Impl));
|
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
strmbase_filter_init(&obj->filter, outer, &CLSID_SampleGrabber, &filter_ops);
|
2012-06-26 23:50:54 +02:00
|
|
|
obj->ISampleGrabber_iface.lpVtbl = &ISampleGrabber_VTable;
|
|
|
|
obj->IMemInputPin_iface.lpVtbl = &IMemInputPin_VTable;
|
2019-11-20 03:18:00 +01:00
|
|
|
|
2019-12-13 04:24:39 +01:00
|
|
|
strmbase_sink_init(&obj->sink, &obj->filter, L"In", &sink_ops, NULL);
|
2019-12-08 05:20:38 +01:00
|
|
|
strmbase_source_init(&obj->source, &obj->filter, L"Out", &source_ops);
|
2019-11-20 03:18:00 +01:00
|
|
|
|
2010-02-04 01:02:59 +01:00
|
|
|
obj->allocator = NULL;
|
2010-02-12 20:09:02 +01:00
|
|
|
obj->grabberIface = NULL;
|
|
|
|
obj->grabberMethod = -1;
|
|
|
|
obj->oneShot = OneShot_None;
|
2010-03-12 13:15:51 +01:00
|
|
|
obj->bufferLen = -1;
|
|
|
|
obj->bufferData = NULL;
|
2010-02-04 01:02:59 +01:00
|
|
|
|
2019-06-05 00:54:26 +02:00
|
|
|
hr = CoCreateInstance(&CLSID_SeekingPassThru, &obj->filter.IUnknown_inner,
|
|
|
|
CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&obj->seekthru_unk);
|
2013-02-26 14:09:42 +01:00
|
|
|
if(hr)
|
|
|
|
return hr;
|
|
|
|
IUnknown_QueryInterface(obj->seekthru_unk, &IID_ISeekingPassThru, (void**)&passthru);
|
2019-11-20 03:18:03 +01:00
|
|
|
ISeekingPassThru_Init(passthru, FALSE, &obj->sink.pin.IPin_iface);
|
2013-02-26 14:09:42 +01:00
|
|
|
ISeekingPassThru_Release(passthru);
|
|
|
|
|
2019-06-05 00:54:26 +02:00
|
|
|
*out = &obj->filter.IUnknown_inner;
|
2010-02-04 01:02:59 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|