VideoPlayer.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. ** Command & Conquer Generals(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. // File name: GameClient/VideoPlayer.h
  35. //
  36. // Created: 10/22/01
  37. //
  38. //----------------------------------------------------------------------------
  39. #pragma once
  40. #ifndef __GAMECLIENT_VIDEOPLAYER_H_
  41. #define __GAMECLIENT_VIDEOPLAYER_H_
  42. //----------------------------------------------------------------------------
  43. // Includes
  44. //----------------------------------------------------------------------------
  45. #include <lib/BaseType.h>
  46. #include "WWMath/rect.h"
  47. #include "Common/SubsystemInterface.h"
  48. #include "Common/AsciiString.h"
  49. #include "Common/INI.h"
  50. #include "Common/STLTypedefs.h"
  51. //----------------------------------------------------------------------------
  52. // Forward References
  53. //----------------------------------------------------------------------------
  54. struct Video;
  55. class VideoPlayer;
  56. //----------------------------------------------------------------------------
  57. // Type Defines
  58. //----------------------------------------------------------------------------
  59. typedef std::vector<Video> VecVideo;
  60. typedef std::vector<Video>::iterator VecVideoIt;
  61. //----------------------------------------------------------------------------
  62. // Video (Struct)
  63. //----------------------------------------------------------------------------
  64. struct Video
  65. {
  66. AsciiString m_filename; ///< should be filled with the filename on disk
  67. AsciiString m_internalName; ///< should be our internal reference name
  68. AsciiString m_commentForWB;
  69. };
  70. //===============================
  71. // VideoBuffer
  72. //===============================
  73. /**
  74. * Video buffer interface class. The VideoPlayer uses this buffer abstraction
  75. * in order to be able to render a video stream.
  76. */
  77. //===============================
  78. class VideoBuffer
  79. {
  80. public:
  81. // Enumeration of buffer pixel formats
  82. enum Type
  83. {
  84. TYPE_UNKNOWN,
  85. TYPE_R8G8B8,
  86. TYPE_X8R8G8B8,
  87. TYPE_R5G6B5,
  88. TYPE_X1R5G5B5,
  89. NUM_TYPES
  90. };
  91. protected:
  92. UnsignedInt m_xPos; ///< X pixel buffer offset
  93. UnsignedInt m_yPos; ///< Y pixel buffer offset
  94. UnsignedInt m_width; ///< Buffer visible width
  95. UnsignedInt m_height; ///< Buffer height
  96. UnsignedInt m_textureWidth; ///< Buffer visible width
  97. UnsignedInt m_textureHeight;///< Buffer height
  98. UnsignedInt m_pitch; ///< buffer pitch
  99. Type m_format; ///< buffer pixel format
  100. public:
  101. VideoBuffer( Type format );
  102. virtual ~VideoBuffer() {};
  103. virtual Bool allocate( UnsignedInt width, UnsignedInt Height ) = 0; ///< Allocate buffer
  104. virtual void free( void ) = 0; ///< Free the buffer
  105. virtual void* lock( void ) = 0; ///< Returns memory pointer to start of buffer
  106. virtual void unlock( void ) = 0; ///< Release buffer
  107. virtual Bool valid( void ) = 0; ///< Is the buffer valid to use
  108. UnsignedInt xPos( void ) { return m_xPos;};///< X pixel offset to draw into
  109. UnsignedInt yPos( void ) { return m_yPos;};///< Y pixel offset to draw into
  110. void setPos( UnsignedInt x, UnsignedInt y ) { m_xPos = x; m_yPos = y;}; ///< Set the x and y buffer offset
  111. UnsignedInt width( void ) { return m_width;}; ///< Returns pixel width of visible texture
  112. UnsignedInt height( void ) { return m_height;}; ///< Returns pixel height of visible texture
  113. UnsignedInt textureWidth( void ) { return m_textureWidth;}; ///< Returns pixel width of texture
  114. UnsignedInt textureHeight( void ) { return m_textureHeight;}; ///< Returns pixel height of texture
  115. UnsignedInt pitch( void ) { return m_pitch;}; ///< Returns buffer pitch in bytes
  116. Type format( void ) { return m_format;}; ///< Returns buffer pixel format
  117. RectClass Rect( Real x1, Real y1, Real x2, Real y2 );
  118. };
  119. //===============================
  120. // VideoStreamInterface
  121. //===============================
  122. /**
  123. * Video stream interface class.
  124. */
  125. //===============================
  126. class VideoStreamInterface
  127. {
  128. friend class VideoPlayerInterface;
  129. protected:
  130. virtual ~VideoStreamInterface(){}; ///< only VideoPlayerInterfaces can create these
  131. public:
  132. virtual VideoStreamInterface* next( void ) = 0; ///< Returns next open stream
  133. virtual void update( void ) = 0; ///< Update stream
  134. virtual void close( void ) = 0; ///< Close and free stream
  135. virtual Bool isFrameReady( void ) = 0; ///< Is the frame ready to be displayed
  136. virtual void frameDecompress( void ) = 0; ///< Render current frame in to buffer
  137. virtual void frameRender( VideoBuffer *buffer ) = 0; ///< Render current frame in to buffer
  138. virtual void frameNext( void ) = 0; ///< Advance to next frame
  139. virtual Int frameIndex( void ) = 0; ///< Returns zero based index of current frame
  140. virtual Int frameCount( void ) = 0; ///< Returns the total number of frames in the stream
  141. virtual void frameGoto( Int index ) = 0; ///< Go to the spcified frame index
  142. virtual Int height( void ) = 0; ///< Return the height of the video
  143. virtual Int width( void ) = 0; ///< Return the width of the video
  144. };
  145. //===============================
  146. // VideoStream
  147. //===============================
  148. class VideoStream : public VideoStreamInterface
  149. {
  150. friend class VideoPlayer;
  151. protected:
  152. VideoPlayer *m_player; ///< Video player we were created with
  153. VideoStream *m_next; ///< Next open stream
  154. VideoStream(); ///< only VideoPlayer can create these
  155. virtual ~VideoStream();
  156. public:
  157. virtual VideoStreamInterface* next( void ); ///< Returns next open stream
  158. virtual void update( void ); ///< Update stream
  159. virtual void close( void ); ///< Close and free stream
  160. virtual Bool isFrameReady( void ); ///< Is the frame ready to be displayed
  161. virtual void frameDecompress( void ); ///< Render current frame in to buffer
  162. virtual void frameRender( VideoBuffer *buffer ); ///< Render current frame in to buffer
  163. virtual void frameNext( void ); ///< Advance to next frame
  164. virtual Int frameIndex( void ); ///< Returns zero based index of current frame
  165. virtual Int frameCount( void ); ///< Returns the total number of frames in the stream
  166. virtual void frameGoto( Int index ); ///< Go to the spcified frame index
  167. virtual Int height( void ); ///< Return the height of the video
  168. virtual Int width( void ); ///< Return the width of the video
  169. };
  170. //===============================
  171. // VideoPlayerInterface
  172. //===============================
  173. /**
  174. * Interface for video playback.
  175. */
  176. //===============================
  177. class VideoPlayerInterface : public SubsystemInterface
  178. {
  179. public:
  180. virtual void init( void ) = 0; ///< Initialize video playback
  181. virtual void reset( void ) = 0; ///< Reset video playback
  182. virtual void update( void ) = 0; ///< Services all video tasks. Should be called frequently
  183. virtual void deinit( void ) = 0; ///< Close down player
  184. virtual ~VideoPlayerInterface() {};
  185. // service
  186. virtual void loseFocus( void ) = 0; ///< Should be called when application loses focus
  187. virtual void regainFocus( void ) = 0; ///< Should be called when application regains focus
  188. virtual VideoStreamInterface* open( AsciiString movieTitle ) = 0; ///< Open video file for playback
  189. virtual VideoStreamInterface* load( AsciiString movieTitle ) = 0; ///< Load video file in to memory for playback
  190. virtual VideoStreamInterface* firstStream( void ) = 0; ///< Return the first open/loaded video stream
  191. virtual void closeAllStreams( void ) = 0; ///< Close all open streams
  192. virtual void addVideo( Video* videoToAdd ) = 0; ///< Add a video to the list of videos we can play
  193. virtual void removeVideo( Video* videoToRemove ) = 0; ///< Remove a video to the list of videos we can play
  194. virtual Int getNumVideos( void ) = 0; ///< Retrieve info about the number of videos currently listed
  195. virtual const Video* getVideo( AsciiString movieTitle ) = 0; ///< Retrieve info about a movie based on internal name
  196. virtual const Video* getVideo( Int index ) = 0; ///< Retrieve info about a movie based on index
  197. virtual const FieldParse *getFieldParse( void ) const = 0; ///< Return the field parse info
  198. virtual void notifyVideoPlayerOfNewProvider( Bool nowHasValid ) = 0; ///< Notify the video player that they can now ask for an audio handle, or they need to give theirs up.
  199. };
  200. //===============================
  201. // VideoPlayer
  202. //===============================
  203. /**
  204. * Common video playback code.
  205. */
  206. //===============================
  207. class VideoPlayer : public VideoPlayerInterface
  208. {
  209. protected:
  210. VecVideo mVideosAvailableForPlay;
  211. VideoStream *m_firstStream;
  212. static const FieldParse m_videoFieldParseTable[];
  213. public:
  214. // subsytem requirements
  215. virtual void init( void ); ///< Initialize video playback code
  216. virtual void reset( void ); ///< Reset video playback
  217. virtual void update( void ); ///< Services all audio tasks. Should be called frequently
  218. virtual void deinit( void ); ///< Close down player
  219. VideoPlayer();
  220. ~VideoPlayer();
  221. // service
  222. virtual void loseFocus( void ); ///< Should be called when application loses focus
  223. virtual void regainFocus( void ); ///< Should be called when application regains focus
  224. virtual VideoStreamInterface* open( AsciiString movieTitle ); ///< Open video file for playback
  225. virtual VideoStreamInterface* load( AsciiString movieTitle ); ///< Load video file in to memory for playback
  226. virtual VideoStreamInterface* firstStream( void ); ///< Return the first open/loaded video stream
  227. virtual void closeAllStreams( void ); ///< Close all open streams
  228. virtual void addVideo( Video* videoToAdd ); ///< Add a video to the list of videos we can play
  229. virtual void removeVideo( Video* videoToRemove ); ///< Remove a video to the list of videos we can play
  230. virtual Int getNumVideos( void ); ///< Retrieve info about the number of videos currently listed
  231. virtual const Video* getVideo( AsciiString movieTitle ); ///< Retrieve info about a movie based on internal name
  232. virtual const Video* getVideo( Int index ); ///< Retrieve info about a movie based on index
  233. virtual const FieldParse *getFieldParse( void ) const { return m_videoFieldParseTable; } ///< Return the field parse info
  234. virtual void notifyVideoPlayerOfNewProvider( Bool nowHasValid ) { }
  235. // Implementation specific
  236. void remove( VideoStream *stream ); ///< remove stream from active list
  237. };
  238. extern VideoPlayerInterface *TheVideoPlayer;
  239. //----------------------------------------------------------------------------
  240. // Inlining
  241. //----------------------------------------------------------------------------
  242. #endif // __GAMECLIENT_VIDEOPLAYER_H_