📄 dmo_videodecoder.c
字号:
/******************************************************** DirectShow Video decoder implementation Copyright 2000 Eugene Kuznetsov (divx@euro.ru)*********************************************************/#include "config.h"#include "dshow/guids.h"#include "dshow/interfaces.h"#include "registry.h"#ifdef WIN32_LOADER#include "../ldt_keeper.h"#endif#include "dshow/libwin32.h"#include "DMO_Filter.h"#include "DMO_VideoDecoder.h"struct _DMO_VideoDecoder{ IVideoDecoder iv; DMO_Filter* m_pDMO_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;};//#include "DMO_VideoDecoder.h"#include "../wine/winerror.h"#include <mplaylib.h>#include <fcntl.h>#include <errno.h>#include <sys/types.h>#ifndef __MINGW32__#include <sys/mman.h>#endif#include <mplaylib.h>#include <mplaylib.h> // labs#undef memcpy#define memcpy uc_memcpy// strcmp((const char*)info.dll,...) is used instead of (... == ...)// so Arpi could use char* pointer in his simplified DMO_VideoDecoder class#define false 0#define true 1//int DMO_VideoDecoder_GetCapabilities(DMO_VideoDecoder *this){return this->m_Caps;}typedef struct _ct ct;struct _ct { fourcc_t fcc; unsigned int bits; const GUID* subtype; int cap; char *name; }; static ct check[] = { { fccI420, 12, &MEDIASUBTYPE_I420, CAP_I420, NULL }, { fccYV12, 12, &MEDIASUBTYPE_YV12, CAP_YV12, NULL }, { fccYUY2, 16, &MEDIASUBTYPE_YUY2, CAP_YUY2, NULL }, { fccUYVY, 16, &MEDIASUBTYPE_UYVY, CAP_UYVY, NULL }, { fccYVYU, 16, &MEDIASUBTYPE_YVYU, CAP_YVYU, NULL }, { fccIYUV, 24, &MEDIASUBTYPE_IYUV, CAP_IYUV, NULL }, { 8, 8, &MEDIASUBTYPE_RGB8, CAP_NONE, "RGB8" }, { 15, 16, &MEDIASUBTYPE_RGB555, CAP_NONE, "RGB555" }, { 16, 16, &MEDIASUBTYPE_RGB565, CAP_NONE, "RGB565" }, { 24, 24, &MEDIASUBTYPE_RGB24, CAP_NONE, "RGB24" }, { 32, 32, &MEDIASUBTYPE_RGB32, CAP_NONE, "RGB32" }, {0,0,NULL,0},};DMO_VideoDecoder * DMO_VideoDecoder_Open(char* dllname, GUID* guid, BITMAPINFOHEADER * format, int flip, int maxauto){ DMO_VideoDecoder *this; HRESULT result; ct* c; this = malloc(sizeof(DMO_VideoDecoder)); memset( this, 0, sizeof(DMO_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 = (VIDEOINFOHEADER*)(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((char*)this->m_sVhdr2, 0, sizeof(VIDEOINFOHEADER)+12); this->m_sVhdr2->rcTarget = this->m_sVhdr->rcTarget;// this->m_sVhdr2->rcSource = this->m_sVhdr->rcSource; 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_pDMO_Filter = DMO_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType); if (!this->m_pDMO_Filter) { printf("Failed to create DMO 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_pDMO_Filter->m_pOutputPin->vt->QueryAccept(this->m_pDMO_Filter->m_pOutputPin, &this->m_sDestType); result = this->m_pDMO_Filter->m_pMedia->vt->SetOutputType(this->m_pDMO_Filter->m_pMedia, 0, &this->m_sDestType, DMO_SET_TYPEF_TEST_ONLY); 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 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_pDMO_Filter->m_pOutputPin->vt->QueryAccept(this->m_pDMO_Filter->m_pOutputPin, &this->m_sDestType); result = this->m_pDMO_Filter->m_pMedia->vt->SetOutputType(this->m_pDMO_Filter->m_pMedia, 0, &this->m_sDestType, DMO_SET_TYPEF_TEST_ONLY); if (!result) { this->m_Caps = (this->m_Caps | c->cap); if (c->name) printf("%s ", c->name); else 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; } /*catch (FatalError& error) { delete[] m_sVhdr; delete[] m_sVhdr2; delete m_pDMO_Filter; throw; }*/ return this;}void DMO_VideoDecoder_Destroy(DMO_VideoDecoder *this){ DMO_VideoDecoder_StopInternal(this); this->iv.m_State = STOP; free(this->m_sVhdr); free(this->m_sVhdr2); DMO_Filter_Destroy(this->m_pDMO_Filter);}void DMO_VideoDecoder_StartInternal(DMO_VideoDecoder *this){#if 0 ALLOCATOR_PROPERTIES props, props1; Debug printf("DMO_VideoDecoder_StartInternal\n"); //cout << "DSSTART" << endl; this->m_pDMO_Filter->Start(this->m_pDMO_Filter);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -