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 "media/base/decryptor.h" | 17 #include "media/base/decryptor.h" |
18 #include "media/base/demuxer_stream.h" | 18 #include "media/base/demuxer_stream.h" |
19 #include "media/base/media_log.h" | 19 #include "media/base/media_log.h" |
20 #include "media/base/pipeline_status.h" | 20 #include "media/base/pipeline_status.h" |
21 #include "media/base/video_decoder.h" | 21 #include "media/base/video_decoder.h" |
22 #include "media/base/video_frame.h" | 22 #include "media/base/video_frame.h" |
23 #include "media/base/video_renderer.h" | 23 #include "media/base/video_renderer.h" |
| 24 #include "media/base/video_renderer_sink.h" |
24 #include "media/filters/decoder_stream.h" | 25 #include "media/filters/decoder_stream.h" |
25 | 26 |
26 namespace base { | 27 namespace base { |
27 class SingleThreadTaskRunner; | 28 class SingleThreadTaskRunner; |
28 class TickClock; | 29 class TickClock; |
29 } | 30 } |
30 | 31 |
31 namespace media { | 32 namespace media { |
32 | 33 |
33 // VideoRendererImpl creates its own thread for the sole purpose of timing frame | 34 // VideoRendererImpl creates its own thread for the sole purpose of timing frame |
34 // presentation. It handles reading from the VideoFrameStream and stores the | 35 // presentation. It handles reading from the VideoFrameStream and stores the |
35 // results in a queue of decoded frames and executing a callback when a frame is | 36 // results in a queue of decoded frames and executing a callback when a frame is |
36 // ready for rendering. | 37 // ready for rendering. |
37 class MEDIA_EXPORT VideoRendererImpl | 38 class MEDIA_EXPORT VideoRendererImpl |
38 : public VideoRenderer, | 39 : public VideoRenderer, |
| 40 public NON_EXPORTED_BASE(VideoRendererSink::RenderCallback), |
39 public base::PlatformThread::Delegate { | 41 public base::PlatformThread::Delegate { |
40 public: | 42 public: |
41 // |decoders| contains the VideoDecoders to use when initializing. | 43 // |decoders| contains the VideoDecoders to use when initializing. |
42 // | 44 // |
43 // Implementors should avoid doing any sort of heavy work in this method and | 45 // Implementors should avoid doing any sort of heavy work in this method and |
44 // instead post a task to a common/worker thread to handle rendering. Slowing | 46 // instead post a task to a common/worker thread to handle rendering. Slowing |
45 // down the video thread may result in losing synchronization with audio. | 47 // down the video thread may result in losing synchronization with audio. |
46 // | 48 // |
47 // Setting |drop_frames_| to true causes the renderer to drop expired frames. | 49 // Setting |drop_frames_| to true causes the renderer to drop expired frames. |
48 VideoRendererImpl( | 50 VideoRendererImpl( |
49 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 51 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 52 VideoRendererSink* sink, |
50 ScopedVector<VideoDecoder> decoders, | 53 ScopedVector<VideoDecoder> decoders, |
51 bool drop_frames, | 54 bool drop_frames, |
52 const scoped_refptr<MediaLog>& media_log); | 55 const scoped_refptr<MediaLog>& media_log); |
53 ~VideoRendererImpl() override; | 56 ~VideoRendererImpl() override; |
54 | 57 |
55 // VideoRenderer implementation. | 58 // VideoRenderer implementation. |
56 void Initialize(DemuxerStream* stream, | 59 void Initialize(DemuxerStream* stream, |
57 const PipelineStatusCB& init_cb, | 60 const PipelineStatusCB& init_cb, |
58 const SetDecryptorReadyCB& set_decryptor_ready_cb, | 61 const SetDecryptorReadyCB& set_decryptor_ready_cb, |
59 const StatisticsCB& statistics_cb, | 62 const StatisticsCB& statistics_cb, |
60 const BufferingStateCB& buffering_state_cb, | 63 const BufferingStateCB& buffering_state_cb, |
61 const PaintCB& paint_cb, | |
62 const base::Closure& ended_cb, | 64 const base::Closure& ended_cb, |
63 const PipelineStatusCB& error_cb, | 65 const PipelineStatusCB& error_cb, |
64 const WallClockTimeCB& wall_clock_time_cb, | 66 const WallClockTimeCB& wall_clock_time_cb, |
65 const base::Closure& waiting_for_decryption_key_cb) override; | 67 const base::Closure& waiting_for_decryption_key_cb) override; |
66 void Flush(const base::Closure& callback) override; | 68 void Flush(const base::Closure& callback) override; |
67 void StartPlayingFrom(base::TimeDelta timestamp) override; | 69 void StartPlayingFrom(base::TimeDelta timestamp) override; |
68 void OnTimeStateChanged(bool time_progressing) override; | 70 void OnTimeStateChanged(bool time_progressing) override; |
69 | 71 |
70 // PlatformThread::Delegate implementation. | 72 // PlatformThread::Delegate implementation. |
71 void ThreadMain() override; | 73 void ThreadMain() override; |
72 | 74 |
73 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock); | 75 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock); |
74 | 76 |
| 77 // VideoRendererSink::RenderCallback implementation. |
| 78 scoped_refptr<VideoFrame> Render(base::TimeTicks deadline_min, |
| 79 base::TimeTicks deadline_max) override; |
| 80 void OnFrameDropped() override; |
| 81 |
75 private: | 82 private: |
76 // Creates a dedicated |thread_| for video rendering. | 83 // Creates a dedicated |thread_| for video rendering. |
77 void CreateVideoThread(); | 84 void CreateVideoThread(); |
78 | 85 |
79 // Callback for |video_frame_stream_| initialization. | 86 // Callback for |video_frame_stream_| initialization. |
80 void OnVideoFrameStreamInitialized(bool success); | 87 void OnVideoFrameStreamInitialized(bool success); |
81 | 88 |
82 // Callback for |video_frame_stream_| to deliver decoded video frames and | 89 // Callback for |video_frame_stream_| to deliver decoded video frames and |
83 // report video decoding status. | 90 // report video decoding status. |
84 void FrameReady(VideoFrameStream::Status status, | 91 void FrameReady(VideoFrameStream::Status status, |
(...skipping 26 matching lines...) Expand all Loading... |
111 bool HaveEnoughData_Locked(); | 118 bool HaveEnoughData_Locked(); |
112 void TransitionToHaveEnough_Locked(); | 119 void TransitionToHaveEnough_Locked(); |
113 | 120 |
114 // Runs |statistics_cb_| with |frames_decoded_| and |frames_dropped_|, resets | 121 // Runs |statistics_cb_| with |frames_decoded_| and |frames_dropped_|, resets |
115 // them to 0, and then waits on |frame_available_| for up to the | 122 // them to 0, and then waits on |frame_available_| for up to the |
116 // |wait_duration|. | 123 // |wait_duration|. |
117 void UpdateStatsAndWait_Locked(base::TimeDelta wait_duration); | 124 void UpdateStatsAndWait_Locked(base::TimeDelta wait_duration); |
118 | 125 |
119 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 126 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
120 | 127 |
| 128 VideoRendererSink* const sink_; |
| 129 |
121 // Used for accessing data members. | 130 // Used for accessing data members. |
122 base::Lock lock_; | 131 base::Lock lock_; |
123 | 132 |
124 // Provides video frames to VideoRendererImpl. | 133 // Provides video frames to VideoRendererImpl. |
125 scoped_ptr<VideoFrameStream> video_frame_stream_; | 134 scoped_ptr<VideoFrameStream> video_frame_stream_; |
126 | 135 |
127 // Flag indicating low-delay mode. | 136 // Flag indicating low-delay mode. |
128 bool low_delay_; | 137 bool low_delay_; |
129 | 138 |
130 // Queue of incoming frames yet to be painted. | 139 // Queue of incoming frames yet to be painted. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 221 |
213 // NOTE: Weak pointers must be invalidated before all other member variables. | 222 // NOTE: Weak pointers must be invalidated before all other member variables. |
214 base::WeakPtrFactory<VideoRendererImpl> weak_factory_; | 223 base::WeakPtrFactory<VideoRendererImpl> weak_factory_; |
215 | 224 |
216 DISALLOW_COPY_AND_ASSIGN(VideoRendererImpl); | 225 DISALLOW_COPY_AND_ASSIGN(VideoRendererImpl); |
217 }; | 226 }; |
218 | 227 |
219 } // namespace media | 228 } // namespace media |
220 | 229 |
221 #endif // MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ | 230 #endif // MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ |
OLD | NEW |