[svn] / trunk / xvidcore / dshow / src / CXvidDecoder.cpp Repository:
ViewVC logotype

Diff of /trunk/xvidcore/dshow/src/CXvidDecoder.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1427, Wed Apr 14 02:44:20 2004 UTC revision 1896, Sat Oct 16 12:20:30 2010 UTC
# Line 1  Line 1 
1  /*****************************************************************************  /*****************************************************************************
2   *   *
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-2004 Peter Ross <pross@xvid.org>   *  Copyright(C) 2002-2010 Peter Ross <pross@xvid.org>
7     *               2003-2010 Michael Militzer <michael@xvid.org>
8   *   *
9   *  This program is free software ; you can redistribute it and/or modify   *  This program is free software ; you can redistribute it and/or modify
10   *  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 20 
20   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
21   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   *   *
23   * $Id: CXvidDecoder.cpp,v 1.4 2004-04-14 02:44:20 syskin Exp $   * $Id: CXvidDecoder.cpp,v 1.19 2010-10-16 12:20:30 Isibaar Exp $
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
# Line 36  Line 37 
37          place these paths at the top of the Tools|Options|Directories list          place these paths at the top of the Tools|Options|Directories list
38    
39          headers:          headers:
40          C:\DXVCSDK\include          C:\DX90SDK\Include
41          C:\DXVCSDK\samples\Multimedia\DirectShow\BaseClasses          C:\DX90SDK\Samples\C++\DirectShow\BaseClasses
42    
43          libraries (optional):          C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\Release
44          C:\DXVCSDK\samples\Multimedia\DirectShow\BaseClasses\Release          C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\Debug
45  */  */
46    
47    //#define XVID_USE_TRAYICON
48    
49  #include <windows.h>  #include <windows.h>
50    
# Line 55  Line 56 
56  #endif  #endif
57  #include <dvdmedia.h>   // VIDEOINFOHEADER2  #include <dvdmedia.h>   // VIDEOINFOHEADER2
58    
59  #include <xvid.h>               // XviD API  #include <shellapi.h>
60    
61    #include <xvid.h>               // Xvid API
62    
63    #include "resource.h"
64    
65  #include "IXvidDecoder.h"  #include "IXvidDecoder.h"
66  #include "CXvidDecoder.h"  #include "CXvidDecoder.h"
# Line 82  Line 87 
87          { &MEDIATYPE_Video, &CLSID_DX50 },          { &MEDIATYPE_Video, &CLSID_DX50 },
88          { &MEDIATYPE_Video, &CLSID_DX50_UC },          { &MEDIATYPE_Video, &CLSID_DX50_UC },
89          { &MEDIATYPE_Video, &CLSID_MP4V },          { &MEDIATYPE_Video, &CLSID_MP4V },
90      { &MEDIATYPE_Video, &CLSID_MP4V_UC },
91  };  };
92    
93  const AMOVIESETUP_MEDIATYPE sudOutputPinTypes[] =  const AMOVIESETUP_MEDIATYPE sudOutputPinTypes[] =
# Line 148  Line 154 
154    
155  };  };
156    
   
