Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3388 lines
97 KiB

  1. //////////////////////////////////////////////////////////////////////////////o
  2. //
  3. // Compman.c
  4. //
  5. // Manager routines for compressing/decompressing/and choosing compressors.
  6. //
  7. // (C) Copyright Microsoft Corp. 1991-1995. All rights reserved.
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. /*
  11. * This code contains 16 thunk code for NT. If the 16 bit open fails
  12. * we will try and open a 32 bit codec. (The reason for not trying the 32
  13. * bit codec first is an attempt to keep most things on the 16 bit side.
  14. * The performance under NT appears reasonable, and for frame specific
  15. * operations it reduces the number of 16/32 transitions.
  16. */
  17. #include <windows.h>
  18. #include <windowsx.h>
  19. #include <mmsystem.h>
  20. #include <win32.h>
  21. #ifdef _WIN32
  22. #include <mmddk.h> // needed for definition of DRIVERS_SECTION
  23. BOOL IsAdmin(void);
  24. #endif
  25. #ifdef NT_THUNK16
  26. #include "thunks.h" // Define the thunk stuff
  27. #endif
  28. #ifdef _WIN32
  29. #ifdef DEBUGLOAD
  30. #define ICEnterCrit(p) \
  31. if (!(gdwLoadFlags & ICLOAD_CALLED)) { \
  32. OutputDebugStringA("ICOPEN Crit Sec not setup (ENTER)\n"); \
  33. DebugBreak(); \
  34. } \
  35. (EnterCriticalSection(p))
  36. #define ICLeaveCrit(p) \
  37. if (!(gdwLoadFlags & ICLOAD_CALLED)) { \
  38. OutputDebugStringA("ICOPEN Crit Sec not setup (LEAVE)\n"); \
  39. DebugBreak(); \
  40. } \
  41. (LeaveCriticalSection(p))
  42. #else
  43. #define ICEnterCrit(p) (EnterCriticalSection(p))
  44. #define ICLeaveCrit(p) (LeaveCriticalSection(p))
  45. #endif
  46. #else
  47. // non-win32 code has no critsecs
  48. #define ICEnterCrit(p)
  49. #define ICLeaveCrit(p)
  50. #endif
  51. #include <profile.h>
  52. //
  53. // define these before compman.h, so our functions get declared right.
  54. //
  55. #ifndef _WIN32
  56. #define VFWAPI FAR PASCAL _loadds
  57. #define VFWAPIV FAR CDECL _loadds
  58. #endif
  59. #include <vfw.h>
  60. #include "icm.rc"
  61. #ifndef _WIN32
  62. #define LoadLibraryA LoadLibrary
  63. #define CharLowerA AnsiLower
  64. #endif
  65. #ifndef streamtypeVIDEO
  66. #define streamtypeVIDEO mmioFOURCC('v', 'i', 'd', 's')
  67. #endif
  68. #define ICTYPE_VCAP mmioFOURCC('v', 'c', 'a', 'p')
  69. #define ICTYPE_ACM mmioFOURCC('a', 'u', 'd', 'c')
  70. #define SMAG mmioFOURCC('S', 'm', 'a', 'g')
  71. #define IC_INI TEXT("Installable Compressors")
  72. //STATICDT TCHAR sz44s[] = TEXT("%4.4hs");
  73. STATICDT TCHAR szMSACM[] = TEXT("MSACM");
  74. STATICDT TCHAR szVIDC[] = TEXT("VIDC");
  75. STATICDT TCHAR gszIniSect[] = IC_INI;
  76. STATICDT TCHAR gszSystemIni[] = TEXT("SYSTEM.INI");
  77. STATICDT TCHAR gszDrivers[] = DRIVERS_SECTION;
  78. STATICDT TCHAR szNull[] = TEXT("");
  79. STATICDT TCHAR szICKey[] = TEXT("%4.4hs.%4.4hs");
  80. STATICDT TCHAR szMSVideo[] = TEXT("MSVideo");
  81. STATICDT SZCODEA szDriverProc[] = "DriverProc";
  82. #ifdef _WIN32
  83. // Use a mapping to get stuff into and out of the registry
  84. BOOL myWritePrivateProfileString(
  85. LPCTSTR lpszSection, // address of section name
  86. LPCTSTR lpszKey, // address of key name
  87. LPCTSTR lpszString // address of string to add
  88. );
  89. DWORD myGetPrivateProfileString(
  90. LPCTSTR lpszSection, // address of section name
  91. LPCTSTR lpszKey, // address of key name
  92. LPCTSTR lpszDefault, // address of default string
  93. LPTSTR lpszReturnBuffer, // address of destination buffer
  94. DWORD cchReturnBuffer // size of destination buffer
  95. );
  96. #endif
  97. #ifdef DEBUG
  98. #define DPF( x ) dprintfc x
  99. #define DEBUG_RETAIL
  100. #else
  101. #define DPF(x)
  102. #endif
  103. #ifdef DEBUG_RETAIL
  104. STATICFN void CDECL dprintfc(LPSTR, ...);
  105. static char gszModname[] = "COMPMAN";
  106. #define MODNAME gszModname
  107. #define RPF( x ) dprintfc x
  108. #define ROUT(sz) {static SZCODEA ach[] = sz; dprintfc(ach); }
  109. void ICDebugMessage(HIC hic, UINT msg, DWORD_PTR dw1, DWORD_PTR dw2);
  110. LRESULT ICDebugReturn(LRESULT err);
  111. #ifdef _WIN32
  112. #define DebugErr(flags, sz) {static SZCODEA ach[] = "COMPMAN: "sz; OutputDebugStringA(ach); }
  113. #else
  114. #define DebugErr(flags, sz) {static SZCODE ach[] = "COMPMAN: "sz; DebugOutput(flags | DBF_MMSYSTEM, ach); }
  115. #endif
  116. #else // !DEBUG_RETAIL
  117. #define RPF(x)
  118. #define ROUT(sz)
  119. #define ICDebugMessage(hic, msg, dw1, dw2)
  120. #define ICDebugReturn(err) err
  121. #define DebugErr(flags, sz)
  122. #endif
  123. #ifndef WF_WINNT
  124. #define WF_WINNT 0x4000
  125. #endif
  126. #ifdef _WIN32
  127. #define IsWow() FALSE
  128. #else
  129. #define IsWow() ((BOOL) (GetWinFlags() & WF_WINNT))
  130. #define GetDriverModuleHandle(h) (IsWow() ? h : GetDriverModuleHandle(h))
  131. #endif
  132. // HACK!
  133. //
  134. //
  135. #if defined _WIN32 && !defined UNICODE
  136. #pragma message ("hack! use DrvGetModuleHandle on Chicago")
  137. #undef GetDriverModuleHandle
  138. #define GetDriverModuleHandle(h) DrvGetModuleHandle(h)
  139. extern HMODULE _stdcall DrvGetModuleHandle(HDRVR);
  140. #endif
  141. __inline void ictokey(DWORD fccType, DWORD fcc, LPTSTR sz)
  142. {
  143. int i = wsprintf(sz, szICKey, (LPSTR)&(fccType),(LPSTR)&(fcc));
  144. while (i>0 && sz[i-1] == ' ')
  145. sz[--i] = 0;
  146. }
  147. #define WIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
  148. #define DIBWIDTHBYTES(bi) (int)WIDTHBYTES((int)(bi).biWidth * (int)(bi).biBitCount)
  149. #ifdef DEBUG_RETAIL
  150. STATICFN void ICDump(void);
  151. #endif
  152. //
  153. // the following array is used for 'installed' converters
  154. //
  155. // converters are either driver handles or indexes into this array
  156. //
  157. // 'function' converters are installed into this array, 'driver' converters
  158. // are installed in SYSTEM.INI
  159. //
  160. #define MAX_CONVERTERS 75 // maximum installed converters.
  161. typedef struct {
  162. DWORD dwSmag; // 'Smag'
  163. HTASK hTask; // owner task.
  164. DWORD fccType; // converter type ie 'vidc'
  165. DWORD fccHandler; // converter id ie 'rle '
  166. HDRVR hDriver; // handle of driver
  167. LPARAM dwDriver; // driver id for functions
  168. DRIVERPROC DriverProc; // function to call
  169. #ifdef NT_THUNK16
  170. DWORD h32; // 32-bit driver handle
  171. #endif
  172. } IC, *PIC;
  173. IC aicConverters[MAX_CONVERTERS];
  174. int giMaxConverters = 0; // High water mark of installed converters
  175. /*
  176. * We dynamically allocate a buffer used in ICInfo to read all the
  177. * installable compressor definitions from system.ini.
  178. * The buffer is freed when the driver is unloaded (in IC_Unload).
  179. * The previous code had a buffer which was only freed when the executable
  180. * was unloaded, and not freed on DLL unload.
  181. */
  182. static LPVOID lpICInfoMem = NULL;
  183. /*****************************************************************************
  184. ****************************************************************************/
  185. LRESULT CALLBACK DriverProcNull(DWORD_PTR dwDriverID, HANDLE hDriver, UINT wMessage, LPARAM dwParam1, LPARAM dwParam2)
  186. {
  187. DPF(("codec called after it has been removed with ICRemove\r\n"));
  188. return ICERR_UNSUPPORTED;
  189. }
  190. /*****************************************************************************
  191. ****************************************************************************/
  192. #if defined _WIN32
  193. STATICFN HDRVR LoadDriver(LPWSTR szDriver, DRIVERPROC FAR *lpDriverProc);
  194. #else
  195. STATICFN HDRVR LoadDriver(LPSTR szDriver, DRIVERPROC FAR *lpDriverProc);
  196. #endif
  197. STATICFN void FreeDriver(HDRVR hDriver);
  198. /*****************************************************************************
  199. driver cache - to make enuming/loading faster we keep the last N
  200. module's open for a while.
  201. ****************************************************************************/
  202. #define NEVERCACHECODECS // turn caching off for M6....
  203. #if defined _WIN32 || defined NEVERCACHECODECS
  204. #define CacheModule(x)
  205. #else
  206. #define N_MODULES 10 //!!!????
  207. HMODULE ahModule[N_MODULES];
  208. int iModule = 0;
  209. STATICFN void CacheModule(HMODULE hModule)
  210. {
  211. char ach[128];
  212. //
  213. // what if this module is in the list currently?
  214. //
  215. #if 0
  216. // we dont do this so unused compressors will fall off the end....
  217. int i;
  218. for (i=0; i<N_MODULES; i++)
  219. {
  220. if (ahModule[i] && ahModule[i] == hModule)
  221. return;
  222. }
  223. #endif
  224. //
  225. // add this module to the cache
  226. //
  227. if (hModule)
  228. {
  229. extern HMODULE ghInst; // in MSVIDEO/init.c
  230. int iUsage;
  231. GetModuleFileNameA(hModule, ach, sizeof(ach));
  232. DPF(("Loading module: %s\r\n", (LPSTR)ach));
  233. #ifndef _WIN32 // On NT GetModuleUsage always returns 1. So... we cache
  234. iUsage = GetModuleUsage(ghInst);
  235. #endif
  236. LoadLibraryA(ach);
  237. #ifndef _WIN32 // On NT GetModuleUsage always returns 1. So... we cache
  238. //
  239. // dont cache modules that link to MSVIDEO
  240. // we should realy do a toolhelp thing!
  241. // or force apps to call VFWInit and VFWExit()
  242. //
  243. // The NT position is more awkward..!
  244. //
  245. if (iUsage != GetModuleUsage(ghInst))
  246. {
  247. DPF(("Not caching this module because it links to MSVIDEO\r\n"));
  248. FreeLibrary(hModule);
  249. return;
  250. }
  251. #endif
  252. }
  253. //
  254. // free module in our slot.
  255. //
  256. if (ahModule[iModule] != NULL)
  257. {
  258. #ifdef DEBUG
  259. GetModuleFileNameA(ahModule[iModule], ach, sizeof(ach));
  260. DPF(("Freeing module: %s Handle==%8x\r\n", (LPSTR)ach, ahModule[iModule]));
  261. if (hModule!=NULL) {
  262. GetModuleFileNameA(hModule, ach, sizeof(ach));
  263. DPF(("Replacing with: %s Handle==%8x\r\n", (LPSTR)ach, hModule));
  264. } else
  265. DPF(("Slot now empty\r\n"));
  266. #endif
  267. FreeLibrary(ahModule[iModule]);
  268. }
  269. ahModule[iModule] = hModule;
  270. iModule++;
  271. if (iModule >= N_MODULES)
  272. iModule = 0;
  273. }
  274. #endif
  275. /*****************************************************************************
  276. ****************************************************************************/
  277. /*****************************************************************************
  278. * FixFOURCC - clean up a FOURCC
  279. ****************************************************************************/
  280. INLINE STATICFN DWORD Fix4CC(DWORD fcc)
  281. {
  282. int i;
  283. if (fcc > 256)
  284. {
  285. AnsiLowerBuff((LPSTR)&fcc, sizeof(fcc));
  286. for (i=0; i<4; i++)
  287. {
  288. if (((LPSTR)&fcc)[i] == 0)
  289. for (; i<4; i++)
  290. ((LPSTR)&fcc)[i] = ' ';
  291. }
  292. }
  293. return fcc;
  294. }
  295. /*****************************************************************************
  296. * @doc INTERNAL IC
  297. *
  298. * @api PIC | FindConverter |
  299. * search the converter list for a un-opened converter
  300. *
  301. ****************************************************************************/
  302. STATICFN PIC FindConverter(DWORD fccType, DWORD fccHandler)
  303. {
  304. int i;
  305. PIC pic;
  306. // By running the loop to <= giMaxConverters we allow an empty slot to
  307. // be found.
  308. for (i=0; i<=giMaxConverters; i++)
  309. {
  310. pic = &aicConverters[i];
  311. if (pic->fccType == fccType &&
  312. pic->fccHandler == fccHandler &&
  313. pic->dwDriver == 0L)
  314. {
  315. if (pic->DriverProc != NULL && IsBadCodePtr((FARPROC)pic->DriverProc))
  316. {
  317. pic->DriverProc = NULL;
  318. ICClose((HIC)pic);
  319. DPF(("NO driver for fccType=%4.4hs, Handler=%4.4hs\n", (LPSTR)&fccType, (LPSTR)&fccHandler));
  320. return NULL;
  321. }
  322. if ((0 == fccType + fccHandler)
  323. && (i < (MAX_CONVERTERS-1))
  324. && (i==giMaxConverters))
  325. {
  326. ++giMaxConverters; // Up the high water mark
  327. }
  328. DPF(("Possible driver for fccType=%4.4hs, Handler=%4.4hs, Slot %d\n", (LPSTR)&fccType, (LPSTR)&fccHandler, i));
  329. return pic;
  330. }
  331. }
  332. DPF(("FindConverter: NO drivers for fccType=%4.4hs, Handler=%4.4hs\n", (LPSTR)&fccType, (LPSTR)&fccHandler));
  333. return NULL;
  334. }
  335. #ifdef _WIN32
  336. /*
  337. * we need to hold a critical section around the ICOpen code to protect
  338. * multi-thread simultaneous opens. This critsec is initialized by
  339. * ICDllEntryPoint (called from video\init.c at dll attach time) and is deleted
  340. * by ICDllEntryPoint (called from video\init.c at dll detach time).
  341. */
  342. CRITICAL_SECTION ICOpenCritSec;
  343. #ifdef DEBUGLOAD
  344. // There is a suspicion that a nasty problem exists on NT whereby the DLL
  345. // load/unload routines might not be called in certain esoteric cases. As
  346. // we rely on these routines to set up the ICOpenCritSec code has been
  347. // added to verify that the critical section has indeed been set up. On
  348. // LOAD we turn one bit on in a global variable. On UNLOAD we turn that
  349. // bit off and turn another bit on.
  350. DWORD gdwLoadFlags = 0;
  351. #define ICLOAD_CALLED 0x00010000
  352. #define ICUNLOAD_CALLED 0x00000001
  353. #endif
  354. //
  355. // We load/unload wow32.dll here. This is used in the thunking code which
  356. // just does GetModuleHandle on it. This is not really necessary in
  357. // Daytona but is in Chicago.
  358. //
  359. // WORSE: IT IS IMPERATIVE TO NOT DO THIS ON DAYTONA. The Daytona code
  360. // uses the fact the WOW32.DLL is loaded in the context of this process
  361. // as the indication that it is executing in the WOW process.
  362. #ifdef CHICAGO
  363. HMODULE hWow32 = NULL;
  364. #endif
  365. #endif
  366. #ifdef _WIN32
  367. //--------------------------------------------------------------------------;
  368. //
  369. // BOOL ICDllEntryPoint [32-bit]
  370. //
  371. // Description:
  372. // Called by msvideo's DllEntryPoint
  373. //
  374. // History:
  375. // 11/02/94 [frankye]
  376. //
  377. //--------------------------------------------------------------------------;
  378. #ifdef LS_THUNK32
  379. BOOL PASCAL ls_ThunkConnect32(LPCSTR pszDll16, LPCSTR pszDll32, HINSTANCE hinst, DWORD dwReason);
  380. BOOL PASCAL sl_ThunkConnect32(LPCSTR pszDll16, LPCSTR pszDll32, HINSTANCE hinst, DWORD dwReason);
  381. #endif
  382. BOOL WINAPI ICDllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  383. {
  384. switch (fdwReason)
  385. {
  386. case DLL_PROCESS_ATTACH:
  387. {
  388. //DPFS(dbgInit, 0, "ICDllEntryPoint(DLL_PROCESS_ATTACH)");
  389. #ifdef DEBUGLOAD
  390. if (gdwLoadFlags & ICLOAD_CALLED) {
  391. #ifdef DEBUG
  392. DPF(("!IC open crit sec already set up"));
  393. #endif
  394. }
  395. gdwLoadFlags |= ICLOAD_CALLED;
  396. gdwLoadFlags &= ~ICUNLOAD_CALLED;
  397. #endif
  398. InitializeCriticalSection(&ICOpenCritSec);
  399. #ifdef LS_THUNK32
  400. hWow32 = LoadLibrary(TEXT("WOW32.DLL"));
  401. ls_ThunkConnect32(TEXT("MSVIDEO.DLL"), TEXT("MSVFW32.DLL"), hinstDLL, fdwReason);
  402. sl_ThunkConnect32(TEXT("MSVIDEO.DLL"), TEXT("MSVFW32.DLL"), hinstDLL, fdwReason);
  403. #endif
  404. return TRUE;
  405. }
  406. case DLL_PROCESS_DETACH:
  407. {
  408. //DPFS(dbgInit, 0, "ICDllEntryPoint(DLL_PROCESS_DETACH)");
  409. #ifdef LS_THUNK32
  410. ls_ThunkConnect32(TEXT("MSVIDEO.DLL"), TEXT("MSVFW32.DLL"), hinstDLL, fdwReason);
  411. sl_ThunkConnect32(TEXT("MSVIDEO.DLL"), TEXT("MSVFW32.DLL"), hinstDLL, fdwReason);
  412. if (NULL != hWow32) FreeLibrary(hWow32);
  413. #endif
  414. DeleteCriticalSection(&ICOpenCritSec);
  415. #ifdef DEBUGLOAD
  416. gdwLoadFlags |= ICUNLOAD_CALLED;
  417. gdwLoadFlags &= ~ICLOAD_CALLED;
  418. #endif
  419. if (lpICInfoMem) {
  420. GlobalFreePtr(lpICInfoMem);
  421. lpICInfoMem = NULL;
  422. }
  423. #ifdef CHICAGO
  424. dbgCheckShutdown();
  425. #endif
  426. return TRUE;
  427. }
  428. }
  429. return TRUE;
  430. }
  431. #else
  432. //--------------------------------------------------------------------------;
  433. //
  434. // BOOL ICDllEntryPoint [16-bit]
  435. //
  436. // Description:
  437. // Called by msvideo's DllEntryPoint
  438. //
  439. // History:
  440. // 11/02/94 [frankye]
  441. //
  442. //--------------------------------------------------------------------------;
  443. BOOL FAR PASCAL ls_ThunkConnect16(LPCSTR pszDll16, LPCSTR pszDll32, HINSTANCE hinst, DWORD dwReason);
  444. BOOL FAR PASCAL sl_ThunkConnect16(LPCSTR pszDll16, LPCSTR pszDll32, HINSTANCE hinst, DWORD dwReason);
  445. BOOL FAR PASCAL ICDllEntryPoint(DWORD dwReason, HINSTANCE hinstDLL, WORD wDS, WORD wHeapSize, DWORD dwReserved1, WORD wReserved2)
  446. {
  447. PICMGARB pig;
  448. DPFS(dbgInit, 0, "ICDllEntryPoint()");
  449. switch (dwReason)
  450. {
  451. case 1:
  452. {
  453. if (NULL == (pig = pigFind()))
  454. {
  455. if (NULL == (pig = pigNew()))
  456. {
  457. return FALSE;
  458. }
  459. }
  460. #ifdef LS_THUNK16
  461. ls_ThunkConnect16(TEXT("MSVIDEO.DLL"), TEXT("MSVFW32.DLL"), hinstDLL, dwReason);
  462. sl_ThunkConnect16(TEXT("MSVIDEO.DLL"), TEXT("MSVFW32.DLL"), hinstDLL, dwReason);
  463. #endif
  464. if (1 == ++pig->cUsage)
  465. {
  466. DPFS(dbgInit, 0, "ICProcessAttach: New process %08lXh", pig->pid);
  467. //
  468. // We can do one-time-per-process init here...
  469. //
  470. }
  471. return TRUE;
  472. }
  473. case 0:
  474. {
  475. if (NULL == (pig = pigFind()))
  476. {
  477. DPF(0, "!ICProcessDetach: ERROR: Being freed by process %08lXh in which it was not loaded", GetCurrentProcessId());
  478. DebugErr(DBF_ERROR, "ICProcessDetach: ERROR: Being freed by a process in which it was not loaded");
  479. return FALSE;
  480. }
  481. if (0 == --pig->cUsage)
  482. {
  483. //
  484. // We can do one-time-per-process termination here...
  485. //
  486. DPFS(dbgInit, 0, "ICProcessDetach: Terminating for process %08lXh", pig->pid);
  487. #ifdef NT_THUNK16
  488. genthunkTerminate(pig);
  489. #endif
  490. pigDelete(pig);
  491. dbgCheckShutdown();
  492. }
  493. #ifdef LS_THUNK16
  494. ls_ThunkConnect16(TEXT("MSVIDEO.DLL"), TEXT("MSVFW32.DLL"), hinstDLL, dwReason);
  495. sl_ThunkConnect16(TEXT("MSVIDEO.DLL"), TEXT("MSVFW32.DLL"), hinstDLL, dwReason);
  496. #endif
  497. return TRUE;
  498. }
  499. }
  500. return TRUE;
  501. }
  502. #endif
  503. /*****************************************************************************
  504. ****************************************************************************/
  505. __inline BOOL ICValid(HIC hic)
  506. {
  507. PIC pic = (PIC)hic;
  508. if (pic < &aicConverters[0] ||
  509. pic >= &aicConverters[MAX_CONVERTERS] ||
  510. pic->dwSmag != SMAG)
  511. {
  512. DebugErr(DBF_ERROR, "Invalid HIC\r\n");
  513. return FALSE;
  514. }
  515. return TRUE;
  516. }
  517. /*****************************************************************************
  518. ****************************************************************************/
  519. #define V_HIC(hic) \
  520. if (!ICValid(hic)) \
  521. return ICERR_BADHANDLE;
  522. /*****************************************************************************
  523. * @doc INTERNAL IC
  524. *
  525. * @api BOOL | ICCleanup | This function is called when a task exits or
  526. * MSVIDEO.DLL is being unloaded.
  527. *
  528. * @parm HTASK | hTask | the task being terminated, NULL if DLL being unloaded
  529. *
  530. * @rdesc Returns nothing
  531. *
  532. * @comm currently MSVIDEO only calles this function from it's WEP()
  533. *
  534. ****************************************************************************/
  535. void FAR PASCAL ICCleanup(HTASK hTask)
  536. {
  537. int i;
  538. PIC pic;
  539. //
  540. // free all HICs
  541. //
  542. for (i=0; i < giMaxConverters; i++)
  543. {
  544. pic = &aicConverters[i];
  545. if (pic->dwDriver != 0L && (pic->hTask == hTask || hTask == NULL))
  546. {
  547. ROUT("Decompressor left open, closing\r\n");
  548. ICClose((HIC)pic);
  549. }
  550. }
  551. #ifdef N_MODULES
  552. //
  553. // free the module cache.
  554. //
  555. for (i=0; i<N_MODULES; i++)
  556. CacheModule(NULL);
  557. #endif
  558. }
  559. /*****************************************************************************
  560. * @doc EXTERNAL IC ICAPPS
  561. *
  562. * @api BOOL | ICInstall | This function installs a new compressor
  563. * or decompressor.
  564. *
  565. * @parm DWORD | fccType | Specifies a four-character code indicating the
  566. * type of data used by the compressor or decompressor. Use 'vidc'
  567. * for a video compressor or decompressor.
  568. *
  569. * @parm DWORD | fccHandler | Specifies a four-character code identifying
  570. * a specific compressor or decompressor.
  571. *
  572. * @parm LPARAM | lParam | Specifies a pointer to a zero-terminated
  573. * string containing the name of the compressor or decompressor,
  574. * or it specifies a far pointer to a function used for compression
  575. * or decompression. The contents of this parameter are defined
  576. * by the flags set for <p wFlags>.
  577. *
  578. * @parm LPSTR | szDesc | Specifies a pointer to a zero-terminated string
  579. * describing the installed compressor. Not use.
  580. *
  581. * @parm UINT | wFlags | Specifies flags defining the contents of <p lParam>.
  582. * The following flags are defined:
  583. *
  584. * @flag ICINSTALL_DRIVER | Indicates <p lParam> is a pointer to a zero-terminated
  585. * string containing the name of the compressor to install.
  586. *
  587. * @flag ICINSTALL_FUNCTION | Indicates <p lParam> is a far pointer to
  588. * a compressor function. This function should
  589. * be structured like the <f DriverProc> entry
  590. * point function used by compressors.
  591. *
  592. * @rdesc Returns TRUE if successful.
  593. *
  594. * @comm Applications must still open the installed compressor or
  595. * decompressor before it can use the compressor or decompressor.
  596. *
  597. * Usually, compressors and decompressors are installed by the user
  598. * with the Drivers option of the Control Panel.
  599. *
  600. * If your application installs a function as a compressor or
  601. * decompressor, it should remove the compressor or decompressor
  602. * with <f ICRemove> before it terminates. This prevents other
  603. * applications from trying to access the function when it is not
  604. * available.
  605. *
  606. *
  607. * @xref <f ICRemove>
  608. ****************************************************************************/
  609. BOOL VFWAPI ICInstall(DWORD fccType, DWORD fccHandler, LPARAM lParam, LPSTR szDesc, UINT wFlags)
  610. {
  611. TCHAR achKey[20];
  612. TCHAR buf[256];
  613. DWORD n;
  614. PIC pic;
  615. ICEnterCrit(&ICOpenCritSec);
  616. fccType = Fix4CC(fccType);
  617. fccHandler = Fix4CC(fccHandler);
  618. if ((pic = FindConverter(fccType, fccHandler)) == NULL)
  619. pic = FindConverter(0L, 0L);
  620. if (wFlags & ICINSTALL_DRIVER)
  621. {
  622. //
  623. // dwConverter is the file name of a driver to install.
  624. //
  625. ictokey(fccType, fccHandler, achKey);
  626. #ifdef UNICODE
  627. if (wFlags & ICINSTALL_UNICODE) {
  628. lstrcpy(buf, (LPWSTR)lParam);
  629. n = lstrlen(buf) + 1; // Point past the terminating zero;
  630. if (szDesc)
  631. {
  632. lstrcpyn(buf+n, (LPWSTR)szDesc, NUMELMS(buf)-n);
  633. n += lstrlen(buf+n);
  634. }
  635. buf[n]=0; // Always guarantee a second string - even if a null one
  636. } else {
  637. // Convert the ANSI strings to UNICODE
  638. n = 1 + wsprintf(buf, TEXT("%hs"), (LPSTR) lParam);
  639. if (szDesc) {
  640. n += 1 + wsprintf(buf+n, TEXT("%hs"), szDesc);
  641. }
  642. }
  643. // Buf now contains two strings, the second of which may be null (the description)
  644. #else
  645. lstrcpy(buf, (LPSTR)lParam);
  646. if (szDesc)
  647. {
  648. lstrcat(buf, TEXT(" "));
  649. lstrcat(buf, szDesc);
  650. }
  651. #endif
  652. ICLeaveCrit(&ICOpenCritSec);
  653. // Data is written (via the inifilemapping) to
  654. // HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Drivers32
  655. // HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Drivers.desc
  656. if (myWritePrivateProfileString(gszDrivers,achKey,buf))
  657. {
  658. // delete the installable compressors entry for this driver
  659. myWritePrivateProfileString(gszIniSect,achKey,NULL);
  660. return TRUE;
  661. }
  662. return(FALSE);
  663. }
  664. else if (wFlags & ICINSTALL_FUNCTION)
  665. {
  666. if (pic == NULL)
  667. {
  668. ICLeaveCrit(&ICOpenCritSec);
  669. return FALSE;
  670. }
  671. pic->dwSmag = SMAG;
  672. pic->fccType = fccType;
  673. pic->fccHandler = fccHandler;
  674. pic->dwDriver = 0L;
  675. pic->hDriver = NULL;
  676. pic->DriverProc = (DRIVERPROC)lParam;
  677. DPF(("ICInstall, fccType=%4.4hs, Handler=%4.4hs, Pic %x\n", (LPSTR)&fccType, (LPSTR)&fccHandler, pic));
  678. ICLeaveCrit(&ICOpenCritSec);
  679. return TRUE;
  680. }
  681. #if 0
  682. else if (wFlags & ICINSTALL_HDRV)
  683. {
  684. if (pic == NULL)
  685. {
  686. ICLeaveCrit(&ICOpenCritSec);
  687. return FALSE;
  688. }
  689. pic->fccType = fccType;
  690. pic->fccHandler = fccHandler;
  691. pic->hDriver = (HDRVR)lParam;
  692. pic->dwDriver = 0L;
  693. pic->DrvProc = NULL;
  694. ICLeaveCrit(&ICOpenCritSec);
  695. return TRUE;
  696. }
  697. #endif
  698. ICLeaveCrit(&ICOpenCritSec);
  699. return FALSE;
  700. }
  701. /*****************************************************************************
  702. * @doc EXTERNAL IC ICAPPS
  703. *
  704. * @api BOOL | ICRemove | This function removes an installed compressor.
  705. *
  706. * @parm DWORD | fccType | Specifies a four-character code indicating the
  707. * type of data used by the compressor. Use 'vidc' for video compressors.
  708. *
  709. * @parm DWORD | fccHandler | Specifies a four-character code identifying
  710. * a specific compressor.
  711. *
  712. * @parm UINT | wFlags | Not used.
  713. *
  714. * @rdesc Returns TRUE if successful.
  715. *
  716. * @xref <f ICInstall>
  717. ****************************************************************************/
  718. BOOL VFWAPI ICRemove(DWORD fccType, DWORD fccHandler, UINT wFlags)
  719. {
  720. TCHAR achKey[20];
  721. PIC pic;
  722. ICEnterCrit(&ICOpenCritSec);
  723. fccType = Fix4CC(fccType);
  724. fccHandler = Fix4CC(fccHandler);
  725. if (pic = FindConverter(fccType, fccHandler))
  726. {
  727. int i;
  728. //
  729. // we should realy keep usage counts!!!
  730. //
  731. for (i=0; i<giMaxConverters; i++)
  732. {
  733. if (pic->DriverProc == aicConverters[i].DriverProc)
  734. {
  735. DPF(("ACK! Handler is in use\r\n"));
  736. pic->DriverProc = (DRIVERPROC)DriverProcNull;
  737. }
  738. }
  739. ICClose((HIC)pic);
  740. }
  741. else
  742. {
  743. // Remove the information
  744. ictokey(fccType, fccHandler, achKey);
  745. myWritePrivateProfileString(gszIniSect,achKey,NULL);
  746. myWritePrivateProfileString(gszDrivers,achKey,NULL);
  747. }
  748. ICLeaveCrit(&ICOpenCritSec);
  749. return TRUE;
  750. }
  751. //
  752. // Internal routine to enumerate all the installed drivers
  753. //
  754. BOOL ReadDriversInfo()
  755. {
  756. LPSTR psz = NULL; // THIS IS ALWAYS an ANSI string pointer!
  757. if (lpICInfoMem == NULL) {
  758. UINT cbBuffer = 125 * sizeof(TCHAR);
  759. UINT cchBuffer;
  760. ICEnterCrit(&ICOpenCritSec);
  761. for (;;)
  762. {
  763. lpICInfoMem = GlobalAllocPtr(GMEM_SHARE | GHND, cbBuffer);
  764. if (!lpICInfoMem) {
  765. DPF(("Out of memory for SYSTEM.INI keys\r\n"));
  766. ICLeaveCrit(&ICOpenCritSec);
  767. return FALSE;
  768. }
  769. cchBuffer = (UINT)myGetPrivateProfileString(gszDrivers,
  770. NULL,
  771. szNull,
  772. lpICInfoMem,
  773. cbBuffer / sizeof(TCHAR));
  774. if (cchBuffer < ((cbBuffer/sizeof(TCHAR)) - 5)) {
  775. cchBuffer += (UINT)myGetPrivateProfileString(gszIniSect,
  776. NULL,
  777. szNull,
  778. (LPTSTR)lpICInfoMem + cchBuffer,
  779. (cbBuffer/sizeof(TCHAR)) - cchBuffer);
  780. //
  781. // if all of the INI data fit, we can
  782. // leave the loop
  783. //
  784. if (cchBuffer < ((cbBuffer/sizeof(TCHAR)) - 5))
  785. break;
  786. }
  787. GlobalFreePtr(lpICInfoMem), lpICInfoMem = NULL;
  788. //
  789. // if cannot fit drivers section in 32k, then something is horked
  790. // with the section... so let's bail.
  791. //
  792. if (cbBuffer >= 0x8000) {
  793. DPF(("SYSTEM.INI keys won't fit in 32K????\r\n"));
  794. ICLeaveCrit(&ICOpenCritSec);
  795. return FALSE;
  796. }
  797. //
  798. // double the size of our buffer and try again.
  799. //
  800. cbBuffer *= 2;
  801. DPF(("Increasing size of SYSTEM.INI buffer to %d\r\n", cbBuffer));
  802. }
  803. #if defined UNICODE
  804. // convert the INI data from UNICODE to ANSI
  805. //
  806. psz = GlobalAllocPtr (GMEM_SHARE | GHND, cchBuffer + 7);
  807. if ( ! psz) {
  808. GlobalFreePtr (lpICInfoMem), lpICInfoMem = NULL;
  809. ICLeaveCrit(&ICOpenCritSec);
  810. return FALSE;
  811. }
  812. mmWideToAnsi (psz, lpICInfoMem, cchBuffer+2);
  813. GlobalFreePtr (lpICInfoMem);
  814. lpICInfoMem = psz;
  815. #endif
  816. // convert codec information to lowercase
  817. for (psz = lpICInfoMem; *psz != 0; psz += lstrlenA(psz) + 1)
  818. {
  819. #if 0 // we only put valid codecs into lpICInfoMem these days
  820. if (psz[4] != '.')
  821. continue;
  822. #endif
  823. // convert this piece to lowercase
  824. CharLowerA (psz);
  825. DPF(("Compressor: %hs\n", psz));
  826. }
  827. ICLeaveCrit(&ICOpenCritSec);
  828. }
  829. return (lpICInfoMem != NULL);
  830. }
  831. /*****************************************************************************
  832. * @doc EXTERNAL IC ICAPPS
  833. *
  834. * @api BOOL | ICInfo | This function returns information about
  835. * specific installed compressors, or it enumerates
  836. * the compressors installed.
  837. *
  838. * @parm DWORD | fccType | Specifies a four-character code indicating
  839. * the type of compressor. To match all compressor types specify zero.
  840. *
  841. * @parm DWORD | fccHandler | Specifies a four-character code identifying
  842. * a specific compressor, or a number between 0 and the number
  843. * of installed compressors of the type specified by <t fccType>.
  844. *
  845. * @parm ICINFO FAR * | lpicinfo | Specifies a far pointer to a
  846. * <t ICINFO> structure used to return
  847. * information about the compressor.
  848. *
  849. * @comm This function does not return full informaiton about
  850. * a compressor or decompressor. Use <f ICGetInfo> for full
  851. * information.
  852. *
  853. * @rdesc Returns TRUE if successful.
  854. ****************************************************************************/
  855. #ifdef NT_THUNK16
  856. BOOL VFWAPI ICInfoInternal(DWORD fccType, DWORD fccHandler, ICINFO FAR * lpicinfo);
  857. // If we are compiling the thunks, then the ICINFO entry point calls
  858. // the 32 bit thunk, or calls the real ICInfo code (as ICInfoInternal).
  859. // We deliberately give precedence to 16 bit compressors, although this
  860. // ordering can be trivially changed.
  861. // ??: Should we allow an INI setting to change the order?
  862. BOOL VFWAPI ICInfo(DWORD fccType, DWORD fccHandler, ICINFO FAR * lpicinfo)
  863. {
  864. #ifdef DEBUG
  865. BOOL fResult;
  866. #endif
  867. //
  868. // See if there is a 32-bit compressor we can use
  869. //
  870. if (ICInfoInternal(fccType, fccHandler, lpicinfo)) {
  871. return(TRUE);
  872. }
  873. #ifdef DEBUG
  874. fResult = (ICInfo32(fccType, fccHandler, lpicinfo));
  875. DPF(("ICInfo32 returned %s\r\n", (fResult ? "TRUE" : "FALSE")));
  876. return fResult;
  877. #else
  878. return (ICInfo32(fccType, fccHandler, lpicinfo));
  879. #endif
  880. }
  881. // Now map ICInfo calls to ICInfoInternal for the duration of the ICInfo
  882. // routine. This affects the two recursive calls within ICInfo.
  883. #define ICInfo ICInfoInternal
  884. #endif // NT_THUNK16
  885. BOOL VFWAPI ICInfo(DWORD fccType, DWORD fccHandler, ICINFO FAR * lpicinfo)
  886. {
  887. LPSTR psz = NULL; // THIS IS ALWAYS an ANSI string pointer!
  888. TCHAR buf[128];
  889. TCHAR achKey[20];
  890. int i;
  891. int iComp;
  892. PIC pic;
  893. if (lpicinfo == NULL)
  894. return FALSE;
  895. if (fccType > 0 && fccType < 256) {
  896. DPF(("fcctype invalid (%d)\n", fccType));
  897. return FALSE;
  898. }
  899. fccType = Fix4CC(fccType);
  900. fccHandler = Fix4CC(fccHandler);
  901. if (fccType != 0 && fccHandler > 256)
  902. {
  903. //
  904. // the user has given us a specific fccType and fccHandler
  905. // get the info and return.
  906. //
  907. if (pic = FindConverter(fccType, fccHandler))
  908. {
  909. ICGetInfo((HIC)pic, lpicinfo, sizeof(ICINFO));
  910. return TRUE;
  911. }
  912. else
  913. {
  914. lpicinfo->dwSize = sizeof(ICINFO);
  915. lpicinfo->fccType = fccType;
  916. lpicinfo->fccHandler = fccHandler;
  917. lpicinfo->dwFlags = 0;
  918. lpicinfo->dwVersionICM = ICVERSION;
  919. lpicinfo->dwVersion = 0;
  920. lpicinfo->szDriver[0] = 0;
  921. lpicinfo->szDescription[0] = 0;
  922. lpicinfo->szName[0] = 0;
  923. DPF(("ICInfo, fccType=%4.4hs, Handler=%4.4hs\n", (LPSTR)&fccType, (LPSTR)&fccHandler));
  924. ictokey(fccType, fccHandler, achKey);
  925. if (!myGetPrivateProfileString(gszDrivers,achKey,szNull,buf,NUMELMS(buf)) &&
  926. !myGetPrivateProfileString(gszIniSect,achKey,szNull,buf,NUMELMS(buf)))
  927. {
  928. DPF(("NO information in DRIVERS section\n"));
  929. return FALSE;
  930. }
  931. for (i=0; buf[i] && buf[i] != TEXT(' '); ++i)
  932. lpicinfo->szDriver[i] = buf[i];
  933. lpicinfo->szDriver[i] = 0;
  934. //
  935. // the driver must be opened to get description
  936. //
  937. lpicinfo->szDescription[0] = 0;
  938. return TRUE;
  939. }
  940. }
  941. else
  942. {
  943. //
  944. // the user has given us a specific fccType and a
  945. // ordinal for fccHandler, enum the compressors, looking for
  946. // the nth compressor of 'fccType'
  947. //
  948. iComp = (int)fccHandler;
  949. //
  950. // walk the installed converters.
  951. //
  952. for (i=0; i < giMaxConverters; i++)
  953. {
  954. pic = &aicConverters[i];
  955. if (pic->fccType != 0 &&
  956. (fccType == 0 || pic->fccType == fccType) &&
  957. pic->dwDriver == 0L && iComp-- == 0)
  958. {
  959. return ICInfo(pic->fccType, pic->fccHandler, lpicinfo);
  960. }
  961. }
  962. //
  963. // read all the keys. from [Drivers] and [Instalable Compressors]
  964. // if we havent read them before.
  965. //
  966. // NOTE: what we get back will always be ANSI or WIDE depending
  967. // on whether UNICODE is defined. If WIDE, we convert to
  968. // ANSI before exiting the if statement.
  969. //
  970. if (lpICInfoMem == NULL) {
  971. if (!ReadDriversInfo())
  972. return(FALSE);
  973. }
  974. // set our pointer psz to point to the beginning of
  975. // the buffer of INI information we just read.
  976. // remember that we KNOW that this is ANSI data now.
  977. //
  978. //assert (sizeof(*psz) == 1);
  979. //assert (lpICInfoMem != NULL);
  980. // loop through the buffer until we get to a double '\0'
  981. // which indicates the end of the data.
  982. //
  983. for (psz = lpICInfoMem; *psz != 0; psz += lstrlenA(psz) + 1)
  984. {
  985. #if 0 // there can only be valid codec in the memory block
  986. if (psz[4] != '.')
  987. continue;
  988. #endif
  989. // convert this piece to lowercase and check to see
  990. // if it matches the requested type signature
  991. //
  992. // NO. Done when first read. CharLowerA (psz);
  993. // if this is a match, and it's the one we wanted,
  994. // return its ICINFO
  995. //
  996. if ((fccType == 0 || fccType == *(DWORD UNALIGNED FAR *)psz)
  997. && iComp-- == 0)
  998. {
  999. return ICInfo(*(DWORD UNALIGNED FAR *)psz,
  1000. *(DWORD UNALIGNED FAR *)&psz[5],
  1001. lpicinfo);
  1002. }
  1003. }
  1004. #ifdef DAYTONA
  1005. // If we get to here, then the index is higher than the number
  1006. // of installed compressors.
  1007. //
  1008. // Write the number of compressors found into the structure.
  1009. // This value is used by the NT thunks to pass back to the 16
  1010. // bit side the maximum number of 32 bit compressors.
  1011. lpicinfo->fccHandler = (int)fccHandler-iComp;
  1012. // LATER: we MUST enumerate the count of installed msvideo drivers
  1013. // as well. However, lets see if this fixes the Adobe Premiere problem.
  1014. #endif
  1015. //
  1016. // now walk the msvideo drivers. these are listed in system.ini
  1017. // like so:
  1018. //
  1019. // [Drivers]
  1020. // MSVideo = driver
  1021. // MSVideo1 = driver
  1022. // MSVideoN =
  1023. //
  1024. if (fccType == 0 || fccType == ICTYPE_VCAP)
  1025. {
  1026. lstrcpy(achKey, szMSVideo);
  1027. if (iComp > 0)
  1028. wsprintf(achKey+lstrlen(achKey), (LPVOID)"%d", iComp);
  1029. if (!myGetPrivateProfileString(gszDrivers,achKey,szNull,buf,NUMELMS(buf)))
  1030. return FALSE;
  1031. lpicinfo->dwSize = sizeof(ICINFO);
  1032. lpicinfo->fccType = ICTYPE_VCAP;
  1033. lpicinfo->fccHandler = iComp;
  1034. lpicinfo->dwFlags = 0;
  1035. lpicinfo->dwVersionICM = ICVERSION; //??? right for video?
  1036. lpicinfo->dwVersion = 0;
  1037. lpicinfo->szDriver[0] = 0;
  1038. lpicinfo->szDescription[0] = 0;
  1039. lpicinfo->szName[0] = 0;
  1040. for (i=0; buf[i] && buf[i] != TEXT(' '); i++)
  1041. lpicinfo->szDriver[i] = buf[i];
  1042. lpicinfo->szDriver[i] = 0;
  1043. return TRUE;
  1044. }
  1045. return FALSE;
  1046. }
  1047. }
  1048. #undef ICInfo
  1049. BOOL VFWAPI ICInfoInternal(DWORD fccType, DWORD fccHandler, ICINFO FAR * lpicinfo)
  1050. {
  1051. return(ICInfo(fccType, fccHandler, lpicinfo));
  1052. }
  1053. ////////////////////////////////////////////////////////////////////////////
  1054. ////////////////////////////////////////////////////////////////////////////
  1055. /*****************************************************************************
  1056. * @doc EXTERNAL IC ICAPPS
  1057. *
  1058. * @api LRESULT | ICGetInfo | This function obtains information about
  1059. * a compressor.
  1060. *
  1061. * @parm HIC | hic | Specifies a handle to a compressor.
  1062. *
  1063. * @parm ICINFO FAR * | lpicinfo | Specifies a far pointer to <t ICINFO> structure
  1064. * used to return information about the compressor.
  1065. *
  1066. * @parm DWORD | cb | Specifies the size, in bytes, of the structure pointed to
  1067. * by <p lpicinfo>.
  1068. *
  1069. * @rdesc Return the number of bytes copied into the data structure,
  1070. * or zero if an error occurs.
  1071. *
  1072. * @comm Use <f ICInfo> for full information about a compressor.
  1073. *
  1074. ****************************************************************************/
  1075. LRESULT VFWAPI ICGetInfo(HIC hic, ICINFO FAR *picinfo, DWORD cb)
  1076. {
  1077. PIC pic = (PIC)hic;
  1078. LRESULT dw;
  1079. V_HIC(hic);
  1080. picinfo->dwSize = sizeof(ICINFO);
  1081. picinfo->fccType = 0;
  1082. picinfo->fccHandler = 0;
  1083. picinfo->dwFlags = 0;
  1084. picinfo->dwVersionICM = ICVERSION;
  1085. picinfo->dwVersion = 0;
  1086. picinfo->szDriver[0] = 0;
  1087. picinfo->szDescription[0] = 0;
  1088. picinfo->szName[0] = 0;
  1089. #ifdef NT_THUNK16
  1090. if (!Is32bitHandle(hic))
  1091. #endif //NT_THUNK16
  1092. if (pic->hDriver)
  1093. {
  1094. #if defined _WIN32 && ! defined UNICODE
  1095. char szDriver[NUMELMS(picinfo->szDriver)];
  1096. GetModuleFileName (GetDriverModuleHandle (pic->hDriver),
  1097. szDriver, sizeof(szDriver));
  1098. mmAnsiToWide (picinfo->szDriver, szDriver, NUMELMS(szDriver));
  1099. #else
  1100. GetModuleFileName(GetDriverModuleHandle (pic->hDriver),
  1101. picinfo->szDriver, sizeof(picinfo->szDriver));
  1102. #endif
  1103. }
  1104. dw = ICSendMessage((HIC)pic, ICM_GETINFO, (DWORD_PTR)picinfo, cb);
  1105. return dw;
  1106. }
  1107. /*****************************************************************************
  1108. * @doc EXTERNAL IC ICAPPS
  1109. *
  1110. * @api LRESULT | ICSendMessage | This function sends a
  1111. * message to a compressor.
  1112. *
  1113. * @parm HIC | hic | Specifies the handle of the
  1114. * compressor to receive the message.
  1115. *
  1116. * @parm UINT | wMsg | Specifies the message to send.
  1117. *
  1118. * @parm DWORD | dw1 | Specifies additional message-specific information.
  1119. *
  1120. * @parm DWORD | dw2 | Specifies additional message-specific information.
  1121. *
  1122. * @rdesc Returns a message-specific result.
  1123. ****************************************************************************/
  1124. LRESULT VFWAPI ICSendMessage(HIC hic, UINT msg, DWORD_PTR dw1, DWORD_PTR dw2)
  1125. {
  1126. PIC pic = (PIC)hic;
  1127. LRESULT l;
  1128. V_HIC(hic);
  1129. #ifdef NT_THUNK16
  1130. //
  1131. // If it's a 32-bit handle then send it to the 32-bit code
  1132. // We need to take some extra care with ICM_DRAW_SUGGESTFORMAT
  1133. // which can include a HIC in the ICDRAWSUGGEST structure.
  1134. //
  1135. #define ICD(dw1) ((ICDRAWSUGGEST FAR *)(dw1))
  1136. if (pic->h32) {
  1137. if ((msg == ICM_DRAW_SUGGESTFORMAT)
  1138. && (((ICDRAWSUGGEST FAR *)dw1)->hicDecompressor))
  1139. {
  1140. // We are in the problem area.
  1141. // IF the hicDecompressor field is NULL, pass as is.
  1142. // IF it identifies a 32 bit decompressor, translate the handle
  1143. // OTHERWISE... what? We have a 32 bit compressor, that is
  1144. // being told it can use a 16 bit decompressor!!
  1145. if ( ((PIC) (((ICDRAWSUGGEST FAR *)dw1)->hicDecompressor))->h32)
  1146. {
  1147. ICD(dw1)->hicDecompressor
  1148. = (HIC)((PIC)(ICD(dw1)->hicDecompressor))->h32;
  1149. } else
  1150. {
  1151. ICD(dw1)->hicDecompressor = NULL; // Sigh...
  1152. }
  1153. }
  1154. return ICSendMessage32(pic->h32, msg, dw1, dw2);
  1155. }
  1156. #endif //NT_THUNK16
  1157. ICDebugMessage(hic, msg, dw1, dw2);
  1158. l = pic->DriverProc(pic->dwDriver, (HDRVR)1, msg, dw1, dw2);
  1159. #if 1 //!!! is this realy needed! !!!yes I think it is
  1160. //
  1161. // special case some messages and give default values.
  1162. //
  1163. if (l == ICERR_UNSUPPORTED)
  1164. {
  1165. switch (msg)
  1166. {
  1167. case ICM_GETDEFAULTQUALITY:
  1168. *((LPDWORD)dw1) = ICQUALITY_HIGH;
  1169. l = ICERR_OK;
  1170. break;
  1171. case ICM_GETDEFAULTKEYFRAMERATE:
  1172. *((LPDWORD)dw1) = 15;
  1173. l = ICERR_OK;
  1174. break;
  1175. }
  1176. }
  1177. #endif
  1178. return ICDebugReturn(l);
  1179. }
  1180. #ifndef _WIN32
  1181. /*****************************************************************************
  1182. * @doc EXTERNAL IC ICAPPS
  1183. *
  1184. * @api LRESULT | ICMessage | This function sends a
  1185. * message and a variable number of arguments to a compressor.
  1186. * If a macro is defined for the message you want to send,
  1187. * use the macro rather than this function.
  1188. *
  1189. * @parm HIC | hic | Specifies the handle of the
  1190. * compressor to receive the message.
  1191. *
  1192. * @parm UINT | msg | Specifies the message to send.
  1193. *
  1194. * @parm UINT | cb | Specifies the size, in bytes, of the
  1195. * optional parameters. (This is usually the size of the data
  1196. * structure used to store the parameters.)
  1197. *
  1198. * @parm . | . . | Represents the variable number of arguments used
  1199. * for the optional parameters.
  1200. *
  1201. * @rdesc Returns a message-specific result.
  1202. ****************************************************************************/
  1203. LRESULT VFWAPIV ICMessage(HIC hic, UINT msg, UINT cb, ...)
  1204. {
  1205. // NOTE no LOADDS!
  1206. #ifndef _WIN32
  1207. return ICSendMessage(hic, msg, (DWORD_PTR)(LPVOID)(&cb+1), cb);
  1208. #else
  1209. va_list va;
  1210. va_start(va, cb);
  1211. va_end(va);
  1212. // nice try, but doesn't work. va is larger than 4 bytes.
  1213. return ICSendMessage(hic, msg, (DWORD_PTR)va, cb);
  1214. #endif
  1215. }
  1216. // on Win32, ICMessage is not supported. All compman.h macros that call
  1217. // it are defined in compman.h as static inline functions
  1218. #endif
  1219. /*****************************************************************************
  1220. * @doc EXTERNAL IC ICAPPS
  1221. *
  1222. * @api HIC | ICOpen | This function opens a compressor or decompressor.
  1223. *
  1224. * @parm DWORD | fccType | Specifies the type of compressor
  1225. * the caller is trying to open. For video, this is ICTYPE_VIDEO.
  1226. *
  1227. * @parm DWORD | fccHandler | Specifies a single preferred handler of the
  1228. * given type that should be tried first. Typically, this comes
  1229. * from the stream header in an AVI file.
  1230. *
  1231. * @parm UINT | wMode | Specifies a flag to defining the use of
  1232. * the compressor or decompressor.
  1233. * This parameter can contain one of the following values:
  1234. *
  1235. * @flag ICMODE_COMPRESS | Advises a compressor it is opened for compression.
  1236. *
  1237. * @flag ICMODE_FASTCOMPRESS | Advise a compressor it is open
  1238. * for fast (real-time) compression.
  1239. *
  1240. * @flag ICMODE_DECOMPRESS | Advises a decompressor it is opened for decompression.
  1241. *
  1242. * @flag ICMODE_FASTDECOMPRESS | Advises a decompressor it is opened
  1243. * for fast (real-time) decompression.
  1244. *
  1245. * @flag ICMODE_DRAW | Advises a decompressor it is opened
  1246. * to decompress an image and draw it directly to hardware.
  1247. *
  1248. * @flag ICMODE_QUERY | Advise a compressor or decompressor it is opened
  1249. * to obtain information.
  1250. *
  1251. * @rdesc Returns a handle to a compressor or decompressor
  1252. * if successful, otherwise it returns zero.
  1253. ****************************************************************************/
  1254. /* Helper functions for compression library */
  1255. HIC VFWAPI ICOpen(DWORD fccType, DWORD fccHandler, UINT wMode)
  1256. {
  1257. ICOPEN icopen;
  1258. ICINFO icinfo;
  1259. PIC pic, picT;
  1260. LRESULT dw;
  1261. ICEnterCrit(&ICOpenCritSec);
  1262. AnsiLowerBuff((LPSTR) &fccType, sizeof(DWORD));
  1263. AnsiLowerBuff((LPSTR) &fccHandler, sizeof(DWORD));
  1264. icopen.dwSize = sizeof(ICOPEN);
  1265. icopen.fccType = fccType;
  1266. icopen.fccHandler = fccHandler;
  1267. icopen.dwFlags = wMode;
  1268. icopen.dwError = 0;
  1269. DPF(("ICOpen('%4.4hs','%4.4hs)'\r\n", (LPSTR)&fccType, (LPSTR)&fccHandler));
  1270. if (!ICInfo(fccType, fccHandler, &icinfo))
  1271. {
  1272. RPF(("Unable to locate Compression module '%4.4hs' '%4.4hs'\r\n", (LPSTR)&fccType, (LPSTR)&fccHandler));
  1273. ICLeaveCrit(&ICOpenCritSec);
  1274. if((fccHandler == mmioFOURCC('i', 'v', '5', '0') ||
  1275. fccHandler == mmioFOURCC('i', 'v', '4', '1')) &&
  1276. fccType == mmioFOURCC('v', 'i', 'd', 'c'))
  1277. {
  1278. void IndeoAppCompat();
  1279. IndeoAppCompat();
  1280. }
  1281. return NULL;
  1282. }
  1283. pic = FindConverter(0L, 0L);
  1284. if (pic == NULL)
  1285. {
  1286. ICLeaveCrit(&ICOpenCritSec);
  1287. return NULL;
  1288. }
  1289. #ifdef NT_THUNK16
  1290. // Try and open on the 32 bit side first.
  1291. // This block and the one below can be interchanged to alter the order
  1292. // in which we try and open the compressor.
  1293. pic->dwSmag = SMAG;
  1294. pic->hTask = (HTASK)GetCurrentTask();
  1295. pic->h32 = ICOpen32(fccType, fccHandler, wMode);
  1296. if (pic->h32 != 0) {
  1297. pic->fccType = fccType;
  1298. pic->fccHandler = fccHandler;
  1299. pic->dwDriver = (DWORD_PTR) -1;
  1300. pic->DriverProc = NULL;
  1301. ICLeaveCrit(&ICOpenCritSec); // A noop for 16 bit code...but...
  1302. return (HIC)pic;
  1303. }
  1304. // Try and open on the 16 bit side
  1305. #endif //NT_THUNK16
  1306. pic->dwSmag = SMAG;
  1307. pic->hTask = GetCurrentTask();
  1308. if (icinfo.szDriver[0])
  1309. {
  1310. #ifdef DEBUG
  1311. DWORD time = timeGetTime();
  1312. //char ach[80];
  1313. #endif
  1314. pic->hDriver = LoadDriver(icinfo.szDriver, &pic->DriverProc);
  1315. #ifdef DEBUG
  1316. time = timeGetTime() - time;
  1317. DPF(("ICOPEN: LoadDriver(%ls) (%ldms) Module Handle==%8x\r\n", (LPSTR)icinfo.szDriver, time, pic->hDriver));
  1318. //wsprintfA(ach, "COMPMAN: LoadDriver(%ls) (%ldms)\r\n", (LPSTR)icinfo.szDriver, time);
  1319. //OutputDebugStringA(ach);
  1320. #endif
  1321. if (pic->hDriver == NULL)
  1322. {
  1323. pic->dwSmag = 0;
  1324. ICLeaveCrit(&ICOpenCritSec);
  1325. return NULL;
  1326. }
  1327. //
  1328. // now try to open the driver as a codec.
  1329. //
  1330. pic->dwDriver = ICSendMessage((HIC)pic, DRV_OPEN, 0, (DWORD_PTR)(LPVOID)&icopen);
  1331. //
  1332. // we want to be able to install 1.0 draw handlers in SYSTEM.INI as:
  1333. //
  1334. // VIDS.SMAG = SMAG.DRV
  1335. //
  1336. // but old driver's may not open iff fccType == 'vids' only if
  1337. // fccType == 'vidc'
  1338. //
  1339. // they also may not like ICMODE_DRAW
  1340. //
  1341. if (pic->dwDriver == 0 &&
  1342. icopen.dwError != 0 &&
  1343. fccType == streamtypeVIDEO)
  1344. {
  1345. if (wMode == ICMODE_DRAW)
  1346. icopen.dwFlags = ICMODE_DECOMPRESS;
  1347. icopen.fccType = ICTYPE_VIDEO;
  1348. pic->dwDriver = ICSendMessage((HIC)pic, DRV_OPEN, 0, (DWORD_PTR)(LPVOID)&icopen);
  1349. }
  1350. if (pic->dwDriver == 0)
  1351. {
  1352. ICClose((HIC)pic);
  1353. ICLeaveCrit(&ICOpenCritSec);
  1354. return NULL;
  1355. }
  1356. // open'ed ok mark these
  1357. pic->fccType = fccType;
  1358. pic->fccHandler = fccHandler;
  1359. }
  1360. else if (picT = FindConverter(fccType, fccHandler))
  1361. {
  1362. picT->dwSmag = SMAG;
  1363. dw = ICSendMessage((HIC)picT, DRV_OPEN, 0, (DWORD_PTR)(LPVOID)&icopen);
  1364. if (dw == 0)
  1365. {
  1366. pic->dwSmag = 0;
  1367. ICLeaveCrit(&ICOpenCritSec);
  1368. return NULL;
  1369. }
  1370. *pic = *picT;
  1371. pic->dwDriver = dw;
  1372. }
  1373. ICLeaveCrit(&ICOpenCritSec);
  1374. return (HIC)pic;
  1375. }
  1376. /*****************************************************************************
  1377. * @doc EXTERNAL IC ICAPPS
  1378. *
  1379. * @api HIC | ICOpenFunction | This function opens
  1380. * a compressor or decompressor defined as a function.
  1381. *
  1382. * @parm DWORD | fccType | Specifies the type of compressor
  1383. * the caller is trying to open. For video, this is ICTYPE_VIDEO.
  1384. *
  1385. * @parm DWORD | fccHandler | Specifies a single preferred handler of the
  1386. * given type that should be tried first. Typically, this comes
  1387. * from the stream header in an AVI file.
  1388. *
  1389. * @parm UINT | wMode | Specifies a flag to defining the use of
  1390. * the compressor or decompressor.
  1391. * This parameter can contain one of the following values:
  1392. *
  1393. * @flag ICMODE_COMPRESS | Advises a compressor it is opened for compression.
  1394. *
  1395. * @flag ICMODE_FASTCOMPRESS | Advises a compressor it is open
  1396. * for fast (real-time) compression.
  1397. *
  1398. * @flag ICMODE_DECOMPRESS | Advises a decompressor it is opened for decompression.
  1399. *
  1400. * @flag ICMODE_FASTDECOMPRESS | Advises a decompressor it is opened
  1401. * for fast (real-time) decompression.
  1402. *
  1403. * @flag ICMODE_DRAW | Advises a decompressor it is opened
  1404. * to decompress an image and draw it directly to hardware.
  1405. *
  1406. * @flag ICMODE_QUERY | Advises a compressor or decompressor it is opened
  1407. * to obtain information.
  1408. *
  1409. * @parm FARPROC | lpfnHandler | Specifies a pointer to the function
  1410. * used as the compressor or decompressor.
  1411. *
  1412. * @rdesc Returns a handle to a compressor or decompressor
  1413. * if successful, otherwise it returns zero.
  1414. ****************************************************************************/
  1415. HIC VFWAPI ICOpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode, FARPROC lpfnHandler)
  1416. {
  1417. ICOPEN icopen;
  1418. PIC pic;
  1419. LRESULT dw;
  1420. if (IsBadCodePtr(lpfnHandler))
  1421. return NULL;
  1422. #ifdef NT_THUNK16
  1423. // lpfnHandler points to 16 bit code that will be used as a compressor.
  1424. // We do not want this to go over to the 32 bit side, so only open on
  1425. // the 16 bit side.
  1426. #endif // NT_THUNK16
  1427. ICEnterCrit(&ICOpenCritSec);
  1428. AnsiLowerBuff((LPSTR) &fccType, sizeof(DWORD));
  1429. AnsiLowerBuff((LPSTR) &fccHandler, sizeof(DWORD));
  1430. icopen.dwSize = sizeof(ICOPEN);
  1431. icopen.fccType = fccType;
  1432. icopen.fccHandler = fccHandler;
  1433. icopen.dwFlags = wMode;
  1434. pic = FindConverter(0L, 0L);
  1435. if (pic == NULL) {
  1436. ICLeaveCrit(&ICOpenCritSec);
  1437. return NULL;
  1438. }
  1439. pic->dwSmag = SMAG;
  1440. pic->fccType = fccType;
  1441. pic->fccHandler = fccHandler;
  1442. pic->dwDriver = 0L;
  1443. pic->hDriver = NULL;
  1444. pic->DriverProc = (DRIVERPROC)lpfnHandler;
  1445. dw = ICSendMessage((HIC)pic, DRV_OPEN, 0, (DWORD_PTR)(LPVOID)&icopen);
  1446. if (dw == 0)
  1447. {
  1448. ICClose((HIC) pic);
  1449. ICLeaveCrit(&ICOpenCritSec);
  1450. return NULL;
  1451. }
  1452. pic->dwDriver = dw;
  1453. ICLeaveCrit(&ICOpenCritSec);
  1454. return (HIC)pic;
  1455. }
  1456. ////////////////////////////////////////////////////////////////////////////
  1457. ////////////////////////////////////////////////////////////////////////////
  1458. /*****************************************************************************
  1459. * @doc EXTERNAL IC ICAPPS
  1460. *
  1461. * @api LRESULT | ICClose | This function closes a compressor or decompressor.
  1462. *
  1463. * @parm HIC | hic | Specifies a handle to a compressor or decompressor.
  1464. *
  1465. * @rdesc Returns ICERR_OK if successful, otherwise it returns an error number.
  1466. *
  1467. ****************************************************************************/
  1468. LRESULT VFWAPI ICClose(HIC hic)
  1469. {
  1470. PIC pic = (PIC)hic;
  1471. V_HIC(hic);
  1472. #ifdef NT_THUNK16
  1473. if (pic->h32 != 0) {
  1474. LRESULT lres = ICClose32(pic->h32);
  1475. pic->h32 = 0; // Next user of this slot does not want h32 set
  1476. return(lres);
  1477. }
  1478. #endif //NT_THUNK16
  1479. #ifdef DEBUG
  1480. {
  1481. char ach[80];
  1482. if (pic->hDriver)
  1483. GetModuleFileNameA(GetDriverModuleHandle (pic->hDriver), ach, sizeof(ach));
  1484. else
  1485. ach[0] = 0;
  1486. DPF(("ICClose(%04X) %4.4hs.%4.4hs %s\r\n", hic, (LPSTR)&pic->fccType, (LPSTR)&pic->fccHandler, (LPSTR)ach));
  1487. }
  1488. #endif
  1489. #ifdef DEBUG
  1490. ICDump();
  1491. #endif
  1492. ICEnterCrit(&ICOpenCritSec);
  1493. if (pic->dwDriver)
  1494. {
  1495. if (pic->DriverProc)
  1496. ICSendMessage((HIC)pic, DRV_CLOSE, 0, 0);
  1497. }
  1498. if (pic->hDriver)
  1499. FreeDriver(pic->hDriver);
  1500. pic->dwSmag = 0L;
  1501. pic->fccType = 0L;
  1502. pic->fccHandler = 0L;
  1503. pic->dwDriver = 0;
  1504. pic->hDriver = NULL;
  1505. pic->DriverProc = NULL;
  1506. ICLeaveCrit(&ICOpenCritSec);
  1507. return ICERR_OK;
  1508. }
  1509. ////////////////////////////////////////////////////////////////////////////
  1510. ////////////////////////////////////////////////////////////////////////////
  1511. /****************************************************************
  1512. * @doc EXTERNAL IC ICAPPS
  1513. *
  1514. * @api DWORD | ICCompress | This function compresses a single video
  1515. * image.
  1516. *
  1517. * @parm HIC | hic | Specifies the handle of the compressor to
  1518. * use.
  1519. *
  1520. * @parm DWORD | dwFlags | Specifies applicable flags for the compression.
  1521. * The following flag is defined:
  1522. *
  1523. * @flag ICCOMPRESS_KEYFRAME | Indicates that the compressor
  1524. * should make this frame a key frame.
  1525. *
  1526. * @parm LPBITMAPINFOHEADER | lpbiOutput | Specifies a far pointer
  1527. * to a <t BITMAPINFO> structure holding the output format.
  1528. *
  1529. * @parm LPVOID | lpData | Specifies a far pointer to output data buffer.
  1530. *
  1531. * @parm LPBITMAPINFOHEADER | lpbiInput | Specifies a far pointer
  1532. * to a <t BITMAPINFO> structure containing the input format.
  1533. *
  1534. * @parm LPVOID | lpBits | Specifies a far pointer to the input data buffer.
  1535. *
  1536. * @parm LPDWORD | lpckid | Not used.
  1537. *
  1538. * @parm LPDWORD | lpdwFlags | Specifies a far pointer to a <t DWORD>
  1539. * holding the return flags used in the AVI index. The following
  1540. * flag is defined:
  1541. *
  1542. * @flag AVIIF_KEYFRAME | Indicates this frame should be used as a key-frame.
  1543. *
  1544. * @parm LONG | lFrameNum | Specifies the frame number.
  1545. *
  1546. * @parm DWORD | dwFrameSize | Specifies the requested frame size in bytes.
  1547. * If set to zero, the compressor chooses the frame size.
  1548. *
  1549. * @parm DWORD | dwQuality | Specifies the requested quality value for the frame.
  1550. *
  1551. * @parm LPBITMAPINFOHEADER | lpbiPrev | Specifies a far pointer to
  1552. * a <t BITMAPINFO> structure holding the previous frame's format.
  1553. * This parameter is not used for fast temporal compression.
  1554. *
  1555. * @parm LPVOID | lpPrev | Specifies a far pointer to the
  1556. * previous frame's data buffer. This parameter is not used for fast
  1557. * temporal compression.
  1558. *
  1559. * @comm The <p lpData> buffer should be large enough to hold a compressed
  1560. * frame. You can obtain the size of this buffer by calling
  1561. * <f ICCompressGetSize>.
  1562. *
  1563. * Set the <p dwFrameSize> parameter to a requested frame
  1564. * size only if the compressor returns the VIDCF_CRUNCH flag in
  1565. * response to <f ICGetInfo>. If this flag is not set, or if a data
  1566. * rate is not specified, set this parameter to zero.
  1567. *
  1568. * Set the <p dwQuality> parameter to a quality value only
  1569. * if the compressor returns the VIDCF_QUALITY flag in response
  1570. * to <f ICGetInfo>. Without this flag, set this parameter to zero.
  1571. *
  1572. * @rdesc This function returns ICERR_OK if successful. Otherwise,
  1573. * it returns an error code.
  1574. *
  1575. * @xref <f ICCompressBegin> <f ICCompressEnd> <f ICCompressGetSize> <f ICGetInfo>
  1576. *
  1577. **********************************************************************/
  1578. DWORD VFWAPIV ICCompress(
  1579. HIC hic,
  1580. DWORD dwFlags, // flags
  1581. LPBITMAPINFOHEADER lpbiOutput, // output format
  1582. LPVOID lpData, // output data
  1583. LPBITMAPINFOHEADER lpbiInput, // format of frame to compress
  1584. LPVOID lpBits, // frame data to compress
  1585. LPDWORD lpckid, // ckid for data in AVI file
  1586. LPDWORD lpdwFlags, // flags in the AVI index.
  1587. LONG lFrameNum, // frame number of seq.
  1588. DWORD dwFrameSize, // reqested size in bytes. (if non zero)
  1589. DWORD dwQuality, // quality
  1590. LPBITMAPINFOHEADER lpbiPrev, // format of previous frame
  1591. LPVOID lpPrev) // previous frame
  1592. {
  1593. #ifdef _WIN32
  1594. // We cannot rely on the stack alignment giving us the right layout
  1595. ICCOMPRESS icc;
  1596. icc.dwFlags = dwFlags;
  1597. icc.lpbiOutput = lpbiOutput;
  1598. icc.lpOutput = lpData;
  1599. icc.lpbiInput = lpbiInput;
  1600. icc.lpInput = lpBits;
  1601. icc.lpckid = lpckid;
  1602. icc.lpdwFlags = lpdwFlags;
  1603. icc.lFrameNum = lFrameNum;
  1604. icc.dwFrameSize = dwFrameSize;
  1605. icc.dwQuality = dwQuality;
  1606. icc.lpbiPrev = lpbiPrev;
  1607. icc.lpPrev = lpPrev;
  1608. return (DWORD) ICSendMessage(hic, ICM_COMPRESS, (DWORD_PTR)(LPVOID)&icc, sizeof(ICCOMPRESS));
  1609. // NOTE: We do NOT copy any results from this temporary structure back
  1610. // to the input variables.
  1611. #else
  1612. return ICSendMessage(hic, ICM_COMPRESS, (DWORD_PTR)(LPVOID)&dwFlags, sizeof(ICCOMPRESS));
  1613. #endif
  1614. }
  1615. /************************************************************************
  1616. decompression functions
  1617. ************************************************************************/
  1618. /*******************************************************************
  1619. * @doc EXTERNAL IC ICAPPS
  1620. *
  1621. * @api DWORD | ICDecompress | The function decompresses a single video frame.
  1622. *
  1623. * @parm HIC | hic | Specifies a handle to the decompressor to use.
  1624. *
  1625. * @parm DWORD | dwFlags | Specifies applicable flags for decompression.
  1626. * The following flags are defined:
  1627. *
  1628. * @flag ICDECOMPRESS_HURRYUP | Indicates the decompressor should try to
  1629. * decompress at a faster rate. When an application uses this flag,
  1630. * it should not draw the decompressed data.
  1631. *
  1632. * @flag ICDECOMPRESS_UPDATE | Indicates that the screen is being updated.
  1633. *
  1634. * @flag ICDECOMPRESS_PREROLL | Indicates that this frame will not actually
  1635. * be drawn, because it is before the point in the movie where play
  1636. * will start.
  1637. *
  1638. * @flag ICDECOMPRESS_NULLFRAME | Indicates that this frame does not actually
  1639. * have any data, and the decompressed image should be left the same.
  1640. *
  1641. * @flag ICDECOMPRESS_NOTKEYFRAME | Indicates that this frame is not a
  1642. * key frame.
  1643. *
  1644. * @parm LPBITMAPINFOHEADER | lpbiFormat | Specifies a far pointer
  1645. * to a <t BITMAPINFO> structure containing the format of
  1646. * the compressed data.
  1647. *
  1648. * @parm LPVOID | lpData | Specifies a far pointer to the input data.
  1649. *
  1650. * @parm LPBITMAPINFOHEADER | lpbi | Specifies a far pointer to a
  1651. * <t BITMAPINFO> structure containing the output format.
  1652. *
  1653. * @parm LPVOID | lpBits | Specifies a far pointer to a data buffer for the
  1654. * decompressed data.
  1655. *
  1656. * @comm The <p lpBits> parameter should point to a buffer large
  1657. * enough to hold the decompressed data. Applications can obtain
  1658. * the size of this buffer with <f ICDecompressGetSize>.
  1659. *
  1660. * @rdesc Returns ICERR_OK on success, otherwise it returns an error code.
  1661. *
  1662. * @xref <f ICDecompressBegin< <f ICDecompressEnd> <f ICDecompressGetSize>
  1663. *
  1664. ********************************************************************/
  1665. DWORD VFWAPIV ICDecompress(
  1666. HIC hic,
  1667. DWORD dwFlags, // flags (from AVI index...)
  1668. LPBITMAPINFOHEADER lpbiFormat, // BITMAPINFO of compressed data
  1669. // biSizeImage has the chunk size
  1670. // biCompression has the ckid (AVI only)
  1671. LPVOID lpData, // data
  1672. LPBITMAPINFOHEADER lpbi, // DIB to decompress to
  1673. LPVOID lpBits)
  1674. {
  1675. #ifdef _WIN32
  1676. ICDECOMPRESS icd;
  1677. // We cannot rely on the stack alignment giving us the right layout
  1678. icd.dwFlags = dwFlags;
  1679. icd.lpbiInput = lpbiFormat;
  1680. icd.lpInput = lpData;
  1681. icd.lpbiOutput = lpbi;
  1682. icd.lpOutput = lpBits;
  1683. icd.ckid = 0;
  1684. return (DWORD) ICSendMessage(hic, ICM_DECOMPRESS, (DWORD_PTR)(LPVOID)&icd, sizeof(ICDECOMPRESS));
  1685. #else
  1686. return ICSendMessage(hic, ICM_DECOMPRESS, (DWORD_PTR)(LPVOID)&dwFlags, sizeof(ICDECOMPRESS));
  1687. #endif
  1688. }
  1689. /************************************************************************
  1690. drawing functions
  1691. ************************************************************************/
  1692. /**********************************************************************
  1693. * @doc EXTERNAL IC ICAPPS
  1694. *
  1695. * @api DWORD | ICDrawBegin | This function starts decompressing
  1696. * data directly to the screen.
  1697. *
  1698. * @parm HIC | hic | Specifies a handle to the decompressor to use.
  1699. *
  1700. * @parm DWORD | dwFlags | Specifies flags for the decompression. The
  1701. * following flags are defined:
  1702. *
  1703. * @flag ICDRAW_QUERY | Determines if the decompressor can handle
  1704. * the decompression. The driver does not actually decompress the data.
  1705. *
  1706. * @flag ICDRAW_FULLSCREEN | Tells the decompressor to draw
  1707. * the decompressed data on the full screen.
  1708. *
  1709. * @flag ICDRAW_HDC | Indicates the decompressor should use the window
  1710. * handle specified by <p hwnd> and the display context
  1711. * handle specified by <p hdc> for drawing the decompressed data.
  1712. *
  1713. * @flag ICDRAW_ANIMATE | Indicates the palette might be animated.
  1714. *
  1715. * @flag ICDRAW_CONTINUE | Indicates drawing is a
  1716. * continuation of the previous frame.
  1717. *
  1718. * @flag ICDRAW_MEMORYDC | Indicates the display context is offscreen.
  1719. *
  1720. * @flag ICDRAW_UPDATING | Indicates the frame is being
  1721. * updated rather than played.
  1722. *
  1723. * @parm HPALETTE | hpal | Specifies a handle to the palette used for drawing.
  1724. *
  1725. * @parm HWND | hwnd | Specifies a handle for the window used for drawing.
  1726. *
  1727. * @parm HDC | hdc | Specifies the display context used for drawing.
  1728. *
  1729. * @parm int | xDst | Specifies the x-position of the upper-right
  1730. * corner of the destination rectangle.
  1731. *
  1732. * @parm int | yDst | Specifies the y-position of the upper-right
  1733. * corner of the destination rectangle.
  1734. *
  1735. * @parm int | dxDst | Specifies the width of the destination rectangle.
  1736. *
  1737. * @parm int | dyDst | Specifies the height of the destination rectangle.
  1738. *
  1739. * @parm LPBITMAPINFOHEADER | lpbi | Specifies a far pointer to
  1740. * a <t BITMAPINFO> structure containing the format of
  1741. * the input data to be decompressed.
  1742. *
  1743. * @parm int | xSrc | Specifies the x-position of the upper-right corner
  1744. * of the source rectangle.
  1745. *
  1746. * @parm int | ySrc | Specifies the y-position of the upper-right corner
  1747. * of the source rectangle.
  1748. *
  1749. * @parm int | dxSrc | Specifies the width of the source rectangle.
  1750. *
  1751. * @parm int | dySrc | Specifies the height of the source rectangle.
  1752. *
  1753. * @parm DWORD | dwRate | Specifies the data rate. The
  1754. * data rate in frames per second equals <p dwRate> divided
  1755. * by <p dwScale>.
  1756. *
  1757. * @parm DWORD | dwScale | Specifies the data rate.
  1758. *
  1759. * @comm Decompressors use the <p hwnd> and <p hdc> parameters
  1760. * only if an application sets ICDRAW_HDC flag in <p dwFlags>.
  1761. * It will ignore these parameters if an application sets
  1762. * the ICDRAW_FULLSCREEN flag. When an application uses the
  1763. * ICDRAW_FULLSCREEN flag, it should set <p hwnd> and <p hdc>
  1764. * to NULL.
  1765. *
  1766. * The destination rectangle is specified only if ICDRAW_HDC is used.
  1767. * If an application sets the ICDRAW_FULLSCREEN flag, the destination
  1768. * rectangle is ignored and its parameters can be set to zero.
  1769. *
  1770. * The source rectangle is relative to the full video frame.
  1771. * The portion of the video frame specified by the source
  1772. * rectangle will be stretched to fit in the destination rectangle.
  1773. *
  1774. * @rdesc Returns ICERR_OK if it can handle the decompression, otherwise
  1775. * it returns ICERR_UNSUPPORTED.
  1776. *
  1777. * @xref <f ICDraw> <f ICDrawEnd>
  1778. *
  1779. *********************************************************************/
  1780. DWORD VFWAPIV ICDrawBegin(
  1781. HIC hic,
  1782. DWORD dwFlags, // flags
  1783. HPALETTE hpal, // palette to draw with
  1784. HWND hwnd, // window to draw to
  1785. HDC hdc, // HDC to draw to
  1786. int xDst, // destination rectangle
  1787. int yDst,
  1788. int dxDst,
  1789. int dyDst,
  1790. LPBITMAPINFOHEADER lpbi, // format of frame to draw
  1791. int xSrc, // source rectangle
  1792. int ySrc,
  1793. int dxSrc,
  1794. int dySrc,
  1795. DWORD dwRate, // frames/second = (dwRate/dwScale)
  1796. DWORD dwScale)
  1797. {
  1798. #ifdef _WIN32
  1799. ICDRAWBEGIN icdraw;
  1800. icdraw.dwFlags = dwFlags;
  1801. icdraw.hpal = hpal;
  1802. icdraw.hwnd = hwnd;
  1803. icdraw.hdc = hdc;
  1804. icdraw.xDst = xDst;
  1805. icdraw.yDst = yDst;
  1806. icdraw.dxDst = dxDst;
  1807. icdraw.dyDst = dyDst;
  1808. icdraw.lpbi = lpbi;
  1809. icdraw.xSrc = xSrc;
  1810. icdraw.ySrc = ySrc;
  1811. icdraw.dxSrc = dxSrc;
  1812. icdraw.dySrc = dySrc;
  1813. icdraw.dwRate = dwRate;
  1814. icdraw.dwScale = dwScale;
  1815. return (DWORD) ICSendMessage(hic, ICM_DRAW_BEGIN, (DWORD_PTR)(LPVOID)&icdraw, sizeof(ICDRAWBEGIN));
  1816. #else
  1817. return ICSendMessage(hic, ICM_DRAW_BEGIN, (DWORD_PTR)(LPVOID)&dwFlags, sizeof(ICDRAWBEGIN));
  1818. #endif
  1819. }
  1820. /**********************************************************************
  1821. * @doc EXTERNAL IC ICAPPS
  1822. *
  1823. * @api DWORD | ICDraw | This function decompress an image for drawing.
  1824. *
  1825. * @parm HIC | hic | Specifies a handle to an decompressor.
  1826. *
  1827. * @parm DWORD | dwFlags | Specifies any flags for the decompression.
  1828. * The following flags are defined:
  1829. *
  1830. * @flag ICDRAW_HURRYUP | Indicates the decompressor should
  1831. * just buffer the data if it needs it for decompression
  1832. * and not draw it to the screen.
  1833. *
  1834. * @flag ICDRAW_UPDATE | Tells the decompressor to update the screen based
  1835. * on data previously received. Set <p lpData> to NULL when
  1836. * this flag is used.
  1837. *
  1838. * @flag ICDRAW_PREROLL | Indicates that this frame of video occurs before
  1839. * actual playback should start. For example, if playback is to
  1840. * begin on frame 10, and frame 0 is the nearest previous keyframe,
  1841. * frames 0 through 9 are sent to the driver with the ICDRAW_PREROLL
  1842. * flag set. The driver needs this data so it can displya frmae 10
  1843. * properly, but frames 0 through 9 need not be individually displayed.
  1844. *
  1845. * @flag ICDRAW_NULLFRAME | Indicates that this frame does not actually
  1846. * have any data, and the previous frame should be redrawn.
  1847. *
  1848. * @flag ICDRAW_NOTKEYFRAME | Indicates that this frame is not a
  1849. * key frame.
  1850. *
  1851. * @parm LPVOID | lpFormat | Specifies a far pointer to a
  1852. * <t BITMAPINFOHEADER> structure containing the input
  1853. * format of the data.
  1854. *
  1855. * @parm LPVOID | lpData | Specifies a far pointer to the actual input data.
  1856. *
  1857. * @parm DWORD | cbData | Specifies the size of the input data (in bytes).
  1858. *
  1859. * @parm LONG | lTime | Specifies the time to draw this frame based on the
  1860. * time scale sent with <f ICDrawBegin>.
  1861. *
  1862. * @comm This function is used to decompress the image data for drawing
  1863. * by the decompressor. Actual drawing of frames does not occur
  1864. * until <f ICDrawStart> is called. The application should be sure to
  1865. * pre-buffer the required number of frames before drawing is started
  1866. * (you can obtain this value with <f ICGetBuffersWanted>).
  1867. *
  1868. * @rdesc Returns ICERR_OK on success, otherwise it returns an appropriate error
  1869. * number.
  1870. *
  1871. * @xref <f ICDrawBegin> <f ICDrawEnd> <f ICDrawStart> <f ICDrawStop> <f ICGetBuffersRequired>
  1872. *
  1873. **********************************************************************/
  1874. DWORD VFWAPIV ICDraw(
  1875. HIC hic,
  1876. DWORD dwFlags, // flags
  1877. LPVOID lpFormat, // format of frame to decompress
  1878. LPVOID lpData, // frame data to decompress
  1879. DWORD cbData, // size in bytes of data
  1880. LONG lTime) // time to draw this frame (see drawbegin dwRate and dwScale)
  1881. {
  1882. #ifdef _WIN32
  1883. ICDRAW icdraw;
  1884. icdraw.dwFlags = dwFlags;
  1885. icdraw.lpFormat = lpFormat;
  1886. icdraw.lpData = lpData;
  1887. icdraw.cbData = cbData;
  1888. icdraw.lTime = lTime;
  1889. return (DWORD) ICSendMessage(hic, ICM_DRAW, (DWORD_PTR)(LPVOID)&icdraw, sizeof(ICDRAW));
  1890. #else
  1891. return ICSendMessage(hic, ICM_DRAW, (DWORD_PTR)(LPVOID)&dwFlags, sizeof(ICDRAW));
  1892. #endif
  1893. }
  1894. /*****************************************************************************
  1895. * @doc EXTERNAL IC ICAPPS
  1896. *
  1897. * @api HIC | ICGetDisplayFormat | This function returns the "best"
  1898. * format available for displaying a compressed image. The function
  1899. * will also open a compressor if a handle to an open compressor
  1900. * is not specified.
  1901. *
  1902. * @parm HIC | hic | Specifies the decompressor that should be used. If
  1903. * this is NULL, an appropriate compressor will be opened and returned.
  1904. *
  1905. * @parm LPBITMAPINFOHEADER | lpbiIn | Specifies a pointer to
  1906. * <t BITMAPINFOHEADER> structure containing the compressed format.
  1907. *
  1908. * @parm LPBITMAPINFOHEADER | lpbiOut | Specifies a pointer
  1909. * to a buffer used to return the decompressed format.
  1910. * The buffer should be large enough for a <t BITMAPINFOHEADER>
  1911. * structure and 256 color entries.
  1912. *
  1913. * @parm int | BitDepth | If non-zero, specifies the preferred bit depth.
  1914. *
  1915. * @parm int | dx | If non-zero, specifies the width to which the image
  1916. * is to be stretched.
  1917. *
  1918. * @parm int | dy | If non-zero, specifies the height to which the image
  1919. * is to be stretched.
  1920. *
  1921. * @rdesc Returns a handle to a decompressor if successful, otherwise, it
  1922. * returns zero.
  1923. ****************************************************************************/
  1924. HIC VFWAPI ICGetDisplayFormat(HIC hic, LPBITMAPINFOHEADER lpbiIn, LPBITMAPINFOHEADER lpbiOut, int BitDepth, int dx, int dy)
  1925. {
  1926. LRESULT dw;
  1927. HDC hdc;
  1928. BOOL fNukeHic = (hic == NULL);
  1929. static int ScreenBitDepth = -1;
  1930. // HACK: We link to some internal DrawDib stuff to find out whether
  1931. // the current display driver is using 565 RGB dibs....
  1932. extern UINT FAR GetBitmapType(VOID);
  1933. #define BM_16565 0x06 // most HiDAC cards
  1934. #define HACK_565_DEPTH 17
  1935. if (hic == NULL)
  1936. hic = ICDecompressOpen(ICTYPE_VIDEO, 0L, lpbiIn, NULL);
  1937. if (hic == NULL)
  1938. return NULL;
  1939. //
  1940. // dx = 0 and dy = 0 means don't stretch.
  1941. //
  1942. if (dx == (int)lpbiIn->biWidth && dy == (int)lpbiIn->biHeight)
  1943. dx = dy = 0;
  1944. //
  1945. // ask the compressor if it likes the format.
  1946. //
  1947. dw = ICDecompressQuery(hic, lpbiIn, NULL);
  1948. if (dw != ICERR_OK)
  1949. {
  1950. DPF(("Decompressor did not recognize the input data format\r\n"));
  1951. goto error;
  1952. }
  1953. try_again:
  1954. //
  1955. // ask the compressor first. (so it can set the palette)
  1956. // this is a HACK, we will send the ICM_GET_PALETTE message later.
  1957. //
  1958. dw = ICDecompressGetFormat(hic, lpbiIn, lpbiOut);
  1959. //
  1960. // init the output format
  1961. //
  1962. *lpbiOut = *lpbiIn;
  1963. lpbiOut->biSize = sizeof(BITMAPINFOHEADER);
  1964. lpbiOut->biCompression = BI_RGB;
  1965. //
  1966. // default to the screen depth.
  1967. //
  1968. if (BitDepth == 0)
  1969. {
  1970. if (ScreenBitDepth < 0)
  1971. {
  1972. hdc = GetDC(NULL);
  1973. ScreenBitDepth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
  1974. ReleaseDC(NULL, hdc);
  1975. if (ScreenBitDepth == 15)
  1976. ScreenBitDepth = 16;
  1977. if (ScreenBitDepth < 8)
  1978. ScreenBitDepth = 8;
  1979. //
  1980. // only try 16 bpp if the display supports drawing it.
  1981. //
  1982. if (ScreenBitDepth == 16)
  1983. {
  1984. lpbiOut->biBitCount = 16;
  1985. if (!DrawDibProfileDisplay(lpbiOut))
  1986. ScreenBitDepth = 24;
  1987. }
  1988. if (ScreenBitDepth > 24)
  1989. {
  1990. lpbiOut->biBitCount = 32;
  1991. if (!DrawDibProfileDisplay(lpbiOut))
  1992. ScreenBitDepth = 24;
  1993. }
  1994. if (ScreenBitDepth == 16 && GetBitmapType() == BM_16565) {
  1995. // If the display is really 565, take this into account.
  1996. ScreenBitDepth = HACK_565_DEPTH;
  1997. }
  1998. }
  1999. #ifdef DEBUG
  2000. ScreenBitDepth = mmGetProfileIntA("DrawDib",
  2001. "ScreenBitDepth",
  2002. ScreenBitDepth);
  2003. #endif
  2004. BitDepth = ScreenBitDepth;
  2005. }
  2006. //
  2007. // always try 8bit first for '8' bit data
  2008. //
  2009. if (lpbiIn->biBitCount == 8)
  2010. BitDepth = 8;
  2011. //
  2012. // lets suggest a format to the device.
  2013. //
  2014. try_bit_depth:
  2015. if (BitDepth != HACK_565_DEPTH) {
  2016. lpbiOut->biSize = sizeof(BITMAPINFOHEADER);
  2017. lpbiOut->biCompression = BI_RGB;
  2018. lpbiOut->biBitCount = (WORD) BitDepth;
  2019. } else {
  2020. #ifndef BI_BITFIELDS
  2021. #define BI_BITFIELDS 3L
  2022. #endif
  2023. // For RGB565, we need to use BI_BITFIELDS.
  2024. lpbiOut->biSize = sizeof(BITMAPINFOHEADER);
  2025. lpbiOut->biCompression = BI_BITFIELDS;
  2026. lpbiOut->biBitCount = 16;
  2027. ((LPDWORD)(lpbiOut+1))[0] = 0x00F800;
  2028. ((LPDWORD)(lpbiOut+1))[1] = 0x0007E0;
  2029. ((LPDWORD)(lpbiOut+1))[2] = 0x00001F;
  2030. // Set lpbiOut->biClrUsed = 3?
  2031. }
  2032. //
  2033. // should we suggest a stretched decompress
  2034. //
  2035. if (dx > 0 && dy > 0)
  2036. {
  2037. lpbiOut->biWidth = dx;
  2038. lpbiOut->biHeight = dy;
  2039. }
  2040. lpbiOut->biSizeImage = (DWORD)(UINT)DIBWIDTHBYTES(*lpbiOut) *
  2041. (DWORD)(UINT)lpbiOut->biHeight;
  2042. //
  2043. // ask the compressor if it likes the suggested format.
  2044. //
  2045. dw = ICDecompressQuery(hic, lpbiIn, lpbiOut);
  2046. //
  2047. // if it likes it then return success.
  2048. //
  2049. if (dw == ICERR_OK)
  2050. goto success;
  2051. // 8: 8, 16,24,32,X
  2052. // 16: 16,565,24,32,X
  2053. // 565: 565,16,24,32,X
  2054. // 24: 24,32,16,X
  2055. // 32: 32,24,16,X
  2056. //
  2057. // try another bit depth in this order 8,16,RGB565,24,32
  2058. //
  2059. if (BitDepth <= 8)
  2060. {
  2061. BitDepth = 16;
  2062. goto try_bit_depth;
  2063. }
  2064. if (ScreenBitDepth == HACK_565_DEPTH) {
  2065. // If the screen is RGB565, we try 565 before 555.
  2066. if (BitDepth == 16) {
  2067. BitDepth = 24;
  2068. goto try_bit_depth;
  2069. }
  2070. if (BitDepth == HACK_565_DEPTH) {
  2071. BitDepth = 16;
  2072. goto try_bit_depth;
  2073. }
  2074. }
  2075. if (BitDepth == 16) {
  2076. // otherwise, we try 565 after 555.
  2077. BitDepth = HACK_565_DEPTH;
  2078. goto try_bit_depth;
  2079. }
  2080. if (BitDepth == HACK_565_DEPTH) {
  2081. BitDepth = 24;
  2082. goto try_bit_depth;
  2083. }
  2084. if (BitDepth == 24)
  2085. {
  2086. BitDepth = 32;
  2087. goto try_bit_depth;
  2088. }
  2089. if (BitDepth != 32)
  2090. {
  2091. BitDepth = 32;
  2092. goto try_bit_depth;
  2093. }
  2094. if (dx > 0 && dy > 0)
  2095. {
  2096. #ifndef DAYTONA // it is not clear that this is correct for Daytona
  2097. // while we work it out disable the code, but match blues
  2098. // as closely as possible.
  2099. //
  2100. // If it's already stretched "pretty big", try decompressing
  2101. // stretched by two, and then stretching/shrinking from there.
  2102. // Otherwise, give up and try decompressing normally.
  2103. //
  2104. if ((dx > (lpbiIn->biWidth * 3) / 2) &&
  2105. (dy > (lpbiIn->biHeight * 3) / 2) &&
  2106. ((dx != lpbiIn->biWidth * 2) || (dy != lpbiIn->biHeight * 2))) {
  2107. dx = (int) lpbiIn->biWidth * 2;
  2108. dy = (int) lpbiIn->biHeight * 2;
  2109. } else {
  2110. dx = 0;
  2111. dy = 0;
  2112. }
  2113. //
  2114. // try to find a non stretched format. but don't let the
  2115. // device dither if we are going to stretch!
  2116. // - note that this only applies for palettised displays.
  2117. // for 16-bit displays we need to restart to ensure we get the
  2118. // right format (555, 565). On 4-bit displays we can also restart
  2119. // (ask DavidMay about the 4-bit cases).
  2120. //
  2121. BitDepth = 0;
  2122. #else
  2123. dx = 0;
  2124. dy = 0;
  2125. if ((lpbiIn->biBitCount > 8) && (ScreenBitDepth == 8))
  2126. BitDepth = 16;
  2127. else
  2128. BitDepth = 0;
  2129. #endif
  2130. goto try_again;
  2131. }
  2132. else
  2133. {
  2134. //
  2135. // let the compressor suggest a format
  2136. //
  2137. dw = ICDecompressGetFormat(hic, lpbiIn, lpbiOut);
  2138. if (dw == ICERR_OK)
  2139. goto success;
  2140. }
  2141. error:
  2142. if (hic && fNukeHic)
  2143. ICClose(hic);
  2144. return NULL;
  2145. success:
  2146. if (lpbiOut->biBitCount == 8)
  2147. ICDecompressGetPalette(hic, lpbiIn, lpbiOut);
  2148. return hic;
  2149. }
  2150. /*****************************************************************************
  2151. * @doc EXTERNAL IC ICAPPS
  2152. *
  2153. * @api HIC | ICLocate | This function finds a compressor or decompressor
  2154. * that can handle images with the formats specified, or it finds a
  2155. * driver that can decompress an image with a specified
  2156. * format directly to hardware. Applications must close the
  2157. * compressor when it has finished using the compressor.
  2158. *
  2159. * @parm DWORD | fccType | Specifies the type of compressor
  2160. * the caller is trying to open. For video, this is ICTYPE_VIDEO.
  2161. *
  2162. * @parm DWORD | fccHandler | Specifies a single preferred handler of the
  2163. * given type that should be tried first. Typically, this comes
  2164. * from the stream header in an AVI file.
  2165. *
  2166. * @parm LPBITMAPINFOHEADER | lpbiIn | Specifies a pointer to
  2167. * <t BITMAPINFOHEADER> structure defining the input format.
  2168. * A compressor handle will not be returned unless it
  2169. * can handle this format.
  2170. *
  2171. * @parm LPBITMAPINFOHEADER | lpbiOut | Specifies zero or a pointer to
  2172. * <t BITMAPINFOHEADER> structure defining an optional decompressed
  2173. * format. If <p lpbiOut> is nonzero, a compressor handle will not
  2174. * be returned unless it can create this output format.
  2175. *
  2176. * @parm WORD | wFlags | Specifies a flag to defining the use of the compressor.
  2177. * This parameter must contain one of the following values:
  2178. *
  2179. * @flag ICMODE_COMPRESS | Indicates the compressor should
  2180. * be able to compress an image with a format defined by <p lpbiIn>
  2181. * to the format defined by <p lpbiOut>.
  2182. *
  2183. * @flag ICMODE_DECOMPRESS | Indicates the decompressor should
  2184. * be able to decompress an image with a format defined by <p lpbiIn>
  2185. * to the format defined by <p lpbiOut>.
  2186. *
  2187. * @flag ICMODE_FASTDECOMPRESS | Has the same definition as ICMODE_DECOMPRESS except the
  2188. * decompressor is being used for a real-time operation and should trade off speed
  2189. * for quality if possible.
  2190. *
  2191. * @flag ICMODE_FASTCOMPRESS | Has the same definition as ICMODE_COMPRESS except the
  2192. * compressor is being used for a real-time operation and should trade off speed
  2193. * for quality if possible.
  2194. *
  2195. * @flag ICMODE_DRAW | Indicates the decompressor should
  2196. * be able to decompress an image with a format defined by <p lpbiIn>
  2197. * and draw it directly to hardware.
  2198. *
  2199. * @rdesc Returns a handle to a compressor or decompressor
  2200. * if successful, otherwise it returns zero.
  2201. ****************************************************************************/
  2202. HIC VFWAPI ICLocate(DWORD fccType, DWORD fccHandler, LPBITMAPINFOHEADER lpbiIn, LPBITMAPINFOHEADER lpbiOut, WORD wFlags)
  2203. {
  2204. HIC hic=NULL;
  2205. int i;
  2206. ICINFO icinfo;
  2207. UINT msg;
  2208. if (fccType == 0)
  2209. return NULL;
  2210. switch (wFlags)
  2211. {
  2212. case ICMODE_FASTCOMPRESS:
  2213. case ICMODE_COMPRESS:
  2214. msg = ICM_COMPRESS_QUERY;
  2215. break;
  2216. case ICMODE_FASTDECOMPRESS:
  2217. case ICMODE_DECOMPRESS:
  2218. msg = ICM_DECOMPRESS_QUERY;
  2219. break;
  2220. case ICMODE_DRAW:
  2221. msg = ICM_DRAW_QUERY;
  2222. break;
  2223. default:
  2224. return NULL;
  2225. }
  2226. if (fccHandler)
  2227. {
  2228. hic = ICOpen(fccType, fccHandler, wFlags);
  2229. if (hic && ICSendMessage(hic, msg, (DWORD_PTR)lpbiIn, (DWORD_PTR)lpbiOut) == ICERR_OK)
  2230. return hic;
  2231. else if (hic)
  2232. ICClose(hic);
  2233. }
  2234. if (fccType == ICTYPE_VIDEO && lpbiIn)
  2235. {
  2236. DWORD fccHandler = lpbiIn->biCompression;
  2237. // They're decompressed already.. use our RLE handler so we don't
  2238. // waste time looking for a decompressor or fail and think we don't
  2239. // support these formats!
  2240. if (fccHandler == BI_RLE8 || fccHandler == BI_RGB)
  2241. fccHandler = mmioFOURCC('M', 'R', 'L', 'E');
  2242. if (fccHandler > 256)
  2243. {
  2244. if (fccHandler == mmioFOURCC('C', 'R', 'A', 'M'))
  2245. fccHandler = mmioFOURCC('M', 'S', 'V', 'C');
  2246. hic = ICOpen(fccType, fccHandler, wFlags);
  2247. if (hic && ICSendMessage(hic, msg, (DWORD_PTR)lpbiIn, (DWORD_PTR)lpbiOut) == ICERR_OK)
  2248. return hic;
  2249. else if (hic)
  2250. ICClose(hic);
  2251. }
  2252. }
  2253. //
  2254. // Search through all of the compressors, to see if one can do what we
  2255. // want.
  2256. //
  2257. for (i=0; ICInfo(fccType, i, &icinfo); i++)
  2258. {
  2259. // Protect against arbitrary 3rd party code crashing us
  2260. try {
  2261. hic = ICOpen(fccType, icinfo.fccHandler, wFlags);
  2262. if (hic == NULL)
  2263. continue;
  2264. if (ICSendMessage(hic, msg, (DWORD_PTR)lpbiIn, (DWORD_PTR)lpbiOut) != ICERR_OK)
  2265. {
  2266. ICClose(hic);
  2267. continue;
  2268. }
  2269. } except (EXCEPTION_EXECUTE_HANDLER) {
  2270. if (hic) {
  2271. ICClose(hic);
  2272. hic = NULL;
  2273. }
  2274. }
  2275. if (hic) {
  2276. return hic;
  2277. }
  2278. return hic;
  2279. }
  2280. return NULL;
  2281. }
  2282. /*****************************************************************************
  2283. * @doc INTERNAL IC
  2284. *
  2285. * @api HDRVR | LoadDriver | load a driver
  2286. *
  2287. * Note: on chicago, the string szDriver may not be longer than
  2288. * the number of characters in ICINFO.szDriver
  2289. *
  2290. ****************************************************************************/
  2291. #if defined _WIN32
  2292. STATICFN HDRVR LoadDriver(LPWSTR szDriver, DRIVERPROC FAR *lpDriverProc)
  2293. #else
  2294. STATICFN HDRVR LoadDriver(LPSTR szDriver, DRIVERPROC FAR *lpDriverProc)
  2295. #endif
  2296. {
  2297. HMODULE hModule;
  2298. UINT u;
  2299. DRIVERPROC DriverProc;
  2300. BOOL fWow;
  2301. HDRVR hDriver;
  2302. fWow = IsWow();
  2303. if (fWow)
  2304. {
  2305. u = SetErrorMode(SEM_NOOPENFILEERRORBOX);
  2306. #if defined _WIN32 && ! defined UNICODE
  2307. {
  2308. char ach[NUMELMS(((ICINFO *)0)->szDriver)]; // same size as PICINFO.szDriver
  2309. hModule = LoadLibrary (mmWideToAnsi(ach, szDriver, NUMELMS(ach)));
  2310. }
  2311. #else
  2312. hModule = LoadLibrary(szDriver);
  2313. #endif
  2314. SetErrorMode(u);
  2315. if (hModule <= (HMODULE)HINSTANCE_ERROR)
  2316. return NULL;
  2317. hDriver = (HDRVR) hModule;
  2318. }
  2319. else
  2320. {
  2321. hDriver = OpenDriver (szDriver, NULL, 0);
  2322. if (!hDriver)
  2323. return NULL;
  2324. hModule = GetDriverModuleHandle (hDriver);
  2325. }
  2326. DPF(("LoadDriver: %ls, handle %8x hModule %8x\n", szDriver, hDriver, hModule));
  2327. DriverProc = (DRIVERPROC)GetProcAddress(hModule, szDriverProc);
  2328. if (DriverProc == NULL)
  2329. {
  2330. if (fWow)
  2331. {
  2332. FreeLibrary(hModule);
  2333. }
  2334. else
  2335. {
  2336. CloseDriver (hDriver, 0L, 0L);
  2337. }
  2338. DPF(("Freeing library %8x as no driverproc found\r\n",hModule));
  2339. return NULL;
  2340. }
  2341. #if ! defined _WIN32
  2342. if (fWow && GetModuleUsage(hModule) == 1) //!!!this is not exacly like USER
  2343. {
  2344. if (!DriverProc(0, (HDRVR)1, DRV_LOAD, 0L, 0L))
  2345. {
  2346. DPF(("Freeing library %8x as driverproc returned an error\r\n",hModule));
  2347. FreeLibrary(hModule);
  2348. return NULL;
  2349. }
  2350. DriverProc(0, (HDRVR)1, DRV_ENABLE, 0L, 0L);
  2351. }
  2352. CacheModule (hModule);
  2353. #endif
  2354. *lpDriverProc = DriverProc;
  2355. return hDriver;
  2356. }
  2357. /*****************************************************************************
  2358. * @doc INTERNAL IC
  2359. *
  2360. * @api void | FreeDriver | unload a driver
  2361. *
  2362. ****************************************************************************/
  2363. STATICFN void FreeDriver(HDRVR hDriver)
  2364. {
  2365. if (!IsWow())
  2366. {
  2367. DPF(("FreeDriver, driver handle is %x\n", hDriver));
  2368. CloseDriver (hDriver, 0L, 0L);
  2369. }
  2370. #ifndef _WIN32
  2371. else
  2372. {
  2373. // This cannot be WIN32 code due to the definition of IsWow()
  2374. if (GetModuleUsage((HMODULE) hDriver) == 1)
  2375. {
  2376. DRIVERPROC DriverProc;
  2377. DriverProc = (DRIVERPROC)GetProcAddress((HMODULE) hDriver, szDriverProc);
  2378. if (DriverProc)
  2379. {
  2380. DriverProc(0, (HDRVR)1, DRV_DISABLE, 0L, 0L);
  2381. DriverProc(0, (HDRVR)1, DRV_FREE, 0L, 0L);
  2382. }
  2383. }
  2384. FreeLibrary((HMODULE) hDriver);
  2385. DPF(("Freeing library %8x in FreeDriver\r\n",hDriver));
  2386. }
  2387. #endif
  2388. }
  2389. #ifdef DEBUG_RETAIL
  2390. /************************************************************************
  2391. messages.
  2392. ************************************************************************/
  2393. static const struct {
  2394. UINT msg;
  2395. char *szMsg;
  2396. } aMsg[] = {
  2397. DRV_OPEN , "DRV_OPEN",
  2398. DRV_CLOSE , "DRV_CLOSE",
  2399. ICM_GETSTATE , "ICM_GETSTATE",
  2400. ICM_SETSTATE , "ICM_SETSTATE",
  2401. ICM_GETINFO , "ICM_GETINFO",
  2402. ICM_CONFIGURE , "ICM_CONFIGURE",
  2403. ICM_ABOUT , "ICM_ABOUT",
  2404. ICM_GETERRORTEXT , "ICM_GETERRORTEXT",
  2405. ICM_GETFORMATNAME , "ICM_GETFORMATNAME",
  2406. ICM_ENUMFORMATS , "ICM_ENUMFORMATS",
  2407. ICM_GETDEFAULTQUALITY , "ICM_GETDEFAULTQUALITY",
  2408. ICM_GETQUALITY , "ICM_GETQUALITY",
  2409. ICM_SETQUALITY , "ICM_SETQUALITY",
  2410. ICM_COMPRESS_GET_FORMAT , "ICM_COMPRESS_GET_FORMAT",
  2411. ICM_COMPRESS_GET_SIZE , "ICM_COMPRESS_GET_SIZE",
  2412. ICM_COMPRESS_QUERY , "ICM_COMPRESS_QUERY",
  2413. ICM_COMPRESS_BEGIN , "ICM_COMPRESS_BEGIN",
  2414. ICM_COMPRESS , "ICM_COMPRESS",
  2415. ICM_COMPRESS_END , "ICM_COMPRESS_END",
  2416. ICM_DECOMPRESS_GET_FORMAT , "ICM_DECOMPRESS_GET_FORMAT",
  2417. ICM_DECOMPRESS_QUERY , "ICM_DECOMPRESS_QUERY",
  2418. ICM_DECOMPRESS_BEGIN , "ICM_DECOMPRESS_BEGIN",
  2419. ICM_DECOMPRESS , "ICM_DECOMPRESS",
  2420. ICM_DECOMPRESS_END , "ICM_DECOMPRESS_END",
  2421. ICM_DECOMPRESS_GET_PALETTE , "ICM_DECOMPRESS_GET_PALETTE",
  2422. ICM_DECOMPRESS_SET_PALETTE , "ICM_DECOMPRESS_SET_PALETTE",
  2423. ICM_DECOMPRESSEX_QUERY , "ICM_DECOMPRESSEX_QUERY",
  2424. ICM_DECOMPRESSEX_BEGIN , "ICM_DECOMPRESSEX_BEGIN",
  2425. ICM_DECOMPRESSEX , "ICM_DECOMPRESSEX",
  2426. ICM_DECOMPRESSEX_END , "ICM_DECOMPRESSEX_END",
  2427. ICM_DRAW_QUERY , "ICM_DRAW_QUERY",
  2428. ICM_DRAW_BEGIN , "ICM_DRAW_BEGIN",
  2429. ICM_DRAW_GET_PALETTE , "ICM_DRAW_GET_PALETTE",
  2430. ICM_DRAW_UPDATE , "ICM_DRAW_UPDATE",
  2431. ICM_DRAW_START , "ICM_DRAW_START",
  2432. ICM_DRAW_STOP , "ICM_DRAW_STOP",
  2433. ICM_DRAW_BITS , "ICM_DRAW_BITS",
  2434. ICM_DRAW_END , "ICM_DRAW_END",
  2435. ICM_DRAW_GETTIME , "ICM_DRAW_GETTIME",
  2436. ICM_DRAW , "ICM_DRAW",
  2437. ICM_DRAW_WINDOW , "ICM_DRAW_WINDOW",
  2438. ICM_DRAW_SETTIME , "ICM_DRAW_SETTIME",
  2439. ICM_DRAW_REALIZE , "ICM_DRAW_REALIZE",
  2440. ICM_GETBUFFERSWANTED , "ICM_GETBUFFERSWANTED",
  2441. ICM_GETDEFAULTKEYFRAMERATE , "ICM_GETDEFAULTKEYFRAMERATE",
  2442. 0 , NULL
  2443. };
  2444. static const struct {
  2445. LRESULT err;
  2446. char *szErr;
  2447. } aErr[] = {
  2448. ICERR_DONTDRAW , "ICERR_DONTDRAW",
  2449. ICERR_NEWPALETTE , "ICERR_NEWPALETTE",
  2450. ICERR_UNSUPPORTED , "ICERR_UNSUPPORTED",
  2451. ICERR_BADFORMAT , "ICERR_BADFORMAT",
  2452. ICERR_MEMORY , "ICERR_MEMORY",
  2453. ICERR_INTERNAL , "ICERR_INTERNAL",
  2454. ICERR_BADFLAGS , "ICERR_BADFLAGS",
  2455. ICERR_BADPARAM , "ICERR_BADPARAM",
  2456. ICERR_BADSIZE , "ICERR_BADSIZE",
  2457. ICERR_BADHANDLE , "ICERR_BADHANDLE",
  2458. ICERR_CANTUPDATE , "ICERR_CANTUPDATE",
  2459. ICERR_ERROR , "ICERR_ERROR",
  2460. ICERR_BADBITDEPTH , "ICERR_BADBITDEPTH",
  2461. ICERR_BADIMAGESIZE , "ICERR_BADIMAGESIZE",
  2462. ICERR_OK , "ICERR_OK"
  2463. };
  2464. STATICDT BOOL cmfDebug = -1;
  2465. STATICDT DWORD dwTime;
  2466. void ICDebugMessage(HIC hic, UINT msg, DWORD_PTR dw1, DWORD_PTR dw2)
  2467. {
  2468. int i;
  2469. if (!cmfDebug)
  2470. return;
  2471. for (i=0; aMsg[i].msg && aMsg[i].msg != msg; i++)
  2472. ;
  2473. if (aMsg[i].msg == 0)
  2474. RPF(("ICM(%04X,ICM_%04X,%08lX,%08lX) ", hic, msg, dw1, dw2));
  2475. else
  2476. RPF(("ICM(%04X,%s,%08lX,%08lX) ", hic, (LPSTR)aMsg[i].szMsg, dw1, dw2));
  2477. dwTime = timeGetTime();
  2478. }
  2479. LRESULT ICDebugReturn(LRESULT err)
  2480. {
  2481. int i;
  2482. if (!cmfDebug)
  2483. return err;
  2484. dwTime = timeGetTime() - dwTime;
  2485. for (i=0; aErr[i].err && aErr[i].err != err; i++)
  2486. ;
  2487. if (aErr[i].err != err)
  2488. RPF(("! : 0x%08lX (%ldms)\r\n", err, dwTime));
  2489. else
  2490. RPF(("! : %s (%ldms)\r\n", (LPSTR)aErr[i].szErr, dwTime));
  2491. return err;
  2492. }
  2493. STATICFN void ICDump()
  2494. {
  2495. int i;
  2496. PIC pic;
  2497. TCHAR ach[80];
  2498. DPF(("ICDump ---------------------------------------\r\n"));
  2499. for (i=0; i<giMaxConverters; i++)
  2500. {
  2501. pic = &aicConverters[i];
  2502. if (pic->fccType == 0)
  2503. continue;
  2504. if (pic->dwSmag == 0)
  2505. continue;
  2506. if (pic->hDriver)
  2507. GetModuleFileName(GetDriverModuleHandle (pic->hDriver), ach, NUMELMS(ach));
  2508. else
  2509. ach[0] = 0;
  2510. #ifdef _WIN32
  2511. DPF((" HIC: %04X %4.4hs.%4.4hs hTask=%04X Proc=%08lx %ls\r\n", (HIC)pic, (LPSTR)&pic->fccType, (LPSTR)&pic->fccHandler, pic->hTask, pic->DriverProc, ach));
  2512. #else
  2513. DPF((" HIC: %04X %4.4s.%4.4s hTask=%04X Proc=%08lx %s\r\n", (HIC)pic, (LPSTR)&pic->fccType, (LPSTR)&pic->fccHandler, pic->hTask, pic->DriverProc, (LPSTR)ach));
  2514. #endif
  2515. }
  2516. DPF(("----------------------------------------------\r\n"));
  2517. }
  2518. #endif
  2519. /*****************************************************************************
  2520. *
  2521. * dprintf() is called by the DPF macro if DEBUG is defined at compile time.
  2522. *
  2523. * The messages will be send to COM1: like any debug message. To
  2524. * enable debug output, add the following to WIN.INI :
  2525. *
  2526. * [debug]
  2527. * COMPMAN=1
  2528. *
  2529. ****************************************************************************/
  2530. char szDebug[] = "Debug";
  2531. #ifdef DEBUG_RETAIL
  2532. STATICFN void cdecl dprintfc(LPSTR szFormat, ...)
  2533. {
  2534. char ach[128];
  2535. #ifdef _WIN32
  2536. va_list va;
  2537. if (cmfDebug == -1)
  2538. cmfDebug = mmGetProfileIntA(szDebug, MODNAME, 0);
  2539. if (!cmfDebug)
  2540. return;
  2541. va_start(va, szFormat);
  2542. if (szFormat[0] == '!')
  2543. ach[0]=0, szFormat++;
  2544. else
  2545. wsprintfA(ach, "%s: (tid %x) ", MODNAME, GetCurrentThreadId());
  2546. wvsprintfA(ach+lstrlenA(ach),szFormat,va);
  2547. va_end(va);
  2548. // lstrcatA(ach, "\r\r\n");
  2549. #else // Following is WIN16 code...
  2550. if (cmfDebug == -1)
  2551. cmfDebug = GetProfileIntA("Debug",MODNAME, 0);
  2552. if (!cmfDebug)
  2553. return;
  2554. if (szFormat[0] == '!')
  2555. ach[0]=0, szFormat++;
  2556. else
  2557. lstrcpyA(ach, MODNAME ": ");
  2558. wvsprintfA(ach+lstrlenA(ach),szFormat,(LPSTR)(&szFormat+1));
  2559. // lstrcatA(ach, "\r\r\n");
  2560. #endif
  2561. OutputDebugStringA(ach);
  2562. }
  2563. #endif
  2564. #ifdef _WIN32
  2565. #define FADMIN_NOT_CACHED 15
  2566. int fIsAdmin = FADMIN_NOT_CACHED; // any arbitrary value that will not be TRUE or FALSE
  2567. BOOL IsAdmin(void)
  2568. {
  2569. BOOL IsMember;
  2570. SID_IDENTIFIER_AUTHORITY sia = SECURITY_NT_AUTHORITY;
  2571. PSID AdminSid;
  2572. #ifdef DEBUG_RETAIL
  2573. // see if we should run as a normal user.
  2574. // ADMINs can pretend to be normal users; vice versa does not work
  2575. // Hence you have to pass the security checks below to be recognised
  2576. // as an admin
  2577. if (mmGetProfileIntA(MODNAME, "NormalUser", FALSE)) {
  2578. DPF(("Forcing NON admin"));
  2579. return(FALSE);
  2580. }
  2581. #endif
  2582. // If we have cached a value, return the cached value
  2583. if (FADMIN_NOT_CACHED != fIsAdmin) {
  2584. return(fIsAdmin);
  2585. }
  2586. if (!AllocateAndInitializeSid(&sia, // identifier authority
  2587. 2, // subauthority count
  2588. SECURITY_BUILTIN_DOMAIN_RID, // subauthority 0
  2589. DOMAIN_ALIAS_RID_ADMINS, // subauthority 1
  2590. 0,0,0,0,0,0, // subauthority 2-7
  2591. &AdminSid)) { // result target
  2592. //
  2593. // Failed, don't assume we are an admin.
  2594. //
  2595. return FALSE;
  2596. } else if (!CheckTokenMembership(NULL,
  2597. AdminSid,
  2598. &IsMember)) {
  2599. //
  2600. // Failed, don't assume we are an admin.
  2601. //
  2602. FreeSid(AdminSid);
  2603. return FALSE;
  2604. } else {
  2605. //
  2606. // We have a definitive answer, set the cached value.
  2607. //
  2608. fIsAdmin = IsMember;
  2609. FreeSid(AdminSid);
  2610. return fIsAdmin;
  2611. }
  2612. // NOT REACHED
  2613. return FALSE;
  2614. }
  2615. #endif // _WIN32
  2616. #ifdef DAYTONA
  2617. #define KEYSECTION TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\")
  2618. LONG OpenUserKey(PHKEY pKey, LPCTSTR lp, LPCTSTR pSection)
  2619. {
  2620. DWORD disposition;
  2621. TCHAR section[256];
  2622. lstrcpy(section, KEYSECTION);
  2623. lstrcat(section, pSection);
  2624. if (lp) {
  2625. // Note: we should never need to create the user section in order
  2626. // to query the data. If the section does not exist, then nothing is
  2627. // the right thing to return.
  2628. return(RegCreateKeyExW(HKEY_CURRENT_USER, section, 0, NULL, 0,
  2629. KEY_SET_VALUE, NULL, pKey, &disposition));
  2630. } else {
  2631. // We are only reading what is there...
  2632. return(RegOpenKeyExW(HKEY_CURRENT_USER, section, 0, KEY_QUERY_VALUE, pKey));
  2633. }
  2634. }
  2635. LONG OpenSystemKey(PHKEY pKey, LPCTSTR lp, LPCTSTR pSection)
  2636. {
  2637. DWORD disposition;
  2638. TCHAR section[256];
  2639. lstrcpy(section, KEYSECTION);
  2640. lstrcat(section, pSection);
  2641. if (lp) {
  2642. return(RegCreateKeyExW(HKEY_LOCAL_MACHINE, section, 0, NULL, 0,
  2643. KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, pKey, &disposition));
  2644. } else {
  2645. // We are only reading what is there...
  2646. return(RegOpenKeyExW(HKEY_LOCAL_MACHINE, section, 0, KEY_QUERY_VALUE, pKey));
  2647. }
  2648. }
  2649. // Use a mapping to get the stuff into the registry
  2650. BOOL myWritePrivateProfileString(
  2651. LPCTSTR lpszSection, // address of section name
  2652. LPCTSTR lpszKeyName, // address of key name
  2653. LPCTSTR lpszString // address of string to add
  2654. )
  2655. {
  2656. if (IsAdmin()) {
  2657. return WritePrivateProfileString(lpszSection, lpszKeyName, lpszString, gszSystemIni);
  2658. } else /* NOT ADMIN */ {
  2659. // write to HKEY_CURRENT_USER
  2660. // Data is written to
  2661. HKEY key;
  2662. // If we have something to write, then we must create the key
  2663. // If we are about to delete something that might not exist we only
  2664. // want to open the key. Hence OpenUserKey needs to know if lpszString is NULL
  2665. if (ERROR_SUCCESS == OpenUserKey(&key, lpszString, lpszSection)) {
  2666. // We have access. Now write the data
  2667. if (lpszString) {
  2668. LPCTSTR lpStr;
  2669. RegSetValueEx(key, lpszKeyName, 0, REG_SZ,
  2670. (LPCVOID)lpszString, sizeof(TCHAR)*(lstrlen(lpszString)+1));
  2671. lpStr = lpszString + 1 + lstrlen(lpszString);
  2672. // Is there an associated description ??
  2673. if (*(lpStr)) {
  2674. HKEY key2;
  2675. DWORD disposition;
  2676. TCHAR section[256];
  2677. // Write the description
  2678. lstrcpy(section, KEYSECTION);
  2679. lstrcat(section, TEXT("Drivers.desc"));
  2680. if (ERROR_SUCCESS ==
  2681. (RegCreateKeyExW(HKEY_CURRENT_USER, section, 0, NULL, 0,
  2682. KEY_SET_VALUE, NULL, &key2, &disposition))) {
  2683. RegSetValueEx(key2, lpszString, 0, REG_SZ,
  2684. (LPCVOID)lpStr, sizeof(TCHAR)*(lstrlen(lpStr)+1));
  2685. RegCloseKey(key2);
  2686. }
  2687. }
  2688. } else {
  2689. // delete the data
  2690. RegDeleteValue(key, lpszKeyName);
  2691. }
  2692. RegCloseKey(key);
  2693. return(TRUE);
  2694. }
  2695. return(FALSE);
  2696. }
  2697. }
  2698. DWORD myGetPrivateProfileString(
  2699. LPCTSTR lpszSection, // address of section name
  2700. LPCTSTR lpszKey, // address of key name
  2701. LPCTSTR lpszDefault, // address of default string
  2702. LPTSTR lpszReturnBuffer, // address of destination buffer
  2703. DWORD cchReturnBuffer) // size of destination buffer
  2704. {
  2705. // Whether we are an admin or not we have to read data from HKEY_CURRENT_USER
  2706. // first as that overrides the SYSTEM installed details.
  2707. // If we are enumerating the section, then we want to delete duplicate definitions
  2708. // in the system block. This is where the complexity enters.
  2709. DWORD dwType;
  2710. HKEY key;
  2711. UINT nSize;
  2712. UINT nRet=ERROR_NO_MORE_ITEMS;
  2713. LPTSTR lpBuf;
  2714. LPVOID lpEnd;
  2715. UINT size = cchReturnBuffer * sizeof(TCHAR);
  2716. lpBuf = lpszReturnBuffer;
  2717. lpEnd = ((LPBYTE)lpBuf)+size;
  2718. #define CUSERDRIVERS 20
  2719. if (!lpszKey) {
  2720. // Will enumerate the list of installed drivers - first USER
  2721. // then SYSTEM. User installed drivers take precendence (if
  2722. // there is duplication). We used to read the whole section,
  2723. // but we are only interested in fcctype.fcchandler type entries.
  2724. // Therefore, any that do not match this pattern are skipped.
  2725. UINT cch1, count;
  2726. TCHAR section[256];
  2727. LPTSTR aszUserDrivers[CUSERDRIVERS];
  2728. UINT cUserDrivers=0;
  2729. UINT iKey;
  2730. #ifdef DEBUG
  2731. memset(lpszReturnBuffer, 0xfe, cchReturnBuffer*sizeof(TCHAR));
  2732. // verify that we do not write more data than we should
  2733. #endif
  2734. #if 0
  2735. // This is the old code. Use this to verify that the registry enumeration is
  2736. // correct.
  2737. // Check that the registry enumeration code produces the same result
  2738. cch1 = GetPrivateProfileString(lpszSection, lpszKey, lpszDefault,
  2739. lpszReturnBuffer, cchReturnBuffer, gszSystemIni);
  2740. #endif
  2741. // Read the user section
  2742. // then read the system section, skipping codecs already found
  2743. if (ERROR_SUCCESS == OpenUserKey(&key, NULL, lpszSection)) {
  2744. for (iKey = 0; ; ++iKey) {
  2745. // Calculate - in characters - how much space is left in the
  2746. // name buffer
  2747. nSize = (UINT) (UINT_PTR) ((LPTSTR)lpEnd-lpBuf);
  2748. // Enumerate the name. We do not at this point need the values
  2749. // associated with the names, only the list of installed driver types
  2750. nRet = RegEnumValue(key, iKey, lpBuf, &nSize, NULL,
  2751. &dwType, NULL, NULL);
  2752. if (nRet!= ERROR_SUCCESS) break; // bail out
  2753. // If this is not xxxx.yyyy then ignore it.
  2754. if ((nSize != sizeof(FOURCC)+sizeof(FOURCC)+1)
  2755. || (lpBuf[4] != TEXT('.')))
  2756. {
  2757. continue;
  2758. }
  2759. if (cUserDrivers<CUSERDRIVERS) {
  2760. // Remember the name of this driver
  2761. aszUserDrivers[cUserDrivers++] = lpBuf;
  2762. } else {
  2763. // Too many user installed drivers... let there be duplicates
  2764. }
  2765. lpBuf += nSize+1; // Step over this name and its terminating null
  2766. }
  2767. RegCloseKey(key);
  2768. }
  2769. // Unless we ran out of room we need to read the system section
  2770. if (nRet == ERROR_NO_MORE_ITEMS)
  2771. if (ERROR_SUCCESS == OpenSystemKey(&key, NULL, lpszSection)) {
  2772. for (iKey = 0; ; ++iKey) {
  2773. // Calculate - in characters - how much space is left in the
  2774. // name buffer
  2775. nSize = (DWORD) (DWORD_PTR) ((LPTSTR)lpEnd-lpBuf);
  2776. // Enumerate the name. We do not at this point need the values
  2777. // associated with the names, only the list of installed driver types
  2778. nRet = RegEnumValue(key, iKey, lpBuf, &nSize, NULL,
  2779. &dwType, NULL, NULL);
  2780. if (nRet!= ERROR_SUCCESS) break; // bail out
  2781. // If this is not xxxx.yyyy then ignore it.
  2782. if (nSize != sizeof(FOURCC)+sizeof(FOURCC)+1) {
  2783. continue;
  2784. }
  2785. // If we have already found this driver in the user section, then
  2786. // ignore the system definition
  2787. for (count=0; count<cUserDrivers; ++count) {
  2788. if (0 == lstrcmpi(lpBuf, aszUserDrivers[count])) {
  2789. *lpBuf = 0; // wipeout the last value
  2790. goto skipped;
  2791. }
  2792. }
  2793. lpBuf += nSize+1; // Step over this name and its terminating null
  2794. skipped: ;
  2795. }
  2796. RegCloseKey(key);
  2797. }
  2798. if (ERROR_MORE_DATA == nRet) {
  2799. // we ran out of room
  2800. nSize = cchReturnBuffer-2; // same return as GetPrivateProfileString
  2801. } else if (nRet == ERROR_NO_MORE_ITEMS) {
  2802. // Success. Calculate the number of characters in the buffer
  2803. *lpBuf = 0; // Write a second terminating zero
  2804. // Now calculate how many characters we are returning, excluding one
  2805. // of the two terminating zeros
  2806. nSize = (DWORD) (DWORD_PTR) (lpBuf-lpszReturnBuffer);
  2807. } else {
  2808. // something went wrong. No data, or another error, return nothing
  2809. // Make sure the buffer has a double terminating null
  2810. *lpBuf++ = 0;
  2811. *lpBuf++ = 0;
  2812. nSize=0;
  2813. }
  2814. return(nSize);
  2815. } else {
  2816. // Not enumerating. We have a specific value to look for
  2817. if (ERROR_SUCCESS == OpenUserKey(&key, NULL, lpszSection)) {
  2818. // Calculate - in bytes - how much space is in the buffer
  2819. nSize = (DWORD) (DWORD_PTR) ((LPBYTE)lpEnd-(LPBYTE)lpBuf);
  2820. // Get the data
  2821. nRet = RegQueryValueEx(key, lpszKey, NULL,
  2822. &dwType, (LPBYTE)lpBuf, &nSize);
  2823. RegCloseKey(key);
  2824. }
  2825. // If we could not find the data in the user key then try SYSTEM
  2826. if ((ERROR_SUCCESS != nRet) && (ERROR_MORE_DATA != nRet)) {
  2827. // Try the system key
  2828. if (ERROR_SUCCESS == OpenSystemKey(&key, NULL, lpszSection)) {
  2829. // Calculate - in bytes - how much space is in the buffer
  2830. nSize = (DWORD) (DWORD_PTR) ((LPBYTE)lpEnd-(LPBYTE)lpBuf);
  2831. // Get the data
  2832. nRet = RegQueryValueEx(key, lpszKey, NULL,
  2833. &dwType, (LPBYTE)lpBuf, &nSize);
  2834. RegCloseKey(key);
  2835. }
  2836. }
  2837. if (ERROR_MORE_DATA == nRet) {
  2838. return(cchReturnBuffer-1); // not enough room for the data
  2839. }
  2840. if (nRet != ERROR_SUCCESS) {
  2841. return(0); // cannot find the data
  2842. }
  2843. if (REG_SZ != dwType) {
  2844. return(0); // we must have string data
  2845. }
  2846. //RegQueryValueEx returns length in bytes and includes the terminating zero
  2847. return (DWORD) (nSize/sizeof(TCHAR) - 1);
  2848. }
  2849. }
  2850. #endif
  2851. // Display an apps help message to the user before his app crashes
  2852. // because Indeo5 was removed from XP. ApphelpShowDialog()
  2853. // is a private API, so we launch appshelp directly to avoid calling
  2854. // private APIs from dshow which is redisted outside the OS. This code
  2855. // is duplicated in compman.c and intel.cpp
  2856. //
  2857. void IndeoAppCompat()
  2858. {
  2859. STARTUPINFO StartupInfo;
  2860. PROCESS_INFORMATION ProcessInfo;
  2861. HWND hwndForeground;
  2862. static int nCallAhui=0;
  2863. TCHAR szCmdLine[MAX_PATH * 2];
  2864. UINT cch = GetSystemDirectory(szCmdLine, MAX_PATH);
  2865. if(!cch) {
  2866. return;
  2867. }
  2868. lstrcat(szCmdLine, TEXT("\\ahui.exe /HTMLHELPID:0x5349 /SEVERITY:0x1 ")
  2869. TEXT("/GUID:{1A42E45A-C662-4F47-BC71-91C6872347A7}"));
  2870. ZeroMemory(&StartupInfo, sizeof(StartupInfo));
  2871. ZeroMemory(&ProcessInfo, sizeof(ProcessInfo));
  2872. StartupInfo.cb = sizeof(StartupInfo);
  2873. //
  2874. // Only call once. Calling mulitple times increase the bad app to freak out.
  2875. //
  2876. if ( nCallAhui++ != 0 ) {
  2877. return;
  2878. }
  2879. hwndForeground = GetForegroundWindow();
  2880. if ( NULL != hwndForeground ) {
  2881. //
  2882. // Temporarily deactivate foreground window in case it's in fullscreen mode
  2883. //
  2884. SendMessage( hwndForeground, WM_ACTIVATEAPP, FALSE, 0);
  2885. }
  2886. //
  2887. // post the message via ahui
  2888. //
  2889. if (CreateProcess(NULL,
  2890. szCmdLine,
  2891. NULL,
  2892. NULL,
  2893. FALSE,
  2894. 0,
  2895. NULL,
  2896. NULL,
  2897. &StartupInfo, &ProcessInfo)) {
  2898. WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
  2899. CloseHandle(ProcessInfo.hProcess);
  2900. CloseHandle(ProcessInfo.hThread);
  2901. }
  2902. //
  2903. // reactivate the foreground
  2904. //
  2905. if ( NULL != hwndForeground ) {
  2906. SendMessage( hwndForeground, WM_ACTIVATEAPP, TRUE, 0);
  2907. }
  2908. return;
  2909. }