vp8_vaapi_video_encoder_delegate.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_GPU_VAAPI_VP8_VAAPI_VIDEO_ENCODER_DELEGATE_H_
  5. #define MEDIA_GPU_VAAPI_VP8_VAAPI_VIDEO_ENCODER_DELEGATE_H_
  6. #include <vector>
  7. #include "media/base/video_bitrate_allocation.h"
  8. #include "media/gpu/vaapi/vaapi_video_encoder_delegate.h"
  9. #include "media/gpu/video_rate_control.h"
  10. #include "media/gpu/vp8_picture.h"
  11. #include "media/gpu/vp8_reference_frame_vector.h"
  12. #include "media/parsers/vp8_parser.h"
  13. namespace libvpx {
  14. struct VP8FrameParamsQpRTC;
  15. class VP8RateControlRTC;
  16. struct VP8RateControlRtcConfig;
  17. } // namespace libvpx
  18. namespace media {
  19. class VaapiWrapper;
  20. class VP8VaapiVideoEncoderDelegate : public VaapiVideoEncoderDelegate {
  21. public:
  22. struct EncodeParams {
  23. EncodeParams();
  24. // Produce a keyframe at least once per this many frames.
  25. size_t kf_period_frames;
  26. // Bitrate allocation in bps.
  27. VideoBitrateAllocation bitrate_allocation;
  28. // Framerate in FPS.
  29. uint32_t framerate;
  30. // Quantization parameter. They are vp8 ac/dc indices and their ranges are
  31. // 0-127.
  32. uint8_t min_qp;
  33. uint8_t max_qp;
  34. };
  35. VP8VaapiVideoEncoderDelegate(scoped_refptr<VaapiWrapper> vaapi_wrapper,
  36. base::RepeatingClosure error_cb);
  37. VP8VaapiVideoEncoderDelegate(const VP8VaapiVideoEncoderDelegate&) = delete;
  38. VP8VaapiVideoEncoderDelegate& operator=(const VP8VaapiVideoEncoderDelegate&) =
  39. delete;
  40. ~VP8VaapiVideoEncoderDelegate() override;
  41. // VaapiVideoEncoderDelegate implementation.
  42. bool Initialize(const VideoEncodeAccelerator::Config& config,
  43. const VaapiVideoEncoderDelegate::Config& ave_config) override;
  44. bool UpdateRates(const VideoBitrateAllocation& bitrate_allocation,
  45. uint32_t framerate) override;
  46. gfx::Size GetCodedSize() const override;
  47. size_t GetMaxNumOfRefFrames() const override;
  48. std::vector<gfx::Size> GetSVCLayerResolutions() override;
  49. private:
  50. void InitializeFrameHeader();
  51. void SetFrameHeader(
  52. size_t frame_num,
  53. VP8Picture& picture,
  54. std::array<bool, kNumVp8ReferenceBuffers>& ref_frames_used);
  55. void UpdateReferenceFrames(scoped_refptr<VP8Picture> picture);
  56. void Reset();
  57. bool PrepareEncodeJob(EncodeJob& encode_job) override;
  58. BitstreamBufferMetadata GetMetadata(const EncodeJob& encode_job,
  59. size_t payload_size) override;
  60. void BitrateControlUpdate(uint64_t encoded_chunk_size_bytes) override;
  61. bool SubmitFrameParameters(
  62. EncodeJob& job,
  63. const EncodeParams& encode_params,
  64. scoped_refptr<VP8Picture> pic,
  65. const Vp8ReferenceFrameVector& ref_frames,
  66. const std::array<bool, kNumVp8ReferenceBuffers>& ref_frames_used);
  67. gfx::Size visible_size_;
  68. gfx::Size coded_size_; // Macroblock-aligned.
  69. uint8_t num_temporal_layers_ = 1;
  70. // Frame count since last keyframe, reset to 0 every keyframe period.
  71. size_t frame_num_ = 0;
  72. EncodeParams current_params_;
  73. Vp8ReferenceFrameVector reference_frames_;
  74. using VP8RateControl = VideoRateControl<libvpx::VP8RateControlRtcConfig,
  75. libvpx::VP8RateControlRTC,
  76. libvpx::VP8FrameParamsQpRTC>;
  77. std::unique_ptr<VP8RateControl> rate_ctrl_;
  78. };
  79. } // namespace media
  80. #endif // MEDIA_GPU_VAAPI_VP8_VAAPI_VIDEO_ENCODER_DELEGATE_H_