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

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: rebase 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
« no previous file with comments | « media/filters/video_frame_stream.h ('k') | media/filters/video_frame_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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; 116 stream_ = NULL;
129 decrypting_demuxer_stream_ = NULL;
130 decoder_.reset(); 117 decoder_.reset();
118 decrypting_demuxer_stream_.reset();
131 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&stop_cb_)); 119 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&stop_cb_));
132 } 120 }
133 121
134 bool VideoFrameStream::HasOutputFrameAvailable() const { 122 bool VideoFrameStream::HasOutputFrameAvailable() const {
135 DCHECK(message_loop_->BelongsToCurrentThread()); 123 DCHECK(message_loop_->BelongsToCurrentThread());
136 return decoder_->HasOutputFrameAvailable(); 124 return decoder_->HasOutputFrameAvailable();
137 } 125 }
138 126
139 void VideoFrameStream::Read(const ReadCB& read_cb) { 127 void VideoFrameStream::Read(const ReadCB& read_cb) {
140 DCHECK(message_loop_->BelongsToCurrentThread()); 128 DCHECK(message_loop_->BelongsToCurrentThread());
(...skipping 15 matching lines...) Expand all
156 DCHECK(message_loop_->BelongsToCurrentThread()); 144 DCHECK(message_loop_->BelongsToCurrentThread());
157 return VIDEO; 145 return VIDEO;
158 } 146 }
159 147
160 void VideoFrameStream::EnableBitstreamConverter() { 148 void VideoFrameStream::EnableBitstreamConverter() {
161 DCHECK(message_loop_->BelongsToCurrentThread()); 149 DCHECK(message_loop_->BelongsToCurrentThread());
162 stream_->EnableBitstreamConverter(); 150 stream_->EnableBitstreamConverter();
163 } 151 }
164 152
165 void VideoFrameStream::OnDecoderSelected( 153 void VideoFrameStream::OnDecoderSelected(
166 scoped_ptr<VideoDecoderSelector> decoder_selector,
167 scoped_ptr<VideoDecoder> selected_decoder, 154 scoped_ptr<VideoDecoder> selected_decoder,
168 const scoped_refptr<DecryptingDemuxerStream>& decrypting_demuxer_stream) { 155 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream) {
169 DCHECK(message_loop_->BelongsToCurrentThread()); 156 DCHECK(message_loop_->BelongsToCurrentThread());
170 DCHECK_EQ(state_, UNINITIALIZED); 157 DCHECK_EQ(state_, UNINITIALIZED);
171 DCHECK(!init_cb_.is_null()); 158 DCHECK(!init_cb_.is_null());
159 decoder_selector_.reset();
172 160
173 if (!selected_decoder) { 161 if (!selected_decoder) {
174 state_ = UNINITIALIZED; 162 state_ = UNINITIALIZED;
175 base::ResetAndReturn(&init_cb_).Run(false, false); 163 base::ResetAndReturn(&init_cb_).Run(false, false);
176 } else { 164 } else {
177 decoder_ = selected_decoder.Pass(); 165 decoder_ = selected_decoder.Pass();
178 decrypting_demuxer_stream_ = decrypting_demuxer_stream; 166 decrypting_demuxer_stream_ = decrypting_demuxer_stream.Pass();
179 state_ = NORMAL; 167 state_ = NORMAL;
180 base::ResetAndReturn(&init_cb_).Run(true, decoder_->HasAlpha()); 168 base::ResetAndReturn(&init_cb_).Run(true, decoder_->HasAlpha());
181 } 169 }
182 170
183 // Stop() called during initialization. 171 // Stop() called during initialization.
184 if (!stop_cb_.is_null()) { 172 if (!stop_cb_.is_null()) {
185 Stop(base::ResetAndReturn(&stop_cb_)); 173 Stop(base::ResetAndReturn(&stop_cb_));
186 return; 174 return;
187 } 175 }
188 } 176 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 void VideoFrameStream::OnDecoderStopped() { 214 void VideoFrameStream::OnDecoderStopped() {
227 DCHECK(message_loop_->BelongsToCurrentThread()); 215 DCHECK(message_loop_->BelongsToCurrentThread());
228 DCHECK_EQ(state_, NORMAL); 216 DCHECK_EQ(state_, NORMAL);
229 // If Stop() was called during pending read/reset, read/reset callback should 217 // If Stop() was called during pending read/reset, read/reset callback should
230 // be fired before the stop callback is fired. 218 // be fired before the stop callback is fired.
231 DCHECK(read_cb_.is_null()); 219 DCHECK(read_cb_.is_null());
232 DCHECK(reset_cb_.is_null()); 220 DCHECK(reset_cb_.is_null());
233 DCHECK(!stop_cb_.is_null()); 221 DCHECK(!stop_cb_.is_null());
234 222
235 state_ = STOPPED; 223 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; 224 stream_ = NULL;
240 decrypting_demuxer_stream_ = NULL;
241 decoder_.reset(); 225 decoder_.reset();
226 decrypting_demuxer_stream_.reset();
242 base::ResetAndReturn(&stop_cb_).Run(); 227 base::ResetAndReturn(&stop_cb_).Run();
243 } 228 }
244 229
245 } // namespace media 230 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/video_frame_stream.h ('k') | media/filters/video_frame_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698