Advertisement
jerker_back

Xvid patch for UNICODE build of dshow filter

Jun 13th, 2011
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 20.85 KB | None | 0 0
  1.  
  2. Patch to enable UNICODE build in Xvid MPEG-4 DirectShow/MediaFoundation
  3. filter xvid.ax.
  4.  
  5. Patch to make exported functions of the Xvid MPEG-4 (libxvidcore) library
  6. robust against different calling conventions in Xvid implementations.
  7.  
  8. Jerker Back 2011-06-15
  9.  
  10. Patch made by AnkhSVN (ASCII/LF formatted).
  11.  
  12.  
  13. Index: xvidcore/dshow/src/config.h
  14. ===================================================================
  15. --- xvidcore/dshow/src/config.h (revision 2017)
  16. +++ xvidcore/dshow/src/config.h (working copy)
  17. @@ -32,8 +32,8 @@
  18.  
  19.  /* registry stuff */
  20.  #define XVID_REG_KEY   HKEY_CURRENT_USER
  21. -#define XVID_REG_SUBKEY    "Software\\GNU\\XviD"
  22. -#define XVID_REG_CLASS "config"
  23. +#define XVID_REG_SUBKEY    TEXT("Software\\GNU\\XviD")
  24. +#define XVID_REG_CLASS TEXT("config")
  25.  
  26.  #define REG_GET_N(X, Y, Z) size=sizeof(int);if(RegQueryValueEx(hKey, X, 0, 0, (LPBYTE)&Y, &size) != ERROR_SUCCESS) {Y=Z;}
  27.  #define REG_GET_S(X, Y, Z) size=MAX_PATH;if(RegQueryValueEx(hKey, X, 0, 0, Y, &size) != ERROR_SUCCESS) {lstrcpy(Y, Z);}
  28. @@ -79,7 +79,7 @@
  29.  void SaveRegistryInfo();
  30.  INT_PTR CALLBACK adv_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  31.  
  32. -#define XVID_DLL_NAME "xvidcore.dll"
  33. +#define XVID_DLL_NAME TEXT("xvidcore.dll")
  34.  
  35.  #ifdef __cplusplus
  36.  }
  37.  
  38. ===================================================================
  39.  
  40. This patch enable a __stdcall compile and corrects types of ar_x, ar_y
  41.  
  42. Index: xvidcore/dshow/src/CXvidDecoder.h
  43. ===================================================================
  44. --- xvidcore/dshow/src/CXvidDecoder.h   (revision 2017)
  45. +++ xvidcore/dshow/src/CXvidDecoder.h   (working copy)
  46. @@ -161,9 +161,9 @@
  47.     xvid_dec_frame_t m_frame;
  48.  
  49.     HINSTANCE m_hdll;
  50. -   int (*xvid_global_func)(void *handle, int opt, void *param1, void *param2);
  51. -   int (*xvid_decore_func)(void *handle, int opt, void *param1, void *param2);
  52. -   int ar_x, ar_y;
  53. +   int (__cdecl *xvid_global_func)(void *handle, int opt, void *param1, void *param2);
  54. +   int (__cdecl *xvid_decore_func)(void *handle, int opt, void *param1, void *param2);
  55. +   UINT ar_x, ar_y;
  56.     bool forced_ar;
  57.  
  58.     int rgb_flip;
  59.  
  60. Index: xvidcore/dshow/src/config.c
  61. ===================================================================
  62. --- xvidcore/dshow/src/config.c (revision 2017)
  63. +++ xvidcore/dshow/src/config.c (working copy)
  64. @@ -44,19 +44,19 @@
  65.     RegOpenKeyEx(XVID_REG_KEY, XVID_REG_SUBKEY, 0, KEY_READ, &hKey);
  66.  
  67.     // Set the default post-processing settings
  68. -   REG_GET_N("Brightness", g_config.nBrightness, 0)
  69. -   REG_GET_N("Deblock_Y",  g_config.nDeblock_Y, 0)
  70. -   REG_GET_N("Deblock_UV", g_config.nDeblock_UV, 0)
  71. -   REG_GET_N("Dering_Y",  g_config.nDering_Y, 0)
  72. -   REG_GET_N("Dering_UV",  g_config.nDering_UV, 0)
  73. -   REG_GET_N("FilmEffect", g_config.nFilmEffect, 0)
  74. -   REG_GET_N("ForceColorspace", g_config.nForceColorspace, 0)
  75. -   REG_GET_N("FlipVideo",  g_config.nFlipVideo, 0)
  76. -   REG_GET_N("Supported_4CC",  g_config.supported_4cc, 0)
  77. -   REG_GET_N("Videoinfo_Compat",  g_config.videoinfo_compat, 0)
  78. -   REG_GET_N("Decoder_Aspect_Ratio",  g_config.aspect_ratio, 0)
  79. -   REG_GET_N("num_threads",  g_config.num_threads, 0)
  80. -   REG_GET_N("cpu_flags", g_config.cpu, 0)
  81. +   REG_GET_N(TEXT("Brightness"), g_config.nBrightness, 0)
  82. +   REG_GET_N(TEXT("Deblock_Y"),  g_config.nDeblock_Y, 0)
  83. +   REG_GET_N(TEXT("Deblock_UV"), g_config.nDeblock_UV, 0)
  84. +   REG_GET_N(TEXT("Dering_Y"),  g_config.nDering_Y, 0)
  85. +   REG_GET_N(TEXT("Dering_UV"),  g_config.nDering_UV, 0)
  86. +   REG_GET_N(TEXT("FilmEffect"), g_config.nFilmEffect, 0)
  87. +   REG_GET_N(TEXT("ForceColorspace"), g_config.nForceColorspace, 0)
  88. +   REG_GET_N(TEXT("FlipVideo"),  g_config.nFlipVideo, 0)
  89. +   REG_GET_N(TEXT("Supported_4CC"),  g_config.supported_4cc, 0)
  90. +   REG_GET_N(TEXT("Videoinfo_Compat"),  g_config.videoinfo_compat, 0)
  91. +   REG_GET_N(TEXT("Decoder_Aspect_Ratio"),  g_config.aspect_ratio, 0)
  92. +   REG_GET_N(TEXT("num_threads"),  g_config.num_threads, 0)
  93. +   REG_GET_N(TEXT("cpu_flags"), g_config.cpu, 0)
  94.  
  95.     RegCloseKey(hKey);
  96.  }
  97. @@ -77,22 +77,22 @@
  98.             &hKey,
  99.             &dispo) != ERROR_SUCCESS)
  100.     {
  101. -       OutputDebugString("Couldn't create XVID_REG_SUBKEY");
  102. +       OutputDebugString(TEXT("Couldn't create XVID_REG_SUBKEY"));
  103.         return;
  104.     }
  105.  
  106. -   REG_SET_N("Brightness", g_config.nBrightness);
  107. -   REG_SET_N("Deblock_Y",  g_config.nDeblock_Y);
  108. -   REG_SET_N("Deblock_UV", g_config.nDeblock_UV);
  109. -   REG_SET_N("Dering_Y", g_config.nDering_Y);
  110. -   REG_SET_N("Dering_UV", g_config.nDering_UV);
  111. -   REG_SET_N("FilmEffect", g_config.nFilmEffect);
  112. -   REG_SET_N("ForceColorspace", g_config.nForceColorspace);
  113. -   REG_SET_N("FlipVideo", g_config.nFlipVideo);
  114. -   REG_SET_N("Supported_4CC",  g_config.supported_4cc);
  115. -   REG_SET_N("Videoinfo_Compat",  g_config.videoinfo_compat);
  116. -   REG_SET_N("Decoder_Aspect_Ratio", g_config.aspect_ratio);
  117. -   REG_SET_N("num_threads",  g_config.num_threads);
  118. +   REG_SET_N(TEXT("Brightness"), g_config.nBrightness);
  119. +   REG_SET_N(TEXT("Deblock_Y"),  g_config.nDeblock_Y);
  120. +   REG_SET_N(TEXT("Deblock_UV"), g_config.nDeblock_UV);
  121. +   REG_SET_N(TEXT("Dering_Y"), g_config.nDering_Y);
  122. +   REG_SET_N(TEXT("Dering_UV"), g_config.nDering_UV);
  123. +   REG_SET_N(TEXT("FilmEffect"), g_config.nFilmEffect);
  124. +   REG_SET_N(TEXT("ForceColorspace"), g_config.nForceColorspace);
  125. +   REG_SET_N(TEXT("FlipVideo"), g_config.nFlipVideo);
  126. +   REG_SET_N(TEXT("Supported_4CC"),  g_config.supported_4cc);
  127. +   REG_SET_N(TEXT("Videoinfo_Compat"),  g_config.videoinfo_compat);
  128. +   REG_SET_N(TEXT("Decoder_Aspect_Ratio"), g_config.aspect_ratio);
  129. +   REG_SET_N(TEXT("num_threads"),  g_config.num_threads);
  130.  
  131.     RegCloseKey(hKey);
  132.  }
  133. @@ -103,6 +103,7 @@
  134.  {
  135.     HWND hBrightness;
  136.  
  137. +   UNREFERENCED_PARAMETER(lParam);
  138.     switch ( uMsg )
  139.     {
  140.     case WM_DESTROY:
  141. @@ -113,14 +114,14 @@
  142.             nForceColorspace = SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_GETCURSEL, 0, 0);
  143.             if ( g_config.nForceColorspace != nForceColorspace )
  144.             {
  145. -               MessageBox(0, "You have changed the output colorspace.\r\nClose the movie and open it for the new colorspace to take effect.", "Xvid DShow", MB_TOPMOST);
  146. +               MessageBox(0, TEXT("You have changed the output colorspace.\r\nClose the movie and open it for the new colorspace to take effect."), TEXT("Xvid DShow"), MB_TOPMOST);
  147.             }
  148.             g_config.nForceColorspace = (int) nForceColorspace;
  149.  
  150.             aspect_ratio = SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_GETCURSEL, 0, 0);
  151.             if ( g_config.aspect_ratio != aspect_ratio )
  152.             {
  153. -               MessageBox(0, "You have changed the default aspect ratio.\r\nClose the movie and open it for the new aspect ratio to take effect.", "Xvid DShow", MB_TOPMOST);
  154. +               MessageBox(0, TEXT("You have changed the default aspect ratio.\r\nClose the movie and open it for the new aspect ratio to take effect."), TEXT("Xvid DShow"), MB_TOPMOST);
  155.             }
  156.             g_config.aspect_ratio = (int) aspect_ratio;
  157.             SaveRegistryInfo();
  158. @@ -142,25 +143,25 @@
  159.                 ((int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"))
  160.                     (0, XVID_GBL_INFO, &info, NULL);
  161.  
  162. -               wsprintf(core, "Xvid MPEG-4 Video Codec v%d.%d.%d",
  163. +               wsprintfA(core, "Xvid MPEG-4 Video Codec v%d.%d.%d",
  164.                     XVID_VERSION_MAJOR(info.actual_version),
  165.                     XVID_VERSION_MINOR(info.actual_version),
  166.                     XVID_VERSION_PATCH(info.actual_version));
  167.  
  168.                 FreeLibrary(m_hdll);
  169.             } else {
  170. -               wsprintf(core, "xvidcore.dll not found!");
  171. +               wsprintfA(core, "xvidcore.dll not found!");
  172.             }
  173.  
  174. -           SetDlgItemText(hwnd, IDC_CORE, core);
  175. +           SetDlgItemTextA(hwnd, IDC_CORE, core);
  176.         }
  177.  
  178.         // Load Force Colorspace Box
  179. -       SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_ADDSTRING, 0, (LPARAM)"No Force");
  180. -       SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_ADDSTRING, 0, (LPARAM)"YV12");
  181. -       SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_ADDSTRING, 0, (LPARAM)"YUY2");
  182. -       SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_ADDSTRING, 0, (LPARAM)"RGB24");
  183. -       SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_ADDSTRING, 0, (LPARAM)"RGB32");
  184. +       SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_ADDSTRING, 0, (LPARAM)TEXT("No Force"));
  185. +       SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_ADDSTRING, 0, (LPARAM)TEXT("YV12"));
  186. +       SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_ADDSTRING, 0, (LPARAM)TEXT("YUY2"));
  187. +       SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_ADDSTRING, 0, (LPARAM)TEXT("RGB24"));
  188. +       SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_ADDSTRING, 0, (LPARAM)TEXT("RGB32"));
  189.  
  190.         // Select Colorspace
  191.         SendMessage(GetDlgItem(hwnd, IDC_COLORSPACE), CB_SETCURSEL, g_config.nForceColorspace, 0);
  192. @@ -171,11 +172,11 @@
  193.         SendMessage(hBrightness, TBM_SETPOS, (WPARAM)TRUE, (LPARAM) g_config.nBrightness);
  194.  
  195.         // Load Aspect Ratio Box
  196. -       SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_ADDSTRING, 0, (LPARAM)"Auto (MPEG-4 first)");
  197. -       SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_ADDSTRING, 0, (LPARAM)"Auto (external first)");
  198. -       SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_ADDSTRING, 0, (LPARAM)"4:3");
  199. -       SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_ADDSTRING, 0, (LPARAM)"16:9");
  200. -       SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_ADDSTRING, 0, (LPARAM)"2.35:1");
  201. +       SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_ADDSTRING, 0, (LPARAM)TEXT("Auto (MPEG-4 first)"));
  202. +       SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_ADDSTRING, 0, (LPARAM)TEXT("Auto (external first)"));
  203. +       SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_ADDSTRING, 0, (LPARAM)TEXT("4:3"));
  204. +       SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_ADDSTRING, 0, (LPARAM)TEXT("16:9"));
  205. +       SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_ADDSTRING, 0, (LPARAM)TEXT("2.35:1"));
  206.  
  207.         // Select Aspect Ratio
  208.         SendMessage(GetDlgItem(hwnd, IDC_USE_AR), CB_SETCURSEL, g_config.aspect_ratio, 0);
  209.  
  210. Index: xvidcore/dshow/src/Configure.cpp
  211. ===================================================================
  212. --- xvidcore/dshow/src/Configure.cpp    (revision 2017)
  213. +++ xvidcore/dshow/src/Configure.cpp    (working copy)
  214. @@ -44,7 +44,7 @@
  215.     psp[0].pszTemplate = MAKEINTRESOURCE (IDD_ABOUT);
  216.     psp[0].pszIcon = NULL;
  217.     psp[0].pfnDlgProc = adv_proc;
  218. -   psp[0].pszTitle = "About";
  219. +   psp[0].pszTitle = TEXT("About");
  220.     psp[0].lParam = 0;
  221.  
  222.     psh.dwSize = sizeof (PROPSHEETHEADER);
  223. @@ -52,7 +52,7 @@
  224.     psh.hwndParent = hwndOwner;
  225.     psh.hInstance = g_xvid_hInst;
  226.     psh.pszIcon = NULL;
  227. -   psh.pszCaption = (LPSTR)"Xvid Configuration";
  228. +   psh.pszCaption = TEXT("Xvid Configuration");
  229.     psh.nPages = sizeof (psp) / sizeof (PROPSHEETPAGE);
  230.     psh.ppsp = psp;
  231.  
  232. ===================================================================
  233.  
  234. Change the DirectShow macro NAME to the global macro TEXT (they are the same)
  235. Change strcpy_s (a bit of an overkill) to the UNICODE aware lstrcpy.
  236. The szTip member of NOTIFYICONDATA have a buffer of 128 characters, so this
  237. change is safe.
  238.  
  239. Index: xvidcore/dshow/src/CXvidDecoder.cpp
  240. ===================================================================
  241. --- xvidcore/dshow/src/CXvidDecoder.cpp (revision 2017)
  242. +++ xvidcore/dshow/src/CXvidDecoder.cpp (working copy)
  243. @@ -314,7 +314,7 @@
  244.  /* constructor */
  245.  
  246.  CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) :
  247. -    CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID), m_hdll (NULL)
  248. +    CVideoTransformFilter(TEXT("CXvidDecoder"), punk, CLSID_XVID), m_hdll (NULL)
  249.  {
  250.     DPRINTF("Constructor");
  251.  
  252. @@ -356,7 +356,7 @@
  253.     m_hdll = LoadLibrary(XVID_DLL_NAME);
  254.     if (m_hdll == NULL) {
  255.         DPRINTF("dll load failed");
  256. -       MessageBox(0, XVID_DLL_NAME " not found","Error", MB_TOPMOST);
  257. +       MessageBox(0, XVID_DLL_NAME TEXT(" not found"), TEXT("Error"), MB_TOPMOST);
  258.         return E_FAIL;
  259.     }
  260.  
  261. @@ -364,7 +364,7 @@
  262.     if (xvid_global_func == NULL) {
  263.          FreeLibrary(m_hdll);
  264.          m_hdll = NULL;
  265. -       MessageBox(0, "xvid_global() not found", "Error", MB_TOPMOST);
  266. +       MessageBox(0, TEXT("xvid_global() not found"), TEXT("Error"), MB_TOPMOST);
  267.         return E_FAIL;
  268.     }
  269.  
  270. @@ -373,7 +373,7 @@
  271.          xvid_global_func = NULL;
  272.          FreeLibrary(m_hdll);
  273.          m_hdll = NULL;
  274. -       MessageBox(0, "xvid_decore() not found", "Error", MB_TOPMOST);
  275. +       MessageBox(0, TEXT("xvid_decore() not found"), TEXT("Error"), MB_TOPMOST);
  276.         return E_FAIL;
  277.     }
  278.  
  279. @@ -383,7 +383,7 @@
  280.          xvid_decore_func = NULL;
  281.          FreeLibrary(m_hdll);
  282.          m_hdll = NULL;
  283. -       MessageBox(0, "xvid_global() failed", "Error", MB_TOPMOST);
  284. +       MessageBox(0, TEXT("xvid_global() failed"), TEXT("Error"), MB_TOPMOST);
  285.         return E_FAIL;
  286.     }
  287.  
  288. @@ -393,7 +393,7 @@
  289.          xvid_decore_func = NULL;
  290.          FreeLibrary(m_hdll);
  291.          m_hdll = NULL;
  292. -       MessageBox(0, "xvid_global() failed", "Error", MB_TOPMOST);
  293. +       MessageBox(0, TEXT("xvid_global() failed"), TEXT("Error"), MB_TOPMOST);
  294.         return E_FAIL;
  295.     }
  296.  
  297. @@ -948,14 +948,14 @@
  298.         wc.hInstance = (HINSTANCE) g_xvid_hInst;
  299.         wc.hbrBackground = (HBRUSH) GetStockObject(NULL_BRUSH);
  300.         wc.lpszMenuName = NULL;
  301. -       wc.lpszClassName = "XVID_MSG_WINDOW";
  302. +       wc.lpszClassName = TEXT("XVID_MSG_WINDOW");
  303.         wc.hIcon = NULL;
  304.         wc.hIconSm = NULL;
  305.         wc.hCursor = NULL;
  306.         RegisterClassEx(&wc);
  307.  
  308. -       MSG_hwnd = CreateWindowEx(0, "XVID_MSG_WINDOW", NULL, 0, CW_USEDEFAULT,
  309. -                                  CW_USEDEFAULT, 0, 0, HWND_MESSAGE, NULL, (HINSTANCE) g_xvid_hInst, NULL);
  310. +       MSG_hwnd = CreateWindowEx(0, TEXT("XVID_MSG_WINDOW"), NULL, 0, CW_USEDEFAULT,
  311. +           CW_USEDEFAULT, 0, 0, HWND_MESSAGE, NULL, (HINSTANCE) g_xvid_hInst, NULL);
  312.  
  313.         /* display the tray icon */
  314.         NOTIFYICONDATA nid;    
  315. @@ -966,7 +966,7 @@
  316.         nid.uID = 1456;  
  317.         nid.uCallbackMessage = WM_ICONMESSAGE;  
  318.         nid.hIcon = LoadIcon(g_xvid_hInst, MAKEINTRESOURCE(IDI_ICON));  
  319. -       strcpy_s(nid.szTip, 19, "Xvid Video Decoder");  
  320. +       lstrcpy(nid.szTip, TEXT("Xvid Video Decoder"));  
  321.         nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
  322.    
  323.         Shell_NotifyIcon(NIM_ADD, &nid);
  324. @@ -1660,13 +1660,13 @@
  325.         wc.hInstance = (HINSTANCE) g_xvid_hInst;
  326.         wc.hbrBackground = (HBRUSH) GetStockObject(NULL_BRUSH);
  327.         wc.lpszMenuName = NULL;
  328. -       wc.lpszClassName = "XVID_MSG_WINDOW";
  329. +       wc.lpszClassName = TEXT("XVID_MSG_WINDOW");
  330.         wc.hIcon = NULL;
  331.         wc.hIconSm = NULL;
  332.         wc.hCursor = NULL;
  333.         RegisterClassEx(&wc);
  334.  
  335. -       MSG_hwnd = CreateWindowEx(0, "XVID_MSG_WINDOW", NULL, 0, CW_USEDEFAULT,
  336. +       MSG_hwnd = CreateWindowEx(0, TEXT("XVID_MSG_WINDOW"), NULL, 0, CW_USEDEFAULT,
  337.                                    CW_USEDEFAULT, 0, 0, HWND_MESSAGE, NULL, (HINSTANCE) g_xvid_hInst, NULL);
  338.  
  339.         /* display the tray icon */
  340. @@ -1677,8 +1677,8 @@
  341.         nid.hWnd = MSG_hwnd;  
  342.         nid.uID = 1456;  
  343.         nid.uCallbackMessage = WM_ICONMESSAGE;  
  344. -       nid.hIcon = LoadIcon(g_xvid_hInst, MAKEINTRESOURCE(IDI_ICON));  
  345. -       strcpy_s(nid.szTip, 19, "Xvid Video Decoder");  
  346. +       nid.hIcon = LoadIcon(g_xvid_hInst, MAKEINTRESOURCE(IDI_ICON));
  347. +       lstrcpy(nid.szTip, TEXT("Xvid Video Decoder"));
  348.         nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
  349.        
  350.         Shell_NotifyIcon(NIM_ADD, &nid);
  351. @@ -1907,7 +1907,7 @@
  352.     EnterCriticalSection(&m_mft_lock);
  353.  
  354.     HRESULT hr = S_OK;
  355. -   IMFMediaBuffer *pBuffer;
  356. +   IMFMediaBuffer *pBuffer = NULL;
  357.  
  358.     if (SUCCEEDED(hr)) {
  359.         hr = pSample->ConvertToContiguousBuffer(&pBuffer);
  360. @@ -2161,9 +2161,9 @@
  361.     }
  362.    
  363.     if (m_hdll == NULL) {
  364. -       HRESULT hr = OpenLib();
  365. +       HRESULT hr2 = OpenLib();
  366.        
  367. -       if (FAILED(hr) || (m_hdll == NULL)) // Paranoid checks.
  368. +       if (FAILED(hr2) || (m_hdll == NULL)) // Paranoid checks.
  369.             hr = MF_E_INVALIDTYPE;
  370.     }
  371.  
  372. ===================================================================
  373.  
  374. We need OutputDebugStringA (which is preferrable) since the strings
  375. are ASCII.
  376.  
  377. Index: xvidcore/dshow/src/debug.c
  378. ===================================================================
  379. --- xvidcore/dshow/src/debug.c  (revision 2017)
  380. +++ xvidcore/dshow/src/debug.c  (working copy)
  381. @@ -13,6 +13,6 @@
  382.  
  383.     va_start(args, fmt);
  384.     vsprintf(buf, fmt, args);
  385. -   OutputDebugString(buf);
  386. +   OutputDebugStringA(buf);
  387.  #endif
  388.  }
  389.  
  390. ===================================================================
  391.  
  392. This patch ensure that the calling convention of exported xvidcore functions
  393. is correct regardless of compile settings in calling applications. This makes
  394. the library robust against __stdcall/__fastcall compile settings in Xvid
  395. implementations. The calling convention is specified with the XVID_CALL
  396. macro and is only visible for compilers that care about these things.
  397.  
  398. I also added the XVID_IMPEXP macro to mark exported functions (for convenience).
  399.  
  400. NB: xvidcore itself cannot be compiled with __stdcall/__fastcall without
  401. extensive changes in the code (mostly due to assembler source). A developer
  402. may be successful if alterering the assembler options to allow __stdcall/__fastcall
  403. calling conventions and using an assembler that support these features.
  404. Otherwise all functions implemented in assembler must be marked with the
  405. XVID_CALL macro. There is however currently no good place to define this
  406. macro since not all source files include xvid.h.
  407.  
  408. A realistic view is therefore to state that xvidcore require a __cdecl
  409. calling convention. In 64-bit this is of course no issue.
  410.  
  411. Index: xvidcore/src/xvid.h
  412. ===================================================================
  413. --- xvidcore/src/xvid.h (revision 2017)
  414. +++ xvidcore/src/xvid.h (working copy)
  415. @@ -26,12 +26,28 @@
  416.  #ifndef _XVID_H_
  417.  #define _XVID_H_
  418.  
  419. -
  420.  #ifdef __cplusplus
  421.  extern "C" {
  422.  #endif
  423.  
  424.  /*****************************************************************************
  425. + * function export defines
  426. + ****************************************************************************/
  427. +
  428. +#if defined(XVID_BUILD_DLL) && (defined(_WIN32) || defined(__CYGWIN__) || defined(_MSC_VER))
  429. +#define XVID_IMPEXP             __declspec(dllexport)
  430. +#elif defined(XVID_BUILD_DLL) && (defined(__GNUC__) && (__GNUC__ >= 4))
  431. +#define XVID_IMPEXP             __attribute__ ((visibility ("default")))
  432. +#else
  433. +#define XVID_IMPEXP             extern
  434. +#endif
  435. +#if defined(_WIN32) || defined(_MSC_VER)
  436. +#define XVID_CALL               __cdecl
  437. +#else
  438. +#define XVID_CALL
  439. +#endif
  440. +
  441. +/*****************************************************************************
  442.   * versioning
  443.   ****************************************************************************/
  444.  
  445. @@ -225,7 +241,7 @@
  446.  #define XVID_GBL_INFO    1 /* return some info about xvidcore, and the host computer */
  447.  #define XVID_GBL_CONVERT 2 /* colorspace conversion utility */
  448.  
  449. -extern int xvid_global(void *handle, int opt, void *param1, void *param2);
  450. +XVID_IMPEXP int XVID_CALL xvid_global(void *handle, int opt, void *param1, void *param2);
  451.  
  452.  
  453.  /*****************************************************************************
  454. @@ -236,7 +252,7 @@
  455.  #define XVID_DEC_DESTROY 1 /* destroy decore instance: return 0 on success */
  456.  #define XVID_DEC_DECODE  2 /* decode a frame: returns number of bytes consumed >= 0 */
  457.  
  458. -extern int xvid_decore(void *handle, int opt, void *param1, void *param2);
  459. +XVID_IMPEXP int XVID_CALL xvid_decore(void *handle, int opt, void *param1, void *param2);
  460.  
  461.  /* XVID_DEC_CREATE param 1
  462.     image width & height as well as FourCC code may be specified
  463. @@ -475,7 +491,7 @@
  464.  
  465.   ****************************************************************************/
  466.  
  467. -typedef int (xvid_plugin_func)(void * handle, int opt, void * param1, void * param2);
  468. +typedef int (XVID_CALL xvid_plugin_func)(void * handle, int opt, void * param1, void * param2);
  469.  
  470.  typedef struct
  471.  {
  472. @@ -483,20 +499,19 @@
  473.     void * param;
  474.  } xvid_enc_plugin_t;
  475.  
  476. +XVID_IMPEXP xvid_plugin_func xvid_plugin_single;   /* single-pass rate control */
  477. +XVID_IMPEXP xvid_plugin_func xvid_plugin_2pass1;   /* two-pass rate control: first pass */
  478. +XVID_IMPEXP xvid_plugin_func xvid_plugin_2pass2;   /* two-pass rate control: second pass */
  479.  
  480. -extern xvid_plugin_func xvid_plugin_single;   /* single-pass rate control */
  481. -extern xvid_plugin_func xvid_plugin_2pass1;   /* two-pass rate control: first pass */
  482. -extern xvid_plugin_func xvid_plugin_2pass2;   /* two-pass rate control: second pass */
  483. +XVID_IMPEXP xvid_plugin_func xvid_plugin_lumimasking;  /* lumimasking */
  484.  
  485. -extern xvid_plugin_func xvid_plugin_lumimasking;  /* lumimasking */
  486. +XVID_IMPEXP xvid_plugin_func xvid_plugin_psnr;      /* write psnr values to stdout */
  487. +XVID_IMPEXP xvid_plugin_func xvid_plugin_dump;      /* dump before and after yuvpgms */
  488.  
  489. -extern xvid_plugin_func xvid_plugin_psnr;  /* write psnr values to stdout */
  490. -extern xvid_plugin_func xvid_plugin_dump;  /* dump before and after yuvpgms */
  491. +XVID_IMPEXP xvid_plugin_func xvid_plugin_ssim;      /*write ssim values to stdout*/
  492. +XVID_IMPEXP xvid_plugin_func xvid_plugin_psnrhvsm;  /*write psnrhvsm values to stdout*/
  493.  
  494. -extern xvid_plugin_func xvid_plugin_ssim;      /*write ssim values to stdout*/
  495. -extern xvid_plugin_func xvid_plugin_psnrhvsm;  /*write psnrhvsm values to stdout*/
  496.  
  497. -
  498.  /* single pass rate control
  499.   * CBR and Constant quantizer modes */
  500.  typedef struct
  501. @@ -591,7 +606,7 @@
  502.   * Encoder entry point
  503.   *--------------------------------------------------------------------------*/
  504.  
  505. -extern int xvid_encore(void *handle, int opt, void *param1, void *param2);
  506. +XVID_IMPEXP int XVID_CALL xvid_encore(void *handle, int opt, void *param1, void *param2);
  507.  
  508.  /* Quick API reference
  509.   *
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement