MCI.CPP 7.4 KB

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