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/media_export.h"
13 #include "media/base/video_renderer_sink.h"
16 class SingleThreadTaskRunner
;
21 class MEDIA_EXPORT NullVideoSink
: public VideoRendererSink
{
23 using NewFrameCB
= base::Callback
<void(const scoped_refptr
<VideoFrame
>&)>;
25 // Periodically calls |callback| every |interval| on |task_runner| once the
26 // sink has been started. If |clockless| is true, the RenderCallback will
27 // be called back to back by repeated post tasks. Optionally, if specified,
28 // |new_frame_cb| will be called for each new frame received.
29 NullVideoSink(bool clockless
,
30 base::TimeDelta interval
,
31 const NewFrameCB
& new_frame_cb
,
32 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
);
33 ~NullVideoSink() override
;
35 // VideoRendererSink implementation.
36 void Start(RenderCallback
* callback
) override
;
38 void PaintFrameUsingOldRenderingPath(
39 const scoped_refptr
<VideoFrame
>& frame
) override
;
41 void set_tick_clock_for_testing(base::TickClock
* tick_clock
) {
42 tick_clock_
= tick_clock
;
45 // Sets |stop_cb_|, which will be fired when Stop() is called.
46 void set_stop_cb(const base::Closure
& stop_cb
) {
50 bool is_started() const { return started_
; }
52 void set_background_render(bool is_background_rendering
) {
53 background_render_
= is_background_rendering
;
57 // Task that periodically calls Render() to consume video data.
60 const bool clockless_
;
61 const base::TimeDelta interval_
;
62 const NewFrameCB new_frame_cb_
;
63 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
66 RenderCallback
* callback_
;
68 // Manages cancellation of periodic Render() callback task.
69 base::CancelableClosure cancelable_worker_
;
71 // Used to determine when a new frame is received.
72 scoped_refptr
<VideoFrame
> last_frame_
;
74 // Used to determine the interval given to RenderCallback::Render() as well as
75 // to maintain stable periodicity of callbacks.
76 base::TimeTicks current_render_time_
;
78 // Allow for an injectable tick clock for testing.
79 base::DefaultTickClock default_tick_clock_
;
80 base::TimeTicks last_now_
;
82 // If specified, used instead of |default_tick_clock_|.
83 base::TickClock
* tick_clock_
;
85 // If set, called when Stop() is called.
86 base::Closure stop_cb_
;
88 // Value passed to RenderCallback::Render().
89 bool background_render_
;
91 DISALLOW_COPY_AND_ASSIGN(NullVideoSink
);
96 #endif // MEDIA_AUDIO_NULL_VIDEO_SINK_H_