[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 1314, Wed Jan 21 04:26:21 2004 UTC revision 1367, Sat Feb 28 07:24:34 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.11 2004-01-21 04:26:21 syskin Exp $   * $Id: CXvidDecoder.cpp,v 1.1.2.19 2004-02-28 07:24:34 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 246  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("Dering",  PPSettings.bDering, 0)  
         REG_GET_N("FilmEffect", PPSettings.bFilmEffect, 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 270  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 341  Line 329 
329                  hdr = &vih->bmiHeader;                  hdr = &vih->bmiHeader;
330                  /* PAR (x:y) is (1/ppm_X):(1/ppm_Y) where ppm is pixels-per-meter                  /* 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 */                     which is equal to ppm_Y:ppm_X */
332                  ar_x = vih->bmiHeader.biYPelsPerMeter*hdr->biWidth;                  ar_x = vih->bmiHeader.biYPelsPerMeter * abs(hdr->biWidth);
333                  ar_y = vih->bmiHeader.biXPelsPerMeter*hdr->biHeight;                  ar_y = vih->bmiHeader.biXPelsPerMeter * abs(hdr->biHeight);
334                    DPRINTF("VIDEOINFOHEADER PAR: %d:%d -> AR %d:%d",
335                            vih->bmiHeader.biYPelsPerMeter,vih->bmiHeader.biXPelsPerMeter, ar_x, ar_y);
336          }          }
337          else if (*mtIn->FormatType() == FORMAT_VideoInfo2)          else if (*mtIn->FormatType() == FORMAT_VideoInfo2)
338          {          {
# Line 350  Line 340 
340                  hdr = &vih2->bmiHeader;                  hdr = &vih2->bmiHeader;
341                  ar_x = vih2->dwPictAspectRatioX;                  ar_x = vih2->dwPictAspectRatioX;
342                  ar_y = vih2->dwPictAspectRatioY;                  ar_y = vih2->dwPictAspectRatioY;
343                    DPRINTF("VIDEOINFOHEADER2 AR: %d:%d", ar_x, ar_y);
344          }          }
345          else          else
346          {          {
# Line 367  Line 358 
358    
359          switch(hdr->biCompression)          switch(hdr->biCompression)
360          {          {
361    
362            case FOURCC_MP4V:
363                    if (!(g_config.supported_4cc & SUPPORT_MP4V)) return VFW_E_TYPE_NOT_ACCEPTED;
364                    break;
365            case FOURCC_DIVX :
366                    if (!(g_config.supported_4cc & SUPPORT_DIVX)) return VFW_E_TYPE_NOT_ACCEPTED;
367                    break;
368            case FOURCC_DX50 :
369                    if (!(g_config.supported_4cc & SUPPORT_DX50)) return VFW_E_TYPE_NOT_ACCEPTED;
370          case FOURCC_XVID :          case FOURCC_XVID :
 //      case FOURCC_DIVX :  
 //      case FOURCC_DX50 :  
371                  break;                  break;
372    
373    
374          default :          default :
375                  DPRINTF("Unknown fourcc: 0x%08x (%c%c%c%c)",                  DPRINTF("Unknown fourcc: 0x%08x (%c%c%c%c)",
376                          hdr->biCompression,                          hdr->biCompression,
# Line 381  Line 380 
380                          (hdr->biCompression>>24)&0xff);                          (hdr->biCompression>>24)&0xff);
381                  return VFW_E_TYPE_NOT_ACCEPTED;                  return VFW_E_TYPE_NOT_ACCEPTED;
382          }          }
   
383          return S_OK;          return S_OK;
384  }  }
385    
# Line 391  Line 389 
389    
390  HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut)  HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut)
391  {  {
392            BITMAPINFOHEADER * bmih;
393          DPRINTF("GetMediaType");          DPRINTF("GetMediaType");
394    
395          if (m_pInput->IsConnected() == FALSE)          if (m_pInput->IsConnected() == FALSE)
# Line 398  Line 397 
397                  return E_UNEXPECTED;                  return E_UNEXPECTED;
398          }          }
399    
400            if (!g_config.videoinfo_compat) {
401          VIDEOINFOHEADER2 * vih = (VIDEOINFOHEADER2 *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER2));          VIDEOINFOHEADER2 * vih = (VIDEOINFOHEADER2 *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER2));
402          if (vih == NULL)                  if (vih == NULL) return E_OUTOFMEMORY;
403          {  
404                  return E_OUTOFMEMORY;                  ZeroMemory(vih, sizeof (VIDEOINFOHEADER2));
405                    bmih = &(vih->bmiHeader);
406                    mtOut->SetFormatType(&FORMAT_VideoInfo2);
407    
408                    if (ar_x != 0 && ar_y != 0) {
409                            vih->dwPictAspectRatioX = ar_x;
410                            vih->dwPictAspectRatioY = ar_y;
411                    } else { // just to be safe
412                            vih->dwPictAspectRatioX = m_create.width;
413                            vih->dwPictAspectRatioY = abs(m_create.height);
414          }          }
415    
416          ZeroMemory(vih, sizeof (VIDEOINFOHEADER));          } else {
         vih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);  
         vih->bmiHeader.biWidth  = m_create.width;  
         vih->bmiHeader.biHeight = m_create.height;  
         vih->bmiHeader.biPlanes = 1;  
