[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 1208, Sat Nov 15 02:51:41 2003 UTC revision 1301, Fri Jan 2 13:18:28 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.3 2003-11-15 02:51:41 suxen_drol Exp $   * $Id: CXvidDecoder.cpp,v 1.1.2.8 2004-01-02 13:18:28 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 132  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 180  Line 199 
199    
200    
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 191  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            m_hdll = LoadLibrary(XVID_DLL_NAME);
216            if (m_hdll == NULL) {
217                    DPRINTF("dll load failed");
218                    MessageBox(0, XVID_DLL_NAME " not found","Error", 0);
219                    return;
220            }
221    
222            xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global");
223            if (xvid_global_func == NULL) {
224                    MessageBox(0, "xvid_global() not found", "Error", 0);
225                    return;
226            }
227    
228            xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore");
229            if (xvid_decore_func == NULL) {
230                    MessageBox(0, "xvid_decore() not found", "Error", 0);
231                    return;
232            }
233    
234            if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0)
235          {          {
236                  MessageBox(0, "xvid_global() failed", "Error", 0);                  MessageBox(0, "xvid_global() failed", "Error", 0);
237                  return;                  return;
# Line 203  Line 243 
243    
244          memset(&m_frame, 0, sizeof(m_frame));          memset(&m_frame, 0, sizeof(m_frame));
245          m_frame.version = XVID_VERSION;          m_frame.version = XVID_VERSION;
246    
247            HKEY hKey;
248            DWORD size;
249            RegOpenKeyEx(XVID_REG_KEY, XVID_REG_SUBKEY, 0, KEY_READ, &hKey);
250    
251            // Set the default post-processing settings
252            REG_GET_N("Brightness", PPSettings.nBrightness, 25)
253            REG_GET_N("Deblock_Y",  PPSettings.bDeblock_Y, 1)
254            REG_GET_N("Deblock_UV", PPSettings.bDeblock_UV, 1)
255            REG_GET_N("Dering",  PPSettings.bDering, 1)
256            REG_GET_N("FilmEffect", PPSettings.bFilmEffect, 1)
257            REG_GET_N("ForceColorspace", PPSettings.nForceColorspace, 0)
258    
259            RegCloseKey(hKey);
260    
261            USE_IYUV = false;
262            USE_YV12 = false;
263            USE_YUY2 = false;
264            USE_YVYU = false;
265            USE_UYVY = false;
266            USE_RGB32 = false;
267            USE_RGB24 = false;
268            USE_RG555 = false;
269            USE_RG565 = false;
270    
271            switch ( PPSettings.nForceColorspace )
272            {
273            case FORCE_NONE:
274                    USE_IYUV = true;
275                    USE_YV12 = true;
276                    USE_YUY2 = true;
277                    USE_YVYU = true;
278                    USE_UYVY = true;
279                    USE_RGB32 = true;
280                    USE_RGB24 = true;
281                    USE_RG555 = true;
282                    USE_RG565 = true;
283                    break;
284            case FORCE_YV12:
285                    USE_IYUV = true;
286                    USE_YV12 = true;
287                    break;
288            case FORCE_YUY2:
289                    USE_YUY2 = true;
290                    break;
291            case FORCE_RGB24:
292                    USE_RGB24 = true;
293                    break;
294            case FORCE_RGB32:
295                    USE_RGB32 = true;
296                    break;
297            }
298  }  }
299    
300    
# Line 215  Line 307 
307    
308          if (m_create.handle != NULL)          if (m_create.handle != NULL)
309          {          {
310                  xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0);                  xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0);
311                  m_create.handle = NULL;                  m_create.handle = NULL;
312          }          }
313    
314            if (m_hdll != NULL)
315            {
316                    FreeLibrary(m_hdll);
317                    m_hdll = NULL;
318            }
319  }  }
320    
321    
# Line 280  Line 378 
378  }  }
379    
380    
 #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  
   
