[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 1260, Fri Dec 12 15:09:01 2003 UTC revision 1353, Sat Feb 7 03:57:39 2004 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - XviD Decoder part of the DShow Filter  -   *  - XviD Decoder part of the DShow Filter  -
5   *   *
6   *  Copyright(C) 2002-2003 Peter Ross <pross@xvid.org>   *  Copyright(C) 2002-2004 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 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.5 2003-12-12 15:09:01 Isibaar Exp $   * $Id: CXvidDecoder.cpp,v 1.1.2.18 2004-02-07 03:57:39 syskin Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# Line 60  Line 60 
60  #include "IXvidDecoder.h"  #include "IXvidDecoder.h"
61  #include "CXvidDecoder.h"  #include "CXvidDecoder.h"
62  #include "CAbout.h"  #include "CAbout.h"
63    #include "config.h"
64    #include "debug.h"
65    
66  // Externs defined here  static bool USE_IYUV;
67  PostProcessing_Settings PPSettings;  static bool USE_YV12;
68    static bool USE_YUY2;
69  int rgb_flip;  static bool USE_YVYU;
70    static bool USE_UYVY;
71  bool USE_IYUV;  static bool USE_RGB32;
72  bool USE_YV12;  static bool USE_RGB24;
73  bool USE_YUY2;  static bool USE_RG555;
74  bool USE_YVYU;  static bool USE_RG565;
 bool USE_UYVY;  
 bool USE_RGB32;  
 bool USE_RGB24;  
 bool USE_RG555;  
 bool USE_RG565;  
75    
76  const AMOVIESETUP_MEDIATYPE sudInputPinTypes[] =  const AMOVIESETUP_MEDIATYPE sudInputPinTypes[] =
77  {  {
# Line 84  Line 81 
81          { &MEDIATYPE_Video, &CLSID_DIVX_UC },          { &MEDIATYPE_Video, &CLSID_DIVX_UC },
82          { &MEDIATYPE_Video, &CLSID_DX50 },          { &MEDIATYPE_Video, &CLSID_DX50 },
83          { &MEDIATYPE_Video, &CLSID_DX50_UC },          { &MEDIATYPE_Video, &CLSID_DX50_UC },
84            { &MEDIATYPE_Video, &CLSID_MP4V },
85  };  };
86    
87  const AMOVIESETUP_MEDIATYPE sudOutputPinTypes[] =  const AMOVIESETUP_MEDIATYPE sudOutputPinTypes[] =
# Line 150  Line 148 
148    
149  };  };
150    
151    
152    /* note: g_cTemplates must be global; used by strmbase.lib(dllentry.cpp,dllsetup.cpp) */
153  int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate);  int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate);
154    
155    
# Line 201  Line 201 
201    
202  /* constructor */  /* constructor */
203    
204    #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)
208  {  {
# Line 209  Line 211 
211          xvid_gbl_init_t init;          xvid_gbl_init_t init;
212          memset(&init, 0, sizeof(init));          memset(&init, 0, sizeof(init));
213          init.version = XVID_VERSION;          init.version = XVID_VERSION;
214          if (xvid_global(0, XVID_GBL_INIT, &init, NULL) < 0)  
215            ar_x = ar_y = 0;
216    
217            m_hdll = LoadLibrary(XVID_DLL_NAME);
218            if (m_hdll == NULL) {
219                    DPRINTF("dll load failed");
220                    MessageBox(0, XVID_DLL_NAME " not found","Error", 0);
221                    return;
222            }
223    
224            xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global");
225            if (xvid_global_func == NULL) {
226                    MessageBox(0, "xvid_global() not found", "Error", 0);
227                    return;
228            }
229    
230            xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore");
231            if (xvid_decore_func == NULL) {
232                    MessageBox(0, "xvid_decore() not found", "Error", 0);
233                    return;
234            }
235    
236            if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0)
237          {          {
238                  MessageBox(0, "xvid_global() failed", "Error", 0);                  MessageBox(0, "xvid_global() failed", "Error", 0);
239                  return;                  return;
# Line 222  Line 246 
246          memset(&m_frame, 0, sizeof(m_frame));          memset(&m_frame, 0, sizeof(m_frame));
247          m_frame.version = XVID_VERSION;          m_frame.version = XVID_VERSION;
248    
249          HKEY hKey;          LoadRegistryInfo();
         DWORD size;  
         RegOpenKeyEx(XVID_REG_KEY, XVID_REG_SUBKEY, 0, KEY_READ, &hKey);  
   
         // Set the default post-processing settings  
         REG_GET_N("Brightness", PPSettings.nBrightness, 25)  
         REG_GET_N("Deblock_Y",  PPSettings.bDeblock_Y, 0)  
         REG_GET_N("Deblock_UV", PPSettings.bDeblock_UV, 0)  
         REG_GET_N("ForceColorspace", PPSettings.nForceColorspace, 0)  
   
         RegCloseKey(hKey);  
250    
251          USE_IYUV = false;          USE_IYUV = false;
252          USE_YV12 = false;          USE_YV12 = false;
# Line 244  Line 258 
258          USE_RG555 = false;          USE_RG555 = false;
259          USE_RG565 = false;          USE_RG565 = false;
260    
261          switch ( PPSettings.nForceColorspace )          switch ( g_config.nForceColorspace )
262          {          {
263          case FORCE_NONE:          case FORCE_NONE:
264                  USE_IYUV = true;                  USE_IYUV = true;
# Line 283  Line 297 
297    
298          if (m_create.handle != NULL)          if (m_create.handle != NULL)
299          {          {
300                  xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0);                  xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0);
301                  m_create.handle = NULL;                  m_create.handle = NULL;
302          }          }
303    
304            if (m_hdll != NULL)
305            {
306                    FreeLibrary(m_hdll);
307                    m_hdll = NULL;
308            }
309  }  }
310    
311    
# Line 307  Line 327 
327          {          {
328                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format();                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format();
329                  hdr = &vih->bmiHeader;                  hdr = &vih->bmiHeader;
330                    /* PAR (x:y) is (1/ppm_X):(1/ppm_Y) where ppm is pixels-per-meter
331                       which is equal to ppm_Y:ppm_X */
332                    ar_x = vih->bmiHeader.biYPelsPerMeter * abs(hdr->biWidth);
333                    ar_y = vih->bmiHeader.biXPelsPerMeter * abs(hdr->biHeight);
334          }          }
335          else if (*mtIn->FormatType() == FORMAT_VideoInfo2)          else if (*mtIn->FormatType() == FORMAT_VideoInfo2)
336          {          {
337                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format();                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format();
338                  hdr = &vih2->bmiHeader;                  hdr = &vih2->bmiHeader;
339                    ar_x = vih2->dwPictAspectRatioX;
340                    ar_y = vih2->dwPictAspectRatioY;
341          }          }
342          else          else
343          {          {
# Line 329  Line 355 
355    
356          switch(hdr->biCompression)          switch(hdr->biCompression)
357          {          {
358    
359            case FOURCC_MP4V:
360                    if (!(g_config.supported_4cc & SUPPORT_MP4V)) return VFW_E_TYPE_NOT_ACCEPTED;
361                    break;
362            case FOURCC_DIVX :
363                    if (!(g_config.supported_4cc & SUPPORT_DIVX)) return VFW_E_TYPE_NOT_ACCEPTED;
364                    break;
365            case FOURCC_DX50 :
366                    if (!(g_config.supported_4cc & SUPPORT_DX50)) return VFW_E_TYPE_NOT_ACCEPTED;
367          case FOURCC_XVID :          case FOURCC_XVID :
 //      case FOURCC_DIVX :  
 //      case FOURCC_DX50 :  
368                  break;                  break;
369    
370    
371          default :          default :
372                  DPRINTF("Unknown fourcc: 0x%08x (%c%c%c%c)",                  DPRINTF("Unknown fourcc: 0x%08x (%c%c%c%c)",
373                          hdr->biCompression,                          hdr->biCompression,
# Line 343  Line 377 
377                          (hdr->biCompression>>24)&0xff);                          (hdr->biCompression>>24)&0xff);
378                  return VFW_E_TYPE_NOT_ACCEPTED;                  return VFW_E_TYPE_NOT_ACCEPTED;
379          }          }
   
380          return S_OK;          return S_OK;
381  }  }
382    
# Line 360  Line 393 
393                  return E_UNEXPECTED;                  return E_UNEXPECTED;
394          }          }
395    
396          VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER));          VIDEOINFOHEADER2 * vih = (VIDEOINFOHEADER2 *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER2));
397          if (vih == NULL)          if (vih == NULL)
398          {          {
399                  return E_OUTOFMEMORY;                  return E_OUTOFMEMORY;
400          }          }
401    
402          ZeroMemory(vih, sizeof (VIDEOINFOHEADER));          ZeroMemory(vih, sizeof (VIDEOINFOHEADER2));
403          vih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);          vih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
404          vih->bmiHeader.biWidth  = m_create.width;          vih->bmiHeader.biWidth  = m_create.width;
405          vih->bmiHeader.biHeight = m_create.height;          vih->bmiHeader.biHeight = m_create.height;
# Line 379  Line 412 
412    
413          switch(iPosition)          switch(iPosition)
414          {          {
415    
416          case 0  :          case 0  :
 if ( USE_IYUV )  
 {  
                 vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1;  
                 vih->bmiHeader.biBitCount = 12;  
                 mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV);  
                 break;  
 }  
         case 1  :  
 if ( USE_YV12 )  
 {  
                 vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;  
                 vih->bmiHeader.biBitCount = 12;  
                 mtOut->SetSubtype(&MEDIASUBTYPE_YV12);  
                 break;  
 }  
         case 2:  
417  if ( USE_YUY2 )  if ( USE_YUY2 )
418  {  {
419                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;
# Line 403  Line 421 
421                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);
422                  break;                  break;
423  }  }
424          case 3 :          case 1 :
425  if ( USE_YVYU )  if ( USE_YVYU )
426  {  {
427                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;
# Line 411  Line 429 
429                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);
430                  break;                  break;
431  }  }
432          case 4 :          case 2 :
433  if ( USE_UYVY )  if ( USE_UYVY )
434  {  {
435                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;
# Line 419  Line 437 
437                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);
438                  break;                  break;
439  }  }
440            case 3  :
441                    if ( USE_IYUV )
442    {
443                    vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1;
444                    vih->bmiHeader.biBitCount = 12;
445                    mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV);
446                    break;
447    }
448            case 4  :
449    if ( USE_YV12 )
450    {
451                    vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;
452                    vih->bmiHeader.biBitCount = 12;
453                    mtOut->SetSubtype(&MEDIASUBTYPE_YV12);
454                    break;
455    }
456          case 5 :          case 5 :
457  if ( USE_RGB32 )  if ( USE_RGB32 )
458  {  {
# Line 457  Line 491 
491    
492          vih->bmiHeader.biSizeImage = GetBitmapSize(&vih->bmiHeader);          vih->bmiHeader.biSizeImage = GetBitmapSize(&vih->bmiHeader);
493    
494            if (ar_x != 0 && ar_y != 0) {
495                    vih->dwPictAspectRatioX = ar_x;
496                    vih->dwPictAspectRatioY = ar_y;
497            } else { // just to be safe
498                    vih->dwPictAspectRatioX = m_create.width;
499                    vih->dwPictAspectRatioY = abs(m_create.height);
500            }
501    
502          mtOut->SetType(&MEDIATYPE_Video);          mtOut->SetType(&MEDIATYPE_Video);
503          mtOut->SetFormatType(&FORMAT_VideoInfo);          mtOut->SetFormatType(&FORMAT_VideoInfo2);
504          mtOut->SetTemporalCompression(FALSE);          mtOut->SetTemporalCompression(FALSE);
505          mtOut->SetSampleSize(vih->bmiHeader.biSizeImage);          mtOut->SetSampleSize(vih->bmiHeader.biSizeImage);
506    
# Line 490  Line 532 
532          if (subtype == CLSID_MEDIASUBTYPE_IYUV)          if (subtype == CLSID_MEDIASUBTYPE_IYUV)
533          {          {
534                  DPRINTF("IYUV");                  DPRINTF("IYUV");
535                    rgb_flip = 0;
536                  m_frame.output.csp = XVID_CSP_I420;                  m_frame.output.csp = XVID_CSP_I420;
537                  m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3;  /* planar format fix */                  m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3;  /* planar format fix */
538          }          }
539          else if (subtype == MEDIASUBTYPE_YV12)          else if (subtype == MEDIASUBTYPE_YV12)
540          {          {
541                  DPRINTF("YV12");                  DPRINTF("YV12");
542                    rgb_flip = 0;
543                  m_frame.output.csp = XVID_CSP_YV12;                  m_frame.output.csp = XVID_CSP_YV12;
544                  m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3;  /* planar format fix */                  m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3;  /* planar format fix */
545          }          }
546          else if (subtype == MEDIASUBTYPE_YUY2)          else if (subtype == MEDIASUBTYPE_YUY2)
547          {          {
548                  DPRINTF("YUY2");                  DPRINTF("YUY2");
549                    rgb_flip = 0;
550                  m_frame.output.csp = XVID_CSP_YUY2;                  m_frame.output.csp = XVID_CSP_YUY2;
551          }          }
552          else if (subtype == MEDIASUBTYPE_YVYU)          else if (subtype == MEDIASUBTYPE_YVYU)
553          {          {
554                  DPRINTF("YVYU");                  DPRINTF("YVYU");
555                    rgb_flip = 0;
556                  m_frame.output.csp = XVID_CSP_YVYU;                  m_frame.output.csp = XVID_CSP_YVYU;
557          }          }
558          else if (subtype == MEDIASUBTYPE_UYVY)          else if (subtype == MEDIASUBTYPE_UYVY)
559          {          {
560                  DPRINTF("UYVY");                  DPRINTF("UYVY");
561                    rgb_flip = 0;
562                  m_frame.output.csp = XVID_CSP_UYVY;                  m_frame.output.csp = XVID_CSP_UYVY;
563          }          }
564          else if (subtype == MEDIASUBTYPE_RGB32)          else if (subtype == MEDIASUBTYPE_RGB32)
# Line 618  Line 665 
665    
666          if (m_create.handle == NULL)          if (m_create.handle == NULL)
667          {          {
668                  if (xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0)                  if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0)
669                  {                  {
670              DPRINTF("*** XVID_DEC_CREATE error");              DPRINTF("*** XVID_DEC_CREATE error");
671                          return S_FALSE;                          return S_FALSE;
# Line 657  Line 704 
704          if (pIn->IsDiscontinuity() == S_OK)          if (pIn->IsDiscontinuity() == S_OK)
705                  m_frame.general = XVID_DISCONTINUITY;                  m_frame.general = XVID_DISCONTINUITY;
706    
707          if (PPSettings.bDeblock_Y)          if (g_config.nDeblock_Y)
708                  m_frame.general |= XVID_DEBLOCKY;                  m_frame.general |= XVID_DEBLOCKY;
709    
710          if (PPSettings.bDeblock_UV)          if (g_config.nDeblock_UV)
711                  m_frame.general |= XVID_DEBLOCKUV;                  m_frame.general |= XVID_DEBLOCKUV;
712    /*
713            if (g_config.nDering)
714                    m_frame.general |= XVID_DERING;
715    */
716            if (g_config.nFilmEffect)
717                    m_frame.general |= XVID_FILMEFFECT;
718    
         if (PPSettings.bFlipVideo) {  
                 if (rgb_flip)  
719                          m_frame.output.csp &= ~XVID_CSP_VFLIP;                          m_frame.output.csp &= ~XVID_CSP_VFLIP;
720                  else          m_frame.output.csp |= rgb_flip^(g_config.nFlipVideo ? XVID_CSP_VFLIP : 0);
                         m_frame.output.csp |= XVID_CSP_VFLIP;  
         }  
         else {  
                 if (rgb_flip)  
                         m_frame.output.csp |= XVID_CSP_VFLIP;  
                 else  
                         m_frame.output.csp &= ~XVID_CSP_VFLIP;  
         }  
721    
722  repeat :  repeat :
723    
724          if (pIn->IsPreroll() != S_OK)          if (pIn->IsPreroll() != S_OK)
725          {          {
726                  length = xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);                  length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);
727    
728                  if (length < 0)                  if (length < 0)
729                  {                  {
# Line 689  Line 732 
732                  }                  }
733          }          }
734          else          else
735          {          {       /* Preroll frame - won't be displayed */
736                  int tmp = m_frame.output.csp;                  int tmp = m_frame.output.csp;
737                    int tmp_gen = m_frame.general;
738    
739                  m_frame.output.csp = XVID_CSP_NULL;                  m_frame.output.csp = XVID_CSP_NULL;
740    
741                  length = xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);                  /* Disable postprocessing to speed-up seeking */
742                    m_frame.general &= ~XVID_DEBLOCKY;
743                    m_frame.general &= ~XVID_DEBLOCKUV;
744    /*              m_frame.general &= ~XVID_DERING; */
745                    m_frame.general &= ~XVID_FILMEFFECT;
746    
747                    length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);
748                  if (length < 0)                  if (length < 0)
749                  {                  {
750              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
# Line 701  Line 752 
752                  }                  }
753    
754                  m_frame.output.csp = tmp;                  m_frame.output.csp = tmp;
755                    m_frame.general = tmp_gen;
756          }          }
757    
758          if (stats.type == XVID_TYPE_NOTHING) {          if (stats.type == XVID_TYPE_NOTHING && length > 0) {
759                  DPRINTF("B-Frame decoder lag");                  DPRINTF("B-Frame decoder lag");
760                  return S_FALSE;                  return S_FALSE;
761          }          }
# Line 718  Line 770 
770                          return S_FALSE;                          return S_FALSE;
771                  }                  }
772    
773                    pOut->SetDiscontinuity(TRUE);
774                    pOut->SetSyncPoint(TRUE);
775    
776                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;
777                  m_frame.length -= length;                  m_frame.length -= length;
778                  goto repeat;                  goto repeat;
779          }          }
780    
781            if (pIn->IsPreroll() == S_OK) {
782                    return S_FALSE;
783            }
784    
785          return S_OK;          return S_OK;
786  }  }
787    

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

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