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.

142 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #include "cbase.h"
  5. #if defined( REPLAY_ENABLED )
  6. #include "replayvideo.h"
  7. // memdbgon must be the last include file in a .cpp file!!!
  8. #include <tier0/memdbgon.h>
  9. //-----------------------------------------------------------------------------
  10. static ReplayVideoMode_t s_VideoModes[] =
  11. {
  12. { 720, 480, 24, true, "#Replay_Res_480p" },
  13. { 1280, 720, 24, true, "#Replay_Res_720p" },
  14. { 1920, 1080, 24, true, "#Replay_Res_1080p" },
  15. { 320, 240, 15, false, "#Replay_Res_Web" },
  16. { 960, 640, 24, true, "#Replay_Res_iPhone_Horizontal" },
  17. { 640, 960, 24, true, "#Replay_Res_iPhone_Vertical" },
  18. };
  19. #define VIDEO_MODE_COUNT ( sizeof( s_VideoModes ) / sizeof( s_VideoModes[0] ) )
  20. //-----------------------------------------------------------------------------
  21. #ifdef USE_WEBM_FOR_REPLAY
  22. static ReplayCodec_t s_Codecs[] =
  23. {
  24. { VideoEncodeCodec::WEBM_CODEC, "#Replay_Codec_WEBM" },
  25. };
  26. static int s_nNumCodecs = ARRAYSIZE( s_Codecs );
  27. //-----------------------------------------------------------------------------
  28. static ReplayQualityPreset_t s_QualityPresets[] =
  29. {
  30. { "#Replay_RenderSetting_Low", VideoEncodeCodec::WEBM_CODEC, 0, false, 0 },
  31. { "#Replay_RenderSetting_Medium", VideoEncodeCodec::WEBM_CODEC, 50, false, 1 },
  32. { "#Replay_RenderSetting_High", VideoEncodeCodec::WEBM_CODEC, 100, true, 2 },
  33. { "#Replay_RenderSetting_Max", VideoEncodeCodec::WEBM_CODEC, 100, true, 3 },
  34. };
  35. static int s_NumQualityPresets = ARRAYSIZE( s_QualityPresets );
  36. static int s_DefaultQualityPreset = 1;
  37. #else
  38. static ReplayCodec_t s_Codecs[] =
  39. {
  40. { VideoEncodeCodec::MJPEG_A_CODEC, "#Replay_Codec_MJPEGA" },
  41. { VideoEncodeCodec::H264_CODEC, "#Replay_Codec_H264" },
  42. };
  43. static int s_nNumCodecs = ARRAYSIZE( s_Codecs );
  44. //-----------------------------------------------------------------------------
  45. static ReplayQualityPreset_t s_QualityPresets[] =
  46. {
  47. { "#Replay_RenderSetting_Low", VideoEncodeCodec::MJPEG_A_CODEC, 0, false, 0 },
  48. { "#Replay_RenderSetting_Medium", VideoEncodeCodec::MJPEG_A_CODEC, 50, false, 1 },
  49. { "#Replay_RenderSetting_High", VideoEncodeCodec::MJPEG_A_CODEC, 100, true, 2 },
  50. { "#Replay_RenderSetting_Max", VideoEncodeCodec::H264_CODEC, 100, true, 3 },
  51. };
  52. static int s_NumQualityPresets = ARRAYSIZE( s_QualityPresets );
  53. static int s_DefaultQualityPreset = 1;
  54. #endif
  55. //-----------------------------------------------------------------------------
  56. static const int s_QualityRange = 4;
  57. static const int s_QualityInterval = 100 / s_QualityRange;
  58. //-----------------------------------------------------------------------------
  59. int ReplayVideo_GetVideoModeCount()
  60. {
  61. return VIDEO_MODE_COUNT;
  62. }
  63. const ReplayVideoMode_t &ReplayVideo_GetVideoMode( int i )
  64. {
  65. AssertMsg( i >= 0 && i < VIDEO_MODE_COUNT, "Replay video mode out of range!" );
  66. return s_VideoModes[ i ];
  67. }
  68. int ReplayVideo_GetDefaultQualityPreset()
  69. {
  70. return s_DefaultQualityPreset;
  71. }
  72. int ReplayVideo_GetQualityInterval()
  73. {
  74. return s_QualityInterval;
  75. }
  76. int ReplayVideo_GetQualityRange()
  77. {
  78. return s_QualityRange;
  79. }
  80. int ReplayVideo_GetQualityPresetCount()
  81. {
  82. return s_NumQualityPresets;
  83. }
  84. const ReplayQualityPreset_t &ReplayVideo_GetQualityPreset( int i )
  85. {
  86. return s_QualityPresets[ i ];
  87. }
  88. int ReplayVideo_GetCodecCount()
  89. {
  90. return s_nNumCodecs;
  91. }
  92. const ReplayCodec_t &ReplayVideo_GetCodec( int i )
  93. {
  94. AssertMsg( i >= 0 && i < s_nNumCodecs, "Replay codec out of range!" );
  95. return s_Codecs[ i ];
  96. }
  97. int ReplayVideo_FindCodecPresetFromCodec( VideoEncodeCodec_t nCodecId )
  98. {
  99. AssertMsg( nCodecId < VideoEncodeCodec::CODEC_COUNT, "Codec ID out of range!" );
  100. for ( int i = 0; i < VideoEncodeCodec::CODEC_COUNT; ++i )
  101. {
  102. if ( s_Codecs[ i ].m_nCodecId == nCodecId )
  103. return i;
  104. }
  105. AssertMsg( 0, "Codec not found! This should never happen!" );
  106. return 0;
  107. }
  108. //-----------------------------------------------------------------------------
  109. #endif