381  /* get list of supported output colorspaces */  /* get list of supported output colorspaces */
382    
383    
# Line 322  Line 410 
410          switch(iPosition)          switch(iPosition)
411          {          {
412          case 0  :          case 0  :
413  #ifdef USE_IYUV  if ( USE_IYUV )
414    {
415                  vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1;                  vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1;
416                  vih->bmiHeader.biBitCount = 12;                  vih->bmiHeader.biBitCount = 12;
417                  mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV);                  mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV);
418                  break;                  break;
419  #endif  }
420          case 1  :          case 1  :
421  #ifdef USE_YV12  if ( USE_YV12 )
422    {
423                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1;
424                  vih->bmiHeader.biBitCount = 12;                  vih->bmiHeader.biBitCount = 12;
425                  mtOut->SetSubtype(&MEDIASUBTYPE_YV12);                  mtOut->SetSubtype(&MEDIASUBTYPE_YV12);
426                  break;                  break;
427  #endif  }
428          case 2:          case 2:
429  #ifdef USE_YUY2  if ( USE_YUY2 )
430    {
431                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;
432                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
433                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);
434                  break;                  break;
435  #endif  }
436          case 3 :          case 3 :
437  #ifdef USE_YVYU  if ( USE_YVYU )
438    {
439                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;
440                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
441                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);
442                  break;                  break;
443  #endif  }
444          case 4 :          case 4 :
445  #ifdef USE_UYVY  if ( USE_UYVY )
446    {
447                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;
448                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
449                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);
450                  break;                  break;
451  #endif  }
452          case 5 :          case 5 :
453  #ifdef USE_RGB32  if ( USE_RGB32 )
454    {
455                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
456                  vih->bmiHeader.biBitCount = 32;                  vih->bmiHeader.biBitCount = 32;
457                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);
458                  break;                  break;
459  #endif  }
460          case 6 :          case 6 :
461  #ifdef USE_RGB24  if ( USE_RGB24 )
462    {
463                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
464                  vih->bmiHeader.biBitCount = 24;                  vih->bmiHeader.biBitCount = 24;
465                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);
466                  break;                  break;
467  #endif  }
468          case 7 :          case 7 :
469  #ifdef USE_RG555  if ( USE_RG555 )
470    {
471                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
472                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
473                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);
474                  break;                  break;
475  #endif  }
476          case 8 :          case 8 :
477  #ifdef USE_RG565  if ( USE_RG565 )
478    {
479                  vih->bmiHeader.biCompression = BI_RGB;                  vih->bmiHeader.biCompression = BI_RGB;
480                  vih->bmiHeader.biBitCount = 16;                  vih->bmiHeader.biBitCount = 16;
481                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);                  mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);
482                  break;                  break;
483  #endif  }
484          default :          default :
485                  return VFW_S_NO_MORE_ITEMS;                  return VFW_S_NO_MORE_ITEMS;
486          }          }
# Line 403  Line 500 
500    
501  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)
502  {  {
         int rgb_flip;  
   
503          if (formattype == FORMAT_VideoInfo)          if (formattype == FORMAT_VideoInfo)
504          {          {
505                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;
# Line 553  Line 648 
648    
649          if (m_create.handle == NULL)          if (m_create.handle == NULL)
650          {          {
651                  if (xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0)                  if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0)
652                  {                  {
653              DPRINTF("*** XVID_DEC_CREATE error");              DPRINTF("*** XVID_DEC_CREATE error");
654                          return S_FALSE;                          return S_FALSE;
# Line 588  Line 683 
683          }          }
684    
685          m_frame.general = XVID_LOWDELAY;          m_frame.general = XVID_LOWDELAY;
686    
687          if (pIn->IsDiscontinuity() == S_OK)          if (pIn->IsDiscontinuity() == S_OK)
688                  m_frame.general = XVID_DISCONTINUITY;                  m_frame.general = XVID_DISCONTINUITY;
689    
690            if (PPSettings.bDeblock_Y)
691                    m_frame.general |= XVID_DEBLOCKY;
692    
693            if (PPSettings.bDeblock_UV)
694                    m_frame.general |= XVID_DEBLOCKUV;
695    /*
696            if (PPSettings.bDering)
697                    m_frame.general |= XVID_DERING;
698    */
699            if (PPSettings.bFilmEffect)
700                    m_frame.general |= XVID_FILMEFFECT;
701    
702            if (PPSettings.bFlipVideo) {
703                    if (rgb_flip)
704                            m_frame.output.csp &= ~XVID_CSP_VFLIP;
705                    else
706                            m_frame.output.csp |= XVID_CSP_VFLIP;
707            }
708            else {
709                    if (rgb_flip)
710                            m_frame.output.csp |= XVID_CSP_VFLIP;
711                    else
712                            m_frame.output.csp &= ~XVID_CSP_VFLIP;
713            }
714    
715  repeat :  repeat :
716    
717          if (pIn->IsPreroll() != S_OK)          if (pIn->IsPreroll() != S_OK)
718          {          {
719                  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);
720    
721                  if (length < 0)                  if (length < 0)
722                  {                  {
723              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
# Line 603  Line 725 
725                  }                  }
726          }          }
727          else          else
728          {          {       /* Preroll frame - won't be displayed */
729                  int tmp = m_frame.output.csp;                  int tmp = m_frame.output.csp;
730                    int tmp_gen = m_frame.general;
731    
732                  m_frame.output.csp = XVID_CSP_NULL;                  m_frame.output.csp = XVID_CSP_NULL;
733    
734                  length = xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);                  /* Disable postprocessing to speed-up seeking */
735                    m_frame.general &= ~XVID_DEBLOCKY;
736                    m_frame.general &= ~XVID_DEBLOCKUV;
737    /*              m_frame.general &= ~XVID_DERING; */
738                    m_frame.general &= ~XVID_FILMEFFECT;
739    
740                    length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);
741                  if (length < 0)                  if (length < 0)
742                  {                  {
743              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
# Line 615  Line 745 
745                  }                  }
746    
747                  m_frame.output.csp = tmp;                  m_frame.output.csp = tmp;
748                    m_frame.general = tmp_gen;
749            }
750    
751            if (stats.type == XVID_TYPE_NOTHING) {
752                    DPRINTF("B-Frame decoder lag");
753                    return S_FALSE;
754          }          }
755    
756    
757          if (stats.type == XVID_TYPE_VOL)          if (stats.type == XVID_TYPE_VOL)
758          {          {
759                  if (stats.data.vol.width != m_create.width ||                  if (stats.data.vol.width != m_create.width ||
# Line 626  Line 763 
763                          return S_FALSE;                          return S_FALSE;
764                  }                  }
765    
766                    pOut->SetDiscontinuity(TRUE);
767                    pOut->SetSyncPoint(TRUE);
768    
769                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;
770                  m_frame.length -= length;                  m_frame.length -= length;
771                  goto repeat;                  goto repeat;
772          }          }
773    
774            if (pIn->IsPreroll() == S_OK) {
775                    return S_FALSE;
776            }
777    
778          return S_OK;          return S_OK;
779  }  }
780    

Legend:
Removed from v.1208  
changed lines
  Added in v.1301

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