Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

274 lines
8.0 KiB

  1. //===== Copyright (c) 2010, Valve Corporation, All rights reserved. ===========
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef QUICKTIME_H
  7. #define QUICKTIME_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include <avi/iquicktime.h>
  12. //-----------------------------------------------------------------------------
  13. // Forward declarations
  14. //-----------------------------------------------------------------------------
  15. class IFileSystem;
  16. class IMaterialSystem;
  17. class CQuickTimeMaterial;
  18. //-----------------------------------------------------------------------------
  19. // Global interfaces - you already did the needed includes, right?
  20. //-----------------------------------------------------------------------------
  21. extern IFileSystem *g_pFileSystem;
  22. extern IMaterialSystem *materials;
  23. //-----------------------------------------------------------------------------
  24. // Quicktime includes - conditional compilation on #define QUICKTIME in VPC
  25. // The intent is to have a default functionality fallback if not defined
  26. // which provides a dynamically generated texture (moving line on background)
  27. //-----------------------------------------------------------------------------
  28. #if defined( QUICKTIME_VIDEO )
  29. #if defined ( OSX )
  30. #include <quicktime/QTML.h>
  31. #include <quicktime/Movies.h>
  32. #elif defined ( WIN32 )
  33. #include <QTML.h>
  34. #include <Movies.h>
  35. #include <windows.h>
  36. #endif
  37. #else
  38. typedef TimeValue long;
  39. #endif
  40. // -----------------------------------------------------------------------
  41. // eVideoFrameFormat_t - bitformat for quicktime video frames
  42. // -----------------------------------------------------------------------
  43. enum eVideoFrameFormat_t
  44. {
  45. cVFF_Undefined = 0,
  46. cVFF_R8G8B8A8_32Bit,
  47. cVFF_R8G8B8_24Bit,
  48. cVFF_Count, // Auto list counter
  49. cVFF_ForceInt32 = 0x7FFFFFFF // Make sure eNum is (at least) an int32
  50. };
  51. //-----------------------------------------------------------------------------
  52. // texture regenerator - callback to get new movie pixels into the texture
  53. //-----------------------------------------------------------------------------
  54. class CQuicktimeMaterialRGBTextureRegenerator : public ITextureRegenerator
  55. {
  56. public:
  57. CQuicktimeMaterialRGBTextureRegenerator() :
  58. m_pQTMaterial( NULL ),
  59. m_nSourceWidth( 0 ),
  60. m_nSourceHeight( 0 )
  61. {
  62. }
  63. void SetParentMaterial( CQuickTimeMaterial *pQTMaterial, int nWidth, int nHeight )
  64. {
  65. m_pQTMaterial = pQTMaterial;
  66. m_nSourceWidth = nWidth;
  67. m_nSourceHeight = nHeight;
  68. }
  69. // Inherited from ITextureRegenerator
  70. virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pRect );
  71. virtual void Release();
  72. private:
  73. CQuickTimeMaterial *m_pQTMaterial;
  74. int m_nSourceWidth;
  75. int m_nSourceHeight;
  76. };
  77. //-----------------------------------------------------------------------------
  78. //
  79. // Class used to associated QuickTime video files with IMaterials
  80. //
  81. //-----------------------------------------------------------------------------
  82. class CQuickTimeMaterial
  83. {
  84. public:
  85. CQuickTimeMaterial();
  86. ~CQuickTimeMaterial();
  87. // Initializes, shuts down the material
  88. bool Init( const char *pMaterialName, const char *pFileName, const char *pPathID );
  89. void Shutdown();
  90. // Keeps the frames updated
  91. bool Update( void );
  92. // Check if a new frame is available
  93. bool ReadyForSwap( void );
  94. // Returns the material
  95. IMaterial *GetMaterial();
  96. // Returns the texcoord range
  97. void GetTexCoordRange( float *pMaxU, float *pMaxV );
  98. // Returns the frame size of the QuickTime Video (stored in a subrect of the material itself)
  99. void GetFrameSize( int *pWidth, int *pHeight );
  100. // Sets the current time
  101. void SetTime( float flTime );
  102. // Returns the frame rate/count of the QuickTime Material
  103. int GetFrameRate( );
  104. int GetFrameCount( );
  105. // Sets the frame for an QuickTime material (use instead of SetTime) ??
  106. void SetFrame( float flFrame );
  107. void SetLooping( bool loop );
  108. private:
  109. friend class CQuicktimeMaterialRGBTextureRegenerator;
  110. void Reset();
  111. void OpenQTMovie( const char* theQTMovieFileName );
  112. void SetQTFileName( const char *theQTMovieFileName );
  113. void GetErrorFrame();
  114. void CloseQTFile();
  115. // Initializes, shuts down the procedural texture
  116. void CreateProceduralTexture( const char *pTextureName );
  117. void DestroyProceduralTexture();
  118. // Initializes, shuts down the procedural material
  119. void CreateProceduralMaterial( const char *pMaterialName );
  120. void DestroyProceduralMaterial();
  121. // Initializes, shuts down the video stream
  122. CQuicktimeMaterialRGBTextureRegenerator m_TextureRegen;
  123. CMaterialReference m_Material; // Ref to Material used for rendering the video frame
  124. CTextureReference m_Texture; // Ref to the renderable texture which contains the most recent video frame (in a sub-rect)
  125. float m_TexCordU; // Max U texture coordinate of the texture sub-rect which holds the video frame
  126. float m_TexCordV; // Max V texture coordinate of the texture sub-rect which holds the video frame
  127. int m_VideoFrameWidth;
  128. int m_VideoFrameHeight;
  129. char *m_pFileName;
  130. char m_TextureName[128];
  131. char m_MaterialName[128];
  132. bool m_bActive;
  133. bool m_bLoopMovie;
  134. bool m_bMoviePlaying;
  135. double m_MovieBeganPlayingTime;
  136. double m_MovieCurrentTime;
  137. #if defined( QUICKTIME_VIDEO )
  138. // QuickTime Stuff
  139. Movie m_QTMovie;
  140. TimeValue m_QTMovieTimeScale; // Units per second
  141. TimeValue m_QTMovieDuration; // movie duration is UPS
  142. float m_QTMovieDurationinSec; // movie duration in seconds
  143. long m_QTMoveFrameRate;
  144. Rect m_QTMovieRect;
  145. GWorldPtr m_MovieGWorld;
  146. QTAudioContextRef m_AudioContext;
  147. TimeValue m_LastInterestingTimePlayed;
  148. TimeValue m_NextInterestingTimeToPlay;
  149. // our Frame buffer stuff
  150. #if defined ( WIN32 )
  151. BITMAPINFO m_BitmapInfo;
  152. #endif
  153. #endif
  154. void *m_BitMapData;
  155. int m_BitMapDataSize;
  156. bool m_bIsErrorFrame;
  157. float m_nLastFrameTime;
  158. static const int cMaxQTFileNameLen = 255;
  159. static const int cMinVideoFrameWidth = 16;
  160. static const int cMinVideoFrameHeight = 16;
  161. static const int cMaxVideoFrameWidth = 2048;
  162. static const int cMaxVideoFrameHeight = 2048;
  163. };
  164. //-----------------------------------------------------------------------------
  165. //
  166. // Implementation of IQuickTime
  167. //
  168. //-----------------------------------------------------------------------------
  169. class CQuickTime : public CBaseAppSystem<IQuickTime>
  170. {
  171. public:
  172. CQuickTime();
  173. ~CQuickTime();
  174. // Inherited from IAppSystem
  175. virtual bool Connect( CreateInterfaceFn factory );
  176. virtual void Disconnect();
  177. virtual void *QueryInterface( const char *pInterfaceName );
  178. virtual InitReturnVal_t Init();
  179. virtual void Shutdown();
  180. // Inherited from IQuickTime
  181. virtual QUICKTIMEMaterial_t CreateMaterial( const char *pMaterialName, const char *pFileName, const char *pPathID, int flags = 0 );
  182. virtual void DestroyMaterial( QUICKTIMEMaterial_t hMaterial );
  183. virtual bool Update( QUICKTIMEMaterial_t hMaterial );
  184. virtual bool ReadyForSwap( QUICKTIMEMaterial_t hMaterial );
  185. virtual IMaterial *GetMaterial( QUICKTIMEMaterial_t hMaterial );
  186. virtual void GetTexCoordRange( QUICKTIMEMaterial_t hMaterial, float *pMaxU, float *pMaxV );
  187. virtual void GetFrameSize( QUICKTIMEMaterial_t hMaterial, int *pWidth, int *pHeight );
  188. virtual int GetFrameRate( QUICKTIMEMaterial_t hMaterial );
  189. virtual void SetFrame( QUICKTIMEMaterial_t hMaterial, float flFrame );
  190. virtual int GetFrameCount( QUICKTIMEMaterial_t hMaterial );
  191. virtual bool SetSoundDevice( void *pDevice );
  192. private:
  193. bool SetupQuicktime();
  194. void ShutdownQuicktime();
  195. // NOTE: Have to use pointers here since QuickTimeKMaterials inherit from ITextureRegenerator
  196. // The realloc screws up the pointers held to ITextureRegenerators in the material system.
  197. CUtlLinkedList< CQuickTimeMaterial*, QUICKTIMEMaterial_t > m_QTMaterials;
  198. bool m_bQTInitialized;
  199. };
  200. #endif // QUICKTIME_H