| 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/synchronization/condition_variable.h" | 11 #include "base/synchronization/condition_variable.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 14 #include "media/base/demuxer_stream.h" |
| 14 #include "media/base/pipeline_status.h" | 15 #include "media/base/pipeline_status.h" |
| 15 #include "media/base/video_decoder.h" | 16 #include "media/base/video_decoder.h" |
| 16 #include "media/base/video_frame.h" | 17 #include "media/base/video_frame.h" |
| 17 #include "media/base/video_renderer.h" | 18 #include "media/base/video_renderer.h" |
| 18 | 19 |
| 19 namespace media { | 20 namespace media { |
| 20 | 21 |
| 21 // VideoRendererBase creates its own thread for the sole purpose of timing frame | 22 // VideoRendererBase creates its own thread for the sole purpose of timing frame |
| 22 // presentation. It handles reading from the decoder and stores the results in | 23 // presentation. It handles reading from the decoder and stores the results in |
| 23 // a queue of decoded frames and executing a callback when a frame is ready for | 24 // a queue of decoded frames and executing a callback when a frame is ready for |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 // | 44 // |
| 44 // Setting |drop_frames_| to true causes the renderer to drop expired frames. | 45 // Setting |drop_frames_| to true causes the renderer to drop expired frames. |
| 45 // | 46 // |
| 46 // TODO(scherkus): pass the VideoFrame* to this callback and remove | 47 // TODO(scherkus): pass the VideoFrame* to this callback and remove |
| 47 // Get/PutCurrentFrame() http://crbug.com/108435 | 48 // Get/PutCurrentFrame() http://crbug.com/108435 |
| 48 VideoRendererBase(const base::Closure& paint_cb, | 49 VideoRendererBase(const base::Closure& paint_cb, |
| 49 const SetOpaqueCB& set_opaque_cb, | 50 const SetOpaqueCB& set_opaque_cb, |
| 50 bool drop_frames); | 51 bool drop_frames); |
| 51 | 52 |
| 52 // VideoRenderer implementation. | 53 // VideoRenderer implementation. |
| 53 virtual void Initialize(const scoped_refptr<VideoDecoder>& decoder, | 54 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, |
| 55 const VideoDecoderList& decoders, |
| 54 const PipelineStatusCB& init_cb, | 56 const PipelineStatusCB& init_cb, |
| 55 const StatisticsCB& statistics_cb, | 57 const StatisticsCB& statistics_cb, |
| 56 const TimeCB& max_time_cb, | 58 const TimeCB& max_time_cb, |
| 57 const NaturalSizeChangedCB& size_changed_cb, | 59 const NaturalSizeChangedCB& size_changed_cb, |
| 58 const base::Closure& ended_cb, | 60 const base::Closure& ended_cb, |
| 59 const PipelineStatusCB& error_cb, | 61 const PipelineStatusCB& error_cb, |
| 60 const TimeDeltaCB& get_time_cb, | 62 const TimeDeltaCB& get_time_cb, |
| 61 const TimeDeltaCB& get_duration_cb) OVERRIDE; | 63 const TimeDeltaCB& get_duration_cb) OVERRIDE; |
| 62 virtual void Play(const base::Closure& callback) OVERRIDE; | 64 virtual void Play(const base::Closure& callback) OVERRIDE; |
| 63 virtual void Pause(const base::Closure& callback) OVERRIDE; | 65 virtual void Pause(const base::Closure& callback) OVERRIDE; |
| 64 virtual void Flush(const base::Closure& callback) OVERRIDE; | 66 virtual void Flush(const base::Closure& callback) OVERRIDE; |
| 65 virtual void Preroll(base::TimeDelta time, | 67 virtual void Preroll(base::TimeDelta time, |
| 66 const PipelineStatusCB& cb) OVERRIDE; | 68 const PipelineStatusCB& cb) OVERRIDE; |
| 67 virtual void Stop(const base::Closure& callback) OVERRIDE; | 69 virtual void Stop(const base::Closure& callback) OVERRIDE; |
| 68 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; | 70 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
| 71 virtual void PrepareForShutdownHack() OVERRIDE; |
| 69 | 72 |
| 70 // PlatformThread::Delegate implementation. | 73 // PlatformThread::Delegate implementation. |
| 71 virtual void ThreadMain() OVERRIDE; | 74 virtual void ThreadMain() OVERRIDE; |
| 72 | 75 |
| 73 // Clients of this class (painter/compositor) should use GetCurrentFrame() | 76 // Clients of this class (painter/compositor) should use GetCurrentFrame() |
| 74 // obtain ownership of VideoFrame, it should always relinquish the ownership | 77 // obtain ownership of VideoFrame, it should always relinquish the ownership |
| 75 // by use PutCurrentFrame(). Current frame is not guaranteed to be non-NULL. | 78 // by use PutCurrentFrame(). Current frame is not guaranteed to be non-NULL. |
| 76 // It expects clients to use color-fill the background if current frame | 79 // It expects clients to use color-fill the background if current frame |
| 77 // is NULL. This could happen before pipeline is pre-rolled or during | 80 // is NULL. This could happen before pipeline is pre-rolled or during |
| 78 // pause/flush/preroll. | 81 // pause/flush/preroll. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // Helper function that flushes the buffers when a Stop() or error occurs. | 115 // Helper function that flushes the buffers when a Stop() or error occurs. |
| 113 void DoStopOrError_Locked(); | 116 void DoStopOrError_Locked(); |
| 114 | 117 |
| 115 // Return the number of frames currently held by this class. | 118 // Return the number of frames currently held by this class. |
| 116 int NumFrames_Locked() const; | 119 int NumFrames_Locked() const; |
| 117 | 120 |
| 118 // Updates |current_frame_| to the next frame on |ready_frames_| and calls | 121 // Updates |current_frame_| to the next frame on |ready_frames_| and calls |
| 119 // |size_changed_cb_| if the natural size changes. | 122 // |size_changed_cb_| if the natural size changes. |
| 120 void SetCurrentFrameToNextReadyFrame(); | 123 void SetCurrentFrameToNextReadyFrame(); |
| 121 | 124 |
| 125 // Pops the front of |decoders|, assigns it to |decoder_| and then |
| 126 // calls initialize on the new decoder. |
| 127 void InitializeNextDecoder(const scoped_refptr<DemuxerStream>& demuxer_stream, |
| 128 scoped_ptr<VideoDecoderList> decoders); |
| 129 |
| 130 // Called when |decoder_| initialization completes. |
| 131 // |demuxer_stream| & |decoders| are used if initialization failed and |
| 132 // InitializeNextDecoder() needs to be called again. |
| 133 void OnDecoderInitDone(const scoped_refptr<DemuxerStream>& demuxer_stream, |
| 134 scoped_ptr<VideoDecoderList> decoders, |
| 135 PipelineStatus status); |
| 136 |
| 122 // Used for accessing data members. | 137 // Used for accessing data members. |
| 123 base::Lock lock_; | 138 base::Lock lock_; |
| 124 | 139 |
| 125 scoped_refptr<VideoDecoder> decoder_; | 140 scoped_refptr<VideoDecoder> decoder_; |
| 126 | 141 |
| 127 // Queue of incoming frames as well as the current frame since the last time | 142 // Queue of incoming frames as well as the current frame since the last time |
| 128 // OnFrameAvailable() was called. | 143 // OnFrameAvailable() was called. |
| 129 typedef std::deque<scoped_refptr<VideoFrame> > VideoFrameQueue; | 144 typedef std::deque<scoped_refptr<VideoFrame> > VideoFrameQueue; |
| 130 VideoFrameQueue ready_frames_; | 145 VideoFrameQueue ready_frames_; |
| 131 | 146 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 218 |
| 204 bool drop_frames_; | 219 bool drop_frames_; |
| 205 | 220 |
| 206 float playback_rate_; | 221 float playback_rate_; |
| 207 | 222 |
| 208 // Playback operation callbacks. | 223 // Playback operation callbacks. |
| 209 base::Closure flush_cb_; | 224 base::Closure flush_cb_; |
| 210 PipelineStatusCB preroll_cb_; | 225 PipelineStatusCB preroll_cb_; |
| 211 | 226 |
| 212 // Event callbacks. | 227 // Event callbacks. |
| 228 PipelineStatusCB init_cb_; |
| 213 StatisticsCB statistics_cb_; | 229 StatisticsCB statistics_cb_; |
| 214 TimeCB max_time_cb_; | 230 TimeCB max_time_cb_; |
| 215 NaturalSizeChangedCB size_changed_cb_; | 231 NaturalSizeChangedCB size_changed_cb_; |
| 216 base::Closure ended_cb_; | 232 base::Closure ended_cb_; |
| 217 PipelineStatusCB error_cb_; | 233 PipelineStatusCB error_cb_; |
| 218 TimeDeltaCB get_time_cb_; | 234 TimeDeltaCB get_time_cb_; |
| 219 TimeDeltaCB get_duration_cb_; | 235 TimeDeltaCB get_duration_cb_; |
| 220 | 236 |
| 221 base::TimeDelta preroll_timestamp_; | 237 base::TimeDelta preroll_timestamp_; |
| 222 | 238 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 233 | 249 |
| 234 // The last natural size |size_changed_cb_| was called with. | 250 // The last natural size |size_changed_cb_| was called with. |
| 235 gfx::Size last_natural_size_; | 251 gfx::Size last_natural_size_; |
| 236 | 252 |
| 237 DISALLOW_COPY_AND_ASSIGN(VideoRendererBase); | 253 DISALLOW_COPY_AND_ASSIGN(VideoRendererBase); |
| 238 }; | 254 }; |
| 239 | 255 |
| 240 } // namespace media | 256 } // namespace media |
| 241 | 257 |
| 242 #endif // MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_ | 258 #endif // MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_ |
| OLD | NEW |