[svn] / branches / release-1_3-branch / xvidcore / dshow / src / CXvidDecoder.cpp Repository:
ViewVC logotype

Diff of /branches/release-1_3-branch/xvidcore/dshow/src/CXvidDecoder.cpp

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

revision 1558, Mon Oct 25 10:29:10 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.13 2004-10-25 10:29:10 suxen_drol Exp $   * $Id: CXvidDecoder.cpp,v 1.19 2010-10-16 12:20:30 Isibaar Exp $
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
# Line 43  Line 44 
44          C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\Debug          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;
# Line 216  Line 272 
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", MB_TOPMOST);                  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            FreeLibrary(m_hdll);
281            m_hdll = NULL;
282                  MessageBox(0, "xvid_global() not found", "Error", MB_TOPMOST);                  MessageBox(0, "xvid_global() not found", "Error", MB_TOPMOST);
283                  return;                  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            xvid_global_func = NULL;
289            FreeLibrary(m_hdll);
290            m_hdll = NULL;
291                  MessageBox(0, "xvid_decore() not found", "Error", MB_TOPMOST);                  MessageBox(0, "xvid_decore() not found", "Error", MB_TOPMOST);
292                  return;                  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            xvid_global_func = NULL;
298            xvid_decore_func = NULL;
299            FreeLibrary(m_hdll);
300            m_hdll = NULL;
301                  MessageBox(0, "xvid_global() failed", "Error", MB_TOPMOST);                  MessageBox(0, "xvid_global() failed", "Error", MB_TOPMOST);
302                  return;                  return E_FAIL;
303          }          }
304    
305          memset(&m_create, 0, sizeof(m_create));          memset(&m_create, 0, sizeof(m_create));
# Line 244  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 302  Line 365 
365                  ar_y = 20;                  ar_y = 20;
366                  break;                  break;
367          }          }
368    
369            return S_OK;
370  }  }
371    
372  void CXvidDecoder::CloseLib()  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          }          }
# Line 317  Line 383 
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 */  /* destructor */
391    
392  CXvidDecoder::~CXvidDecoder()  CXvidDecoder::~CXvidDecoder()
393  {  {
394        DPRINTF("Destructor");
395          CloseLib();          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 344  Line 427 
427                  return VFW_E_TYPE_NOT_ACCEPTED;                  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;
436        }
437    
438          if (*mtIn->FormatType() == FORMAT_VideoInfo)          if (*mtIn->FormatType() == FORMAT_VideoInfo)
439          {          {
440                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format();                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format();
# Line 359  Line 450 
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");
# Line 376  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)) {                  if (!(g_config.supported_4cc & SUPPORT_MP4V)) {
516                          CloseLib();                          CloseLib();
# Line 408  Line 542 
542                  CloseLib();                  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 659  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;          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;
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 710  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 769  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    
# Line 778  Line 992 
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                  } else
1002                          if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1 && forced_ar == false) {                          if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1 && forced_ar == false) {
                         // inspired by minolta! works for VMR 7 + 9  
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;                          IMediaSample2 *pOut2 = NULL;
1007                          AM_SAMPLE2_PROPERTIES outProp2;                          AM_SAMPLE2_PROPERTIES outProp2;
1008                          if (SUCCEEDED(pOut->QueryInterface(IID_IMediaSample2, (void **)&pOut2)) &&                          if (SUCCEEDED(pOut->QueryInterface(IID_IMediaSample2, (void **)&pOut2)) &&
# Line 806  Line 1023 
1023                          }                          }
1024                  }                  }
1025          }          }
1026            }
1027          else          else
1028          {       /* Preroll frame - won't be displayed */          {       /* Preroll frame - won't be displayed */
1029                  int tmp = m_frame.output.csp;                  int tmp = m_frame.output.csp;
# Line 820  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;

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

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