1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID DIRECTSHOW FRONTEND -- decoder fitler |
* XVID MPEG-4 VIDEO CODEC |
4 |
* Copyright (c) 2002 Peter Ross <pross@xvid.org> |
* - XviD Decoder part of the DShow Filter - |
5 |
|
* |
6 |
|
* Copyright(C) 2002-2003 Peter Ross <pross@xvid.org> |
7 |
* |
* |
8 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
17 |
* |
* |
18 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
19 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
20 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
|
* |
22 |
|
* $Id: CXvidDecoder.cpp,v 1.1.2.8 2004-01-02 13:18:28 syskin Exp $ |
23 |
|
* |
24 |
|
****************************************************************************/ |
25 |
|
|
26 |
|
/**************************************************************************** |
27 |
|
* |
28 |
|
* 2003/12/11 - added some additional options, mainly to make the deblocking |
29 |
|
* code from xvidcore available. Most of the new code is taken |
30 |
|
* from Nic's dshow filter, (C) Nic, http://nic.dnsalias.com |
31 |
* |
* |
32 |
*************************************************************************/ |
****************************************************************************/ |
33 |
|
|
34 |
/* |
/* |
35 |
this requires the directx sdk |
this requires the directx sdk |
61 |
#include "CXvidDecoder.h" |
#include "CXvidDecoder.h" |
62 |
#include "CAbout.h" |
#include "CAbout.h" |
63 |
|
|
64 |
|
// Externs defined here |
65 |
|
PostProcessing_Settings PPSettings; |
66 |
|
|
67 |
|
int rgb_flip; |
68 |
|
|
69 |
|
bool USE_IYUV; |
70 |
|
bool USE_YV12; |
71 |
|
bool USE_YUY2; |
72 |
|
bool USE_YVYU; |
73 |
|
bool USE_UYVY; |
74 |
|
bool USE_RGB32; |
75 |
|
bool USE_RGB24; |
76 |
|
bool USE_RG555; |
77 |
|
bool USE_RG565; |
78 |
|
|
79 |
const AMOVIESETUP_MEDIATYPE sudInputPinTypes[] = |
const AMOVIESETUP_MEDIATYPE sudInputPinTypes[] = |
80 |
{ |
{ |
153 |
int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate); |
int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate); |
154 |
|
|
155 |
|
|
|
|
|
|
|
|
156 |
STDAPI DllRegisterServer() |
STDAPI DllRegisterServer() |
157 |
{ |
{ |
158 |
return AMovieDllRegisterServer2( TRUE ); |
return AMovieDllRegisterServer2( TRUE ); |
199 |
|
|
200 |
|
|
201 |
|
|
|
/* dummy decore() */ |
|
|
|
|
|
static int dummy_xvid_decore(void * handle, int opt, void * param1, void * param2) |
|
|
{ |
|
|
return XVID_ERR_FAIL; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
202 |
/* constructor */ |
/* constructor */ |
203 |
|
|
204 |
#define XVID_DLL_NAME "xvid.dll" |
#define XVID_DLL_NAME "xvidcore.dll" |
|
#define XVID_GLOBAL_NAME "xvid_global" |
|
|
#define XVID_DECORE_NAME "xvid_decore" |
|
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) |
208 |
{ |
{ |
209 |
DPRINTF("Constructor"); |
DPRINTF("Constructor"); |
210 |
|
|
211 |
m_xvid_decore = dummy_xvid_decore; |
xvid_gbl_init_t init; |
212 |
|
memset(&init, 0, sizeof(init)); |
213 |
|
init.version = XVID_VERSION; |
214 |
|
|
215 |
m_hdll = LoadLibrary(XVID_DLL_NAME); |
m_hdll = LoadLibrary(XVID_DLL_NAME); |
216 |
if (m_hdll == NULL) { |
if (m_hdll == NULL) { |
219 |
return; |
return; |
220 |
} |
} |
221 |
|
|
222 |
m_xvid_global = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, XVID_GLOBAL_NAME); |
xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"); |
223 |
if (m_xvid_global == NULL) { |
if (xvid_global_func == NULL) { |
224 |
MessageBox(0, XVID_GLOBAL_NAME "() not found", "Error", 0); |
MessageBox(0, "xvid_global() not found", "Error", 0); |
225 |
return; |
return; |
226 |
} |
} |
227 |
|
|
228 |
m_xvid_decore = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, XVID_DECORE_NAME); |
xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore"); |
229 |
if (m_xvid_decore == NULL) { |
if (xvid_decore_func == NULL) { |
230 |
MessageBox(0, XVID_DECORE_NAME "() not found", "Error", 0); |
MessageBox(0, "xvid_decore() not found", "Error", 0); |
231 |
return; |
return; |
232 |
} |
} |
233 |
|
|
234 |
xvid_gbl_init_t init; |
if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0) |
|
memset(&init, 0, sizeof(init)); |
|
|
init.version = XVID_VERSION; |
|
|
if (m_xvid_global(0, XVID_GBL_INIT, &init, NULL) < 0) |
|
235 |
{ |
{ |
236 |
MessageBox(0, XVID_GLOBAL_NAME "() failed", "Error", 0); |
MessageBox(0, "xvid_global() failed", "Error", 0); |
237 |
return; |
return; |
238 |
} |
} |
239 |
|
|
243 |
|
|
244 |
memset(&m_frame, 0, sizeof(m_frame)); |
memset(&m_frame, 0, sizeof(m_frame)); |
245 |
m_frame.version = XVID_VERSION; |
m_frame.version = XVID_VERSION; |
246 |
|
|
247 |
|
HKEY hKey; |
248 |
|
DWORD size; |
249 |
|
RegOpenKeyEx(XVID_REG_KEY, XVID_REG_SUBKEY, 0, KEY_READ, &hKey); |
250 |
|
|
251 |
|
// Set the default post-processing settings |
252 |
|
REG_GET_N("Brightness", PPSettings.nBrightness, 25) |
253 |
|
REG_GET_N("Deblock_Y", PPSettings.bDeblock_Y, 1) |
254 |
|
REG_GET_N("Deblock_UV", PPSettings.bDeblock_UV, 1) |
255 |
|
REG_GET_N("Dering", PPSettings.bDering, 1) |
256 |
|
REG_GET_N("FilmEffect", PPSettings.bFilmEffect, 1) |
257 |
|
REG_GET_N("ForceColorspace", PPSettings.nForceColorspace, 0) |
258 |
|
|
259 |
|
RegCloseKey(hKey); |
260 |
|
|
261 |
|
USE_IYUV = false; |
262 |
|
USE_YV12 = false; |
263 |
|
USE_YUY2 = false; |
264 |
|
USE_YVYU = false; |
265 |
|
USE_UYVY = false; |
266 |
|
USE_RGB32 = false; |
267 |
|
USE_RGB24 = false; |
268 |
|
USE_RG555 = false; |
269 |
|
USE_RG565 = false; |
270 |
|
|
271 |
|
switch ( PPSettings.nForceColorspace ) |
272 |
|
{ |
273 |
|
case FORCE_NONE: |
274 |
|
USE_IYUV = true; |
275 |
|
USE_YV12 = true; |
276 |
|
USE_YUY2 = true; |
277 |
|
USE_YVYU = true; |
278 |
|
USE_UYVY = true; |
279 |
|
USE_RGB32 = true; |
280 |
|
USE_RGB24 = true; |
281 |
|
USE_RG555 = true; |
282 |
|
USE_RG565 = true; |
283 |
|
break; |
284 |
|
case FORCE_YV12: |
285 |
|
USE_IYUV = true; |
286 |
|
USE_YV12 = true; |
287 |
|
break; |
288 |
|
case FORCE_YUY2: |
289 |
|
USE_YUY2 = true; |
290 |
|
break; |
291 |
|
case FORCE_RGB24: |
292 |
|
USE_RGB24 = true; |
293 |
|
break; |
294 |
|
case FORCE_RGB32: |
295 |
|
USE_RGB32 = true; |
296 |
|
break; |
297 |
|
} |
298 |
} |
} |
299 |
|
|
300 |
|
|
307 |
|
|
308 |
if (m_create.handle != NULL) |
if (m_create.handle != NULL) |
309 |
{ |
{ |
310 |
m_xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0); |
xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0); |
311 |
m_create.handle = NULL; |
m_create.handle = NULL; |
312 |
} |
} |
313 |
|
|
378 |
} |
} |
379 |
|
|
380 |
|
|
|
#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 |
|
|
|
|
381 |
/* get list of supported output colorspaces */ |
/* get list of supported output colorspaces */ |
382 |
|
|
383 |
|
|
384 |
HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut) |
HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut) |
385 |
{ |
{ |
386 |
DPRINTF("GetMediaType"); |
DPRINTF("GetMediaType"); |
410 |
switch(iPosition) |
switch(iPosition) |
411 |
{ |
{ |
412 |
case 0 : |
case 0 : |
413 |
#ifdef USE_IYUV |
if ( USE_IYUV ) |
414 |
vih->bmiHeader.biCompression = MEDIASUBTYPE_IYUV.Data1; |
{ |
415 |
|
vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1; |
416 |
vih->bmiHeader.biBitCount = 12; |
vih->bmiHeader.biBitCount = 12; |
417 |
mtOut->SetSubtype(&MEDIASUBTYPE_IYUV); |
mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV); |
418 |
break; |
break; |
419 |
#endif |
} |
420 |
case 1 : |
case 1 : |
421 |
#ifdef USE_YV12 |
if ( USE_YV12 ) |
422 |
|
{ |
423 |
vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1; |
vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1; |
424 |
vih->bmiHeader.biBitCount = 12; |
vih->bmiHeader.biBitCount = 12; |
425 |
mtOut->SetSubtype(&MEDIASUBTYPE_YV12); |
mtOut->SetSubtype(&MEDIASUBTYPE_YV12); |
426 |
break; |
break; |
427 |
#endif |
} |
428 |
case 2: |
case 2: |
429 |
#ifdef USE_YUY2 |
if ( USE_YUY2 ) |
430 |
|
{ |
431 |
vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1; |
vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1; |
432 |
vih->bmiHeader.biBitCount = 16; |
vih->bmiHeader.biBitCount = 16; |
433 |
mtOut->SetSubtype(&MEDIASUBTYPE_YUY2); |
mtOut->SetSubtype(&MEDIASUBTYPE_YUY2); |
434 |
break; |
break; |
435 |
#endif |
} |
436 |
case 3 : |
case 3 : |
437 |
#ifdef USE_YVYU |
if ( USE_YVYU ) |
438 |
|
{ |
439 |
vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1; |
vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1; |
440 |
vih->bmiHeader.biBitCount = 16; |
vih->bmiHeader.biBitCount = 16; |
441 |
mtOut->SetSubtype(&MEDIASUBTYPE_YVYU); |
mtOut->SetSubtype(&MEDIASUBTYPE_YVYU); |
442 |
break; |
break; |
443 |
#endif |
} |
444 |
case 4 : |
case 4 : |
445 |
#ifdef USE_UYVY |
if ( USE_UYVY ) |
446 |
|
{ |
447 |
vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1; |
vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1; |
448 |
vih->bmiHeader.biBitCount = 16; |
vih->bmiHeader.biBitCount = 16; |
449 |
mtOut->SetSubtype(&MEDIASUBTYPE_UYVY); |
mtOut->SetSubtype(&MEDIASUBTYPE_UYVY); |
450 |
break; |
break; |
451 |
#endif |
} |
452 |
case 5 : |
case 5 : |
453 |
#ifdef USE_RGB32 |
if ( USE_RGB32 ) |
454 |
|
{ |
455 |
vih->bmiHeader.biCompression = BI_RGB; |
vih->bmiHeader.biCompression = BI_RGB; |
456 |
vih->bmiHeader.biBitCount = 32; |
vih->bmiHeader.biBitCount = 32; |
457 |
mtOut->SetSubtype(&MEDIASUBTYPE_RGB32); |
mtOut->SetSubtype(&MEDIASUBTYPE_RGB32); |
458 |
break; |
break; |
459 |
#endif |
} |
460 |
case 6 : |
case 6 : |
461 |
#ifdef USE_RGB24 |
if ( USE_RGB24 ) |
462 |
|
{ |
463 |
vih->bmiHeader.biCompression = BI_RGB; |
vih->bmiHeader.biCompression = BI_RGB; |
464 |
vih->bmiHeader.biBitCount = 24; |
vih->bmiHeader.biBitCount = 24; |
465 |
mtOut->SetSubtype(&MEDIASUBTYPE_RGB24); |
mtOut->SetSubtype(&MEDIASUBTYPE_RGB24); |
466 |
break; |
break; |
467 |
#endif |
} |
468 |
case 7 : |
case 7 : |
469 |
#ifdef USE_RG555 |
if ( USE_RG555 ) |
470 |
|
{ |
471 |
vih->bmiHeader.biCompression = BI_RGB; |
vih->bmiHeader.biCompression = BI_RGB; |
472 |
vih->bmiHeader.biBitCount = 16; |
vih->bmiHeader.biBitCount = 16; |
473 |
mtOut->SetSubtype(&MEDIASUBTYPE_RGB555); |
mtOut->SetSubtype(&MEDIASUBTYPE_RGB555); |
474 |
break; |
break; |
475 |
#endif |
} |
476 |
case 8 : |
case 8 : |
477 |
#ifdef USE_RG565 |
if ( USE_RG565 ) |
478 |
|
{ |
479 |
vih->bmiHeader.biCompression = BI_RGB; |
vih->bmiHeader.biCompression = BI_RGB; |
480 |
vih->bmiHeader.biBitCount = 16; |
vih->bmiHeader.biBitCount = 16; |
481 |
mtOut->SetSubtype(&MEDIASUBTYPE_RGB565); |
mtOut->SetSubtype(&MEDIASUBTYPE_RGB565); |
482 |
break; |
break; |
483 |
#endif |
} |
484 |
default : |
default : |
485 |
return VFW_S_NO_MORE_ITEMS; |
return VFW_S_NO_MORE_ITEMS; |
486 |
} |
} |
500 |
|
|
501 |
HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format) |
HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format) |
502 |
{ |
{ |
|
int rgb_flip; |
|
|
|
|
503 |
if (formattype == FORMAT_VideoInfo) |
if (formattype == FORMAT_VideoInfo) |
504 |
{ |
{ |
505 |
VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format; |
VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format; |
517 |
return S_FALSE; |
return S_FALSE; |
518 |
} |
} |
519 |
|
|
520 |
if (subtype == MEDIASUBTYPE_IYUV) |
if (subtype == CLSID_MEDIASUBTYPE_IYUV) |
521 |
{ |
{ |
522 |
DPRINTF("IYUV"); |
DPRINTF("IYUV"); |
523 |
m_frame.output.csp = XVID_CSP_I420; |
m_frame.output.csp = XVID_CSP_I420; |
648 |
|
|
649 |
if (m_create.handle == NULL) |
if (m_create.handle == NULL) |
650 |
{ |
{ |
651 |
if (m_xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0) |
if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0) |
652 |
{ |
{ |
653 |
DPRINTF("*** XVID_DEC_CREATE error"); |
DPRINTF("*** XVID_DEC_CREATE error"); |
654 |
return S_FALSE; |
return S_FALSE; |
683 |
} |
} |
684 |
|
|
685 |
m_frame.general = XVID_LOWDELAY; |
m_frame.general = XVID_LOWDELAY; |
686 |
|
|
687 |
if (pIn->IsDiscontinuity() == S_OK) |
if (pIn->IsDiscontinuity() == S_OK) |
688 |
m_frame.general = XVID_DISCONTINUITY; |
m_frame.general = XVID_DISCONTINUITY; |
689 |
|
|
690 |
|
if (PPSettings.bDeblock_Y) |
691 |
|
m_frame.general |= XVID_DEBLOCKY; |
692 |
|
|
693 |
|
if (PPSettings.bDeblock_UV) |
694 |
|
m_frame.general |= XVID_DEBLOCKUV; |
695 |
|
/* |
696 |
|
if (PPSettings.bDering) |
697 |
|
m_frame.general |= XVID_DERING; |
698 |
|
*/ |
699 |
|
if (PPSettings.bFilmEffect) |
700 |
|
m_frame.general |= XVID_FILMEFFECT; |
701 |
|
|
702 |
|
if (PPSettings.bFlipVideo) { |
703 |
|
if (rgb_flip) |
704 |
|
m_frame.output.csp &= ~XVID_CSP_VFLIP; |
705 |
|
else |
706 |
|
m_frame.output.csp |= XVID_CSP_VFLIP; |
707 |
|
} |
708 |
|
else { |
709 |
|
if (rgb_flip) |
710 |
|
m_frame.output.csp |= XVID_CSP_VFLIP; |
711 |
|
else |
712 |
|
m_frame.output.csp &= ~XVID_CSP_VFLIP; |
713 |
|
} |
714 |
|
|
715 |
repeat : |
repeat : |
716 |
|
|
717 |
if (pIn->IsPreroll() != S_OK) |
if (pIn->IsPreroll() != S_OK) |
718 |
{ |
{ |
719 |
length = m_xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); |
length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); |
720 |
|
|
721 |
if (length < 0) |
if (length < 0) |
722 |
{ |
{ |
723 |
DPRINTF("*** XVID_DEC_DECODE"); |
DPRINTF("*** XVID_DEC_DECODE"); |
725 |
} |
} |
726 |
} |
} |
727 |
else |
else |
728 |
{ |
{ /* Preroll frame - won't be displayed */ |
729 |
int tmp = m_frame.output.csp; |
int tmp = m_frame.output.csp; |
730 |
|
int tmp_gen = m_frame.general; |
731 |
|
|
732 |
m_frame.output.csp = XVID_CSP_NULL; |
m_frame.output.csp = XVID_CSP_NULL; |
733 |
|
|
734 |
length = m_xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); |
/* Disable postprocessing to speed-up seeking */ |
735 |
|
m_frame.general &= ~XVID_DEBLOCKY; |
736 |
|
m_frame.general &= ~XVID_DEBLOCKUV; |
737 |
|
/* m_frame.general &= ~XVID_DERING; */ |
738 |
|
m_frame.general &= ~XVID_FILMEFFECT; |
739 |
|
|
740 |
|
length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); |
741 |
if (length < 0) |
if (length < 0) |
742 |
{ |
{ |
743 |
DPRINTF("*** XVID_DEC_DECODE"); |
DPRINTF("*** XVID_DEC_DECODE"); |
745 |
} |
} |
746 |
|
|
747 |
m_frame.output.csp = tmp; |
m_frame.output.csp = tmp; |
748 |
|
m_frame.general = tmp_gen; |
749 |
|
} |
750 |
|
|
751 |
|
if (stats.type == XVID_TYPE_NOTHING) { |
752 |
|
DPRINTF("B-Frame decoder lag"); |
753 |
|
return S_FALSE; |
754 |
} |
} |
755 |
|
|
756 |
|
|
757 |
if (stats.type == XVID_TYPE_VOL) |
if (stats.type == XVID_TYPE_VOL) |
758 |
{ |
{ |
759 |
if (stats.data.vol.width != m_create.width || |
if (stats.data.vol.width != m_create.width || |
763 |
return S_FALSE; |
return S_FALSE; |
764 |
} |
} |
765 |
|
|
766 |
|
pOut->SetDiscontinuity(TRUE); |
767 |
|
pOut->SetSyncPoint(TRUE); |
768 |
|
|
769 |
m_frame.bitstream = (BYTE*)m_frame.bitstream + length; |
m_frame.bitstream = (BYTE*)m_frame.bitstream + length; |
770 |
m_frame.length -= length; |
m_frame.length -= length; |
771 |
goto repeat; |
goto repeat; |
772 |
} |
} |
773 |
|
|
774 |
|
if (pIn->IsPreroll() == S_OK) { |
775 |
|
return S_FALSE; |
776 |
|
} |
777 |
|
|
778 |
return S_OK; |
return S_OK; |
779 |
} |
} |
780 |
|
|