[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 1310, Fri Jan 9 04:37:59 2004 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.10 2004-01-09 04:37:59 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    
# 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    
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 208  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 235  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.bDeblock_Y, 1)
256            REG_GET_N("Deblock_UV", PPSettings.bDeblock_UV, 1)
257            REG_GET_N("Dering",  PPSettings.bDering, 1)
258            REG_GET_N("FilmEffect", PPSettings.bFilmEffect, 1)
259            REG_GET_N("ForceColorspace", PPSettings.nForceColorspace, 0)
260    
261            RegCloseKey(hKey);
262    
263            USE_IYUV = false;
264            USE_YV12 = false;
265            USE_YUY2 = false;
266            USE_YVYU = false;
267            USE_UYVY = false;
268            USE_RGB32 = false;
269            USE_RGB24 = false;
270            USE_RG555 = false;
271            USE_RG565 = false;
272    
273            switch ( PPSettings.nForceColorspace )
274            {
275            case FORCE_NONE:
276                    USE_IYUV = true;
277                    USE_YV12 = true;
278                    USE_YUY2 = true;
279                    USE_YVYU = true;
280                    USE_UYVY = true;
281                    USE_RGB32 = true;
282                    USE_RGB24 = true;
283                    USE_RG555 = true;
284                    USE_RG565 = true;
285                    break;
286            case FORCE_YV12:
287                    USE_IYUV = true;
288                    USE_YV12 = true;
289                    break;
290            case FORCE_YUY2:
291                    USE_YUY2 = true;
292                    break;
293            case FORCE_RGB24:
294                    USE_RGB24 = true;
295                    break;
296            case FORCE_RGB32:
297                    USE_RGB32 = true;
298                    break;
299            }
300  }  }
301    
302    
# Line 247  Line 309 
309    
310          if (m_create.handle != NULL)          if (m_create.handle != NULL)
311          {          {
312                  m_xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0);                  xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0);
313                  m_create.handle = NULL;                  m_create.handle = NULL;
314          }          }
315    
# Line 277  Line 339 
339          {          {
340                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format();                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format();
341                  hdr = &vih->bmiHeader;                  hdr = &vih->bmiHeader;
342                    /* PAR (x:y) is (1/ppm_X):(1/ppm_Y) where ppm is pixels-per-meter
343                       which is equal to ppm_Y:ppm_X */
344                    ar_x = vih->bmiHeader.biYPelsPerMeter*hdr->biWidth;
345                    ar_y = vih->bmiHeader.biXPelsPerMeter*hdr->biHeight;
346          }          }
347          else if (*mtIn->FormatType() == FORMAT_VideoInfo2)          else if (*mtIn->FormatType() == FORMAT_VideoInfo2)
348          {          {
349                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format();                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format();
350                  hdr = &vih2->bmiHeader;                  hdr = &vih2->bmiHeader;
351                    ar_x = vih2->dwPictAspectRatioX;
352                    ar_y = vih2->dwPictAspectRatioY;
353          }          }
354          else          else
355          {          {
# Line 318  Line 386 
386  }  }
387    
388    
 #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  
   
