Index: Makefile =================================================================== --- Makefile (revision 22190) +++ Makefile (working copy) @@ -5,7 +5,7 @@ CFLAGS= -Idshow -DMPLAYER -D__WINE__ -DNOAVIFILE_HEADERS #CFLAGS+=-Ddbg_printf=__vprintf -DTRACE=__vprintf -DDETAILED_OUT -SRCS= driver.c afl.c vfl.c +SRCS= driver.c afl.c vfl.c util.c ifneq ($(TARGET_WIN32),yes) SRCS+= ldt_keeper.c pe_image.c module.c ext.c win32.c \ pe_resource.c resource.c registry.c elfdll.c Index: util.c =================================================================== --- util.c (revision 0) +++ util.c (revision 0) @@ -0,0 +1,127 @@ +#include "util.h" +#include "mp_msg.h" +#include "winerror.h" +/* +------------------------------------------------------------------- + AM_MEDIA_TYPE service functions implementations +------------------------------------------------------------------- +*/ +#ifdef DEBUG +void DisplayMediaType(const char * label,const AM_MEDIA_TYPE* pmt){ + WAVEFORMATEX* pWF; + VIDEOINFOHEADER* Vhdr; + int i; + GUID* iid; + + + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"=======================\n"); + if(label) + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"AM_MEDIA_TYPE: %s\n",label); + else + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"AM_MEDIA_TYPE:\n"); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"-(Ptr:%p)--------\n",pmt); + for(i=0;ipbFormat,pmt->cbFormat); + for(i=0;icbFormat;i++){ + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"%02x ",(BYTE)pmt->pbFormat[i]); + if((i+1)%8==0) Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"\n"); + } + if((i)%8!=0) Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"\n"); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"-----------------------\n"); + iid=(GUID*)&(pmt->subtype); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"Subtype: %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], + (unsigned char)iid->f4[2], (unsigned char)iid->f4[3], + (unsigned char)iid->f4[4], (unsigned char)iid->f4[5], + (unsigned char)iid->f4[6], (unsigned char)iid->f4[7]); + + iid=(GUID*)&(pmt->formattype); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"Format type: %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], + (unsigned char)iid->f4[2], (unsigned char)iid->f4[3], + (unsigned char)iid->f4[4], (unsigned char)iid->f4[5], + (unsigned char)iid->f4[6], (unsigned char)iid->f4[7]); + if(pmt && memcmp(&pmt->formattype,&FORMAT_WaveFormatEx,16)==0 && pmt->pbFormat){ + pWF=(WAVEFORMATEX*)pmt->pbFormat; + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"PMT: nChannels %d\n",pWF->nChannels); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"PMT: nSamplesPerSec %d\n",pWF->nSamplesPerSec); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"PMT: wBitsPerSample %d\n",pWF->wBitsPerSample); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"PMT: nBlockAlign %d\n",pWF->nBlockAlign); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"PMT: nAvgBytesPerSec %d\n",pWF->nAvgBytesPerSec); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"PMT: SampleSize %ld\n",pmt->lSampleSize); + } + if(pmt && memcmp(&pmt->formattype,&FORMAT_VideoInfo,16)==0 && pmt->pbFormat){ + Vhdr=(VIDEOINFOHEADER*)pmt->pbFormat; + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"Vhdr: dwBitRate %ld\n",Vhdr->dwBitRate); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"Vhdr: biWidth %ld\n",Vhdr->bmiHeader.biWidth); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"Vhdr: biHeight %d\n",Vhdr->bmiHeader.biHeight); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"Vhdr: biSizeImage %d\n",Vhdr->bmiHeader.biSizeImage); + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"Vhdr: biBitCount %d\n",Vhdr->bmiHeader.biBitCount); + if(Vhdr->bmiHeader.biCompression){ + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"Vhdr: biComression 0x%08x (%s)\n",Vhdr->bmiHeader.biCompression,vo_format_name(Vhdr->bmiHeader.biCompression)); + }else + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"Vhdr: biComression 0x00000000\n"); + + } + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"=======================\n"); +} +#endif +void FreeMediaType(AM_MEDIA_TYPE* pmt){ + if(!pmt) return; + if (pmt->cbFormat){ + CoTaskMemFree(pmt->pbFormat); + pmt->pbFormat=NULL; + pmt->cbFormat=0; + } + if (pmt->pUnk){ + pmt->pUnk->vt->Release(pmt->pUnk); + pmt->pUnk=NULL; + } +} + +void DeleteMediaType(AM_MEDIA_TYPE* pmt){ + if(!pmt) return; + FreeMediaType(pmt); + CoTaskMemFree(pmt); +} + +HRESULT CopyMediaType(AM_MEDIA_TYPE* pDst,const AM_MEDIA_TYPE* pSrc){ + Debug mp_msg(MSGT_LOADER,MSGL_DBG4,"%s(%p) called\n", "CopyMediaType",pSrc); + + if(!pSrc || !pDst) return E_POINTER; + + if(pSrc == pDst) return E_INVALIDARG; + + if(!pSrc->pbFormat && pSrc->cbFormat) return E_POINTER; + + *pDst=*pSrc; + + if(pDst->cbFormat>0){ + pDst->pbFormat=CoTaskMemAlloc(pDst->cbFormat); + if(!pDst->pbFormat){ + pDst->cbFormat=0; + return E_OUTOFMEMORY; + }else + memcpy(pDst->pbFormat,pSrc->pbFormat,pDst->cbFormat); + } + return S_OK; +} + +AM_MEDIA_TYPE* CreateMediaType(const AM_MEDIA_TYPE* pSrc){ + HRESULT hr; + AM_MEDIA_TYPE* pDst=CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE)); + if (!pDst) return NULL; + hr=CopyMediaType(pDst,pSrc); + if(!FAILED(hr)) return pDst; + //Copy failed + CoTaskMemFree(pDst); + return NULL; +} Index: util.h =================================================================== --- util.h (revision 0) +++ util.h (revision 0) @@ -0,0 +1,66 @@ +/* +------------------------------------------------------------------- + AM_MEDIA_TYPE service functions declarations +------------------------------------------------------------------- +*/ +#include "guids.h" + +#ifdef DEBUG +/** + * \brief print info from AM_MEDIA_TYPE structure + * =param[in] label short lable for media type + * \param[in] pmt pointer to AM_MEDIA_TYPE + * + * routine used for debug purposes + * + */ +void DisplayMediaType(const char * label,const AM_MEDIA_TYPE* pmt); +#endif +/** + * \brief frees memory, pointed by pbFormat and pUnk members of AM_MEDIA_TYPE structure + * + * \param[in] pmt pointer to structure + * + * \note + * routine does not frees memory allocated for AM_MEDIA_TYPE, so given pointer will be + * valid after this routine call. + * + */ +void FreeMediaType(AM_MEDIA_TYPE* pmt); +/** + * \brief frees memory allocated for AM_MEDIA_TYPE structure, including pbFormat and pUnk + * members + * + * \param[in] pmt pointer to structure + * + * \note + * after call to this routine, pointer to AM_MEDIA_TYPE will not be valid anymore + * + */ +void DeleteMediaType(AM_MEDIA_TYPE* pmt); +/** + * \brief copyies info from source to destination AM_MEDIA_TYPE structures + * + * \param[in] pSrc pointer to AM_MEDIA_TYPE structure to copy data from + * \param[out] pDst pointer to AM_MEDIA_TYPE structure to copy data to + * + * \return S_OK - success + * \return E_POINTER - pSrc or pDst is NULL or (pSrc->cbFormat && !pSrc->pbFormat) + * \return E_INVALIDARG - (pSrc == pDst) + * \return E_OUTOFMEMORY - Insufficient memory + * + * \note + * - pDst must point to existing AM_MEDIA_TYPE structure (all data will be overwritten) + * - if pDst->pbFormat!=NULL this will cause memory leak (as described in Directshow SDK)! + * + */ +HRESULT CopyMediaType(AM_MEDIA_TYPE* pDst,const AM_MEDIA_TYPE* pSrc); +/** + * \brief allocates new AM_MEDIA_TYPE structure and fills it with info from given one + * + * \param[in] pSrc pointer to AM_MEDIA_TYPE structure to copy data from + * + * \return result code, returned from CopyMediaType + * + */ +AM_MEDIA_TYPE* CreateMediaType(const AM_MEDIA_TYPE* pSrc);