Team Fortress 2 Source Code as on 22/4/2020
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.

221 lines
8.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef QUICKTIME_MATERIAL_H
  7. #define QUICKTIME_MATERIAL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. //-----------------------------------------------------------------------------
  12. // Forward declarations
  13. //-----------------------------------------------------------------------------
  14. class IFileSystem;
  15. class IMaterialSystem;
  16. class CQuickTimeMaterial;
  17. //-----------------------------------------------------------------------------
  18. // Global interfaces - you already did the needed includes, right?
  19. //-----------------------------------------------------------------------------
  20. extern IFileSystem *g_pFileSystem;
  21. extern IMaterialSystem *materials;
  22. //-----------------------------------------------------------------------------
  23. // Quicktime includes
  24. //-----------------------------------------------------------------------------
  25. #if defined ( OSX )
  26. #include <quicktime/QTML.h>
  27. #include <quicktime/Movies.h>
  28. #include <quicktime/MediaHandlers.h>
  29. #elif defined ( WIN32 )
  30. #include <QTML.h>
  31. #include <Movies.h>
  32. #include <windows.h>
  33. #include <MediaHandlers.h>
  34. #elif
  35. #error "Quicktime not supported on this target platform"
  36. #endif
  37. #include "video/ivideoservices.h"
  38. #include "video_macros.h"
  39. #include "quicktime_common.h"
  40. #include "materialsystem/itexture.h"
  41. #include "materialsystem/imaterialsystem.h"
  42. #include "materialsystem/MaterialSystemUtil.h"
  43. // -----------------------------------------------------------------------------
  44. // Texture regenerator - callback to get new movie pixels into the texture
  45. // -----------------------------------------------------------------------------
  46. class CQuicktimeMaterialRGBTextureRegenerator : public ITextureRegenerator
  47. {
  48. public:
  49. CQuicktimeMaterialRGBTextureRegenerator();
  50. ~CQuicktimeMaterialRGBTextureRegenerator();
  51. void SetSourceGWorld( GWorldPtr theGWorld, int nWidth, int nHeight );
  52. // Inherited from ITextureRegenerator
  53. virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pRect );
  54. virtual void Release();
  55. private:
  56. GWorldPtr m_SrcGWorld;
  57. int m_nSourceWidth;
  58. int m_nSourceHeight;
  59. };
  60. // -----------------------------------------------------------------------------
  61. // Class used to play a QuickTime video onto a texture
  62. // -----------------------------------------------------------------------------
  63. class CQuickTimeMaterial : public IVideoMaterial
  64. {
  65. public:
  66. CQuickTimeMaterial();
  67. ~CQuickTimeMaterial();
  68. static const int MAX_QT_FILENAME_LEN = 255;
  69. static const int MAX_MATERIAL_NAME_LEN = 255;
  70. static const int TEXTURE_SIZE_ALIGNMENT = 8;
  71. // Initializes, shuts down the material
  72. bool Init( const char *pMaterialName, const char *pFileName, VideoPlaybackFlags_t flags );
  73. void Shutdown();
  74. // Video information functions
  75. virtual const char *GetVideoFileName(); // Gets the file name of the video this material is playing
  76. virtual VideoResult_t GetLastResult(); // Gets detailed info on the last operation
  77. virtual VideoFrameRate_t &GetVideoFrameRate(); // Returns the frame rate of the associated video in FPS
  78. // Audio Functions
  79. virtual bool HasAudio(); // Query if the video has an audio track
  80. virtual bool SetVolume( float fVolume ); // Adjust the playback volume
  81. virtual float GetVolume(); // Query the current volume
  82. virtual void SetMuted( bool bMuteState ); // Mute/UnMutes the audio playback
  83. virtual bool IsMuted(); // Query muted status
  84. virtual VideoResult_t SoundDeviceCommand( VideoSoundDeviceOperation_t operation, void *pDevice = nullptr, void *pData = nullptr ); // Assign Sound Device for this Video Material
  85. // Video playback state functions
  86. virtual bool IsVideoReadyToPlay(); // Queries if the video material was initialized successfully and is ready for playback, but not playing or finished
  87. virtual bool IsVideoPlaying(); // Is the video currently playing (and needs update calls, etc)
  88. virtual bool IsNewFrameReady(); // Do we have a new frame to get & display?
  89. virtual bool IsFinishedPlaying(); // Have we reached the end of the movie
  90. virtual bool StartVideo(); // Starts the video playing
  91. virtual bool StopVideo(); // Terminates the video playing
  92. virtual void SetLooping( bool bLoopVideo ); // Sets the video to loop (or not)
  93. virtual bool IsLooping(); // Queries if the video is looping
  94. virtual void SetPaused( bool bPauseState ); // Pauses or Unpauses video playback
  95. virtual bool IsPaused(); // Queries if the video is paused
  96. // Position in playback functions
  97. virtual float GetVideoDuration(); // Returns the duration of the associated video in seconds
  98. virtual int GetFrameCount(); // Returns the total number of (unique) frames in the video
  99. virtual bool SetFrame( int FrameNum ); // Sets the current frame # in the video to play next
  100. virtual int GetCurrentFrame(); // Gets the current frame # for the video playback, 0 Based
  101. virtual bool SetTime( float flTime ); // Sets the video playback to specified time (in seconds)
  102. virtual float GetCurrentVideoTime(); // Gets the current time in the video playback
  103. // Update function
  104. virtual bool Update(); // Updates the video frame to reflect the time passed, true = new frame available
  105. // Material / Texture Info functions
  106. virtual IMaterial *GetMaterial(); // Gets the IMaterial associated with an video material
  107. virtual void GetVideoTexCoordRange( float *pMaxU, float *pMaxV ) ; // Returns the max texture coordinate of the video portion of the material surface ( 0.0, 0.0 to U, V )
  108. virtual void GetVideoImageSize( int *pWidth, int *pHeight ); // Returns the frame size of the Video Image Frame in pixels ( the stored in a subrect of the material itself)
  109. private:
  110. friend class CQuicktimeMaterialRGBTextureRegenerator;
  111. void Reset(); // clears internal state
  112. void SetQTFileName( const char *theQTMovieFileName );
  113. VideoResult_t SetResult( VideoResult_t status );
  114. // Initializes, shuts down the video stream
  115. void OpenQTMovie( const char *theQTMovieFileName );
  116. void CloseQTFile();
  117. // Initializes, shuts down the procedural texture
  118. void CreateProceduralTexture( const char *pTextureName );
  119. void DestroyProceduralTexture();
  120. // Initializes, shuts down the procedural material
  121. void CreateProceduralMaterial( const char *pMaterialName );
  122. void DestroyProceduralMaterial();
  123. CQuicktimeMaterialRGBTextureRegenerator m_TextureRegen;
  124. VideoResult_t m_LastResult;
  125. CMaterialReference m_Material; // Ref to Material used for rendering the video frame
  126. CTextureReference m_Texture; // Ref to the renderable texture which contains the most recent video frame (in a sub-rect)
  127. float m_TexCordU; // Max U texture coordinate of the texture sub-rect which holds the video frame
  128. float m_TexCordV; // Max V texture coordinate of the texture sub-rect which holds the video frame
  129. int m_VideoFrameWidth; // Size of the movie frame in pixels
  130. int m_VideoFrameHeight;
  131. char *m_pFileName; // resolved filename of the movie being played
  132. VideoPlaybackFlags_t m_PlaybackFlags; // option flags user supplied
  133. bool m_bInitCalled;
  134. bool m_bMovieInitialized;
  135. bool m_bMoviePlaying;
  136. bool m_bMovieFinishedPlaying;
  137. bool m_bMoviePaused;
  138. bool m_bLoopMovie;
  139. bool m_bHasAudio;
  140. bool m_bMuted;
  141. float m_CurrentVolume;
  142. // QuickTime Stuff
  143. Movie m_QTMovie;
  144. TimeScale m_QTMovieTimeScale; // Units per second
  145. TimeValue m_QTMovieDuration; // movie duration in TimeScale Units Per Second
  146. float m_QTMovieDurationinSec; // movie duration in seconds
  147. VideoFrameRate_t m_QTMovieFrameRate; // Frame Rate of movie
  148. int m_QTMovieFrameCount;
  149. Rect m_QTMovieRect;
  150. GWorldPtr m_MovieGWorld;
  151. QTAudioContextRef m_AudioContext;
  152. TimeValue m_MovieFirstFrameTime;
  153. TimeValue m_NextInterestingTimeToPlay;
  154. TimeValue m_MoviePauseTime;
  155. };
  156. #endif // QUICKTIME_MATERIAL_H