| 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/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/synchronization/condition_variable.h" | 13 #include "base/synchronization/condition_variable.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 #include "media/base/decryptor.h" | 16 #include "media/base/decryptor.h" |
| 17 #include "media/base/demuxer_stream.h" | 17 #include "media/base/demuxer_stream.h" |
| 18 #include "media/base/pipeline_status.h" | 18 #include "media/base/pipeline_status.h" |
| 19 #include "media/base/video_decoder.h" | 19 #include "media/base/video_decoder.h" |
| 20 #include "media/base/video_frame.h" | 20 #include "media/base/video_frame.h" |
| 21 #include "media/base/video_renderer.h" | 21 #include "media/base/video_renderer.h" |
| 22 #include "media/filters/video_frame_stream.h" | 22 #include "media/filters/video_frame_stream.h" |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 class MessageLoopProxy; | 25 class SingleThreadTaskRunner; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace media { | 28 namespace media { |
| 29 | 29 |
| 30 // VideoRendererBase creates its own thread for the sole purpose of timing frame | 30 // VideoRendererBase creates its own thread for the sole purpose of timing frame |
| 31 // presentation. It handles reading from the VideoFrameStream and stores the | 31 // presentation. It handles reading from the VideoFrameStream and stores the |
| 32 // results in a queue of decoded frames and executing a callback when a frame is | 32 // results in a queue of decoded frames and executing a callback when a frame is |
| 33 // ready for rendering. | 33 // ready for rendering. |
| 34 class MEDIA_EXPORT VideoRendererBase | 34 class MEDIA_EXPORT VideoRendererBase |
| 35 : public VideoRenderer, | 35 : public VideoRenderer, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 47 // frame is available for painting. | 47 // frame is available for painting. |
| 48 // | 48 // |
| 49 // |set_opaque_cb| is executed when the renderer is initialized to inform | 49 // |set_opaque_cb| is executed when the renderer is initialized to inform |
| 50 // the player whether the decoded output will be opaque or not. | 50 // the player whether the decoded output will be opaque or not. |
| 51 // | 51 // |
| 52 // Implementors should avoid doing any sort of heavy work in this method and | 52 // Implementors should avoid doing any sort of heavy work in this method and |
| 53 // instead post a task to a common/worker thread to handle rendering. Slowing | 53 // instead post a task to a common/worker thread to handle rendering. Slowing |
| 54 // down the video thread may result in losing synchronization with audio. | 54 // down the video thread may result in losing synchronization with audio. |
| 55 // | 55 // |
| 56 // Setting |drop_frames_| to true causes the renderer to drop expired frames. | 56 // Setting |drop_frames_| to true causes the renderer to drop expired frames. |
| 57 VideoRendererBase(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 57 VideoRendererBase( |
| 58 ScopedVector<VideoDecoder> decoders, | 58 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 59 const SetDecryptorReadyCB& set_decryptor_ready_cb, | 59 ScopedVector<VideoDecoder> decoders, |
| 60 const PaintCB& paint_cb, | 60 const SetDecryptorReadyCB& set_decryptor_ready_cb, |
| 61 const SetOpaqueCB& set_opaque_cb, | 61 const PaintCB& paint_cb, |
| 62 bool drop_frames); | 62 const SetOpaqueCB& set_opaque_cb, |
| 63 bool drop_frames); |
| 63 virtual ~VideoRendererBase(); | 64 virtual ~VideoRendererBase(); |
| 64 | 65 |
| 65 // VideoRenderer implementation. | 66 // VideoRenderer implementation. |
| 66 virtual void Initialize(DemuxerStream* stream, | 67 virtual void Initialize(DemuxerStream* stream, |
| 67 const PipelineStatusCB& init_cb, | 68 const PipelineStatusCB& init_cb, |
| 68 const StatisticsCB& statistics_cb, | 69 const StatisticsCB& statistics_cb, |
| 69 const TimeCB& max_time_cb, | 70 const TimeCB& max_time_cb, |
| 70 const NaturalSizeChangedCB& size_changed_cb, | 71 const NaturalSizeChangedCB& size_changed_cb, |
| 71 const base::Closure& ended_cb, | 72 const base::Closure& ended_cb, |
| 72 const PipelineStatusCB& error_cb, | 73 const PipelineStatusCB& error_cb, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // A read is scheduled to replace the frame. | 128 // A read is scheduled to replace the frame. |
| 128 void DropNextReadyFrame_Locked(); | 129 void DropNextReadyFrame_Locked(); |
| 129 | 130 |
| 130 void TransitionToPrerolled_Locked(); | 131 void TransitionToPrerolled_Locked(); |
| 131 | 132 |
| 132 // Runs |statistics_cb_| with |frames_decoded_| and |frames_dropped_|, resets | 133 // Runs |statistics_cb_| with |frames_decoded_| and |frames_dropped_|, resets |
| 133 // them to 0, and then waits on |frame_available_| for up to the | 134 // them to 0, and then waits on |frame_available_| for up to the |
| 134 // |wait_duration|. | 135 // |wait_duration|. |
| 135 void UpdateStatsAndWait_Locked(base::TimeDelta wait_duration); | 136 void UpdateStatsAndWait_Locked(base::TimeDelta wait_duration); |
| 136 | 137 |
| 137 scoped_refptr<base::MessageLoopProxy> message_loop_; | 138 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 138 base::WeakPtrFactory<VideoRendererBase> weak_factory_; | 139 base::WeakPtrFactory<VideoRendererBase> weak_factory_; |
| 139 base::WeakPtr<VideoRendererBase> weak_this_; | 140 base::WeakPtr<VideoRendererBase> weak_this_; |
| 140 | 141 |
| 141 // Used for accessing data members. | 142 // Used for accessing data members. |
| 142 base::Lock lock_; | 143 base::Lock lock_; |
| 143 | 144 |
| 144 // Provides video frames to VideoRendererBase. | 145 // Provides video frames to VideoRendererBase. |
| 145 VideoFrameStream video_frame_stream_; | 146 VideoFrameStream video_frame_stream_; |
| 146 | 147 |
| 147 // Queue of incoming frames yet to be painted. | 148 // Queue of incoming frames yet to be painted. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // last call to |statistics_cb_|. These must be accessed under lock. | 246 // last call to |statistics_cb_|. These must be accessed under lock. |
| 246 int frames_decoded_; | 247 int frames_decoded_; |
| 247 int frames_dropped_; | 248 int frames_dropped_; |
| 248 | 249 |
| 249 DISALLOW_COPY_AND_ASSIGN(VideoRendererBase); | 250 DISALLOW_COPY_AND_ASSIGN(VideoRendererBase); |
| 250 }; | 251 }; |
| 251 | 252 |
| 252 } // namespace media | 253 } // namespace media |
| 253 | 254 |
| 254 #endif // MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_ | 255 #endif // MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_ |
| OLD | NEW |