diff options
Diffstat (limited to 'loader/dshow')
-rw-r--r-- | loader/dshow/DS_AudioDecoder.c | 192 | ||||
-rw-r--r-- | loader/dshow/DS_AudioDecoder.h | 20 | ||||
-rw-r--r-- | loader/dshow/DS_Filter.c | 318 | ||||
-rw-r--r-- | loader/dshow/DS_Filter.h | 42 | ||||
-rw-r--r-- | loader/dshow/DS_VideoDecoder.c | 916 | ||||
-rw-r--r-- | loader/dshow/DS_VideoDecoder.h | 32 | ||||
-rw-r--r-- | loader/dshow/allocator.c | 363 | ||||
-rw-r--r-- | loader/dshow/allocator.h | 27 | ||||
-rw-r--r-- | loader/dshow/cmediasample.c | 576 | ||||
-rw-r--r-- | loader/dshow/cmediasample.h | 32 | ||||
-rw-r--r-- | loader/dshow/graph.c | 165 | ||||
-rw-r--r-- | loader/dshow/graph.h | 57 | ||||
-rw-r--r-- | loader/dshow/guids.c | 83 | ||||
-rw-r--r-- | loader/dshow/guids.h | 89 | ||||
-rw-r--r-- | loader/dshow/inputpin.c | 1492 | ||||
-rw-r--r-- | loader/dshow/inputpin.h | 70 | ||||
-rw-r--r-- | loader/dshow/interfaces.h | 360 | ||||
-rw-r--r-- | loader/dshow/iunk.h | 54 | ||||
-rw-r--r-- | loader/dshow/libwin32.h | 256 | ||||
-rw-r--r-- | loader/dshow/mediatype.c | 161 | ||||
-rw-r--r-- | loader/dshow/mediatype.h | 96 | ||||
-rw-r--r-- | loader/dshow/outputpin.c | 957 | ||||
-rw-r--r-- | loader/dshow/outputpin.h | 32 |
23 files changed, 0 insertions, 6390 deletions
diff --git a/loader/dshow/DS_AudioDecoder.c b/loader/dshow/DS_AudioDecoder.c deleted file mode 100644 index cfa2fcb5a2..0000000000 --- a/loader/dshow/DS_AudioDecoder.c +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************** - - DirectShow audio decoder - Copyright 2001 Eugene Kuznetsov (divx@euro.ru) - -*********************************************************/ -#include "config.h" - -#include "libwin32.h" - -#include "DS_Filter.h" - -struct DS_AudioDecoder -{ - WAVEFORMATEX in_fmt; - AM_MEDIA_TYPE m_sOurType, m_sDestType; - DS_Filter* m_pDS_Filter; - char* m_sVhdr; - char* m_sVhdr2; -}; - -#include "DS_AudioDecoder.h" -#ifdef WIN32_LOADER -#include "loader/ldt_keeper.h" -#endif - -#include <string.h> -#include <stdio.h> -#include <stdlib.h> - -typedef long STDCALL (*GETCLASS) (GUID*, GUID*, void**); - -static SampleProcUserData sampleProcData; - - -DS_AudioDecoder * DS_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf) -//DS_AudioDecoder * DS_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf) -{ - DS_AudioDecoder *this; - int sz; - WAVEFORMATEX* pWF; - -#ifdef WIN32_LOADER - Setup_LDT_Keeper(); - Setup_FS_Segment(); -#endif - - this = malloc(sizeof(DS_AudioDecoder)); - - sz = 18 + wf->cbSize; - this->m_sVhdr = malloc(sz); - memcpy(this->m_sVhdr, wf, sz); - this->m_sVhdr2 = malloc(18); - memcpy(this->m_sVhdr2, this->m_sVhdr, 18); - - pWF = (WAVEFORMATEX*)this->m_sVhdr2; - pWF->wFormatTag = 1; - pWF->wBitsPerSample = 16; - pWF->nBlockAlign = pWF->nChannels * (pWF->wBitsPerSample + 7) / 8; - pWF->cbSize = 0; - pWF->nAvgBytesPerSec = pWF->nBlockAlign * pWF->nSamplesPerSec; - - memcpy(&this->in_fmt,wf,sizeof(WAVEFORMATEX)); - - memset(&this->m_sOurType, 0, sizeof(this->m_sOurType)); - this->m_sOurType.majortype=MEDIATYPE_Audio; - this->m_sOurType.subtype=MEDIASUBTYPE_PCM; - this->m_sOurType.subtype.f1=wf->wFormatTag; - this->m_sOurType.formattype=FORMAT_WaveFormatEx; - this->m_sOurType.lSampleSize=wf->nBlockAlign; - this->m_sOurType.bFixedSizeSamples=1; - this->m_sOurType.bTemporalCompression=0; - this->m_sOurType.pUnk=0; - this->m_sOurType.cbFormat=sz; - this->m_sOurType.pbFormat=this->m_sVhdr; - - memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); - this->m_sDestType.majortype=MEDIATYPE_Audio; - this->m_sDestType.subtype=MEDIASUBTYPE_PCM; -// this->m_sDestType.subtype.f1=pWF->wFormatTag; - this->m_sDestType.formattype=FORMAT_WaveFormatEx; - this->m_sDestType.bFixedSizeSamples=1; - this->m_sDestType.bTemporalCompression=0; - this->m_sDestType.lSampleSize=pWF->nBlockAlign; - if (wf->wFormatTag == 0x130) - // ACEL hack to prevent memory corruption - // obviosly we are missing something here - this->m_sDestType.lSampleSize *= 288; - this->m_sDestType.pUnk=0; - this->m_sDestType.cbFormat=18; //pWF->cbSize; - this->m_sDestType.pbFormat=this->m_sVhdr2; - -//print_wave_header(this->m_sVhdr, MSGL_V); -//print_wave_header(this->m_sVhdr2, MSGL_V); - - /*try*/ - { - this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType,&sampleProcData); - if( !this->m_pDS_Filter ) { - free(this); - return NULL; - } - - //Commit should be done before binary codec start - this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll); - - this->m_pDS_Filter->Start(this->m_pDS_Filter); - - } - /* - catch (FatalError& e) - { - e.PrintAll(); - delete[] m_sVhdr; - delete[] m_sVhdr2; - delete m_pDS_Filter; - throw; - } - */ - return this; -} - -void DS_AudioDecoder_Destroy(DS_AudioDecoder *this) -{ - free(this->m_sVhdr); - free(this->m_sVhdr2); - DS_Filter_Destroy(this->m_pDS_Filter); - free(this); -} - -int DS_AudioDecoder_Convert(DS_AudioDecoder *this, const void* in_data, unsigned int in_size, - void* out_data, unsigned int out_size, - unsigned int* size_read, unsigned int* size_written) -{ - unsigned int written = 0; - unsigned int read = 0; - - if (!in_data || !out_data) - return -1; - -#ifdef WIN32_LOADER - Setup_FS_Segment(); -#endif - - in_size -= in_size%this->in_fmt.nBlockAlign; - while (in_size>0) - { - IMediaSample* sample=0; - char* ptr; - int result; - this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0); - if (!sample) - { - Debug printf("DS_AudioDecoder::Convert() Error: null sample\n"); - break; - } - sample->vt->SetActualDataLength(sample, this->in_fmt.nBlockAlign); - sample->vt->GetPointer(sample, (BYTE **)&ptr); - memcpy(ptr, (const uint8_t*)in_data + read, this->in_fmt.nBlockAlign); - sample->vt->SetSyncPoint(sample, 1); - sample->vt->SetPreroll(sample, 0); - result = this->m_pDS_Filter->m_pImp->vt->Receive(this->m_pDS_Filter->m_pImp, sample); - if (result) - Debug printf("DS_AudioDecoder::Convert() Error: putting data into input pin %x\n", result); - if ((written + sampleProcData.frame_size) > out_size) - { - sample->vt->Release((IUnknown*)sample); - break; - } - memcpy((uint8_t*)out_data + written, sampleProcData.frame_pointer, sampleProcData.frame_size); - sample->vt->Release((IUnknown*)sample); - read+=this->in_fmt.nBlockAlign; - written+=sampleProcData.frame_size; - break; - } - if (size_read) - *size_read = read; - if (size_written) - *size_written = written; - return 0; -} - -int DS_AudioDecoder_GetSrcSize(DS_AudioDecoder *this, int dest_size) -{ - double efficiency =(double) this->in_fmt.nAvgBytesPerSec - / (this->in_fmt.nSamplesPerSec*this->in_fmt.nBlockAlign); - int frames = (int)(dest_size*efficiency); - - if (frames < 1) - frames = 1; - return frames * this->in_fmt.nBlockAlign; -} diff --git a/loader/dshow/DS_AudioDecoder.h b/loader/dshow/DS_AudioDecoder.h deleted file mode 100644 index 157993cda3..0000000000 --- a/loader/dshow/DS_AudioDecoder.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MPLAYER_DS_AUDIODECODER_H -#define MPLAYER_DS_AUDIODECODER_H - -#include "loader/com.h" -#include "loader/wine/mmreg.h" - -typedef struct DS_AudioDecoder DS_AudioDecoder; - -//DS_AudioDecoder * DS_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf); -DS_AudioDecoder * DS_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf); - -void DS_AudioDecoder_Destroy(DS_AudioDecoder *this); - -int DS_AudioDecoder_Convert(DS_AudioDecoder *this, const void* in_data, unsigned int in_size, - void* out_data, unsigned int out_size, - unsigned int* size_read, unsigned int* size_written); - -int DS_AudioDecoder_GetSrcSize(DS_AudioDecoder *this, int dest_size); - -#endif /* MPLAYER_DS_AUDIODECODER_H */ diff --git a/loader/dshow/DS_Filter.c b/loader/dshow/DS_Filter.c deleted file mode 100644 index 88f881523a..0000000000 --- a/loader/dshow/DS_Filter.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Modified for use with MPlayer, detailed changelog at - * http://svn.mplayerhq.hu/mplayer/trunk/ - */ - -#include "config.h" -#include "DS_Filter.h" -#include "graph.h" -#include "loader/drv.h" -#include "loader/com.h" -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include "loader/win32.h" // printf macro - -typedef long STDCALL (*GETCLASS) (const GUID*, const GUID*, void**); - -#ifndef WIN32_LOADER -const GUID IID_IUnknown = -{ - 0x00000000, 0x0000, 0x0000, - {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} -}; -const GUID IID_IClassFactory = -{ - 0x00000001, 0x0000, 0x0000, - {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} -}; - -HRESULT STDCALL CoInitialize(LPVOID pvReserved); -void STDCALL CoUninitialize(void); -#endif - -static void DS_Filter_Start(DS_Filter* This) -{ - HRESULT hr; - - //Debug printf("DS_Filter_Start(%p)\n", This); - hr = This->m_pFilter->vt->Run(This->m_pFilter, (REFERENCE_TIME)0); - if (hr != 0) - { - Debug printf("WARNING: m_Filter->Run() failed, error code %x\n", (int)hr); - } -} - -static void DS_Filter_Stop(DS_Filter* This) -{ - if (This->m_pAll) - { - //Debug printf("DS_Filter_Stop(%p)\n", This); - 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; - } -} - -void DS_Filter_Destroy(DS_Filter* This) -{ - This->Stop(This); - - if (This->m_pOurInput) - This->m_pOurInput->vt->Release((IUnknown*)This->m_pOurInput); - if (This->m_pInputPin) - This->m_pInputPin->vt->Disconnect(This->m_pInputPin); - if (This->m_pOutputPin) - This->m_pOutputPin->vt->Disconnect(This->m_pOutputPin); - if (This->m_pFilter) - This->m_pFilter->vt->Release((IUnknown*)This->m_pFilter); - if (This->m_pOutputPin) - This->m_pOutputPin->vt->Release((IUnknown*)This->m_pOutputPin); - if (This->m_pInputPin) - This->m_pInputPin->vt->Release((IUnknown*)This->m_pInputPin); - if (This->m_pImp) - This->m_pImp->vt->Release((IUnknown*)This->m_pImp); - - if (This->m_pOurOutput) - This->m_pOurOutput->vt->Release((IUnknown*)This->m_pOurOutput); - if (This->m_pParentFilter) - This->m_pParentFilter->vt->Release((IUnknown*)This->m_pParentFilter); - if (This->m_pSrcFilter) - This->m_pSrcFilter->vt->Release((IUnknown*)This->m_pSrcFilter); - - // FIXME - we are still leaving few things allocated! - if (This->m_iHandle) - FreeLibrary((unsigned)This->m_iHandle); - - free(This); - -#ifdef WIN32_LOADER - CodecRelease(); -#else - CoUninitialize(); -#endif -} - -static HRESULT STDCALL DS_Filter_CopySample(void* pUserData,IMediaSample* pSample){ - BYTE* pointer; - int len; - SampleProcUserData* pData=pUserData; - Debug printf("CopySample called(%p,%p)\n",pSample,pUserData); - if (pSample->vt->GetPointer(pSample, &pointer)) - return 1; - len = pSample->vt->GetActualDataLength(pSample); - if (len == 0) - len = pSample->vt->GetSize(pSample);//for iv50 - - pData->frame_pointer = pointer; - pData->frame_size = len; -/* - FILE* file=fopen("./uncompr.bmp", "wb"); - char head[14]={0x42, 0x4D, 0x36, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00}; - *(int*)(&head[2])=len+0x36; - fwrite(head, 14, 1, file); - fwrite(&((VIDEOINFOHEADER*)me.type.pbFormat)->bmiHeader, sizeof(BITMAPINFOHEADER), 1, file); - fwrite(pointer, len, 1, file); - fclose(file); -*/ - return 0; -} - -DS_Filter* DS_FilterCreate(const char* dllname, const GUID* id, - AM_MEDIA_TYPE* in_fmt, - AM_MEDIA_TYPE* out_fmt,SampleProcUserData* pUserData) -{ - int init = 0; -// char eb[250]; - const char* em = NULL; - MemAllocator* tempAll; - FilterGraph* graph; - ALLOCATOR_PROPERTIES props,props1; - DS_Filter* This = malloc(sizeof(DS_Filter)); - if (!This) - return NULL; - -#ifdef WIN32_LOADER - CodecAlloc(); -#else - CoInitialize(0L); -#endif - - /* - tempAll is not used anywhere. - MemAllocatorCreate() is called to ensure that RegisterComObject for IMemoryAllocator - will be called before possible call - to CoCreateInstance(...,&IID_IMemoryAllocator,...) from binary codec. - */ - tempAll=MemAllocatorCreate(); - This->m_pFilter = NULL; - This->m_pInputPin = NULL; - This->m_pOutputPin = NULL; - This->m_pSrcFilter = NULL; - This->m_pParentFilter = NULL; - This->m_pOurInput = NULL; - This->m_pOurOutput = NULL; - This->m_pAll = NULL; - This->m_pImp = NULL; - - This->Start = DS_Filter_Start; - This->Stop = DS_Filter_Stop; - - for (;;) - { - GETCLASS func; - struct IClassFactory* factory = NULL; - struct IUnknown* object = NULL; - IEnumPins* enum_pins = 0; - IPin* array[256]; - ULONG fetched; - HRESULT result; - unsigned int i; - static const uint16_t filter_name[] = { 'F', 'i', 'l', 't', 'e', 'r', 0 }; - - This->m_iHandle = LoadLibraryA(dllname); - if (!This->m_iHandle) - { - em = "could not open DirectShow DLL"; - break; - } - func = (GETCLASS)GetProcAddress((unsigned)This->m_iHandle, "DllGetClassObject"); - if (!func) - { - em = "illegal or corrupt DirectShow DLL"; - break; - } - result = func(id, &IID_IClassFactory, (void*)&factory); - if (result || !factory) - { - em = "no such class object"; - break; - } - result = factory->vt->CreateInstance(factory, 0, &IID_IUnknown, (void*)&object); - factory->vt->Release((IUnknown*)factory); - if (result || !object) - { - 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) - { - em = "object does not provide IBaseFilter interface"; - break; - } - - graph = FilterGraphCreate(); - result = This->m_pFilter->vt->JoinFilterGraph(This->m_pFilter, (IFilterGraph*)graph, filter_name); - - // enumerate pins - result = This->m_pFilter->vt->EnumPins(This->m_pFilter, &enum_pins); - if (result || !enum_pins) - { - em = "could not enumerate pins"; - break; - } - - enum_pins->vt->Reset(enum_pins); - result = enum_pins->vt->Next(enum_pins, (ULONG)256, (IPin**)array, &fetched); - enum_pins->vt->Release((IUnknown*)enum_pins); - Debug printf("Pins enumeration returned %ld pins, error is %x\n", fetched, (int)result); - - for (i = 0; i < fetched; i++) - { - PIN_DIRECTION direction = -1; - array[i]->vt->QueryDirection(array[i], &direction); - if (!This->m_pInputPin && direction == PINDIR_INPUT) - { - This->m_pInputPin = array[i]; - This->m_pInputPin->vt->AddRef((IUnknown*)This->m_pInputPin); - } - if (!This->m_pOutputPin && direction == PINDIR_OUTPUT) - { - This->m_pOutputPin = array[i]; - This->m_pOutputPin->vt->AddRef((IUnknown*)This->m_pOutputPin); - } - array[i]->vt->Release((IUnknown*)(array[i])); - } - if (!This->m_pInputPin) - { - em = "could not find input pin"; - break; - } - if (!This->m_pOutputPin) - { - em = "could not find output pin"; - break; - } - result = This->m_pInputPin->vt->QueryInterface((IUnknown*)This->m_pInputPin, - &IID_IMemInputPin, - (void*)&This->m_pImp); - if (result) - { - em = "could not get IMemInputPin interface"; - break; - } - - This->m_pOurType = in_fmt; - This->m_pDestType = out_fmt; - result = This->m_pInputPin->vt->QueryAccept(This->m_pInputPin, This->m_pOurType); - if (result) - { - em = "source format is not accepted"; - break; - } - This->m_pParentFilter = CBaseFilter2Create(); - This->m_pSrcFilter = CBaseFilterCreate(This->m_pOurType, This->m_pParentFilter); - This->m_pOurInput = This->m_pSrcFilter->GetPin(This->m_pSrcFilter); - This->m_pOurInput->vt->AddRef((IUnknown*)This->m_pOurInput); - - result = This->m_pInputPin->vt->ReceiveConnection(This->m_pInputPin, - This->m_pOurInput, - This->m_pOurType); - if (result) - { - em = "could not connect to input pin"; - break; - } - result = This->m_pImp->vt->GetAllocator(This->m_pImp, &This->m_pAll); - if (result || !This->m_pAll) - { - em="error getting IMemAllocator interface"; - break; - } - - //Seting allocator property according to our media type - props.cBuffers=1; - props.cbBuffer=This->m_pOurType->lSampleSize; - props.cbAlign=1; - props.cbPrefix=0; - This->m_pAll->vt->SetProperties(This->m_pAll, &props, &props1); - - //Notify remote pin about choosed allocator - This->m_pImp->vt->NotifyAllocator(This->m_pImp, This->m_pAll, 0); - - This->m_pOurOutput = COutputPinCreate(This->m_pDestType,DS_Filter_CopySample,pUserData); - - result = This->m_pOutputPin->vt->ReceiveConnection(This->m_pOutputPin, - (IPin*) This->m_pOurOutput, - This->m_pDestType); - if (result) - { - em = "could not connect to output pin"; - break; - } - - init++; - break; - } - tempAll->vt->Release((IUnknown*)tempAll); - - if (!init) - { - DS_Filter_Destroy(This); - printf("Warning: DS_Filter() %s. (DLL=%.200s)\n", em, dllname); - This = 0; - } - return This; -} diff --git a/loader/dshow/DS_Filter.h b/loader/dshow/DS_Filter.h deleted file mode 100644 index 945321a153..0000000000 --- a/loader/dshow/DS_Filter.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef MPLAYER_DS_FILTER_H -#define MPLAYER_DS_FILTER_H - -#include "inputpin.h" -#include "outputpin.h" - -typedef struct { - char* frame_pointer; - long frame_size; -} SampleProcUserData; - -/** - User will allocate and fill format structures, call Create(), - and then set up m_pAll. - **/ - -typedef struct DS_Filter DS_Filter; -struct DS_Filter -{ - int m_iHandle; - IBaseFilter* m_pFilter; - IPin* m_pInputPin; - IPin* m_pOutputPin; - - CBaseFilter* m_pSrcFilter; - CBaseFilter2* m_pParentFilter; - IPin* m_pOurInput; - COutputPin* m_pOurOutput; - - AM_MEDIA_TYPE *m_pOurType, *m_pDestType; - IMemAllocator* m_pAll; - IMemInputPin* m_pImp; - - void ( *Start )(DS_Filter*); - void ( *Stop )(DS_Filter*); -}; - -DS_Filter* DS_FilterCreate(const char* dllname, const GUID* id, - AM_MEDIA_TYPE* in_fmt, AM_MEDIA_TYPE* out_fmt,SampleProcUserData* pUserData); -void DS_Filter_Destroy(DS_Filter* This); - -#endif /* MPLAYER_DS_FILTER_H */ diff --git a/loader/dshow/DS_VideoDecoder.c b/loader/dshow/DS_VideoDecoder.c deleted file mode 100644 index c8cc988b61..0000000000 --- a/loader/dshow/DS_VideoDecoder.c +++ /dev/null @@ -1,916 +0,0 @@ -/******************************************************** - - DirectShow Video decoder implementation - Copyright 2000 Eugene Kuznetsov (divx@euro.ru) - -*********************************************************/ -#include "config.h" -#include "guids.h" -#include "interfaces.h" -#include "loader/registry.h" -#include "libwin32.h" -#include "DS_Filter.h" - -struct DS_VideoDecoder -{ - IVideoDecoder iv; - - DS_Filter* m_pDS_Filter; - AM_MEDIA_TYPE m_sOurType, m_sDestType; - VIDEOINFOHEADER* m_sVhdr; - VIDEOINFOHEADER* m_sVhdr2; - int m_Caps;//CAPS m_Caps; // capabilities of DirectShow decoder - int m_iLastQuality; // remember last quality as integer - int m_iMinBuffers; - int m_iMaxAuto; - int m_bIsDivX; // for speed - int m_bIsDivX4; // for speed -}; -static SampleProcUserData sampleProcData; - -#include "DS_VideoDecoder.h" - -#include "loader/wine/winerror.h" -#ifdef WIN32_LOADER -#include "loader/ldt_keeper.h" -#endif - -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <sys/types.h> -#ifdef HAVE_SYS_MMAN_H -#include <sys/mman.h> -#endif -#include <stdio.h> -#include <stdlib.h> // labs - -// strcmp((const char*)info.dll,...) is used instead of (... == ...) -// so Arpi could use char* pointer in his simplified DS_VideoDecoder class - -#define false 0 -#define true 1 - -int DS_VideoDecoder_GetCapabilities(DS_VideoDecoder *this) -{return this->m_Caps;} - -typedef struct ct ct; - -struct ct { - unsigned int bits; - fourcc_t fcc; - const GUID *subtype; - int cap; - }; - -static ct check[] = { - {16, fccYUY2, &MEDIASUBTYPE_YUY2, CAP_YUY2}, - {12, fccIYUV, &MEDIASUBTYPE_IYUV, CAP_IYUV}, - {16, fccUYVY, &MEDIASUBTYPE_UYVY, CAP_UYVY}, - {12, fccYV12, &MEDIASUBTYPE_YV12, CAP_YV12}, - //{16, fccYV12, &MEDIASUBTYPE_YV12, CAP_YV12}, - {16, fccYVYU, &MEDIASUBTYPE_YVYU, CAP_YVYU}, - {12, fccI420, &MEDIASUBTYPE_I420, CAP_I420}, - {9, fccYVU9, &MEDIASUBTYPE_YVU9, CAP_YVU9}, - {0, 0, 0, 0}, - }; - - -DS_VideoDecoder * DS_VideoDecoder_Open(char* dllname, GUID* guid, BITMAPINFOHEADER * format, int flip, int maxauto) -{ - DS_VideoDecoder *this; - HRESULT result; - ct* c; - - this = malloc(sizeof(DS_VideoDecoder)); - memset( this, 0, sizeof(DS_VideoDecoder)); - - this->m_sVhdr2 = 0; - this->m_iLastQuality = -1; - this->m_iMaxAuto = maxauto; - -#ifdef WIN32_LOADER - Setup_LDT_Keeper(); -#endif - - //memset(&m_obh, 0, sizeof(m_obh)); - //m_obh.biSize = sizeof(m_obh); - /*try*/ - { - unsigned int bihs; - - bihs = (format->biSize < (int) sizeof(BITMAPINFOHEADER)) ? - sizeof(BITMAPINFOHEADER) : format->biSize; - - this->iv.m_bh = malloc(bihs); - memcpy(this->iv.m_bh, format, bihs); - this->iv.m_bh->biSize = bihs; - - this->iv.m_State = STOP; - //this->iv.m_pFrame = 0; - this->iv.m_Mode = DIRECT; - this->iv.m_iDecpos = 0; - this->iv.m_iPlaypos = -1; - this->iv.m_fQuality = 0.0f; - this->iv.m_bCapable16b = true; - - bihs += sizeof(VIDEOINFOHEADER) - sizeof(BITMAPINFOHEADER); - this->m_sVhdr = malloc(bihs); - memset(this->m_sVhdr, 0, bihs); - memcpy(&this->m_sVhdr->bmiHeader, this->iv.m_bh, this->iv.m_bh->biSize); - this->m_sVhdr->rcSource.left = this->m_sVhdr->rcSource.top = 0; - this->m_sVhdr->rcSource.right = this->m_sVhdr->bmiHeader.biWidth; - this->m_sVhdr->rcSource.bottom = this->m_sVhdr->bmiHeader.biHeight; - //this->m_sVhdr->rcSource.right = 0; - //this->m_sVhdr->rcSource.bottom = 0; - this->m_sVhdr->rcTarget = this->m_sVhdr->rcSource; - - this->m_sOurType.majortype = MEDIATYPE_Video; - this->m_sOurType.subtype = MEDIATYPE_Video; - this->m_sOurType.subtype.f1 = this->m_sVhdr->bmiHeader.biCompression; - this->m_sOurType.formattype = FORMAT_VideoInfo; - this->m_sOurType.bFixedSizeSamples = false; - this->m_sOurType.bTemporalCompression = true; - this->m_sOurType.pUnk = 0; - this->m_sOurType.cbFormat = bihs; - this->m_sOurType.pbFormat = (char*)this->m_sVhdr; - - this->m_sVhdr2 = malloc(sizeof(VIDEOINFOHEADER)+12); - memcpy(this->m_sVhdr2, this->m_sVhdr, sizeof(VIDEOINFOHEADER)); - memset((char*)this->m_sVhdr2 + sizeof(VIDEOINFOHEADER), 0, 12); - this->m_sVhdr2->bmiHeader.biCompression = 0; - this->m_sVhdr2->bmiHeader.biBitCount = 24; - - memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); - this->m_sDestType.majortype = MEDIATYPE_Video; - this->m_sDestType.subtype = MEDIASUBTYPE_RGB24; - this->m_sDestType.formattype = FORMAT_VideoInfo; - this->m_sDestType.bFixedSizeSamples = true; - this->m_sDestType.bTemporalCompression = false; - this->m_sDestType.lSampleSize = labs(this->m_sVhdr2->bmiHeader.biWidth*this->m_sVhdr2->bmiHeader.biHeight - * ((this->m_sVhdr2->bmiHeader.biBitCount + 7) / 8)); - this->m_sVhdr2->bmiHeader.biSizeImage = this->m_sDestType.lSampleSize; - this->m_sDestType.pUnk = 0; - this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER); - this->m_sDestType.pbFormat = (char*)this->m_sVhdr2; - - memset(&this->iv.m_obh, 0, sizeof(this->iv.m_obh)); - memcpy(&this->iv.m_obh, this->iv.m_bh, sizeof(this->iv.m_obh) < (unsigned) this->iv.m_bh->biSize - ? sizeof(this->iv.m_obh) : (unsigned) this->iv.m_bh->biSize); - this->iv.m_obh.biBitCount=24; - this->iv.m_obh.biSize = sizeof(BITMAPINFOHEADER); - this->iv.m_obh.biCompression = 0; //BI_RGB - //this->iv.m_obh.biHeight = labs(this->iv.m_obh.biHeight); - this->iv.m_obh.biSizeImage = labs(this->iv.m_obh.biWidth * this->iv.m_obh.biHeight) - * ((this->iv.m_obh.biBitCount + 7) / 8); - - - this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType,&sampleProcData); - - if (!this->m_pDS_Filter) - { - printf("Failed to create DirectShow filter\n"); - return 0; - } - - if (!flip) - { - this->iv.m_obh.biHeight *= -1; - this->m_sVhdr2->bmiHeader.biHeight = this->iv.m_obh.biHeight; - result = this->m_pDS_Filter->m_pOutputPin->vt->QueryAccept(this->m_pDS_Filter->m_pOutputPin, &this->m_sDestType); - if (result) - { - printf("Decoder does not support upside-down RGB frames\n"); - this->iv.m_obh.biHeight *= -1; - this->m_sVhdr2->bmiHeader.biHeight = this->iv.m_obh.biHeight; - } - } - - memcpy( &this->iv.m_decoder, &this->iv.m_obh, sizeof(this->iv.m_obh) ); - - switch (this->iv.m_bh->biCompression) - { -#if 0 - case fccDIV3: - case fccDIV4: - case fccDIV5: - case fccDIV6: - case fccMP42: - case fccWMV2: - //YV12 seems to be broken for DivX :-) codec -// case fccIV50: - //produces incorrect picture - //m_Caps = (CAPS) (m_Caps & ~CAP_YV12); - //m_Caps = CAP_UYVY;//CAP_YUY2; // | CAP_I420; - //m_Caps = CAP_I420; - this->m_Caps = (CAP_YUY2 | CAP_UYVY); - break; -#endif - default: - - this->m_Caps = CAP_NONE; - - printf("Decoder supports the following YUV formats: "); - for (c = check; c->bits; c++) - { - this->m_sVhdr2->bmiHeader.biBitCount = c->bits; - this->m_sVhdr2->bmiHeader.biCompression = c->fcc; - this->m_sDestType.subtype = *c->subtype; - result = this->m_pDS_Filter->m_pOutputPin->vt->QueryAccept(this->m_pDS_Filter->m_pOutputPin, &this->m_sDestType); - if (!result) - { - this->m_Caps = (this->m_Caps | c->cap); - printf("%.4s ", (char *)&c->fcc); - } - } - printf("\n"); - } - - if (this->m_Caps != CAP_NONE) - printf("Decoder is capable of YUV output (flags 0x%x)\n", (int)this->m_Caps); - - this->m_sVhdr2->bmiHeader.biBitCount = 24; - this->m_sVhdr2->bmiHeader.biCompression = 0; - this->m_sDestType.subtype = MEDIASUBTYPE_RGB24; - - this->m_iMinBuffers = this->iv.VBUFSIZE; - this->m_bIsDivX = (strcmp(dllname, "divxcvki.ax") == 0 - || strcmp(dllname, "divx_c32.ax") == 0 - || strcmp(dllname, "wmvds32.ax") == 0 - || strcmp(dllname, "wmv8ds32.ax") == 0); - this->m_bIsDivX4 = (strcmp(dllname, "divxdec.ax") == 0); - if (this->m_bIsDivX) - this->iv.VBUFSIZE += 7; - else if (this->m_bIsDivX4) - this->iv.VBUFSIZE += 9; - } - /*catch (FatalError& error) - { - delete[] m_sVhdr; - delete[] m_sVhdr2; - delete m_pDS_Filter; - throw; - }*/ - return this; -} - -void DS_VideoDecoder_Destroy(DS_VideoDecoder *this) -{ - DS_VideoDecoder_StopInternal(this); - this->iv.m_State = STOP; - free(this->m_sVhdr); - free(this->m_sVhdr2); - DS_Filter_Destroy(this->m_pDS_Filter); -} - -void DS_VideoDecoder_StartInternal(DS_VideoDecoder *this) -{ - Debug printf("DS_VideoDecoder_StartInternal\n"); - //cout << "DSSTART" << endl; - this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll); - this->m_pDS_Filter->Start(this->m_pDS_Filter); - - this->iv.m_State = START; -} - -void DS_VideoDecoder_StopInternal(DS_VideoDecoder *this) -{ - this->m_pDS_Filter->Stop(this->m_pDS_Filter); - //??? why was this here ??? m_pOurOutput->SetFramePointer(0); -} - -int DS_VideoDecoder_DecodeInternal(DS_VideoDecoder *this, const void* src, int size, int is_keyframe, char* pImage) -{ - IMediaSample* sample = 0; - char* ptr; - int result; - - Debug printf("DS_VideoDecoder_DecodeInternal(%p,%p,%d,%d,%p)\n",this,src,size,is_keyframe,pImage); - - this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0); - - if (!sample) - { - Debug printf("ERROR: null sample\n"); - return -1; - } - - //cout << "DECODE " << (void*) pImage << " d: " << (void*) pImage->Data() << endl; - - - sample->vt->SetActualDataLength(sample, size); - sample->vt->GetPointer(sample, (BYTE **)&ptr); - memcpy(ptr, src, size); - sample->vt->SetSyncPoint(sample, is_keyframe); - sample->vt->SetPreroll(sample, pImage ? 0 : 1); - |