Index: media/base/null_video_sink.h |
diff --git a/media/base/null_video_sink.h b/media/base/null_video_sink.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..da0498139cad14c456f0abfe20a306e9dc6b8bf9 |
--- /dev/null |
+++ b/media/base/null_video_sink.h |
@@ -0,0 +1,95 @@ |
+// Copyright 2015 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_AUDIO_NULL_VIDEO_SINK_H_ |
+#define MEDIA_AUDIO_NULL_VIDEO_SINK_H_ |
+ |
+#include "base/cancelable_callback.h" |
+#include "base/md5.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/time/default_tick_clock.h" |
+#include "base/time/tick_clock.h" |
+#include "media/base/video_renderer_sink.h" |
+ |
+namespace base { |
+class SingleThreadTaskRunner; |
+} |
+ |
+namespace media { |
+ |
+class MEDIA_EXPORT NullVideoSink : NON_EXPORTED_BASE(public VideoRendererSink) { |
+ public: |
+ using NewFrameCB = base::Callback<void(const scoped_refptr<VideoFrame>&)>; |
+ |
+ // Periodically calls |callback| every |interval| on |task_runner| once the |
+ // sink has been started. If |clockless| is true, the RenderCallback will |
+ // be called back to back by repeated post tasks. Optionally, if specified, |
+ // |new_frame_cb| will be called for each new frame received. |
+ NullVideoSink(bool clockless, |
+ base::TimeDelta interval, |
+ const NewFrameCB& new_frame_cb, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
+ ~NullVideoSink() override; |
+ |
+ // VideoRendererSink implementation. |
+ void Start(RenderCallback* callback) override; |
+ void Stop() override; |
+ void PaintFrameUsingOldRenderingPath( |
+ const scoped_refptr<VideoFrame>& frame) override; |
+ |
+ // Allows tests to simulate suspension of Render() callbacks. |
+ void pause_render_callbacks(base::TimeTicks pause_util) { |
xhwang
2015/04/29 03:49:13
Here and below: based on the style guide:
1. Only
DaleCurtis
2015/04/29 04:26:48
Disagree especially on the middle one, for_testing
xhwang
2015/04/29 05:20:19
I missed this text. Thanks for pointing that out!
|
+ pause_end_time_ = pause_util; |
+ } |
+ |
+ void set_tick_clock_for_testing(base::TickClock* tick_clock) { |
+ tick_clock_ = tick_clock; |
+ } |
+ |
+ // Sets |stop_cb_|, which will be fired when Stop() is called. |
+ void set_stop_callback(const base::Closure& stop_cb) { |
+ stop_cb_ = stop_cb; |
+ } |
+ |
+ private: |
+ // Task that periodically calls Render() to consume video data. |
+ void CallRender(); |
+ |
+ const bool clockless_; |
+ const base::TimeDelta interval_; |
+ const NewFrameCB new_frame_cb_; |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
+ |
+ bool started_; |
+ RenderCallback* callback_; |
+ |
+ // Manages cancellation of periodic Render() callback task. |
+ base::CancelableClosure cancelable_worker_; |
+ |
+ // Used to determine when a new frame is received. |
+ scoped_refptr<VideoFrame> last_frame_; |
+ |
+ // Used to determine the interval given to RenderCallback::Render() as well as |
+ // to maintain stable periodicity of callbacks. |
+ base::TimeTicks current_render_time_; |
+ |
+ // Used to suspend Render() callbacks to |callback_| for some time. |
+ base::TimeTicks pause_end_time_; |
+ |
+ // Allow for an injectable tick clock for testing. |
+ base::DefaultTickClock default_tick_clock_; |
+ base::TimeTicks last_now_; |
+ |
+ // If specified, used instead of |default_tick_clock_|. |
+ base::TickClock* tick_clock_; |
+ |
+ // If set, called when Stop() is called. |
+ base::Closure stop_cb_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NullVideoSink); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_AUDIO_NULL_VIDEO_SINK_H_ |