2008-02-13 23:12:17 +01:00
|
|
|
/* DirectShow Media Detector object (QEDIT.DLL)
|
|
|
|
*
|
2008-04-10 01:01:30 +02:00
|
|
|
* Copyright 2008 Google (Lei Zhang, Dan Hipschman)
|
2008-02-13 23:12:17 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2008-04-10 01:01:30 +02:00
|
|
|
#include <assert.h>
|
2008-04-09 01:52:50 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
|
2008-02-13 23:12:17 +01:00
|
|
|
#include "qedit_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(qedit);
|
|
|
|
|
|
|
|
typedef struct MediaDetImpl {
|
2012-07-01 00:06:15 +02:00
|
|
|
IUnknown IUnknown_inner;
|
2010-12-08 22:59:33 +01:00
|
|
|
IMediaDet IMediaDet_iface;
|
2012-07-01 00:06:15 +02:00
|
|
|
IUnknown *outer_unk;
|
|
|
|
LONG ref;
|
2008-04-09 01:52:14 +02:00
|
|
|
IGraphBuilder *graph;
|
|
|
|
IBaseFilter *source;
|
2008-04-09 01:53:52 +02:00
|
|
|
IBaseFilter *splitter;
|
2020-04-23 21:45:44 +02:00
|
|
|
WCHAR *filename;
|
2010-05-11 10:34:43 +02:00
|
|
|
LONG num_streams;
|
|
|
|
LONG cur_stream;
|
2008-04-10 01:01:30 +02:00
|
|
|
IPin *cur_pin;
|
2008-02-13 23:12:17 +01:00
|
|
|
} MediaDetImpl;
|
|
|
|
|
2012-07-01 00:06:15 +02:00
|
|
|
static inline MediaDetImpl *impl_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, MediaDetImpl, IUnknown_inner);
|
|
|
|
}
|
|
|
|
|
2010-12-08 22:59:33 +01:00
|
|
|
static inline MediaDetImpl *impl_from_IMediaDet(IMediaDet *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, MediaDetImpl, IMediaDet_iface);
|
|
|
|
}
|
|
|
|
|
2008-04-09 01:52:14 +02:00
|
|
|
static void MD_cleanup(MediaDetImpl *This)
|
|
|
|
{
|
2008-04-10 01:01:30 +02:00
|
|
|
if (This->cur_pin) IPin_Release(This->cur_pin);
|
|
|
|
This->cur_pin = NULL;
|
2008-04-09 01:52:14 +02:00
|
|
|
if (This->source) IBaseFilter_Release(This->source);
|
|
|
|
This->source = NULL;
|
2008-04-09 01:53:52 +02:00
|
|
|
if (This->splitter) IBaseFilter_Release(This->splitter);
|
|
|
|
This->splitter = NULL;
|
2008-04-09 01:52:14 +02:00
|
|
|
if (This->graph) IGraphBuilder_Release(This->graph);
|
|
|
|
This->graph = NULL;
|
2020-04-23 21:45:44 +02:00
|
|
|
if (This->filename)
|
|
|
|
free(This->filename);
|
|
|
|
This->filename = NULL;
|
2008-04-09 01:55:37 +02:00
|
|
|
This->num_streams = -1;
|
|
|
|
This->cur_stream = 0;
|
2008-04-09 01:52:14 +02:00
|
|
|
}
|
|
|
|
|
2020-04-23 21:45:40 +02:00
|
|
|
static HRESULT get_filter_info(IMoniker *moniker, GUID *clsid, VARIANT *var)
|
|
|
|
{
|
|
|
|
IPropertyBag *prop_bag;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (FAILED(hr = IMoniker_BindToStorage(moniker, NULL, NULL, &IID_IPropertyBag, (void **)&prop_bag)))
|
|
|
|
{
|
|
|
|
ERR("Failed to get property bag, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantInit(var);
|
|
|
|
V_VT(var) = VT_BSTR;
|
|
|
|
if (FAILED(hr = IPropertyBag_Read(prop_bag, L"CLSID", var, NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to get CLSID, hr %#x.\n", hr);
|
|
|
|
IPropertyBag_Release(prop_bag);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
CLSIDFromString(V_BSTR(var), clsid);
|
|
|
|
VariantClear(var);
|
|
|
|
|
|
|
|
if (FAILED(hr = IPropertyBag_Read(prop_bag, L"FriendlyName", var, NULL)))
|
|
|
|
ERR("Failed to get name, hr %#x.\n", hr);
|
|
|
|
|
|
|
|
IPropertyBag_Release(prop_bag);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-04-27 21:14:03 +02:00
|
|
|
static HRESULT get_pin_media_type(IPin *pin, AM_MEDIA_TYPE *out)
|
|
|
|
{
|
|
|
|
IEnumMediaTypes *enummt;
|
|
|
|
AM_MEDIA_TYPE *pmt;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (FAILED(hr = IPin_EnumMediaTypes(pin, &enummt)))
|
|
|
|
return hr;
|
|
|
|
hr = IEnumMediaTypes_Next(enummt, 1, &pmt, NULL);
|
|
|
|
IEnumMediaTypes_Release(enummt);
|
|
|
|
if (hr != S_OK)
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
*out = *pmt;
|
|
|
|
CoTaskMemFree(pmt);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:45:41 +02:00
|
|
|
static HRESULT find_splitter(MediaDetImpl *detector)
|
|
|
|
{
|
|
|
|
IPin *source_pin, *splitter_pin;
|
|
|
|
IEnumMoniker *enum_moniker;
|
|
|
|
IFilterMapper2 *mapper;
|
|
|
|
IBaseFilter *splitter;
|
|
|
|
IEnumPins *enum_pins;
|
|
|
|
AM_MEDIA_TYPE mt;
|
|
|
|
IMoniker *mon;
|
|
|
|
GUID type[2];
|
|
|
|
VARIANT var;
|
|
|
|
HRESULT hr;
|
|
|
|
GUID clsid;
|
|
|
|
|
|
|
|
if (FAILED(hr = IBaseFilter_EnumPins(detector->source, &enum_pins)))
|
|
|
|
{
|
|
|
|
ERR("Failed to enumerate source pins, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
hr = IEnumPins_Next(enum_pins, 1, &source_pin, NULL);
|
|
|
|
IEnumPins_Release(enum_pins);
|
2020-04-27 15:07:42 +02:00
|
|
|
if (hr != S_OK)
|
2020-04-23 21:45:41 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to get source pin, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-04-27 21:14:04 +02:00
|
|
|
if (FAILED(hr = get_pin_media_type(source_pin, &mt)))
|
|
|
|
{
|
|
|
|
ERR("Failed to get media type, hr %#x.\n", hr);
|
|
|
|
IPin_Release(source_pin);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
type[0] = mt.majortype;
|
|
|
|
type[1] = mt.subtype;
|
|
|
|
FreeMediaType(&mt);
|
|
|
|
|
2020-04-23 21:45:41 +02:00
|
|
|
if (FAILED(hr = CoCreateInstance(&CLSID_FilterMapper2, NULL,
|
|
|
|
CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (void **)&mapper)))
|
|
|
|
{
|
|
|
|
IPin_Release(source_pin);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IFilterMapper2_EnumMatchingFilters(mapper, &enum_moniker, 0, TRUE,
|
|
|
|
MERIT_UNLIKELY, FALSE, 1, type, NULL, NULL, FALSE, TRUE, 0, NULL, NULL, NULL);
|
|
|
|
IFilterMapper2_Release(mapper);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IPin_Release(source_pin);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = E_NOINTERFACE;
|
|
|
|
while (IEnumMoniker_Next(enum_moniker, 1, &mon, NULL) == S_OK)
|
|
|
|
{
|
|
|
|
hr = get_filter_info(mon, &clsid, &var);
|
|
|
|
IMoniker_Release(mon);
|
|
|
|
if (FAILED(hr))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IBaseFilter, (void **)&splitter);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
VariantClear(&var);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IGraphBuilder_AddFilter(detector->graph, splitter, V_BSTR(&var));
|
|
|
|
VariantClear(&var);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IBaseFilter_Release(splitter);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IBaseFilter_EnumPins(splitter, &enum_pins);
|
|
|
|
if (FAILED(hr))
|
2020-04-23 21:45:45 +02:00
|
|
|
goto next;
|
|
|
|
|
2020-04-23 21:45:41 +02:00
|
|
|
hr = IEnumPins_Next(enum_pins, 1, &splitter_pin, NULL);
|
|
|
|
IEnumPins_Release(enum_pins);
|
2020-04-27 15:07:41 +02:00
|
|
|
if (hr != S_OK)
|
2020-04-23 21:45:45 +02:00
|
|
|
goto next;
|
2020-04-23 21:45:41 +02:00
|
|
|
|
|
|
|
hr = IPin_Connect(source_pin, splitter_pin, NULL);
|
|
|
|
IPin_Release(splitter_pin);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
detector->splitter = splitter;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:45:45 +02:00
|
|
|
next:
|
|
|
|
IGraphBuilder_RemoveFilter(detector->graph, splitter);
|
2020-04-23 21:45:41 +02:00
|
|
|
IBaseFilter_Release(splitter);
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumMoniker_Release(enum_moniker);
|
|
|
|
IPin_Release(source_pin);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-07-01 00:06:15 +02:00
|
|
|
/* MediaDet inner IUnknown */
|
|
|
|
static HRESULT WINAPI MediaDet_inner_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2012-07-01 00:06:15 +02:00
|
|
|
MediaDetImpl *This = impl_from_IUnknown(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
*ppv = &This->IUnknown_inner;
|
2013-02-06 23:13:12 +01:00
|
|
|
else if (IsEqualIID(riid, &IID_IMediaDet))
|
2012-07-01 00:06:15 +02:00
|
|
|
*ppv = &This->IMediaDet_iface;
|
|
|
|
else
|
|
|
|
WARN("(%p, %s,%p): not found\n", This, debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if (!*ppv)
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
2012-07-01 00:06:15 +02:00
|
|
|
static ULONG WINAPI MediaDet_inner_AddRef(IUnknown *iface)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2012-07-01 00:06:15 +02:00
|
|
|
MediaDetImpl *This = impl_from_IUnknown(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) new ref = %u\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MediaDet_inner_Release(IUnknown *iface)
|
|
|
|
{
|
|
|
|
MediaDetImpl *This = impl_from_IUnknown(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) new ref = %u\n", This, ref);
|
2008-02-13 23:12:17 +01:00
|
|
|
|
2012-07-01 00:06:15 +02:00
|
|
|
if (ref == 0)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2008-04-09 01:52:14 +02:00
|
|
|
MD_cleanup(This);
|
2008-02-13 23:12:17 +01:00
|
|
|
CoTaskMemFree(This);
|
|
|
|
}
|
|
|
|
|
2012-07-01 00:06:15 +02:00
|
|
|
return ref;
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
2012-07-01 00:06:15 +02:00
|
|
|
static const IUnknownVtbl mediadet_vtbl =
|
|
|
|
{
|
|
|
|
MediaDet_inner_QueryInterface,
|
|
|
|
MediaDet_inner_AddRef,
|
|
|
|
MediaDet_inner_Release,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* IMediaDet implementation */
|
|
|
|
static HRESULT WINAPI MediaDet_QueryInterface(IMediaDet *iface, REFIID riid, void **ppv)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2012-07-01 00:06:15 +02:00
|
|
|
return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
|
|
|
|
}
|
2008-02-13 23:12:17 +01:00
|
|
|
|
2012-07-01 00:06:15 +02:00
|
|
|
static ULONG WINAPI MediaDet_AddRef(IMediaDet *iface)
|
|
|
|
{
|
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
|
|
|
return IUnknown_AddRef(This->outer_unk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MediaDet_Release(IMediaDet *iface)
|
|
|
|
{
|
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
|
|
|
return IUnknown_Release(This->outer_unk);
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
2020-04-17 22:02:08 +02:00
|
|
|
static HRESULT WINAPI MediaDet_get_Filter(IMediaDet *iface, IUnknown **filter)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2020-04-17 22:02:08 +02:00
|
|
|
MediaDetImpl *detector = impl_from_IMediaDet(iface);
|
|
|
|
|
|
|
|
TRACE("detector %p, filter %p.\n", detector, filter);
|
|
|
|
|
|
|
|
if (!filter)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*filter = (IUnknown *)detector->source;
|
|
|
|
if (*filter)
|
|
|
|
IUnknown_AddRef(*filter);
|
|
|
|
else
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
return S_OK;
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
2020-04-23 21:45:42 +02:00
|
|
|
static HRESULT WINAPI MediaDet_put_Filter(IMediaDet *iface, IUnknown *unk)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2020-04-23 21:45:42 +02:00
|
|
|
MediaDetImpl *detector = impl_from_IMediaDet(iface);
|
|
|
|
IGraphBuilder *graph;
|
|
|
|
IBaseFilter *filter;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("detector %p, unk %p.\n", detector, unk);
|
|
|
|
|
|
|
|
if (!unk)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (FAILED(hr = IUnknown_QueryInterface(unk, &IID_IBaseFilter, (void **)&filter)))
|
|
|
|
{
|
|
|
|
WARN("Object does not expose IBaseFilter.\n");
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detector->graph)
|
|
|
|
MD_cleanup(detector);
|
|
|
|
|
|
|
|
if (FAILED(hr = CoCreateInstance(&CLSID_FilterGraph, NULL,
|
|
|
|
CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (void **)&graph)))
|
|
|
|
{
|
|
|
|
IBaseFilter_Release(filter);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr = IGraphBuilder_AddFilter(graph, filter, L"Source")))
|
|
|
|
{
|
|
|
|
IGraphBuilder_Release(graph);
|
|
|
|
IBaseFilter_Release(filter);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
detector->graph = graph;
|
|
|
|
detector->source = filter;
|
|
|
|
if (FAILED(find_splitter(detector)))
|
|
|
|
{
|
|
|
|
detector->splitter = detector->source;
|
|
|
|
IBaseFilter_AddRef(detector->splitter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IMediaDet_put_CurrentStream(&detector->IMediaDet_iface, 0);
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
2009-03-12 01:42:24 +01:00
|
|
|
static HRESULT WINAPI MediaDet_get_OutputStreams(IMediaDet* iface, LONG *pVal)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2008-04-09 01:53:52 +02:00
|
|
|
IEnumPins *pins;
|
|
|
|
IPin *pin;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if (!This->splitter)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-04-09 01:55:37 +02:00
|
|
|
if (This->num_streams != -1)
|
|
|
|
{
|
|
|
|
*pVal = This->num_streams;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-09 01:53:52 +02:00
|
|
|
*pVal = 0;
|
|
|
|
|
|
|
|
hr = IBaseFilter_EnumPins(This->splitter, &pins);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK)
|
|
|
|
{
|
|
|
|
PIN_DIRECTION dir;
|
|
|
|
hr = IPin_QueryDirection(pin, &dir);
|
|
|
|
IPin_Release(pin);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IEnumPins_Release(pins);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dir == PINDIR_OUTPUT)
|
|
|
|
++*pVal;
|
|
|
|
}
|
|
|
|
IEnumPins_Release(pins);
|
|
|
|
|
2008-04-09 01:55:37 +02:00
|
|
|
This->num_streams = *pVal;
|
2008-04-09 01:53:52 +02:00
|
|
|
return S_OK;
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
2009-03-12 01:42:24 +01:00
|
|
|
static HRESULT WINAPI MediaDet_get_CurrentStream(IMediaDet* iface, LONG *pVal)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2008-04-09 01:55:37 +02:00
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if (!pVal)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*pVal = This->cur_stream;
|
|
|
|
return S_OK;
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
2010-05-11 10:34:43 +02:00
|
|
|
static HRESULT SetCurPin(MediaDetImpl *This, LONG strm)
|
2008-04-10 01:01:30 +02:00
|
|
|
{
|
|
|
|
IEnumPins *pins;
|
|
|
|
IPin *pin;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
assert(This->splitter);
|
|
|
|
assert(0 <= strm && strm < This->num_streams);
|
|
|
|
|
|
|
|
if (This->cur_pin)
|
|
|
|
{
|
|
|
|
IPin_Release(This->cur_pin);
|
|
|
|
This->cur_pin = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IBaseFilter_EnumPins(This->splitter, &pins);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK && !This->cur_pin)
|
|
|
|
{
|
|
|
|
PIN_DIRECTION dir;
|
|
|
|
hr = IPin_QueryDirection(pin, &dir);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IPin_Release(pin);
|
|
|
|
IEnumPins_Release(pins);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dir == PINDIR_OUTPUT && strm-- == 0)
|
|
|
|
This->cur_pin = pin;
|
|
|
|
else
|
|
|
|
IPin_Release(pin);
|
|
|
|
}
|
|
|
|
IEnumPins_Release(pins);
|
|
|
|
|
|
|
|
assert(This->cur_pin);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-12 01:42:24 +01:00
|
|
|
static HRESULT WINAPI MediaDet_put_CurrentStream(IMediaDet* iface, LONG newVal)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2008-04-09 01:55:37 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2009-03-12 01:42:24 +01:00
|
|
|
TRACE("(%p)->(%d)\n", This, newVal);
|
2008-04-09 01:55:37 +02:00
|
|
|
|
|
|
|
if (This->num_streams == -1)
|
|
|
|
{
|
2009-03-12 01:42:24 +01:00
|
|
|
LONG n;
|
2008-04-09 01:55:37 +02:00
|
|
|
hr = MediaDet_get_OutputStreams(iface, &n);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newVal < 0 || This->num_streams <= newVal)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-04-10 01:01:30 +02:00
|
|
|
hr = SetCurPin(This, newVal);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2008-04-09 01:55:37 +02:00
|
|
|
This->cur_stream = newVal;
|
|
|
|
return S_OK;
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
2020-04-17 22:02:06 +02:00
|
|
|
static HRESULT WINAPI MediaDet_get_StreamType(IMediaDet *iface, GUID *majortype)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2020-04-17 22:02:06 +02:00
|
|
|
MediaDetImpl *detector = impl_from_IMediaDet(iface);
|
|
|
|
AM_MEDIA_TYPE mt;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("detector %p, majortype %p.\n", detector, majortype);
|
|
|
|
|
|
|
|
if (!majortype)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = IMediaDet_get_StreamMediaType(iface, &mt)))
|
|
|
|
{
|
|
|
|
*majortype = mt.majortype;
|
|
|
|
FreeMediaType(&mt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
2020-04-17 22:02:07 +02:00
|
|
|
static HRESULT WINAPI MediaDet_get_StreamTypeB(IMediaDet *iface, BSTR *bstr)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2020-04-17 22:02:07 +02:00
|
|
|
MediaDetImpl *detector = impl_from_IMediaDet(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
GUID guid;
|
|
|
|
|
|
|
|
TRACE("detector %p, bstr %p.\n", detector, bstr);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = IMediaDet_get_StreamType(iface, &guid)))
|
|
|
|
{
|
|
|
|
if (!(*bstr = SysAllocStringLen(NULL, CHARS_IN_GUID - 1)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
StringFromGUID2(&guid, *bstr, CHARS_IN_GUID);
|
|
|
|
}
|
|
|
|
return hr;
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
2020-04-27 21:14:05 +02:00
|
|
|
static HRESULT WINAPI MediaDet_get_StreamLength(IMediaDet *iface, double *length)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2020-04-27 21:14:05 +02:00
|
|
|
MediaDetImpl *detector = impl_from_IMediaDet(iface);
|
|
|
|
IMediaSeeking *seeking;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("detector %p, length %p.\n", detector, length);
|
|
|
|
|
|
|
|
if (!length)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (!detector->cur_pin)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = IPin_QueryInterface(detector->cur_pin,
|
|
|
|
&IID_IMediaSeeking, (void **)&seeking)))
|
|
|
|
{
|
|
|
|
LONGLONG duration;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = IMediaSeeking_GetDuration(seeking, &duration)))
|
|
|
|
{
|
|
|
|
/* Windows assumes the time format is TIME_FORMAT_MEDIA_TIME
|
|
|
|
and does not check it nor convert it, as tests show. */
|
|
|
|
*length = (REFTIME)duration / 10000000;
|
|
|
|
}
|
|
|
|
IMediaSeeking_Release(seeking);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MediaDet_get_Filename(IMediaDet* iface, BSTR *pVal)
|
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2008-04-09 01:52:50 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if (!pVal)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*pVal = NULL;
|
|
|
|
/* MSDN says it should return E_FAIL if no file is open, but tests
|
|
|
|
show otherwise. */
|
2020-04-23 21:45:44 +02:00
|
|
|
if (!This->filename)
|
2008-04-09 01:52:50 +02:00
|
|
|
return S_OK;
|
|
|
|
|
2020-04-23 21:45:44 +02:00
|
|
|
*pVal = SysAllocString(This->filename);
|
2008-04-09 01:52:50 +02:00
|
|
|
if (!*pVal)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return S_OK;
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
2020-04-23 21:45:44 +02:00
|
|
|
static HRESULT WINAPI MediaDet_put_Filename(IMediaDet *iface, BSTR filename)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2008-04-09 01:52:14 +02:00
|
|
|
IGraphBuilder *gb;
|
|
|
|
IBaseFilter *bf;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2020-04-23 21:45:44 +02:00
|
|
|
TRACE("detector %p, filename %s.\n", This, debugstr_w(filename));
|
2008-04-09 01:52:14 +02:00
|
|
|
|
|
|
|
if (This->graph)
|
|
|
|
{
|
|
|
|
WARN("MSDN says not to call this method twice\n");
|
|
|
|
MD_cleanup(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IGraphBuilder, (void **) &gb);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2020-04-23 21:45:44 +02:00
|
|
|
if (FAILED(hr = IGraphBuilder_AddSourceFilter(gb, filename, L"Source", &bf)))
|
2008-04-09 01:52:14 +02:00
|
|
|
{
|
|
|
|
IGraphBuilder_Release(gb);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:45:44 +02:00
|
|
|
if (!(This->filename = wcsdup(filename)))
|
|
|
|
{
|
|
|
|
IBaseFilter_Release(bf);
|
|
|
|
IGraphBuilder_Release(gb);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2008-04-09 01:52:14 +02:00
|
|
|
This->graph = gb;
|
|
|
|
This->source = bf;
|
2020-04-23 21:45:41 +02:00
|
|
|
hr = find_splitter(This);
|
2008-04-10 01:01:30 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
return MediaDet_put_CurrentStream(iface, 0);
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MediaDet_GetBitmapBits(IMediaDet* iface,
|
|
|
|
double StreamTime,
|
2009-03-12 01:42:24 +01:00
|
|
|
LONG *pBufferSize, char *pBuffer,
|
|
|
|
LONG Width, LONG Height)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2009-03-12 01:42:24 +01:00
|
|
|
FIXME("(%p)->(%f %p %p %d %d): not implemented!\n", This, StreamTime, pBufferSize, pBuffer,
|
2008-02-13 23:12:17 +01:00
|
|
|
Width, Height);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MediaDet_WriteBitmapBits(IMediaDet* iface,
|
2009-03-12 01:42:24 +01:00
|
|
|
double StreamTime, LONG Width,
|
|
|
|
LONG Height, BSTR Filename)
|
2008-02-13 23:12:17 +01:00
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2009-03-12 01:42:24 +01:00
|
|
|
FIXME("(%p)->(%f %d %d %p): not implemented!\n", This, StreamTime, Width, Height, Filename);
|
2008-02-13 23:12:17 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MediaDet_get_StreamMediaType(IMediaDet* iface,
|
|
|
|
AM_MEDIA_TYPE *pVal)
|
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2008-04-10 01:01:30 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if (!pVal)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (!This->cur_pin)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2020-04-27 21:14:03 +02:00
|
|
|
return get_pin_media_type(This->cur_pin, pVal);
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MediaDet_GetSampleGrabber(IMediaDet* iface,
|
|
|
|
ISampleGrabber **ppVal)
|
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2008-04-04 02:54:45 +02:00
|
|
|
FIXME("(%p)->(%p): not implemented!\n", This, ppVal);
|
2008-02-13 23:12:17 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MediaDet_get_FrameRate(IMediaDet* iface, double *pVal)
|
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2008-04-10 01:02:02 +02:00
|
|
|
AM_MEDIA_TYPE mt;
|
|
|
|
VIDEOINFOHEADER *vh;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if (!pVal)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
hr = MediaDet_get_StreamMediaType(iface, &mt);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (!IsEqualGUID(&mt.majortype, &MEDIATYPE_Video))
|
|
|
|
{
|
|
|
|
CoTaskMemFree(mt.pbFormat);
|
|
|
|
return VFW_E_INVALIDMEDIATYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
vh = (VIDEOINFOHEADER *) mt.pbFormat;
|
|
|
|
*pVal = 1.0e7 / (double) vh->AvgTimePerFrame;
|
|
|
|
|
|
|
|
CoTaskMemFree(mt.pbFormat);
|
|
|
|
return S_OK;
|
2008-02-13 23:12:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MediaDet_EnterBitmapGrabMode(IMediaDet* iface,
|
|
|
|
double SeekTime)
|
|
|
|
{
|
2010-12-08 22:59:33 +01:00
|
|
|
MediaDetImpl *This = impl_from_IMediaDet(iface);
|
2008-04-04 02:54:45 +02:00
|
|
|
FIXME("(%p)->(%f): not implemented!\n", This, SeekTime);
|
2008-02-13 23:12:17 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMediaDetVtbl IMediaDet_VTable =
|
|
|
|
{
|
|
|
|
MediaDet_QueryInterface,
|
|
|
|
MediaDet_AddRef,
|
|
|
|
MediaDet_Release,
|
|
|
|
MediaDet_get_Filter,
|
|
|
|
MediaDet_put_Filter,
|
|
|
|
MediaDet_get_OutputStreams,
|
|
|
|
MediaDet_get_CurrentStream,
|
|
|
|
MediaDet_put_CurrentStream,
|
|
|
|
MediaDet_get_StreamType,
|
|
|
|
MediaDet_get_StreamTypeB,
|
|
|
|
MediaDet_get_StreamLength,
|
|
|
|
MediaDet_get_Filename,
|
|
|
|
MediaDet_put_Filename,
|
|
|
|
MediaDet_GetBitmapBits,
|
|
|
|
MediaDet_WriteBitmapBits,
|
|
|
|
MediaDet_get_StreamMediaType,
|
|
|
|
MediaDet_GetSampleGrabber,
|
|
|
|
MediaDet_get_FrameRate,
|
|
|
|
MediaDet_EnterBitmapGrabMode,
|
|
|
|
};
|
|
|
|
|
2020-03-12 03:10:09 +01:00
|
|
|
HRESULT media_detector_create(IUnknown *pUnkOuter, IUnknown **ppv)
|
|
|
|
{
|
2008-02-13 23:12:17 +01:00
|
|
|
MediaDetImpl* obj = NULL;
|
|
|
|
|
2016-04-22 08:18:00 +02:00
|
|
|
TRACE("(%p,%p)\n", pUnkOuter, ppv);
|
2008-02-13 23:12:17 +01:00
|
|
|
|
|
|
|
obj = CoTaskMemAlloc(sizeof(MediaDetImpl));
|
|
|
|
if (NULL == obj) {
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
ZeroMemory(obj, sizeof(MediaDetImpl));
|
|
|
|
|
2012-07-01 00:06:15 +02:00
|
|
|
obj->ref = 1;
|
|
|
|
obj->IUnknown_inner.lpVtbl = &mediadet_vtbl;
|
2010-12-08 22:59:33 +01:00
|
|
|
obj->IMediaDet_iface.lpVtbl = &IMediaDet_VTable;
|
2008-04-09 01:52:14 +02:00
|
|
|
obj->graph = NULL;
|
|
|
|
obj->source = NULL;
|
2008-04-09 01:53:52 +02:00
|
|
|
obj->splitter = NULL;
|
2008-04-10 01:01:30 +02:00
|
|
|
obj->cur_pin = NULL;
|
2008-04-09 01:55:37 +02:00
|
|
|
obj->num_streams = -1;
|
|
|
|
obj->cur_stream = 0;
|
2008-02-13 23:12:17 +01:00
|
|
|
|
2012-07-01 00:06:15 +02:00
|
|
|
if (pUnkOuter)
|
|
|
|
obj->outer_unk = pUnkOuter;
|
|
|
|
else
|
|
|
|
obj->outer_unk = &obj->IUnknown_inner;
|
|
|
|
|
|
|
|
*ppv = &obj->IUnknown_inner;
|
2008-02-13 23:12:17 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|