OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FILTERS_VIDEO_RENDERER_BASE_H_ | 5 #ifndef MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_ |
6 #define MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_ | 6 #define MEDIA_FILTERS_VIDEO_RENDERER_BASE_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/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/synchronization/condition_variable.h" | 12 #include "base/synchronization/condition_variable.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
15 #include "media/base/decryptor.h" | 15 #include "media/base/decryptor.h" |
16 #include "media/base/demuxer_stream.h" | 16 #include "media/base/demuxer_stream.h" |
17 #include "media/base/pipeline_status.h" | 17 #include "media/base/pipeline_status.h" |
18 #include "media/base/video_decoder.h" | 18 #include "media/base/video_decoder.h" |
19 #include "media/base/video_frame.h" | 19 #include "media/base/video_frame.h" |
20 #include "media/base/video_renderer.h" | 20 #include "media/base/video_renderer.h" |
| 21 #include "media/filters/video_frame_stream.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class MessageLoopProxy; | 24 class MessageLoopProxy; |
24 } | 25 } |
25 | 26 |
26 namespace media { | 27 namespace media { |
27 | 28 |
28 class DecryptingDemuxerStream; | 29 class DecryptingDemuxerStream; |
29 class VideoDecoderSelector; | 30 class VideoDecoderSelector; |
30 | 31 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 virtual void Flush(const base::Closure& callback) OVERRIDE; | 77 virtual void Flush(const base::Closure& callback) OVERRIDE; |
77 virtual void Preroll(base::TimeDelta time, | 78 virtual void Preroll(base::TimeDelta time, |
78 const PipelineStatusCB& cb) OVERRIDE; | 79 const PipelineStatusCB& cb) OVERRIDE; |
79 virtual void Stop(const base::Closure& callback) OVERRIDE; | 80 virtual void Stop(const base::Closure& callback) OVERRIDE; |
80 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; | 81 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
81 | 82 |
82 // PlatformThread::Delegate implementation. | 83 // PlatformThread::Delegate implementation. |
83 virtual void ThreadMain() OVERRIDE; | 84 virtual void ThreadMain() OVERRIDE; |
84 | 85 |
85 private: | 86 private: |
86 // Called when |decoder_selector_| selected the |selected_decoder|. | 87 // Callback for |video_frame_stream_| initialization. |
87 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream | 88 void OnVideoFrameStreamInitialized(bool success, bool has_alpha); |
88 // created to help decrypt the encrypted stream. | |
89 // Note: |decoder_selector| is passed here to keep the VideoDecoderSelector | |
90 // alive until OnDecoderSelected() finishes. | |
91 void OnDecoderSelected( | |
92 scoped_ptr<VideoDecoderSelector> decoder_selector, | |
93 const scoped_refptr<VideoDecoder>& selected_decoder, | |
94 const scoped_refptr<DecryptingDemuxerStream>& decrypting_demuxer_stream); | |
95 | 89 |
96 // Callback from the video decoder delivering decoded video frames and | 90 // Callback from the video decoder delivering decoded video frames and |
97 // reporting video decoder status. | 91 // reporting video decoder status. |
98 void FrameReady(VideoDecoder::Status status, | 92 void FrameReady(VideoDecoder::Status status, |
99 const scoped_refptr<VideoFrame>& frame); | 93 const scoped_refptr<VideoFrame>& frame); |
100 | 94 |
101 // Helper method for adding a frame to |ready_frames_|. | 95 // Helper method for adding a frame to |ready_frames_|. |
102 void AddReadyFrame_Locked(const scoped_refptr<VideoFrame>& frame); | 96 void AddReadyFrame_Locked(const scoped_refptr<VideoFrame>& frame); |
103 | 97 |
104 // Helper method that schedules an asynchronous read from the decoder as long | 98 // Helper method that schedules an asynchronous read from the decoder as long |
105 // as there isn't a pending read and we have capacity. | 99 // as there isn't a pending read and we have capacity. |
106 void AttemptRead(); | 100 void AttemptRead(); |
107 void AttemptRead_Locked(); | 101 void AttemptRead_Locked(); |
108 | 102 |
109 // Called when VideoDecoder::Reset() completes. | 103 // Called when VideoFrameStream::Reset() completes. |
110 void OnDecoderResetDone(); | 104 void OnVideoFrameStreamResetDone(); |
111 | 105 |
112 // Attempts to complete flushing and transition into the flushed state. | 106 // Attempts to complete flushing and transition into the flushed state. |
113 void AttemptFlush_Locked(); | 107 void AttemptFlush_Locked(); |
114 | 108 |
115 // Calculates the duration to sleep for based on |last_timestamp_|, | 109 // Calculates the duration to sleep for based on |last_timestamp_|, |
116 // the next frame timestamp (may be NULL), and the provided playback rate. | 110 // the next frame timestamp (may be NULL), and the provided playback rate. |
117 // | 111 // |
118 // We don't use |playback_rate_| to avoid locking. | 112 // We don't use |playback_rate_| to avoid locking. |
119 base::TimeDelta CalculateSleepDuration( | 113 base::TimeDelta CalculateSleepDuration( |
120 const scoped_refptr<VideoFrame>& next_frame, | 114 const scoped_refptr<VideoFrame>& next_frame, |
121 float playback_rate); | 115 float playback_rate); |
122 | 116 |
123 // Helper function that flushes the buffers when a Stop() or error occurs. | 117 // Helper function that flushes the buffers when a Stop() or error occurs. |
124 void DoStopOrError_Locked(); | 118 void DoStopOrError_Locked(); |
125 | 119 |
126 // Runs |paint_cb_| with the next frame from |ready_frames_|, updating | 120 // Runs |paint_cb_| with the next frame from |ready_frames_|, updating |
127 // |last_natural_size_| and running |size_changed_cb_| if the natural size | 121 // |last_natural_size_| and running |size_changed_cb_| if the natural size |
128 // changes. | 122 // changes. |
129 // | 123 // |
130 // A read is scheduled to replace the frame. | 124 // A read is scheduled to replace the frame. |
131 void PaintNextReadyFrame_Locked(); | 125 void PaintNextReadyFrame_Locked(); |
132 | 126 |
133 // Drops the next frame from |ready_frames_| and runs |statistics_cb_|. | 127 // Drops the next frame from |ready_frames_| and runs |statistics_cb_|. |
134 // | 128 // |
135 // A read is scheduled to replace the frame. | 129 // A read is scheduled to replace the frame. |
136 void DropNextReadyFrame_Locked(); | 130 void DropNextReadyFrame_Locked(); |
137 | 131 |
138 void ResetDecoder(); | |
139 void StopDecoder(const base::Closure& callback); | |
140 | |
141 // Pops the front of |decoders|, assigns it to |decoder_| and then | |
142 // calls initialize on the new decoder. | |
143 void InitializeNextDecoder(const scoped_refptr<DemuxerStream>& demuxer_stream, | |
144 scoped_ptr<VideoDecoderList> decoders); | |
145 | |
146 // Called when |decoder_| initialization completes. | |
147 // |demuxer_stream| & |decoders| are used if initialization failed and | |
148 // InitializeNextDecoder() needs to be called again. | |
149 void OnDecoderInitDone(const scoped_refptr<DemuxerStream>& demuxer_stream, | |
150 scoped_ptr<VideoDecoderList> decoders, | |
151 PipelineStatus status); | |
152 | |
153 void TransitionToPrerolled_Locked(); | 132 void TransitionToPrerolled_Locked(); |
154 | 133 |
155 scoped_refptr<base::MessageLoopProxy> message_loop_; | 134 scoped_refptr<base::MessageLoopProxy> message_loop_; |
156 base::WeakPtrFactory<VideoRendererBase> weak_factory_; | 135 base::WeakPtrFactory<VideoRendererBase> weak_factory_; |
157 base::WeakPtr<VideoRendererBase> weak_this_; | 136 base::WeakPtr<VideoRendererBase> weak_this_; |
158 | 137 |
159 // Used for accessing data members. | 138 // Used for accessing data members. |
160 base::Lock lock_; | 139 base::Lock lock_; |
161 | 140 |
162 SetDecryptorReadyCB set_decryptor_ready_cb_; | 141 // Provides video frames to VideoRendererBase. |
163 | 142 VideoFrameStream video_frame_stream_; |
164 // These two will be set by VideoDecoderSelector::SelectVideoDecoder(). | |
165 scoped_refptr<VideoDecoder> decoder_; | |
166 scoped_refptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; | |
167 | 143 |
168 // Queue of incoming frames yet to be painted. | 144 // Queue of incoming frames yet to be painted. |
169 typedef std::deque<scoped_refptr<VideoFrame> > VideoFrameQueue; | 145 typedef std::deque<scoped_refptr<VideoFrame> > VideoFrameQueue; |
170 VideoFrameQueue ready_frames_; | 146 VideoFrameQueue ready_frames_; |
171 | 147 |
172 // Keeps track of whether we received the end of stream buffer. | 148 // Keeps track of whether we received the end of stream buffer. |
173 bool received_end_of_stream_; | 149 bool received_end_of_stream_; |
174 | 150 |
175 // Used to signal |thread_| as frames are added to |frames_|. Rule of thumb: | 151 // Used to signal |thread_| as frames are added to |frames_|. Rule of thumb: |
176 // always check |state_| to see if it was set to STOPPED after waking up! | 152 // always check |state_| to see if it was set to STOPPED after waking up! |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // either for calling |paint_cb_| or for dropping. Set to kNoTimestamp() | 239 // either for calling |paint_cb_| or for dropping. Set to kNoTimestamp() |
264 // during flushing. | 240 // during flushing. |
265 base::TimeDelta last_timestamp_; | 241 base::TimeDelta last_timestamp_; |
266 | 242 |
267 DISALLOW_COPY_AND_ASSIGN(VideoRendererBase); | 243 DISALLOW_COPY_AND_ASSIGN(VideoRendererBase); |
268 }; | 244 }; |
269 | 245 |
270 } // namespace media | 246 } // namespace media |
271 | 247 |
272 #endif // MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_ | 248 #endif // MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_ |
OLD | NEW |