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