MCI.CPP 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /****************************************************************************
  15. *
  16. * FILE
  17. * MCI.cpp
  18. *
  19. * DESCRIPTION
  20. *
  21. * PROGRAMMER
  22. * Denzil E. Long, Jr.
  23. *
  24. * DATE
  25. * 6/22/98
  26. *
  27. ****************************************************************************/
  28. #include "function.h"
  29. #ifdef MCIMPEG
  30. #include "mci.h"
  31. /****************************************************************************
  32. *
  33. * NAME
  34. * GetDeviceCount()
  35. *
  36. * DESCRIPTION
  37. *
  38. * INPUTS
  39. * NONE
  40. *
  41. * RESULT
  42. * Count - Number of MCI device entries
  43. *
  44. ****************************************************************************/
  45. unsigned int MCI::GetDeviceCount(void)
  46. {
  47. MCIERROR rc;
  48. MCI_SYSINFO_PARMS sysInfo;
  49. unsigned int count;
  50. memset(&sysInfo, 0, sizeof(sysInfo));
  51. sysInfo.lpstrReturn = (LPSTR)&count;
  52. sysInfo.dwRetSize = sizeof(count);
  53. rc = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO,
  54. MCI_WAIT | MCI_SYSINFO_QUANTITY, (DWORD)&sysInfo);
  55. if (rc)
  56. return 0;
  57. return count;
  58. }
  59. /****************************************************************************
  60. *
  61. * NAME
  62. * GetDeviceName(entry, name)
  63. *
  64. * DESCRIPTION
  65. *
  66. * INPUTS
  67. * Entry - Entry number to get name for.
  68. * Name - On return; device entry name
  69. *
  70. * RESULT
  71. * Success - Success / Failure flag
  72. *
  73. ****************************************************************************/
  74. bool MCI::GetDeviceName(unsigned int item, char* buffer)
  75. {
  76. MCIERROR rc;
  77. MCI_SYSINFO_PARMS sysInfo;
  78. // Get device name
  79. memset(&sysInfo, 0, sizeof(sysInfo));
  80. sysInfo.lpstrReturn = (LPSTR)buffer;
  81. sysInfo.dwRetSize = 63;
  82. sysInfo.dwNumber = item;
  83. rc = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO,
  84. MCI_WAIT | MCI_SYSINFO_NAME, (DWORD)&sysInfo);
  85. if (rc)
  86. return false;
  87. return true;
  88. }
  89. /****************************************************************************
  90. *
  91. * NAME
  92. *
  93. * DESCRIPTION
  94. *
  95. * INPUTS
  96. *
  97. * RESULT
  98. *
  99. ****************************************************************************/
  100. bool MCI::GetProductName(MCIDEVICEID id, char* buffer)
  101. {
  102. MCIERROR rc;
  103. MCI_INFO_PARMS info;
  104. // Get device product name
  105. memset(&info, 0, sizeof(info));
  106. info.lpstrReturn = (LPSTR)buffer;
  107. info.dwRetSize = 63;
  108. rc = mciSendCommand(id, MCI_INFO, MCI_WAIT | MCI_INFO_PRODUCT,
  109. (DWORD)&info);
  110. if (rc)
  111. return false;
  112. return true;
  113. }
  114. /****************************************************************************
  115. *
  116. * NAME
  117. * OpenDevice(name)
  118. *
  119. * DESCRIPTION
  120. *
  121. * INPUTS
  122. * Name - Device name to open
  123. *
  124. * RESULT
  125. * DeviceID - ID of opened device, 0 if error.
  126. *
  127. ****************************************************************************/
  128. MCIDEVICEID MCI::OpenDevice(const char* name)
  129. {
  130. MCIERROR rc;
  131. MCI_OPEN_PARMS open;
  132. memset(&open, 0, sizeof(open));
  133. open.lpstrDeviceType = name;
  134. rc = mciSendCommand(0, MCI_OPEN, MCI_WAIT | MCI_OPEN_TYPE, (DWORD)&open);
  135. if (rc)
  136. return 0;
  137. return (open.wDeviceID);
  138. }
  139. void MCI::CloseDevice(MCIDEVICEID id)
  140. {
  141. MCI_GENERIC_PARMS close;
  142. close.dwCallback = (DWORD)NULL;
  143. if (id)
  144. mciSendCommand(id, MCI_CLOSE, MCI_WAIT, (DWORD)&close);
  145. }
  146. /****************************************************************************
  147. *
  148. * NAME
  149. * GetDeviceDescription
  150. *
  151. * DESCRIPTION
  152. *
  153. * INPUTS
  154. *
  155. * RESULT
  156. *
  157. ****************************************************************************/
  158. bool MCI::GetDeviceDescription(const char* name, MCIDevice* caps)
  159. {
  160. MCIDEVICEID id;
  161. unsigned long result;
  162. // Copy the name
  163. strncpy(caps->name, name, 63);
  164. if ((id = OpenDevice(name)) == 0)
  165. return false;
  166. // Get device product name
  167. GetProductName(id, caps->description);
  168. // Get device type
  169. if (GetCapability(id, MCI_GETDEVCAPS_DEVICE_TYPE, &result))
  170. caps->type = result;
  171. if (GetCapability(id, MCI_GETDEVCAPS_CAN_EJECT, &result))
  172. caps->canEject = ((result) ? true : false);
  173. if (GetCapability(id, MCI_GETDEVCAPS_CAN_PLAY, &result))
  174. caps->canPlay = ((result) ? true : false);
  175. if (GetCapability(id, MCI_GETDEVCAPS_CAN_RECORD, &result))
  176. caps->canRecord = ((result) ? true : false);
  177. if (GetCapability(id, MCI_GETDEVCAPS_CAN_SAVE, &result))
  178. caps->canSave = ((result) ? true : false);
  179. if (GetCapability(id, MCI_GETDEVCAPS_COMPOUND_DEVICE, &result))
  180. caps->usesDevElem = ((result) ? true : false);
  181. if (GetCapability(id, MCI_GETDEVCAPS_HAS_AUDIO, &result))
  182. caps->hasAudio = ((result) ? true : false);
  183. if (GetCapability(id, MCI_GETDEVCAPS_HAS_VIDEO, &result))
  184. caps->hasVideo = ((result) ? true : false);
  185. if (GetCapability(id, MCI_GETDEVCAPS_USES_FILES, &result))
  186. caps->reqElemFile = ((result) ? true : false);
  187. CloseDevice(id);
  188. return true;
  189. }
  190. /****************************************************************************
  191. *
  192. * NAME
  193. *
  194. * DESCRIPTION
  195. *
  196. * INPUTS
  197. *
  198. * RESULT
  199. *
  200. ****************************************************************************/
  201. bool MCI::GetCapability(MCIDEVICEID id, unsigned long capItem,
  202. unsigned long* result)
  203. {
  204. MCIERROR rc;
  205. MCI_GETDEVCAPS_PARMS devCaps;
  206. memset(&devCaps, 0, sizeof(devCaps));
  207. devCaps.dwItem = capItem;
  208. rc = mciSendCommand(id, MCI_GETDEVCAPS, MCI_WAIT|MCI_GETDEVCAPS_ITEM,
  209. (DWORD)&devCaps);
  210. if (rc)
  211. return false;
  212. *result = devCaps.dwReturn;
  213. return true;
  214. }
  215. /****************************************************************************
  216. *
  217. * NAME
  218. *
  219. * DESCRIPTION
  220. *
  221. * INPUTS
  222. *
  223. * RESULT
  224. *
  225. ****************************************************************************/
  226. const char* MCI::GetDeviceTypeName(unsigned long type)
  227. {
  228. static struct _DeviceType {unsigned long typeID; const char* typeName;}
  229. _deviceTypeNames[] =
  230. {
  231. {MCI_DEVTYPE_ANIMATION, "Animation"},
  232. {MCI_DEVTYPE_CD_AUDIO, "CD Audio"},
  233. {MCI_DEVTYPE_DAT, "DAT"},
  234. {MCI_DEVTYPE_DIGITAL_VIDEO, "Digital Video"},
  235. {MCI_DEVTYPE_OTHER, "Other"},
  236. {MCI_DEVTYPE_OVERLAY, "Overlay"},
  237. {MCI_DEVTYPE_SCANNER, "Scanner"},
  238. {MCI_DEVTYPE_SEQUENCER, "MIDI Sequencer"},
  239. {MCI_DEVTYPE_VCR, "VCR"},
  240. {MCI_DEVTYPE_VIDEODISC, "VideoDisc"},
  241. {MCI_DEVTYPE_WAVEFORM_AUDIO, "Wave Audio"},
  242. {0, NULL},
  243. };
  244. int i = 0;
  245. while (_deviceTypeNames[i].typeID != 0)
  246. {
  247. if (_deviceTypeNames[i].typeID == type)
  248. return _deviceTypeNames[i].typeName;
  249. i++;
  250. }
  251. return NULL;
  252. }
  253. /****************************************************************************
  254. *
  255. * NAME
  256. * MCIEnumerate(callack, context)
  257. *
  258. * DESCRIPTION
  259. *
  260. * INPUTS
  261. * Callback -
  262. * Context -
  263. *
  264. * RESULT
  265. * Success - Success / Failure flag
  266. *
  267. ****************************************************************************/
  268. bool MCI::EnumerateDevices(MCIEnumCB* callback, void* context)
  269. {
  270. DWORD count;
  271. DWORD i;
  272. char name[64];
  273. MCIDevice device;
  274. // Get the number of devices
  275. count = GetDeviceCount();
  276. // Do for each device
  277. for (i = 1; i <= count; i++)
  278. {
  279. GetDeviceName(i, name);
  280. memset(&device, 0, sizeof(device));
  281. if (GetDeviceDescription(name, &device))
  282. {
  283. if (!callback(&device, context))
  284. break;
  285. }
  286. }
  287. return true;
  288. }
  289. #endif // MCIMPEG