36 |
place these paths at the top of the Tools|Options|Directories list |
place these paths at the top of the Tools|Options|Directories list |
37 |
|
|
38 |
headers: |
headers: |
39 |
C:\DXVCSDK\include |
C:\DX90SDK\Include |
40 |
C:\DXVCSDK\samples\Multimedia\DirectShow\BaseClasses |
C:\DX90SDK\Samples\C++\DirectShow\BaseClasses |
41 |
|
|
42 |
libraries (optional): |
C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\Release |
43 |
C:\DXVCSDK\samples\Multimedia\DirectShow\BaseClasses\Release |
C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\Debug |
44 |
*/ |
*/ |
45 |
|
|
46 |
|
|
204 |
#define XVID_DLL_NAME "xvidcore.dll" |
#define XVID_DLL_NAME "xvidcore.dll" |
205 |
|
|
206 |
CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) : |
CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) : |
207 |
CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID) |
CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID), m_hdll (NULL) |
208 |
{ |
{ |
209 |
DPRINTF("Constructor"); |
DPRINTF("Constructor"); |
210 |
|
|
211 |
|
xvid_decore_func = NULL; // Hmm, some strange errors appearing if I try to initialize... |
212 |
|
xvid_global_func = NULL; // ...this in constructor's init-list. So, they assigned here. |
213 |
|
|
214 |
|
LoadRegistryInfo(); |
215 |
|
|
216 |
|
*phr = OpenLib(); |
217 |
|
} |
218 |
|
|
219 |
|
HRESULT CXvidDecoder::OpenLib() |
220 |
|
{ |
221 |
|
DPRINTF("OpenLib"); |
222 |
|
|
223 |
|
if (m_hdll != NULL) |
224 |
|
return E_UNEXPECTED; // Seems, that library already opened. |
225 |
|
|
226 |
xvid_gbl_init_t init; |
xvid_gbl_init_t init; |
227 |
memset(&init, 0, sizeof(init)); |
memset(&init, 0, sizeof(init)); |
228 |
init.version = XVID_VERSION; |
init.version = XVID_VERSION; |
230 |
m_hdll = LoadLibrary(XVID_DLL_NAME); |
m_hdll = LoadLibrary(XVID_DLL_NAME); |
231 |
if (m_hdll == NULL) { |
if (m_hdll == NULL) { |
232 |
DPRINTF("dll load failed"); |
DPRINTF("dll load failed"); |
233 |
MessageBox(0, XVID_DLL_NAME " not found","Error", 0); |
MessageBox(0, XVID_DLL_NAME " not found","Error", MB_TOPMOST); |
234 |
return; |
return E_FAIL; |
235 |
} |
} |
236 |
|
|
237 |
xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"); |
xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"); |
238 |
if (xvid_global_func == NULL) { |
if (xvid_global_func == NULL) { |
239 |
MessageBox(0, "xvid_global() not found", "Error", 0); |
FreeLibrary(m_hdll); |
240 |
return; |
m_hdll = NULL; |
241 |
|
MessageBox(0, "xvid_global() not found", "Error", MB_TOPMOST); |
242 |
|
return E_FAIL; |
243 |
} |
} |
244 |
|
|
245 |
xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore"); |
xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore"); |
246 |
if (xvid_decore_func == NULL) { |
if (xvid_decore_func == NULL) { |
247 |
MessageBox(0, "xvid_decore() not found", "Error", 0); |
xvid_global_func = NULL; |
248 |
return; |
FreeLibrary(m_hdll); |
249 |
|
m_hdll = NULL; |
250 |
|
MessageBox(0, "xvid_decore() not found", "Error", MB_TOPMOST); |
251 |
|
return E_FAIL; |
252 |
} |
} |
253 |
|
|
254 |
if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0) |
if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0) |
255 |
{ |
{ |
256 |
MessageBox(0, "xvid_global() failed", "Error", 0); |
xvid_global_func = NULL; |
257 |
return; |
xvid_decore_func = NULL; |
258 |
|
FreeLibrary(m_hdll); |
259 |
|
m_hdll = NULL; |
260 |
|
MessageBox(0, "xvid_global() failed", "Error", MB_TOPMOST); |
261 |
|
return E_FAIL; |
262 |
} |
} |
263 |
|
|
264 |
memset(&m_create, 0, sizeof(m_create)); |
memset(&m_create, 0, sizeof(m_create)); |
268 |
memset(&m_frame, 0, sizeof(m_frame)); |
memset(&m_frame, 0, sizeof(m_frame)); |
269 |
m_frame.version = XVID_VERSION; |
m_frame.version = XVID_VERSION; |
270 |
|
|
|
LoadRegistryInfo(); |
|
|
|
|
271 |
USE_IYUV = false; |
USE_IYUV = false; |
272 |
USE_YV12 = false; |
USE_YV12 = false; |
273 |
USE_YUY2 = false; |
USE_YUY2 = false; |
308 |
|
|
309 |
switch (g_config.aspect_ratio) |
switch (g_config.aspect_ratio) |
310 |
{ |
{ |
311 |
case 0: // Auto mode |
case 0: |
|
ar_x = ar_y = 0; |
|
|
break; |
|
312 |
case 1: |
case 1: |
313 |
|
break; |
314 |
|
case 2: |
315 |
ar_x = 4; |
ar_x = 4; |
316 |
ar_y = 3; |
ar_y = 3; |
317 |
break; |
break; |
318 |
case 2: |
case 3: |
319 |
ar_x = 16; |
ar_x = 16; |
320 |
ar_y = 9; |
ar_y = 9; |
321 |
break; |
break; |
322 |
case 3: |
case 4: |
323 |
ar_x = 47; |
ar_x = 47; |
324 |
ar_y = 20; |
ar_y = 20; |
325 |
break; |
break; |
326 |
} |
} |
327 |
|
|
328 |
|
return S_OK; |
329 |
} |
} |
330 |
|
|
331 |
void CXvidDecoder::CloseLib() |
void CXvidDecoder::CloseLib() |
332 |
{ |
{ |
333 |
DPRINTF("Destructor"); |
DPRINTF("CloseLib"); |
334 |
|
|
335 |
if (m_create.handle != NULL) { |
if ((m_create.handle != NULL) && (xvid_decore_func != NULL)) |
336 |
|
{ |
337 |
xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0); |
xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0); |
338 |
m_create.handle = NULL; |
m_create.handle = NULL; |
339 |
} |
} |
342 |
FreeLibrary(m_hdll); |
FreeLibrary(m_hdll); |
343 |
m_hdll = NULL; |
m_hdll = NULL; |
344 |
} |
} |
345 |
|
xvid_decore_func = NULL; |
346 |
|
xvid_global_func = NULL; |
347 |
} |
} |
348 |
|
|
349 |
/* destructor */ |
/* destructor */ |
350 |
|
|
351 |
CXvidDecoder::~CXvidDecoder() |
CXvidDecoder::~CXvidDecoder() |
352 |
{ |
{ |
353 |
|
DPRINTF("Destructor"); |
354 |
CloseLib(); |
CloseLib(); |
355 |
} |
} |
356 |
|
|
363 |
DPRINTF("CheckInputType"); |
DPRINTF("CheckInputType"); |
364 |
BITMAPINFOHEADER * hdr; |
BITMAPINFOHEADER * hdr; |
365 |
|
|
366 |
|
ar_x = ar_y = 0; |
367 |
|
|
368 |
if (*mtIn->Type() != MEDIATYPE_Video) |
if (*mtIn->Type() != MEDIATYPE_Video) |
369 |
{ |
{ |
370 |
DPRINTF("Error: Unknown Type"); |
DPRINTF("Error: Unknown Type"); |
372 |
return VFW_E_TYPE_NOT_ACCEPTED; |
return VFW_E_TYPE_NOT_ACCEPTED; |
373 |
} |
} |
374 |
|
|
375 |
|
if (m_hdll == NULL) |
376 |
|
{ |
377 |
|
HRESULT hr = OpenLib(); |
378 |
|
|
379 |
|
if (FAILED(hr) || (m_hdll == NULL)) // Paranoid checks. |
380 |
|
return VFW_E_TYPE_NOT_ACCEPTED; |
381 |
|
} |
382 |
|
|
383 |
if (*mtIn->FormatType() == FORMAT_VideoInfo) |
if (*mtIn->FormatType() == FORMAT_VideoInfo) |
384 |
{ |
{ |
385 |
VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format(); |
VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format(); |
386 |
hdr = &vih->bmiHeader; |
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 */ |
|
|
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); |
|
387 |
} |
} |
388 |
else if (*mtIn->FormatType() == FORMAT_VideoInfo2) |
else if (*mtIn->FormatType() == FORMAT_VideoInfo2) |
389 |
{ |
{ |
390 |
VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format(); |
VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format(); |
391 |
hdr = &vih2->bmiHeader; |
hdr = &vih2->bmiHeader; |
392 |
if ((ar_x == 0) && (ar_y == 0)) // selected Auto-mode |
if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) { |
|
{ |
|
393 |
ar_x = vih2->dwPictAspectRatioX; |
ar_x = vih2->dwPictAspectRatioX; |
394 |
ar_y = vih2->dwPictAspectRatioY; |
ar_y = vih2->dwPictAspectRatioY; |
395 |
} |
} |
472 |
if (ar_x != 0 && ar_y != 0) { |
if (ar_x != 0 && ar_y != 0) { |
473 |
vih->dwPictAspectRatioX = ar_x; |
vih->dwPictAspectRatioX = ar_x; |
474 |
vih->dwPictAspectRatioY = ar_y; |
vih->dwPictAspectRatioY = ar_y; |
475 |
|
forced_ar = true; |
476 |
} else { // just to be safe |
} else { // just to be safe |
477 |
vih->dwPictAspectRatioX = m_create.width; |
vih->dwPictAspectRatioX = m_create.width; |
478 |
vih->dwPictAspectRatioY = abs(m_create.height); |
vih->dwPictAspectRatioY = abs(m_create.height); |
479 |
|
forced_ar = false; |
480 |
} |
} |
|
|
|
481 |
} else { |
} else { |
482 |
|
|
483 |
VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER)); |
VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER)); |
585 |
|
|
586 |
|
|
587 |
/* (internal function) change colorspace */ |
/* (internal function) change colorspace */ |
588 |
|
#define CALC_BI_STRIDE(width,bitcount) ((((width * bitcount) + 31) & ~31) >> 3) |
589 |
|
|
590 |
HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format) |
HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format) |
591 |
{ |
{ |
592 |
|
DWORD biWidth; |
593 |
|
|
594 |
if (formattype == FORMAT_VideoInfo) |
if (formattype == FORMAT_VideoInfo) |
595 |
{ |
{ |
596 |
VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format; |
VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format; |
597 |
m_frame.output.stride[0] = (((vih->bmiHeader.biWidth * vih->bmiHeader.biBitCount) + 31) & ~31) >> 3; |
biWidth = vih->bmiHeader.biWidth; |
598 |
|
m_frame.output.stride[0] = CALC_BI_STRIDE(vih->bmiHeader.biWidth, vih->bmiHeader.biBitCount); |
599 |
rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); |
rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); |
600 |
} |
} |
601 |
else if (formattype == FORMAT_VideoInfo2) |
else if (formattype == FORMAT_VideoInfo2) |
602 |
{ |
{ |
603 |
VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format; |
VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format; |
604 |
m_frame.output.stride[0] = (((vih2->bmiHeader.biWidth * vih2->bmiHeader.biBitCount) + 31) & ~31) >> 3; |
biWidth = vih2->bmiHeader.biWidth; |
605 |
|
m_frame.output.stride[0] = CALC_BI_STRIDE(vih2->bmiHeader.biWidth, vih2->bmiHeader.biBitCount); |
606 |
rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); |
rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); |
607 |
} |
} |
608 |
else |
else |
615 |
DPRINTF("IYUV"); |
DPRINTF("IYUV"); |
616 |
rgb_flip = 0; |
rgb_flip = 0; |
617 |
m_frame.output.csp = XVID_CSP_I420; |
m_frame.output.csp = XVID_CSP_I420; |
618 |
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 */ |
619 |
} |
} |
620 |
else if (subtype == MEDIASUBTYPE_YV12) |
else if (subtype == MEDIASUBTYPE_YV12) |
621 |
{ |
{ |
622 |
DPRINTF("YV12"); |
DPRINTF("YV12"); |
623 |
rgb_flip = 0; |
rgb_flip = 0; |
624 |
m_frame.output.csp = XVID_CSP_YV12; |
m_frame.output.csp = XVID_CSP_YV12; |
625 |
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 */ |
626 |
} |
} |
627 |
else if (subtype == MEDIASUBTYPE_YUY2) |
else if (subtype == MEDIASUBTYPE_YUY2) |
628 |
{ |
{ |
746 |
|
|
747 |
if (m_create.handle == NULL) |
if (m_create.handle == NULL) |
748 |
{ |
{ |
749 |
|
if (xvid_decore_func == NULL) |
750 |
|
return E_FAIL; |
751 |
|
|
752 |
if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0) |
if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0) |
753 |
{ |
{ |
754 |
DPRINTF("*** XVID_DEC_CREATE error"); |
DPRINTF("*** XVID_DEC_CREATE error"); |
808 |
m_frame.output.csp &= ~XVID_CSP_VFLIP; |
m_frame.output.csp &= ~XVID_CSP_VFLIP; |
809 |
m_frame.output.csp |= rgb_flip^(g_config.nFlipVideo ? XVID_CSP_VFLIP : 0); |
m_frame.output.csp |= rgb_flip^(g_config.nFlipVideo ? XVID_CSP_VFLIP : 0); |
810 |
|
|
811 |
|
// Paranoid check. |
812 |
|
if (xvid_decore_func == NULL) |
813 |
|
return E_FAIL; |
814 |
|
|
815 |
|
|
816 |
|
|
817 |
repeat : |
repeat : |
818 |
|
|
819 |
if (pIn->IsPreroll() != S_OK) |
if (pIn->IsPreroll() != S_OK) |
824 |
{ |
{ |
825 |
DPRINTF("*** XVID_DEC_DECODE"); |
DPRINTF("*** XVID_DEC_DECODE"); |
826 |
return S_FALSE; |
return S_FALSE; |
827 |
|
} else |
828 |
|
if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1 && forced_ar == false) { |
829 |
|
// inspired by minolta! works for VMR 7 + 9 |
830 |
|
|
831 |
|
IMediaSample2 *pOut2 = NULL; |
832 |
|
AM_SAMPLE2_PROPERTIES outProp2; |
833 |
|
if (SUCCEEDED(pOut->QueryInterface(IID_IMediaSample2, (void **)&pOut2)) && |
834 |
|
SUCCEEDED(pOut2->GetProperties(FIELD_OFFSET(AM_SAMPLE2_PROPERTIES, tStart), (PBYTE)&outProp2))) |
835 |
|
{ |
836 |
|
CMediaType mtOut2 = m_pOutput->CurrentMediaType(); |
837 |
|
VIDEOINFOHEADER2* vihOut2 = (VIDEOINFOHEADER2*)mtOut2.Format(); |
838 |
|
|
839 |
|
if (*mtOut2.FormatType() == FORMAT_VideoInfo2 && |
840 |
|
vihOut2->dwPictAspectRatioX != ar_x && vihOut2->dwPictAspectRatioY != ar_y) |
841 |
|
{ |
842 |
|
vihOut2->dwPictAspectRatioX = ar_x; |
843 |
|
vihOut2->dwPictAspectRatioY = ar_y; |
844 |
|
pOut2->SetMediaType(&mtOut2); |
845 |
|
m_pOutput->SetMediaType(&mtOut2); |
846 |
|
} |
847 |
|
pOut2->Release(); |
848 |
|
} |
849 |
} |
} |
850 |
} |
} |
851 |
else |
else |
887 |
return S_FALSE; |
return S_FALSE; |
888 |
} |
} |
889 |
|
|
|
// pOut->SetDiscontinuity(TRUE); |
|
890 |
pOut->SetSyncPoint(TRUE); |
pOut->SetSyncPoint(TRUE); |
891 |
|
|
892 |
|
if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) { /* auto */ |
893 |
|
int par_x, par_y; |
894 |
|
if (stats.data.vol.par == XVID_PAR_EXT) { |
895 |
|
par_x = stats.data.vol.par_width; |
896 |
|
par_y = stats.data.vol.par_height; |
897 |
|
} else { |
898 |
|
par_x = PARS[stats.data.vol.par-1][0]; |
899 |
|
par_y = PARS[stats.data.vol.par-1][1]; |
900 |
|
} |
901 |
|
|
902 |
|
ar_x = par_x * stats.data.vol.width; |
903 |
|
ar_y = par_y * stats.data.vol.height; |
904 |
|
} |
905 |
|
|
906 |
m_frame.bitstream = (BYTE*)m_frame.bitstream + length; |
m_frame.bitstream = (BYTE*)m_frame.bitstream + length; |
907 |
m_frame.length -= length; |
m_frame.length -= length; |
908 |
goto repeat; |
goto repeat; |