#ifndef MEDIA_GPU_V4L2_V4L2_FRAMERATE_CONTROL_H_
#define MEDIA_GPU_V4L2_V4L2_FRAMERATE_CONTROL_H_
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/moving_window.h"
#include "base/sequence_checker.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "media/base/video_frame.h"
#include "media/gpu/chromeos/frame_resource.h"
namespace media {
class V4L2FrameRateControl {
public:
using IoctlAsCallback = base::RepeatingCallback<int(int, void*)>;
V4L2FrameRateControl(const IoctlAsCallback& ioctl_cb,
scoped_refptr<base::SequencedTaskRunner> task_runner);
~V4L2FrameRateControl();
static void RecordFrameDurationThunk(
base::WeakPtr<V4L2FrameRateControl> weak_this,
scoped_refptr<base::SequencedTaskRunner> task_runner);
void RecordFrameDuration();
void AttachToVideoFrame(scoped_refptr<VideoFrame>& video_frame);
void AttachToFrameResource(scoped_refptr<FrameResource>& frame);
private:
void UpdateFrameRate();
const IoctlAsCallback ioctl_cb_;
const bool framerate_control_present_;
int64_t current_frame_duration_avg_ms_;
base::TimeTicks last_frame_display_time_;
base::MovingAverage<base::TimeDelta, base::TimeDelta>
frame_duration_moving_average_;
const scoped_refptr<base::SequencedTaskRunner> task_runner_;
SEQUENCE_CHECKER(sequence_checker_);
base::WeakPtrFactory<V4L2FrameRateControl> weak_this_factory_;
};
}
#endif