417    
418          if (iPosition < 0)                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER));
419          {                  if (vih == NULL) return E_OUTOFMEMORY;
420                  return E_INVALIDARG;  
421                    ZeroMemory(vih, sizeof (VIDEOINFOHEADER2));
422                    bmih = &(vih->bmiHeader);
423                    mtOut->SetFormatType(&FORMAT_VideoInfo);
424          }          }
425    
426            bmih->biSize = sizeof(BITMAPINFOHEADER);
427            bmih->biWidth   = m_create.width;
428            bmih->biHeight = m_create.height;
429            bmih->biPlanes = 1;
430    
431            if (iPosition < 0) return E_INVALIDARG;
432    
433          switch(iPosition)          switch(iPosition)
434          {          {
435    
436          case 0:          case 0:
437  if ( USE_YUY2 )  if ( USE_YUY2 )
438  {  {
439                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;                  bmih->biCompression = MEDIASUBTYPE_YUY2.Data1;
440                  vih->bmiHeader.biBitCount = 16;                  bmih->biBitCount = 16;
441                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);
442                  break;                  break;
443  }  }
444          case 1 :          case 1 :
445  if ( USE_YVYU )  if ( USE_YVYU )
446  {  {
447                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;                  bmih->biCompression = MEDIASUBTYPE_YVYU.Data1;
448                  vih->bmiHeader.biBitCount = 16;                  bmih->biBitCount = 16;
449                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);
450                  break;                  break;
451  }  }
452          case 2 :          case 2 :
453  if ( USE_UYVY )  if ( USE_UYVY )
454  {  {
455                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;                  bmih->biCompression = MEDIASUBTYPE_UYVY.Data1;
456                  vih->bmiHeader.biBitCount = 16;                  bmih->biBitCount = 16;
457                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);
458                  break;                  break;
459  }  }
460          case 3  :          case 3  :
461                  if ( USE_IYUV )                  if ( USE_IYUV )
462  {  {
463                  vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1;                  bmih->biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1;
464                  vih->bmiHeader.biBitCount = 12;                  bmih->biBitCount = 12;
465                  mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV);                  mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV);
466                  break;                  break;
467  }  }
468          case 4  :          case 4  :
469  if ( USE_YV12 )  if ( USE_YV12 )
470  {  {
471                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;                  bmih->biCompression = MEDIASUBTYPE_YV12.Data1;
472                  vih->bmiHeader.biBitCount = 12;                  bmih->biBitCount = 12;
473                  mtOut->SetSubtype(&MEDIASUBTYPE_YV12);                  mtOut->SetSubtype(&MEDIASUBTYPE_YV12);
474                  break;                  break;
475  }  }
476          case 5 :          case 5 :
477  if ( USE_RGB32 )  if ( USE_RGB32 )
478  {  {
479                  vih->bmiHeader.biCompression = BI_RGB;                  bmih->biCompression = BI_RGB;
480                  vih->bmiHeader.biBitCount = 32;                  bmih->biBitCount = 32;
481                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);
482                  break;                  break;
483  }  }
484          case 6 :          case 6 :
485  if ( USE_RGB24 )  if ( USE_RGB24 )
486  {  {
487                  vih->bmiHeader.biCompression = BI_RGB;                  bmih->biCompression = BI_RGB;
488                  vih->bmiHeader.biBitCount = 24;                  bmih->biBitCount = 24;
489                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);
490                  break;                  break;
491  }  }
492          case 7 :          case 7 :
493  if ( USE_RG555 )  if ( USE_RG555 )
494  {  {
495                  vih->bmiHeader.biCompression = BI_RGB;                  bmih->biCompression = BI_RGB;
496                  vih->bmiHeader.biBitCount = 16;                  bmih->biBitCount = 16;
497                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);
498                  break;                  break;
499  }  }
500          case 8 :          case 8 :
501  if ( USE_RG565 )  if ( USE_RG565 )
502  {  {
503                  vih->bmiHeader.biCompression = BI_RGB;                  bmih->biCompression = BI_RGB;
504                  vih->bmiHeader.biBitCount = 16;                  bmih->biBitCount = 16;
505                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);
506                  break;                  break;
507  }  }
# Line 494  Line 509 
509                  return VFW_S_NO_MORE_ITEMS;                  return VFW_S_NO_MORE_ITEMS;
510          }          }
511    
512          vih->bmiHeader.biSizeImage = GetBitmapSize(&vih->bmiHeader);          bmih->biSizeImage = GetBitmapSize(bmih);
   
         if (ar_x != 0 && ar_y != 0) {  
                 vih->dwPictAspectRatioX = ar_x;  
                 vih->dwPictAspectRatioY = ar_y;  
         } else { // just to be safe  
                 vih->dwPictAspectRatioX = m_create.width;  
                 vih->dwPictAspectRatioY = m_create.height;  
         }  
