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

Side by Side Diff: media/filters/video_frame_stream.cc

Issue 14217008: Remove reference counting from media::DemuxerStream and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "media/filters/video_frame_stream.h" 5 #include "media/filters/video_frame_stream.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "media/base/bind_to_loop.h" 12 #include "media/base/bind_to_loop.h"
13 #include "media/base/demuxer_stream.h" 13 #include "media/base/demuxer_stream.h"
14 #include "media/base/video_decoder_config.h" 14 #include "media/base/video_decoder_config.h"
15 #include "media/filters/decrypting_demuxer_stream.h" 15 #include "media/filters/decrypting_demuxer_stream.h"
16 #include "media/filters/video_decoder_selector.h" 16 #include "media/filters/video_decoder_selector.h"
17 17
18 namespace media { 18 namespace media {
19 19
20 VideoFrameStream::VideoFrameStream( 20 VideoFrameStream::VideoFrameStream(
21 const scoped_refptr<base::MessageLoopProxy>& message_loop, 21 const scoped_refptr<base::MessageLoopProxy>& message_loop,
22 ScopedVector<VideoDecoder> decoders, 22 ScopedVector<VideoDecoder> decoders,
23 const SetDecryptorReadyCB& set_decryptor_ready_cb) 23 const SetDecryptorReadyCB& set_decryptor_ready_cb)
24 : message_loop_(message_loop), 24 : message_loop_(message_loop),
25 weak_factory_(this), 25 weak_factory_(this),
26 state_(UNINITIALIZED), 26 state_(UNINITIALIZED),
27 decoders_(decoders.Pass()), 27 stream_(NULL),
28 set_decryptor_ready_cb_(set_decryptor_ready_cb) { 28 decoder_selector_(new VideoDecoderSelector(
29 message_loop, decoders.Pass(), set_decryptor_ready_cb)) {
29 } 30 }
30 31
31 VideoFrameStream::~VideoFrameStream() { 32 VideoFrameStream::~VideoFrameStream() {
32 DCHECK(state_ == UNINITIALIZED || state_ == STOPPED) << state_; 33 DCHECK(state_ == UNINITIALIZED || state_ == STOPPED) << state_;
33 } 34 }
34 35
35 void VideoFrameStream::Initialize(const scoped_refptr<DemuxerStream>& stream, 36 void VideoFrameStream::Initialize(DemuxerStream* stream,
36 const StatisticsCB& statistics_cb, 37 const StatisticsCB& statistics_cb,
37 const InitCB& init_cb) { 38 const InitCB& init_cb) {
38 DCHECK(message_loop_->BelongsToCurrentThread()); 39 DCHECK(message_loop_->BelongsToCurrentThread());
39 DCHECK_EQ(state_, UNINITIALIZED); 40 DCHECK_EQ(state_, UNINITIALIZED);
40 41
41 weak_this_ = weak_factory_.GetWeakPtr(); 42 weak_this_ = weak_factory_.GetWeakPtr();
42 43
43 DCHECK(init_cb_.is_null()); 44 DCHECK(init_cb_.is_null());
44 DCHECK(!init_cb.is_null()); 45 DCHECK(!init_cb.is_null());
45 init_cb_ = init_cb; 46 init_cb_ = init_cb;
46 stream_ = stream; 47 stream_ = stream;
47 48
48 // TODO(scherkus): Make |decoder_selector| a member variable after 49 decoder_selector_->SelectVideoDecoder(this, statistics_cb, base::Bind(
49 // DemuxerStream is no longer refcounted. Today we're forced to do this 50 &VideoFrameStream::OnDecoderSelected, weak_this_));
50 // because it creates a refcount loop between |this| and |decoder_selector|.
51 scoped_ptr<VideoDecoderSelector> decoder_selector(new VideoDecoderSelector(
52 message_loop_, decoders_.Pass(), set_decryptor_ready_cb_));
53 set_decryptor_ready_cb_.Reset();
54
55 VideoDecoderSelector* decoder_selector_ptr = decoder_selector.get();
56
57 decoder_selector_ptr->SelectVideoDecoder(this, statistics_cb, base::Bind(
58 &VideoFrameStream::OnDecoderSelected, weak_this_,
59 base::Passed(&decoder_selector)));
60 } 51 }
61 52
62 void VideoFrameStream::ReadFrame(const VideoDecoder::ReadCB& read_cb) { 53 void VideoFrameStream::ReadFrame(const VideoDecoder::ReadCB& read_cb) {
63 DCHECK(message_loop_->BelongsToCurrentThread()); 54 DCHECK(message_loop_->BelongsToCurrentThread());
64 DCHECK_EQ(state_, NORMAL); 55 DCHECK_EQ(state_, NORMAL);
65 // No two reads in the flight at any time. 56 // No two reads in the flight at any time.
66 DCHECK(read_cb_.is_null()); 57 DCHECK(read_cb_.is_null());
67 // No read during resetting or stopping process. 58 // No read during resetting or stopping process.
68 DCHECK(reset_cb_.is_null()); 59 DCHECK(reset_cb_.is_null());
69 DCHECK(stop_cb_.is_null()); 60 DCHECK(stop_cb_.is_null());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 &VideoFrameStream::StopDecoder, weak_this_)); 106 &VideoFrameStream::StopDecoder, weak_this_));
116 return; 107 return;
117 } 108 }
118 109
119 if (decoder_) { 110 if (decoder_) {
120 StopDecoder(); 111 StopDecoder();
121 return; 112 return;
122 } 113 }
123 114
124 state_ = STOPPED; 115 state_ = STOPPED;
125 // Break the ref-count loop so we don't leak objects.
126 // TODO(scherkus): Make DemuxerStream and/or VideoDecoder not ref-counted so
127 // we don't need this here. See: http://crbug.com/173313
128 stream_ = NULL;
acolwell GONE FROM CHROMIUM 2013/04/23 03:20:42 nit: Any harm in keeping this?
scherkus (not reviewing) 2013/04/23 18:43:40 Done.
129 decrypting_demuxer_stream_ = NULL;
130 decoder_.reset(); 116 decoder_.reset();
117 decrypting_demuxer_stream_.reset();
131 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&stop_cb_)); 118 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&stop_cb_));
132 } 119 }
133 120
134 bool VideoFrameStream::HasOutputFrameAvailable() const { 121 bool VideoFrameStream::HasOutputFrameAvailable() const {
135 DCHECK(message_loop_->BelongsToCurrentThread()); 122 DCHECK(message_loop_->BelongsToCurrentThread());
136 return decoder_->HasOutputFrameAvailable(); 123 return decoder_->HasOutputFrameAvailable();
137 } 124 }
138 125
139 void VideoFrameStream::Read(const ReadCB& read_cb) { 126 void VideoFrameStream::Read(const ReadCB& read_cb) {
140 DCHECK(message_loop_->BelongsToCurrentThread()); 127 DCHECK(message_loop_->BelongsToCurrentThread());
(...skipping 15 matching lines...) Expand all
156 DCHECK(message_loop_->BelongsToCurrentThread()); 143 DCHECK(message_loop_->BelongsToCurrentThread());
157 return VIDEO; 144 return VIDEO;
158 } 145 }
159 146
160 void VideoFrameStream::EnableBitstreamConverter() { 147 void VideoFrameStream::EnableBitstreamConverter() {
161 DCHECK(message_loop_->BelongsToCurrentThread()); 148 DCHECK(message_loop_->BelongsToCurrentThread());
162 stream_->EnableBitstreamConverter(); 149 stream_->EnableBitstreamConverter();
163 } 150 }
164 151
165 void VideoFrameStream::OnDecoderSelected( 152 void VideoFrameStream::OnDecoderSelected(
166 scoped_ptr<VideoDecoderSelector> decoder_selector,
167 scoped_ptr<VideoDecoder> selected_decoder, 153 scoped_ptr<VideoDecoder> selected_decoder,
168 const scoped_refptr<DecryptingDemuxerStream>& decrypting_demuxer_stream) { 154 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream) {
169 DCHECK(message_loop_->BelongsToCurrentThread()); 155 DCHECK(message_loop_->BelongsToCurrentThread());
170 DCHECK_EQ(state_, UNINITIALIZED); 156 DCHECK_EQ(state_, UNINITIALIZED);
171 DCHECK(!init_cb_.is_null()); 157 DCHECK(!init_cb_.is_null());
158 decoder_selector_.reset();
172 159
173 if (!selected_decoder) { 160 if (!selected_decoder) {
174 state_ = UNINITIALIZED; 161 state_ = UNINITIALIZED;
175 base::ResetAndReturn(&init_cb_).Run(false, false); 162 base::ResetAndReturn(&init_cb_).Run(false, false);
176 } else { 163 } else {
177 decoder_ = selected_decoder.Pass(); 164 decoder_ = selected_decoder.Pass();
178 decrypting_demuxer_stream_ = decrypting_demuxer_stream; 165 decrypting_demuxer_stream_ = decrypting_demuxer_stream.Pass();
179 state_ = NORMAL; 166 state_ = NORMAL;
180 base::ResetAndReturn(&init_cb_).Run(true, decoder_->HasAlpha()); 167 base::ResetAndReturn(&init_cb_).Run(true, decoder_->HasAlpha());
181 } 168 }
182 169
183 // Stop() called during initialization. 170 // Stop() called during initialization.
184 if (!stop_cb_.is_null()) { 171 if (!stop_cb_.is_null()) {
185 Stop(base::ResetAndReturn(&stop_cb_)); 172 Stop(base::ResetAndReturn(&stop_cb_));
186 return; 173 return;
187 } 174 }
188 } 175 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 void VideoFrameStream::OnDecoderStopped() { 213 void VideoFrameStream::OnDecoderStopped() {
227 DCHECK(message_loop_->BelongsToCurrentThread()); 214 DCHECK(message_loop_->BelongsToCurrentThread());
228 DCHECK_EQ(state_, NORMAL); 215 DCHECK_EQ(state_, NORMAL);
229 // If Stop() was called during pending read/reset, read/reset callback should 216 // If Stop() was called during pending read/reset, read/reset callback should
230 // be fired before the stop callback is fired. 217 // be fired before the stop callback is fired.
231 DCHECK(read_cb_.is_null()); 218 DCHECK(read_cb_.is_null());
232 DCHECK(reset_cb_.is_null()); 219 DCHECK(reset_cb_.is_null());
233 DCHECK(!stop_cb_.is_null()); 220 DCHECK(!stop_cb_.is_null());
234 221
235 state_ = STOPPED; 222 state_ = STOPPED;
236 // Break the ref-count loop so we don't leak objects.
237 // TODO(scherkus): Make DemuxerStream and/or VideoDecoder not ref-counted so
238 // we don't need this here. See: http://crbug.com/173313
239 stream_ = NULL;
acolwell GONE FROM CHROMIUM 2013/04/23 03:20:42 nit:ditto
scherkus (not reviewing) 2013/04/23 18:43:40 Done.
240 decrypting_demuxer_stream_ = NULL;
241 decoder_.reset(); 223 decoder_.reset();
224 decrypting_demuxer_stream_.reset();
242 base::ResetAndReturn(&stop_cb_).Run(); 225 base::ResetAndReturn(&stop_cb_).Run();
243 } 226 }
244 227
245 } // namespace media 228 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698