MCIMOVIE.CPP 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. #include "function.h"
  19. #ifdef MCIMPEG
  20. #include "mcimovie.h"
  21. #include <memory.h>
  22. /****************************************************************************
  23. *
  24. * NAME
  25. * MCIMovie - Constructor
  26. *
  27. * DESCRIPTION
  28. *
  29. * INPUTS
  30. * HInstance - Application instance handle
  31. *
  32. * RESULT
  33. * NONE
  34. *
  35. ****************************************************************************/
  36. MCIMovie::MCIMovie(HWND mainWindow)
  37. : mMainWindow(mainWindow), mMCIWindow(NULL), mName(NULL), mDeviceID(0)
  38. {
  39. mWidth = mHeight = 0;
  40. }
  41. /****************************************************************************
  42. *
  43. * NAME
  44. * ~MCIMovie - Destructor
  45. *
  46. * DESCRIPTION
  47. *
  48. * INPUTS
  49. *
  50. * RESULT
  51. *
  52. ****************************************************************************/
  53. MCIMovie::~MCIMovie()
  54. {
  55. // Stop any playing movie
  56. Close();
  57. // Free name
  58. if (mName != NULL)
  59. free(mName);
  60. }
  61. /****************************************************************************
  62. *
  63. * NAME
  64. * Open()
  65. *
  66. * DESCRIPTION
  67. * Open the media file in preparation for playback.
  68. *
  69. * INPUTS
  70. * NONE
  71. *
  72. * RESULT
  73. * Success - Success/Failure flag
  74. *
  75. ****************************************************************************/
  76. bool MCIMovie::Open(const char* name, const char* device)
  77. {
  78. MCIERROR rc;
  79. MCI_DGV_RECT_PARMS rectParm;
  80. MCI_BREAK_PARMS breakParm;
  81. // Stop any currently playing movie
  82. Close();
  83. // Copy the movie name for our use
  84. if (mName != NULL)
  85. free(mName);
  86. mName = strdup(name);
  87. if (device == NULL)
  88. device = "mpegvideo";
  89. // Setup open parameters
  90. memset((void*)&mOpenParm, 0, sizeof(mOpenParm));
  91. mOpenParm.dwCallback = NULL;
  92. mOpenParm.lpstrDeviceType = device;
  93. mOpenParm.lpstrElementName = name;
  94. rc = mciSendCommand(0, MCI_OPEN, MCI_WAIT | MCI_OPEN_TYPE |
  95. MCI_OPEN_ELEMENT, (DWORD)&mOpenParm);
  96. if (rc)
  97. {
  98. char buffer[512];
  99. mciGetErrorString(rc, buffer, 512);
  100. return false;
  101. }
  102. // Set device ID
  103. mDeviceID = mOpenParm.wDeviceID;
  104. // Retrieve movie dimensions
  105. rectParm.dwCallback = NULL;
  106. rc = mciSendCommand(mDeviceID, MCI_WHERE, MCI_WAIT | MCI_DGV_WHERE_SOURCE,
  107. (DWORD)&rectParm);
  108. if (rc)
  109. {
  110. char buffer[512];
  111. mciGetErrorString(rc, buffer, 512);
  112. return false;
  113. }
  114. mWidth = rectParm.rc.right - rectParm.rc.left;
  115. mHeight = rectParm.rc.bottom - rectParm.rc.top;
  116. // Set break key to escape
  117. breakParm.dwCallback = NULL;
  118. breakParm.nVirtKey = VK_ESCAPE;
  119. breakParm.hwndBreak = mMainWindow;
  120. rc = mciSendCommand(mDeviceID, MCI_BREAK, MCI_WAIT | MCI_BREAK_HWND |
  121. MCI_BREAK_KEY, (DWORD)&breakParm);
  122. if (rc)
  123. {
  124. char buffer[512];
  125. mciGetErrorString(rc, buffer, 512);
  126. }
  127. return true;
  128. }
  129. /****************************************************************************
  130. *
  131. * NAME
  132. * Play - Play the specified movie.
  133. *
  134. * DESCRIPTION
  135. *
  136. * INPUTS
  137. *
  138. * RESULT
  139. * Success - Success/Failure flag
  140. *
  141. ****************************************************************************/
  142. bool MCIMovie::Play(HWND window)
  143. {
  144. MCIERROR rc;
  145. if (mDeviceID == 0)
  146. return false;
  147. // Provide window for playback
  148. if (AttachWindow(window))
  149. {
  150. // Size the video area
  151. if (SizeDestination())
  152. {
  153. // Start playing
  154. memset((void*)&mPlayParm, 0, sizeof(mPlayParm));
  155. mPlayParm.dwCallback = NULL;
  156. rc = mciSendCommand(mDeviceID, MCI_PLAY, MCI_WAIT, (DWORD)&mPlayParm);
  157. if (rc)
  158. {
  159. char buffer[512];
  160. mciGetErrorString(rc, buffer, 512);
  161. return false;
  162. }
  163. Close();
  164. }
  165. }
  166. return true;
  167. }
  168. /****************************************************************************
  169. *
  170. * NAME
  171. * Pause
  172. *
  173. * DESCRIPTION
  174. *
  175. * INPUTS
  176. *
  177. * RESULT
  178. * Success - Success/Failure flag
  179. *
  180. ****************************************************************************/
  181. bool MCIMovie::Pause(void)
  182. {
  183. if (mDeviceID == 0)
  184. return false;
  185. if (mciSendCommand(mDeviceID, MCI_PAUSE, 0, (DWORD)NULL))
  186. return false;
  187. return true;
  188. }
  189. /****************************************************************************
  190. *
  191. * NAME
  192. * Stop
  193. *
  194. * DESCRIPTION
  195. *
  196. * INPUTS
  197. *
  198. * RESULT
  199. * Success - Success/Failure flag
  200. *
  201. ****************************************************************************/
  202. bool MCIMovie::Close(void)
  203. {
  204. MCIERROR rc;
  205. if (mDeviceID == 0)
  206. return false;
  207. rc = mciSendCommand(mDeviceID, MCI_CLOSE, 0, (DWORD)NULL);
  208. mDeviceID = 0;
  209. if (rc)
  210. {
  211. char buffer[512];
  212. mciGetErrorString(rc, buffer, 512);
  213. return false;
  214. }
  215. return true;
  216. }
  217. /****************************************************************************
  218. *
  219. * NAME
  220. * SizeDestination
  221. *
  222. * DESCRIPTION
  223. *
  224. * INPUTS
  225. *
  226. * RESULT
  227. *
  228. ****************************************************************************/
  229. bool MCIMovie::SizeDestination(void)
  230. {
  231. MCIERROR rc;
  232. MCI_DGV_PUT_PARMS putParm;
  233. RECT rect;
  234. if (mMCIWindow == NULL)
  235. return false;
  236. GetClientRect(mMCIWindow, &rect);
  237. ClientToScreen(mMCIWindow, (LPPOINT)&rect);
  238. ClientToScreen(mMCIWindow, (LPPOINT)&rect + 1);
  239. putParm.dwCallback = NULL;
  240. putParm.rc.left = rect.left;
  241. putParm.rc.top = rect.top;
  242. putParm.rc.right = rect.right;
  243. putParm.rc.bottom = rect.bottom;
  244. rc = mciSendCommand(mDeviceID, MCI_PUT, MCI_WAIT | MCI_DGV_RECT |
  245. MCI_DGV_PUT_DESTINATION, (DWORD)&putParm);
  246. if (rc)
  247. {
  248. char buffer[512];
  249. mciGetErrorString(rc, buffer, 512);
  250. return false;
  251. }
  252. return true;
  253. }
  254. /****************************************************************************
  255. *
  256. * NAME
  257. * AttachWindow
  258. *
  259. * DESCRIPTION
  260. *
  261. * INPUTS
  262. *
  263. * RESULT
  264. *
  265. ****************************************************************************/
  266. bool MCIMovie::AttachWindow(HWND window)
  267. {
  268. MCIERROR rc;
  269. MCI_DGV_WINDOW_PARMS winParm;
  270. mMCIWindow = window;
  271. memset((void*)&winParm, 0, sizeof(winParm));
  272. winParm.dwCallback = NULL;
  273. winParm.hWnd = window;
  274. winParm.nCmdShow = SW_SHOW;
  275. rc = mciSendCommand(mDeviceID, MCI_WINDOW, MCI_WAIT| MCI_DGV_WINDOW_HWND |
  276. MCI_DGV_WINDOW_STATE, (DWORD)&winParm);
  277. if (rc)
  278. {
  279. char buffer[512];
  280. mciGetErrorString(rc, buffer, 512);
  281. return false;
  282. }
  283. return true;
  284. }
  285. #endif // MCIMPEG