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.

454 lines
15 KiB

  1. //===== Copyright � 1996-2009, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Video Caching Command Messages
  4. // Enums, structs, objects
  5. //
  6. // Used by //utils/videocache.exe and any app the talks to it.
  7. //
  8. // $Header: $
  9. // $NoKeywords: $
  10. //===========================================================================//
  11. #ifndef VIDEO_CACHE_COMMANDS_H
  12. #define VIDEO_CACHE_COMMANDS_H
  13. #include "videocache/videomaterialdefs.h"
  14. // -----------------------------------------------------------------------
  15. // Command type enumeration, parameters specified in comments
  16. // Required CVidCmd Parameters noted as follows:
  17. //
  18. // f0 - f2: 32-bit float parameters
  19. // i0 - I2: 32-bit int parameters
  20. // u0 - u2: unsigned 32-bit int parameters
  21. // np = no additional parameters
  22. //
  23. // Additional parameters that follow the CVidCmd struct are noted in "[]"
  24. // -----------------------------------------------------------------------
  25. enum eVidCacheCommand_t
  26. {
  27. cVCC_Unknown = 0, // Used to indicate uninitialized command
  28. cVCC_Ping = 1, // request ack from video cache app: np
  29. cVCC_Quit = 2, // request video cache app shutdown: np
  30. cVCC_Ack = 3, // general purpose response : np
  31. cVCC_BeginCacheSession = 0x09, // Request to begin a video caching session. i0 = local Id [CVideoCacheSessionInfo]
  32. cVCC_BeginCacheSessionResult = 0x0A, // Begin Session Result: i0 = local Id, b = Success bool, e = reason
  33. cVCC_EndCacheSession = 0x0C, // Request to end a video caching session i0 = Session ID
  34. // Response is Ack
  35. cVCC_CacheFile = 0x11, // Request to cache a file: i0 = Local Id, i1 = FileNameLen, [filename string]
  36. cVCC_CacheFileResult = 0x12, // Cache file Result Status: i0 = Local Id, b = Success bool, e = reason, u1 = Server Handle, [CVideoFrameInfo]
  37. cVCC_UncacheFile = 0x17, // Request to stop caching a file (no longer needed): u0 = Server Handle
  38. // Response is Ack
  39. cVCC_UncacheAllFiles = 0x18, // Request to unload all cached files (no longer needed): np
  40. // Response is Ack
  41. cVCC_RequestFrame = 0x21, // Request a frame from a file: u0 = Server Handle, f1 = Frame Time
  42. cVCC_RequestFrameResult = 0x22, // Frame Request Result: u0 = Server Handle, f1 = Frame time, b = Success bool, e = reason [CVideoFrameInfo], [Bitmap Pixels]
  43. cVCC_BeginEncodingSession = 0x31, // Begin a session to encode a movie: i0 = Local Id, i1 = FileNameLen, [CVideoEncodeSessionParams] [filename string]
  44. cVCC_BeginEncodingResult = 0x32, // Results of encoding session begin: i0 = Local ID, b = Success bool, e = reason, u1 = Server Handle
  45. cVCC_EncodeFrame = 0x37, // Receive Frame of Video to encode: u0 = Server Handle, i1 = Frame Number [ Video Frame Data ]
  46. cVCC_EncodeFrameResult = 0x38, // Encode Frame Result u0 = Server Handle, i1 = Frame Number, bi2 = Success bool
  47. cVCC_EndEncodingSession = 0x3A, // End an encoding sessions: u0 = Server Handle
  48. cVCC_EndEncodingResult = 0x3B, // Result of encoding session end: u0 = Server Handle, i1 = Success bool
  49. cVCC_ForceUint8 = UINT8_MAX
  50. };
  51. // enum eVidCacheError_t
  52. // {
  53. // cVCE_NoErr = 0, // success!
  54. //
  55. // cVCE_NoChacheSession, // not in a current cache session
  56. // cVCE_CacheSessionOpen, // already opened a cache session
  57. // cVCE_FileNotFound, // the file doesn't exist
  58. // cVCE_FileNotMovie, // unable to open file as a movie
  59. //
  60. // cVCE_ForceUint8 = UINT8_MAX
  61. // };
  62. struct CVideoCacheSessionInfo
  63. {
  64. public:
  65. int32 m_nFrameWidth;
  66. int32 m_nFrameHeight;
  67. eVideoFrameFormat_t m_FrameFormat;
  68. CVideoCacheSessionInfo()
  69. {
  70. V_memset( this, 0, sizeof( *this ) );
  71. }
  72. CVideoCacheSessionInfo( int width, int height, eVideoFrameFormat_t format ) :
  73. m_nFrameWidth( width ),
  74. m_nFrameHeight( height ),
  75. m_FrameFormat( format )
  76. {
  77. }
  78. };
  79. // -----------------------------------------------------------------------
  80. // CVideoFrameInfo - Info about the uncompressed bitmaps that
  81. // are served up. 32 bpp RBGA is assumed
  82. // -----------------------------------------------------------------------
  83. struct CVideoFrameInfo
  84. {
  85. public:
  86. int32 m_nBitMapWidth;
  87. int32 m_nBitmapHeight;
  88. int32 m_nBitmapImageBytes;
  89. eVideoFrameFormat_t m_BitmapFormat;
  90. float m_nImageTime;
  91. // constructors
  92. CVideoFrameInfo() :
  93. m_nBitMapWidth( 0 ),
  94. m_nBitmapHeight( 0 ),
  95. m_nBitmapImageBytes( 0 ),
  96. m_BitmapFormat( cVFF_Undefined ),
  97. m_nImageTime( VIDEO_TIME_UNINITALIZED )
  98. {
  99. }
  100. CVideoFrameInfo( float timeVal, int width, int height ) :
  101. m_nBitMapWidth( width ),
  102. m_nBitmapHeight( height ),
  103. m_nBitmapImageBytes( width * height * 4 ),
  104. m_nImageTime( timeVal )
  105. {
  106. }
  107. };
  108. // -----------------------------------------------------------------------
  109. // CVideoEncodeSessionParams - Info about the movie we would like to
  110. // create from still frames (and later, Audio data)
  111. // -----------------------------------------------------------------------
  112. struct CVideoEncodeSessionParams
  113. {
  114. public:
  115. int32 m_VideoFPSRate; // Number of frames per second the video will be recorded at
  116. int32 m_VideoDurationInFrames; // Number of frames total in the movie
  117. int32 m_VideoFrameImageWidth; // Horizontal resolution of the video source images
  118. int32 m_VideoFrameImageHeight; // Vertical resolution of the video source images
  119. eVideoFrameFormat_t m_VideoFrameFormat; // Format of the frames to be received
  120. int32 m_VideoCodecToUse; // Codec to use for encoding
  121. int32 m_VideoQuality; // Quality of the video encoding
  122. int32 m_VideoFrameImageSize; // Size of the images buffer for one frame
  123. int32 m_nCurrentFrameNo; // current frame number
  124. // accessors
  125. inline eVideoFrameFormat_t GetFormat() { return m_VideoFrameFormat; }
  126. inline void SetFormat( eVideoFrameFormat_t theFormat ) { m_VideoFrameFormat = theFormat; }
  127. inline eVideoCodec_t GetCodec() { return (eVideoCodec_t) m_VideoCodecToUse; }
  128. inline void SetCodec( eVideoCodec_t theCodec ) { m_VideoCodecToUse = (int32) theCodec; }
  129. inline eVideoQuality_t GetQuality() { return (eVideoQuality_t) m_VideoQuality; }
  130. inline void SetQualty( eVideoQuality_t theQuality ) { m_VideoQuality = (int32) theQuality; }
  131. // Constructors
  132. CVideoEncodeSessionParams()
  133. {
  134. V_memset( this, 0, sizeof( *this ) );
  135. }
  136. // copy operators
  137. CVideoEncodeSessionParams& operator = ( CVideoEncodeSessionParams& rhs )
  138. {
  139. V_memcpy( this, &rhs, sizeof( *this ) );
  140. return *this;
  141. }
  142. };
  143. // -----------------------------------------------------------------------
  144. // CVidCmd - command packet structure for remote video cache
  145. // The parameters which are Dependant upon the actual command value
  146. // are mapped in a union for direct access by type
  147. // -----------------------------------------------------------------------
  148. struct CVidCmd
  149. {
  150. public:
  151. uint8 m_Command; // command converted from eVidCacheCommand_t
  152. uint8 m_Success; // success bool
  153. uint8 m_LastError; // info on last error (if success == false)
  154. uint8 m_SessionID; // session ID
  155. union
  156. {
  157. char m_data1[12];
  158. float m_fData[3];
  159. int32 m_iData[3];
  160. uint32 m_uData[3];
  161. };
  162. // constructors - must include the command
  163. inline CVidCmd( eVidCacheCommand_t theCommand )
  164. {
  165. V_memset( this, 0, sizeof( *this ) );
  166. m_Command = theCommand;
  167. }
  168. inline CVidCmd( eVidCacheCommand_t theCommand, RemoteVideoSessionId_t theSession )
  169. {
  170. V_memset( this, 0, sizeof( *this ) );
  171. m_Command = theCommand;
  172. m_SessionID = theSession;
  173. }
  174. inline CVidCmd( eVidCacheCommand_t theCommand, bool success )
  175. {
  176. V_memset( this, 0, sizeof( *this ) );
  177. m_Command = theCommand;
  178. m_Success = success;
  179. }
  180. inline CVidCmd( eVidCacheCommand_t theCommand, eVidCacheError_t theErrorCode )
  181. {
  182. V_memset( this, 0, sizeof( *this ) );
  183. m_Command = theCommand;
  184. m_LastError = theErrorCode;
  185. }
  186. inline CVidCmd( eVidCacheCommand_t theCommand, bool success, eVidCacheError_t theErrorCode )
  187. {
  188. V_memset( this, 0, sizeof( *this ) );
  189. m_Command = theCommand;
  190. m_Success = success;
  191. m_LastError = theErrorCode;
  192. }
  193. inline CVidCmd( eVidCacheCommand_t theCommand, RemoteVideoSessionId_t theSession, bool success )
  194. {
  195. V_memset( this, 0, sizeof( *this ) );
  196. m_Command = theCommand;
  197. m_Success = success;
  198. m_SessionID = theSession;
  199. }
  200. inline CVidCmd( eVidCacheCommand_t theCommand, RemoteVideoSessionId_t theSession, bool success, eVidCacheError_t theErrorCode )
  201. {
  202. V_memset( this, 0, sizeof( *this ) );
  203. m_Command = theCommand;
  204. m_Success = success;
  205. m_LastError = theErrorCode;
  206. m_SessionID = theSession;
  207. }
  208. // accessors
  209. inline eVidCacheCommand_t GetCommand() { return (eVidCacheCommand_t) m_Command; }
  210. inline bool GetSuccess() { return ( m_Success != 0 ); }
  211. inline eVidCacheError_t GetError() { return (eVidCacheError_t) m_LastError; }
  212. inline RemoteVideoSessionId_t GetSessionID() { return m_SessionID; }
  213. inline void SetSuccess( bool success ) { m_Success = success; }
  214. inline void SetError( eVidCacheError_t theErr ) { m_LastError = theErr; }
  215. inline void SetSession( RemoteVideoSessionId_t id ) { m_SessionID = id; }
  216. private:
  217. inline CVidCmd() { V_memset( this, 0, sizeof( *this ) ); } // disable
  218. };
  219. // -----------------------------------------------------------------------
  220. // Quick Constructors for putting together specific commands
  221. // -----------------------------------------------------------------------
  222. struct CVidCacheCmdPing : public CVidCmd
  223. {
  224. CVidCacheCmdPing( ) : CVidCmd( cVCC_Ping ) {}
  225. };
  226. struct CVidCacheCmdQuit : public CVidCmd
  227. {
  228. CVidCacheCmdQuit( ) : CVidCmd( cVCC_Quit ) {}
  229. };
  230. struct CVidCacheCmdAck : public CVidCmd
  231. {
  232. CVidCacheCmdAck( bool success = true ) : CVidCmd( cVCC_Ack, success ) {}
  233. CVidCacheCmdAck( eVidCacheError_t err ) : CVidCmd( cVCC_Ack, ( err == cVCE_NoErr ), err ) {}
  234. };
  235. // Open / Close a video caching session
  236. struct CVidCacheCmdBeginCacheSession : public CVidCmd
  237. {
  238. CVidCacheCmdBeginCacheSession( int localId ) : CVidCmd( cVCC_BeginCacheSession )
  239. {
  240. m_iData[0] = localId;
  241. }
  242. inline int GetLocalId() { return m_iData[0]; }
  243. };
  244. struct CVidCacheCmdBeginCacheSessionResult : public CVidCmd
  245. {
  246. CVidCacheCmdBeginCacheSessionResult( int localId, RemoteVideoSessionId_t id, bool success, eVidCacheError_t err ) : CVidCmd( cVCC_BeginCacheSessionResult, id, success, err )
  247. {
  248. m_iData[0] = localId;
  249. }
  250. inline int GetLocalId() { return m_iData[0]; }
  251. };
  252. struct CVidCacheCmdEndCacheSession : public CVidCmd
  253. {
  254. CVidCacheCmdEndCacheSession( RemoteVideoSessionId_t id ) : CVidCmd( cVCC_EndCacheSession, id ) {}
  255. };
  256. // cache / uncache individual video file
  257. struct CVidCacheCmdCacheFile : public CVidCmd
  258. {
  259. CVidCacheCmdCacheFile( int localId, RemoteVideoSessionId_t id, const char* fileName ) : CVidCmd( cVCC_CacheFile, id )
  260. {
  261. m_iData[0] = localId;
  262. m_iData[1] = V_strlen( fileName ) + 1; // Include trailing NULL
  263. }
  264. inline int GetLocalId() { return m_iData[0]; }
  265. inline int GetFileNameBufferLen() { return m_iData[1]; }
  266. };
  267. struct CVidCacheCmdCacheFileResult : public CVidCmd
  268. {
  269. CVidCacheCmdCacheFileResult( int localId, bool success, eVidCacheError_t err, ServerVideoHandle_t serverHandle ) : CVidCmd( cVCC_CacheFileResult, success, err )
  270. {
  271. m_iData[0] = localId;
  272. m_uData[1] = serverHandle;
  273. }
  274. int GetLocalId() { return m_iData[0]; }
  275. ServerVideoHandle_t GetServerHandle() { return (ServerVideoHandle_t) m_uData[1]; }
  276. };
  277. struct CVidCacheCmdUncacheFile : public CVidCmd
  278. {
  279. CVidCacheCmdUncacheFile( ServerVideoHandle_t serverHandle, RemoteVideoSessionId_t id ) : CVidCmd( cVCC_UncacheFile, id )
  280. {
  281. m_uData[0] = serverHandle;
  282. }
  283. ServerVideoHandle_t GetServerHandle() { return (ServerVideoHandle_t) m_uData[0]; }
  284. };
  285. struct CVidCacheCmdUncacheAllFiles : public CVidCmd
  286. {
  287. CVidCacheCmdUncacheAllFiles( RemoteVideoSessionId_t id ) : CVidCmd( cVCC_UncacheAllFiles, id ) {}
  288. };
  289. // Requesting specific frames
  290. struct CVidCacheCmdRequestFrame : public CVidCmd
  291. {
  292. CVidCacheCmdRequestFrame( ServerVideoHandle_t serverHandle, float frameTime ) : CVidCmd( cVCC_RequestFrame )
  293. {
  294. m_uData[0] = serverHandle;
  295. m_fData[1] = frameTime;
  296. }
  297. ServerVideoHandle_t GetServerHandle() { return (ServerVideoHandle_t) m_uData[0]; }
  298. float GetFrameTime() { return m_fData[1]; }
  299. };
  300. struct CVidCacheCmdRequestFrameResult : public CVidCmd
  301. {
  302. CVidCacheCmdRequestFrameResult( ServerVideoHandle_t serverHandle, float frameTime, bool success) : CVidCmd( cVCC_RequestFrameResult, success )
  303. {
  304. m_uData[0] = serverHandle;
  305. m_fData[1] = frameTime;
  306. }
  307. ServerVideoHandle_t GetServerHandle() { return (ServerVideoHandle_t) m_uData[0]; }
  308. float GetFrameTime() { return m_fData[1]; }
  309. };
  310. // begin / end video encoding
  311. struct CVidCacheCmdBeginEncodingSession : public CVidCmd
  312. {
  313. CVidCacheCmdBeginEncodingSession( int localId, const char* fileName ) : CVidCmd( cVCC_BeginEncodingSession )
  314. {
  315. m_iData[0] = localId;
  316. m_iData[1] = V_strlen( fileName ) + 1; // Include trailing NULL
  317. }
  318. int GetLocalId() { return m_iData[0]; }
  319. int GetFileNameBufferLen() { return m_iData[1]; }
  320. };
  321. struct CVidCacheCmdBeginEncodingResult : public CVidCmd
  322. {
  323. CVidCacheCmdBeginEncodingResult( int localId, bool success, ServerVideoHandle_t serverHandle ) : CVidCmd( cVCC_BeginEncodingResult, success )
  324. {
  325. m_iData[0] = localId;
  326. m_uData[1] = serverHandle;
  327. }
  328. int GetLocalId() { return m_iData[0]; }
  329. ServerVideoHandle_t GetServerHandle() { return (ServerVideoHandle_t) m_uData[1]; }
  330. };
  331. struct CVidCacheCmdEncodeFrame : public CVidCmd
  332. {
  333. CVidCacheCmdEncodeFrame( ServerVideoHandle_t serverHandle, int frameNum ) : CVidCmd( cVCC_EncodeFrame )
  334. {
  335. m_uData[0] = serverHandle;
  336. m_iData[1] = frameNum;
  337. }
  338. ServerVideoHandle_t GetServerHandle() { return (ServerVideoHandle_t) m_uData[0]; }
  339. int GetFrameNumber() { return m_iData[1]; }
  340. };
  341. struct CVidCacheCmdEncodeFrameResult : public CVidCmd
  342. {
  343. CVidCacheCmdEncodeFrameResult( ServerVideoHandle_t serverHandle, int frameNum, bool success) : CVidCmd( cVCC_EncodeFrameResult, success )
  344. {
  345. m_uData[0] = serverHandle;
  346. m_iData[1] = frameNum;
  347. }
  348. ServerVideoHandle_t GetServerHandle() { return (ServerVideoHandle_t) m_uData[0]; }
  349. int GetFrameNumber() { return m_iData[1]; }
  350. };
  351. struct CVidCacheCmdEndEncodingSession : public CVidCmd
  352. {
  353. CVidCacheCmdEndEncodingSession( ServerVideoHandle_t serverHandle ) : CVidCmd( cVCC_EndEncodingSession )
  354. {
  355. m_uData[0] = serverHandle;
  356. }
  357. ServerVideoHandle_t GetServerHandle() { return (ServerVideoHandle_t) m_uData[0]; }
  358. };
  359. struct CVidCacheCmdEndEncodingResult : public CVidCmd
  360. {
  361. CVidCacheCmdEndEncodingResult( ServerVideoHandle_t serverHandle, bool success ) : CVidCmd( cVCC_EndEncodingResult )
  362. {
  363. m_uData[0] = serverHandle;
  364. m_iData[1] = (int32) success;
  365. }
  366. bool GetSuccess() { return ( m_iData[1] != 0 ); }
  367. ServerVideoHandle_t GetServerHandle() { return (ServerVideoHandle_t) m_uData[0]; }
  368. };
  369. // -----------------------------------------------------------------------
  370. // misc definitions
  371. // -----------------------------------------------------------------------
  372. const uint16 cSFMVidCachePort = 26832;
  373. #define VIDEO_CACHE_APP_MUTEX_NAME TEXT( "sfm_vid_cache_app" )
  374. #define VIDEO_CACHE_APP_SIGNAL_EVENT_NAME TEXT( "sfm_vid_cache_event1" )
  375. #endif // VIDEO_CACHE_COMMANDS_H