[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 1334, Mon Jan 26 05:49:42 2004 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.12 2004-01-26 05:49:42 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
# 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    
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            ar_x = ar_y = 0;
216    
217          m_hdll = LoadLibrary(XVID_DLL_NAME);          m_hdll = LoadLibrary(XVID_DLL_NAME);
218          if (m_hdll == NULL) {          if (m_hdll == NULL) {
# Line 204  Line 221 
221                  return;                  return;
222          }          }
223    
224          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");
225          if (m_xvid_global == NULL) {          if (xvid_global_func == NULL) {
226                  MessageBox(0, XVID_GLOBAL_NAME "() not found", "Error", 0);                  MessageBox(0, "xvid_global() not found", "Error", 0);
227                  return;                  return;
228          }          }
229    
230          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");
231          if (m_xvid_decore == NULL) {          if (xvid_decore_func == NULL) {
232                  MessageBox(0, XVID_DECORE_NAME "() not found", "Error", 0);                  MessageBox(0, "xvid_decore() not found", "Error", 0);
233                  return;                  return;
234          }          }
235    
236          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)  
237          {          {
238                  MessageBox(0, XVID_GLOBAL_NAME "() failed", "Error", 0);                  MessageBox(0, "xvid_global() failed", "Error", 0);
239                  return;                  return;
240          }          }
241    
# Line 231  Line 245 
245    
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;
250            DWORD size;
251            RegOpenKeyEx(XVID_REG_KEY, XVID_REG_SUBKEY, 0, KEY_READ, &hKey);
252    
253            // Set the default post-processing settings
254            REG_GET_N("Brightness", PPSettings.nBrightness, 25)
255            REG_GET_N("Deblock_Y",  PPSettings.nDeblock_Y, 0)
256            REG_GET_N("Deblock_UV", PPSettings.nDeblock_UV, 0)
257            REG_GET_N("Dering",  PPSettings.nDering, 0)
258            REG_GET_N("FilmEffect", PPSettings.nFilmEffect, 0)
259            REG_GET_N("ForceColorspace", PPSettings.nForceColorspace, 0)
260            REG_GET_N("FlipVideo",  PPSettings.nFlipVideo, 0)
261    
262            RegCloseKey(hKey);
263    
264            USE_IYUV = false;
265            USE_YV12 = false;
266            USE_YUY2 = false;
267            USE_YVYU = false;
268            USE_UYVY = false;
269            USE_RGB32 = false;
270            USE_RGB24 = false;
271            USE_RG555 = false;
272            USE_RG565 = false;
273    
274            switch ( PPSettings.nForceColorspace )
275            {
276            case FORCE_NONE:
277                    USE_IYUV = true;
278                    USE_YV12 = true;
279                    USE_YUY2 = true;
280                    USE_YVYU = true;
281                    USE_UYVY = true;
282                    USE_RGB32 = true;
283                    USE_RGB24 = true;
284                    USE_RG555 = true;
285                    USE_RG565 = true;
286                    break;
287            case FORCE_YV12:
288                    USE_IYUV = true;
289                    USE_YV12 = true;
290                    break;
291            case FORCE_YUY2:
292                    USE_YUY2 = true;
293                    break;
294            case FORCE_RGB24:
295                    USE_RGB24 = true;
296                    break;
297            case FORCE_RGB32:
298                    USE_RGB32 = true;
299                    break;
300            }
301  }  }
302    
303    
# Line 243  Line 310 
310    
311          if (m_create.handle != NULL)          if (m_create.handle != NULL)
312          {          {
313                  m_xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0);                  xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0);
314                  m_create.handle = NULL;                  m_create.handle = NULL;
315          }          }
316    
# Line 273  Line 340 
340          {          {
341                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format();                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format();
342                  hdr = &vih->bmiHeader;                  hdr = &vih->bmiHeader;
343                    /* PAR (x:y) is (1/ppm_X):(1/ppm_Y) where ppm is pixels-per-meter
344                       which is equal to ppm_Y:ppm_X */
345                    ar_x = vih->bmiHeader.biYPelsPerMeter*hdr->biWidth;
346                    ar_y = vih->bmiHeader.biXPelsPerMeter*hdr->biHeight;
347          }          }
348          else if (*mtIn->FormatType() == FORMAT_VideoInfo2)          else if (*mtIn->FormatType() == FORMAT_VideoInfo2)
349          {          {
350                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format();                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format();
351                  hdr = &vih2->bmiHeader;                  hdr = &vih2->bmiHeader;
352                    ar_x = vih2->dwPictAspectRatioX;
353                    ar_y = vih2->dwPictAspectRatioY;
354          }          }
355          else          else
356          {          {
# Line 314  Line 387 
387  }  }
388    
389    
 #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  
   
