2003-08-07 00:04:45 +02:00
|
|
|
/*
|
|
|
|
* Implementation of IEnumMediaTypes Interface
|
|
|
|
*
|
|
|
|
* Copyright 2003 Robert Shearman
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "quartz_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
|
|
|
|
2003-09-11 23:18:36 +02:00
|
|
|
HRESULT CopyMediaType(AM_MEDIA_TYPE * pDest, const AM_MEDIA_TYPE *pSrc)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
|
|
|
memcpy(pDest, pSrc, sizeof(AM_MEDIA_TYPE));
|
2005-05-06 16:34:02 +02:00
|
|
|
if (!pSrc->pbFormat) return S_OK;
|
2003-09-11 23:18:36 +02:00
|
|
|
if (!(pDest->pbFormat = CoTaskMemAlloc(pSrc->cbFormat)))
|
|
|
|
return E_OUTOFMEMORY;
|
2003-08-07 00:04:45 +02:00
|
|
|
memcpy(pDest->pbFormat, pSrc->pbFormat, pSrc->cbFormat);
|
2005-06-05 21:18:34 +02:00
|
|
|
if (pDest->pUnk)
|
|
|
|
IUnknown_AddRef(pDest->pUnk);
|
2003-09-11 23:18:36 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-06 16:34:02 +02:00
|
|
|
void FreeMediaType(AM_MEDIA_TYPE * pMediaType)
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
|
|
|
if (pMediaType->pbFormat)
|
|
|
|
{
|
|
|
|
CoTaskMemFree(pMediaType->pbFormat);
|
|
|
|
pMediaType->pbFormat = NULL;
|
|
|
|
}
|
|
|
|
if (pMediaType->pUnk)
|
|
|
|
{
|
|
|
|
IUnknown_Release(pMediaType->pUnk);
|
|
|
|
pMediaType->pUnk = NULL;
|
|
|
|
}
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
2005-06-05 21:18:34 +02:00
|
|
|
AM_MEDIA_TYPE * 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;
|
|
|
|
}
|
|
|
|
|
2005-05-06 16:34:02 +02:00
|
|
|
void DeleteMediaType(AM_MEDIA_TYPE * pMediaType)
|
|
|
|
{
|
|
|
|
FreeMediaType(pMediaType);
|
|
|
|
CoTaskMemFree(pMediaType);
|
|
|
|
}
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
BOOL CompareMediaTypes(const AM_MEDIA_TYPE * pmt1, const AM_MEDIA_TYPE * pmt2, BOOL bWildcards)
|
|
|
|
{
|
|
|
|
TRACE("pmt1: ");
|
|
|
|
dump_AM_MEDIA_TYPE(pmt1);
|
|
|
|
TRACE("pmt2: ");
|
|
|
|
dump_AM_MEDIA_TYPE(pmt2);
|
|
|
|
return (((bWildcards && (IsEqualGUID(&pmt1->majortype, &GUID_NULL) || IsEqualGUID(&pmt2->majortype, &GUID_NULL))) || IsEqualGUID(&pmt1->majortype, &pmt2->majortype)) &&
|
|
|
|
((bWildcards && (IsEqualGUID(&pmt1->subtype, &GUID_NULL) || IsEqualGUID(&pmt2->subtype, &GUID_NULL))) || IsEqualGUID(&pmt1->subtype, &pmt2->subtype)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump_AM_MEDIA_TYPE(const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
|
|
|
if (!pmt)
|
|
|
|
return;
|
|
|
|
TRACE("\t%s\n\t%s\n\t...\n\t%s\n", qzdebugstr_guid(&pmt->majortype), qzdebugstr_guid(&pmt->subtype), qzdebugstr_guid(&pmt->formattype));
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct IEnumMediaTypesImpl
|
|
|
|
{
|
|
|
|
const IEnumMediaTypesVtbl * lpVtbl;
|
|
|
|
ULONG refCount;
|
|
|
|
ENUMMEDIADETAILS enumMediaDetails;
|
|
|
|
ULONG uIndex;
|
|
|
|
} IEnumMediaTypesImpl;
|
|
|
|
|
|
|
|
static const struct IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl;
|
|
|
|
|
|
|
|
HRESULT IEnumMediaTypesImpl_Construct(const ENUMMEDIADETAILS * pDetails, IEnumMediaTypes ** ppEnum)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
IEnumMediaTypesImpl * pEnumMediaTypes = CoTaskMemAlloc(sizeof(IEnumMediaTypesImpl));
|
|
|
|
|
|
|
|
if (!pEnumMediaTypes)
|
|
|
|
{
|
|
|
|
*ppEnum = NULL;
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
pEnumMediaTypes->lpVtbl = &IEnumMediaTypesImpl_Vtbl;
|
|
|
|
pEnumMediaTypes->refCount = 1;
|
|
|
|
pEnumMediaTypes->uIndex = 0;
|
|
|
|
pEnumMediaTypes->enumMediaDetails.cMediaTypes = pDetails->cMediaTypes;
|
|
|
|
pEnumMediaTypes->enumMediaDetails.pMediaTypes = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE) * pDetails->cMediaTypes);
|
|
|
|
for (i = 0; i < pDetails->cMediaTypes; i++)
|
2005-06-05 21:18:34 +02:00
|
|
|
if (FAILED(CopyMediaType(&pEnumMediaTypes->enumMediaDetails.pMediaTypes[i], &pDetails->pMediaTypes[i])))
|
|
|
|
{
|
2005-05-07 14:12:29 +02:00
|
|
|
while (i--)
|
|
|
|
CoTaskMemFree(pEnumMediaTypes->enumMediaDetails.pMediaTypes[i].pbFormat);
|
2005-05-06 16:34:02 +02:00
|
|
|
CoTaskMemFree(pEnumMediaTypes->enumMediaDetails.pMediaTypes);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2003-08-07 00:04:45 +02:00
|
|
|
*ppEnum = (IEnumMediaTypes *)(&pEnumMediaTypes->lpVtbl);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumMediaTypesImpl_QueryInterface(IEnumMediaTypes * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
|
|
|
TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
else if (IsEqualIID(riid, &IID_IEnumMediaTypes))
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
|
|
|
|
if (*ppv)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef((IUnknown *)(*ppv));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IEnumMediaTypesImpl_AddRef(IEnumMediaTypes * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->refCount);
|
|
|
|
|
2005-06-05 21:18:34 +02:00
|
|
|
TRACE("(%p)->() AddRef from %ld\n", iface, refCount - 1);
|
2005-01-06 20:36:47 +01:00
|
|
|
|
|
|
|
return refCount;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IEnumMediaTypesImpl_Release(IEnumMediaTypes * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->refCount);
|
|
|
|
|
2005-06-05 21:18:34 +02:00
|
|
|
TRACE("(%p)->() Release from %ld\n", iface, refCount + 1);
|
2005-01-06 20:36:47 +01:00
|
|
|
|
|
|
|
if (!refCount)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2005-05-06 16:34:02 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < This->enumMediaDetails.cMediaTypes; i++)
|
|
|
|
if (This->enumMediaDetails.pMediaTypes[i].pbFormat)
|
|
|
|
CoTaskMemFree(This->enumMediaDetails.pMediaTypes[i].pbFormat);
|
2003-08-07 00:04:45 +02:00
|
|
|
CoTaskMemFree(This->enumMediaDetails.pMediaTypes);
|
|
|
|
CoTaskMemFree(This);
|
|
|
|
}
|
2005-05-06 16:34:02 +02:00
|
|
|
return refCount;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumMediaTypesImpl_Next(IEnumMediaTypes * iface, ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes, ULONG * pcFetched)
|
|
|
|
{
|
|
|
|
ULONG cFetched;
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
cFetched = min(This->enumMediaDetails.cMediaTypes, This->uIndex + cMediaTypes) - This->uIndex;
|
|
|
|
|
|
|
|
TRACE("(%lu, %p, %p)\n", cMediaTypes, ppMediaTypes, pcFetched);
|
|
|
|
TRACE("Next uIndex: %lu, cFetched: %lu\n", This->uIndex, cFetched);
|
|
|
|
|
|
|
|
if (cFetched > 0)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
for (i = 0; i < cFetched; i++)
|
2005-06-05 21:18:34 +02:00
|
|
|
if (!(ppMediaTypes[i] = CreateMediaType(&This->enumMediaDetails.pMediaTypes[This->uIndex + i])))
|
|
|
|
{
|
2005-05-07 14:12:29 +02:00
|
|
|
while (i--)
|
2005-06-05 21:18:34 +02:00
|
|
|
DeleteMediaType(ppMediaTypes[i]);
|
|
|
|
*pcFetched = 0;
|
2005-05-06 16:34:02 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((cMediaTypes != 1) || pcFetched)
|
|
|
|
*pcFetched = cFetched;
|
|
|
|
|
|
|
|
This->uIndex += cFetched;
|
|
|
|
|
|
|
|
if (cFetched != cMediaTypes)
|
|
|
|
return S_FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumMediaTypesImpl_Skip(IEnumMediaTypes * iface, ULONG cMediaTypes)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
TRACE("(%lu)\n", cMediaTypes);
|
|
|
|
|
|
|
|
if (This->uIndex + cMediaTypes < This->enumMediaDetails.cMediaTypes)
|
|
|
|
{
|
|
|
|
This->uIndex += cMediaTypes;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumMediaTypesImpl_Reset(IEnumMediaTypes * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
This->uIndex = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IEnumMediaTypesImpl_Clone(IEnumMediaTypes * iface, IEnumMediaTypes ** ppEnum)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2004-09-08 03:50:37 +02:00
|
|
|
IEnumMediaTypesImpl *This = (IEnumMediaTypesImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", ppEnum);
|
|
|
|
|
|
|
|
hr = IEnumMediaTypesImpl_Construct(&This->enumMediaDetails, ppEnum);
|
|
|
|
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
|
|
|
|
};
|