157  /* note: g_cTemplates must be global; used by strmbase.lib(dllentry.cpp,dllsetup.cpp) */  /* note: g_cTemplates must be global; used by strmbase.lib(dllentry.cpp,dllsetup.cpp) */
158  int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate);  int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate);
159    
160    #ifdef XVID_USE_TRAYICON
161    extern HINSTANCE g_xvid_hInst;
162    
163    static int GUI_Page = 0;
164    extern "C" void CALLBACK Configure(HWND hWndParent, HINSTANCE hInstParent, LPSTR lpCmdLine, int nCmdShow );
165    
166    LRESULT CALLBACK msg_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
167    {
168            switch ( uMsg )
169            {
170            case WM_ICONMESSAGE:
171                    switch(lParam)
172                    {
173                    case WM_LBUTTONDBLCLK:
174                            if (!GUI_Page) {
175                                    GUI_Page = 1;
176                                    Configure(hwnd, g_xvid_hInst, "", 1);
177                                    GUI_Page = 0;
178                            }
179                            break;
180                    default:
181                            return DefWindowProc(hwnd, uMsg, wParam, lParam);
182                    };
183                    break;
184    
185            default:
186                    return DefWindowProc(hwnd, uMsg, wParam, lParam);
187            }
188    
189            return TRUE; /* ok */
190    }
191    #endif
192    
193  STDAPI DllRegisterServer()  STDAPI DllRegisterServer()
194  {  {
# Line 204  Line 241 
241  #define XVID_DLL_NAME "xvidcore.dll"  #define XVID_DLL_NAME "xvidcore.dll"
242    
243  CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) :  CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) :
244      CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID)      CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID), m_hdll (NULL)
245  {  {
246          DPRINTF("Constructor");          DPRINTF("Constructor");
247    
248        xvid_decore_func = NULL; // Hmm, some strange errors appearing if I try to initialize...
249        xvid_global_func = NULL; // ...this in constructor's init-list. So, they assigned here.
250    
251    #ifdef XVID_USE_TRAYICON
252            MSG_hwnd = NULL;
253    #endif
254    
255        LoadRegistryInfo();
256    
257        *phr = OpenLib();
258    }
259    
260    HRESULT CXvidDecoder::OpenLib()
261    {
262        DPRINTF("OpenLib");
263    
264        if (m_hdll != NULL)
265                    return E_UNEXPECTED; // Seems, that library already opened.
266    
267          xvid_gbl_init_t init;          xvid_gbl_init_t init;
268          memset(&init, 0, sizeof(init));          memset(&init, 0, sizeof(init));
269          init.version = XVID_VERSION;          init.version = XVID_VERSION;
270    
         ar_x = ar_y = 0;  
   
271          m_hdll = LoadLibrary(XVID_DLL_NAME);          m_hdll = LoadLibrary(XVID_DLL_NAME);
272          if (m_hdll == NULL) {          if (m_hdll == NULL) {
273                  DPRINTF("dll load failed");                  DPRINTF("dll load failed");
274                  MessageBox(0, XVID_DLL_NAME " not found","Error", 0);                  MessageBox(0, XVID_DLL_NAME " not found","Error", MB_TOPMOST);
275                  return;                  return E_FAIL;
276          }          }
277    
278          xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global");          xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global");
279          if (xvid_global_func == NULL) {          if (xvid_global_func == NULL) {
280                  MessageBox(0, "xvid_global() not found", "Error", 0);          FreeLibrary(m_hdll);
281                  return;          m_hdll = NULL;
282                    MessageBox(0, "xvid_global() not found", "Error", MB_TOPMOST);
283                    return E_FAIL;
284          }          }
285    
286          xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore");          xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore");
287          if (xvid_decore_func == NULL) {          if (xvid_decore_func == NULL) {
288                  MessageBox(0, "xvid_decore() not found", "Error", 0);          xvid_global_func = NULL;
289                  return;          FreeLibrary(m_hdll);
290            m_hdll = NULL;
291                    MessageBox(0, "xvid_decore() not found", "Error", MB_TOPMOST);
292                    return E_FAIL;
293          }          }
294    
295          if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0)          if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0)
296          {          {
297                  MessageBox(0, "xvid_global() failed", "Error", 0);          xvid_global_func = NULL;
298                  return;          xvid_decore_func = NULL;
299            FreeLibrary(m_hdll);
300            m_hdll = NULL;
301                    MessageBox(0, "xvid_global() failed", "Error", MB_TOPMOST);
302                    return E_FAIL;
303          }          }
304    
305          memset(&m_create, 0, sizeof(m_create));          memset(&m_create, 0, sizeof(m_create));
# Line 246  Line 309 
309          memset(&m_frame, 0, sizeof(m_frame));          memset(&m_frame, 0, sizeof(m_frame));
310          m_frame.version = XVID_VERSION;          m_frame.version = XVID_VERSION;
311    
         LoadRegistryInfo();  
   
312          USE_IYUV = false;          USE_IYUV = false;
313          USE_YV12 = false;          USE_YV12 = false;
314          USE_YUY2 = false;          USE_YUY2 = false;
# Line 285  Line 346 
346                  USE_RGB32 = true;                  USE_RGB32 = true;
347                  break;                  break;
348          }          }
 }  
   
