Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Unified Diff: media/filters/video_frame_scheduler_impl.h

Issue 237093007: Introduce VideoFrameScheduler{Impl}. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/filters/video_frame_scheduler_impl.h
diff --git a/media/filters/video_frame_scheduler_impl.h b/media/filters/video_frame_scheduler_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..f6bc78dd2751b28a94583a3dc61ac8c1d8e565d7
--- /dev/null
+++ b/media/filters/video_frame_scheduler_impl.h
@@ -0,0 +1,74 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_FILTERS_VIDEO_FRAME_SCHEDULER_IMPL_H_
+#define MEDIA_FILTERS_VIDEO_FRAME_SCHEDULER_IMPL_H_
+
+#include <queue>
+
+#include "base/memory/ref_counted.h"
+#include "base/timer/timer.h"
+#include "media/filters/video_frame_scheduler.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+class TickClock;
+}
+
+namespace media {
+
+// A scheduler that uses delayed tasks on a task runner for timing the display
+// of video frames.
+//
+// Single threaded. Calls must be on |task_runner|.
+class MEDIA_EXPORT VideoFrameSchedulerImpl : public VideoFrameScheduler {
+ public:
+ typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> DisplayCB;
+
+ // |task_runner| is used for scheduling the delayed tasks.
+ // |display_cb| is run when a frame is to be displayed.
+ VideoFrameSchedulerImpl(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
+ const DisplayCB& display_cb);
+ virtual ~VideoFrameSchedulerImpl();
+
+ // VideoFrameScheduler implementation.
+ virtual void ScheduleVideoFrame(const scoped_refptr<VideoFrame>& frame,
+ base::TimeTicks wall_ticks,
+ const DoneCB& done_cb) OVERRIDE;
+ virtual void Reset() OVERRIDE;
+
+ void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock);
+
+ private:
+ void ResetTimerIfNecessary();
+ void OnTimerFired();
+
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ DisplayCB display_cb_;
+ scoped_ptr<base::TickClock> tick_clock_;
+ base::OneShotTimer<VideoFrameScheduler> timer_;
+
+ struct PendingFrame {
+ PendingFrame(const scoped_refptr<VideoFrame>& frame,
+ base::TimeTicks wall_ticks,
+ const DoneCB& done_cb);
+ ~PendingFrame();
+
+ // For use with std::priority_queue<T>.
+ bool operator<(const PendingFrame& other) const;
+
+ scoped_refptr<VideoFrame> frame;
+ base::TimeTicks wall_ticks;
+ DoneCB done_cb;
+ };
+ typedef std::priority_queue<PendingFrame> PendingFrameQueue;
+ PendingFrameQueue pending_frames_;
+
+ DISALLOW_COPY_AND_ASSIGN(VideoFrameSchedulerImpl);
+};
+
+} // namespace media
+
+#endif // MEDIA_FILTERS_VIDEO_FRAME_SCHEDULER_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698