| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- /*
- ** Command & Conquer Red Alert(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /****************************************************************************
- *
- * FILE
- * MCI.cpp
- *
- * DESCRIPTION
- *
- * PROGRAMMER
- * Denzil E. Long, Jr.
- *
- * DATE
- * 6/22/98
- *
- ****************************************************************************/
- #include "function.h"
- #ifdef MCIMPEG
- #include "mci.h"
- /****************************************************************************
- *
- * NAME
- * GetDeviceCount()
- *
- * DESCRIPTION
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * Count - Number of MCI device entries
- *
- ****************************************************************************/
- unsigned int MCI::GetDeviceCount(void)
- {
- MCIERROR rc;
- MCI_SYSINFO_PARMS sysInfo;
- unsigned int count;
- memset(&sysInfo, 0, sizeof(sysInfo));
- sysInfo.lpstrReturn = (LPSTR)&count;
- sysInfo.dwRetSize = sizeof(count);
- rc = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO,
- MCI_WAIT | MCI_SYSINFO_QUANTITY, (DWORD)&sysInfo);
- if (rc)
- return 0;
- return count;
- }
- /****************************************************************************
- *
- * NAME
- * GetDeviceName(entry, name)
- *
- * DESCRIPTION
- *
- * INPUTS
- * Entry - Entry number to get name for.
- * Name - On return; device entry name
- *
- * RESULT
- * Success - Success / Failure flag
- *
- ****************************************************************************/
- bool MCI::GetDeviceName(unsigned int item, char* buffer)
- {
- MCIERROR rc;
- MCI_SYSINFO_PARMS sysInfo;
- // Get device name
- memset(&sysInfo, 0, sizeof(sysInfo));
- sysInfo.lpstrReturn = (LPSTR)buffer;
- sysInfo.dwRetSize = 63;
- sysInfo.dwNumber = item;
- rc = mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO,
- MCI_WAIT | MCI_SYSINFO_NAME, (DWORD)&sysInfo);
- if (rc)
- return false;
- return true;
- }
- /****************************************************************************
- *
- * NAME
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- *
- ****************************************************************************/
- bool MCI::GetProductName(MCIDEVICEID id, char* buffer)
- {
- MCIERROR rc;
- MCI_INFO_PARMS info;
- // Get device product name
- memset(&info, 0, sizeof(info));
- info.lpstrReturn = (LPSTR)buffer;
- info.dwRetSize = 63;
- rc = mciSendCommand(id, MCI_INFO, MCI_WAIT | MCI_INFO_PRODUCT,
- (DWORD)&info);
- if (rc)
- return false;
- return true;
- }
- /****************************************************************************
- *
- * NAME
- * OpenDevice(name)
- *
- * DESCRIPTION
- *
- * INPUTS
- * Name - Device name to open
- *
- * RESULT
- * DeviceID - ID of opened device, 0 if error.
- *
- ****************************************************************************/
- MCIDEVICEID MCI::OpenDevice(const char* name)
- {
- MCIERROR rc;
- MCI_OPEN_PARMS open;
- memset(&open, 0, sizeof(open));
- open.lpstrDeviceType = name;
- rc = mciSendCommand(0, MCI_OPEN, MCI_WAIT | MCI_OPEN_TYPE, (DWORD)&open);
- if (rc)
- return 0;
- return (open.wDeviceID);
- }
- void MCI::CloseDevice(MCIDEVICEID id)
- {
- MCI_GENERIC_PARMS close;
- close.dwCallback = (DWORD)NULL;
-
- if (id)
- mciSendCommand(id, MCI_CLOSE, MCI_WAIT, (DWORD)&close);
- }
- /****************************************************************************
- *
- * NAME
- * GetDeviceDescription
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- *
- ****************************************************************************/
- bool MCI::GetDeviceDescription(const char* name, MCIDevice* caps)
- {
- MCIDEVICEID id;
- unsigned long result;
- // Copy the name
- strncpy(caps->name, name, 63);
- if ((id = OpenDevice(name)) == 0)
- return false;
- // Get device product name
- GetProductName(id, caps->description);
- // Get device type
- if (GetCapability(id, MCI_GETDEVCAPS_DEVICE_TYPE, &result))
- caps->type = result;
- if (GetCapability(id, MCI_GETDEVCAPS_CAN_EJECT, &result))
- caps->canEject = ((result) ? true : false);
- if (GetCapability(id, MCI_GETDEVCAPS_CAN_PLAY, &result))
- caps->canPlay = ((result) ? true : false);
- if (GetCapability(id, MCI_GETDEVCAPS_CAN_RECORD, &result))
- caps->canRecord = ((result) ? true : false);
- if (GetCapability(id, MCI_GETDEVCAPS_CAN_SAVE, &result))
- caps->canSave = ((result) ? true : false);
- if (GetCapability(id, MCI_GETDEVCAPS_COMPOUND_DEVICE, &result))
- caps->usesDevElem = ((result) ? true : false);
- if (GetCapability(id, MCI_GETDEVCAPS_HAS_AUDIO, &result))
- caps->hasAudio = ((result) ? true : false);
- if (GetCapability(id, MCI_GETDEVCAPS_HAS_VIDEO, &result))
- caps->hasVideo = ((result) ? true : false);
- if (GetCapability(id, MCI_GETDEVCAPS_USES_FILES, &result))
- caps->reqElemFile = ((result) ? true : false);
- CloseDevice(id);
- return true;
- }
- /****************************************************************************
- *
- * NAME
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- *
- ****************************************************************************/
- bool MCI::GetCapability(MCIDEVICEID id, unsigned long capItem,
- unsigned long* result)
- {
- MCIERROR rc;
- MCI_GETDEVCAPS_PARMS devCaps;
- memset(&devCaps, 0, sizeof(devCaps));
- devCaps.dwItem = capItem;
- rc = mciSendCommand(id, MCI_GETDEVCAPS, MCI_WAIT|MCI_GETDEVCAPS_ITEM,
- (DWORD)&devCaps);
- if (rc)
- return false;
- *result = devCaps.dwReturn;
- return true;
- }
- /****************************************************************************
- *
- * NAME
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- *
- ****************************************************************************/
- const char* MCI::GetDeviceTypeName(unsigned long type)
- {
- static struct _DeviceType {unsigned long typeID; const char* typeName;}
- _deviceTypeNames[] =
- {
- {MCI_DEVTYPE_ANIMATION, "Animation"},
- {MCI_DEVTYPE_CD_AUDIO, "CD Audio"},
- {MCI_DEVTYPE_DAT, "DAT"},
- {MCI_DEVTYPE_DIGITAL_VIDEO, "Digital Video"},
- {MCI_DEVTYPE_OTHER, "Other"},
- {MCI_DEVTYPE_OVERLAY, "Overlay"},
- {MCI_DEVTYPE_SCANNER, "Scanner"},
- {MCI_DEVTYPE_SEQUENCER, "MIDI Sequencer"},
- {MCI_DEVTYPE_VCR, "VCR"},
- {MCI_DEVTYPE_VIDEODISC, "VideoDisc"},
- {MCI_DEVTYPE_WAVEFORM_AUDIO, "Wave Audio"},
- {0, NULL},
- };
- int i = 0;
- while (_deviceTypeNames[i].typeID != 0)
- {
- if (_deviceTypeNames[i].typeID == type)
- return _deviceTypeNames[i].typeName;
- i++;
- }
- return NULL;
- }
- /****************************************************************************
- *
- * NAME
- * MCIEnumerate(callack, context)
- *
- * DESCRIPTION
- *
- * INPUTS
- * Callback -
- * Context -
- *
- * RESULT
- * Success - Success / Failure flag
- *
- ****************************************************************************/
- bool MCI::EnumerateDevices(MCIEnumCB* callback, void* context)
- {
- DWORD count;
- DWORD i;
- char name[64];
- MCIDevice device;
- // Get the number of devices
- count = GetDeviceCount();
- // Do for each device
- for (i = 1; i <= count; i++)
- {
- GetDeviceName(i, name);
- memset(&device, 0, sizeof(device));
- if (GetDeviceDescription(name, &device))
- {
- if (!callback(&device, context))
- break;
- }
- }
- return true;
- }
- #endif // MCIMPEG
|