2010-10-04 16:48:25 +02:00
|
|
|
/*
|
|
|
|
* Implementation of MedaType utility functions
|
|
|
|
*
|
|
|
|
* Copyright 2003 Robert Shearman
|
|
|
|
* Copyright 2010 Aric Stewart, CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2019-10-06 02:18:50 +02:00
|
|
|
#include "strmbase_private.h"
|
2010-10-04 16:48:25 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(strmbase);
|
|
|
|
|
2019-10-06 02:18:50 +02:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const GUID *guid;
|
|
|
|
const char *name;
|
|
|
|
}
|
|
|
|
strmbase_guids[] =
|
|
|
|
{
|
|
|
|
#define X(g) {&(g), #g}
|
|
|
|
X(GUID_NULL),
|
|
|
|
|
|
|
|
#undef OUR_GUID_ENTRY
|
|
|
|
#define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) X(name),
|
|
|
|
#include "uuids.h"
|
|
|
|
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *strmbase_debugstr_guid(const GUID *guid)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(strmbase_guids); ++i)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(strmbase_guids[i].guid, guid))
|
|
|
|
return wine_dbg_sprintf("%s", strmbase_guids[i].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return debugstr_guid(guid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *debugstr_fourcc(DWORD fourcc)
|
|
|
|
{
|
|
|
|
char str[4] = {fourcc, fourcc >> 8, fourcc >> 16, fourcc >> 24};
|
|
|
|
if (isprint(str[0]) && isprint(str[1]) && isprint(str[2]) && isprint(str[3]))
|
|
|
|
return wine_dbgstr_an(str, 4);
|
|
|
|
return wine_dbg_sprintf("%#x", fourcc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void strmbase_dump_media_type(const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
if (!TRACE_ON(strmbase) || !mt) return;
|
|
|
|
|
|
|
|
TRACE("Dumping media type %p: major type %s, subtype %s",
|
|
|
|
mt, strmbase_debugstr_guid(&mt->majortype), strmbase_debugstr_guid(&mt->subtype));
|
|
|
|
if (mt->bFixedSizeSamples) TRACE(", fixed size samples");
|
|
|
|
if (mt->bTemporalCompression) TRACE(", temporal compression");
|
|
|
|
if (mt->lSampleSize) TRACE(", sample size %d", mt->lSampleSize);
|
|
|
|
if (mt->pUnk) TRACE(", pUnk %p", mt->pUnk);
|
|
|
|
TRACE(", format type %s.\n", strmbase_debugstr_guid(&mt->formattype));
|
|
|
|
|
|
|
|
if (!mt->pbFormat) return;
|
|
|
|
|
|
|
|
TRACE("Dumping format %p: ", mt->pbFormat);
|
|
|
|
|
|
|
|
if (IsEqualGUID(&mt->formattype, &FORMAT_WaveFormatEx) && mt->cbFormat >= sizeof(WAVEFORMATEX))
|
|
|
|
{
|
|
|
|
WAVEFORMATEX *wfx = (WAVEFORMATEX *)mt->pbFormat;
|
|
|
|
|
|
|
|
TRACE("tag %#x, %u channels, sample rate %u, %u bytes/sec, alignment %u, %u bits/sample.\n",
|
|
|
|
wfx->wFormatTag, wfx->nChannels, wfx->nSamplesPerSec,
|
|
|
|
wfx->nAvgBytesPerSec, wfx->nBlockAlign, wfx->wBitsPerSample);
|
|
|
|
|
|
|
|
if (wfx->cbSize)
|
|
|
|
{
|
|
|
|
const unsigned char *extra = (const unsigned char *)(wfx + 1);
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
TRACE(" Extra bytes:");
|
|
|
|
for (i = 0; i < wfx->cbSize; ++i)
|
|
|
|
{
|
|
|
|
if (!(i % 16)) TRACE("\n ");
|
|
|
|
TRACE(" %02x", extra[i]);
|
|
|
|
}
|
|
|
|
TRACE("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo) && mt->cbFormat >= sizeof(VIDEOINFOHEADER))
|
|
|
|
{
|
|
|
|
VIDEOINFOHEADER *vih = (VIDEOINFOHEADER *)mt->pbFormat;
|
|
|
|
|
|
|
|
TRACE("source %s, target %s, bitrate %u, error rate %u, %s sec/frame, ",
|
|
|
|
wine_dbgstr_rect(&vih->rcSource), wine_dbgstr_rect(&vih->rcTarget),
|
|
|
|
vih->dwBitRate, vih->dwBitErrorRate, debugstr_time(vih->AvgTimePerFrame));
|
|
|
|
TRACE("size %dx%d, %u planes, %u bpp, compression %s, image size %u",
|
|
|
|
vih->bmiHeader.biWidth, vih->bmiHeader.biHeight, vih->bmiHeader.biPlanes,
|
|
|
|
vih->bmiHeader.biBitCount, debugstr_fourcc(vih->bmiHeader.biCompression),
|
|
|
|
vih->bmiHeader.biSizeImage);
|
|
|
|
if (vih->bmiHeader.biXPelsPerMeter || vih->bmiHeader.biYPelsPerMeter)
|
|
|
|
TRACE(", resolution %dx%d", vih->bmiHeader.biXPelsPerMeter, vih->bmiHeader.biYPelsPerMeter);
|
|
|
|
if (vih->bmiHeader.biClrUsed) TRACE(", %d colours", vih->bmiHeader.biClrUsed);
|
|
|
|
if (vih->bmiHeader.biClrImportant) TRACE(", %d important colours", vih->bmiHeader.biClrImportant);
|
|
|
|
TRACE(".\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
TRACE("not implemented for this format type.\n");
|
|
|
|
}
|
|
|
|
|
2012-11-21 09:48:06 +01:00
|
|
|
HRESULT WINAPI CopyMediaType(AM_MEDIA_TYPE *dest, const AM_MEDIA_TYPE *src)
|
2010-10-04 16:48:25 +02:00
|
|
|
{
|
2012-11-21 09:48:06 +01:00
|
|
|
*dest = *src;
|
|
|
|
if (src->pbFormat)
|
|
|
|
{
|
|
|
|
dest->pbFormat = CoTaskMemAlloc(src->cbFormat);
|
|
|
|
if (!dest->pbFormat)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
memcpy(dest->pbFormat, src->pbFormat, src->cbFormat);
|
|
|
|
}
|
|
|
|
if (dest->pUnk)
|
|
|
|
IUnknown_AddRef(dest->pUnk);
|
2010-10-04 16:48:25 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WINAPI FreeMediaType(AM_MEDIA_TYPE * pMediaType)
|
|
|
|
{
|
2019-01-29 20:38:09 +01:00
|
|
|
CoTaskMemFree(pMediaType->pbFormat);
|
|
|
|
pMediaType->pbFormat = NULL;
|
2010-10-04 16:48:25 +02:00
|
|
|
if (pMediaType->pUnk)
|
|
|
|
{
|
|
|
|
IUnknown_Release(pMediaType->pUnk);
|
|
|
|
pMediaType->pUnk = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AM_MEDIA_TYPE * WINAPI CreateMediaType(AM_MEDIA_TYPE const * pSrc)
|
|
|
|
{
|
|
|
|
AM_MEDIA_TYPE * pDest;
|
|
|
|
|
|
|
|
pDest = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
|
|
|
|
if (!pDest)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (FAILED(CopyMediaType(pDest, pSrc)))
|
|
|
|
{
|
|
|
|
CoTaskMemFree(pDest);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pDest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WINAPI DeleteMediaType(AM_MEDIA_TYPE * pMediaType)
|
|
|
|
{
|
|
|
|
FreeMediaType(pMediaType);
|
|
|
|
CoTaskMemFree(pMediaType);
|
|
|
|
}
|
2010-10-05 21:37:30 +02:00
|
|
|
|
|
|
|
typedef struct IEnumMediaTypesImpl
|
|
|
|
{
|
2010-12-08 22:59:24 +01:00
|
|
|
IEnumMediaTypes IEnumMediaTypes_iface;
|
2010-10-05 21:37:30 +02:00
|
|
|
LONG refCount;
|
2019-09-24 02:33:24 +02:00
|
|
|
struct strmbase_pin *basePin;
|
2019-05-15 02:41:58 +02:00
|
|
|
ULONG count;
|
2010-10-05 21:37:30 +02:00
|
|
|
ULONG uIndex;
|
|
|
|
} IEnumMediaTypesImpl;
|
|
|
|
|
2010-12-08 22:59:24 +01:00
|
|
|
static inline IEnumMediaTypesImpl *impl_from_IEnumMediaTypes(IEnumMediaTypes *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IEnumMediaTypesImpl, IEnumMediaTypes_iface);
|
|
|
|
}
|
|
|
|
|
2010-10-05 21:37:30 +02:00
|
|
|
static const struct IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl;
|
|
|
|
|
2019-09-24 02:33:24 +02:00
|
|
|
HRESULT enum_media_types_create(struct strmbase_pin *basePin, IEnumMediaTypes **ppEnum)
|
2010-10-05 21:37:30 +02:00
|
|
|
{
|
|
|
|
IEnumMediaTypesImpl * pEnumMediaTypes = CoTaskMemAlloc(sizeof(IEnumMediaTypesImpl));
|
|
|
|
|
2016-07-28 14:43:21 +02:00
|
|
|
*ppEnum = NULL;
|
|
|
|
|
2010-10-05 21:37:30 +02:00
|
|
|
if (!pEnumMediaTypes)
|
|
|
|
return E_OUTOFMEMORY;
|
2016-07-28 14:43:21 +02:00
|
|
|
|
2010-12-08 22:59:24 +01:00
|
|
|
pEnumMediaTypes->IEnumMediaTypes_iface.lpVtbl = &IEnumMediaTypesImpl_Vtbl;
|
2010-10-05 21:37:30 +02:00
|
|
|
pEnumMediaTypes->refCount = 1;
|
|
|
|
pEnumMediaTypes->uIndex = 0;
|
2012-03-24 17:42:32 +01:00
|
|
|
IPin_AddRef(&basePin->IPin_iface);
|
2010-10-05 21:37:30 +02:00
|
|
|
pEnumMediaTypes->basePin = basePin;
|
|
|
|
|
2019-09-24 02:33:23 +02:00
|
|
|
IEnumMediaTypes_Reset(&pEnumMediaTypes->IEnumMediaTypes_iface);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2010-12-08 22:59:24 +01:00
|
|
|
*ppEnum = &pEnumMediaTypes->IEnumMediaTypes_iface;
|
2010-10-05 21:37:30 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-23 09:47:05 +01:00
|
|
|
static HRESULT WINAPI IEnumMediaTypesImpl_QueryInterface(IEnumMediaTypes * iface, REFIID riid, void ** ret_iface)
|
2010-10-05 21:37:30 +02:00
|
|
|
{
|
2012-11-23 09:47:05 +01:00
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ret_iface);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2012-11-23 09:47:05 +01:00
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IEnumMediaTypes))
|
2010-10-05 21:37:30 +02:00
|
|
|
{
|
2012-11-23 09:47:05 +01:00
|
|
|
IEnumMediaTypes_AddRef(iface);
|
|
|
|
*ret_iface = iface;
|
2010-10-05 21:37:30 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-23 09:47:05 +01:00
|
|
|
*ret_iface = NULL;
|
|
|
|
|
|
|
|
WARN("No interface for %s\n", debugstr_guid(riid));
|
2010-10-05 21:37:30 +02:00
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IEnumMediaTypesImpl_AddRef(IEnumMediaTypes * iface)
|
|
|
|
{
|
2010-12-08 22:59:24 +01:00
|
|
|
IEnumMediaTypesImpl *This = impl_from_IEnumMediaTypes(iface);
|
2012-11-23 09:46:50 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->refCount);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2012-11-23 09:46:50 +01:00
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2012-11-23 09:46:50 +01:00
|
|
|
return ref;
|
2010-10-05 21:37:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IEnumMediaTypesImpl_Release(IEnumMediaTypes * iface)
|
|
|
|
{
|
2010-12-08 22:59:24 +01:00
|
|
|
IEnumMediaTypesImpl *This = impl_from_IEnumMediaTypes(iface);
|
2012-11-23 09:46:50 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->refCount);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2012-11-23 09:46:50 +01:00
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2012-11-23 09:46:50 +01:00
|
|
|
if (!ref)
|
2010-10-05 21:37:30 +02:00
|
|
|
{
|
2012-03-24 17:42:32 +01:00
|
|
|
IPin_Release(&This->basePin->IPin_iface);
|
2010-10-05 21:37:30 +02:00
|
|
|
CoTaskMemFree(This);
|
|
|
|
}
|
2012-11-23 09:46:50 +01:00
|
|
|
return ref;
|
2010-10-05 21:37:30 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 20:43:49 +02:00
|
|
|
static HRESULT WINAPI IEnumMediaTypesImpl_Next(IEnumMediaTypes *iface,
|
|
|
|
ULONG count, AM_MEDIA_TYPE **mts, ULONG *ret_count)
|
2010-10-05 21:37:30 +02:00
|
|
|
{
|
2019-06-29 20:43:49 +02:00
|
|
|
IEnumMediaTypesImpl *enummt = impl_from_IEnumMediaTypes(iface);
|
|
|
|
ULONG i;
|
2012-11-23 09:46:58 +01:00
|
|
|
|
2019-06-29 20:43:49 +02:00
|
|
|
TRACE("iface %p, count %u, mts %p, ret_count %p.\n", iface, count, mts, ret_count);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2019-06-29 20:43:49 +02:00
|
|
|
for (i = 0; i < count && enummt->uIndex + i < enummt->count; i++)
|
2010-10-05 21:37:30 +02:00
|
|
|
{
|
2019-06-29 20:43:49 +02:00
|
|
|
if (!(mts[i] = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE)))
|
2019-09-25 02:10:11 +02:00
|
|
|
|| FAILED(enummt->basePin->pFuncsTable->pin_get_media_type(enummt->basePin, enummt->uIndex + i, mts[i])))
|
2019-05-15 02:41:57 +02:00
|
|
|
{
|
2019-06-29 20:43:49 +02:00
|
|
|
while (i--)
|
|
|
|
DeleteMediaType(mts[i]);
|
|
|
|
*ret_count = 0;
|
|
|
|
return E_OUTOFMEMORY;
|
2019-05-15 02:41:57 +02:00
|
|
|
}
|
2019-10-06 02:18:50 +02:00
|
|
|
|
|
|
|
if (TRACE_ON(strmbase))
|
|
|
|
{
|
|
|
|
TRACE("Returning media type %u:\n", enummt->uIndex + i);
|
|
|
|
strmbase_dump_media_type(mts[i]);
|
|
|
|
}
|
2010-10-05 21:37:30 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 20:43:49 +02:00
|
|
|
if ((count != 1) || ret_count)
|
|
|
|
*ret_count = i;
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2019-06-29 20:43:49 +02:00
|
|
|
enummt->uIndex += i;
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2019-06-29 20:43:49 +02:00
|
|
|
return i == count ? S_OK : S_FALSE;
|
2010-10-05 21:37:30 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 20:43:50 +02:00
|
|
|
static HRESULT WINAPI IEnumMediaTypesImpl_Skip(IEnumMediaTypes *iface, ULONG count)
|
2010-10-05 21:37:30 +02:00
|
|
|
{
|
2019-06-29 20:43:50 +02:00
|
|
|
IEnumMediaTypesImpl *enummt = impl_from_IEnumMediaTypes(iface);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2019-06-29 20:43:50 +02:00
|
|
|
TRACE("iface %p, count %u.\n", iface, count);
|
2012-11-23 09:46:58 +01:00
|
|
|
|
2019-06-29 20:43:50 +02:00
|
|
|
enummt->uIndex += count;
|
|
|
|
|
|
|
|
return enummt->uIndex > enummt->count ? S_FALSE : S_OK;
|
2010-10-05 21:37:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumMediaTypesImpl_Reset(IEnumMediaTypes * iface)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
AM_MEDIA_TYPE amt;
|
2010-12-08 22:59:24 +01:00
|
|
|
IEnumMediaTypesImpl *This = impl_from_IEnumMediaTypes(iface);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2012-11-23 09:46:58 +01:00
|
|
|
TRACE("(%p)->()\n", iface);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
|
|
|
i = 0;
|
2019-09-25 02:10:11 +02:00
|
|
|
while (This->basePin->pFuncsTable->pin_get_media_type(This->basePin, i, &amt) == S_OK)
|
2019-01-29 20:28:58 +01:00
|
|
|
{
|
|
|
|
FreeMediaType(&amt);
|
|
|
|
i++;
|
|
|
|
}
|
2019-05-15 02:41:58 +02:00
|
|
|
This->count = i;
|
2010-10-05 21:37:30 +02:00
|
|
|
This->uIndex = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumMediaTypesImpl_Clone(IEnumMediaTypes * iface, IEnumMediaTypes ** ppEnum)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2010-12-08 22:59:24 +01:00
|
|
|
IEnumMediaTypesImpl *This = impl_from_IEnumMediaTypes(iface);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2012-11-23 09:46:58 +01:00
|
|
|
TRACE("(%p)->(%p)\n", iface, ppEnum);
|
2010-10-05 21:37:30 +02:00
|
|
|
|
2019-09-24 02:33:23 +02:00
|
|
|
hr = enum_media_types_create(This->basePin, ppEnum);
|
2010-10-05 21:37:30 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
return IEnumMediaTypes_Skip(*ppEnum, This->uIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl =
|
|
|
|
{
|
|
|
|
IEnumMediaTypesImpl_QueryInterface,
|
|
|
|
IEnumMediaTypesImpl_AddRef,
|
|
|
|
IEnumMediaTypesImpl_Release,
|
|
|
|
IEnumMediaTypesImpl_Next,
|
|
|
|
IEnumMediaTypesImpl_Skip,
|
|
|
|
IEnumMediaTypesImpl_Reset,
|
|
|
|
IEnumMediaTypesImpl_Clone
|
|
|
|
};
|