349    
350            switch (g_config.aspect_ratio)
351            {
352            case 0:
353            case 1:
354                    break;
355            case 2:
356                    ar_x = 4;
357                    ar_y = 3;
358                    break;
359            case 3:
360                    ar_x = 16;
361                    ar_y = 9;
362                    break;
363            case 4:
364                    ar_x = 47;
365                    ar_y = 20;
366                    break;
367            }
368    
369  /* destructor */          return S_OK;
370    }
371    
372  CXvidDecoder::~CXvidDecoder()  void CXvidDecoder::CloseLib()
373  {  {
374          DPRINTF("Destructor");          DPRINTF("CloseLib");
375    
376          if (m_create.handle != NULL)          if ((m_create.handle != NULL) && (xvid_decore_func != NULL))
377          {          {
378                  xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0);                  xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0);
379                  m_create.handle = NULL;                  m_create.handle = NULL;
380          }          }
381    
382          if (m_hdll != NULL)          if (m_hdll != NULL) {
         {  
383                  FreeLibrary(m_hdll);                  FreeLibrary(m_hdll);
384                  m_hdll = NULL;                  m_hdll = NULL;
385          }          }
386        xvid_decore_func = NULL;
387        xvid_global_func = NULL;
388    }
389    
390    /* destructor */
391    
392    CXvidDecoder::~CXvidDecoder()
393    {
394        DPRINTF("Destructor");
395            CloseLib();
396    
397    #ifdef XVID_USE_TRAYICON
398            if (MSG_hwnd != NULL) {
399                    NOTIFYICONDATA nid;
400                    nid.cbSize = sizeof(NOTIFYICONDATA);
401                    nid.hWnd = MSG_hwnd;
402                    nid.uID = 100;
403    
404                    Shell_NotifyIcon(NIM_DELETE, &nid);
405    
406                    DestroyWindow(MSG_hwnd);
407                    MSG_hwnd = NULL;
408            }
409    #endif
410  }  }
411    
412    
# Line 317  Line 418 
418          DPRINTF("CheckInputType");          DPRINTF("CheckInputType");
419          BITMAPINFOHEADER * hdr;          BITMAPINFOHEADER * hdr;
420    
421            ar_x = ar_y = 0;
422    
423          if (*mtIn->Type() != MEDIATYPE_Video)          if (*mtIn->Type() != MEDIATYPE_Video)
424          {          {
425                  DPRINTF("Error: Unknown Type");                  DPRINTF("Error: Unknown Type");
426                    CloseLib();
427                    return VFW_E_TYPE_NOT_ACCEPTED;
428            }
429    
430        if (m_hdll == NULL)
431        {
432                    HRESULT hr = OpenLib();
433    
434            if (FAILED(hr) || (m_hdll == NULL)) // Paranoid checks.
435                  return VFW_E_TYPE_NOT_ACCEPTED;                  return VFW_E_TYPE_NOT_ACCEPTED;
436          }          }
437    
# Line 327  Line 439 
439          {          {
440                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format();                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format();
441                  hdr = &vih->bmiHeader;                  hdr = &vih->bmiHeader;
                 /* PAR (x:y) is (1/ppm_X):(1/ppm_Y) where ppm is pixels-per-meter  
                    which is equal to ppm_Y:ppm_X */  
                 ar_x = vih->bmiHeader.biYPelsPerMeter * abs(hdr->biWidth);  
                 ar_y = vih->bmiHeader.biXPelsPerMeter * abs(hdr->biHeight);  
                 DPRINTF("VIDEOINFOHEADER PAR: %d:%d -> AR %d:%d",  
                         vih->bmiHeader.biYPelsPerMeter,vih->bmiHeader.biXPelsPerMeter, ar_x, ar_y);  
442          }          }
443          else if (*mtIn->FormatType() == FORMAT_VideoInfo2)          else if (*mtIn->FormatType() == FORMAT_VideoInfo2)
444          {          {
445                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format();                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format();
446                  hdr = &vih2->bmiHeader;                  hdr = &vih2->bmiHeader;
447                    if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) {
448                  ar_x = vih2->dwPictAspectRatioX;                  ar_x = vih2->dwPictAspectRatioX;
449                  ar_y = vih2->dwPictAspectRatioY;                  ar_y = vih2->dwPictAspectRatioY;
450                    }
451                  DPRINTF("VIDEOINFOHEADER2 AR: %d:%d", ar_x, ar_y);                  DPRINTF("VIDEOINFOHEADER2 AR: %d:%d", ar_x, ar_y);
452          }          }
453      else if (*mtIn->FormatType() == FORMAT_MPEG2Video) {
454        MPEG2VIDEOINFO * mpgvi = (MPEG2VIDEOINFO*)mtIn->Format();
455        VIDEOINFOHEADER2 * vih2 = &mpgvi->hdr;
456                    hdr = &vih2->bmiHeader;
457                    if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) {
458                            ar_x = vih2->dwPictAspectRatioX;
459                            ar_y = vih2->dwPictAspectRatioY;
460                    }
461                    DPRINTF("VIDEOINFOHEADER2 AR: %d:%d", ar_x, ar_y);
462    
463        /* haali media splitter reports VOL information in the format header */
464    
465        if (mpgvi->cbSequenceHeader>0) {
466    
467          xvid_dec_stats_t stats;
468                memset(&stats, 0, sizeof(stats));
469                stats.version = XVID_VERSION;
470    
471                if (m_create.handle == NULL) {
472                        if (xvid_decore_func == NULL)
473                                return E_FAIL;
474                        if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0) {
475              DPRINTF("*** XVID_DEC_CREATE error");
476                                return E_FAIL;
477                        }
478                }
479    
480          m_frame.general = 0;
481          m_frame.bitstream = (void*)mpgvi->dwSequenceHeader;
482          m_frame.length = mpgvi->cbSequenceHeader;
483          m_frame.output.csp = XVID_CSP_NULL;
484    
485          int ret = 0;
486          if ((ret=xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats)) >= 0) {
487            /* honour video dimensions reported in VOL header */
488                  if (stats.type == XVID_TYPE_VOL) {
489              hdr->biWidth = stats.data.vol.width;
490              hdr->biHeight = stats.data.vol.height;
491            }
492          }
493          if (ret == XVID_ERR_MEMORY) return E_FAIL;
494        }
495      }
496          else          else
497          {          {
498                  DPRINTF("Error: Unknown FormatType");                  DPRINTF("Error: Unknown FormatType");
499                    CloseLib();
500                  return VFW_E_TYPE_NOT_ACCEPTED;                  return VFW_E_TYPE_NOT_ACCEPTED;
501          }          }
502    
# Line 358  Line 510 
510    
511          switch(hdr->biCompression)          switch(hdr->biCompression)
512          {          {
513      case FOURCC_mp4v:
514          case FOURCC_MP4V:          case FOURCC_MP4V:
515                  if (!(g_config.supported_4cc & SUPPORT_MP4V)) return VFW_E_TYPE_NOT_ACCEPTED;                  if (!(g_config.supported_4cc & SUPPORT_MP4V)) {
516                            CloseLib();
517                            return VFW_E_TYPE_NOT_ACCEPTED;
518                    }
519                  break;                  break;
520          case FOURCC_DIVX :          case FOURCC_DIVX :
521                  if (!(g_config.supported_4cc & SUPPORT_DIVX)) return VFW_E_TYPE_NOT_ACCEPTED;                  if (!(g_config.supported_4cc & SUPPORT_DIVX)) {
522                            CloseLib();
523                            return VFW_E_TYPE_NOT_ACCEPTED;
524                    }
525                  break;                  break;
526          case FOURCC_DX50 :          case FOURCC_DX50 :
527                  if (!(g_config.supported_4cc & SUPPORT_DX50)) return VFW_E_TYPE_NOT_ACCEPTED;                  if (!(g_config.supported_4cc & SUPPORT_DX50)) {
528                            CloseLib();
529                            return VFW_E_TYPE_NOT_ACCEPTED;
530                    }
531          case FOURCC_XVID :          case FOURCC_XVID :
532                  break;                  break;
533    
# Line 378  Line 539 
539                          (hdr->biCompression>>8)&0xff,                          (hdr->biCompression>>8)&0xff,
540                          (hdr->biCompression>>16)&0xff,                          (hdr->biCompression>>16)&0xff,
541                          (hdr->biCompression>>24)&0xff);                          (hdr->biCompression>>24)&0xff);
542                    CloseLib();
543                  return VFW_E_TYPE_NOT_ACCEPTED;                  return VFW_E_TYPE_NOT_ACCEPTED;
544          }          }
545    
546            m_create.fourcc = hdr->biCompression;
547    
548          return S_OK;          return S_OK;
549  }  }
550    
# Line 408  Line 573 
573                  if (ar_x != 0 && ar_y != 0) {                  if (ar_x != 0 && ar_y != 0) {
574                          vih->dwPictAspectRatioX = ar_x;                          vih->dwPictAspectRatioX = ar_x;
575                          vih->dwPictAspectRatioY = ar_y;                          vih->dwPictAspectRatioY = ar_y;
576                            forced_ar = true;
577                  } else { // just to be safe                  } else { // just to be safe
578                          vih->dwPictAspectRatioX = m_create.width;                          vih->dwPictAspectRatioX = m_create.width;
579                          vih->dwPictAspectRatioY = abs(m_create.height);                          vih->dwPictAspectRatioY = abs(m_create.height);
580                            forced_ar = false;
581                  }                  }
   
