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.

126 lines
5.2 KiB

  1. //========= Copyright (c) Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Playback of broadcast (cst) files
  4. //
  5. //=============================================================================//
  6. #ifndef ENGINE_CL_BROADCAST_HDR
  7. #define ENGINE_CL_BROADCAST_HDR
  8. #include "broadcast.h"
  9. #include "demostreamhttp.h"
  10. #include "tier1/utlbufferstrider.h"
  11. class CBroadcastPlayer : public IDemoPlayer, public IDemoStreamClient
  12. {
  13. public:
  14. CBroadcastPlayer();
  15. ~CBroadcastPlayer();
  16. virtual IDemoStream *GetDemoStream();
  17. virtual int GetPlaybackStartTick( void ) OVERRIDE;
  18. virtual int GetPlaybackTick( void ) OVERRIDE;
  19. virtual int GetPlaybackDeltaTick( void ) ;
  20. virtual int GetPacketTick( void ) ;
  21. void StartStreaming( const char *url, const char *options );
  22. bool StartBroadcastPlayback( int nStartingTick );
  23. bool OnEngineGotvSyncPacket( const CEngineGotvSyncPacket *pPkt );
  24. virtual bool IsPlayingBack( void ) const OVERRIDE { return m_bPlayingBack; }
  25. virtual bool IsPlaybackPaused( void ) const OVERRIDE;
  26. virtual bool IsPlayingTimeDemo( void ) const OVERRIDE { return false; } // not supported
  27. virtual bool IsSkipping( void ) const OVERRIDE { return m_bPlayingBack && m_nSkipToTick != -1; } // true, if demo player skipping trough packets
  28. virtual bool CanSkipBackwards( void ) const OVERRIDE { return true; } // true if demoplayer can skip backwards
  29. virtual void SetPlaybackTimeScale( float timescale ) OVERRIDE; // sets playback timescale
  30. virtual float GetPlaybackTimeScale( void ) OVERRIDE; // get playback timescale
  31. virtual void PausePlayback( float seconds ) OVERRIDE; // pause playback n seconds, -1 = forever
  32. virtual void SkipToTick( int tick, bool bRelative, bool bPause ) OVERRIDE { } // goto a specific tick, 0 = start, -1 = end
  33. virtual void SkipToImportantTick( const DemoImportantTick_t *pTick ) OVERRIDE { }
  34. virtual void ResumePlayback( void ) OVERRIDE; // resume playback
  35. virtual void StopPlayback( void ) OVERRIDE; // stop playback, close file
  36. virtual void InterpolateViewpoint() OVERRIDE { } // override viewpoint
  37. virtual netpacket_t *ReadPacket( void ) OVERRIDE; // read packet from demo file
  38. void SetDemoBuffer( CDemoStreamHttp::Buffer_t * pBuffer );
  39. void StrideDemoPacket( int nLength );
  40. void StrideDemoPacket();
  41. uint GetReminingStrideLength();
  42. virtual void ResetDemoInterpolation() OVERRIDE { }
  43. virtual CDemoPlaybackParameters_t const * GetDemoPlaybackParameters() OVERRIDE;
  44. virtual void SetPacketReadSuspended( bool bSuspendPacketReading ) OVERRIDE;
  45. virtual void SetImportantEventData( const KeyValues *pData ) OVERRIDE { }
  46. virtual int FindNextImportantTick( int nCurrentTick, const char *pEventName = NULL ) OVERRIDE { Assert( !"not implemented" ); return 0; } // -1 = no next important tick
  47. virtual int FindPreviousImportantTick( int nCurrentTick, const char *pEventName = NULL ) OVERRIDE { Assert( !"not implemented" ); return 0; } // -1 = no previous important tick
  48. virtual const DemoImportantTick_t *GetImportantTick( int nIndex ) OVERRIDE { Assert( !"not implemented" ); return NULL; }
  49. virtual const DemoImportantGameEvent_t *GetImportantGameEvent( const char *pszEventName ) OVERRIDE { Assert( !"not implemented" ); return NULL; }
  50. virtual void ListImportantTicks( void ) OVERRIDE { Assert( !"not implemented" ); }
  51. virtual void ListHighlightData( void ) OVERRIDE { Assert( !"not implemented" ); }
  52. virtual void SetHighlightXuid( uint64 xuid, bool bLowlights ) OVERRIDE { Assert( !"not implemented" ); }
  53. virtual bool ScanDemo( const char *filename, const char* pszMode ) OVERRIDE { Assert( !"not implemented" ); return false; }
  54. virtual void OnDemoStreamStart( const DemoStreamReference_t &start, int nResync );
  55. virtual bool OnDemoStreamRestarting();
  56. virtual void OnDemoStreamStop() OVERRIDE;
  57. protected:
  58. bool StartStreamingInternal();
  59. void ResyncDemoClock();
  60. bool CheckPausedPlayback( void );
  61. bool PreparePacket( void ); // read packet from demo file
  62. void ReadCmdHeader( unsigned char& cmd, int& tick, int &nPlayerSlot );
  63. void ResyncStream();
  64. protected:
  65. int m_nStartHostTick; // For synchronizing playback during timedemo.
  66. int m_nStreamStartTick;
  67. int m_nPreviousTick;
  68. CDemoStreamHttp::BufferRef m_DemoBuffer;
  69. CBufferStrider m_DemoStrider;
  70. netpacket_t m_DemoPacket; // last read demo packet
  71. bool m_bPlayingBack;
  72. bool m_bPlaybackPaused;
  73. float m_flAutoResumeTime;
  74. float m_flPlaybackRateModifier;
  75. int m_nSkipToTick; // skip to tick ASAP, -1 = off
  76. uint m_nFileSize;
  77. CUtlVector< BroadcastTocKeyframe_t > m_Keyframes;
  78. bool m_bInterpolateView;
  79. bool m_bResetInterpolation;
  80. bool m_bPacketReadSuspended;
  81. float m_flTotalFPSVariability; // Frame rate variability
  82. int m_nPacketTick;
  83. int m_nPreparePacketLastFail;
  84. enum StreamStateEnum_t
  85. {
  86. STREAM_STOP,
  87. STREAM_SYNC,
  88. STREAM_START,
  89. STREAM_MAP_LOADED,
  90. STREAM_WAITING_FOR_KEYFRAME,
  91. STREAM_FULLFRAME,
  92. STREAM_BEFORE_DELTAFRAMES,
  93. STREAM_DELTAFRAMES
  94. };
  95. StreamStateEnum_t m_nStreamState; // the pieces of stream state that still need to be streamed
  96. int m_nStreamFragment; // the next fragment to stream
  97. double m_dDelayedPrecacheTimeStart;
  98. CDemoStreamHttp m_DemoStream;
  99. bool m_bIgnoreDemoStopCommand;
  100. bool m_bSkipSync;
  101. double m_dResyncTimerStart;
  102. };
  103. extern CBroadcastPlayer s_ClientBroadcastPlayer;
  104. #endif