video_rate_control.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2021 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_VIDEO_RATE_CONTROL_H_
  5. #define MEDIA_GPU_VIDEO_RATE_CONTROL_H_
  6. #include <memory>
  7. #include "base/logging.h"
  8. namespace media {
  9. // VideoRateControl is an interface to compute proper quantization
  10. // parameter and loop filter level for vp8 and vp9.
  11. // T is a libvpx::VP(8|9)RateControlRtcConfig
  12. // S is a libvpx::VP(8|9)RateControlRTC
  13. // U is a libvpx::VP(8|9)FrameParamsQpRTC
  14. template <typename T, typename S, typename U>
  15. class VideoRateControl {
  16. public:
  17. // Creates VideoRateControl using libvpx implementation.
  18. static std::unique_ptr<VideoRateControl> Create(const T& config) {
  19. auto impl = S::Create(config);
  20. if (!impl) {
  21. DLOG(ERROR) << "Failed creating video RateControlRTC";
  22. return nullptr;
  23. }
  24. return std::make_unique<VideoRateControl>(std::move(impl));
  25. }
  26. VideoRateControl() = default;
  27. explicit VideoRateControl(std::unique_ptr<S> impl) : impl_(std::move(impl)) {}
  28. virtual ~VideoRateControl() = default;
  29. virtual void UpdateRateControl(const T& rate_control_config) {
  30. impl_->UpdateRateControl(rate_control_config);
  31. }
  32. // libvpx::VP(8|9)FrameParamsQpRTC take 0-63 quantization parameter.
  33. virtual void ComputeQP(const U& frame_params) {
  34. impl_->ComputeQP(frame_params);
  35. }
  36. // GetQP() returns vp8/9 ac/dc table index. The range is 0-255.
  37. virtual int GetQP() const { return impl_->GetQP(); }
  38. // GetLoopfilterLevel() is only available for VP9 -- see .cc file.
  39. virtual int GetLoopfilterLevel() const { return -1; }
  40. virtual void PostEncodeUpdate(uint64_t encoded_frame_size) {
  41. impl_->PostEncodeUpdate(encoded_frame_size);
  42. }
  43. private:
  44. const std::unique_ptr<S> impl_;
  45. };
  46. } // namespace media
  47. #endif // MEDIA_GPU_VIDEO_RATE_CONTROL_H_