--- branches/dev-api-4/xvidcore/dshow/src/CXvidDecoder.cpp 2003/12/17 17:08:29 1271 +++ branches/dev-api-4/xvidcore/dshow/src/CXvidDecoder.cpp 2004/01/26 05:49:42 1334 @@ -19,7 +19,7 @@ * 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.6 2003-12-17 17:08:29 Isibaar Exp $ + * $Id: CXvidDecoder.cpp,v 1.1.2.12 2004-01-26 05:49:42 syskin Exp $ * ****************************************************************************/ @@ -201,6 +201,8 @@ /* constructor */ +#define XVID_DLL_NAME "xvidcore.dll" + CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) : CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID) { @@ -209,7 +211,29 @@ xvid_gbl_init_t init; memset(&init, 0, sizeof(init)); init.version = XVID_VERSION; - if (xvid_global(0, XVID_GBL_INIT, &init, NULL) < 0) + + ar_x = ar_y = 0; + + m_hdll = LoadLibrary(XVID_DLL_NAME); + if (m_hdll == NULL) { + DPRINTF("dll load failed"); + MessageBox(0, XVID_DLL_NAME " not found","Error", 0); + return; + } + + xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"); + if (xvid_global_func == NULL) { + MessageBox(0, "xvid_global() not found", "Error", 0); + return; + } + + xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore"); + if (xvid_decore_func == NULL) { + MessageBox(0, "xvid_decore() not found", "Error", 0); + return; + } + + if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0) { MessageBox(0, "xvid_global() failed", "Error", 0); return; @@ -228,11 +252,12 @@ // 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("Dering", PPSettings.bDering, 0) - REG_GET_N("FilmEffect", PPSettings.bFilmEffect, 0) + REG_GET_N("Deblock_Y", PPSettings.nDeblock_Y, 0) + REG_GET_N("Deblock_UV", PPSettings.nDeblock_UV, 0) + REG_GET_N("Dering", PPSettings.nDering, 0) + REG_GET_N("FilmEffect", PPSettings.nFilmEffect, 0) REG_GET_N("ForceColorspace", PPSettings.nForceColorspace, 0) + REG_GET_N("FlipVideo", PPSettings.nFlipVideo, 0) RegCloseKey(hKey); @@ -285,9 +310,15 @@ if (m_create.handle != NULL) { - xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0); + xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0); m_create.handle = NULL; } + + if (m_hdll != NULL) + { + FreeLibrary(m_hdll); + m_hdll = NULL; + } } @@ -309,11 +340,17 @@ { VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format(); hdr = &vih->bmiHeader; + /* PAR (x:y) is (1/ppm_X):(1/ppm_Y) where ppm is pixels-per-meter + which is equal to ppm_Y:ppm_X */ + ar_x = vih->bmiHeader.biYPelsPerMeter*hdr->biWidth; + ar_y = vih->bmiHeader.biXPelsPerMeter*hdr->biHeight; } else if (*mtIn->FormatType() == FORMAT_VideoInfo2) { VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format(); hdr = &vih2->bmiHeader; + ar_x = vih2->dwPictAspectRatioX; + ar_y = vih2->dwPictAspectRatioY; } else { @@ -362,7 +399,7 @@ return E_UNEXPECTED; } - VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER)); + VIDEOINFOHEADER2 * vih = (VIDEOINFOHEADER2 *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER2)); if (vih == NULL) { return E_OUTOFMEMORY; @@ -381,23 +418,8 @@ switch(iPosition) { - case 0 : -if ( USE_IYUV ) -{ - vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1; - vih->bmiHeader.biBitCount = 12; - mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV); - break; -} - case 1 : -if ( USE_YV12 ) -{ - vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1; - vih->bmiHeader.biBitCount = 12; - mtOut->SetSubtype(&MEDIASUBTYPE_YV12); - break; -} - case 2: + + case 0: if ( USE_YUY2 ) { vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1; @@ -405,7 +427,7 @@ mtOut->SetSubtype(&MEDIASUBTYPE_YUY2); break; } - case 3 : + case 1 : if ( USE_YVYU ) { vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1; @@ -413,7 +435,7 @@ mtOut->SetSubtype(&MEDIASUBTYPE_YVYU); break; } - case 4 : + case 2 : if ( USE_UYVY ) { vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1; @@ -421,6 +443,22 @@ mtOut->SetSubtype(&MEDIASUBTYPE_UYVY); break; } + case 3 : + if ( USE_IYUV ) +{ + vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1; + vih->bmiHeader.biBitCount = 12; + mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV); + break; +} + case 4 : +if ( USE_YV12 ) +{ + vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1; + vih->bmiHeader.biBitCount = 12; + mtOut->SetSubtype(&MEDIASUBTYPE_YV12); + break; +} case 5 : if ( USE_RGB32 ) { @@ -459,8 +497,16 @@ vih->bmiHeader.biSizeImage = GetBitmapSize(&vih->bmiHeader); + if (ar_x != 0 && ar_y != 0) { + vih->dwPictAspectRatioX = ar_x; + vih->dwPictAspectRatioY = ar_y; + } else { // just to be safe + vih->dwPictAspectRatioX = m_create.width; + vih->dwPictAspectRatioY = m_create.height; + } + mtOut->SetType(&MEDIATYPE_Video); - mtOut->SetFormatType(&FORMAT_VideoInfo); + mtOut->SetFormatType(&FORMAT_VideoInfo2); mtOut->SetTemporalCompression(FALSE); mtOut->SetSampleSize(vih->bmiHeader.biSizeImage); @@ -620,7 +666,7 @@ if (m_create.handle == NULL) { - if (xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0) + if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0) { DPRINTF("*** XVID_DEC_CREATE error"); return S_FALSE; @@ -659,36 +705,26 @@ if (pIn->IsDiscontinuity() == S_OK) m_frame.general = XVID_DISCONTINUITY; - if (PPSettings.bDeblock_Y) + if (PPSettings.nDeblock_Y) m_frame.general |= XVID_DEBLOCKY; - if (PPSettings.bDeblock_UV) + if (PPSettings.nDeblock_UV) m_frame.general |= XVID_DEBLOCKUV; /* - if (PPSettings.bDering) + if (PPSettings.nDering) m_frame.general |= XVID_DERING; */ - if (PPSettings.bFilmEffect) + if (PPSettings.nFilmEffect) m_frame.general |= XVID_FILMEFFECT; - 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; - } + m_frame.output.csp &= ~XVID_CSP_VFLIP; + m_frame.output.csp |= rgb_flip^(PPSettings.nFlipVideo ? XVID_CSP_VFLIP : 0); repeat : if (pIn->IsPreroll() != S_OK) { - length = xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); + length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); if (length < 0) { @@ -697,11 +733,19 @@ } } else - { + { /* Preroll frame - won't be displayed */ int tmp = m_frame.output.csp; + int tmp_gen = m_frame.general; + m_frame.output.csp = XVID_CSP_NULL; - length = xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); + /* Disable postprocessing to speed-up seeking */ + m_frame.general &= ~XVID_DEBLOCKY; + m_frame.general &= ~XVID_DEBLOCKUV; +/* m_frame.general &= ~XVID_DERING; */ + m_frame.general &= ~XVID_FILMEFFECT; + + length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); if (length < 0) { DPRINTF("*** XVID_DEC_DECODE"); @@ -709,6 +753,7 @@ } m_frame.output.csp = tmp; + m_frame.general = tmp_gen; } if (stats.type == XVID_TYPE_NOTHING) { @@ -726,11 +771,18 @@ return S_FALSE; } + pOut->SetDiscontinuity(TRUE); + pOut->SetSyncPoint(TRUE); + m_frame.bitstream = (BYTE*)m_frame.bitstream + length; m_frame.length -= length; goto repeat; } + if (pIn->IsPreroll() == S_OK) { + return S_FALSE; + } + return S_OK; }