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

Unified Diff: media/base/null_video_sink.h

Issue 1116473002: Introduce NullVideoSink for test classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/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..40fcccf41600cb5f32b2a97a682be9654787b1a1
--- /dev/null
+++ b/media/base/null_video_sink.h
@@ -0,0 +1,92 @@
+// 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
+ // called back to back by repeated post tasks. Optionally, if specified,
xhwang 2015/04/28 23:12:06 s/called/be called/
DaleCurtis 2015/04/29 00:54:07 Done.
+ // |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_callbacks(base::TimeTicks pause_util) {
xhwang 2015/04/28 23:12:06 s/pause_callbacks/PauseRenderCallbacks/?
DaleCurtis 2015/04/29 00:54:07 Done.
+ pause_end_time_ = pause_util;
+ }
+
+ void set_tick_clock_for_testing(base::TickClock* tick_clock) {
xhwang 2015/04/28 23:12:06 Use SetTickClockForTesting() since this is not str
xhwang 2015/04/28 23:12:06 Put comments here since this is the public interfa
DaleCurtis 2015/04/29 00:54:07 That doesn't apply to this case, the reason being
+ tick_clock_ = tick_clock;
+ }
+
+ void set_stop_callback(const base::Closure& stop_cb) {
xhwang 2015/04/28 23:12:06 set_stop_cb? Also add comment. It's not clear unle
DaleCurtis 2015/04/29 00:54:07 I prefer it spelled out for a method name. Added a
+ stop_cb_ = stop_cb;
+ }
+
+ private:
+ // Task that periodically calls Render() to consume audio data.
xhwang 2015/04/28 23:12:06 s/audio/video
DaleCurtis 2015/04/29 00:54:07 Done.
+ 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 cancelation 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_;
+
+ // If specified, used instead of base::TimeTicks::Now().
xhwang 2015/04/28 23:12:06 This comment only applies to |tick_clock_|, right?
DaleCurtis 2015/04/29 00:54:07 Done.
+ base::DefaultTickClock default_tick_clock_;
+ base::TickClock* tick_clock_;
+ base::TimeTicks last_now_;
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698