[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 2003, Thu May 19 12:24:11 2011 UTC revision 2131, Fri Jan 8 17:44:53 2016 UTC
# Line 4  Line 4 
4   *  - Xvid Decoder part of the DShow Filter  -   *  - Xvid Decoder part of the DShow Filter  -
5   *   *
6   *  Copyright(C) 2002-2011 Peter Ross <pross@xvid.org>   *  Copyright(C) 2002-2011 Peter Ross <pross@xvid.org>
7   *               2003-2011 Michael Militzer <michael@xvid.org>   *               2003-2012 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 20  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.25.2.4 2011-03-17 15:13:25 Isibaar Exp $   * $Id$
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
# Line 40  Line 40 
40  #define XVID_USE_MFT  #define XVID_USE_MFT
41  #endif  #endif
42    
 #define XVID_USE_TRAYICON  
   
43  #include <windows.h>  #include <windows.h>
44    
45  #include <streams.h>  #include <streams.h>
# Line 177  Line 175 
175  /* 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) */
176  int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate);  int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate);
177    
 #ifdef XVID_USE_TRAYICON  
178  extern HINSTANCE g_xvid_hInst;  extern HINSTANCE g_xvid_hInst;
179    
180  static int GUI_Page = 0;  static int GUI_Page = 0;
181  static int Tray_Icon = 0;  static HWND MSG_hwnd = NULL; /* message handler window */
182    
183  extern "C" void CALLBACK Configure(HWND hWndParent, HINSTANCE hInstParent, LPSTR lpCmdLine, int nCmdShow );  extern "C" void CALLBACK Configure(HWND hWndParent, HINSTANCE hInstParent, LPSTR lpCmdLine, int nCmdShow );
184    
185  LRESULT CALLBACK msg_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)  LRESULT CALLBACK msg_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
# Line 191  Line 189 
189          case WM_ICONMESSAGE:          case WM_ICONMESSAGE:
190                  switch(lParam)                  switch(lParam)
191                  {                  {
192                    case WM_LBUTTONUP:
193                  case WM_LBUTTONDBLCLK:                  case WM_LBUTTONDBLCLK:
194                          if (!GUI_Page) {                          if (!GUI_Page) {
195                                  GUI_Page = 1;                                  GUI_Page = 1;
# Line 207  Line 206 
206                  NOTIFYICONDATA nid;                  NOTIFYICONDATA nid;
207                  ZeroMemory(&nid,sizeof(NOTIFYICONDATA));                  ZeroMemory(&nid,sizeof(NOTIFYICONDATA));
208    
209                  nid.cbSize = NOTIFYICONDATA_V1_SIZE;                  nid.cbSize = sizeof(NOTIFYICONDATA);
210                  nid.hWnd = hwnd;                  nid.hWnd = hwnd;
211                  nid.uID = 1456;                  nid.uID = 1456;
   
212                  Shell_NotifyIcon(NIM_DELETE, &nid);                  Shell_NotifyIcon(NIM_DELETE, &nid);
                 Tray_Icon = 0;  
213          default:          default:
214                  return DefWindowProc(hwnd, uMsg, wParam, lParam);                  return DefWindowProc(hwnd, uMsg, wParam, lParam);
215          }          }
216    
217          return TRUE; /* ok */          return TRUE; /* ok */
218  }  }
 #endif  
