--- trunk/xvidcore/dshow/src/CXvidDecoder.cpp 2004/04/01 11:11:28 1397 +++ trunk/xvidcore/dshow/src/CXvidDecoder.cpp 2004/07/11 10:22:47 1488 @@ -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.3 2004-04-01 11:11:28 suxen_drol Exp $ + * $Id: CXvidDecoder.cpp,v 1.8 2004-07-11 10:22:47 syskin Exp $ * ****************************************************************************/ @@ -212,8 +212,6 @@ memset(&init, 0, sizeof(init)); init.version = XVID_VERSION; - ar_x = ar_y = 0; - m_hdll = LoadLibrary(XVID_DLL_NAME); if (m_hdll == NULL) { DPRINTF("dll load failed"); @@ -285,29 +283,49 @@ USE_RGB32 = true; break; } -} - - -/* destructor */ + switch (g_config.aspect_ratio) + { + case 0: // Auto mode + ar_x = ar_y = 0; + break; + case 1: + ar_x = 4; + ar_y = 3; + break; + case 2: + ar_x = 16; + ar_y = 9; + break; + case 3: + ar_x = 47; + ar_y = 20; + break; + } +} -CXvidDecoder::~CXvidDecoder() +void CXvidDecoder::CloseLib() { DPRINTF("Destructor"); - if (m_create.handle != NULL) - { + if (m_create.handle != NULL) { xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0); m_create.handle = NULL; } - if (m_hdll != NULL) - { + if (m_hdll != NULL) { FreeLibrary(m_hdll); m_hdll = NULL; } } +/* destructor */ + +CXvidDecoder::~CXvidDecoder() +{ + CloseLib(); +} + /* check input type */ @@ -320,6 +338,7 @@ if (*mtIn->Type() != MEDIATYPE_Video) { DPRINTF("Error: Unknown Type"); + CloseLib(); return VFW_E_TYPE_NOT_ACCEPTED; } @@ -329,8 +348,11 @@ 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 * abs(hdr->biWidth); - ar_y = vih->bmiHeader.biXPelsPerMeter * abs(hdr->biHeight); + if ((ar_x == 0) && (ar_y == 0)) // selected Auto-mode + { + ar_x = vih->bmiHeader.biYPelsPerMeter * abs(hdr->biWidth); + ar_y = vih->bmiHeader.biXPelsPerMeter * abs(hdr->biHeight); + } DPRINTF("VIDEOINFOHEADER PAR: %d:%d -> AR %d:%d", vih->bmiHeader.biYPelsPerMeter,vih->bmiHeader.biXPelsPerMeter, ar_x, ar_y); } @@ -338,13 +360,17 @@ { VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format(); hdr = &vih2->bmiHeader; - ar_x = vih2->dwPictAspectRatioX; - ar_y = vih2->dwPictAspectRatioY; + if ((ar_x == 0) && (ar_y == 0)) // selected Auto-mode + { + ar_x = vih2->dwPictAspectRatioX; + ar_y = vih2->dwPictAspectRatioY; + } DPRINTF("VIDEOINFOHEADER2 AR: %d:%d", ar_x, ar_y); } else { DPRINTF("Error: Unknown FormatType"); + CloseLib(); return VFW_E_TYPE_NOT_ACCEPTED; } @@ -360,13 +386,22 @@ { case FOURCC_MP4V: - if (!(g_config.supported_4cc & SUPPORT_MP4V)) return VFW_E_TYPE_NOT_ACCEPTED; + if (!(g_config.supported_4cc & SUPPORT_MP4V)) { + CloseLib(); + return VFW_E_TYPE_NOT_ACCEPTED; + } break; case FOURCC_DIVX : - if (!(g_config.supported_4cc & SUPPORT_DIVX)) return VFW_E_TYPE_NOT_ACCEPTED; + if (!(g_config.supported_4cc & SUPPORT_DIVX)) { + CloseLib(); + return VFW_E_TYPE_NOT_ACCEPTED; + } break; case FOURCC_DX50 : - if (!(g_config.supported_4cc & SUPPORT_DX50)) return VFW_E_TYPE_NOT_ACCEPTED; + if (!(g_config.supported_4cc & SUPPORT_DX50)) { + CloseLib(); + return VFW_E_TYPE_NOT_ACCEPTED; + } case FOURCC_XVID : break; @@ -378,6 +413,7 @@ (hdr->biCompression>>8)&0xff, (hdr->biCompression>>16)&0xff, (hdr->biCompression>>24)&0xff); + CloseLib(); return VFW_E_TYPE_NOT_ACCEPTED; } return S_OK; @@ -713,17 +749,20 @@ m_frame.general = XVID_LOWDELAY; if (pIn->IsDiscontinuity() == S_OK) - m_frame.general = XVID_DISCONTINUITY; + m_frame.general |= XVID_DISCONTINUITY; if (g_config.nDeblock_Y) m_frame.general |= XVID_DEBLOCKY; if (g_config.nDeblock_UV) m_frame.general |= XVID_DEBLOCKUV; -/* - if (g_config.nDering) - m_frame.general |= XVID_DERING; -*/ + + if (g_config.nDering_Y) + m_frame.general |= XVID_DERINGY; + + if (g_config.nDering_UV) + m_frame.general |= XVID_DERINGUV; + if (g_config.nFilmEffect) m_frame.general |= XVID_FILMEFFECT; @@ -769,7 +808,7 @@ } if (stats.type == XVID_TYPE_NOTHING && length > 0) { - DPRINTF("B-Frame decoder lag"); + DPRINTF(" B-Frame decoder lag"); return S_FALSE; }