Mercurial > mplayer.hg
changeset 3467:e3bbf44dbab2
avifile sync
author | arpi |
---|---|
date | Tue, 11 Dec 2001 23:29:24 +0000 |
parents | b6caac381405 |
children | a601fd57875d |
files | loader/dshow/DS_Filter.c loader/dshow/DS_Filter.h loader/dshow/allocator.c loader/dshow/cmediasample.c loader/dshow/cmediasample.h loader/dshow/guids.c loader/dshow/guids.h loader/dshow/inputpin.c loader/dshow/inputpin.h loader/dshow/interfaces.h loader/dshow/outputpin.c |
diffstat | 11 files changed, 314 insertions(+), 137 deletions(-) [+] |
line wrap: on
line diff
--- a/loader/dshow/DS_Filter.c Tue Dec 11 23:29:11 2001 +0000 +++ b/loader/dshow/DS_Filter.c Tue Dec 11 23:29:24 2001 +0000 @@ -12,7 +12,7 @@ { HRESULT hr; - if (This->m_iState != 1) + if (This->m_pAll) return; //Debug printf("DS_Filter_Start(%p)\n", This); @@ -30,23 +30,14 @@ return; } This->m_pImp->vt->NotifyAllocator(This->m_pImp, This->m_pAll, 0); - This->m_iState = 2; } static void DS_Filter_Stop(DS_Filter* This) { - if (This->m_iState == 2) + if (This->m_pAll) { - This->m_iState = 1; //Debug printf("DS_Filter_Stop(%p)\n", This); - if (This->m_pFilter) - { - //printf("vt: %p\n", m_pFilter->vt); - //printf("vtstop %p\n", m_pFilter->vt->Stop); - This->m_pFilter->vt->Stop(This->m_pFilter); // causes weird crash ??? FIXME - } - else - printf("WARNING: DS_Filter::Stop() m_pFilter is NULL!\n"); + This->m_pFilter->vt->Stop(This->m_pFilter); // causes weird crash ??? FIXME This->m_pAll->vt->Release((IUnknown*)This->m_pAll); This->m_pAll = 0; } @@ -56,8 +47,6 @@ { This->Stop(This); - This->m_iState = 0; - if (This->m_pOurInput) This->m_pOurInput->vt->Release((IUnknown*)This->m_pOurInput); if (This->m_pInputPin) @@ -93,6 +82,9 @@ AM_MEDIA_TYPE* in_fmt, AM_MEDIA_TYPE* out_fmt) { + int init = 0; + char eb[250]; + const char* em = NULL; DS_Filter* This = (DS_Filter*) malloc(sizeof(DS_Filter)); if (!This) return NULL; @@ -108,7 +100,6 @@ This->m_pOurOutput = NULL; This->m_pAll = NULL; This->m_pImp = NULL; - This->m_iState = 0; This->Start = DS_Filter_Start; This->Stop = DS_Filter_Stop; @@ -127,40 +118,40 @@ This->m_iHandle = LoadLibraryA(dllname); if (!This->m_iHandle) { - printf("Could not open DirectShow DLL: %.200s\n", dllname); + em = "could not open DirectShow DLL"; break; } func = (GETCLASS)GetProcAddress(This->m_iHandle, "DllGetClassObject"); if (!func) { - printf("Illegal or corrupt DirectShow DLL: %.200s\n", dllname); + em = "illegal or corrupt DirectShow DLL"; break; } result = func(id, &IID_IClassFactory, (void**)&factory); if (result || !factory) { - printf("No such class object\n"); + em = "no such class object"; break; } result = factory->vt->CreateInstance(factory, 0, &IID_IUnknown, (void**)&object); factory->vt->Release((IUnknown*)factory); if (result || !object) { - printf("Class factory failure\n"); + em = "class factory failure"; break; } result = object->vt->QueryInterface(object, &IID_IBaseFilter, (void**)&This->m_pFilter); object->vt->Release((IUnknown*)object); if (result || !This->m_pFilter) { - printf("Object does not have IBaseFilter interface\n"); + em = "object does not have IBaseFilter interface"; break; } // enumerate pins result = This->m_pFilter->vt->EnumPins(This->m_pFilter, &enum_pins); if (result || !enum_pins) { - printf("Could not enumerate pins\n"); + em = "could not enumerate pins"; break; } @@ -186,12 +177,12 @@ } if (!This->m_pInputPin) { - printf("Input pin not found\n"); + em = "could not find input pin"; break; } if (!This->m_pOutputPin) { - printf("Output pin not found\n"); + em = "could not find output pin"; break; } result = This->m_pInputPin->vt->QueryInterface((IUnknown*)This->m_pInputPin, @@ -199,7 +190,7 @@ (void**)&This->m_pImp); if (result) { - printf("Error getting IMemInputPin interface\n"); + em = "could not get IMemInputPin interface"; break; } @@ -208,7 +199,7 @@ result = This->m_pInputPin->vt->QueryAccept(This->m_pInputPin, This->m_pOurType); if (result) { - printf("Source format is not accepted\n"); + em = "source format is not accepted"; break; } This->m_pParentFilter = CBaseFilter2Create(); @@ -221,7 +212,7 @@ This->m_pOurType); if (result) { - printf("Error connecting to input pin\n"); + em = "could not connect to input pin"; break; } @@ -232,19 +223,19 @@ This->m_pDestType); if (result) { - //printf("Tracking ACELP %d 0%x\n", result); - printf("Error connecting to output pin\n"); + em = "could not connect to output pin"; break; } printf("Using DirectShow codec: %s\n", dllname); - This->m_iState = 1; + init++; break; } - if (This->m_iState != 1) + if (!init) { DS_Filter_Destroy(This); + printf("Warning: DS_Filter() %s. (DLL=%.200s)\n", em, dllname); This = 0; } return This;
--- a/loader/dshow/DS_Filter.h Tue Dec 11 23:29:11 2001 +0000 +++ b/loader/dshow/DS_Filter.h Tue Dec 11 23:29:24 2001 +0000 @@ -29,7 +29,6 @@ AM_MEDIA_TYPE *m_pOurType, *m_pDestType; IMemAllocator* m_pAll; IMemInputPin* m_pImp; - int m_iState; void ( *Start )(DS_Filter*); void ( *Stop )(DS_Filter*);
--- a/loader/dshow/allocator.c Tue Dec 11 23:29:11 2001 +0000 +++ b/loader/dshow/allocator.c Tue Dec 11 23:29:24 2001 +0000 @@ -69,6 +69,7 @@ static inline avm_list_t* avm_list_del_head(avm_list_t* head) { avm_list_t* n = 0; + if (head) { if (head->next != head) @@ -77,10 +78,8 @@ head->prev->next = head->next; head->next->prev = head->prev; } - free(head); } - return n; } @@ -130,8 +129,12 @@ return E_FAIL; if (me->used_list != 0 || me->free_list != 0) return E_FAIL; - me->props = *pRequest; + *pActual = *pRequest; + //if (pActual->cbBuffer == 2) + // pActual->cbBuffer = 576; + + me->props = *pActual; return 0; } @@ -162,8 +165,9 @@ { CMediaSample* sample = CMediaSampleCreate((IMemAllocator*)me, me->props.cbBuffer); + if (!sample) + return E_OUTOFMEMORY; //printf("FREEEEEEEEEEEE ADDED %p\n", sample); - me->free_list = avm_list_add_tail(me->free_list, sample); //avm_list_print(me->free_list); } @@ -179,10 +183,8 @@ //printf("Deleted mem %p: %d %d\n", me, me->free_list.size(), me->used_list.size()); while (me->used_list) { - CMediaSample* sample = (CMediaSample*) me->used_list->member; - //printf("****************** Decommiting USED %p\n", sample); - //sample->vt->Release((IUnknown*)sample); - CMediaSample_Destroy((CMediaSample*)sample); + me->free_list = avm_list_add_tail(me->free_list, + (CMediaSample*) me->used_list->member); me->used_list = avm_list_del_head(me->used_list); } @@ -192,7 +194,7 @@ //printf("****************** Decommiting FREE %p\n", sample); //sample->vt->Release((IUnknown*)sample); CMediaSample_Destroy((CMediaSample*)sample); - me->free_list = avm_list_del_head(me->free_list); + me->free_list = avm_list_del_head(me->free_list); } return 0; @@ -206,8 +208,9 @@ { MemAllocator* me = (MemAllocator*)This; CMediaSample* sample; - Debug printf("MemAllocator_GetBuffer(%p) called %d %d\n", This, + Debug printf("MemAllocator_ReleaseBuffer(%p) called %d %d\n", This, avm_list_size(me->used_list), avm_list_size(me->free_list)); + if (!me->free_list) { Debug printf("No samples available\n"); @@ -218,8 +221,6 @@ me->free_list = avm_list_del_head(me->free_list); me->used_list = avm_list_add_tail(me->used_list, sample); - //printf("MemAllocator getbuffer: %p %d %d\n", sample, avm_list_size(me->used_list), avm_list_size(me->free_list)); - *ppBuffer = (IMediaSample*) sample; sample->vt->AddRef((IUnknown*) sample); if (me->new_pointer) @@ -236,24 +237,24 @@ static HRESULT STDCALL MemAllocator_ReleaseBuffer(IMemAllocator* This, /* [in] */ IMediaSample* pBuffer) { + avm_list_t* l; MemAllocator* me = (MemAllocator*)This; Debug printf("MemAllocator_ReleaseBuffer(%p) called %d %d\n", This, avm_list_size(me->used_list), avm_list_size(me->free_list)); - for (;;) + l = avm_list_find(me->used_list, pBuffer); + if (l) { - avm_list_t* l = avm_list_find(me->used_list, pBuffer); - if (l) + CMediaSample* sample = (CMediaSample*) l->member; + if (me->modified_sample == sample) { - CMediaSample* sample = (CMediaSample*) l->member; - me->used_list = avm_list_del_head(me->used_list); - me->free_list = avm_list_add_head(me->free_list, sample); - //printf("****************** RELEASED OK %p %p\n", me->used_list, me->free_list); - - return 0; + me->modified_sample->ResetPointer(me->modified_sample); + me->modified_sample = 0; } - else - break; + me->used_list = avm_list_del_head(me->used_list); + me->free_list = avm_list_add_head(me->free_list, sample); + //printf("****************** RELEASED OK %p %p\n", me->used_list, me->free_list); + return 0; } Debug printf("MemAllocator_ReleaseBuffer(%p) releasing unknown buffer!!!! %p\n", This, pBuffer); return E_FAIL; @@ -288,6 +289,10 @@ MemAllocator* MemAllocatorCreate() { MemAllocator* This = (MemAllocator*) malloc(sizeof(MemAllocator)); + + if (!This) + return NULL; + Debug printf("MemAllocatorCreate() called -> %p\n", This); This->refcount = 1; @@ -296,6 +301,13 @@ This->props.cbAlign = This->props.cbPrefix = 0; This->vt = (IMemAllocator_vt*) malloc(sizeof(IMemAllocator_vt)); + + if (!This->vt) + { + free(This); + return NULL; + } + This->vt->QueryInterface = MemAllocator_QueryInterface; This->vt->AddRef = MemAllocator_AddRef; This->vt->Release = MemAllocator_Release; @@ -309,8 +321,8 @@ This->SetPointer = MemAllocator_SetPointer; This->ResetPointer = MemAllocator_ResetPointer; + This->modified_sample = 0; This->new_pointer = 0; - This->modified_sample = 0; This->used_list = 0; This->free_list = 0;
--- a/loader/dshow/cmediasample.c Tue Dec 11 23:29:11 2001 +0000 +++ b/loader/dshow/cmediasample.c Tue Dec 11 23:29:24 2001 +0000 @@ -45,10 +45,11 @@ static long STDCALL CMediaSample_Release(IUnknown* This) { - CMediaSample* parent=(CMediaSample*)This; + CMediaSample* parent = (CMediaSample*)This; Debug printf("CMediaSample_Release(%p) called (new ref:%d)\n", This, ((CMediaSample*)This)->refcount-1); - if (--((CMediaSample*)This)->refcount == 0) + + if (--((CMediaSample*) This)->refcount == 0) { parent->all->vt->ReleaseBuffer((IMemAllocator*)(parent->all), (IMediaSample*)This); @@ -56,28 +57,27 @@ return 0; } -static HRESULT STDCALL CMediaSample_GetPointer(IMediaSample * This, - /* [out] */ BYTE **ppBuffer) +static HRESULT STDCALL CMediaSample_GetPointer(IMediaSample* This, + /* [out] */ BYTE** ppBuffer) { - Debug printf("CMediaSample_GetPointer(%p) called\n", This); + Debug printf("CMediaSample_GetPointer(%p) called -> %p, size: %d %d\n", This, ((CMediaSample*) This)->block, ((CMediaSample*)This)->actual_size, ((CMediaSample*)This)->size); if (!ppBuffer) return E_INVALIDARG; - *ppBuffer=(BYTE *)((CMediaSample*)This)->block; + *ppBuffer = (BYTE*) ((CMediaSample*) This)->block; return 0; } static long STDCALL CMediaSample_GetSize(IMediaSample * This) { - Debug printf("CMediaSample_GetSize(%p) called -> %d\n", - This, ((CMediaSample*)This)->size); - return ((CMediaSample*)This)->size; + Debug printf("CMediaSample_GetSize(%p) called -> %d\n", This, ((CMediaSample*) This)->size); + return ((CMediaSample*) This)->size; } static HRESULT STDCALL CMediaSample_GetTime(IMediaSample * This, /* [out] */ REFERENCE_TIME *pTimeStart, /* [out] */ REFERENCE_TIME *pTimeEnd) { - Debug printf("CMediaSample_GetTime(%p) called\n", This); + Debug printf("CMediaSample_GetTime(%p) called (UNIMPLIMENTED)\n", This); return E_NOTIMPL; } @@ -85,7 +85,7 @@ /* [in] */ REFERENCE_TIME *pTimeStart, /* [in] */ REFERENCE_TIME *pTimeEnd) { - Debug printf("CMediaSample_SetTime(%p) called\n", This); + Debug printf("CMediaSample_SetTime(%p) called (UNIMPLIMENTED)\n", This); return E_NOTIMPL; } @@ -101,7 +101,7 @@ long bIsSyncPoint) { Debug printf("CMediaSample_SetSyncPoint(%p) called\n", This); - ((CMediaSample*)This)->isSyncPoint=bIsSyncPoint; + ((CMediaSample*)This)->isSyncPoint = bIsSyncPoint; return 0; } @@ -132,12 +132,19 @@ static HRESULT STDCALL CMediaSample_SetActualDataLength(IMediaSample* This, long __MIDL_0010) { + CMediaSample* cms = (CMediaSample*)This; Debug printf("CMediaSample_SetActualDataLength(%p, %ld) called\n", This, __MIDL_0010); - if (__MIDL_0010 > ((CMediaSample*)This)->size) + if (__MIDL_0010 > cms->size) { - printf("%p: ERROR: CMediaSample buffer overflow\n", This); + char* c = cms->own_block; + Debug printf(" CMediaSample - buffer overflow %ld %d %p %p\n", + __MIDL_0010, ((CMediaSample*)This)->size, cms->own_block, cms->block); + cms->own_block = realloc(cms->own_block, __MIDL_0010); + if (c == cms->block) + cms->block = cms->own_block; + cms->size = __MIDL_0010; } - ((CMediaSample*)This)->actual_size = __MIDL_0010; + cms->actual_size = __MIDL_0010; return 0; } @@ -175,9 +182,14 @@ if (t->pbFormat) CoTaskMemFree(t->pbFormat); t = pMediaType; - t->pbFormat = (char*)CoTaskMemAlloc(t->cbFormat); - memcpy(t->pbFormat, pMediaType->pbFormat, t->cbFormat); - ((CMediaSample*)This)->type_valid=1; + if (t->cbFormat) + { + t->pbFormat = (char*)CoTaskMemAlloc(t->cbFormat); + memcpy(t->pbFormat, pMediaType->pbFormat, t->cbFormat); + } + else + t->pbFormat = 0; + ((CMediaSample*) This)->type_valid=1; return 0; } @@ -185,14 +197,15 @@ static HRESULT STDCALL CMediaSample_IsDiscontinuity(IMediaSample * This) { Debug printf("CMediaSample_IsDiscontinuity(%p) called\n", This); - return 1; + return ((CMediaSample*) This)->isDiscontinuity; } static HRESULT STDCALL CMediaSample_SetDiscontinuity(IMediaSample * This, long bDiscontinuity) { - Debug printf("CMediaSample_SetDiscontinuity(%p) called\n", This); - return E_NOTIMPL; + Debug printf("CMediaSample_SetDiscontinuity(%p) called (%ld)\n", This, bDiscontinuity); + ((CMediaSample*) This)->isDiscontinuity = bDiscontinuity; + return 0; } static HRESULT STDCALL CMediaSample_GetMediaTime(IMediaSample * This, @@ -200,7 +213,11 @@ /* [out] */ LONGLONG *pTimeEnd) { Debug printf("CMediaSample_GetMediaTime(%p) called\n", This); - return E_NOTIMPL; + if (pTimeStart) + *pTimeStart = ((CMediaSample*) This)->time_start; + if (pTimeEnd) + *pTimeEnd = ((CMediaSample*) This)->time_end; + return 0; } static HRESULT STDCALL CMediaSample_SetMediaTime(IMediaSample * This, @@ -208,9 +225,14 @@ /* [in] */ LONGLONG *pTimeEnd) { Debug printf("CMediaSample_SetMediaTime(%p) called\n", This); - return E_NOTIMPL; + if (pTimeStart) + ((CMediaSample*) This)->time_start = *pTimeStart; + if (pTimeEnd) + ((CMediaSample*) This)->time_end = *pTimeEnd; + return 0; } +// extension for direct memory write or decompressed data static void CMediaSample_SetPointer(CMediaSample* This, char* pointer) { Debug printf("CMediaSample_SetPointer(%p) called -> %p\n", This, pointer); @@ -228,8 +250,29 @@ CMediaSample* CMediaSampleCreate(IMemAllocator* allocator, int _size) { - CMediaSample* This = (CMediaSample*) malloc(sizeof( CMediaSample )); + CMediaSample* This = (CMediaSample*) malloc(sizeof(CMediaSample)); + if (!This) + return NULL; + + // some hack here! + // it looks like Acelp decoder is actually accessing + // the allocated memory before it sets the new size for it ??? + // -- maybe it's being initialized with wrong parameters + // anyway this is fixes the problem somehow with some reserves + // + // using different trick for now - in DS_Audio modify sample size + //if (_size < 0x1000) + // _size = (_size + 0xfff) & ~0xfff; + This->vt = (IMediaSample_vt*) malloc(sizeof(IMediaSample_vt)); + This->own_block = (char*) malloc(_size); + This->media_type.pbFormat = 0; + + if (!This->vt || !This->own_block) + { + CMediaSample_Destroy(This); + return NULL; + } This->vt->QueryInterface = CMediaSample_QueryInterface; This->vt->AddRef = CMediaSample_AddRef; @@ -255,10 +298,11 @@ This->size = _size; This->refcount = 0; // increased by MemAllocator This->actual_size = 0; - This->media_type.pbFormat = 0; This->isPreroll = 0; + This->isDiscontinuity = 1; + This->time_start = 0; + This->time_end = 0; This->type_valid = 0; - This->own_block = (char*) malloc(This->size); This->block = This->own_block; This->SetPointer = CMediaSample_SetPointer;
--- a/loader/dshow/cmediasample.h Tue Dec 11 23:29:11 2001 +0000 +++ b/loader/dshow/cmediasample.h Tue Dec 11 23:29:24 2001 +0000 @@ -16,9 +16,12 @@ char* own_block; int isPreroll; int isSyncPoint; + int isDiscontinuity; + LONGLONG time_start; + LONGLONG time_end; AM_MEDIA_TYPE media_type; int type_valid; - void ( *SetPointer) (CMediaSample* This,char* pointer); + void ( *SetPointer) (CMediaSample* This, char* pointer); void ( *ResetPointer) (CMediaSample* This); // FIXME replace with Set & 0 };
--- a/loader/dshow/guids.c Tue Dec 11 23:29:11 2001 +0000 +++ b/loader/dshow/guids.c Tue Dec 11 23:29:24 2001 +0000 @@ -1,5 +1,5 @@ #include "guids.h" -int DSHOW_DEBUG=0; +int DSHOW_DEBUG = 0; GUID CLSID_DivxDecompressorCF={0x82CCd3E0, 0xF71A, 0x11D0, { 0x9f, 0xe5, 0x00, 0x60, 0x97, 0x78, 0xaa, 0xaa}};
--- a/loader/dshow/guids.h Tue Dec 11 23:29:11 2001 +0000 +++ b/loader/dshow/guids.h Tue Dec 11 23:29:24 2001 +0000 @@ -2,13 +2,14 @@ #define GUIDS_H #include "com.h" -#include "wine/winbase.h" +#include "wine/module.h" +#include "wine/windef.h" #include "wine/vfw.h" extern int DSHOW_DEBUG; #define Debug if(DSHOW_DEBUG) -typedef struct _MediaType +typedef struct __attribute__((__packed__)) _MediaType { GUID majortype; //0x0 GUID subtype; //0x10 @@ -18,30 +19,31 @@ GUID formattype; //0x2c IUnknown* pUnk; //0x3c unsigned long cbFormat; //0x40 - char *pbFormat; //0x44 + char* pbFormat; //0x44 } AM_MEDIA_TYPE; typedef enum { - PINDIR_INPUT = 0, - PINDIR_OUTPUT = PINDIR_INPUT + 1 + PINDIR_INPUT = 0, + PINDIR_OUTPUT } PIN_DIRECTION; typedef long long REFERENCE_TIME; -typedef struct RECT32 +typedef struct __attribute__((__packed__)) RECT32 { int left, top, right, bottom; } RECT32; -typedef struct tagVIDEOINFOHEADER { +typedef struct __attribute__((__packed__)) tagVIDEOINFOHEADER { RECT32 rcSource; // The bit we really want to use RECT32 rcTarget; // Where the video should go unsigned long dwBitRate; // Approximate bit data rate unsigned long dwBitErrorRate; // Bit error rate for this stream REFERENCE_TIME AvgTimePerFrame; // Average time per frame (100ns units) - BITMAPINFOHEADER bmiHeader; + BITMAPINFOHEADER bmiHeader; + //int reserved[3]; } VIDEOINFOHEADER; typedef struct _AllocatorProperties
--- a/loader/dshow/inputpin.c Tue Dec 11 23:29:11 2001 +0000 +++ b/loader/dshow/inputpin.c Tue Dec 11 23:29:24 2001 +0000 @@ -17,11 +17,11 @@ typedef struct { IEnumPins_vt* vt; + DECLARE_IUNKNOWN(); IPin* pin1; IPin* pin2; int counter; GUID interfaces[2]; - DECLARE_IUNKNOWN(); } CEnumPins; static long STDCALL CEnumPins_Next(IEnumPins* This, @@ -101,12 +101,20 @@ { CEnumPins* This = (CEnumPins*) malloc(sizeof(CEnumPins)); + if (!This) + return NULL; + + This->refcount = 1; This->pin1 = p; This->pin2 = pp; This->counter = 0; - This->refcount = 1; This->vt = (IEnumPins_vt*) malloc(sizeof(IEnumPins_vt)); + if (!This->vt) + { + free(This); + return NULL; + } This->vt->QueryInterface = CEnumPins_QueryInterface; This->vt->AddRef = CEnumPins_AddRef; This->vt->Release = CEnumPins_Release; @@ -261,11 +269,21 @@ { CInputPin* This = (CInputPin*) malloc(sizeof(CInputPin)); + if (!This) + return NULL; + + This->refcount = 1; This->parent = p; - This->refcount = 1; This->type = *amt; This->vt= (IPin_vt*) malloc(sizeof(IPin_vt)); + + if (!This->vt) + { + free(This); + return NULL; + } + This->vt->QueryInterface = CInputPin_QueryInterface; This->vt->AddRef = CInputPin_AddRef; This->vt->Release = CInputPin_Release; @@ -395,9 +413,12 @@ static void CBaseFilter_Destroy(CBaseFilter* This) { - free(This->vt); - This->pin->vt->Release((IUnknown*)This->pin); - This->unused_pin->vt->Release((IUnknown*)This->unused_pin); + if (This->vt) + free(This->vt); + if (This->pin) + This->pin->vt->Release((IUnknown*)This->pin); + if (This->unused_pin) + This->unused_pin->vt->Release((IUnknown*)This->unused_pin); free(This); } @@ -406,12 +427,21 @@ CBaseFilter* CBaseFilterCreate(const AM_MEDIA_TYPE* type, CBaseFilter2* parent) { CBaseFilter* This = (CBaseFilter*) malloc(sizeof(CBaseFilter)); + if (!This) + return NULL; + This->refcount = 1; This->pin = (IPin*) CInputPinCreate(This, type); This->unused_pin = (IPin*) CRemotePinCreate(This, parent->GetPin(parent)); This->vt = (IBaseFilter_vt*) malloc(sizeof(IBaseFilter_vt)); + if (!This->vt || !This->pin || !This->unused_pin) + { + CBaseFilter_Destroy(This); + return NULL; + } + This->vt->QueryInterface = CBaseFilter_QueryInterface; This->vt->AddRef = CBaseFilter_AddRef; This->vt->Release = CBaseFilter_Release; @@ -541,8 +571,10 @@ static void CBaseFilter2_Destroy(CBaseFilter2* This) { Debug printf("CBaseFilter2_Destroy(%p) called\n", This); - This->pin->vt->Release((IUnknown*) This->pin); - free(This->vt); + if (This->pin) + This->pin->vt->Release((IUnknown*) This->pin); + if (This->vt) + free(This->vt); free(This); } @@ -559,10 +591,20 @@ { CBaseFilter2* This = (CBaseFilter2*) malloc(sizeof(CBaseFilter2)); + if (!This) + return NULL; + This->refcount = 1; This->pin = (IPin*) CRemotePin2Create(This); This->vt = (IBaseFilter_vt*) malloc(sizeof(IBaseFilter_vt)); + + if (!This->pin || !This->vt) + { + CBaseFilter2_Destroy(This); + return NULL; + } + memset(This->vt, 0, sizeof(IBaseFilter_vt)); This->vt->QueryInterface = CBaseFilter2_QueryInterface; This->vt->AddRef = CBaseFilter2_AddRef; @@ -646,6 +688,10 @@ CRemotePin* CRemotePinCreate(CBaseFilter* pt, IPin* rpin) { CRemotePin* This = (CRemotePin*) malloc(sizeof(CRemotePin)); + + if (!This) + return NULL; + Debug printf("CRemotePinCreate() called -> %p\n", This); This->parent = pt; @@ -653,6 +699,13 @@ This->refcount = 1; This->vt = (IPin_vt*) malloc(sizeof(IPin_vt)); + + if (!This->vt) + { + free(This); + return NULL; + } + memset(This->vt, 0, sizeof(IPin_vt)); This->vt->QueryInterface = CRemotePin_QueryInterface; This->vt->AddRef = CRemotePin_AddRef; @@ -698,12 +751,23 @@ CRemotePin2* CRemotePin2Create(CBaseFilter2* p) { CRemotePin2* This = (CRemotePin2*) malloc(sizeof(CRemotePin2)); + + if (!This) + return NULL; + Debug printf("CRemotePin2Create() called -> %p\n", This); This->parent = p; This->refcount = 1; This->vt = (IPin_vt*) malloc(sizeof(IPin_vt)); + + if (!This->vt) + { + free(This); + return NULL; + } + memset(This->vt, 0, sizeof(IPin_vt)); This->vt->QueryInterface = CRemotePin2_QueryInterface; This->vt->AddRef = CRemotePin2_AddRef;
--- a/loader/dshow/inputpin.h Tue Dec 11 23:29:11 2001 +0000 +++ b/loader/dshow/inputpin.h Tue Dec 11 23:29:24 2001 +0000 @@ -38,8 +38,8 @@ { IPin_vt* vt; DECLARE_IUNKNOWN(); + CBaseFilter* parent; AM_MEDIA_TYPE type; - CBaseFilter* parent; GUID interfaces[1]; };
--- a/loader/dshow/interfaces.h Tue Dec 11 23:29:11 2001 +0000 +++ b/loader/dshow/interfaces.h Tue Dec 11 23:29:24 2001 +0000 @@ -84,13 +84,17 @@ { INHERIT_IUNKNOWN(); + // retrieves a specified number of pins in the enumeration sequence.. HRESULT STDCALL ( *Next )(IEnumPins* This, /* [in] */ unsigned long cPins, /* [size_is][out] */ IPin** ppPins, /* [out] */ unsigned long* pcFetched); + // skips over a specified number of pins. HRESULT STDCALL ( *Skip )(IEnumPins* This, /* [in] */ unsigned long cPins); + // resets the enumeration sequence to the beginning. HRESULT STDCALL ( *Reset )(IEnumPins* This); + // makes a copy of the enumerator with the same enumeration state. HRESULT STDCALL ( *Clone )(IEnumPins* This, /* [out] */ IEnumPins** ppEnum); } IEnumPins_vt; @@ -111,25 +115,46 @@ HRESULT STDCALL ( *SetTime )(IMediaSample* This, /* [in] */ REFERENCE_TIME* pTimeStart, /* [in] */ REFERENCE_TIME* pTimeEnd); + + // sync-point property. If true, then the beginning of this + // sample is a sync-point. (note that if AM_MEDIA_TYPE.bTemporalCompression + // is false then all samples are sync points). A filter can start + // a stream at any sync point. S_FALSE if not sync-point, S_OK if true. HRESULT STDCALL ( *IsSyncPoint )(IMediaSample* This); HRESULT STDCALL ( *SetSyncPoint )(IMediaSample* This, long bIsSyncPoint); + + // preroll property. If true, this sample is for preroll only and + // shouldn't be displayed. HRESULT STDCALL ( *IsPreroll )(IMediaSample* This); HRESULT STDCALL ( *SetPreroll )(IMediaSample* This, long bIsPreroll); + LONG STDCALL ( *GetActualDataLength )(IMediaSample* This); HRESULT STDCALL ( *SetActualDataLength )(IMediaSample* This, long __MIDL_0010); + + // these allow for limited format changes in band - if no format change + // has been made when you receive a sample GetMediaType will return S_FALSE HRESULT STDCALL ( *GetMediaType )(IMediaSample* This, AM_MEDIA_TYPE** ppMediaType); HRESULT STDCALL ( *SetMediaType )(IMediaSample* This, AM_MEDIA_TYPE* pMediaType); + + // returns S_OK if there is a discontinuity in the data (this frame is + // not a continuation of the previous stream of data + // - there has been a seek or some dropped samples). HRESULT STDCALL ( *IsDiscontinuity )(IMediaSample* This); HRESULT STDCALL ( *SetDiscontinuity )(IMediaSample* This, long bDiscontinuity); + + // get the media times for this sample HRESULT STDCALL ( *GetMediaTime )(IMediaSample* This, /* [out] */ long long* pTimeStart, /* [out] */ long long* pTimeEnd); + // Set the media times for this sample + // pTimeStart==pTimeEnd==NULL will invalidate the media time stamps in + // this sample HRESULT STDCALL ( *SetMediaTime )(IMediaSample* This, /* [in] */ long long* pTimeStart, /* [in] */ long long* pTimeEnd); @@ -180,18 +205,24 @@ { INHERIT_IUNKNOWN(); + // specifies the number of buffers to allocate and the size of each buffer. HRESULT STDCALL ( *SetProperties )(IMemAllocator* This, /* [in] */ ALLOCATOR_PROPERTIES *pRequest, /* [out] */ ALLOCATOR_PROPERTIES *pActual); + // retrieves the number of buffers that the allocator will create, and the buffer properties. HRESULT STDCALL ( *GetProperties )(IMemAllocator* This, /* [out] */ ALLOCATOR_PROPERTIES *pProps); + // allocates the buffer memory. HRESULT STDCALL ( *Commit )(IMemAllocator* This); + // releases the memory for the buffers. HRESULT STDCALL ( *Decommit )(IMemAllocator* This); + // retrieves a media sample that contains an empty buffer. HRESULT STDCALL ( *GetBuffer )(IMemAllocator* This, /* [out] */ IMediaSample** ppBuffer, /* [in] */ REFERENCE_TIME* pStartTime, /* [in] */ REFERENCE_TIME* pEndTime, /* [in] */ unsigned long dwFlags); + // releases a media sample. HRESULT STDCALL ( *ReleaseBuffer )(IMemAllocator* This, /* [in] */ IMediaSample* pBuffer); } IMemAllocator_vt;
--- a/loader/dshow/outputpin.c Tue Dec 11 23:29:11 2001 +0000 +++ b/loader/dshow/outputpin.c Tue Dec 11 23:29:24 2001 +0000 @@ -10,12 +10,18 @@ Returned by COutputPin through call IPin::EnumMediaTypes(). */ +static int unimplemented(const char* s, void* p) +{ + Debug printf("%s(%p) called (UNIMPLEMENTED)", s, p); + return E_NOTIMPL; +} + typedef struct CEnumMediaTypes { IEnumMediaTypes_vt* vt; + DECLARE_IUNKNOWN(); AM_MEDIA_TYPE type; GUID interfaces[2]; - DECLARE_IUNKNOWN(); } CEnumMediaTypes; @@ -25,7 +31,7 @@ /* [out] */ ULONG *pcFetched) { AM_MEDIA_TYPE* type = &((CEnumMediaTypes*)This)->type; - Debug printf("CEnumMediaTypes::Next() called\n"); + Debug printf("CEnumMediaTypes::Next(%p) called\n", This); if (!ppMediaTypes) return E_INVALIDARG; if (!pcFetched && (cMediaTypes!=1)) @@ -52,20 +58,20 @@ static HRESULT STDCALL CEnumMediaTypes_Skip(IEnumMediaTypes * This, /* [in] */ ULONG cMediaTypes) { - Debug printf("CEnumMediaTypes::Skip() called\n"); + Debug unimplemented("CEnumMediaTypes::Skip", This); return E_NOTIMPL; } static HRESULT STDCALL CEnumMediaTypes_Reset(IEnumMediaTypes * This) { - Debug printf("CEnumMediaTypes::Reset() called\n"); + Debug printf("CEnumMediaTypes::Reset(%p) called\n", This); return 0; } static HRESULT STDCALL CEnumMediaTypes_Clone(IEnumMediaTypes * This, /* [out] */ IEnumMediaTypes **ppEnum) { - Debug printf("CEnumMediaTypes::Clone() called\n"); + Debug printf("CEnumMediaTypes::Clone(%p) called\n", This); return E_NOTIMPL; } @@ -81,10 +87,20 @@ CEnumMediaTypes* CEnumMediaTypesCreate(const AM_MEDIA_TYPE* amt) { CEnumMediaTypes *This = (CEnumMediaTypes*) malloc(sizeof(CEnumMediaTypes)) ; + + if (!This) + return NULL; + + This->vt = (IEnumMediaTypes_vt*) malloc(sizeof(IEnumMediaTypes_vt)); + if (!This->vt) + { + free(This); + return NULL; + } + This->refcount = 1; This->type = *amt; - This->vt = (IEnumMediaTypes_vt*) malloc(sizeof(IEnumMediaTypes_vt)); This->vt->QueryInterface = CEnumMediaTypes_QueryInterface; This->vt->AddRef = CEnumMediaTypes_AddRef; This->vt->Release = CEnumMediaTypes_Release; @@ -126,7 +142,7 @@ return 0; } - Debug printf("Unknown interface : %08x-%04x-%04x-%02x%02x-" \ + Debug printf("Unknown interface : %08x-%04x-%04x-%02x%02x-" "%02x%02x%02x%02x%02x%02x\n", iid->f1, iid->f2, iid->f3, (unsigned char)iid->f4[1], (unsigned char)iid->f4[0], @@ -159,21 +175,21 @@ /* [in] */ IPin *pConnector, /* [in] */ const AM_MEDIA_TYPE *pmt) { - Debug printf("COutputPin_ReceiveConnection() called\n"); - ((COutputPin*)This)->remote=pConnector; + Debug printf("COutputPin_ReceiveConnection(%p) called\n", This); + ((COutputPin*)This)->remote = pConnector; return 0; } static HRESULT STDCALL COutputPin_Disconnect(IPin * This) { - Debug printf("COutputPin_Disconnect() called\n"); + Debug printf("COutputPin_Disconnect(%p) called\n", This); return 1; } static HRESULT STDCALL COutputPin_ConnectedTo(IPin * This, /* [out] */ IPin **pPin) { - Debug printf("COutputPin_ConnectedTo() called\n"); + Debug printf("COutputPin_ConnectedTo(%p) called\n", This); if (!pPin) return E_INVALIDARG; *pPin = ((COutputPin*)This)->remote; @@ -198,14 +214,14 @@ static HRESULT STDCALL COutputPin_QueryPinInfo(IPin * This, /* [out] */ PIN_INFO *pInfo) { - Debug printf("COutputPin_QueryPinInfo() called\n"); + Debug unimplemented("COutputPin_QueryPinInfo", This); return E_NOTIMPL; } static HRESULT STDCALL COutputPin_QueryDirection(IPin * This, /* [out] */ PIN_DIRECTION *pPinDir) { - Debug printf("COutputPin_QueryDirection() called\n"); + Debug printf("COutputPin_QueryDirection(%p) called\n", This); if (!pPinDir) return E_INVALIDARG; *pPinDir = PINDIR_INPUT; @@ -215,14 +231,14 @@ static HRESULT STDCALL COutputPin_QueryId(IPin * This, /* [out] */ LPWSTR *Id) { - Debug printf("COutputPin_QueryId() called\n"); + Debug unimplemented("COutputPin_QueryId", This); return E_NOTIMPL; } static HRESULT STDCALL COutputPin_QueryAccept(IPin * This, /* [in] */ const AM_MEDIA_TYPE *pmt) { - Debug printf("COutputPin_QueryAccept() called\n"); + Debug unimplemented("COutputPin_QueryAccept", This); return E_NOTIMPL; } @@ -240,25 +256,25 @@ /* [out] */ IPin **apPin, /* [out][in] */ ULONG *nPin) { - Debug printf("COutputPin_QueryInternalConnections() called\n"); + Debug unimplemented("COutputPin_QueryInternalConnections", This); return E_NOTIMPL; } static HRESULT STDCALL COutputPin_EndOfStream(IPin * This) { - Debug printf("COutputPin_EndOfStream() called\n"); + Debug unimplemented("COutputPin_EndOfStream", This); return E_NOTIMPL; } static HRESULT STDCALL COutputPin_BeginFlush(IPin * This) { - Debug printf("COutputPin_BeginFlush() called\n"); + Debug unimplemented("COutputPin_BeginFlush", This); return E_NOTIMPL; } static HRESULT STDCALL COutputPin_EndFlush(IPin * This) { - Debug printf("COutputPin_EndFlush() called\n"); + Debug unimplemented("COutputPin_EndFlush", This); return E_NOTIMPL; } @@ -286,7 +302,7 @@ if(!memcmp(iid, &IID_IUnknown, 16)) { - *ppv=p; + *ppv = p; p->vt->AddRef(This); return 0; } @@ -299,7 +315,7 @@ }*/ if(!memcmp(iid, &IID_IMemInputPin, 16)) { - *ppv=p->mempin; + *ppv = p->mempin; p->mempin->vt->AddRef(This); return 0; } @@ -335,7 +351,7 @@ static HRESULT STDCALL COutputPin_GetAllocatorRequirements(IMemInputPin* This, /* [out] */ ALLOCATOR_PROPERTIES* pProps) { - Debug printf("COutputPin_GetAllocatorRequirements() called\n"); + Debug unimplemented("COutputPin_GetAllocatorRequirements", This); return E_NOTIMPL; } @@ -379,13 +395,13 @@ /* [in] */ long nSamples, /* [out] */ long *nSamplesProcessed) { - Debug printf("COutputPin_ReceiveMultiple() called (UNIMPLEMENTED)\n"); + Debug unimplemented("COutputPin_ReceiveMultiple", This); return E_NOTIMPL; } static HRESULT STDCALL COutputPin_ReceiveCanBlock(IMemInputPin * This) { - Debug printf("COutputPin_ReceiveCanBlock() called (UNIMPLEMENTED)\n"); + Debug unimplemented("COutputPin_ReceiveCanBlock", This); return E_NOTIMPL; } @@ -413,25 +429,26 @@ static void COutputPin_Destroy(COutputPin* This) { - free(This->vt); - free(This->mempin->vt); - free(This->mempin); + if (This->mempin->vt) + free(This->mempin->vt); + if (This->mempin) + free(This->mempin); + if (This->vt) + free(This->vt); free(This); } static HRESULT STDCALL COutputPin_AddRef(IUnknown* This) { - Debug printf("COutputPin_AddRef(%p) called (%d)\n", - This, ((COutputPin*)This)->refcount); + Debug printf("COutputPin_AddRef(%p) called (%d)\n", This, ((COutputPin*)This)->refcount); ((COutputPin*)This)->refcount++; return 0; } static HRESULT STDCALL COutputPin_Release(IUnknown* This) { - Debug printf("COutputPin_Release(%p) called (%d)\n", - This, ((COutputPin*)This)->refcount); - if (--((COutputPin*)This)->refcount<=0) + Debug printf("COutputPin_Release(%p) called (%d)\n", This, ((COutputPin*)This)->refcount); + if (--((COutputPin*)This)->refcount <= 0) COutputPin_Destroy((COutputPin*)This); return 0; @@ -440,8 +457,7 @@ static HRESULT STDCALL COutputPin_M_AddRef(IUnknown* This) { COutputMemPin* p = (COutputMemPin*) This; - Debug printf("COutputPin_MAddRef(%p) called (%p, %d)\n", - p, p->parent, p->parent->refcount); + Debug printf("COutputPin_MAddRef(%p) called (%p, %d)\n", p, p->parent, p->parent->refcount); p->parent->refcount++; return 0; } @@ -459,10 +475,27 @@ COutputPin* COutputPinCreate(const AM_MEDIA_TYPE* amt) { COutputPin* This = (COutputPin*) malloc(sizeof(COutputPin)); + IMemInputPin_vt* ivt; + + if (!This) + return NULL; + + This->vt = (IPin_vt*) malloc(sizeof(IPin_vt)); + This->mempin = (COutputMemPin*) malloc(sizeof(COutputMemPin)); + ivt = (IMemInputPin_vt*) malloc(sizeof(IMemInputPin_vt)); + + if (!This->vt || !This->mempin || !ivt) + { + COutputPin_Destroy(This); + return NULL; + } + + This->mempin->vt = ivt; + This->refcount = 1; This->remote = 0; This->type = *amt; - This->vt = (IPin_vt*) malloc(sizeof(IPin_vt)); + This->vt->QueryInterface = COutputPin_QueryInterface; This->vt->AddRef = COutputPin_AddRef; This->vt->Release = COutputPin_Release; @@ -482,8 +515,6 @@ This->vt->EndFlush = COutputPin_EndFlush; This->vt->NewSegment = COutputPin_NewSegment; - This->mempin = (COutputMemPin*) malloc(sizeof(COutputMemPin)); - This->mempin->vt = (IMemInputPin_vt*) malloc(sizeof(IMemInputPin_vt)); This->mempin->vt->QueryInterface = COutputPin_M_QueryInterface; This->mempin->vt->AddRef = COutputPin_M_AddRef; This->mempin->vt->Release = COutputPin_M_Release;