[svn] / branches / dev-api-4 / xvidcore / dshow / src / CXvidDecoder.cpp Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/dshow/src/CXvidDecoder.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1054, Mon Jun 9 13:55:56 2003 UTC revision 1300, Sat Dec 27 14:33:13 2003 UTC
# Line 19  Line 19 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   * $Id: CXvidDecoder.cpp,v 1.1.2.2 2003-06-09 13:49:00 edgomez Exp $   * $Id: CXvidDecoder.cpp,v 1.1.2.7 2003-12-27 14:33:13 Isibaar 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    
# Line 53  Line 61 
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  {  {
# Line 131  Line 153 
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 );
# Line 179  Line 199 
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    
 #define XVID_DLL_NAME           "xvid.dll"  
 #define XVID_GLOBAL_NAME        "xvid_global"  
 #define XVID_DECORE_NAME        "xvid_decore"  
   
204  CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) :  CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) :
205      CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID)      CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID)
206  {  {
207          DPRINTF("Constructor");          DPRINTF("Constructor");
208    
         m_xvid_decore = dummy_xvid_decore;  
   
         m_hdll = LoadLibrary(XVID_DLL_NAME);  
         if (m_hdll == NULL) {  
                 DPRINTF("dll load failed");  
                 MessageBox(0, XVID_DLL_NAME " not found","Error", 0);  
                 return;  
         }  
   
         m_xvid_global = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, XVID_GLOBAL_NAME);  
         if (m_xvid_global == NULL) {  
                 MessageBox(0, XVID_GLOBAL_NAME "() not found", "Error", 0);  
                 return;  
         }  
   
         m_xvid_decore = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, XVID_DECORE_NAME);  
         if (m_xvid_decore == NULL) {  
                 MessageBox(0, XVID_DECORE_NAME "() not found", "Error", 0);  
                 return;  
         }  
   
209          xvid_gbl_init_t init;          xvid_gbl_init_t init;
210          memset(&init, 0, sizeof(init));          memset(&init, 0, sizeof(init));
211          init.version = XVID_VERSION;          init.version = XVID_VERSION;
212          if (m_xvid_global(0, XVID_GBL_INIT, &init, NULL) < 0)          if (xvid_global(0, XVID_GBL_INIT, &init, NULL) < 0)
213          {          {
214                  MessageBox(0, XVID_GLOBAL_NAME "() failed", "Error", 0);                  MessageBox(0, "xvid_global() failed", "Error", 0);
215                  return;                  return;
216          }          }
217    
# Line 235  Line 221 
221    
222          memset(&m_frame, 0, sizeof(m_frame));          memset(&m_frame, 0, sizeof(m_frame));
223          m_frame.version = XVID_VERSION;          m_frame.version = XVID_VERSION;
224    
225            HKEY hKey;
226            DWORD size;
227            RegOpenKeyEx(XVID_REG_KEY, XVID_REG_SUBKEY, 0, KEY_READ, &hKey);
228    
229            // Set the default post-processing settings
230            REG_GET_N("Brightness", PPSettings.nBrightness, 25)
231            REG_GET_N("Deblock_Y",  PPSettings.bDeblock_Y, 1)
232            REG_GET_N("Deblock_UV", PPSettings.bDeblock_UV, 1)
233            REG_GET_N("Dering",  PPSettings.bDering, 1)
234            REG_GET_N("FilmEffect", PPSettings.bFilmEffect, 1)
235            REG_GET_N("ForceColorspace", PPSettings.nForceColorspace, 0)
236    
237            RegCloseKey(hKey);
238    
239            USE_IYUV = false;
240            USE_YV12 = false;
241            USE_YUY2 = false;
242            USE_YVYU = false;
243            USE_UYVY = false;
244            USE_RGB32 = false;
245            USE_RGB24 = false;
246            USE_RG555 = false;
247            USE_RG565 = false;
248    
249            switch ( PPSettings.nForceColorspace )
250            {
251            case FORCE_NONE:
252                    USE_IYUV = true;
253                    USE_YV12 = true;
254                    USE_YUY2 = true;
255                    USE_YVYU = true;
256                    USE_UYVY = true;
257                    USE_RGB32 = true;
258                    USE_RGB24 = true;
259                    USE_RG555 = true;
260                    USE_RG565 = true;
261                    break;
262            case FORCE_YV12:
263                    USE_IYUV = true;
264                    USE_YV12 = true;
265                    break;
266            case FORCE_YUY2:
267                    USE_YUY2 = true;
268                    break;
269            case FORCE_RGB24:
270                    USE_RGB24 = true;
271                    break;
272            case FORCE_RGB32:
273                    USE_RGB32 = true;
274                    break;
275            }
276  }  }
277    
278    
# Line 247  Line 285 
285    
286          if (m_create.handle != NULL)          if (m_create.handle != NULL)
287          {          {
288                  m_xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0);                  xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0);
289                  m_create.handle = NULL;                  m_create.handle = NULL;
290          }          }
   
         if (m_hdll != NULL)  
         {  
                 FreeLibrary(m_hdll);  
                 m_hdll = NULL;  
         }  
