VideoPlayer.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //----------------------------------------------------------------------------
  24. //
  25. // Westwood Studios Pacific.
  26. //
  27. // Confidential Information
  28. // Copyright (C) 2001 - All Rights Reserved
  29. //
  30. //----------------------------------------------------------------------------
  31. //
  32. // Project: Generals
  33. //
  34. // Module: GameClient
  35. //
  36. // File name: VideoPlayer.cpp
  37. //
  38. // Created: 10/22/01 TR
  39. //
  40. //----------------------------------------------------------------------------
  41. //----------------------------------------------------------------------------
  42. // Includes
  43. //----------------------------------------------------------------------------
  44. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  45. #include "Lib/BaseType.h"
  46. #include "GameClient/VideoPlayer.h"
  47. //----------------------------------------------------------------------------
  48. // Externals
  49. //----------------------------------------------------------------------------
  50. //----------------------------------------------------------------------------
  51. // Defines
  52. //----------------------------------------------------------------------------
  53. //----------------------------------------------------------------------------
  54. // Private Types
  55. //----------------------------------------------------------------------------
  56. //----------------------------------------------------------------------------
  57. // Private Data
  58. //----------------------------------------------------------------------------
  59. //----------------------------------------------------------------------------
  60. // Public Data
  61. //----------------------------------------------------------------------------
  62. VideoPlayerInterface *TheVideoPlayer = NULL;
  63. //----------------------------------------------------------------------------
  64. // Private Prototypes
  65. //----------------------------------------------------------------------------
  66. //----------------------------------------------------------------------------
  67. // Private Functions
  68. //----------------------------------------------------------------------------
  69. //----------------------------------------------------------------------------
  70. // Public Functions
  71. //----------------------------------------------------------------------------
  72. //============================================================================
  73. // VideoBuffer::VideoBuffer
  74. //============================================================================
  75. VideoBuffer::VideoBuffer( Type format)
  76. : m_width(0),
  77. m_height(0),
  78. m_textureWidth(0),
  79. m_textureHeight(0),
  80. m_format(format),
  81. m_pitch(0),
  82. m_xPos(0),
  83. m_yPos(0)
  84. {
  85. if ( m_format >= NUM_TYPES || m_format < 0 )
  86. {
  87. m_format = TYPE_UNKNOWN;
  88. }
  89. }
  90. //============================================================================
  91. // VideoBuffer::Rect
  92. //============================================================================
  93. RectClass VideoBuffer::Rect( Real x1, Real y1, Real x2, Real y2 )
  94. {
  95. RectClass rect(0,0,0,0);
  96. if ( valid() )
  97. {
  98. rect.Set(
  99. ((Real)m_width/(Real)m_textureWidth)*x1, ((Real)m_height/(Real)m_textureHeight)*y1,
  100. ((Real)m_width/(Real)m_textureWidth)*x2, ((Real)m_height/(Real)m_textureHeight)*y2
  101. );
  102. }
  103. return rect;
  104. }
  105. //============================================================================
  106. // VideoBuffer::free
  107. //============================================================================
  108. void VideoBuffer::free( void )
  109. {
  110. m_width = 0;
  111. m_height = 0;
  112. m_textureWidth = 0;
  113. m_textureHeight = 0;
  114. }
  115. //============================================================================
  116. // VideoPlayer::VideoPlayer
  117. //============================================================================
  118. VideoPlayer::VideoPlayer()
  119. : m_firstStream(NULL)
  120. {
  121. }
  122. //============================================================================
  123. // VideoPlayer::~VideoPlayer
  124. //============================================================================
  125. VideoPlayer::~VideoPlayer()
  126. {
  127. deinit();
  128. // Set the video player to null if its us. (WB requires this.)
  129. if (this == TheVideoPlayer) {
  130. TheVideoPlayer = NULL;
  131. }
  132. }
  133. //============================================================================
  134. // VideoPlayer::init
  135. //============================================================================
  136. void VideoPlayer::init( void )
  137. {
  138. // Load this here so that WB doesn't have to link to BinkLib, costing us (potentially)
  139. // an extra license.
  140. INI ini;
  141. ini.load( AsciiString( "Data\\INI\\Default\\Video.ini" ), INI_LOAD_OVERWRITE, NULL );
  142. ini.load( AsciiString( "Data\\INI\\Video.ini" ), INI_LOAD_OVERWRITE, NULL );
  143. }
  144. //============================================================================
  145. // VideoPlayer::deinit
  146. //============================================================================
  147. void VideoPlayer::deinit( void )
  148. {
  149. }
  150. //============================================================================
  151. // VideoPlayer::reset
  152. //============================================================================
  153. void VideoPlayer::reset( void )
  154. {
  155. closeAllStreams();
  156. }
  157. //============================================================================
  158. // VideoPlayer::update
  159. //============================================================================
  160. void VideoPlayer::update( void )
  161. {
  162. VideoStreamInterface *stream = firstStream();
  163. while ( stream )
  164. {
  165. stream->update();
  166. stream = stream->next();
  167. }
  168. }
  169. //============================================================================
  170. // VideoPlayer::loseFocus
  171. //============================================================================
  172. void VideoPlayer::loseFocus( void )
  173. {
  174. }
  175. //============================================================================
  176. // VideoPlayer::regainFocus
  177. //============================================================================
  178. void VideoPlayer::regainFocus( void )
  179. {
  180. }
  181. //============================================================================
  182. // VideoPlayer::open
  183. //============================================================================
  184. VideoStreamInterface* VideoPlayer::open( AsciiString movieTitle )
  185. {
  186. return NULL;
  187. }
  188. //============================================================================
  189. // VideoPlayer::load
  190. //============================================================================
  191. VideoStreamInterface* VideoPlayer::load( AsciiString movieTitle )
  192. {
  193. return NULL;
  194. }
  195. //============================================================================
  196. // VideoPlayer::firstStream
  197. //============================================================================
  198. VideoStreamInterface* VideoPlayer::firstStream( void )
  199. {
  200. return m_firstStream;
  201. }
  202. //============================================================================
  203. // VideoPlayer::closeAllStreams
  204. //============================================================================
  205. void VideoPlayer::closeAllStreams( void )
  206. {
  207. VideoStreamInterface *stream ;
  208. while ( (stream = firstStream()) != 0 )
  209. {
  210. stream->close();
  211. }
  212. }
  213. //============================================================================
  214. // VideoPlayer::remove
  215. //============================================================================
  216. void VideoPlayer::remove( VideoStream *stream_to_remove )
  217. {
  218. VideoStream *last = NULL;
  219. VideoStream *stream = (VideoStream*) firstStream();
  220. while ( stream != NULL && stream != stream_to_remove )
  221. {
  222. last = stream;
  223. stream = (VideoStream*) stream->next();
  224. }
  225. if ( stream )
  226. {
  227. if ( last )
  228. {
  229. last->m_next = stream->m_next;
  230. }
  231. else
  232. {
  233. m_firstStream = stream->m_next;
  234. }
  235. }
  236. }
  237. //============================================================================
  238. // VideoPlayer::addVideo
  239. //============================================================================
  240. void VideoPlayer::addVideo( Video* videoToAdd )
  241. {
  242. for (VecVideoIt it = mVideosAvailableForPlay.begin(); it != mVideosAvailableForPlay.end(); ++it) {
  243. if (it->m_internalName == videoToAdd->m_internalName) {
  244. (*it) = (*videoToAdd);
  245. return;
  246. }
  247. }
  248. // That internal name hasn't been used, so push a new entry on the back
  249. mVideosAvailableForPlay.push_back(*videoToAdd);
  250. }
  251. //============================================================================
  252. // VideoPlayer::removeVideo
  253. //============================================================================
  254. void VideoPlayer::removeVideo( Video* videoToRemove )
  255. {
  256. for (VecVideoIt it = mVideosAvailableForPlay.begin(); it != mVideosAvailableForPlay.end(); ++it) {
  257. if (it->m_internalName == videoToRemove->m_internalName) {
  258. mVideosAvailableForPlay.erase(it);
  259. return;
  260. }
  261. }
  262. }
  263. //============================================================================
  264. // VideoPlayer::getNumVideos
  265. //============================================================================
  266. Int VideoPlayer::getNumVideos( void )
  267. {
  268. return mVideosAvailableForPlay.size();
  269. }
  270. //============================================================================
  271. // VideoPlayer::removeVideo
  272. //============================================================================
  273. const Video* VideoPlayer::getVideo( AsciiString movieTitle )
  274. {
  275. for (VecVideoIt it = mVideosAvailableForPlay.begin(); it != mVideosAvailableForPlay.end(); ++it) {
  276. if (it->m_internalName == movieTitle) {
  277. return &(*it);
  278. }
  279. }
  280. return NULL;
  281. }
  282. //============================================================================
  283. // VideoPlayer::getVideo
  284. //============================================================================
  285. const Video* VideoPlayer::getVideo( Int index )
  286. {
  287. if (index < 0 || index >= mVideosAvailableForPlay.size()) {
  288. return NULL;
  289. }
  290. return &mVideosAvailableForPlay[index];
  291. }
  292. //============================================================================
  293. // VideoStream::VideoStream
  294. //============================================================================
  295. VideoStream::VideoStream()
  296. : m_next(NULL),
  297. m_player(NULL)
  298. {
  299. }
  300. //============================================================================
  301. // VideoStream::~VideoStream
  302. //============================================================================
  303. VideoStream::~VideoStream()
  304. {
  305. if ( m_player )
  306. {
  307. m_player->remove( this );
  308. m_player = NULL;
  309. }
  310. }
  311. //============================================================================
  312. // VideoStream::next
  313. //============================================================================
  314. VideoStreamInterface* VideoStream::next( void )
  315. {
  316. return m_next;
  317. }
  318. //============================================================================
  319. // VideoStream::update
  320. //============================================================================
  321. void VideoStream::update( void )
  322. {
  323. }
  324. //============================================================================
  325. // VideoStream::close
  326. //============================================================================
  327. void VideoStream::close( void )
  328. {
  329. delete this;
  330. }
  331. //============================================================================
  332. // VideoStream::isFrameReady
  333. //============================================================================
  334. Bool VideoStream::isFrameReady( void )
  335. {
  336. return TRUE;
  337. }
  338. //============================================================================
  339. // VideoStream::frameDecompress
  340. //============================================================================
  341. void VideoStream::frameDecompress( void )
  342. {
  343. }
  344. //============================================================================
  345. // VideoStream::frameRender
  346. //============================================================================
  347. void VideoStream::frameRender( VideoBuffer *buffer )
  348. {
  349. }
  350. //============================================================================
  351. // VideoStream::frameNext
  352. //============================================================================
  353. void VideoStream::frameNext( void )
  354. {
  355. }
  356. //============================================================================
  357. // VideoStream::frameIndex
  358. //============================================================================
  359. Int VideoStream::frameIndex( void )
  360. {
  361. return 0;
  362. }
  363. //============================================================================
  364. // VideoStream::totalFrames
  365. //============================================================================
  366. Int VideoStream::frameCount( void )
  367. {
  368. return 0;
  369. }
  370. //============================================================================
  371. // VideoStream::frameGoto
  372. //============================================================================
  373. void VideoStream::frameGoto( Int index )
  374. {
  375. }
  376. //============================================================================
  377. // VideoStream::height
  378. //============================================================================
  379. Int VideoStream::height( void )
  380. {
  381. return 0;
  382. }
  383. //============================================================================
  384. // VideoStream::width
  385. //============================================================================
  386. Int VideoStream::width( void )
  387. {
  388. return 0;
  389. }
  390. const FieldParse VideoPlayer::m_videoFieldParseTable[] =
  391. {
  392. { "Filename", INI::parseAsciiString, NULL, offsetof( Video, m_filename) },
  393. { "Comment", INI::parseAsciiString, NULL, offsetof( Video, m_commentForWB) },
  394. { NULL, NULL, NULL, 0 },
  395. };