--- trunk/xvidcore/dshow/src/CXvidDecoder.cpp 2004/04/15 19:44:06 1432 +++ trunk/xvidcore/dshow/src/CXvidDecoder.cpp 2004/10/25 10:29:10 1558 @@ -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.6 2004-04-15 19:44:05 edgomez Exp $ + * $Id: CXvidDecoder.cpp,v 1.13 2004-10-25 10:29:10 suxen_drol Exp $ * ****************************************************************************/ @@ -36,11 +36,11 @@ place these paths at the top of the Tools|Options|Directories list headers: - C:\DXVCSDK\include - C:\DXVCSDK\samples\Multimedia\DirectShow\BaseClasses + C:\DX90SDK\Include + C:\DX90SDK\Samples\C++\DirectShow\BaseClasses - libraries (optional): - C:\DXVCSDK\samples\Multimedia\DirectShow\BaseClasses\Release + C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\Release + C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\Debug */ @@ -212,30 +212,28 @@ 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"); - MessageBox(0, XVID_DLL_NAME " not found","Error", 0); + MessageBox(0, XVID_DLL_NAME " not found","Error", MB_TOPMOST); 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); + MessageBox(0, "xvid_global() not found", "Error", MB_TOPMOST); 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); + MessageBox(0, "xvid_decore() not found", "Error", MB_TOPMOST); return; } if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0) { - MessageBox(0, "xvid_global() failed", "Error", 0); + MessageBox(0, "xvid_global() failed", "Error", MB_TOPMOST); return; } @@ -285,6 +283,25 @@ USE_RGB32 = true; break; } + + switch (g_config.aspect_ratio) + { + case 0: + case 1: + break; + case 2: + ar_x = 4; + ar_y = 3; + break; + case 3: + ar_x = 16; + ar_y = 9; + break; + case 4: + ar_x = 47; + ar_y = 20; + break; + } } void CXvidDecoder::CloseLib() @@ -317,6 +334,8 @@ { DPRINTF("CheckInputType"); BITMAPINFOHEADER * hdr; + + ar_x = ar_y = 0; if (*mtIn->Type() != MEDIATYPE_Video) { @@ -329,19 +348,15 @@ { 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 * 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); } else if (*mtIn->FormatType() == FORMAT_VideoInfo2) { VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format(); hdr = &vih2->bmiHeader; - ar_x = vih2->dwPictAspectRatioX; - ar_y = vih2->dwPictAspectRatioY; + if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) { + ar_x = vih2->dwPictAspectRatioX; + ar_y = vih2->dwPictAspectRatioY; + } DPRINTF("VIDEOINFOHEADER2 AR: %d:%d", ar_x, ar_y); } else @@ -421,11 +436,12 @@ if (ar_x != 0 && ar_y != 0) { vih->dwPictAspectRatioX = ar_x; vih->dwPictAspectRatioY = ar_y; + forced_ar = true; } else { // just to be safe vih->dwPictAspectRatioX = m_create.width; vih->dwPictAspectRatioY = abs(m_create.height); - } - + forced_ar = false; + } } else { VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER)); @@ -533,19 +549,24 @@ /* (internal function) change colorspace */ +#define CALC_BI_STRIDE(width,bitcount) ((((width * bitcount) + 31) & ~31) >> 3) HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format) { + DWORD biWidth; + if (formattype == FORMAT_VideoInfo) { VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format; - m_frame.output.stride[0] = (((vih->bmiHeader.biWidth * vih->bmiHeader.biBitCount) + 31) & ~31) >> 3; + biWidth = vih->bmiHeader.biWidth; + m_frame.output.stride[0] = CALC_BI_STRIDE(vih->bmiHeader.biWidth, vih->bmiHeader.biBitCount); rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); } else if (formattype == FORMAT_VideoInfo2) { VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format; - m_frame.output.stride[0] = (((vih2->bmiHeader.biWidth * vih2->bmiHeader.biBitCount) + 31) & ~31) >> 3; + biWidth = vih2->bmiHeader.biWidth; + m_frame.output.stride[0] = CALC_BI_STRIDE(vih2->bmiHeader.biWidth, vih2->bmiHeader.biBitCount); rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); } else @@ -558,14 +579,14 @@ DPRINTF("IYUV"); rgb_flip = 0; m_frame.output.csp = XVID_CSP_I420; - m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3; /* planar format fix */ + m_frame.output.stride[0] = CALC_BI_STRIDE(biWidth, 8); /* planar format fix */ } else if (subtype == MEDIASUBTYPE_YV12) { DPRINTF("YV12"); rgb_flip = 0; m_frame.output.csp = XVID_CSP_YV12; - m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3; /* planar format fix */ + m_frame.output.stride[0] = CALC_BI_STRIDE(biWidth, 8); /* planar format fix */ } else if (subtype == MEDIASUBTYPE_YUY2) { @@ -733,10 +754,13 @@ 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; @@ -745,6 +769,9 @@ m_frame.output.csp &= ~XVID_CSP_VFLIP; m_frame.output.csp |= rgb_flip^(g_config.nFlipVideo ? XVID_CSP_VFLIP : 0); + + + repeat : if (pIn->IsPreroll() != S_OK) @@ -755,6 +782,28 @@ { DPRINTF("*** XVID_DEC_DECODE"); return S_FALSE; + } else + if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1 && forced_ar == false) { + // inspired by minolta! works for VMR 7 + 9 + + IMediaSample2 *pOut2 = NULL; + AM_SAMPLE2_PROPERTIES outProp2; + if (SUCCEEDED(pOut->QueryInterface(IID_IMediaSample2, (void **)&pOut2)) && + SUCCEEDED(pOut2->GetProperties(FIELD_OFFSET(AM_SAMPLE2_PROPERTIES, tStart), (PBYTE)&outProp2))) + { + CMediaType mtOut2 = m_pOutput->CurrentMediaType(); + VIDEOINFOHEADER2* vihOut2 = (VIDEOINFOHEADER2*)mtOut2.Format(); + + if (*mtOut2.FormatType() == FORMAT_VideoInfo2 && + vihOut2->dwPictAspectRatioX != ar_x && vihOut2->dwPictAspectRatioY != ar_y) + { + vihOut2->dwPictAspectRatioX = ar_x; + vihOut2->dwPictAspectRatioY = ar_y; + pOut2->SetMediaType(&mtOut2); + m_pOutput->SetMediaType(&mtOut2); + } + pOut2->Release(); + } } } else @@ -795,10 +844,23 @@ DPRINTF("TODO: auto-resize"); return S_FALSE; } - -// pOut->SetDiscontinuity(TRUE); + pOut->SetSyncPoint(TRUE); + if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) { /* auto */ + int par_x, par_y; + if (stats.data.vol.par == XVID_PAR_EXT) { + par_x = stats.data.vol.par_width; + par_y = stats.data.vol.par_height; + } else { + par_x = PARS[stats.data.vol.par-1][0]; + par_y = PARS[stats.data.vol.par-1][1]; + } + + ar_x = par_x * stats.data.vol.width; + ar_y = par_y * stats.data.vol.height; + } + m_frame.bitstream = (BYTE*)m_frame.bitstream + length; m_frame.length -= length; goto repeat;