Material PDF: Restore animated entry and exit of viewer toolbars
[chromium-blink-merge.git] / media / base / null_video_sink.h
blob66ff79f59f9d2233c9d85d6cdac2665ed567c2a9
1 // Copyright 2015 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_AUDIO_NULL_VIDEO_SINK_H_
6 #define MEDIA_AUDIO_NULL_VIDEO_SINK_H_
8 #include "base/cancelable_callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/default_tick_clock.h"
11 #include "base/time/tick_clock.h"
12 #include "media/base/video_renderer_sink.h"
14 namespace base {
15 class SingleThreadTaskRunner;
18 namespace media {
20 class NullVideoSink : public VideoRendererSink {
21 public:
22 using NewFrameCB = base::Callback<void(const scoped_refptr<VideoFrame>&)>;
24 // Periodically calls |callback| every |interval| on |task_runner| once the
25 // sink has been started. If |clockless| is true, the RenderCallback will
26 // be called back to back by repeated post tasks. Optionally, if specified,
27 // |new_frame_cb| will be called for each new frame received.
28 NullVideoSink(bool clockless,
29 base::TimeDelta interval,
30 const NewFrameCB& new_frame_cb,
31 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
32 ~NullVideoSink() override;
34 // VideoRendererSink implementation.
35 void Start(RenderCallback* callback) override;
36 void Stop() override;
37 void PaintFrameUsingOldRenderingPath(
38 const scoped_refptr<VideoFrame>& frame) override;
40 void set_tick_clock_for_testing(base::TickClock* tick_clock) {
41 tick_clock_ = tick_clock;
44 // Sets |stop_cb_|, which will be fired when Stop() is called.
45 void set_stop_cb(const base::Closure& stop_cb) {
46 stop_cb_ = stop_cb;
49 bool is_started() const { return started_; }
51 void set_background_render(bool is_background_rendering) {
52 background_render_ = is_background_rendering;
55 private:
56 // Task that periodically calls Render() to consume video data.
57 void CallRender();
59 const bool clockless_;
60 const base::TimeDelta interval_;
61 const NewFrameCB new_frame_cb_;
62 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
64 bool started_;
65 RenderCallback* callback_;
67 // Manages cancellation of periodic Render() callback task.
68 base::CancelableClosure cancelable_worker_;
70 // Used to determine when a new frame is received.
71 scoped_refptr<VideoFrame> last_frame_;
73 // Used to determine the interval given to RenderCallback::Render() as well as
74 // to maintain stable periodicity of callbacks.
75 base::TimeTicks current_render_time_;
77 // Allow for an injectable tick clock for testing.
78 base::DefaultTickClock default_tick_clock_;
79 base::TimeTicks last_now_;
81 // If specified, used instead of |default_tick_clock_|.
82 base::TickClock* tick_clock_;
84 // If set, called when Stop() is called.
85 base::Closure stop_cb_;
87 // Value passed to RenderCallback::Render().
88 bool background_render_;
90 DISALLOW_COPY_AND_ASSIGN(NullVideoSink);
93 } // namespace media
95 #endif // MEDIA_AUDIO_NULL_VIDEO_SINK_H_