513    
514          mtOut->SetType(&MEDIATYPE_Video);          mtOut->SetType(&MEDIATYPE_Video);
         mtOut->SetFormatType(&FORMAT_VideoInfo2);  
515          mtOut->SetTemporalCompression(FALSE);          mtOut->SetTemporalCompression(FALSE);
516          mtOut->SetSampleSize(vih->bmiHeader.biSizeImage);          mtOut->SetSampleSize(bmih->biSizeImage);
517    
518          return S_OK;          return S_OK;
519  }  }
# Line 537  Line 543 
543          if (subtype == CLSID_MEDIASUBTYPE_IYUV)          if (subtype == CLSID_MEDIASUBTYPE_IYUV)
544          {          {
545                  DPRINTF("IYUV");                  DPRINTF("IYUV");
546                    rgb_flip = 0;
547                  m_frame.output.csp = XVID_CSP_I420;                  m_frame.output.csp = XVID_CSP_I420;
548                  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 */
549          }          }
550          else if (subtype == MEDIASUBTYPE_YV12)          else if (subtype == MEDIASUBTYPE_YV12)
551          {          {
552                  DPRINTF("YV12");                  DPRINTF("YV12");
553                    rgb_flip = 0;
554                  m_frame.output.csp = XVID_CSP_YV12;                  m_frame.output.csp = XVID_CSP_YV12;
555                  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 */
556          }          }
557          else if (subtype == MEDIASUBTYPE_YUY2)          else if (subtype == MEDIASUBTYPE_YUY2)
558          {          {
559                  DPRINTF("YUY2");                  DPRINTF("YUY2");
560                    rgb_flip = 0;
561                  m_frame.output.csp = XVID_CSP_YUY2;                  m_frame.output.csp = XVID_CSP_YUY2;
562          }          }
563          else if (subtype == MEDIASUBTYPE_YVYU)          else if (subtype == MEDIASUBTYPE_YVYU)
564          {          {
565                  DPRINTF("YVYU");                  DPRINTF("YVYU");
566                    rgb_flip = 0;
567                  m_frame.output.csp = XVID_CSP_YVYU;                  m_frame.output.csp = XVID_CSP_YVYU;
568          }          }
569          else if (subtype == MEDIASUBTYPE_UYVY)          else if (subtype == MEDIASUBTYPE_UYVY)
570          {          {
571                  DPRINTF("UYVY");                  DPRINTF("UYVY");
572                    rgb_flip = 0;
573                  m_frame.output.csp = XVID_CSP_UYVY;                  m_frame.output.csp = XVID_CSP_UYVY;
574          }          }
575          else if (subtype == MEDIASUBTYPE_RGB32)          else if (subtype == MEDIASUBTYPE_RGB32)
# Line 704  Line 715 
715          if (pIn->IsDiscontinuity() == S_OK)          if (pIn->IsDiscontinuity() == S_OK)
716                  m_frame.general = XVID_DISCONTINUITY;                  m_frame.general = XVID_DISCONTINUITY;
717    
718          if (PPSettings.bDeblock_Y)          if (g_config.nDeblock_Y)
719                  m_frame.general |= XVID_DEBLOCKY;                  m_frame.general |= XVID_DEBLOCKY;
720    
721          if (PPSettings.bDeblock_UV)          if (g_config.nDeblock_UV)
722                  m_frame.general |= XVID_DEBLOCKUV;                  m_frame.general |= XVID_DEBLOCKUV;
723  /*  /*
724          if (PPSettings.bDering)          if (g_config.nDering)
725                  m_frame.general |= XVID_DERING;                  m_frame.general |= XVID_DERING;
726  */  */
727          if (PPSettings.bFilmEffect)          if (g_config.nFilmEffect)
728                  m_frame.general |= XVID_FILMEFFECT;                  m_frame.general |= XVID_FILMEFFECT;
729    
730          m_frame.output.csp &= ~XVID_CSP_VFLIP;          m_frame.output.csp &= ~XVID_CSP_VFLIP;
731          m_frame.output.csp |= rgb_flip^(PPSettings.bFlipVideo ? XVID_CSP_VFLIP : 0);          m_frame.output.csp |= rgb_flip^(g_config.nFlipVideo ? XVID_CSP_VFLIP : 0);
732    
733  repeat :  repeat :
734    
# Line 755  Line 766 
766                  m_frame.general = tmp_gen;                  m_frame.general = tmp_gen;
767          }          }
768    
769          if (stats.type == XVID_TYPE_NOTHING) {          if (stats.type == XVID_TYPE_NOTHING && length > 0) {
770                  DPRINTF("B-Frame decoder lag");                  DPRINTF("B-Frame decoder lag");
771                  return S_FALSE;                  return S_FALSE;
772          }          }
# Line 770  Line 781 
781                          return S_FALSE;                          return S_FALSE;
782                  }                  }
783    
784                  pOut->SetDiscontinuity(TRUE);  //              pOut->SetDiscontinuity(TRUE);
785                  pOut->SetSyncPoint(TRUE);                  pOut->SetSyncPoint(TRUE);
786    
787                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;

Legend:
Removed from v.1314  
changed lines
  Added in v.1367

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