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.

111 lines
3.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //----------------------------------------------------------------------------------------
  4. #ifndef WEBM_RECORDER_H
  5. #define WEBM_RECORDER_H
  6. #ifdef _WIN32
  7. #pragma once
  8. #endif
  9. //--------------------------------------------------------------------------------
  10. //#include ""
  11. #include "video/ivideoservices.h"
  12. #include "video_macros.h"
  13. #include "webm_common.h"
  14. // comment out to prevent logging of creation data
  15. //#define LOG_ENCODER_OPERATIONS
  16. #if defined( LOG_ENCODER_OPERATIONS ) || defined( LOG_ENCODER_AUDIO_OPERATIONS ) || defined ( LOG_FRAMES_TO_TGA ) || defined ( ENABLE_EXTERNAL_ENCODER_LOGGING )
  17. #include <filesystem.h>
  18. #endif
  19. class CWebMVideoRecorder : public IVideoRecorder
  20. {
  21. public:
  22. CWebMVideoRecorder();
  23. ~CWebMVideoRecorder();
  24. virtual bool EstimateMovieFileSize( size_t *pEstSize, int movieWidth, int movieHeight, VideoFrameRate_t movieFps, float movieDuration, VideoEncodeCodec_t theCodec, int videoQuality, AudioEncodeSourceFormat_t srcAudioFormat = AudioEncodeSourceFormat::AUDIO_NONE, int audioSampleRate = 0 );
  25. virtual bool CreateNewMovieFile( const char *pFilename, bool hasAudioTrack = false );
  26. virtual bool SetMovieVideoParameters( VideoEncodeCodec_t theCodec, int videoQuality, int movieFrameWidth, int movieFrameHeight, VideoFrameRate_t movieFPS, VideoEncodeGamma_t gamma = VideoEncodeGamma::NO_GAMMA_ADJUST );
  27. virtual bool SetMovieSourceImageParameters( VideoEncodeSourceFormat_t srcImageFormat, int imgWidth, int imgHeight );
  28. virtual bool SetMovieSourceAudioParameters( AudioEncodeSourceFormat_t srcAudioFormat = AudioEncodeSourceFormat::AUDIO_NONE, int audioSampleRate = 0, AudioEncodeOptions_t audioOptions = AudioEncodeOptions::NO_AUDIO_OPTIONS, int audioSampleGroupSize = 0 );
  29. virtual bool IsReadyToRecord();
  30. virtual VideoResult_t GetLastResult();
  31. virtual bool AppendVideoFrame( void *pFrameBuffer, int nStrideAdjustBytes = 0 );
  32. virtual bool AppendAudioSamples( void *pSampleBuffer, size_t sampleSize );
  33. virtual int GetFrameCount();
  34. virtual int GetSampleCount();
  35. virtual int GetSampleRate();
  36. virtual VideoFrameRate_t GetFPS();
  37. virtual bool AbortMovie();
  38. virtual bool FinishMovie( bool SaveMovieToDisk = true );
  39. private:
  40. bool FlushAudioSamples();
  41. void ConvertBGRAToYV12( void *pFrameBuffer, int nStrideAdjustBytes, vpx_image_t *m_SrcImageYV12Buffer, bool fIncludesAlpha );
  42. void SetResult( VideoResult_t resultCode );
  43. float GetVideoDataRate( int quality, int width, int height );
  44. float GetAudioDataRate( int quality, int width, int height );
  45. VideoResult_t m_LastResult;
  46. bool m_bHasAudio;
  47. bool m_bMovieFinished;
  48. int m_nFramesAdded;
  49. int m_nAudioFramesAdded;
  50. int m_nSamplesAdded;
  51. VideoFrameRate_t m_MovieRecordFPS;
  52. int m_MovieTimeScale;
  53. int m_DurationPerFrame;
  54. unsigned long m_FrameDuration;
  55. int m_MovieFrameWidth;
  56. int m_MovieFrameHeight;
  57. vpx_image_t *m_SrcImageYV12Buffer;
  58. VideoEncodeGamma_t m_MovieGamma;
  59. VideoEncodeSourceFormat_t m_SrcImageFormat;
  60. int m_SrcImageWidth;
  61. int m_SrcImageHeight;
  62. // WebM VPX
  63. vpx_codec_ctx_t m_vpxContext;
  64. vpx_codec_enc_cfg_t m_vpxConfig;
  65. mkvmuxer::MkvWriter m_mkvWriter;
  66. mkvmuxer::Segment m_mkvMuxerSegment;
  67. uint64 m_vid_track;
  68. // Vorbis audio
  69. uint64 m_aud_track;
  70. int m_audioChannels;
  71. int m_audioSampleRate;
  72. int m_audioSampleGroupSize;
  73. int m_audioBitDepth;
  74. vorbis_info m_vi;
  75. vorbis_dsp_state m_vd;
  76. vorbis_block m_vb;
  77. vorbis_comment m_vc;
  78. };
  79. #endif // WEBM_RECORDER_H