Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: media/filters/video_renderer_base.h

Issue 12989009: Remove reference counting from media::VideoDecoder and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/synchronization/condition_variable.h" 13 #include "base/synchronization/condition_variable.h"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
14 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
15 #include "media/base/decryptor.h" 16 #include "media/base/decryptor.h"
16 #include "media/base/demuxer_stream.h" 17 #include "media/base/demuxer_stream.h"
17 #include "media/base/pipeline_status.h" 18 #include "media/base/pipeline_status.h"
18 #include "media/base/video_decoder.h" 19 #include "media/base/video_decoder.h"
19 #include "media/base/video_frame.h" 20 #include "media/base/video_frame.h"
20 #include "media/base/video_renderer.h" 21 #include "media/base/video_renderer.h"
(...skipping 14 matching lines...) Expand all
35 class MEDIA_EXPORT VideoRendererBase 36 class MEDIA_EXPORT VideoRendererBase
36 : public VideoRenderer, 37 : public VideoRenderer,
37 public base::PlatformThread::Delegate { 38 public base::PlatformThread::Delegate {
38 public: 39 public:
39 typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> PaintCB; 40 typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> PaintCB;
40 typedef base::Callback<void(bool)> SetOpaqueCB; 41 typedef base::Callback<void(bool)> SetOpaqueCB;
41 42
42 // Maximum duration of the last frame. 43 // Maximum duration of the last frame.
43 static base::TimeDelta kMaxLastFrameDuration(); 44 static base::TimeDelta kMaxLastFrameDuration();
44 45
46 // |decoders| contains the VideoDecoders to use when initializing.
47 //
45 // |paint_cb| is executed on the video frame timing thread whenever a new 48 // |paint_cb| is executed on the video frame timing thread whenever a new
46 // frame is available for painting. 49 // frame is available for painting.
47 // 50 //
48 // |set_opaque_cb| is executed when the renderer is initialized to inform 51 // |set_opaque_cb| is executed when the renderer is initialized to inform
49 // the player whether the decoder's output will be opaque or not. 52 // the player whether the decoder's output will be opaque or not.
50 // 53 //
51 // Implementors should avoid doing any sort of heavy work in this method and 54 // Implementors should avoid doing any sort of heavy work in this method and
52 // instead post a task to a common/worker thread to handle rendering. Slowing 55 // instead post a task to a common/worker thread to handle rendering. Slowing
53 // down the video thread may result in losing synchronization with audio. 56 // down the video thread may result in losing synchronization with audio.
54 // 57 //
55 // Setting |drop_frames_| to true causes the renderer to drop expired frames. 58 // Setting |drop_frames_| to true causes the renderer to drop expired frames.
56 VideoRendererBase(const scoped_refptr<base::MessageLoopProxy>& message_loop, 59 VideoRendererBase(const scoped_refptr<base::MessageLoopProxy>& message_loop,
60 ScopedVector<VideoDecoder> decoders,
57 const SetDecryptorReadyCB& set_decryptor_ready_cb, 61 const SetDecryptorReadyCB& set_decryptor_ready_cb,
58 const PaintCB& paint_cb, 62 const PaintCB& paint_cb,
59 const SetOpaqueCB& set_opaque_cb, 63 const SetOpaqueCB& set_opaque_cb,
60 bool drop_frames); 64 bool drop_frames);
61 virtual ~VideoRendererBase(); 65 virtual ~VideoRendererBase();
62 66
63 // VideoRenderer implementation. 67 // VideoRenderer implementation.
64 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, 68 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream,
65 const VideoDecoderList& decoders,
66 const PipelineStatusCB& init_cb, 69 const PipelineStatusCB& init_cb,
67 const StatisticsCB& statistics_cb, 70 const StatisticsCB& statistics_cb,
68 const TimeCB& max_time_cb, 71 const TimeCB& max_time_cb,
69 const NaturalSizeChangedCB& size_changed_cb, 72 const NaturalSizeChangedCB& size_changed_cb,
70 const base::Closure& ended_cb, 73 const base::Closure& ended_cb,
71 const PipelineStatusCB& error_cb, 74 const PipelineStatusCB& error_cb,
72 const TimeDeltaCB& get_time_cb, 75 const TimeDeltaCB& get_time_cb,
73 const TimeDeltaCB& get_duration_cb) OVERRIDE; 76 const TimeDeltaCB& get_duration_cb) OVERRIDE;
74 virtual void Play(const base::Closure& callback) OVERRIDE; 77 virtual void Play(const base::Closure& callback) OVERRIDE;
75 virtual void Pause(const base::Closure& callback) OVERRIDE; 78 virtual void Pause(const base::Closure& callback) OVERRIDE;
76 virtual void Flush(const base::Closure& callback) OVERRIDE; 79 virtual void Flush(const base::Closure& callback) OVERRIDE;
77 virtual void Preroll(base::TimeDelta time, 80 virtual void Preroll(base::TimeDelta time,
78 const PipelineStatusCB& cb) OVERRIDE; 81 const PipelineStatusCB& cb) OVERRIDE;
79 virtual void Stop(const base::Closure& callback) OVERRIDE; 82 virtual void Stop(const base::Closure& callback) OVERRIDE;
80 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; 83 virtual void SetPlaybackRate(float playback_rate) OVERRIDE;
81 84
82 // PlatformThread::Delegate implementation. 85 // PlatformThread::Delegate implementation.
83 virtual void ThreadMain() OVERRIDE; 86 virtual void ThreadMain() OVERRIDE;
84 87
85 private: 88 private:
86 // Called when |decoder_selector_| selected the |selected_decoder|. 89 // Called when |decoder_selector_| has selected |decoder| or is null if no
87 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream 90 // decoder could be selected.
91 //
92 // |decrypting_demuxer_stream| is non-null if a DecryptingDemuxerStream was
88 // created to help decrypt the encrypted stream. 93 // 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( 94 void OnDecoderSelected(
92 scoped_ptr<VideoDecoderSelector> decoder_selector, 95 scoped_ptr<VideoDecoder> decoder,
93 const scoped_refptr<VideoDecoder>& selected_decoder,
94 const scoped_refptr<DecryptingDemuxerStream>& decrypting_demuxer_stream); 96 const scoped_refptr<DecryptingDemuxerStream>& decrypting_demuxer_stream);
95 97
96 // Callback from the video decoder delivering decoded video frames and 98 // Callback from the video decoder delivering decoded video frames and
97 // reporting video decoder status. 99 // reporting video decoder status.
98 void FrameReady(VideoDecoder::Status status, 100 void FrameReady(VideoDecoder::Status status,
99 const scoped_refptr<VideoFrame>& frame); 101 const scoped_refptr<VideoFrame>& frame);
100 102
101 // Helper method for adding a frame to |ready_frames_|. 103 // Helper method for adding a frame to |ready_frames_|.
102 void AddReadyFrame_Locked(const scoped_refptr<VideoFrame>& frame); 104 void AddReadyFrame_Locked(const scoped_refptr<VideoFrame>& frame);
103 105
(...skipping 27 matching lines...) Expand all
131 void PaintNextReadyFrame_Locked(); 133 void PaintNextReadyFrame_Locked();
132 134
133 // Drops the next frame from |ready_frames_| and runs |statistics_cb_|. 135 // Drops the next frame from |ready_frames_| and runs |statistics_cb_|.
134 // 136 //
135 // A read is scheduled to replace the frame. 137 // A read is scheduled to replace the frame.
136 void DropNextReadyFrame_Locked(); 138 void DropNextReadyFrame_Locked();
137 139
138 void ResetDecoder(); 140 void ResetDecoder();
139 void StopDecoder(const base::Closure& callback); 141 void StopDecoder(const base::Closure& callback);
140 142
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(); 143 void TransitionToPrerolled_Locked();
154 144
155 scoped_refptr<base::MessageLoopProxy> message_loop_; 145 scoped_refptr<base::MessageLoopProxy> message_loop_;
156 base::WeakPtrFactory<VideoRendererBase> weak_factory_; 146 base::WeakPtrFactory<VideoRendererBase> weak_factory_;
157 base::WeakPtr<VideoRendererBase> weak_this_; 147 base::WeakPtr<VideoRendererBase> weak_this_;
158 148
149 scoped_ptr<VideoDecoderSelector> decoder_selector_;
150
159 // Used for accessing data members. 151 // Used for accessing data members.
160 base::Lock lock_; 152 base::Lock lock_;
161 153
162 SetDecryptorReadyCB set_decryptor_ready_cb_;
163
164 // These two will be set by VideoDecoderSelector::SelectVideoDecoder(). 154 // These two will be set by VideoDecoderSelector::SelectVideoDecoder().
165 scoped_refptr<VideoDecoder> decoder_; 155 scoped_ptr<VideoDecoder> decoder_;
166 scoped_refptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; 156 scoped_refptr<DecryptingDemuxerStream> decrypting_demuxer_stream_;
167 157
168 // Queue of incoming frames yet to be painted. 158 // Queue of incoming frames yet to be painted.
169 typedef std::deque<scoped_refptr<VideoFrame> > VideoFrameQueue; 159 typedef std::deque<scoped_refptr<VideoFrame> > VideoFrameQueue;
170 VideoFrameQueue ready_frames_; 160 VideoFrameQueue ready_frames_;
171 161
172 // Keeps track of whether we received the end of stream buffer. 162 // Keeps track of whether we received the end of stream buffer.
173 bool received_end_of_stream_; 163 bool received_end_of_stream_;
174 164
175 // Used to signal |thread_| as frames are added to |frames_|. Rule of thumb: 165 // Used to signal |thread_| as frames are added to |frames_|. Rule of thumb:
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // either for calling |paint_cb_| or for dropping. Set to kNoTimestamp() 253 // either for calling |paint_cb_| or for dropping. Set to kNoTimestamp()
264 // during flushing. 254 // during flushing.
265 base::TimeDelta last_timestamp_; 255 base::TimeDelta last_timestamp_;
266 256
267 DISALLOW_COPY_AND_ASSIGN(VideoRendererBase); 257 DISALLOW_COPY_AND_ASSIGN(VideoRendererBase);
268 }; 258 };
269 259
270 } // namespace media 260 } // namespace media
271 261
272 #endif // MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_ 262 #endif // MEDIA_FILTERS_VIDEO_RENDERER_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698