[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 1334, Mon Jan 26 05:49:42 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.5 2003-12-12 15:09:01 Isibaar Exp $   * $Id: CXvidDecoder.cpp,v 1.1.2.12 2004-01-26 05:49:42 syskin Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# 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 228  Line 252 
252    
253          // Set the default post-processing settings          // Set the default post-processing settings
254          REG_GET_N("Brightness", PPSettings.nBrightness, 25)          REG_GET_N("Brightness", PPSettings.nBrightness, 25)
255          REG_GET_N("Deblock_Y",  PPSettings.bDeblock_Y, 0)          REG_GET_N("Deblock_Y",  PPSettings.nDeblock_Y, 0)
256          REG_GET_N("Deblock_UV", PPSettings.bDeblock_UV, 0)          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)          REG_GET_N("ForceColorspace", PPSettings.nForceColorspace, 0)
260            REG_GET_N("FlipVideo",  PPSettings.nFlipVideo, 0)
261    
262          RegCloseKey(hKey);          RegCloseKey(hKey);
263    
# Line 283  Line 310 
310    
311          if (m_create.handle != NULL)          if (m_create.handle != NULL)
312          {          {
313                  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    
317            if (m_hdll != NULL)
318            {
319                    FreeLibrary(m_hdll);
320                    m_hdll = NULL;
321            }
322  }  }
323    
324    
# Line 307  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 360  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 379  Line 418 
418    
419          switch(iPosition)          switch(iPosition)
420          {          {
421    
422          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:  
423  if ( USE_YUY2 )  if ( USE_YUY2 )
424  {  {
425                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1;
# Line 403  Line 427 
427                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);                  mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);
428                  break;                  break;
429  }  }
430          case 3 :          case 1 :
431  if ( USE_YVYU )  if ( USE_YVYU )
432  {  {
433                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1;
# Line 411  Line 435 
435                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);                  mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);
436                  break;                  break;
437  }  }
438          case 4 :          case 2 :
439  if ( USE_UYVY )  if ( USE_UYVY )
440  {  {
441                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;                  vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1;
# Line 419  Line 443 
443                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);                  mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);
444                  break;                  break;
445  }  }
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  if ( USE_RGB32 )  if ( USE_RGB32 )
464  {  {
# Line 457  Line 497 
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 618  Line 666 
666    
667          if (m_create.handle == NULL)          if (m_create.handle == NULL)
668          {          {
669                  if (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 657  Line 705 
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.bDeblock_Y)          if (PPSettings.nDeblock_Y)
709                  m_frame.general |= XVID_DEBLOCKY;                  m_frame.general |= XVID_DEBLOCKY;
710    
711          if (PPSettings.bDeblock_UV)          if (PPSettings.nDeblock_UV)
712                  m_frame.general |= XVID_DEBLOCKUV;                  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    
         if (PPSettings.bFlipVideo) {  
                 if (rgb_flip)  
                         m_frame.output.csp &= ~XVID_CSP_VFLIP;  
                 else  
                         m_frame.output.csp |= XVID_CSP_VFLIP;  
         }  
         else {  
                 if (rgb_flip)  
                         m_frame.output.csp |= XVID_CSP_VFLIP;  
                 else  
720                          m_frame.output.csp &= ~XVID_CSP_VFLIP;                          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 = 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                  {                  {
# Line 689  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 = 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 701  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) {          if (stats.type == XVID_TYPE_NOTHING) {
# Line 718  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.1260  
changed lines
  Added in v.1334

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