--- branches/dev-api-4/xvidcore/dshow/src/CXvidDecoder.cpp 2003/02/22 08:22:03 888 +++ branches/dev-api-4/xvidcore/dshow/src/CXvidDecoder.cpp 2003/12/12 15:09:01 1260 @@ -1,23 +1,35 @@ -/************************************************************************** +/***************************************************************************** * - * XVID DIRECTSHOW FRONTEND -- decoder fitler - * Copyright (c) 2002 Peter Ross + * XVID MPEG-4 VIDEO CODEC + * - XviD Decoder part of the DShow Filter - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright(C) 2002-2003 Peter Ross * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is free software ; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation ; either version 2 of the License, or + * (at your option) any later version. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY ; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - *************************************************************************/ + * You should have received a copy of the GNU General Public License + * along with this program ; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: CXvidDecoder.cpp,v 1.1.2.5 2003-12-12 15:09:01 Isibaar Exp $ + * + ****************************************************************************/ + +/**************************************************************************** + * + * 2003/12/11 - added some additional options, mainly to make the deblocking + * code from xvidcore available. Most of the new code is taken + * from Nic's dshow filter, (C) Nic, http://nic.dnsalias.com + * + ****************************************************************************/ /* this requires the directx sdk @@ -49,6 +61,20 @@ #include "CXvidDecoder.h" #include "CAbout.h" +// Externs defined here +PostProcessing_Settings PPSettings; + +int rgb_flip; + +bool USE_IYUV; +bool USE_YV12; +bool USE_YUY2; +bool USE_YVYU; +bool USE_UYVY; +bool USE_RGB32; +bool USE_RGB24; +bool USE_RG555; +bool USE_RG565; const AMOVIESETUP_MEDIATYPE sudInputPinTypes[] = { @@ -127,8 +153,6 @@ int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate); - - STDAPI DllRegisterServer() { return AMovieDllRegisterServer2( TRUE ); @@ -175,53 +199,19 @@ -/* dummy decore() */ - -static int dummy_xvid_decore(void * handle, int opt, void * param1, void * param2) -{ - return XVID_ERR_FAIL; -} - - - /* constructor */ -#define XVID_DLL_NAME "xvid.dll" -#define XVID_GLOBAL_NAME "xvid_global" -#define XVID_DECORE_NAME "xvid_decore" - CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) : CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID) { DPRINTF("Constructor"); - m_xvid_decore = dummy_xvid_decore; - - m_hdll = LoadLibrary(XVID_DLL_NAME); - if (m_hdll == NULL) { - DPRINTF("dll load failed"); - MessageBox(0, XVID_DLL_NAME " not found","Error", 0); - return; - } - - m_xvid_global = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, XVID_GLOBAL_NAME); - if (m_xvid_global == NULL) { - MessageBox(0, XVID_GLOBAL_NAME "() not found", "Error", 0); - return; - } - - m_xvid_decore = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, XVID_DECORE_NAME); - if (m_xvid_decore == NULL) { - MessageBox(0, XVID_DECORE_NAME "() not found", "Error", 0); - return; - } - xvid_gbl_init_t init; memset(&init, 0, sizeof(init)); init.version = XVID_VERSION; - if (m_xvid_global(0, XVID_GBL_INIT, &init, NULL) < 0) + if (xvid_global(0, XVID_GBL_INIT, &init, NULL) < 0) { - MessageBox(0, XVID_GLOBAL_NAME "() failed", "Error", 0); + MessageBox(0, "xvid_global() failed", "Error", 0); return; } @@ -231,6 +221,56 @@ memset(&m_frame, 0, sizeof(m_frame)); m_frame.version = XVID_VERSION; + + HKEY hKey; + DWORD size; + RegOpenKeyEx(XVID_REG_KEY, XVID_REG_SUBKEY, 0, KEY_READ, &hKey); + + // Set the default post-processing settings + REG_GET_N("Brightness", PPSettings.nBrightness, 25) + REG_GET_N("Deblock_Y", PPSettings.bDeblock_Y, 0) + REG_GET_N("Deblock_UV", PPSettings.bDeblock_UV, 0) + REG_GET_N("ForceColorspace", PPSettings.nForceColorspace, 0) + + RegCloseKey(hKey); + + USE_IYUV = false; + USE_YV12 = false; + USE_YUY2 = false; + USE_YVYU = false; + USE_UYVY = false; + USE_RGB32 = false; + USE_RGB24 = false; + USE_RG555 = false; + USE_RG565 = false; + + switch ( PPSettings.nForceColorspace ) + { + case FORCE_NONE: + USE_IYUV = true; + USE_YV12 = true; + USE_YUY2 = true; + USE_YVYU = true; + USE_UYVY = true; + USE_RGB32 = true; + USE_RGB24 = true; + USE_RG555 = true; + USE_RG565 = true; + break; + case FORCE_YV12: + USE_IYUV = true; + USE_YV12 = true; + break; + case FORCE_YUY2: + USE_YUY2 = true; + break; + case FORCE_RGB24: + USE_RGB24 = true; + break; + case FORCE_RGB32: + USE_RGB32 = true; + break; + } } @@ -243,15 +283,9 @@ if (m_create.handle != NULL) { - m_xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0); + xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0); m_create.handle = NULL; } - - if (m_hdll != NULL) - { - FreeLibrary(m_hdll); - m_hdll = NULL; - } } @@ -314,18 +348,9 @@ } -#define USE_IYUV -#define USE_YV12 -#define USE_YUY2 -#define USE_YVYU -#define USE_UYVY -#define USE_RGB32 -#define USE_RGB24 -#define USE_RG555 -#define USE_RG565 - /* get list of supported output colorspaces */ + HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut) { DPRINTF("GetMediaType"); @@ -355,68 +380,77 @@ switch(iPosition) { case 0 : -#ifdef USE_IYUV - vih->bmiHeader.biCompression = MEDIASUBTYPE_IYUV.Data1; +if ( USE_IYUV ) +{ + vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1; vih->bmiHeader.biBitCount = 12; - mtOut->SetSubtype(&MEDIASUBTYPE_IYUV); + mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV); break; -#endif +} case 1 : -#ifdef USE_YV12 +if ( USE_YV12 ) +{ vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1; vih->bmiHeader.biBitCount = 12; mtOut->SetSubtype(&MEDIASUBTYPE_YV12); break; -#endif +} case 2: -#ifdef USE_YUY2 +if ( USE_YUY2 ) +{ vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1; vih->bmiHeader.biBitCount = 16; mtOut->SetSubtype(&MEDIASUBTYPE_YUY2); break; -#endif +} case 3 : -#ifdef USE_YVYU +if ( USE_YVYU ) +{ vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1; vih->bmiHeader.biBitCount = 16; mtOut->SetSubtype(&MEDIASUBTYPE_YVYU); break; -#endif +} case 4 : -#ifdef USE_UYVY +if ( USE_UYVY ) +{ vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1; vih->bmiHeader.biBitCount = 16; mtOut->SetSubtype(&MEDIASUBTYPE_UYVY); break; -#endif +} case 5 : -#ifdef USE_RGB32 +if ( USE_RGB32 ) +{ vih->bmiHeader.biCompression = BI_RGB; vih->bmiHeader.biBitCount = 32; mtOut->SetSubtype(&MEDIASUBTYPE_RGB32); break; -#endif +} case 6 : -#ifdef USE_RGB24 +if ( USE_RGB24 ) +{ vih->bmiHeader.biCompression = BI_RGB; vih->bmiHeader.biBitCount = 24; mtOut->SetSubtype(&MEDIASUBTYPE_RGB24); break; -#endif +} case 7 : -#ifdef USE_RG555 +if ( USE_RG555 ) +{ vih->bmiHeader.biCompression = BI_RGB; vih->bmiHeader.biBitCount = 16; mtOut->SetSubtype(&MEDIASUBTYPE_RGB555); break; -#endif +} case 8 : -#ifdef USE_RG565 +if ( USE_RG565 ) +{ vih->bmiHeader.biCompression = BI_RGB; vih->bmiHeader.biBitCount = 16; mtOut->SetSubtype(&MEDIASUBTYPE_RGB565); break; -#endif +} default : return VFW_S_NO_MORE_ITEMS; } @@ -436,8 +470,6 @@ HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format) { - int rgb_flip; - if (formattype == FORMAT_VideoInfo) { VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format; @@ -455,7 +487,7 @@ return S_FALSE; } - if (subtype == MEDIASUBTYPE_IYUV) + if (subtype == CLSID_MEDIASUBTYPE_IYUV) { DPRINTF("IYUV"); m_frame.output.csp = XVID_CSP_I420; @@ -586,7 +618,7 @@ if (m_create.handle == NULL) { - if (m_xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0) + if (xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0) { DPRINTF("*** XVID_DEC_CREATE error"); return S_FALSE; @@ -621,14 +653,35 @@ } m_frame.general = XVID_LOWDELAY; + if (pIn->IsDiscontinuity() == S_OK) m_frame.general = XVID_DISCONTINUITY; + if (PPSettings.bDeblock_Y) + m_frame.general |= XVID_DEBLOCKY; + + if (PPSettings.bDeblock_UV) + m_frame.general |= XVID_DEBLOCKUV; + + if (PPSettings.bFlipVideo) { + if (rgb_flip) + m_frame.output.csp &= ~XVID_CSP_VFLIP; + else + m_frame.output.csp |= XVID_CSP_VFLIP; + } + else { + if (rgb_flip) + m_frame.output.csp |= XVID_CSP_VFLIP; + else + m_frame.output.csp &= ~XVID_CSP_VFLIP; + } + repeat : if (pIn->IsPreroll() != S_OK) { - length = m_xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); + length = xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); + if (length < 0) { DPRINTF("*** XVID_DEC_DECODE"); @@ -640,7 +693,7 @@ int tmp = m_frame.output.csp; m_frame.output.csp = XVID_CSP_NULL; - length = m_xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); + length = xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); if (length < 0) { DPRINTF("*** XVID_DEC_DECODE"); @@ -650,6 +703,12 @@ m_frame.output.csp = tmp; } + if (stats.type == XVID_TYPE_NOTHING) { + DPRINTF("B-Frame decoder lag"); + return S_FALSE; + } + + if (stats.type == XVID_TYPE_VOL) { if (stats.data.vol.width != m_create.width ||