582          } else {          } else {
583    
584                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER));                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER));
# Line 520  Line 686 
686    
687    
688  /* (internal function) change colorspace */  /* (internal function) change colorspace */
689    #define CALC_BI_STRIDE(width,bitcount)  ((((width * bitcount) + 31) & ~31) >> 3)
690    
691  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)
692  {  {
693            DWORD biWidth;
694    
695          if (formattype == FORMAT_VideoInfo)          if (formattype == FORMAT_VideoInfo)
696          {          {
697                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;
698                  m_frame.output.stride[0] = (((vih->bmiHeader.biWidth * vih->bmiHeader.biBitCount) + 31) & ~31) >> 3;                  biWidth = vih->bmiHeader.biWidth;
699                    m_frame.output.stride[0] = CALC_BI_STRIDE(vih->bmiHeader.biWidth, vih->bmiHeader.biBitCount);
700                  rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP);                  rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP);
701          }          }
702          else if (formattype == FORMAT_VideoInfo2)          else if (formattype == FORMAT_VideoInfo2)
703          {          {
704                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format;                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format;
705                  m_frame.output.stride[0] = (((vih2->bmiHeader.biWidth * vih2->bmiHeader.biBitCount) + 31) & ~31) >> 3;                  biWidth = vih2->bmiHeader.biWidth;
706                    m_frame.output.stride[0] = CALC_BI_STRIDE(vih2->bmiHeader.biWidth, vih2->bmiHeader.biBitCount);
707                  rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP);                  rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP);
708          }          }
709          else          else
# Line 545  Line 716 
716                  DPRINTF("IYUV");                  DPRINTF("IYUV");
717                  rgb_flip = 0;                  rgb_flip = 0;
718                  m_frame.output.csp = XVID_CSP_I420;                  m_frame.output.csp = XVID_CSP_I420;
719                  m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3;  /* planar format fix */                  m_frame.output.stride[0] = CALC_BI_STRIDE(biWidth, 8);  /* planar format fix */
720          }          }
721          else if (subtype == MEDIASUBTYPE_YV12)          else if (subtype == MEDIASUBTYPE_YV12)
722          {          {
723                  DPRINTF("YV12");                  DPRINTF("YV12");
724                  rgb_flip = 0;                  rgb_flip = 0;
725                  m_frame.output.csp = XVID_CSP_YV12;                  m_frame.output.csp = XVID_CSP_YV12;
726                  m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3;  /* planar format fix */                  m_frame.output.stride[0] = CALC_BI_STRIDE(biWidth, 8);  /* planar format fix */
727          }          }
728          else if (subtype == MEDIASUBTYPE_YUY2)          else if (subtype == MEDIASUBTYPE_YUY2)
729          {          {
# Line 625  Line 796 
796  HRESULT CXvidDecoder::CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut)  HRESULT CXvidDecoder::CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut)
797  {  {
798          DPRINTF("CheckTransform");          DPRINTF("CheckTransform");
799    
800            return S_OK;
801    }
802    
803    /* input/output pin connection complete */
804    
805    HRESULT CXvidDecoder::CompleteConnect(PIN_DIRECTION direction, IPin *pReceivePin)
806    {
807            DPRINTF("CompleteConnect");
808    
809    #ifdef XVID_USE_TRAYICON
810            if ((direction == PINDIR_OUTPUT) && (MSG_hwnd == NULL))
811            {
812                    WNDCLASSEX wc;
813    
814                    wc.cbSize = sizeof(WNDCLASSEX);
815                    wc.lpfnWndProc = msg_proc;
816                    wc.style = CS_HREDRAW | CS_VREDRAW;
817                    wc.cbWndExtra = 0;
818                    wc.cbClsExtra = 0;
819                    wc.hInstance = (HINSTANCE) g_xvid_hInst;
820                    wc.hbrBackground = (HBRUSH) GetStockObject(NULL_BRUSH);
821                    wc.lpszMenuName = NULL;
822                    wc.lpszClassName = "XVID_MSG_WINDOW";
823                    wc.hIcon = NULL;
824                    wc.hIconSm = NULL;
825                    wc.hCursor = NULL;
826                    RegisterClassEx(&wc);
827    
828                    MSG_hwnd = CreateWindowEx(0, "XVID_MSG_WINDOW", NULL, 0, CW_USEDEFAULT,
829                                      CW_USEDEFAULT, 0, 0, HWND_MESSAGE, NULL, (HINSTANCE) g_xvid_hInst, NULL);
830    
831                    /* display the tray icon */
832                    NOTIFYICONDATA nid;
833    
834                    nid.cbSize = sizeof(NOTIFYICONDATA);
835                    nid.hWnd = MSG_hwnd;
836                    nid.uID = 100;
837                    nid.uVersion = NOTIFYICON_VERSION;
838                    nid.uCallbackMessage = WM_ICONMESSAGE;
839                    nid.hIcon = LoadIcon(g_xvid_hInst, MAKEINTRESOURCE(IDI_ICON));
840                    strcpy_s(nid.szTip, 19, "Xvid Video Decoder");
841                    nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
842    
843                    Shell_NotifyIcon(NIM_ADD, &nid);
844            }
845    #endif
846    
847          return S_OK;          return S_OK;
848  }  }
849    
850    /* input/output pin disconnected */
851    HRESULT CXvidDecoder::BreakConnect(PIN_DIRECTION direction)
852    {
853            DPRINTF("BreakConnect");
854    
855    #ifdef XVID_USE_TRAYICON
856            if ((direction == PINDIR_OUTPUT) && (MSG_hwnd != NULL)) {
857                    NOTIFYICONDATA nid;
858    
859                    nid.cbSize = sizeof(NOTIFYICONDATA);
860                    nid.hWnd = MSG_hwnd;
861                    nid.uID = 100;
862                    nid.uVersion = NOTIFYICON_VERSION;
863    
864                    if(Shell_NotifyIcon(NIM_DELETE, &nid) == TRUE) {
865                            DestroyWindow(MSG_hwnd);
866                            MSG_hwnd = NULL;
867                    }
868            }
869    #endif
870    
871            return S_OK;
872    }
873    
874  /* alloc output buffer */  /* alloc output buffer */
875    
# Line 676  Line 918 
918    
919          if (m_create.handle == NULL)          if (m_create.handle == NULL)
920          {          {
921                    if (xvid_decore_func == NULL)
922                            return E_FAIL;
923    
924                  if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0)                  if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0)
925                  {                  {
926              DPRINTF("*** XVID_DEC_CREATE error");              DPRINTF("*** XVID_DEC_CREATE error");
927                          return S_FALSE;                          return E_FAIL;
928                  }                  }
929          }          }
930    
# Line 720  Line 965 
965    
966          if (g_config.nDeblock_UV)          if (g_config.nDeblock_UV)
967                  m_frame.general |= XVID_DEBLOCKUV;                  m_frame.general |= XVID_DEBLOCKUV;
968  /*  
969          if (g_config.nDering)          if (g_config.nDering_Y)
970                  m_frame.general |= XVID_DERING;                  m_frame.general |= XVID_DERINGY;
971  */  
972            if (g_config.nDering_UV)
973                    m_frame.general |= XVID_DERINGUV;
974    
975          if (g_config.nFilmEffect)          if (g_config.nFilmEffect)
976                  m_frame.general |= XVID_FILMEFFECT;                  m_frame.general |= XVID_FILMEFFECT;
977    
# Line 732  Line 980 
980          m_frame.output.csp &= ~XVID_CSP_VFLIP;          m_frame.output.csp &= ~XVID_CSP_VFLIP;
981          m_frame.output.csp |= rgb_flip^(g_config.nFlipVideo ? XVID_CSP_VFLIP : 0);          m_frame.output.csp |= rgb_flip^(g_config.nFlipVideo ? XVID_CSP_VFLIP : 0);
982    
983        // Paranoid check.
984        if (xvid_decore_func == NULL)
985                    return E_FAIL;
986    
987    
988    
989  repeat :  repeat :
990    
991          if (pIn->IsPreroll() != S_OK)          if (pIn->IsPreroll() != S_OK)
992          {          {
993                  length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);                  length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);
994    
995                  if (length < 0)                  if (length == XVID_ERR_MEMORY)
996                            return E_FAIL;
997                    else if (length < 0)
998                  {                  {
999              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
1000                          return S_FALSE;                          return S_FALSE;
1001                    } else
1002                            if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1 && forced_ar == false) {
1003    
1004          if (stats.type != XVID_TYPE_NOTHING) {  /* dont attempt to set vmr aspect ratio if no frame was returned by decoder */
1005                            // inspired by minolta! works for VMR 7 + 9
1006                            IMediaSample2 *pOut2 = NULL;
1007                            AM_SAMPLE2_PROPERTIES outProp2;
1008                            if (SUCCEEDED(pOut->QueryInterface(IID_IMediaSample2, (void **)&pOut2)) &&
1009                                    SUCCEEDED(pOut2->GetProperties(FIELD_OFFSET(AM_SAMPLE2_PROPERTIES, tStart), (PBYTE)&outProp2)))
1010                            {
1011                                    CMediaType mtOut2 = m_pOutput->CurrentMediaType();
1012                                    VIDEOINFOHEADER2* vihOut2 = (VIDEOINFOHEADER2*)mtOut2.Format();
1013    
1014                                    if (*mtOut2.FormatType() == FORMAT_VideoInfo2 &&
1015                                            vihOut2->dwPictAspectRatioX != ar_x && vihOut2->dwPictAspectRatioY != ar_y)
1016                                    {
1017                                            vihOut2->dwPictAspectRatioX = ar_x;
1018                                            vihOut2->dwPictAspectRatioY = ar_y;
1019                                            pOut2->SetMediaType(&mtOut2);
1020                                            m_pOutput->SetMediaType(&mtOut2);
1021                                    }
1022                                    pOut2->Release();
1023                            }
1024          }
1025                  }                  }
1026          }          }
1027          else          else
# Line 758  Line 1038 
1038                  m_frame.general &= ~XVID_FILMEFFECT;                  m_frame.general &= ~XVID_FILMEFFECT;
1039    
1040                  length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);                  length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);
1041                  if (length < 0)                  if (length == XVID_ERR_MEMORY)
1042                            return E_FAIL;
1043                    else if (length < 0)
1044                  {                  {
1045              DPRINTF("*** XVID_DEC_DECODE");              DPRINTF("*** XVID_DEC_DECODE");
1046                          return S_FALSE;                          return S_FALSE;
# Line 783  Line 1065 
1065                          return S_FALSE;                          return S_FALSE;
1066                  }                  }
1067    
 //              pOut->SetDiscontinuity(TRUE);  
1068                  pOut->SetSyncPoint(TRUE);                  pOut->SetSyncPoint(TRUE);
1069    
1070                    if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) { /* auto */
1071                            int par_x, par_y;
1072                            if (stats.data.vol.par == XVID_PAR_EXT) {
1073                                    par_x = stats.data.vol.par_width;
1074                                    par_y = stats.data.vol.par_height;
1075                            } else {
1076                                    par_x = PARS[stats.data.vol.par-1][0];
1077                                    par_y = PARS[stats.data.vol.par-1][1];
1078                            }
1079    
1080                            ar_x = par_x * stats.data.vol.width;
1081                            ar_y = par_y * stats.data.vol.height;
1082                    }
1083    
1084                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;
1085                  m_frame.length -= length;                  m_frame.length -= length;
1086                  goto repeat;                  goto repeat;

Legend:
Removed from v.1427  
changed lines
  Added in v.1896

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