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.

198 lines
7.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. //=============================================================================
  9. #ifndef VIDEOSERVICES_H
  10. #define VIDEOSERVICES_H
  11. #if defined ( WIN32 )
  12. #pragma once
  13. #endif
  14. #include "video/ivideoservices.h"
  15. #include "videosubsystem.h"
  16. struct CVideFileoExtInfo_t
  17. {
  18. const char *m_pExtension; // extension including "."
  19. VideoSystem_t m_VideoSystemSupporting;
  20. VideoSystemFeature_t m_VideoFeaturesSupporting;
  21. };
  22. struct CActiveVideoObjectRecord_t
  23. {
  24. void *m_pObject;
  25. int m_VideoSystem;
  26. };
  27. //-----------------------------------------------------------------------------
  28. // Main VIDEO_SERVICES interface
  29. //-----------------------------------------------------------------------------
  30. class CValveVideoServices : public CTier3AppSystem< IVideoServices >
  31. {
  32. typedef CTier3AppSystem< IVideoServices > BaseClass;
  33. public:
  34. CValveVideoServices();
  35. ~CValveVideoServices();
  36. // Inherited from IAppSystem
  37. virtual bool Connect( CreateInterfaceFn factory );
  38. virtual void Disconnect();
  39. virtual void *QueryInterface( const char *pInterfaceName );
  40. virtual InitReturnVal_t Init();
  41. virtual void Shutdown();
  42. // Inherited from IVideoServices
  43. // Query the available video systems
  44. virtual int GetAvailableVideoSystemCount();
  45. virtual VideoSystem_t GetAvailableVideoSystem( int n );
  46. virtual bool IsVideoSystemAvailable( VideoSystem_t videoSystem );
  47. virtual VideoSystemStatus_t GetVideoSystemStatus( VideoSystem_t videoSystem );
  48. virtual VideoSystemFeature_t GetVideoSystemFeatures( VideoSystem_t videoSystem );
  49. virtual const char *GetVideoSystemName( VideoSystem_t videoSystem );
  50. virtual VideoSystem_t FindNextSystemWithFeature( VideoSystemFeature_t features, VideoSystem_t startAfter = VideoSystem::NONE );
  51. virtual VideoResult_t GetLastResult();
  52. // deal with video file extensions and video system mappings
  53. virtual int GetSupportedFileExtensionCount( VideoSystem_t videoSystem );
  54. virtual const char *GetSupportedFileExtension( VideoSystem_t videoSystem, int extNum = 0 );
  55. virtual VideoSystemFeature_t GetSupportedFileExtensionFeatures( VideoSystem_t videoSystem, int extNum = 0 );
  56. virtual VideoSystem_t LocateVideoSystemForPlayingFile( const char *pFileName, VideoSystemFeature_t playMode = VideoSystemFeature::PLAY_VIDEO_FILE_IN_MATERIAL );
  57. virtual VideoResult_t LocatePlayableVideoFile( const char *pSearchFileName, const char *pPathID, VideoSystem_t *pPlaybackSystem, char *pPlaybackFileName, int fileNameMaxLen, VideoSystemFeature_t playMode = VideoSystemFeature::FULL_PLAYBACK );
  58. // Create/destroy a video material
  59. virtual IVideoMaterial *CreateVideoMaterial( const char *pMaterialName, const char *pVideoFileName, const char *pPathID = nullptr,
  60. VideoPlaybackFlags_t playbackFlags = VideoPlaybackFlags::DEFAULT_MATERIAL_OPTIONS,
  61. VideoSystem_t videoSystem = VideoSystem::DETERMINE_FROM_FILE_EXTENSION, bool PlayAlternateIfNotAvailable = true );
  62. virtual VideoResult_t DestroyVideoMaterial( IVideoMaterial* pVideoMaterial );
  63. virtual int GetUniqueMaterialID();
  64. // Create/destroy a video encoder
  65. virtual VideoResult_t IsRecordCodecAvailable( VideoSystem_t videoSystem, VideoEncodeCodec_t codec );
  66. virtual IVideoRecorder *CreateVideoRecorder( VideoSystem_t videoSystem );
  67. virtual VideoResult_t DestroyVideoRecorder( IVideoRecorder *pVideoRecorder );
  68. // Plays a given video file until it completes or the user presses ESC, SPACE, or ENTER
  69. virtual VideoResult_t PlayVideoFileFullScreen( const char *pFileName, const char *pPathID, void *mainWindow, int windowWidth, int windowHeight, int desktopWidth, int desktopHeight, bool windowed, float forcedMinTime,
  70. VideoPlaybackFlags_t playbackFlags = VideoPlaybackFlags::DEFAULT_FULLSCREEN_OPTIONS,
  71. VideoSystem_t videoSystem = VideoSystem::DETERMINE_FROM_FILE_EXTENSION, bool PlayAlternateIfNotAvailable = true );
  72. // Sets the sound devices that the video will decode to
  73. virtual VideoResult_t SoundDeviceCommand( VideoSoundDeviceOperation_t operation, void *pDevice = nullptr, void *pData = nullptr, VideoSystem_t videoSystem = VideoSystem::ALL_VIDEO_SYSTEMS );
  74. // Get the name of a codec as a string
  75. const wchar_t *GetCodecName( VideoEncodeCodec_t nCodec );
  76. private:
  77. VideoResult_t ResolveToPlayableVideoFile( const char *pFileName, const char *pPathID, VideoSystem_t videoSystem, VideoSystemFeature_t requiredFeature, bool PlayAlternateIfNotAvailable,
  78. char *pResolvedFileName, int resolvedFileNameMaxLen, VideoSystem_t *pResolvedVideoSystem );
  79. VideoSystem_t LocateSystemAndFeaturesForFileName( const char *pFileName, VideoSystemFeature_t *pFeatures = nullptr, VideoSystemFeature_t requiredFeatures = VideoSystemFeature::NO_FEATURES );
  80. bool IsMatchAnyExtension( const char *pFileName );
  81. bool ConnectVideoLibraries( CreateInterfaceFn factory );
  82. bool DisconnectVideoLibraries();
  83. int DestroyAllVideoInterfaces();
  84. int GetIndexForSystem( VideoSystem_t n );
  85. VideoSystem_t GetSystemForIndex( int n );
  86. VideoResult_t SetResult( VideoResult_t resultCode );
  87. const char *GetFileExtension( const char *pFileName );
  88. static const int SYSTEM_NOT_FOUND = -1;
  89. VideoResult_t m_LastResult;
  90. int m_nInstalledSystems;
  91. bool m_bInitialized;
  92. CSysModule *m_VideoSystemModule[VideoSystem::VIDEO_SYSTEM_COUNT];
  93. IVideoSubSystem *m_VideoSystems[VideoSystem::VIDEO_SYSTEM_COUNT];
  94. VideoSystem_t m_VideoSystemType[VideoSystem::VIDEO_SYSTEM_COUNT];
  95. VideoSystemFeature_t m_VideoSystemFeatures[VideoSystem::VIDEO_SYSTEM_COUNT];
  96. CUtlVector< VideoFileExtensionInfo_t > m_ExtInfo; // info about supported file extensions
  97. CUtlVector< CActiveVideoObjectRecord_t > m_RecorderList;
  98. CUtlVector< CActiveVideoObjectRecord_t > m_MaterialList;
  99. int m_nMaterialCount;
  100. };
  101. class CVideoCommonServices : public IVideoCommonServices
  102. {
  103. public:
  104. CVideoCommonServices();
  105. ~CVideoCommonServices();
  106. virtual bool CalculateVideoDimensions( int videoWidth, int videoHeight, int displayWidth, int displayHeight, VideoPlaybackFlags_t playbackFlags,
  107. int *pOutputWidth, int *pOutputHeight, int *pXOffset, int *pYOffset );
  108. virtual float GetSystemVolume();
  109. virtual VideoResult_t InitFullScreenPlaybackInputHandler( VideoPlaybackFlags_t playbackFlags, float forcedMinTime, bool windowed );
  110. virtual bool ProcessFullScreenInput( bool &bAbortEvent, bool &bPauseEvent, bool &bQuitEvent );
  111. virtual VideoResult_t TerminateFullScreenPlaybackInputHandler();
  112. private:
  113. void ResetInputHandlerState();
  114. bool m_bInputHandlerInitialized;
  115. bool m_bScanAll;
  116. bool m_bScanEsc;
  117. bool m_bScanReturn;
  118. bool m_bScanSpace;
  119. bool m_bPauseEnabled;
  120. bool m_bAbortEnabled;
  121. bool m_bEscLast;
  122. bool m_bReturnLast;
  123. bool m_bSpaceLast;
  124. bool m_bForceMinPlayTime;
  125. bool m_bWindowed;
  126. VideoPlaybackFlags_t m_playbackFlags;
  127. float m_forcedMinTime;
  128. double m_StartTime;
  129. };
  130. #endif // VIDEOSERVICES_H