389  /* get list of supported output colorspaces */  /* get list of supported output colorspaces */
390    
391    
392  HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut)  HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut)
393  {  {
394          DPRINTF("GetMediaType");          DPRINTF("GetMediaType");
# Line 339  Line 398 
398                  return E_UNEXPECTED;                  return E_UNEXPECTED;
399          }          }
400    
401          VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER));          VIDEOINFOHEADER2 * vih = (VIDEOINFOHEADER2 *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER2));
402          if (vih == NULL)          if (vih == NULL)
403          {          {
404                  return E_OUTOFMEMORY;                  return E_OUTOFMEMORY;
# Line 358  Line 417 
417    
418          switch(iPosition)          switch(iPosition)
419          {          {
420    
421          case 0  :          case 0  :
422  #ifdef USE_IYUV  if ( USE_YUY2 )
423                  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  
424                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;
425                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
426                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);
427                  break;                  break;
428  #endif  }
429          case 3 :          case 1 :
430  #ifdef USE_YVYU  if ( USE_YVYU )
431    {
432                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;
433                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
434                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);
435                  break;                  break;
436  #endif  }
437          case 4 :          case 2 :
438  #ifdef USE_UYVY  if ( USE_UYVY )
439    {
440                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;
441                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
442                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);
443                  break;                  break;
444  #endif  }
445            case 3  :
446                    if ( USE_IYUV )
447    {
448                    vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1;
449                    vih->bmiHeader.biBitCount = 12;
450                    mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV);
451                    break;
452    }
453            case 4  :
454    if ( USE_YV12 )
455    {
456                    vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;
457                    vih->bmiHeader.biBitCount = 12;
458                    mtOut->SetSubtype(&MEDIASUBTYPE_YV12);
459                    break;
460    }
461          case 5 :          case 5 :
462  #ifdef USE_RGB32  if ( USE_RGB32 )
463    {
464                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
465                  vih->bmiHeader.biBitCount = 32;                  vih->bmiHeader.biBitCount = 32;
466                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);
467                  break;                  break;
468  #endif  }
469          case 6 :          case 6 :
470  #ifdef USE_RGB24  if ( USE_RGB24 )
471    {
472                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
473                  vih->bmiHeader.biBitCount = 24;                  vih->bmiHeader.biBitCount = 24;
474                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);
475                  break;                  break;
476  #endif  }
477          case 7 :          case 7 :
478  #ifdef USE_RG555  if ( USE_RG555 )
479    {
480                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
481                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
482                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);
483                  break;                  break;
484  #endif  }
485          case 8 :          case 8 :
486  #ifdef USE_RG565  if ( USE_RG565 )
487    {
488                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
489                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
490                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);
491                  break;                  break;
492  #endif  }
493          default :          default :
494                  return VFW_S_NO_MORE_ITEMS;                  return VFW_S_NO_MORE_ITEMS;
495          }          }
496    
497          vih->bmiHeader.biSizeImage = GetBitmapSize(&vih->bmiHeader);          vih->bmiHeader.biSizeImage = GetBitmapSize(&vih->bmiHeader);
498    
499            if (ar_x != 0 && ar_y != 0) {
500                    vih->dwPictAspectRatioX = ar_x;
501                    vih->dwPictAspectRatioY = ar_y;
502            } else { // just to be safe
503                    vih->dwPictAspectRatioX = m_create.width;
504                    vih->dwPictAspectRatioY = m_create.height;
505            }
506    
507          mtOut->SetType(&MEDIATYPE_Video);          mtOut->SetType(&MEDIATYPE_Video);
508          mtOut->SetFormatType(&FORMAT_VideoInfo);          mtOut->SetFormatType(&FORMAT_VideoInfo2);
509          mtOut->SetTemporalCompression(FALSE);          mtOut->SetTemporalCompression(FALSE);
510          mtOut->SetSampleSize(vih->bmiHeader.biSizeImage);          mtOut->SetSampleSize(vih->bmiHeader.biSizeImage);
511    
# Line 440  Line 517 
517    
518  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)
519  {  {
         int rgb_flip;  
   
520          if (formattype == FORMAT_VideoInfo)          if (formattype == FORMAT_VideoInfo)
521          {          {
522                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;
# Line 459  Line 534 
534                  return S_FALSE;                  return S_FALSE;
535          }          }
536    
537          if (subtype == MEDIASUBTYPE_IYUV)          if (subtype == CLSID_MEDIASUBTYPE_IYUV)
538          {          {
539                  DPRINTF("IYUV");                  DPRINTF("IYUV");
540                  m_frame.output.csp = XVID_CSP_I420;                  m_frame.output.csp = XVID_CSP_I420;
# Line 590  Line 665 
665    
666          if (m_create.handle == NULL)          if (m_create.handle == NULL)
667          {          {
668                  if (m_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 625  Line 700 
700          }          }
701    
702          m_frame.general = XVID_LOWDELAY;          m_frame.general = XVID_LOWDELAY;
703    
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)
708                    m_frame.general |= XVID_DEBLOCKY;
709    
710            if (PPSettings.bDeblock_UV)
711                    m_frame.general |= XVID_DEBLOCKUV;
712    /*
713            if (PPSettings.bDering)
714                    m_frame.general |= XVID_DERING;
715    */
716            if (PPSettings.bFilmEffect)
717                    m_frame.general |= XVID_FILMEFFECT;
718    
719            m_frame.output.csp &= ~XVID_CSP_VFLIP;
720            m_frame.output.csp |= rgb_flip^(PPSettings.bFlipVideo ? XVID_CSP_VFLIP : 0);
721    
722  repeat :  repeat :
723    
724          if (pIn->IsPreroll() != S_OK)          if (pIn->IsPreroll() != S_OK)
725          {          {
726                  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);
727    
728                  if (length < 0)                  if (length < 0)
729                  {                  {
730              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
# Line 640  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 = m_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 652  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) {
759                    DPRINTF("B-Frame decoder lag");
760                    return S_FALSE;
761          }          }
762    
763    
764          if (stats.type == XVID_TYPE_VOL)          if (stats.type == XVID_TYPE_VOL)
765          {          {
766                  if (stats.data.vol.width != m_create.width ||                  if (stats.data.vol.width != m_create.width ||
# Line 663  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.1054  
changed lines
  Added in v.1310

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