VideoFrameScheduler.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include <rtc_base/task_utils/repeating_task.h>
  3. #include "VideoFrame.h"
  4. namespace unity
  5. {
  6. namespace webrtc
  7. {
  8. class VideoFrameScheduler
  9. {
  10. public:
  11. VideoFrameScheduler(TaskQueueBase* queue, Clock* clock = Clock::GetRealTimeClock());
  12. VideoFrameScheduler(const VideoFrameScheduler&) = delete;
  13. VideoFrameScheduler& operator=(const VideoFrameScheduler&) = delete;
  14. virtual ~VideoFrameScheduler();
  15. // Starts the scheduler. |capture_callback| will be called whenever a new
  16. // frame should be captured.
  17. virtual void Start(std::function<void()> capture_callback);
  18. // Pause and resumes the scheduler.
  19. virtual void Pause(bool pause);
  20. // Called after |frame| has been captured. |frame| may be set to nullptr
  21. // if the capture request failed.
  22. virtual void OnFrameCaptured(const VideoFrame* frame);
  23. // Called when WebRTC requests the VideoTrackSource to provide frames
  24. // at a maximum framerate.
  25. virtual void SetMaxFramerateFps(int maxFramerate);
  26. private:
  27. absl::optional<TimeDelta> ScheduleNextFrame();
  28. void CaptureNextFrame();
  29. void StartRepeatingTask();
  30. void StopTask();
  31. std::function<void()> callback_;
  32. bool paused_ = false;
  33. int maxFramerate_;
  34. RepeatingTaskHandle task_;
  35. TaskQueueBase* queue_;
  36. Timestamp lastCaptureStartedTime_;
  37. Clock* clock_;
  38. };
  39. }
  40. }