1 // Copyright 2014 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.
5 #ifndef MEDIA_FILTERS_VIDEO_FRAME_SCHEDULER_IMPL_H_
6 #define MEDIA_FILTERS_VIDEO_FRAME_SCHEDULER_IMPL_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/timer/timer.h"
12 #include "media/filters/video_frame_scheduler.h"
15 class SingleThreadTaskRunner;
21 // A scheduler that uses delayed tasks on a task runner for timing the display
24 // Single threaded. Calls must be on |task_runner|.
25 class MEDIA_EXPORT VideoFrameSchedulerImpl : public VideoFrameScheduler {
27 typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> DisplayCB;
29 // |task_runner| is used for scheduling the delayed tasks.
30 // |display_cb| is run when a frame is to be displayed.
31 VideoFrameSchedulerImpl(
32 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
33 const DisplayCB& display_cb);
34 virtual ~VideoFrameSchedulerImpl();
36 // VideoFrameScheduler implementation.
37 virtual void ScheduleVideoFrame(const scoped_refptr<VideoFrame>& frame,
38 base::TimeTicks wall_ticks,
39 const DoneCB& done_cb) OVERRIDE;
40 virtual void Reset() OVERRIDE;
42 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock);
45 void ResetTimerIfNecessary();
48 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
49 DisplayCB display_cb_;
50 scoped_ptr<base::TickClock> tick_clock_;
51 base::OneShotTimer<VideoFrameScheduler> timer_;
54 PendingFrame(const scoped_refptr<VideoFrame>& frame,
55 base::TimeTicks wall_ticks,
56 const DoneCB& done_cb);
59 // For use with std::priority_queue<T>.
60 bool operator<(const PendingFrame& other) const;
62 scoped_refptr<VideoFrame> frame;
63 base::TimeTicks wall_ticks;
66 typedef std::priority_queue<PendingFrame> PendingFrameQueue;
67 PendingFrameQueue pending_frames_;
69 DISALLOW_COPY_AND_ASSIGN(VideoFrameSchedulerImpl);
74 #endif // MEDIA_FILTERS_VIDEO_FRAME_SCHEDULER_IMPL_H_