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;
|
|
|
|
IMemInputPin *memOutput;
|
|
|
|
|
2019-11-20 03:18:03 +01:00
|
|
|
struct strmbase_sink sink;
|
2019-11-20 03:18:00 +01:00
|
|
|
AM_MEDIA_TYPE mtype;
|
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);
|
2014-02-20 00:13:09 +01:00
|
|
|
if (This->filter.filterInfo.pGraph)
|
|
|
|
WARN("(%p) still joined to filter graph %p\n", This, This->filter.filterInfo.pGraph);
|
2010-02-04 01:02:59 +01:00
|
|
|
if (This->allocator)
|
|
|
|
IMemAllocator_Release(This->allocator);
|
2010-02-12 20:09:02 +01:00
|
|
|
if (This->memOutput)
|
|
|
|
IMemInputPin_Release(This->memOutput);
|
|
|
|
if (This->grabberIface)
|
|
|
|
ISampleGrabberCB_Release(This->grabberIface);
|
2016-07-08 10:11:54 +02:00
|
|
|
CoTaskMemFree(This->mtype.pbFormat);
|
|
|
|
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);
|
|
|
|
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 */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_SetMediaType(ISampleGrabber *iface, const AM_MEDIA_TYPE *type)
|
|
|
|
{
|
|
|
|
SG_Impl *This = impl_from_ISampleGrabber(iface);
|
2010-02-12 20:10:34 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, type);
|
2010-02-04 01:02:59 +01:00
|
|
|
if (!type)
|
|
|
|
return E_POINTER;
|
2010-02-12 20:10:34 +01:00
|
|
|
TRACE("Media type: %s/%s ssize: %u format: %s (%u bytes)\n",
|
|
|
|
debugstr_guid(&type->majortype), debugstr_guid(&type->subtype),
|
|
|
|
type->lSampleSize,
|
|
|
|
debugstr_guid(&type->formattype), type->cbFormat);
|
2016-07-08 10:11:54 +02:00
|
|
|
CoTaskMemFree(This->mtype.pbFormat);
|
2010-02-12 20:10:34 +01:00
|
|
|
This->mtype = *type;
|
|
|
|
This->mtype.pUnk = NULL;
|
|
|
|
if (type->cbFormat) {
|
|
|
|
This->mtype.pbFormat = CoTaskMemAlloc(type->cbFormat);
|
|
|
|
CopyMemory(This->mtype.pbFormat, type->pbFormat, type->cbFormat);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
This->mtype.pbFormat = NULL;
|
|
|
|
return S_OK;
|
2010-02-04 01:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ISampleGrabber */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_ISampleGrabber_GetConnectedMediaType(ISampleGrabber *iface, AM_MEDIA_TYPE *type)
|
|
|
|
{
|
|
|
|
SG_Impl *This = impl_from_ISampleGrabber(iface);
|
2010-02-12 20:10:34 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, type);
|
2010-02-04 01:02:59 +01:00
|
|
|
if (!type)
|
|
|
|
return E_POINTER;
|
2019-11-20 03:18:03 +01:00
|
|
|
if (!This->sink.pin.peer)
|
2010-02-12 20:10:34 +01:00
|
|
|
return VFW_E_NOT_CONNECTED;
|
|
|
|
*type = This->mtype;
|
|
|
|
if (type->cbFormat) {
|
|
|
|
type->pbFormat = CoTaskMemAlloc(type->cbFormat);
|
|
|
|
CopyMemory(type->pbFormat, This->mtype.pbFormat, type->cbFormat);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
return This->memOutput ? IMemInputPin_GetAllocatorRequirements(This->memOutput, props) : E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IMemInputPin */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_IMemInputPin_Receive(IMemInputPin *iface, IMediaSample *sample)
|
|
|
|
{
|
|
|
|
SG_Impl *This = impl_from_IMemInputPin(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
TRACE("(%p)->(%p) output = %p, grabber = %p\n", This, sample, This->memOutput, This->grabberIface);
|
|
|
|
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);
|
2010-02-12 20:09:02 +01:00
|
|
|
hr = This->memOutput ? IMemInputPin_Receive(This->memOutput, sample) : S_OK;
|
|
|
|
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;
|
2010-02-12 20:09:02 +01:00
|
|
|
TRACE("(%p)->(%p, %u, %p) output = %p, grabber = %p\n", This, samples, nSamples, nProcessed, This->memOutput, This->grabberIface);
|
|
|
|
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]);
|
2010-02-12 20:09:02 +01:00
|
|
|
return This->memOutput ? IMemInputPin_ReceiveMultiple(This->memOutput, samples, nSamples, nProcessed) : S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IMemInputPin */
|
|
|
|
static HRESULT WINAPI
|
|
|
|
SampleGrabber_IMemInputPin_ReceiveCanBlock(IMemInputPin *iface)
|
|
|
|
{
|
|
|
|
SG_Impl *This = impl_from_IMemInputPin(iface);
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
return This->memOutput ? IMemInputPin_ReceiveCanBlock(This->memOutput) : S_OK;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT sample_grabber_sink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!index)
|
|
|
|
{
|
|
|
|
CopyMediaType(mt, &filter->mtype);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
|
|
|
}
|
|
|
|
|
2019-12-11 04:53:37 +01:00
|
|
|
static HRESULT sample_grabber_sink_connect(struct strmbase_sink *iface,
|
|
|
|
IPin *peer, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
SG_Impl *filter = impl_from_sink_pin(&iface->pin);
|
|
|
|
|
|
|
|
if (!IsEqualGUID(&mt->formattype, &FORMAT_None)
|
|
|
|
&& !IsEqualGUID(&mt->formattype, &GUID_NULL) && !mt->pbFormat)
|
|
|
|
return VFW_E_INVALIDMEDIATYPE;
|
|
|
|
|
|
|
|
if (!IsEqualGUID(&filter->mtype.majortype, &GUID_NULL)
|
|
|
|
&& !IsEqualGUID(&filter->mtype.majortype, &mt->majortype))
|
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
|
|
|
|
|
|
|
if (!IsEqualGUID(&filter->mtype.subtype,&MEDIASUBTYPE_None)
|
|
|
|
&& !IsEqualGUID(&filter->mtype.subtype, &mt->subtype))
|
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
|
|
|
|
|
|
|
if (!IsEqualGUID(&filter->mtype.formattype, &GUID_NULL)
|
|
|
|
&& !IsEqualGUID(&filter->mtype.formattype, &FORMAT_None)
|
|
|
|
&& !IsEqualGUID(&filter->mtype.formattype, &mt->formattype))
|
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
|
|
|
|
|
|
|
FreeMediaType(&filter->mtype);
|
|
|
|
CopyMediaType(&filter->mtype, mt);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-20 03:18:03 +01:00
|
|
|
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,
|
2019-12-11 04:53:37 +01:00
|
|
|
.sink_connect = sample_grabber_sink_connect,
|
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)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!index)
|
2019-04-16 06:20:49 +02:00
|
|
|
{
|
2019-11-20 03:18:00 +01:00
|
|
|
CopyMediaType(mt, &filter->mtype);
|
|
|
|
return S_OK;
|
2019-04-16 06:20:49 +02:00
|
|
|
}
|
2019-11-20 03:18:00 +01:00
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI sample_grabber_source_AttemptConnection(struct strmbase_source *iface,
|
|
|
|
IPin *peer, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
SG_Impl *filter = impl_from_source_pin(&iface->pin);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (filter->source.pin.peer)
|
|
|
|
return VFW_E_ALREADY_CONNECTED;
|
|
|
|
if (filter->filter.state != State_Stopped)
|
|
|
|
return VFW_E_NOT_STOPPED;
|
|
|
|
if (!IsEqualGUID(&mt->majortype, &filter->mtype.majortype))
|
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
|
|
|
if (!IsEqualGUID(&mt->subtype, &filter->mtype.subtype))
|
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
|
|
|
if (!IsEqualGUID(&mt->formattype, &FORMAT_None)
|
|
|
|
&& !IsEqualGUID(&mt->formattype, &GUID_NULL)
|
|
|
|
&& !IsEqualGUID(&mt->formattype, &filter->mtype.majortype))
|
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
|
|
|
if (!IsEqualGUID(&mt->formattype, &FORMAT_None)
|
|
|
|
&& !IsEqualGUID(&mt->formattype, &GUID_NULL)
|
|
|
|
&& !mt->pbFormat)
|
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
|
|
|
|
|
|
|
IPin_AddRef(filter->source.pin.peer = peer);
|
|
|
|
CopyMediaType(&filter->source.pin.mt, mt);
|
|
|
|
if (SUCCEEDED(hr = IPin_ReceiveConnection(peer, &filter->source.pin.IPin_iface, mt)))
|
|
|
|
hr = IPin_QueryInterface(peer, &IID_IMemInputPin, (void **)&filter->source.pMemInputPin);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
2019-04-16 06:20:49 +02:00
|
|
|
{
|
2019-11-20 03:18:00 +01:00
|
|
|
IPin_Release(filter->source.pin.peer);
|
|
|
|
filter->source.pin.peer = NULL;
|
|
|
|
FreeMediaType(&filter->source.pin.mt);
|
2019-04-16 06:20:49 +02:00
|
|
|
}
|
|
|
|
|
2019-11-20 03:18:00 +01:00
|
|
|
return hr;
|
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,
|
|
|
|
.pfnAttemptConnection = sample_grabber_source_AttemptConnection,
|
|
|
|
};
|
|
|
|
|
2019-06-05 00:54:26 +02:00
|
|
|
HRESULT SampleGrabber_create(IUnknown *outer, void **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-12 20:10:34 +01:00
|
|
|
obj->mtype.majortype = GUID_NULL;
|
|
|
|
obj->mtype.subtype = MEDIASUBTYPE_None;
|
|
|
|
obj->mtype.formattype = FORMAT_None;
|
2010-02-04 01:02:59 +01:00
|
|
|
obj->allocator = NULL;
|
2010-02-12 20:09:02 +01:00
|
|
|
obj->memOutput = NULL;
|
|
|
|
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;
|
|
|
|
}
|