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

Side by Side Diff: media/renderers/video_renderer_impl.h

Issue 1083383005: Connect the new video rendering path to the compositor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@vra
Patch Set: Remove NullVideoSink Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ 5 #ifndef MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_
6 #define MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ 6 #define MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/synchronization/condition_variable.h" 14 #include "base/synchronization/condition_variable.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "base/threading/platform_thread.h" 16 #include "base/threading/platform_thread.h"
17 #include "base/timer/timer.h"
17 #include "media/base/decryptor.h" 18 #include "media/base/decryptor.h"
18 #include "media/base/demuxer_stream.h" 19 #include "media/base/demuxer_stream.h"
19 #include "media/base/media_log.h" 20 #include "media/base/media_log.h"
20 #include "media/base/pipeline_status.h" 21 #include "media/base/pipeline_status.h"
21 #include "media/base/video_decoder.h" 22 #include "media/base/video_decoder.h"
22 #include "media/base/video_frame.h" 23 #include "media/base/video_frame.h"
23 #include "media/base/video_renderer.h" 24 #include "media/base/video_renderer.h"
24 #include "media/base/video_renderer_sink.h" 25 #include "media/base/video_renderer_sink.h"
25 #include "media/filters/decoder_stream.h" 26 #include "media/filters/decoder_stream.h"
27 #include "media/filters/video_renderer_algorithm.h"
26 28
27 namespace base { 29 namespace base {
28 class SingleThreadTaskRunner; 30 class SingleThreadTaskRunner;
29 class TickClock; 31 class TickClock;
30 } 32 }
31 33
32 namespace media { 34 namespace media {
33 35
34 // VideoRendererImpl creates its own thread for the sole purpose of timing frame 36 // VideoRendererImpl creates its own thread for the sole purpose of timing frame
35 // presentation. It handles reading from the VideoFrameStream and stores the 37 // presentation. It handles reading from the VideoFrameStream and stores the
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // PlatformThread::Delegate implementation. 74 // PlatformThread::Delegate implementation.
73 void ThreadMain() override; 75 void ThreadMain() override;
74 76
75 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock); 77 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock);
76 78
77 // VideoRendererSink::RenderCallback implementation. 79 // VideoRendererSink::RenderCallback implementation.
78 scoped_refptr<VideoFrame> Render(base::TimeTicks deadline_min, 80 scoped_refptr<VideoFrame> Render(base::TimeTicks deadline_min,
79 base::TimeTicks deadline_max) override; 81 base::TimeTicks deadline_max) override;
80 void OnFrameDropped() override; 82 void OnFrameDropped() override;
81 83
84 void enable_new_video_renderer_for_testing() {
85 use_new_video_renderering_path_ = true;
86 }
87
88 void SetBackgroundRenderingForTesting(bool enabled, base::TimeDelta timeout);
xhwang 2015/04/29 06:51:55 nit: Add comment, or s/timeout/background_renderin
DaleCurtis 2015/04/30 03:49:37 Done.
89
82 private: 90 private:
83 // Creates a dedicated |thread_| for video rendering. 91 // Creates a dedicated |thread_| for video rendering.
84 void CreateVideoThread(); 92 void CreateVideoThread();
85 93
86 // Callback for |video_frame_stream_| initialization. 94 // Callback for |video_frame_stream_| initialization.
87 void OnVideoFrameStreamInitialized(bool success); 95 void OnVideoFrameStreamInitialized(bool success);
88 96
89 // Callback for |video_frame_stream_| to deliver decoded video frames and 97 // Callback for |video_frame_stream_| to deliver decoded video frames and
90 // report video decoding status. 98 // report video decoding status.
91 void FrameReady(VideoFrameStream::Status status, 99 void FrameReady(VideoFrameStream::Status status,
(...skipping 24 matching lines...) Expand all
116 // Returns true if the renderer has enough data for playback purposes. 124 // Returns true if the renderer has enough data for playback purposes.
117 // Note that having enough data may be due to reaching end of stream. 125 // Note that having enough data may be due to reaching end of stream.
118 bool HaveEnoughData_Locked(); 126 bool HaveEnoughData_Locked();
119 void TransitionToHaveEnough_Locked(); 127 void TransitionToHaveEnough_Locked();
120 128
121 // Runs |statistics_cb_| with |frames_decoded_| and |frames_dropped_|, resets 129 // Runs |statistics_cb_| with |frames_decoded_| and |frames_dropped_|, resets
122 // them to 0, and then waits on |frame_available_| for up to the 130 // them to 0, and then waits on |frame_available_| for up to the
123 // |wait_duration|. 131 // |wait_duration|.
124 void UpdateStatsAndWait_Locked(base::TimeDelta wait_duration); 132 void UpdateStatsAndWait_Locked(base::TimeDelta wait_duration);
125 133
134 // Called after we've painted the first frame. If |time_progressing_| is
135 // false it Stop() on |sink_|.
136 void MaybeStopSinkAfterFirstPaint();
137
138 // Resets and primes the |background_rendering_timer_|, when the timer fires
139 // it calls the BackgroundRender() method below.
140 void RestartBackgroundRenderTimer();
141
142 // Called by |background_rendering_timer_| when enough time elapses where we
143 // haven't seen a Render() call.
144 void BackgroundRender();
145 void BackgroundRender_Locked();
146
147 // Return true if there is no more room for additional buffered frames.
xhwang 2015/04/29 06:51:55 nit: Return_s_
DaleCurtis 2015/04/30 03:49:37 Done.
148 bool HaveReachedBufferingCap();
149
150 // Starts or stops |sink_| respectively. Do not call while |lock_| is held.
151 void StartSink();
152 void StopSink();
153
154 // Fires |ended_cb_| if there are no remaining usable frames and
155 // |received_end_of_stream_| is true. Sets |rendered_end_of_stream_| if it
156 // does so. Returns algorithm_->EffectiveFramesQueued().
157 size_t MaybeFireEndedCallback();
158
126 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 159 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
127 160
161 // Enables the use of VideoRendererAlgorithm and VideoRendererSink for frame
162 // rendering instead of using a thread in a sleep-loop. Set via the command
163 // line flag kEnableNewVideoRenderer or via test methods.
164 bool use_new_video_renderering_path_;
165
166 // Sink which calls into VideoRendererImpl via Render() for video frames. Do
167 // not call any methods on the sink while |lock_| is held or the two threads
168 // might deadlock. Do not call Start() or Stop() on the sink directly, use
169 // StartSink() and StopSink() to ensure background rendering is started.
128 VideoRendererSink* const sink_; 170 VideoRendererSink* const sink_;
129 171
130 // Used for accessing data members. 172 // Used for accessing data members.
131 base::Lock lock_; 173 base::Lock lock_;
132 174
133 // Provides video frames to VideoRendererImpl. 175 // Provides video frames to VideoRendererImpl.
134 scoped_ptr<VideoFrameStream> video_frame_stream_; 176 scoped_ptr<VideoFrameStream> video_frame_stream_;
135 177
136 // Flag indicating low-delay mode. 178 // Flag indicating low-delay mode.
137 bool low_delay_; 179 bool low_delay_;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 254
213 // Keeps track of the number of frames decoded and dropped since the 255 // Keeps track of the number of frames decoded and dropped since the
214 // last call to |statistics_cb_|. These must be accessed under lock. 256 // last call to |statistics_cb_|. These must be accessed under lock.
215 int frames_decoded_; 257 int frames_decoded_;
216 int frames_dropped_; 258 int frames_dropped_;
217 259
218 bool is_shutting_down_; 260 bool is_shutting_down_;
219 261
220 scoped_ptr<base::TickClock> tick_clock_; 262 scoped_ptr<base::TickClock> tick_clock_;
221 263
264 // Algorithm for selecting which frame to render; manages frames and all
265 // timing related information.
266 scoped_ptr<VideoRendererAlgorithm> algorithm_;
267
268 // Indicates that Render() callbacks from |sink_| have timed out, so we've
269 // entered a background rendering mode where dropped frames are not counted.
270 bool is_background_rendering_;
271
272 // Allows tests to disable the background rendering task.
273 bool should_use_background_renderering_;
274
275 // Manages expiration of stale video frames if Render() callbacks timeout. Do
276 // not access from the thread Render() is called on. Must only be used on
277 // |task_runner_|.
278 base::OneShotTimer<VideoRendererImpl> background_rendering_timer_;
279
280 // Indicates whether or not media time is currently progressing or not.
281 bool time_progressing_;
282
283 // Indicates that Render() should only render the first frame and then request
284 // that the sink be stopped.
285 bool render_first_frame_and_stop_;
286
287 // The time to wait for Render() before firing BackgroundRender().
288 base::TimeDelta background_rendering_timeout_;
289
222 // NOTE: Weak pointers must be invalidated before all other member variables. 290 // NOTE: Weak pointers must be invalidated before all other member variables.
223 base::WeakPtrFactory<VideoRendererImpl> weak_factory_; 291 base::WeakPtrFactory<VideoRendererImpl> weak_factory_;
224 292
225 DISALLOW_COPY_AND_ASSIGN(VideoRendererImpl); 293 DISALLOW_COPY_AND_ASSIGN(VideoRendererImpl);
226 }; 294 };
227 295
228 } // namespace media 296 } // namespace media
229 297
230 #endif // MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ 298 #endif // MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698