[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 888, Sat Feb 22 08:22:03 2003 UTC revision 1260, Fri Dec 12 15:09:01 2003 UTC
# Line 1  Line 1 
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
# Line 15  Line 17 
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.5 2003-12-12 15:09:01 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    
34   /*   /*
35          this requires the directx sdk          this requires the directx sdk
# Line 49  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 127  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 175  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 231  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, 0)
232            REG_GET_N("Deblock_UV", PPSettings.bDeblock_UV, 0)
233            REG_GET_N("ForceColorspace", PPSettings.nForceColorspace, 0)
234    
235            RegCloseKey(hKey);
236    
237            USE_IYUV = false;
238            USE_YV12 = false;
239            USE_YUY2 = false;
240            USE_YVYU = false;
241            USE_UYVY = false;
242            USE_RGB32 = false;
243            USE_RGB24 = false;
244            USE_RG555 = false;
245            USE_RG565 = false;
246    
247            switch ( PPSettings.nForceColorspace )
248            {
249            case FORCE_NONE:
250                    USE_IYUV = true;
251                    USE_YV12 = true;
252                    USE_YUY2 = true;
253                    USE_YVYU = true;
254                    USE_UYVY = true;
255                    USE_RGB32 = true;
256                    USE_RGB24 = true;
257                    USE_RG555 = true;
258                    USE_RG565 = true;
259                    break;
260            case FORCE_YV12:
261                    USE_IYUV = true;
262                    USE_YV12 = true;
263                    break;
264            case FORCE_YUY2:
265                    USE_YUY2 = true;
266                    break;
267            case FORCE_RGB24:
268                    USE_RGB24 = true;
269                    break;
270            case FORCE_RGB32:
271                    USE_RGB32 = true;
272                    break;
273            }
274  }  }
275    
276    
# Line 243  Line 283 
283    
284          if (m_create.handle != NULL)          if (m_create.handle != NULL)
285          {          {
286                  m_xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0);                  xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0);
287                  m_create.handle = NULL;                  m_create.handle = NULL;
288          }          }
   
         if (m_hdll != NULL)  
         {  
                 FreeLibrary(m_hdll);  
                 m_hdll = NULL;  
         }  
289  }  }
290    
291    
# Line 314  Line 348 
348  }  }
349    
350    
 #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  
   
351  /* get list of supported output colorspaces */  /* get list of supported output colorspaces */
352    
353    
354  HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut)  HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut)
355  {  {
356          DPRINTF("GetMediaType");          DPRINTF("GetMediaType");
# Line 355  Line 380 
380          switch(iPosition)          switch(iPosition)
381          {          {
382          case 0  :          case 0  :
383  #ifdef USE_IYUV  if ( USE_IYUV )
384                  vih->bmiHeader.biCompression = MEDIASUBTYPE_IYUV.Data1;  {
385                    vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1;
386                  vih->bmiHeader.biBitCount = 12;                  vih->bmiHeader.biBitCount = 12;
387                  mtOut->SetSubtype(&MEDIASUBTYPE_IYUV);                  mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV);
388                  break;                  break;
389  #endif  }
390          case 1  :          case 1  :
391  #ifdef USE_YV12  if ( USE_YV12 )
392    {
393                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;
394                  vih->bmiHeader.biBitCount = 12;                  vih->bmiHeader.biBitCount = 12;
395                  mtOut->SetSubtype(&MEDIASUBTYPE_YV12);                  mtOut->SetSubtype(&MEDIASUBTYPE_YV12);
396                  break;                  break;
397  #endif  }
398          case 2:          case 2:
399  #ifdef USE_YUY2  if ( USE_YUY2 )
400    {
401                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;
402                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
403                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);
404                  break;                  break;
405  #endif  }
406          case 3 :          case 3 :
407  #ifdef USE_YVYU  if ( USE_YVYU )
408    {
409                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;
410                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
411                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);
412                  break;                  break;
413  #endif  }
414          case 4 :          case 4 :
415  #ifdef USE_UYVY  if ( USE_UYVY )
416    {
417                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;
418                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
419                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);
420                  break;                  break;
421  #endif  }
422          case 5 :          case 5 :
423  #ifdef USE_RGB32  if ( USE_RGB32 )
424    {
425                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
426                  vih->bmiHeader.biBitCount = 32;                  vih->bmiHeader.biBitCount = 32;
427                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);
428                  break;                  break;
429  #endif  }
430          case 6 :          case 6 :
431  #ifdef USE_RGB24  if ( USE_RGB24 )
432    {
433                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
434                  vih->bmiHeader.biBitCount = 24;                  vih->bmiHeader.biBitCount = 24;
435                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);
436                  break;                  break;
437  #endif  }
438          case 7 :          case 7 :
439  #ifdef USE_RG555  if ( USE_RG555 )
440    {
441                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
442                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
443                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);
444                  break;                  break;
445  #endif  }
446          case 8 :          case 8 :
447  #ifdef USE_RG565  if ( USE_RG565 )
448    {
449                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
450                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
451                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);
452                  break;                  break;
453  #endif  }
454          default :          default :
455                  return VFW_S_NO_MORE_ITEMS;                  return VFW_S_NO_MORE_ITEMS;
456          }          }
# Line 436  Line 470 
470    
471  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)
472  {  {
         int rgb_flip;  
   
473          if (formattype == FORMAT_VideoInfo)          if (formattype == FORMAT_VideoInfo)
474          {          {
475                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;
# Line 455  Line 487 
487                  return S_FALSE;                  return S_FALSE;
488          }          }
489    
490          if (subtype == MEDIASUBTYPE_IYUV)          if (subtype == CLSID_MEDIASUBTYPE_IYUV)
491          {          {
492                  DPRINTF("IYUV");                  DPRINTF("IYUV");
493                  m_frame.output.csp = XVID_CSP_I420;                  m_frame.output.csp = XVID_CSP_I420;
# Line 586  Line 618 
618    
619          if (m_create.handle == NULL)          if (m_create.handle == NULL)
620          {          {
621                  if (m_xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0)                  if (xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0)
622                  {                  {
623              DPRINTF("*** XVID_DEC_CREATE error");              DPRINTF("*** XVID_DEC_CREATE error");
624                          return S_FALSE;                          return S_FALSE;
# Line 621  Line 653 
653          }          }
654    
655          m_frame.general = XVID_LOWDELAY;          m_frame.general = XVID_LOWDELAY;
656    
657          if (pIn->IsDiscontinuity() == S_OK)          if (pIn->IsDiscontinuity() == S_OK)
658                  m_frame.general = XVID_DISCONTINUITY;                  m_frame.general = XVID_DISCONTINUITY;
659    
660            if (PPSettings.bDeblock_Y)
661                    m_frame.general |= XVID_DEBLOCKY;
662    
663            if (PPSettings.bDeblock_UV)
664                    m_frame.general |= XVID_DEBLOCKUV;
665    
666            if (PPSettings.bFlipVideo) {
667                    if (rgb_flip)
668                            m_frame.output.csp &= ~XVID_CSP_VFLIP;
669                    else
670                            m_frame.output.csp |= XVID_CSP_VFLIP;
671            }
672            else {
673                    if (rgb_flip)
674                            m_frame.output.csp |= XVID_CSP_VFLIP;
675                    else
676                            m_frame.output.csp &= ~XVID_CSP_VFLIP;
677            }
678    
679  repeat :  repeat :
680    
681          if (pIn->IsPreroll() != S_OK)          if (pIn->IsPreroll() != S_OK)
682          {          {
683                  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);
684    
685                  if (length < 0)                  if (length < 0)
686                  {                  {
687              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
# Line 640  Line 693 
693                  int tmp = m_frame.output.csp;                  int tmp = m_frame.output.csp;
694                  m_frame.output.csp = XVID_CSP_NULL;                  m_frame.output.csp = XVID_CSP_NULL;
695    
696                  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);
697                  if (length < 0)                  if (length < 0)
698                  {                  {
699              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
# Line 650  Line 703 
703                  m_frame.output.csp = tmp;                  m_frame.output.csp = tmp;
704          }          }
705    
706            if (stats.type == XVID_TYPE_NOTHING) {
707                    DPRINTF("B-Frame decoder lag");
708                    return S_FALSE;
709            }
710    
711    
712          if (stats.type == XVID_TYPE_VOL)          if (stats.type == XVID_TYPE_VOL)
713          {          {
714                  if (stats.data.vol.width != m_create.width ||                  if (stats.data.vol.width != m_create.width ||

Legend:
Removed from v.888  
changed lines
  Added in v.1260

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