OLD | NEW |
---|---|
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 Loading... | |
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 // Enables or disables background rendering. If |enabled|, |timeout| is the | |
89 // amount of time to wait after the last Render() call beforing starting the | |
xhwang
2015/04/30 16:39:21
s/beforing/before
DaleCurtis
2015/04/30 18:06:01
Done.
| |
90 // background rendering mode. | |
91 void SetBackgroundRenderingForTesting(bool enabled, base::TimeDelta timeout); | |
92 | |
82 private: | 93 private: |
83 // Creates a dedicated |thread_| for video rendering. | 94 // Creates a dedicated |thread_| for video rendering. |
84 void CreateVideoThread(); | 95 void CreateVideoThread(); |
85 | 96 |
86 // Callback for |video_frame_stream_| initialization. | 97 // Callback for |video_frame_stream_| initialization. |
87 void OnVideoFrameStreamInitialized(bool success); | 98 void OnVideoFrameStreamInitialized(bool success); |
88 | 99 |
89 // Callback for |video_frame_stream_| to deliver decoded video frames and | 100 // Callback for |video_frame_stream_| to deliver decoded video frames and |
90 // report video decoding status. | 101 // report video decoding status. |
91 void FrameReady(VideoFrameStream::Status status, | 102 void FrameReady(VideoFrameStream::Status status, |
(...skipping 24 matching lines...) Expand all Loading... | |
116 // Returns true if the renderer has enough data for playback purposes. | 127 // 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. | 128 // Note that having enough data may be due to reaching end of stream. |
118 bool HaveEnoughData_Locked(); | 129 bool HaveEnoughData_Locked(); |
119 void TransitionToHaveEnough_Locked(); | 130 void TransitionToHaveEnough_Locked(); |
120 | 131 |
121 // Runs |statistics_cb_| with |frames_decoded_| and |frames_dropped_|, resets | 132 // Runs |statistics_cb_| with |frames_decoded_| and |frames_dropped_|, resets |
122 // them to 0, and then waits on |frame_available_| for up to the | 133 // them to 0, and then waits on |frame_available_| for up to the |
123 // |wait_duration|. | 134 // |wait_duration|. |
124 void UpdateStatsAndWait_Locked(base::TimeDelta wait_duration); | 135 void UpdateStatsAndWait_Locked(base::TimeDelta wait_duration); |
125 | 136 |
137 // Called after we've painted the first frame. If |time_progressing_| is | |
138 // false it Stop() on |sink_|. | |
139 void MaybeStopSinkAfterFirstPaint(); | |
140 | |
141 // Resets and primes the |background_rendering_timer_|, when the timer fires | |
142 // it calls the BackgroundRender() method below. | |
143 void RestartBackgroundRenderTimer(); | |
xhwang
2015/04/30 16:39:21
This is now only started once after we start the s
DaleCurtis
2015/04/30 18:06:01
Done.
| |
144 | |
145 // Called by |background_rendering_timer_| when enough time elapses where we | |
146 // haven't seen a Render() call. | |
147 void BackgroundRender(); | |
148 void BackgroundRender_Locked(); | |
149 | |
150 // Returns true if there is no more room for additional buffered frames. | |
151 bool HaveReachedBufferingCap(); | |
152 | |
153 // Starts or stops |sink_| respectively. Do not call while |lock_| is held. | |
154 void StartSink(); | |
155 void StopSink(); | |
156 | |
157 // Fires |ended_cb_| if there are no remaining usable frames and | |
158 // |received_end_of_stream_| is true. Sets |rendered_end_of_stream_| if it | |
159 // does so. Returns algorithm_->EffectiveFramesQueued(). | |
160 size_t MaybeFireEndedCallback(); | |
161 | |
126 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 162 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
127 | 163 |
164 // Enables the use of VideoRendererAlgorithm and VideoRendererSink for frame | |
165 // rendering instead of using a thread in a sleep-loop. Set via the command | |
166 // line flag kEnableNewVideoRenderer or via test methods. | |
167 bool use_new_video_renderering_path_; | |
168 | |
169 // Sink which calls into VideoRendererImpl via Render() for video frames. Do | |
170 // not call any methods on the sink while |lock_| is held or the two threads | |
171 // might deadlock. Do not call Start() or Stop() on the sink directly, use | |
172 // StartSink() and StopSink() to ensure background rendering is started. | |
128 VideoRendererSink* const sink_; | 173 VideoRendererSink* const sink_; |
174 bool sink_started_; | |
129 | 175 |
130 // Used for accessing data members. | 176 // Used for accessing data members. |
131 base::Lock lock_; | 177 base::Lock lock_; |
132 | 178 |
133 // Provides video frames to VideoRendererImpl. | 179 // Provides video frames to VideoRendererImpl. |
134 scoped_ptr<VideoFrameStream> video_frame_stream_; | 180 scoped_ptr<VideoFrameStream> video_frame_stream_; |
135 | 181 |
136 // Flag indicating low-delay mode. | 182 // Flag indicating low-delay mode. |
137 bool low_delay_; | 183 bool low_delay_; |
138 | 184 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 | 258 |
213 // Keeps track of the number of frames decoded and dropped since the | 259 // Keeps track of the number of frames decoded and dropped since the |
214 // last call to |statistics_cb_|. These must be accessed under lock. | 260 // last call to |statistics_cb_|. These must be accessed under lock. |
215 int frames_decoded_; | 261 int frames_decoded_; |
216 int frames_dropped_; | 262 int frames_dropped_; |
217 | 263 |
218 bool is_shutting_down_; | 264 bool is_shutting_down_; |
219 | 265 |
220 scoped_ptr<base::TickClock> tick_clock_; | 266 scoped_ptr<base::TickClock> tick_clock_; |
221 | 267 |
268 // Algorithm for selecting which frame to render; manages frames and all | |
269 // timing related information. | |
270 scoped_ptr<VideoRendererAlgorithm> algorithm_; | |
271 | |
272 // Indicates that Render() callbacks from |sink_| have timed out, so we've | |
273 // entered a background rendering mode where dropped frames are not counted. | |
274 bool is_background_rendering_; | |
275 | |
276 // Allows tests to disable the background rendering task. | |
277 bool should_use_background_renderering_; | |
278 | |
279 // Manages expiration of stale video frames if Render() callbacks timeout. Do | |
280 // not access from the thread Render() is called on. Must only be used on | |
281 // |task_runner_|. | |
282 base::RepeatingTimer<VideoRendererImpl> background_rendering_timer_; | |
283 | |
284 // Indicates whether or not media time is currently progressing or not. | |
285 bool time_progressing_; | |
286 | |
287 // Indicates that Render() should only render the first frame and then request | |
288 // that the sink be stopped. | |
289 bool render_first_frame_and_stop_; | |
290 | |
291 // The time to wait for Render() before firing BackgroundRender(). | |
292 base::TimeDelta background_rendering_timeout_; | |
293 | |
294 // Updated on every Render() call, checked by |background_rendering_timer_| to | |
295 // determine if background rendering should start. | |
296 base::TimeTicks last_render_time_; | |
297 | |
222 // NOTE: Weak pointers must be invalidated before all other member variables. | 298 // NOTE: Weak pointers must be invalidated before all other member variables. |
223 base::WeakPtrFactory<VideoRendererImpl> weak_factory_; | 299 base::WeakPtrFactory<VideoRendererImpl> weak_factory_; |
224 | 300 |
225 DISALLOW_COPY_AND_ASSIGN(VideoRendererImpl); | 301 DISALLOW_COPY_AND_ASSIGN(VideoRendererImpl); |
226 }; | 302 }; |
227 | 303 |
228 } // namespace media | 304 } // namespace media |
229 | 305 |
230 #endif // MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ | 306 #endif // MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ |
OLD | NEW |