2003-09-11 23:18:36 +02:00
|
|
|
/*
|
|
|
|
* Memory Allocator and Media Sample Implementation
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-09-11 23:18:36 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "vfwmsgs.h"
|
|
|
|
|
|
|
|
#include "quartz_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
|
|
|
|
2007-08-07 22:01:25 +02:00
|
|
|
void dump_AM_SAMPLE2_PROPERTIES(const AM_SAMPLE2_PROPERTIES * pProps)
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
|
|
|
if (!pProps)
|
|
|
|
{
|
|
|
|
TRACE("AM_SAMPLE2_PROPERTIES: (null)\n");
|
|
|
|
return;
|
|
|
|
}
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("\tcbData: %d\n", pProps->cbData);
|
|
|
|
TRACE("\tdwTypeSpecificFlags: 0x%8x\n", pProps->dwTypeSpecificFlags);
|
|
|
|
TRACE("\tdwSampleFlags: 0x%8x\n", pProps->dwSampleFlags);
|
|
|
|
TRACE("\tlActual: %d\n", pProps->lActual);
|
|
|
|
TRACE("\ttStart: %x%08x%s\n", (LONG)(pProps->tStart >> 32), (LONG)pProps->tStart, pProps->dwSampleFlags & AM_SAMPLE_TIMEVALID ? "" : " (not valid)");
|
|
|
|
TRACE("\ttStop: %x%08x%s\n", (LONG)(pProps->tStop >> 32), (LONG)pProps->tStop, pProps->dwSampleFlags & AM_SAMPLE_STOPVALID ? "" : " (not valid)");
|
|
|
|
TRACE("\tdwStreamId: 0x%x\n", pProps->dwStreamId);
|
2003-09-11 23:18:36 +02:00
|
|
|
TRACE("\tpMediaType: %p\n", pProps->pMediaType);
|
|
|
|
TRACE("\tpbBuffer: %p\n", pProps->pbBuffer);
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("\tcbBuffer: %d\n", pProps->cbBuffer);
|
2003-09-11 23:18:36 +02:00
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IMemAllocatorVtbl BaseMemAllocator_VTable;
|
|
|
|
static const IMediaSample2Vtbl StdMediaSample2_VTable;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
#define AM_SAMPLE2_PROP_SIZE_WRITABLE (unsigned int)(&((AM_SAMPLE2_PROPERTIES *)0)->pbBuffer)
|
|
|
|
|
2005-09-14 12:30:36 +02:00
|
|
|
#define INVALID_MEDIA_TIME (((ULONGLONG)0x7fffffff << 32) | 0xffffffff)
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
HRESULT BaseMemAllocator_Init(HRESULT (* fnAlloc)(IMemAllocator *),
|
|
|
|
HRESULT (* fnFree)(IMemAllocator *),
|
|
|
|
HRESULT (* fnVerify)(IMemAllocator *, ALLOCATOR_PROPERTIES *),
|
|
|
|
HRESULT (* fnBufferPrepare)(IMemAllocator *, StdMediaSample2 *, DWORD),
|
|
|
|
HRESULT (* fnBufferReleased)(IMemAllocator *, StdMediaSample2 *),
|
|
|
|
void (* fnDestroyed)(IMemAllocator *),
|
|
|
|
CRITICAL_SECTION *pCritSect,
|
|
|
|
BaseMemAllocator * pMemAlloc)
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
2008-06-10 18:06:08 +02:00
|
|
|
assert(fnAlloc && fnFree && fnDestroyed);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
pMemAlloc->lpVtbl = &BaseMemAllocator_VTable;
|
|
|
|
|
2004-08-13 21:49:16 +02:00
|
|
|
pMemAlloc->ref = 1;
|
2008-06-10 18:06:08 +02:00
|
|
|
ZeroMemory(&pMemAlloc->props, sizeof(pMemAlloc->props));
|
2003-09-11 23:18:36 +02:00
|
|
|
list_init(&pMemAlloc->free_list);
|
|
|
|
list_init(&pMemAlloc->used_list);
|
|
|
|
pMemAlloc->fnAlloc = fnAlloc;
|
|
|
|
pMemAlloc->fnFree = fnFree;
|
2008-06-10 18:06:08 +02:00
|
|
|
pMemAlloc->fnVerify = fnVerify;
|
|
|
|
pMemAlloc->fnBufferPrepare = fnBufferPrepare;
|
|
|
|
pMemAlloc->fnBufferReleased = fnBufferReleased;
|
|
|
|
pMemAlloc->fnDestroyed = fnDestroyed;
|
2003-09-11 23:18:36 +02:00
|
|
|
pMemAlloc->bDecommitQueued = FALSE;
|
|
|
|
pMemAlloc->bCommitted = FALSE;
|
|
|
|
pMemAlloc->hSemWaiting = NULL;
|
|
|
|
pMemAlloc->lWaiting = 0;
|
2008-06-10 18:06:08 +02:00
|
|
|
pMemAlloc->pCritSect = pCritSect;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BaseMemAllocator_QueryInterface(IMemAllocator * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
BaseMemAllocator *This = (BaseMemAllocator *)iface;
|
2005-08-22 11:27:41 +02:00
|
|
|
TRACE("(%p)->(%s, %p)\n", This, qzdebugstr_guid(riid), ppv);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
*ppv = (LPVOID)This;
|
|
|
|
else if (IsEqualIID(riid, &IID_IMemAllocator))
|
|
|
|
*ppv = (LPVOID)This;
|
|
|
|
|
|
|
|
if (*ppv)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef((IUnknown *)(*ppv));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BaseMemAllocator_AddRef(IMemAllocator * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
BaseMemAllocator *This = (BaseMemAllocator *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%p)->() AddRef from %d\n", iface, ref - 1);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
return ref;
|
2003-09-11 23:18:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BaseMemAllocator_Release(IMemAllocator * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
BaseMemAllocator *This = (BaseMemAllocator *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%p)->() Release from %d\n", iface, ref + 1);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
if (!ref)
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
|
|
|
CloseHandle(This->hSemWaiting);
|
|
|
|
if (This->bCommitted)
|
|
|
|
This->fnFree(iface);
|
2008-06-10 18:06:08 +02:00
|
|
|
|
|
|
|
This->fnDestroyed(iface);
|
2003-09-11 23:18:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2005-01-06 20:36:47 +01:00
|
|
|
return ref;
|
2003-09-11 23:18:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BaseMemAllocator_SetProperties(IMemAllocator * iface, ALLOCATOR_PROPERTIES *pRequest, ALLOCATOR_PROPERTIES *pActual)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
BaseMemAllocator *This = (BaseMemAllocator *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2005-08-22 11:27:41 +02:00
|
|
|
TRACE("(%p)->(%p, %p)\n", This, pRequest, pActual);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
EnterCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
|
|
|
if (!list_empty(&This->used_list))
|
|
|
|
hr = VFW_E_BUFFERS_OUTSTANDING;
|
|
|
|
else if (This->bCommitted)
|
|
|
|
hr = VFW_E_ALREADY_COMMITTED;
|
2005-04-11 20:50:58 +02:00
|
|
|
else if (pRequest->cbAlign == 0)
|
|
|
|
hr = VFW_E_BADALIGN;
|
2003-09-11 23:18:36 +02:00
|
|
|
else
|
|
|
|
{
|
2008-06-10 18:06:08 +02:00
|
|
|
if (This->fnVerify)
|
|
|
|
hr = This->fnVerify(iface, pRequest);
|
2003-09-11 23:18:36 +02:00
|
|
|
else
|
2008-06-10 18:06:08 +02:00
|
|
|
hr = S_OK;
|
2008-03-12 21:32:07 +01:00
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
This->props = *pRequest;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
*pActual = This->props;
|
2003-09-11 23:18:36 +02:00
|
|
|
}
|
|
|
|
}
|
2008-06-10 18:06:08 +02:00
|
|
|
LeaveCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BaseMemAllocator_GetProperties(IMemAllocator * iface, ALLOCATOR_PROPERTIES *pProps)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
BaseMemAllocator *This = (BaseMemAllocator *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2005-08-22 11:27:41 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, pProps);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
EnterCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
2008-06-10 18:06:08 +02:00
|
|
|
memcpy(pProps, &This->props, sizeof(*pProps));
|
2003-09-11 23:18:36 +02:00
|
|
|
}
|
2008-06-10 18:06:08 +02:00
|
|
|
LeaveCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BaseMemAllocator_Commit(IMemAllocator * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
BaseMemAllocator *This = (BaseMemAllocator *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2005-08-22 11:27:41 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
EnterCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
2008-06-10 18:06:08 +02:00
|
|
|
if (!This->props.cbAlign)
|
|
|
|
hr = VFW_E_BADALIGN;
|
|
|
|
else if (!This->props.cbBuffer)
|
2003-09-11 23:18:36 +02:00
|
|
|
hr = VFW_E_SIZENOTSET;
|
2008-06-10 18:06:08 +02:00
|
|
|
else if (!This->props.cBuffers)
|
|
|
|
hr = VFW_E_BUFFER_NOTSET;
|
2008-04-28 18:26:20 +02:00
|
|
|
else if (This->bDecommitQueued && This->bCommitted)
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
|
|
|
This->bDecommitQueued = FALSE;
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
2008-04-28 18:26:20 +02:00
|
|
|
else if (This->bCommitted)
|
|
|
|
hr = S_OK;
|
2003-09-11 23:18:36 +02:00
|
|
|
else
|
|
|
|
{
|
2008-06-10 18:06:08 +02:00
|
|
|
if (!(This->hSemWaiting = CreateSemaphoreW(NULL, This->props.cBuffers, This->props.cBuffers, NULL)))
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
2007-01-05 13:05:20 +01:00
|
|
|
ERR("Couldn't create semaphore (error was %u)\n", GetLastError());
|
2003-09-11 23:18:36 +02:00
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = This->fnAlloc(iface);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
This->bCommitted = TRUE;
|
|
|
|
else
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("fnAlloc failed with error 0x%x\n", hr);
|
2003-09-11 23:18:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-10 18:06:08 +02:00
|
|
|
LeaveCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BaseMemAllocator_Decommit(IMemAllocator * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
BaseMemAllocator *This = (BaseMemAllocator *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2005-08-22 11:27:41 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
EnterCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
|
|
|
if (!This->bCommitted)
|
2005-08-22 11:27:41 +02:00
|
|
|
hr = S_OK;
|
2003-09-11 23:18:36 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!list_empty(&This->used_list))
|
|
|
|
{
|
|
|
|
This->bDecommitQueued = TRUE;
|
|
|
|
/* notify ALL waiting threads that they cannot be allocated a buffer any more */
|
|
|
|
ReleaseSemaphore(This->hSemWaiting, This->lWaiting, NULL);
|
|
|
|
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-16 02:52:09 +02:00
|
|
|
if (This->lWaiting != 0)
|
|
|
|
ERR("Waiting: %d\n", This->lWaiting);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
This->bCommitted = FALSE;
|
|
|
|
CloseHandle(This->hSemWaiting);
|
|
|
|
This->hSemWaiting = NULL;
|
|
|
|
|
|
|
|
hr = This->fnFree(iface);
|
|
|
|
if (FAILED(hr))
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("fnFree failed with error 0x%x\n", hr);
|
2003-09-11 23:18:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-10 18:06:08 +02:00
|
|
|
LeaveCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BaseMemAllocator_GetBuffer(IMemAllocator * iface, IMediaSample ** pSample, REFERENCE_TIME *pStartTime, REFERENCE_TIME *pEndTime, DWORD dwFlags)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
BaseMemAllocator *This = (BaseMemAllocator *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
/* NOTE: The pStartTime and pEndTime parameters are not applied to the sample.
|
|
|
|
* The allocator might use these values to determine which buffer it retrieves */
|
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p, %x)\n", This, pSample, pStartTime, pEndTime, dwFlags);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
*pSample = NULL;
|
|
|
|
|
2008-06-16 02:52:09 +02:00
|
|
|
EnterCriticalSection(This->pCritSect);
|
|
|
|
if (!This->bCommitted || This->bDecommitQueued)
|
2008-06-23 21:08:10 +02:00
|
|
|
{
|
|
|
|
WARN("Not committed\n");
|
2008-06-16 02:52:09 +02:00
|
|
|
hr = VFW_E_NOT_COMMITTED;
|
2008-06-23 21:08:10 +02:00
|
|
|
}
|
2008-06-16 02:52:09 +02:00
|
|
|
else
|
|
|
|
++This->lWaiting;
|
|
|
|
LeaveCriticalSection(This->pCritSect);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
if (WaitForSingleObject(This->hSemWaiting, (dwFlags & AM_GBF_NOWAIT) ? 0 : INFINITE) != WAIT_OBJECT_0)
|
|
|
|
{
|
2008-06-23 21:08:10 +02:00
|
|
|
EnterCriticalSection(This->pCritSect);
|
|
|
|
--This->lWaiting;
|
|
|
|
LeaveCriticalSection(This->pCritSect);
|
|
|
|
WARN("Timed out\n");
|
2003-09-11 23:18:36 +02:00
|
|
|
return VFW_E_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
EnterCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
2008-06-16 02:52:09 +02:00
|
|
|
--This->lWaiting;
|
2003-09-11 23:18:36 +02:00
|
|
|
if (!This->bCommitted)
|
|
|
|
hr = VFW_E_NOT_COMMITTED;
|
|
|
|
else if (This->bDecommitQueued)
|
|
|
|
hr = VFW_E_TIMEOUT;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct list * free = list_head(&This->free_list);
|
|
|
|
list_remove(free);
|
|
|
|
list_add_head(&This->used_list, free);
|
|
|
|
|
|
|
|
*pSample = (IMediaSample *)LIST_ENTRY(free, StdMediaSample2, listentry);
|
|
|
|
|
|
|
|
assert(((StdMediaSample2 *)*pSample)->ref == 0);
|
|
|
|
|
|
|
|
IMediaSample_AddRef(*pSample);
|
|
|
|
}
|
|
|
|
}
|
2008-06-10 18:06:08 +02:00
|
|
|
LeaveCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-06-23 21:08:10 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
WARN("%08x\n", hr);
|
2003-09-11 23:18:36 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BaseMemAllocator_ReleaseBuffer(IMemAllocator * iface, IMediaSample * pSample)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
BaseMemAllocator *This = (BaseMemAllocator *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
StdMediaSample2 * pStdSample = (StdMediaSample2 *)pSample;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2005-08-22 11:27:41 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, pSample);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
/* FIXME: make sure that sample is currently on the used list */
|
|
|
|
|
|
|
|
/* FIXME: we should probably check the ref count on the sample before freeing
|
|
|
|
* it to make sure that it is not still in use */
|
2008-06-10 18:06:08 +02:00
|
|
|
EnterCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
|
|
|
if (!This->bCommitted)
|
|
|
|
ERR("Releasing a buffer when the allocator is not committed?!?\n");
|
|
|
|
|
|
|
|
/* remove from used_list */
|
|
|
|
list_remove(&pStdSample->listentry);
|
|
|
|
|
|
|
|
list_add_head(&This->free_list, &pStdSample->listentry);
|
|
|
|
|
|
|
|
if (list_empty(&This->used_list) && This->bDecommitQueued && This->bCommitted)
|
|
|
|
{
|
|
|
|
HRESULT hrfree;
|
|
|
|
|
2008-06-16 02:52:09 +02:00
|
|
|
if (This->lWaiting != 0)
|
|
|
|
ERR("Waiting: %d\n", This->lWaiting);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
This->bCommitted = FALSE;
|
|
|
|
This->bDecommitQueued = FALSE;
|
|
|
|
|
|
|
|
CloseHandle(This->hSemWaiting);
|
|
|
|
This->hSemWaiting = NULL;
|
|
|
|
|
|
|
|
if (FAILED(hrfree = This->fnFree(iface)))
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("fnFree failed with error 0x%x\n", hrfree);
|
2003-09-11 23:18:36 +02:00
|
|
|
}
|
|
|
|
}
|
2008-06-10 18:06:08 +02:00
|
|
|
LeaveCriticalSection(This->pCritSect);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
/* notify a waiting thread that there is now a free buffer */
|
2007-04-04 14:07:31 +02:00
|
|
|
if (This->hSemWaiting && !ReleaseSemaphore(This->hSemWaiting, 1, NULL))
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
2007-01-05 13:05:20 +01:00
|
|
|
ERR("ReleaseSemaphore failed with error %u\n", GetLastError());
|
2003-09-11 23:18:36 +02:00
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMemAllocatorVtbl BaseMemAllocator_VTable =
|
|
|
|
{
|
|
|
|
BaseMemAllocator_QueryInterface,
|
|
|
|
BaseMemAllocator_AddRef,
|
|
|
|
BaseMemAllocator_Release,
|
|
|
|
BaseMemAllocator_SetProperties,
|
|
|
|
BaseMemAllocator_GetProperties,
|
|
|
|
BaseMemAllocator_Commit,
|
|
|
|
BaseMemAllocator_Decommit,
|
|
|
|
BaseMemAllocator_GetBuffer,
|
|
|
|
BaseMemAllocator_ReleaseBuffer
|
|
|
|
};
|
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
HRESULT StdMediaSample2_Construct(BYTE * pbBuffer, LONG cbBuffer, IMemAllocator * pParent, StdMediaSample2 ** ppSample)
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
|
|
|
assert(pbBuffer && pParent && (cbBuffer > 0));
|
|
|
|
|
|
|
|
if (!(*ppSample = CoTaskMemAlloc(sizeof(StdMediaSample2))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
(*ppSample)->lpvtbl = &StdMediaSample2_VTable;
|
|
|
|
(*ppSample)->ref = 0;
|
|
|
|
ZeroMemory(&(*ppSample)->props, sizeof((*ppSample)->props));
|
|
|
|
|
|
|
|
/* NOTE: no need to AddRef as the parent is guaranteed to be around
|
|
|
|
* at least as long as us and we don't want to create circular
|
|
|
|
* dependencies on the ref count */
|
|
|
|
(*ppSample)->pParent = pParent;
|
|
|
|
(*ppSample)->props.cbData = sizeof(AM_SAMPLE2_PROPERTIES);
|
|
|
|
(*ppSample)->props.cbBuffer = (*ppSample)->props.lActual = cbBuffer;
|
|
|
|
(*ppSample)->props.pbBuffer = pbBuffer;
|
|
|
|
(*ppSample)->tMediaStart = INVALID_MEDIA_TIME;
|
|
|
|
(*ppSample)->tMediaEnd = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
void StdMediaSample2_Delete(StdMediaSample2 * This)
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
|
|
|
/* NOTE: does not remove itself from the list it belongs to */
|
|
|
|
CoTaskMemFree(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_QueryInterface(IMediaSample2 * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
*ppv = (LPVOID)This;
|
|
|
|
else if (IsEqualIID(riid, &IID_IMediaSample))
|
|
|
|
*ppv = (LPVOID)This;
|
|
|
|
else if (IsEqualIID(riid, &IID_IMediaSample2))
|
|
|
|
*ppv = (LPVOID)This;
|
|
|
|
|
|
|
|
if (*ppv)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef((IUnknown *)(*ppv));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI StdMediaSample2_AddRef(IMediaSample2 * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%p)->() AddRef from %d\n", iface, ref - 1);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
return ref;
|
2003-09-11 23:18:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI StdMediaSample2_Release(IMediaSample2 * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%p)->() Release from %d\n", iface, ref + 1);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
if (!ref)
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
2007-03-13 18:26:48 +01:00
|
|
|
if (This->pParent)
|
|
|
|
IMemAllocator_ReleaseBuffer(This->pParent, (IMediaSample *)iface);
|
|
|
|
else
|
|
|
|
StdMediaSample2_Delete(This);
|
2003-09-11 23:18:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2005-01-06 20:36:47 +01:00
|
|
|
return ref;
|
2003-09-11 23:18:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_GetPointer(IMediaSample2 * iface, BYTE ** ppBuffer)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%p)\n", iface, ppBuffer);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
*ppBuffer = This->props.pbBuffer;
|
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
if (!*ppBuffer)
|
|
|
|
{
|
|
|
|
ERR("Requested an unlocked surface and trying to lock regardless\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2003-09-11 23:18:36 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long WINAPI StdMediaSample2_GetSize(IMediaSample2 * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
TRACE("StdMediaSample2_GetSize()\n");
|
|
|
|
|
|
|
|
return This->props.cbBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_GetTime(IMediaSample2 * iface, REFERENCE_TIME * pStart, REFERENCE_TIME * pEnd)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%p, %p)\n", iface, pStart, pEnd);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
if (!(This->props.dwSampleFlags & AM_SAMPLE_TIMEVALID))
|
|
|
|
hr = VFW_E_SAMPLE_TIME_NOT_SET;
|
|
|
|
else if (!(This->props.dwSampleFlags & AM_SAMPLE_STOPVALID))
|
|
|
|
{
|
|
|
|
*pStart = This->props.tStart;
|
|
|
|
*pEnd = This->props.tStart + 1;
|
|
|
|
|
|
|
|
hr = VFW_S_NO_STOP_TIME;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pStart = This->props.tStart;
|
|
|
|
*pEnd = This->props.tStop;
|
|
|
|
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_SetTime(IMediaSample2 * iface, REFERENCE_TIME * pStart, REFERENCE_TIME * pEnd)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%p, %p)\n", iface, pStart, pEnd);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
if (pStart)
|
|
|
|
{
|
|
|
|
This->props.tStart = *pStart;
|
|
|
|
This->props.dwSampleFlags |= AM_SAMPLE_TIMEVALID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
This->props.dwSampleFlags &= ~AM_SAMPLE_TIMEVALID;
|
|
|
|
|
|
|
|
if (pEnd)
|
|
|
|
{
|
|
|
|
This->props.tStop = *pEnd;
|
|
|
|
This->props.dwSampleFlags |= AM_SAMPLE_STOPVALID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
This->props.dwSampleFlags &= ~AM_SAMPLE_STOPVALID;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_IsSyncPoint(IMediaSample2 * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->()\n", iface);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return (This->props.dwSampleFlags & AM_SAMPLE_SPLICEPOINT) ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_SetSyncPoint(IMediaSample2 * iface, BOOL bIsSyncPoint)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%s)\n", iface, bIsSyncPoint ? "TRUE" : "FALSE");
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-04-16 23:24:16 +02:00
|
|
|
if (bIsSyncPoint)
|
|
|
|
This->props.dwSampleFlags |= AM_SAMPLE_SPLICEPOINT;
|
|
|
|
else
|
|
|
|
This->props.dwSampleFlags &= ~AM_SAMPLE_SPLICEPOINT;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_IsPreroll(IMediaSample2 * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->()\n", iface);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return (This->props.dwSampleFlags & AM_SAMPLE_PREROLL) ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_SetPreroll(IMediaSample2 * iface, BOOL bIsPreroll)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%s)\n", iface, bIsPreroll ? "TRUE" : "FALSE");
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-04-16 23:24:16 +02:00
|
|
|
if (bIsPreroll)
|
|
|
|
This->props.dwSampleFlags |= AM_SAMPLE_PREROLL;
|
2008-04-22 22:37:05 +02:00
|
|
|
else
|
|
|
|
This->props.dwSampleFlags &= ~AM_SAMPLE_PREROLL;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG WINAPI StdMediaSample2_GetActualDataLength(IMediaSample2 * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->()\n", iface);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return This->props.lActual;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_SetActualDataLength(IMediaSample2 * iface, LONG len)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%d)\n", iface, len);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
if ((len > This->props.cbBuffer) || (len < 0))
|
2008-06-23 21:08:10 +02:00
|
|
|
{
|
|
|
|
WARN("Tried to set length to %d, while max is %d\n", len, This->props.cbBuffer);
|
2003-09-11 23:18:36 +02:00
|
|
|
return VFW_E_BUFFER_OVERFLOW;
|
2008-06-23 21:08:10 +02:00
|
|
|
}
|
2003-09-11 23:18:36 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
This->props.lActual = len;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_GetMediaType(IMediaSample2 * iface, AM_MEDIA_TYPE ** ppMediaType)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%p)\n", iface, ppMediaType);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2004-12-20 18:07:17 +01:00
|
|
|
if (!This->props.pMediaType) {
|
|
|
|
/* Make sure we return a NULL pointer (required by native Quartz dll) */
|
|
|
|
if (ppMediaType)
|
|
|
|
*ppMediaType = NULL;
|
2003-09-11 23:18:36 +02:00
|
|
|
return S_FALSE;
|
2004-12-20 18:07:17 +01:00
|
|
|
}
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
if (!(*ppMediaType = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return CopyMediaType(*ppMediaType, This->props.pMediaType);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_SetMediaType(IMediaSample2 * iface, AM_MEDIA_TYPE * pMediaType)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%p)\n", iface, pMediaType);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
if (This->props.pMediaType)
|
2005-05-18 15:25:20 +02:00
|
|
|
FreeMediaType(This->props.pMediaType);
|
2003-09-11 23:18:36 +02:00
|
|
|
else if (!(This->props.pMediaType = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return CopyMediaType(This->props.pMediaType, pMediaType);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_IsDiscontinuity(IMediaSample2 * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->()\n", iface);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return (This->props.dwSampleFlags & AM_SAMPLE_DATADISCONTINUITY) ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_SetDiscontinuity(IMediaSample2 * iface, BOOL bIsDiscontinuity)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%s)\n", iface, bIsDiscontinuity ? "TRUE" : "FALSE");
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2007-04-07 14:42:54 +02:00
|
|
|
if (bIsDiscontinuity)
|
|
|
|
This->props.dwSampleFlags |= AM_SAMPLE_DATADISCONTINUITY;
|
|
|
|
else
|
|
|
|
This->props.dwSampleFlags &= ~AM_SAMPLE_DATADISCONTINUITY;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_GetMediaTime(IMediaSample2 * iface, LONGLONG * pStart, LONGLONG * pEnd)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%p, %p)\n", iface, pStart, pEnd);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
if (This->tMediaStart == INVALID_MEDIA_TIME)
|
|
|
|
return VFW_E_MEDIA_TIME_NOT_SET;
|
|
|
|
|
|
|
|
*pStart = This->tMediaStart;
|
|
|
|
*pEnd = This->tMediaEnd;
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_SetMediaTime(IMediaSample2 * iface, LONGLONG * pStart, LONGLONG * pEnd)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%p, %p)\n", iface, pStart, pEnd);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
if (pStart)
|
|
|
|
This->tMediaStart = *pStart;
|
|
|
|
else
|
|
|
|
This->tMediaStart = INVALID_MEDIA_TIME;
|
|
|
|
|
|
|
|
if (pEnd)
|
|
|
|
This->tMediaEnd = *pEnd;
|
|
|
|
else
|
|
|
|
This->tMediaEnd = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_GetProperties(IMediaSample2 * iface, DWORD cbProperties, BYTE * pbProperties)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%d, %p)\n", iface, cbProperties, pbProperties);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
memcpy(pbProperties, &This->props, min(cbProperties, sizeof(This->props)));
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI StdMediaSample2_SetProperties(IMediaSample2 * iface, DWORD cbProperties, const BYTE * pbProperties)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMediaSample2 *This = (StdMediaSample2 *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-07-28 20:29:18 +02:00
|
|
|
TRACE("(%p)->(%d, %p)\n", iface, cbProperties, pbProperties);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
/* NOTE: pbBuffer and cbBuffer are read-only */
|
|
|
|
memcpy(&This->props, pbProperties, min(cbProperties, AM_SAMPLE2_PROP_SIZE_WRITABLE));
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMediaSample2Vtbl StdMediaSample2_VTable =
|
|
|
|
{
|
|
|
|
StdMediaSample2_QueryInterface,
|
|
|
|
StdMediaSample2_AddRef,
|
|
|
|
StdMediaSample2_Release,
|
|
|
|
StdMediaSample2_GetPointer,
|
|
|
|
StdMediaSample2_GetSize,
|
|
|
|
StdMediaSample2_GetTime,
|
|
|
|
StdMediaSample2_SetTime,
|
|
|
|
StdMediaSample2_IsSyncPoint,
|
|
|
|
StdMediaSample2_SetSyncPoint,
|
|
|
|
StdMediaSample2_IsPreroll,
|
|
|
|
StdMediaSample2_SetPreroll,
|
|
|
|
StdMediaSample2_GetActualDataLength,
|
|
|
|
StdMediaSample2_SetActualDataLength,
|
|
|
|
StdMediaSample2_GetMediaType,
|
|
|
|
StdMediaSample2_SetMediaType,
|
|
|
|
StdMediaSample2_IsDiscontinuity,
|
|
|
|
StdMediaSample2_SetDiscontinuity,
|
|
|
|
StdMediaSample2_GetMediaTime,
|
|
|
|
StdMediaSample2_SetMediaTime,
|
|
|
|
StdMediaSample2_GetProperties,
|
|
|
|
StdMediaSample2_SetProperties
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct StdMemAllocator
|
|
|
|
{
|
|
|
|
BaseMemAllocator base;
|
2008-06-10 18:06:08 +02:00
|
|
|
CRITICAL_SECTION csState;
|
2003-09-11 23:18:36 +02:00
|
|
|
LPVOID pMemory;
|
|
|
|
} StdMemAllocator;
|
|
|
|
|
|
|
|
static HRESULT StdMemAllocator_Alloc(IMemAllocator * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMemAllocator *This = (StdMemAllocator *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
StdMediaSample2 * pSample = NULL;
|
|
|
|
SYSTEM_INFO si;
|
|
|
|
long i;
|
|
|
|
|
|
|
|
assert(list_empty(&This->base.free_list));
|
|
|
|
|
|
|
|
/* check alignment */
|
|
|
|
GetSystemInfo(&si);
|
|
|
|
|
|
|
|
/* we do not allow a courser alignment than the OS page size */
|
2008-06-10 18:06:08 +02:00
|
|
|
if ((si.dwPageSize % This->base.props.cbAlign) != 0)
|
2003-09-11 23:18:36 +02:00
|
|
|
return VFW_E_BADALIGN;
|
|
|
|
|
|
|
|
/* FIXME: each sample has to have its buffer start on the right alignment.
|
|
|
|
* We don't do this at the moment */
|
|
|
|
|
|
|
|
/* allocate memory */
|
2008-06-10 18:06:08 +02:00
|
|
|
This->pMemory = VirtualAlloc(NULL, (This->base.props.cbBuffer + This->base.props.cbPrefix) * This->base.props.cBuffers, MEM_COMMIT, PAGE_READWRITE);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
for (i = This->base.props.cBuffers - 1; i >= 0; i--)
|
2003-09-11 23:18:36 +02:00
|
|
|
{
|
|
|
|
/* pbBuffer does not start at the base address, it starts at base + cbPrefix */
|
2008-06-10 18:06:08 +02:00
|
|
|
BYTE * pbBuffer = (BYTE *)This->pMemory + i * (This->base.props.cbBuffer + This->base.props.cbPrefix) + This->base.props.cbPrefix;
|
2003-09-11 23:18:36 +02:00
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
StdMediaSample2_Construct(pbBuffer, This->base.props.cbBuffer, iface, &pSample);
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
list_add_head(&This->base.free_list, &pSample->listentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT StdMemAllocator_Free(IMemAllocator * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
StdMemAllocator *This = (StdMemAllocator *)iface;
|
2003-09-11 23:18:36 +02:00
|
|
|
struct list * cursor;
|
|
|
|
|
2007-03-13 18:26:48 +01:00
|
|
|
if (!list_empty(&This->base.used_list))
|
|
|
|
{
|
|
|
|
WARN("Freeing allocator with outstanding samples!\n");
|
|
|
|
while ((cursor = list_head(&This->base.used_list)) != NULL)
|
|
|
|
{
|
|
|
|
StdMediaSample2 *pSample;
|
|
|
|
list_remove(cursor);
|
|
|
|
pSample = LIST_ENTRY(cursor, StdMediaSample2, listentry);
|
|
|
|
pSample->pParent = NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-09-11 23:18:36 +02:00
|
|
|
|
|
|
|
while ((cursor = list_head(&This->base.free_list)) != NULL)
|
|
|
|
{
|
|
|
|
list_remove(cursor);
|
|
|
|
StdMediaSample2_Delete(LIST_ENTRY(cursor, StdMediaSample2, listentry));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free memory */
|
|
|
|
if (!VirtualFree(This->pMemory, 0, MEM_RELEASE))
|
|
|
|
{
|
2007-01-05 13:05:20 +01:00
|
|
|
ERR("Couldn't free memory. Error: %u\n", GetLastError());
|
2003-09-11 23:18:36 +02:00
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
static void StdMemAllocator_Destroy(IMemAllocator *iface)
|
|
|
|
{
|
|
|
|
StdMemAllocator *This = (StdMemAllocator *)iface;
|
|
|
|
|
|
|
|
This->csState.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&This->csState);
|
|
|
|
|
|
|
|
CoTaskMemFree(This);
|
|
|
|
}
|
|
|
|
|
2003-09-11 23:18:36 +02:00
|
|
|
HRESULT StdMemAllocator_create(LPUNKNOWN lpUnkOuter, LPVOID * ppv)
|
|
|
|
{
|
|
|
|
StdMemAllocator * pMemAlloc;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (lpUnkOuter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
|
|
|
if (!(pMemAlloc = CoTaskMemAlloc(sizeof(*pMemAlloc))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
InitializeCriticalSection(&pMemAlloc->csState);
|
|
|
|
pMemAlloc->csState.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": StdMemAllocator.csState");
|
|
|
|
|
2003-09-11 23:18:36 +02:00
|
|
|
pMemAlloc->pMemory = NULL;
|
|
|
|
|
2008-06-10 18:06:08 +02:00
|
|
|
if (SUCCEEDED(hr = BaseMemAllocator_Init(StdMemAllocator_Alloc, StdMemAllocator_Free, NULL, NULL, NULL, StdMemAllocator_Destroy, &pMemAlloc->csState, &pMemAlloc->base)))
|
2003-09-11 23:18:36 +02:00
|
|
|
*ppv = (LPVOID)pMemAlloc;
|
|
|
|
else
|
|
|
|
CoTaskMemFree(pMemAlloc);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|