219    
220  STDAPI DllRegisterServer()  STDAPI DllRegisterServer()
221  {  {
# Line 244  Line 240 
240          /* Register the MFT decoder */          /* Register the MFT decoder */
241          MFTRegister(CLSID_XVID,                          // CLSID          MFTRegister(CLSID_XVID,                          // CLSID
242                          MFT_CATEGORY_VIDEO_DECODER,          // Category                          MFT_CATEGORY_VIDEO_DECODER,          // Category
243                          const_cast<LPWSTR>(XVID_NAME_L),     // Friendly name                                  const_cast<LPWSTR>(XVID_NAME_MFT_L), // Friendly name
244                          0,                                   // Flags                          0,                                   // Flags
245                          inputs_num,                          // Number of input types                          inputs_num,                          // Number of input types
246                          mft_bs,                              // Input types                          mft_bs,                              // Input types
# Line 321  Line 317 
317      xvid_decore_func = NULL; // Hmm, some strange errors appearing if I try to initialize...      xvid_decore_func = NULL; // Hmm, some strange errors appearing if I try to initialize...
318      xvid_global_func = NULL; // ...this in constructor's init-list. So, they assigned here.      xvid_global_func = NULL; // ...this in constructor's init-list. So, they assigned here.
319    
320            m_tray_icon = 0;
321            m_startClock = clock();
322            interlaced = 0;
323    
324  #if defined(XVID_USE_MFT)  #if defined(XVID_USE_MFT)
325          InitializeCriticalSection(&m_mft_lock);          InitializeCriticalSection(&m_mft_lock);
326          m_pInputType = NULL;          m_pInputType = NULL;
327          m_pOutputType = NULL;          m_pOutputType = NULL;
328            m_pOutputTypeBPP = 32;
329          m_rtFrame = 0;          m_rtFrame = 0;
330          m_duration = 0;          m_duration = 0;
331          m_discont = 0;          m_discont = 0;
332          m_frameRate.Denominator = 1;          m_frameRate.Denominator = 1;
333          m_frameRate.Numerator = 1;          m_frameRate.Numerator = 1;
334            m_thread_handle = NULL;
335  #endif  #endif
336    
337      LoadRegistryInfo();      LoadRegistryInfo();
338    
339      *phr = OpenLib();      *phr = OpenLib();
340    
341            {
342                    TCHAR lpFilename[MAX_PATH];
343                    int sLen = GetModuleFileName(NULL, lpFilename, MAX_PATH);
344    #ifdef _UNICODE
345                    if ((sLen >= 11) && (_wcsnicmp(&(lpFilename[sLen - 11]), TEXT("dllhost.exe"), 11) == 0)) {
346    #else
347                    if ((sLen >= 11) && (_strnicmp(&(lpFilename[sLen - 11]), TEXT("dllhost.exe"), 11) == 0)) {
348    #endif
349                            if (m_tray_icon == 0) m_tray_icon = -1; // create no tray icon upon thumbnail generation
350                    }
351            }
352    
353  }  }
354    
355  HRESULT CXvidDecoder::OpenLib()  HRESULT CXvidDecoder::OpenLib()
# Line 496  Line 511 
511  {  {
512      DPRINTF("Destructor");      DPRINTF("Destructor");
513    
514  #ifdef XVID_USE_TRAYICON          if ((MSG_hwnd != NULL) && (m_tray_icon == 1)) { /* Destroy tray icon */
515          if (Tray_Icon) { /* Destroy tray icon */                  SendMessage(MSG_hwnd, WM_CLOSE, 0, 0);
                 NOTIFYICONDATA nid;  
                 ZeroMemory(&nid,sizeof(NOTIFYICONDATA));  
   
                 nid.cbSize = NOTIFYICONDATA_V1_SIZE;  
                 nid.hWnd = MSG_hwnd;  
                 nid.uID = 1456;  
   
                 Shell_NotifyIcon(NIM_DELETE, &nid);  
                 Tray_Icon = 0;  
516          }          }
 #endif  
517    
518          /* Close xvidcore library */          /* Close xvidcore library */
519          CloseLib();          CloseLib();
520    
521            clock_t endClock = clock();
522            if (((endClock - m_startClock) / CLOCKS_PER_SEC) > 3) {
523                    SaveRegistryInfo((endClock - m_startClock) / (CLOCKS_PER_SEC / 10));
524            }
525    
526            if ((MSG_hwnd != 0) && (m_tray_icon == 1)) { /* Final clean-up */
527              MSG_hwnd = 0;
528              Sleep(200);
529              m_tray_icon = 0;
530    #if defined(XVID_USE_MFT)
531              if (m_thread_handle) {
532                      TerminateThread(m_thread_handle, 0);
533                      CloseHandle(m_thread_handle);
534                      m_thread_handle = NULL;
535              }
536    #endif
537            }
538    
539  #if defined(XVID_USE_MFT)  #if defined(XVID_USE_MFT)
540          DeleteCriticalSection(&m_mft_lock);          DeleteCriticalSection(&m_mft_lock);
541  #endif  #endif
# Line 706  Line 729 
729                          vih->dwPictAspectRatioY = abs(m_create.height);                          vih->dwPictAspectRatioY = abs(m_create.height);
730                          forced_ar = false;                          forced_ar = false;
731                  }                  }
732                    if (interlaced) {
733                            vih->dwInterlaceFlags = AMINTERLACE_IsInterlaced;
734                            if (interlaced > 1) {
735                                    vih->dwInterlaceFlags |= AMINTERLACE_Field1First;
736                            }
737                    }
738                    else {
739                            vih->dwInterlaceFlags = 0;
740                    }
741          } else {          } else {
742    
743                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER));                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER));
# Line 815  Line 847 
847  /* (internal function) change colorspace */  /* (internal function) change colorspace */
848  #define CALC_BI_STRIDE(width,bitcount)  ((((width * bitcount) + 31) & ~31) >> 3)  #define CALC_BI_STRIDE(width,bitcount)  ((((width * bitcount) + 31) & ~31) >> 3)
849    
850  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format, int noflip)  HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void *format, int *bitdepth, int noflip)
851  {  {
852          DWORD biWidth;          DWORD biWidth;
853            *bitdepth = 32;
854    
855          if (formattype == FORMAT_VideoInfo)          if (formattype == FORMAT_VideoInfo)
856          {          {
857                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;                  VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;
858                  biWidth = vih->bmiHeader.biWidth;                  biWidth = vih->bmiHeader.biWidth;
859                    *bitdepth = vih->bmiHeader.biBitCount;
860                  out_stride = CALC_BI_STRIDE(vih->bmiHeader.biWidth, vih->bmiHeader.biBitCount);                  out_stride = CALC_BI_STRIDE(vih->bmiHeader.biWidth, vih->bmiHeader.biBitCount);
861                  rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP);                  rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP);
862          }          }
# Line 830  Line 864 
864          {          {
865                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format;                  VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format;
866                  biWidth = vih2->bmiHeader.biWidth;                  biWidth = vih2->bmiHeader.biWidth;
867                    *bitdepth = vih2->bmiHeader.biBitCount;
868                  out_stride = CALC_BI_STRIDE(vih2->bmiHeader.biWidth, vih2->bmiHeader.biBitCount);                  out_stride = CALC_BI_STRIDE(vih2->bmiHeader.biWidth, vih2->bmiHeader.biBitCount);
869                  rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP);                  rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP);
870          }          }
# Line 909  Line 944 
944    
945  HRESULT CXvidDecoder::SetMediaType(PIN_DIRECTION direction, const CMediaType *pmt)  HRESULT CXvidDecoder::SetMediaType(PIN_DIRECTION direction, const CMediaType *pmt)
946  {  {
947            int bitdepth;
948          DPRINTF("SetMediaType");          DPRINTF("SetMediaType");
949    
950          if (direction == PINDIR_OUTPUT)          if (direction == PINDIR_OUTPUT)
951          {          {
952                  return ChangeColorspace(*pmt->Subtype(), *pmt->FormatType(), pmt->Format(), 0);                  return ChangeColorspace(*pmt->Subtype(), *pmt->FormatType(), pmt->Format(), &bitdepth, 0);
953          }          }
954    
955          return S_OK;          return S_OK;
# Line 935  Line 971 
971  {  {
972          DPRINTF("CompleteConnect");          DPRINTF("CompleteConnect");
973    
974  #ifdef XVID_USE_TRAYICON          if ((direction == PINDIR_OUTPUT) && (MSG_hwnd == 0) && (m_tray_icon == 0) && (g_config.bTrayIcon != 0))
         if ((direction == PINDIR_OUTPUT) && (Tray_Icon == 0))  
975          {          {
976                  WNDCLASSEX wc;                  WNDCLASSEX wc;
977    
# Line 961  Line 996 
996                  NOTIFYICONDATA nid;                  NOTIFYICONDATA nid;
997                  ZeroMemory(&nid,sizeof(NOTIFYICONDATA));                  ZeroMemory(&nid,sizeof(NOTIFYICONDATA));
998    
999                  nid.cbSize = NOTIFYICONDATA_V1_SIZE;                  nid.cbSize = sizeof(NOTIFYICONDATA);
1000                  nid.hWnd = MSG_hwnd;                  nid.hWnd = MSG_hwnd;
1001                  nid.uID = 1456;                  nid.uID = 1456;
1002                    nid.uVersion = NOTIFYICON_VERSION;
1003                  nid.uCallbackMessage = WM_ICONMESSAGE;                  nid.uCallbackMessage = WM_ICONMESSAGE;
1004                  nid.hIcon = LoadIcon(g_xvid_hInst, MAKEINTRESOURCE(IDI_ICON));                  nid.hIcon = LoadIcon(g_xvid_hInst, MAKEINTRESOURCE(IDI_ICON));
1005                  strcpy_s(nid.szTip, 19, "Xvid Video Decoder");                  strcpy_s(nid.szTip, 19, "Xvid Video Decoder");
1006                  nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;                  nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_SHOWTIP;
1007    
1008                  Shell_NotifyIcon(NIM_ADD, &nid);                  Shell_NotifyIcon(NIM_ADD, &nid);
1009                    Shell_NotifyIcon(NIM_SETVERSION, &nid);
1010    
1011                  DestroyIcon(nid.hIcon);                  DestroyIcon(nid.hIcon);
1012                  Tray_Icon = 1;                  m_tray_icon = 1;
1013          }          }
 #endif  
1014    
1015          return S_OK;          return S_OK;
1016  }  }
# Line 1048  Line 1084 
1084          pOut->GetMediaType(&mtOut);          pOut->GetMediaType(&mtOut);
1085          if (mtOut != NULL)          if (mtOut != NULL)
1086          {          {
1087                    int bitdepth;
1088                  HRESULT result;                  HRESULT result;
1089    
1090                  result = ChangeColorspace(mtOut->subtype, mtOut->formattype, mtOut->pbFormat, 0);                  result = ChangeColorspace(mtOut->subtype, mtOut->formattype, mtOut->pbFormat, &bitdepth, 0);
1091                  DeleteMediaType(mtOut);                  DeleteMediaType(mtOut);
1092    
1093                  if (result != S_OK)                  if (result != S_OK)
# Line 1132  Line 1169 
1169                                  {                                  {
1170                                          vihOut2->dwPictAspectRatioX = ar_x;                                          vihOut2->dwPictAspectRatioX = ar_x;
1171                                          vihOut2->dwPictAspectRatioY = ar_y;                                          vihOut2->dwPictAspectRatioY = ar_y;
1172                                            if (interlaced) {
1173                                                    vihOut2->dwInterlaceFlags = AMINTERLACE_IsInterlaced;
1174                                                    if (interlaced > 2) {
1175                                                            vihOut2->dwInterlaceFlags |= AMINTERLACE_Field1First;
1176                                                    }
1177                                            }
1178                                            else {
1179                                                    vihOut2->dwInterlaceFlags = 0;
1180                                            }
1181                                          pOut2->SetMediaType(&mtOut2);                                          pOut2->SetMediaType(&mtOut2);
1182                                          m_pOutput->SetMediaType(&mtOut2);                                          m_pOutput->SetMediaType(&mtOut2);
1183                                  }                                  }
# Line 1320  Line 1366 
1366                  pStreamInfo->cbAlignment = 0;                  pStreamInfo->cbAlignment = 0;
1367          }          }
1368          else {          else {
1369                  pStreamInfo->cbSize = m_create.width * abs(m_create.height) * 4; // XXX                  pStreamInfo->cbSize = (m_create.width * abs(m_create.height) * m_pOutputTypeBPP) >> 3;
1370                  pStreamInfo->cbAlignment = 1;                  pStreamInfo->cbAlignment = 1;
1371          }          }
1372    
# Line 1366  Line 1412 
1412                  return MF_E_INVALIDSTREAMNUMBER;                  return MF_E_INVALIDSTREAMNUMBER;
1413    
1414          DWORD i = 0;          DWORD i = 0;
1415          GUID *bs_guid_table[8];          GUID *bs_guid_table[32];
1416    
1417          bs_guid_table[i++] = (GUID *)&CLSID_XVID;          bs_guid_table[i++] = (GUID *)&CLSID_XVID;
1418          bs_guid_table[i++] = (GUID *)&CLSID_XVID_UC;          bs_guid_table[i++] = (GUID *)&CLSID_XVID_UC;
# Line 1458  Line 1504 
1504                  break;                  break;
1505  }  }
1506          case 1 :          case 1 :
1507    if ( USE_YVYU )
1508    {
1509                csp = MFVideoFormat_YVYU;
1510                bitdepth = 4;
1511                break;
1512    }
1513            case 2 :
1514  if ( USE_UYVY )  if ( USE_UYVY )
1515  {  {
1516                  csp = MFVideoFormat_UYVY;                  csp = MFVideoFormat_UYVY;
1517                  bitdepth = 4;                  bitdepth = 4;
1518                  break;                  break;
1519  }  }
1520          case 2  :          case 3  :
1521                  if ( USE_IYUV )                  if ( USE_IYUV )
1522  {  {
1523                  csp = MFVideoFormat_IYUV;                  csp = MFVideoFormat_IYUV;
1524                  bitdepth = 3;                  bitdepth = 3;
1525                  break;                  break;
1526  }  }
1527          case 3  :          case 4  :
1528  if ( USE_YV12 )  if ( USE_YV12 )
1529  {  {
1530                  csp = MFVideoFormat_YV12;                  csp = MFVideoFormat_YV12;
1531                  bitdepth = 3;                  bitdepth = 3;
1532                  break;                  break;
1533  }  }
1534          case 4 :          case 5 :
1535  if ( USE_RGB32 )  if ( USE_RGB32 )
1536  {  {
1537                  csp = MFVideoFormat_RGB32;                  csp = MFVideoFormat_RGB32;
1538                  bitdepth = 8;                  bitdepth = 8;
1539                  break;                  break;
1540  }  }
1541          case 5 :          case 6 :
1542  if ( USE_RGB24 )  if ( USE_RGB24 )
1543  {  {
1544                  csp = MFVideoFormat_RGB24;                  csp = MFVideoFormat_RGB24;
1545                  bitdepth = 6;                  bitdepth = 6;
1546                  break;                  break;
1547  }  }
1548          case 6 :          case 7 :
1549  if ( USE_RG555 )  if ( USE_RG555 )
1550  {  {
1551                  csp = MFVideoFormat_RGB555;                  csp = MFVideoFormat_RGB555;
1552                  bitdepth = 4;                  bitdepth = 4;
1553                  break;                  break;
1554  }  }
1555          case 7 :          case 8 :
1556  if ( USE_RG565 )  if ( USE_RG565 )
1557  {  {
1558                  csp = MFVideoFormat_RGB565;                  csp = MFVideoFormat_RGB565;
# Line 1537  Line 1590 
1590          }          }
1591    
1592          if (SUCCEEDED(hr)) {          if (SUCCEEDED(hr)) {
1593                  hr = pOutputType->SetUINT32(MF_MT_SAMPLE_SIZE, (m_create.height * m_create.width * bitdepth)>>1);                  hr = pOutputType->SetUINT32(MF_MT_SAMPLE_SIZE, (abs(m_create.height) * m_create.width * bitdepth) >> 1);
1594          }          }
1595    
1596          if (SUCCEEDED(hr)) {          if (SUCCEEDED(hr)) {
1597                  hr = MFSetAttributeSize(pOutputType, MF_MT_FRAME_SIZE, m_create.width, m_create.height);                  hr = MFSetAttributeSize(pOutputType, MF_MT_FRAME_SIZE, m_create.width, abs(m_create.height));
1598          }          }
1599    
1600          if (SUCCEEDED(hr)) {          if (SUCCEEDED(hr)) {
# Line 1549  Line 1602 
1602          }          }
1603    
1604          if (SUCCEEDED(hr)) {          if (SUCCEEDED(hr)) {
1605                    if (interlaced > 1) {
1606                            hr = pOutputType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_FieldInterleavedUpperFirst);
1607                    }
1608                    else if (interlaced) {
1609                            hr = pOutputType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_FieldInterleavedLowerFirst);
1610                    }
1611                    else {
1612                  hr = pOutputType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);                  hr = pOutputType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
1613          }          }
1614            }
1615    
1616          if (SUCCEEDED(hr)) {          if (SUCCEEDED(hr)) {
1617                  hr = MFSetAttributeRatio(pOutputType, MF_MT_PIXEL_ASPECT_RATIO, ar_x, ar_y);                  hr = MFSetAttributeRatio(pOutputType, MF_MT_PIXEL_ASPECT_RATIO, ar_x, ar_y);
# Line 1589  Line 1650 
1650                  hr = MF_E_TRANSFORM_CANNOT_CHANGE_MEDIATYPE_WHILE_PROCESSING;                  hr = MF_E_TRANSFORM_CANNOT_CHANGE_MEDIATYPE_WHILE_PROCESSING;
1651    
1652          if (SUCCEEDED(hr)) {          if (SUCCEEDED(hr)) {
1653          if (pType) { // /* Check the type */          if (pType) { /* Check the type */
1654              hr = OnCheckInputType(pType);              hr = OnCheckInputType(pType);
1655          }          }
1656          }          }
# Line 1604  Line 1665 
1665          return hr;          return hr;
1666  }  }
1667    
1668    DWORD WINAPI CreateTrayIcon(LPVOID lpParameter)
1669    {
1670            WNDCLASSEX wc;
1671    
1672            wc.cbSize = sizeof(WNDCLASSEX);
1673            wc.lpfnWndProc = msg_proc;
1674            wc.style = CS_HREDRAW | CS_VREDRAW;
1675            wc.cbWndExtra = 0;
1676            wc.cbClsExtra = 0;
1677            wc.hInstance = (HINSTANCE)g_xvid_hInst;
1678            wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
1679            wc.lpszMenuName = NULL;
1680            wc.lpszClassName = "XVID_MSG_WINDOW";
1681            wc.hIcon = NULL;
1682            wc.hIconSm = NULL;
1683            wc.hCursor = NULL;
1684            RegisterClassEx(&wc);
1685    
1686            MSG_hwnd = CreateWindowEx(0, "XVID_MSG_WINDOW", NULL, 0, CW_USEDEFAULT,
1687                    CW_USEDEFAULT, 0, 0, HWND_MESSAGE, NULL, (HINSTANCE)g_xvid_hInst, NULL);
1688    
1689            /* display the tray icon */
1690            NOTIFYICONDATA nid;
1691            ZeroMemory(&nid, sizeof(NOTIFYICONDATA));
1692    
1693            nid.cbSize = sizeof(NOTIFYICONDATA);
1694            nid.hWnd = MSG_hwnd;
1695            nid.uID = 1456;
1696            nid.uVersion = NOTIFYICON_VERSION;
1697            nid.uCallbackMessage = WM_ICONMESSAGE;
1698            nid.hIcon = LoadIcon(g_xvid_hInst, MAKEINTRESOURCE(IDI_ICON));
1699            strcpy_s(nid.szTip, 19, "Xvid Video Decoder");
1700            nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_SHOWTIP;
1701    
1702            Shell_NotifyIcon(NIM_ADD, &nid);
1703            Shell_NotifyIcon(NIM_SETVERSION, &nid);
1704    
1705            DestroyIcon(nid.hIcon);
1706    
1707            MSG msg;
1708            while (MSG_hwnd && GetMessage(&msg, MSG_hwnd, 0, 0)) {
1709                    TranslateMessage(&msg);
1710                    DispatchMessage(&msg);
1711            }
1712    
1713            return 0;
1714    }
1715    
1716  HRESULT CXvidDecoder::MFTSetOutputType(DWORD dwOutputStreamID, IMFMediaType *pType, DWORD dwFlags)  HRESULT CXvidDecoder::MFTSetOutputType(DWORD dwOutputStreamID, IMFMediaType *pType, DWORD dwFlags)
1717  {  {
1718          DPRINTF("(MFT)SetOutputType");          DPRINTF("(MFT)SetOutputType");
# Line 1625  Line 1734 
1734          if (HasPendingOutput())          if (HasPendingOutput())
1735                  hr = MF_E_TRANSFORM_CANNOT_CHANGE_MEDIATYPE_WHILE_PROCESSING;                  hr = MF_E_TRANSFORM_CANNOT_CHANGE_MEDIATYPE_WHILE_PROCESSING;
1736    
1737            int bitdepth;
1738          if (SUCCEEDED(hr)) {          if (SUCCEEDED(hr)) {
1739                  if (pType) { /* Check the type */                  if (pType) { /* Check the type */
1740                          AM_MEDIA_TYPE *am;                          AM_MEDIA_TYPE *am;
1741                          hr = MFCreateAMMediaTypeFromMFMediaType(pType, GUID_NULL, &am);                          hr = MFCreateAMMediaTypeFromMFMediaType(pType, GUID_NULL, &am);
1742    
1743                          if (SUCCEEDED(hr)) {                          if (SUCCEEDED(hr)) {
1744                                  if (FAILED(ChangeColorspace(am->subtype, am->formattype, am->pbFormat, 1))) {                                  if (FAILED(ChangeColorspace(am->subtype, am->formattype, am->pbFormat, &bitdepth, 1))) {
1745                                          DPRINTF("(MFT)InternalCheckOutputType (MF_E_INVALIDTYPE)");                                          DPRINTF("(MFT)InternalCheckOutputType (MF_E_INVALIDTYPE)");
1746                                          return MF_E_INVALIDTYPE;                                          return MF_E_INVALIDTYPE;
1747                                  }                                  }
# Line 1644  Line 1754 
1754    
1755          if (SUCCEEDED(hr)) {          if (SUCCEEDED(hr)) {
1756                  if (bReallySet) { /* Set the type if needed */                  if (bReallySet) { /* Set the type if needed */
1757                          hr = OnSetOutputType(pType);                          hr = OnSetOutputType(pType, bitdepth);
1758                  }                  }
1759          }          }
 #ifdef XVID_USE_TRAYICON  
         if (SUCCEEDED(hr) && Tray_Icon == 0) /* Create message passing window */  
         {  
                 WNDCLASSEX wc;  
1760    
1761                  wc.cbSize = sizeof(WNDCLASSEX);          if (SUCCEEDED(hr) && (MSG_hwnd == 0) && (m_tray_icon == 0) && (g_config.bTrayIcon != 0))
1762                  wc.lpfnWndProc = msg_proc;          {
1763                  wc.style = CS_HREDRAW | CS_VREDRAW;                  m_thread_handle = CreateThread(NULL, 0, CreateTrayIcon, NULL, 0, NULL);  /* Create message passing window */
                 wc.cbWndExtra = 0;  
                 wc.cbClsExtra = 0;  
                 wc.hInstance = (HINSTANCE) g_xvid_hInst;  
                 wc.hbrBackground = (HBRUSH) GetStockObject(NULL_BRUSH);  
                 wc.lpszMenuName = NULL;  
                 wc.lpszClassName = "XVID_MSG_WINDOW";  
                 wc.hIcon = NULL;  
                 wc.hIconSm = NULL;  
                 wc.hCursor = NULL;  
                 RegisterClassEx(&wc);  
   
                 MSG_hwnd = CreateWindowEx(0, "XVID_MSG_WINDOW", NULL, 0, CW_USEDEFAULT,  
                                   CW_USEDEFAULT, 0, 0, HWND_MESSAGE, NULL, (HINSTANCE) g_xvid_hInst, NULL);  
   
                 /* display the tray icon */  
                 NOTIFYICONDATA nid;  
                 ZeroMemory(&nid,sizeof(NOTIFYICONDATA));  
   
                 nid.cbSize = NOTIFYICONDATA_V1_SIZE;  
                 nid.hWnd = MSG_hwnd;  
                 nid.uID = 1456;  
                 nid.uCallbackMessage = WM_ICONMESSAGE;  
                 nid.hIcon = LoadIcon(g_xvid_hInst, MAKEINTRESOURCE(IDI_ICON));  
                 strcpy_s(nid.szTip, 19, "Xvid Video Decoder");  
                 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;  
   
                 Shell_NotifyIcon(NIM_ADD, &nid);  
1764    
1765                  DestroyIcon(nid.hIcon);                  if (m_thread_handle)
1766                  Tray_Icon = 1;                      m_tray_icon = 1;
1767          }          }
 #endif  
1768    
1769          LeaveCriticalSection(&m_mft_lock);          LeaveCriticalSection(&m_mft_lock);
1770    
1771          return hr;          return hr;
1772  }  }
1773    
# Line 1756  Line 1835 
1835    
1836          EnterCriticalSection(&m_mft_lock);          EnterCriticalSection(&m_mft_lock);
1837    
1838          /* If there's pending output sampels we don't accept new          /* If there's pending output samples we don't accept new
1839             input data until ProcessOutput() or Flush() was called */             input data until ProcessOutput() or Flush() was called */
1840          if (!HasPendingOutput()) {          if (!HasPendingOutput()) {
1841                  *pdwFlags = MFT_INPUT_STATUS_ACCEPT_DATA;                  *pdwFlags = MFT_INPUT_STATUS_ACCEPT_DATA;
# Line 1993  Line 2072 
2072                          }                          }
2073    
2074                          ar_x = par_x * stats.data.vol.width;                          ar_x = par_x * stats.data.vol.width;
2075                          ar_y = par_y * stats.data.vol.height;                          ar_y = par_y * stats.data.vol.height; /* TODO: Actually set the newly determined AR on the output sample type
2076                                                                                                               or it'll have no effect at all... */
2077                    }
2078    
2079                    if (stats.data.vol.general & XVID_VOL_INTERLACING) {
2080                            interlaced = (stats.data.vop.general & XVID_VOP_TOPFIELDFIRST) ? 2 : 1;
2081                    }
2082                    else {
2083                            interlaced = 0;
2084                  }                  }
2085    
2086                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;                  m_frame.bitstream = (BYTE*)m_frame.bitstream + length;
# Line 2055  Line 2142 
2142    
2143          BYTE *Dst = NULL;          BYTE *Dst = NULL;
2144          DWORD buffer_size;          DWORD buffer_size;
2145            LONG stride = m_create.width;
2146          IMFMediaBuffer *pOutput = NULL;          IMFMediaBuffer *pOutput = NULL;
2147            IMF2DBuffer *pOutput2D = NULL;
2148    
2149          if (SUCCEEDED(hr)) {          if (SUCCEEDED(hr)) {
2150                  hr = pOutputSamples[0].pSample->GetBufferByIndex(0, &pOutput); /* Get output buffer */                  hr = pOutputSamples[0].pSample->GetBufferByIndex(0, &pOutput); /* Get output buffer */
# Line 2066  Line 2154 
2154                  hr = pOutput->GetMaxLength(&buffer_size);                  hr = pOutput->GetMaxLength(&buffer_size);
2155          }          }
2156    
2157          if (SUCCEEDED(hr))          if (SUCCEEDED(hr)) {
2158                    hr = pOutput->QueryInterface(IID_IMF2DBuffer, (void **)&pOutput2D);
2159            }
2160    
2161            if (SUCCEEDED(hr)) {
2162                    hr = pOutput2D->Lock2D(&Dst, &stride);
2163            }
2164            else {
2165                  hr = pOutput->Lock(&Dst, NULL, NULL);                  hr = pOutput->Lock(&Dst, NULL, NULL);
2166            }
2167    
2168          if (SUCCEEDED(hr)) {          if (SUCCEEDED(hr)) {
2169                  xvid_gbl_convert_t convert;                  xvid_gbl_convert_t convert;
# Line 2085  Line 2181 
2181    
2182                  convert.output.csp = m_frame.output.csp;                  convert.output.csp = m_frame.output.csp;
2183                  convert.output.plane[0] = Dst;                  convert.output.plane[0] = Dst;
2184                  convert.output.stride[0] = out_stride;                  convert.output.stride[0] = stride;
2185    
2186                  convert.width = m_create.width;                  convert.width = m_create.width;
2187                  convert.height = m_create.height;                  convert.height = m_create.height;
2188                  convert.interlacing = 0;                  convert.interlacing = (interlaced > 0) ? 1 : 0;
2189    
2190                  if (m_frame.output.plane[1] != NULL && Dst != NULL && xvid_global_func != NULL)                  if (m_frame.output.plane[1] != NULL && Dst != NULL && xvid_global_func != NULL)
2191                          if (xvid_global_func(0, XVID_GBL_CONVERT, &convert, NULL) < 0) /* CSP convert into output buffer */                          if (xvid_global_func(0, XVID_GBL_CONVERT, &convert, NULL) < 0) /* CSP convert into output buffer */
2192                                  hr = E_FAIL;                                  hr = E_FAIL;
   
2193                  m_frame.output.plane[1] = NULL;                  m_frame.output.plane[1] = NULL;
2194          }          }
2195    
# Line 2119  Line 2214 
2214                  }                  }
2215    
2216                  if (SUCCEEDED(hr))                  if (SUCCEEDED(hr))
2217                          hr = pOutput->SetCurrentLength(m_create.width * abs(m_create.height) * 4); // XXX                          hr = pOutput->SetCurrentLength((m_create.width * abs(m_create.height) * m_pOutputTypeBPP) >> 3);
2218          }          }
2219    
2220          if (pOutput) {          if (pOutput2D) {
2221                    pOutput2D->Unlock2D();
2222                    pOutput2D->Release();
2223                    if (pOutput)
2224                        pOutput->Release();
2225            }
2226            else if (pOutput) {
2227                  pOutput->Unlock();                  pOutput->Unlock();
2228                  pOutput->Release();                  pOutput->Release();
2229          }          }
# Line 2310  Line 2411 
2411          return hr;          return hr;
2412  }  }
2413    
2414  HRESULT CXvidDecoder::OnSetOutputType(IMFMediaType *pmt)  HRESULT CXvidDecoder::OnSetOutputType(IMFMediaType *pmt, int bitdepth)
2415  {  {
2416          if (m_pOutputType) m_pOutputType->Release();          if (m_pOutputType) m_pOutputType->Release();
2417    
2418          m_pOutputType = pmt;          m_pOutputType = pmt;
2419          m_pOutputType->AddRef();          m_pOutputType->AddRef();
2420            m_pOutputTypeBPP = bitdepth;
2421    
2422          return S_OK;          return S_OK;
2423  }  }

Legend:
Removed from v.2003  
changed lines
  Added in v.2131

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