summaryrefslogtreecommitdiffstats
path: root/loader/dshow/allocator.c
diff options
context:
space:
mode:
authorarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-08-16 00:50:02 +0000
committerarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-08-16 00:50:02 +0000
commitbda27f2adc68d6065d7a7df1e6558c062efe41f1 (patch)
tree4077a416a09134894f71166eef48f9f39782fc9d /loader/dshow/allocator.c
parentfda7100c9d34a2c5dccddfd25e87193abe55a152 (diff)
downloadmpv-bda27f2adc68d6065d7a7df1e6558c062efe41f1.tar.bz2
mpv-bda27f2adc68d6065d7a7df1e6558c062efe41f1.tar.xz
big avifile sync - from now we have common code
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1546 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'loader/dshow/allocator.c')
-rw-r--r--loader/dshow/allocator.c183
1 files changed, 97 insertions, 86 deletions
diff --git a/loader/dshow/allocator.c b/loader/dshow/allocator.c
index e4a209626b..73b75b6fde 100644
--- a/loader/dshow/allocator.c
+++ b/loader/dshow/allocator.c
@@ -1,47 +1,35 @@
-#include <stdio.h>
#include "allocator.h"
#include <com.h>
-#define E_NOTIMPL 0x80004001
+#include <wine/winerror.h>
+#include <stdio.h>
+
+//#undef Debug
+//#define Debug
+
using namespace std;
class AllocatorKeeper
{
public:
AllocatorKeeper()
- {
+ {
RegisterComClass(&CLSID_MemoryAllocator, MemAllocator::CreateAllocator);
}
+ ~AllocatorKeeper()
+ {
+ UnregisterComClass(&CLSID_MemoryAllocator, MemAllocator::CreateAllocator);
+ }
};
static AllocatorKeeper keeper;
+
+
GUID MemAllocator::interfaces[]=
{
IID_IUnknown,
IID_IMemAllocator,
};
-IMPLEMENT_IUNKNOWN(MemAllocator)
-MemAllocator::MemAllocator()
- :refcount(1)
-{
- Debug printf("MemAllocator::MemAllocator() called\n");
- vt=new IMemAllocator_vt;
- vt->QueryInterface = QueryInterface;
- vt->AddRef = AddRef;
- vt->Release = Release;
- vt->SetProperties = SetProperties;
- vt->GetProperties = GetProperties;
- vt->Commit = Commit;
- vt->Decommit = Decommit;
- vt->GetBuffer = GetBuffer;
- vt->ReleaseBuffer = ReleaseBuffer;
-
- props.cBuffers=1;
- props.cbBuffer=65536;/* :/ */
- props.cbAlign=props.cbPrefix=0;
-
- new_pointer=0;
- modified_sample=0;
-}
+IMPLEMENT_IUNKNOWN(MemAllocator)
long MemAllocator::CreateAllocator(GUID* clsid, GUID* iid, void** ppv)
{
@@ -49,7 +37,7 @@ long MemAllocator::CreateAllocator(GUID* clsid, GUID* iid, void** ppv)
*ppv=0;
if(memcmp(clsid, &CLSID_MemoryAllocator, sizeof(GUID)))
return -1;
-
+
IMemAllocator* p=new MemAllocator;
int result=p->vt->QueryInterface((IUnknown*)p, iid, ppv);
p->vt->Release((IUnknown*)p);
@@ -57,56 +45,52 @@ long MemAllocator::CreateAllocator(GUID* clsid, GUID* iid, void** ppv)
}
-/*
- long cBuffers;
- long cbBuffer;
- long cbAlign;
- long cbPrefix;
-*/
-HRESULT STDCALL MemAllocator::SetProperties (
- IMemAllocator * This,
- /* [in] */ ALLOCATOR_PROPERTIES *pRequest,
- /* [out] */ ALLOCATOR_PROPERTIES *pActual)
+static HRESULT STDCALL MemAllocator_SetProperties(IMemAllocator * This,
+ /* [in] */ ALLOCATOR_PROPERTIES *pRequest,
+ /* [out] */ ALLOCATOR_PROPERTIES *pActual)
{
- Debug printf("MemAllocator::SetProperties() called\n");
- if(!pRequest)return 0x80004003;
- if(!pActual)return 0x80004003;
- if(pRequest->cBuffers<=0)return -1;
- if(pRequest->cbBuffer<=0)return -1;
- MemAllocator* me=(MemAllocator*)This;
- if(me->used_list.size() || me->free_list.size())return -1;
- me->props=*pRequest;
- *pActual=*pRequest;
+ Debug printf("MemAllocator_SetProperties() called\n");
+ if (!pRequest || !pActual)
+ return E_INVALIDARG;
+ if (pRequest->cBuffers<=0 || pRequest->cbBuffer<=0)
+ return E_FAIL;
+ MemAllocator* me = (MemAllocator*)This;
+ if (me->used_list.size() || me->free_list.size())
+ return E_FAIL;
+ me->props = *pRequest;
+ *pActual = *pRequest;
return 0;
}
-HRESULT STDCALL MemAllocator::GetProperties (
- IMemAllocator * This,
- /* [out] */ ALLOCATOR_PROPERTIES *pProps)
+static HRESULT STDCALL MemAllocator_GetProperties(IMemAllocator * This,
+ /* [out] */ ALLOCATOR_PROPERTIES *pProps)
{
- Debug printf("MemAllocator::GetProperties() called\n");
- if(!pProps)return -1;
- if(((MemAllocator*)This)->props.cbBuffer<0)return -1;
+ Debug printf("MemAllocator_GetProperties(%p) called\n", This);
+ if (!pProps)
+ return E_INVALIDARG;
+ if (((MemAllocator*)This)->props.cbBuffer<0)
+ return E_FAIL;
*pProps=((MemAllocator*)This)->props;
return 0;
}
-HRESULT STDCALL MemAllocator::Commit (
- IMemAllocator * This)
+static HRESULT STDCALL MemAllocator_Commit(IMemAllocator * This)
{
- Debug printf("MemAllocator::Commit() called\n");
+ Debug printf("MemAllocator_Commit(%p) called\n", This);
MemAllocator* me=(MemAllocator*)This;
- if(((MemAllocator*)This)->props.cbBuffer<0)return -1;
- if(me->used_list.size() || me->free_list.size())return -1;
- for(int i=0; i<me->props.cBuffers; i++)
+ if (((MemAllocator*)This)->props.cbBuffer < 0)
+ return E_FAIL;
+ if (me->used_list.size() || me->free_list.size())
+ return E_INVALIDARG;
+ for(int i = 0; i<me->props.cBuffers; i++)
me->free_list.push_back(new CMediaSample(me, me->props.cbBuffer));
+
return 0;
}
-HRESULT STDCALL MemAllocator::Decommit (
- IMemAllocator * This)
+static HRESULT STDCALL MemAllocator_Decommit(IMemAllocator * This)
{
- Debug printf("MemAllocator::Decommit() called\n");
+ Debug printf("MemAllocator_Decommit(%p) called\n", This);
MemAllocator* me=(MemAllocator*)This;
list<CMediaSample*>::iterator it;
for(it=me->free_list.begin(); it!=me->free_list.end(); it++)
@@ -114,54 +98,81 @@ HRESULT STDCALL MemAllocator::Decommit (
for(it=me->used_list.begin(); it!=me->used_list.end(); it++)
delete *it;
me->free_list.clear();
- me->used_list.clear();
+ me->used_list.clear();
return 0;
}
-HRESULT STDCALL MemAllocator::GetBuffer (
- IMemAllocator * This,
- /* [out] */ IMediaSample **ppBuffer,
- /* [in] */ REFERENCE_TIME *pStartTime,
- /* [in] */ REFERENCE_TIME *pEndTime,
- /* [in] */ DWORD dwFlags)
+static HRESULT STDCALL MemAllocator_GetBuffer(IMemAllocator * This,
+ /* [out] */ IMediaSample **ppBuffer,
+ /* [in] */ REFERENCE_TIME *pStartTime,
+ /* [in] */ REFERENCE_TIME *pEndTime,
+ /* [in] */ DWORD dwFlags)
{
- Debug printf("%x: MemAllocator::GetBuffer() called\n", This);
- MemAllocator* me=(MemAllocator*)This;
- if(me->free_list.size()==0)
+ Debug printf("MemAllocator_GetBuffer(%p) called\n", This);
+ MemAllocator* me = (MemAllocator*)This;
+ if (me->free_list.size() == 0)
{
Debug printf("No samples available\n");
- return -1;//should block here if no samples are available
- }
- list<CMediaSample*>::iterator it=me->free_list.begin();
+ return E_FAIL;//should block here if no samples are available
+ }
+ list<CMediaSample*>::iterator it = me->free_list.begin();
me->used_list.push_back(*it);
- *ppBuffer=*it;
+ *ppBuffer = *it;
(*ppBuffer)->vt->AddRef((IUnknown*)*ppBuffer);
- if(me->new_pointer)
+ if (me->new_pointer)
{
if(me->modified_sample)
me->modified_sample->ResetPointer();
- (*it)->SetPointer(me->new_pointer);
+ (*it)->SetPointer(me->new_pointer);
me->modified_sample=*it;
- me->new_pointer=0;
+ me->new_pointer = 0;
}
me->free_list.remove(*it);
return 0;
}
-HRESULT STDCALL MemAllocator::ReleaseBuffer (
- IMemAllocator * This,
- /* [in] */ IMediaSample *pBuffer)
+static HRESULT STDCALL MemAllocator_ReleaseBuffer(IMemAllocator * This,
+ /* [in] */ IMediaSample *pBuffer)
{
- Debug printf("%x: MemAllocator::ReleaseBuffer() called\n", This);
- MemAllocator* me=(MemAllocator*)This;
+ Debug printf("MemAllocator_ReleaseBuffer(%p) called\n", This);
+ MemAllocator* me = (MemAllocator*)This;
list<CMediaSample*>::iterator it;
- for(it=me->used_list.begin(); it!=me->used_list.end(); it++)
- if(*it==pBuffer)
+ for (it = me->used_list.begin(); it != me->used_list.end(); it++)
+ if (*it == pBuffer)
{
me->used_list.erase(it);
me->free_list.push_back((CMediaSample*)pBuffer);
return 0;
}
Debug printf("Releasing unknown buffer\n");
- return -1;
+ return E_FAIL;
+}
+
+MemAllocator::MemAllocator()
+{
+ Debug printf("MemAllocator::MemAllocator() called\n");
+ vt = new IMemAllocator_vt;
+ vt->QueryInterface = QueryInterface;
+ vt->AddRef = AddRef;
+ vt->Release = Release;
+ vt->SetProperties = MemAllocator_SetProperties;
+ vt->GetProperties = MemAllocator_GetProperties;
+ vt->Commit = MemAllocator_Commit;
+ vt->Decommit = MemAllocator_Decommit;
+ vt->GetBuffer = MemAllocator_GetBuffer;
+ vt->ReleaseBuffer = MemAllocator_ReleaseBuffer;
+
+ refcount = 1;
+ props.cBuffers = 1;
+ props.cbBuffer = 65536; /* :/ */
+ props.cbAlign = props.cbPrefix = 0;
+
+ new_pointer=0;
+ modified_sample=0;
+}
+
+MemAllocator::~MemAllocator()
+{
+ Debug printf("MemAllocator::~MemAllocator() called\n");
+ delete vt;
}