291  }  }
292    
293    
# Line 318  Line 350 
350  }  }
351    
352    
 #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  
   
353  /* get list of supported output colorspaces */  /* get list of supported output colorspaces */
354    
355    
356  HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut)  HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut)
357  {  {
358          DPRINTF("GetMediaType");          DPRINTF("GetMediaType");
# Line 359  Line 382 
382          switch(iPosition)          switch(iPosition)
383          {          {
384          case 0  :          case 0  :
385  #ifdef USE_IYUV  if ( USE_IYUV )
386                  vih->bmiHeader.biCompression = MEDIASUBTYPE_IYUV.Data1;  {
387                    vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1;
388                  vih->bmiHeader.biBitCount = 12;                  vih->bmiHeader.biBitCount = 12;
389                  mtOut->SetSubtype(&MEDIASUBTYPE_IYUV);                  mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV);
390                  break;                  break;
391  #endif  }
392          case 1  :          case 1  :
393  #ifdef USE_YV12  if ( USE_YV12 )
394    {
395                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;
396                  vih->bmiHeader.biBitCount = 12;                  vih->bmiHeader.biBitCount = 12;
397                  mtOut->SetSubtype(&MEDIASUBTYPE_YV12);                  mtOut->SetSubtype(&MEDIASUBTYPE_YV12);
398                  break;                  break;
399  #endif  }
400          case 2:          case 2:
401  #ifdef USE_YUY2  if ( USE_YUY2 )
402    {
403                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;
404                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
405                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);
406                  break;                  break;
407  #endif  }
408          case 3 :          case 3 :
409  #ifdef USE_YVYU  if ( USE_YVYU )
410    {
411                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;
412                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
413                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);
414                  break;                  break;
415  #endif  }
416          case 4 :          case 4 :
417  #ifdef USE_UYVY  if ( USE_UYVY )
418    {
419                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;
420                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
421                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);
422                  break;                  break;
423  #endif  }
424          case 5 :          case 5 :
425  #ifdef USE_RGB32  if ( USE_RGB32 )
426    {
427                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
428                  vih->bmiHeader.biBitCount = 32;                  vih->bmiHeader.biBitCount = 32;
429                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);
430                  break;                  break;
431  #endif  }
432          case 6 :          case 6 :
433  #ifdef USE_RGB24  if ( USE_RGB24 )
434    {
435                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
436                  vih->bmiHeader.biBitCount = 24;                  vih->bmiHeader.biBitCount = 24;
437                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);
438                  break;                  break;
439  #endif  }
440          case 7 :          case 7 :
441  #ifdef USE_RG555  if ( USE_RG555 )
442    {
443                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
444                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
445                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);
446                  break;                  break;
447  #endif  }
448          case 8 :          case 8 :
449  #ifdef USE_RG565  if ( USE_RG565 )
450    {
451                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
452                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
453                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);
454                  break;                  break;
455  #endif  }
456          default :          default :
457                  return VFW_S_NO_MORE_ITEMS;                  return VFW_S_NO_MORE_ITEMS;
458          }          }
# Line 440  Line 472 
472    
473  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)
474  {  {
         int rgb_flip;  
   
475          if (formattype == FORMAT_VideoInfo)          if (formattype == FORMAT_VideoInfo)
476          {          {
477                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;
# Line 459  Line 489 
489                  return S_FALSE;                  return S_FALSE;
490          }          }
491    
492          if (subtype == MEDIASUBTYPE_IYUV)          if (subtype == CLSID_MEDIASUBTYPE_IYUV)
493          {          {
494                  DPRINTF("IYUV");                  DPRINTF("IYUV");
495                  m_frame.output.csp = XVID_CSP_I420;                  m_frame.output.csp = XVID_CSP_I420;
# Line 590  Line 620 
620    
621          if (m_create.handle == NULL)          if (m_create.handle == NULL)
622          {          {
623                  if (m_xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0)                  if (xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0)
624                  {                  {
625              DPRINTF("*** XVID_DEC_CREATE error");              DPRINTF("*** XVID_DEC_CREATE error");
626                          return S_FALSE;                          return S_FALSE;
# Line 625  Line 655 
655          }          }
656    
657          m_frame.general = XVID_LOWDELAY;          m_frame.general = XVID_LOWDELAY;
658    
659          if (pIn->IsDiscontinuity() == S_OK)          if (pIn->IsDiscontinuity() == S_OK)
660                  m_frame.general = XVID_DISCONTINUITY;                  m_frame.general = XVID_DISCONTINUITY;
661    
662            if (PPSettings.bDeblock_Y)
663                    m_frame.general |= XVID_DEBLOCKY;
664    
665            if (PPSettings.bDeblock_UV)
666                    m_frame.general |= XVID_DEBLOCKUV;
667    /*
668            if (PPSettings.bDering)
669                    m_frame.general |= XVID_DERING;
670    */
671            if (PPSettings.bFilmEffect)
672                    m_frame.general |= XVID_FILMEFFECT;
673    
674            if (PPSettings.bFlipVideo) {
675                    if (rgb_flip)
676                            m_frame.output.csp &= ~XVID_CSP_VFLIP;
677                    else
678                            m_frame.output.csp |= XVID_CSP_VFLIP;
679            }
680            else {
681                    if (rgb_flip)
682                            m_frame.output.csp |= XVID_CSP_VFLIP;
683                    else
684                            m_frame.output.csp &= ~XVID_CSP_VFLIP;
685            }
686    
687  repeat :  repeat :
688    
689          if (pIn->IsPreroll() != S_OK)          if (pIn->IsPreroll() != S_OK)
690          {          {
691                  length = m_xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);                  length = xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);
692    
693                  if (length < 0)                  if (length < 0)
694                  {                  {
695              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
# Line 640  Line 697 
697                  }                  }
698          }          }
699          else          else
700          {          {       /* Preroll frame - won't be displayed */
701                  int tmp = m_frame.output.csp;                  int tmp = m_frame.output.csp;
702                    int tmp_gen = m_frame.general;
703    
704                  m_frame.output.csp = XVID_CSP_NULL;                  m_frame.output.csp = XVID_CSP_NULL;
705    
706                  length = m_xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);                  /* Disable postprocessing to speed-up seeking */
707                    m_frame.general &= ~XVID_DEBLOCKY;
708                    m_frame.general &= ~XVID_DEBLOCKUV;
709    /*              m_frame.general &= ~XVID_DERING; */
710                    m_frame.general &= ~XVID_FILMEFFECT;
711    
712                    length = xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);
713                  if (length < 0)                  if (length < 0)
714                  {                  {
715              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
# Line 652  Line 717 
717                  }                  }
718    
719                  m_frame.output.csp = tmp;                  m_frame.output.csp = tmp;
720                    m_frame.general = tmp_gen;
721            }
722    
723            if (stats.type == XVID_TYPE_NOTHING) {
724                    DPRINTF("B-Frame decoder lag");
725                    return S_FALSE;
726          }          }
727    
728    
729          if (stats.type == XVID_TYPE_VOL)          if (stats.type == XVID_TYPE_VOL)
730          {          {
731                  if (stats.data.vol.width != m_create.width ||                  if (stats.data.vol.width != m_create.width ||
# Line 663  Line 735 
735                          return S_FALSE;                          return S_FALSE;
736                  }                  }
737    
738                    pOut->SetDiscontinuity(TRUE);
739                    pOut->SetSyncPoint(TRUE);
740    
741                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;
742                  m_frame.length -= length;                  m_frame.length -= length;
743                  goto repeat;                  goto repeat;
744          }          }
745    
746            if (pIn->IsPreroll() == S_OK) {
747                    return S_FALSE;
748            }
749    
750          return S_OK;          return S_OK;
751  }  }
752    

Legend:
Removed from v.1054  
changed lines
  Added in v.1300

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4