390  /* get list of supported output colorspaces */  /* get list of supported output colorspaces */
391    
392    
393  HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut)  HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut)
394  {  {
395          DPRINTF("GetMediaType");          DPRINTF("GetMediaType");
# Line 335  Line 399 
399                  return E_UNEXPECTED;                  return E_UNEXPECTED;
400          }          }
401    
402          VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER));          VIDEOINFOHEADER2 * vih = (VIDEOINFOHEADER2 *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER2));
403          if (vih == NULL)          if (vih == NULL)
404          {          {
405                  return E_OUTOFMEMORY;                  return E_OUTOFMEMORY;
# Line 354  Line 418 
418    
419          switch(iPosition)          switch(iPosition)
420          {          {
421    
422          case 0  :          case 0  :
423  #ifdef USE_IYUV  if ( USE_YUY2 )
424                  vih->bmiHeader.biCompression = MEDIASUBTYPE_IYUV.Data1;  {
                 vih->bmiHeader.biBitCount = 12;  
                 mtOut->SetSubtype(&MEDIASUBTYPE_IYUV);  
                 break;  
 #endif  
         case 1  :  
 #ifdef USE_YV12  
                 vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;  
                 vih->bmiHeader.biBitCount = 12;  
                 mtOut->SetSubtype(&MEDIASUBTYPE_YV12);  
                 break;  
 #endif  
         case 2:  
 #ifdef USE_YUY2  
425                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;
426                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
427                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);
428                  break;                  break;
429  #endif  }
430          case 3 :          case 1 :
431  #ifdef USE_YVYU  if ( USE_YVYU )
432    {
433                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;
434                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
435                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);
436                  break;                  break;
437  #endif  }
438          case 4 :          case 2 :
439  #ifdef USE_UYVY  if ( USE_UYVY )
440    {
441                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;
442                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
443                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);
444                  break;                  break;
445  #endif  }
446            case 3  :
447                    if ( USE_IYUV )
448    {
449                    vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1;
450                    vih->bmiHeader.biBitCount = 12;
451                    mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV);
452                    break;
453    }
454            case 4  :
455    if ( USE_YV12 )
456    {
457                    vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;
458                    vih->bmiHeader.biBitCount = 12;
459                    mtOut->SetSubtype(&MEDIASUBTYPE_YV12);
460                    break;
461    }
462          case 5 :          case 5 :
463  #ifdef USE_RGB32  if ( USE_RGB32 )
464    {
465                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
466                  vih->bmiHeader.biBitCount = 32;                  vih->bmiHeader.biBitCount = 32;
467                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);
468                  break;                  break;
469  #endif  }
470          case 6 :          case 6 :
471  #ifdef USE_RGB24  if ( USE_RGB24 )
472    {
473                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
474                  vih->bmiHeader.biBitCount = 24;                  vih->bmiHeader.biBitCount = 24;
475                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);
476                  break;                  break;
477  #endif  }
478          case 7 :          case 7 :
479  #ifdef USE_RG555  if ( USE_RG555 )
480    {
481                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
482                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
483                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);
484                  break;                  break;
485  #endif  }
486          case 8 :          case 8 :
487  #ifdef USE_RG565  if ( USE_RG565 )
488    {
489                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
490                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
491                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);
492                  break;                  break;
493  #endif  }
494          default :          default :
495                  return VFW_S_NO_MORE_ITEMS;                  return VFW_S_NO_MORE_ITEMS;
496          }          }
497    
498          vih->bmiHeader.biSizeImage = GetBitmapSize(&vih->bmiHeader);          vih->bmiHeader.biSizeImage = GetBitmapSize(&vih->bmiHeader);
499    
500            if (ar_x != 0 && ar_y != 0) {
501                    vih->dwPictAspectRatioX = ar_x;
502                    vih->dwPictAspectRatioY = ar_y;
503            } else { // just to be safe
504                    vih->dwPictAspectRatioX = m_create.width;
505                    vih->dwPictAspectRatioY = m_create.height;
506            }
507    
508          mtOut->SetType(&MEDIATYPE_Video);          mtOut->SetType(&MEDIATYPE_Video);
509          mtOut->SetFormatType(&FORMAT_VideoInfo);          mtOut->SetFormatType(&FORMAT_VideoInfo2);
510          mtOut->SetTemporalCompression(FALSE);          mtOut->SetTemporalCompression(FALSE);
511          mtOut->SetSampleSize(vih->bmiHeader.biSizeImage);          mtOut->SetSampleSize(vih->bmiHeader.biSizeImage);
512    
# Line 436  Line 518 
518    
519  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)
520  {  {
         int rgb_flip;  
   
521          if (formattype == FORMAT_VideoInfo)          if (formattype == FORMAT_VideoInfo)
522          {          {
523                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;
# Line 455  Line 535 
535                  return S_FALSE;                  return S_FALSE;
536          }          }
537    
538          if (subtype == MEDIASUBTYPE_IYUV)          if (subtype == CLSID_MEDIASUBTYPE_IYUV)
539          {          {
540                  DPRINTF("IYUV");                  DPRINTF("IYUV");
541                  m_frame.output.csp = XVID_CSP_I420;                  m_frame.output.csp = XVID_CSP_I420;
# Line 586  Line 666 
666    
667          if (m_create.handle == NULL)          if (m_create.handle == NULL)
668          {          {
669                  if (m_xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0)                  if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0)
670                  {                  {
671              DPRINTF("*** XVID_DEC_CREATE error");              DPRINTF("*** XVID_DEC_CREATE error");
672                          return S_FALSE;                          return S_FALSE;
# Line 621  Line 701 
701          }          }
702    
703          m_frame.general = XVID_LOWDELAY;          m_frame.general = XVID_LOWDELAY;
704    
705          if (pIn->IsDiscontinuity() == S_OK)          if (pIn->IsDiscontinuity() == S_OK)
706                  m_frame.general = XVID_DISCONTINUITY;                  m_frame.general = XVID_DISCONTINUITY;
707    
708            if (PPSettings.nDeblock_Y)
709                    m_frame.general |= XVID_DEBLOCKY;
710    
711            if (PPSettings.nDeblock_UV)
712                    m_frame.general |= XVID_DEBLOCKUV;
713    /*
714            if (PPSettings.nDering)
715                    m_frame.general |= XVID_DERING;
716    */
717            if (PPSettings.nFilmEffect)
718                    m_frame.general |= XVID_FILMEFFECT;
719    
720            m_frame.output.csp &= ~XVID_CSP_VFLIP;
721            m_frame.output.csp |= rgb_flip^(PPSettings.nFlipVideo ? XVID_CSP_VFLIP : 0);
722    
723  repeat :  repeat :
724    
725          if (pIn->IsPreroll() != S_OK)          if (pIn->IsPreroll() != S_OK)
726          {          {
727                  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);
728    
729                  if (length < 0)                  if (length < 0)
730                  {                  {
731              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
# Line 636  Line 733 
733                  }                  }
734          }          }
735          else          else
736          {          {       /* Preroll frame - won't be displayed */
737                  int tmp = m_frame.output.csp;                  int tmp = m_frame.output.csp;
738                    int tmp_gen = m_frame.general;
739    
740                  m_frame.output.csp = XVID_CSP_NULL;                  m_frame.output.csp = XVID_CSP_NULL;
741    
742                  length = m_xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);                  /* Disable postprocessing to speed-up seeking */
743                    m_frame.general &= ~XVID_DEBLOCKY;
744                    m_frame.general &= ~XVID_DEBLOCKUV;
745    /*              m_frame.general &= ~XVID_DERING; */
746                    m_frame.general &= ~XVID_FILMEFFECT;
747    
748                    length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);
749                  if (length < 0)                  if (length < 0)
750                  {                  {
751              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
# Line 648  Line 753 
753                  }                  }
754    
755                  m_frame.output.csp = tmp;                  m_frame.output.csp = tmp;
756                    m_frame.general = tmp_gen;
757            }
758    
759            if (stats.type == XVID_TYPE_NOTHING) {
760                    DPRINTF("B-Frame decoder lag");
761                    return S_FALSE;
762          }          }
763    
764    
765          if (stats.type == XVID_TYPE_VOL)          if (stats.type == XVID_TYPE_VOL)
766          {          {
767                  if (stats.data.vol.width != m_create.width ||                  if (stats.data.vol.width != m_create.width ||
# Line 659  Line 771 
771                          return S_FALSE;                          return S_FALSE;
772                  }                  }
773    
774                    pOut->SetDiscontinuity(TRUE);
775                    pOut->SetSyncPoint(TRUE);
776    
777                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;
778                  m_frame.length -= length;                  m_frame.length -= length;
779                  goto repeat;                  goto repeat;
780          }          }
781    
782            if (pIn->IsPreroll() == S_OK) {
783                    return S_FALSE;
784            }
785    
786          return S_OK;          return S_OK;
787  }  }
788    

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

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