encode_usage_resource.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2020 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef VIDEO_ADAPTATION_ENCODE_USAGE_RESOURCE_H_
  11. #define VIDEO_ADAPTATION_ENCODE_USAGE_RESOURCE_H_
  12. #include <memory>
  13. #include <string>
  14. #include "absl/types/optional.h"
  15. #include "api/scoped_refptr.h"
  16. #include "api/video/video_adaptation_reason.h"
  17. #include "rtc_base/ref_counted_object.h"
  18. #include "rtc_base/task_queue.h"
  19. #include "video/adaptation/overuse_frame_detector.h"
  20. #include "video/adaptation/video_stream_encoder_resource.h"
  21. namespace webrtc {
  22. // Handles interaction with the OveruseDetector.
  23. // TODO(hbos): Add unittests specific to this class, it is currently only tested
  24. // indirectly by usage in the ResourceAdaptationProcessor (which is only tested
  25. // because of its usage in VideoStreamEncoder); all tests are currently in
  26. // video_stream_encoder_unittest.cc.
  27. class EncodeUsageResource : public VideoStreamEncoderResource,
  28. public OveruseFrameDetectorObserverInterface {
  29. public:
  30. static rtc::scoped_refptr<EncodeUsageResource> Create(
  31. std::unique_ptr<OveruseFrameDetector> overuse_detector);
  32. explicit EncodeUsageResource(
  33. std::unique_ptr<OveruseFrameDetector> overuse_detector);
  34. ~EncodeUsageResource() override;
  35. bool is_started() const;
  36. void StartCheckForOveruse(CpuOveruseOptions options);
  37. void StopCheckForOveruse();
  38. void SetTargetFrameRate(absl::optional<double> target_frame_rate);
  39. void OnEncodeStarted(const VideoFrame& cropped_frame,
  40. int64_t time_when_first_seen_us);
  41. void OnEncodeCompleted(uint32_t timestamp,
  42. int64_t time_sent_in_us,
  43. int64_t capture_time_us,
  44. absl::optional<int> encode_duration_us);
  45. // OveruseFrameDetectorObserverInterface implementation.
  46. void AdaptUp() override;
  47. void AdaptDown() override;
  48. private:
  49. int TargetFrameRateAsInt();
  50. const std::unique_ptr<OveruseFrameDetector> overuse_detector_
  51. RTC_GUARDED_BY(encoder_queue());
  52. bool is_started_ RTC_GUARDED_BY(encoder_queue());
  53. absl::optional<double> target_frame_rate_ RTC_GUARDED_BY(encoder_queue());
  54. };
  55. } // namespace webrtc
  56. #endif // VIDEO_ADAPTATION_ENCODE_USAGE_RESOURCE_H_