Chromium Code Reviews| OLD | NEW |
|---|---|
| 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), |
|
acolwell GONE FROM CHROMIUM
2013/04/17 20:24:53
stream_(NULL), ?
scherkus (not reviewing)
2013/04/19 01:07:22
not needed (streams are still refcounted)
| |
| 27 decoder_selector_( | 27 decoder_selector_( |
| 28 message_loop_, decoders.Pass(), set_decryptor_ready_cb) { | 28 message_loop_, decoders.Pass(), set_decryptor_ready_cb) { |
| 29 } | 29 } |
| 30 | 30 |
| 31 VideoFrameStream::~VideoFrameStream() { | 31 VideoFrameStream::~VideoFrameStream() { |
| 32 DCHECK(state_ == UNINITIALIZED || state_ == STOPPED) << state_; | 32 DCHECK(state_ == UNINITIALIZED || state_ == STOPPED) << state_; |
| 33 } | 33 } |
| 34 | 34 |
| 35 void VideoFrameStream::Initialize(const scoped_refptr<DemuxerStream>& stream, | 35 void VideoFrameStream::Initialize(DemuxerStream* stream, |
| 36 const StatisticsCB& statistics_cb, | 36 const StatisticsCB& statistics_cb, |
| 37 const InitCB& init_cb) { | 37 const InitCB& init_cb) { |
| 38 DCHECK(message_loop_->BelongsToCurrentThread()); | 38 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 39 DCHECK_EQ(state_, UNINITIALIZED); | 39 DCHECK_EQ(state_, UNINITIALIZED); |
| 40 | 40 |
| 41 weak_this_ = weak_factory_.GetWeakPtr(); | 41 weak_this_ = weak_factory_.GetWeakPtr(); |
| 42 | 42 |
| 43 DCHECK(init_cb_.is_null()); | 43 DCHECK(init_cb_.is_null()); |
| 44 DCHECK(!init_cb.is_null()); | 44 DCHECK(!init_cb.is_null()); |
| 45 init_cb_ = init_cb; | 45 init_cb_ = init_cb; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 &VideoFrameStream::StopDecoder, weak_this_)); | 105 &VideoFrameStream::StopDecoder, weak_this_)); |
| 106 return; | 106 return; |
| 107 } | 107 } |
| 108 | 108 |
| 109 if (decoder_) { | 109 if (decoder_) { |
| 110 StopDecoder(); | 110 StopDecoder(); |
| 111 return; | 111 return; |
| 112 } | 112 } |
| 113 | 113 |
| 114 state_ = STOPPED; | 114 state_ = STOPPED; |
| 115 // Break the ref-count loop so we don't leak objects. | |
| 116 // TODO(scherkus): Make DemuxerStream and/or VideoDecoder not ref-counted so | |
| 117 // we don't need this here. See: http://crbug.com/173313 | |
| 118 stream_ = NULL; | |
| 119 decrypting_demuxer_stream_ = NULL; | |
| 120 decoder_.reset(); | 115 decoder_.reset(); |
| 116 decrypting_demuxer_stream_.reset(); | |
| 121 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&stop_cb_)); | 117 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&stop_cb_)); |
| 122 } | 118 } |
| 123 | 119 |
| 124 bool VideoFrameStream::HasOutputFrameAvailable() const { | 120 bool VideoFrameStream::HasOutputFrameAvailable() const { |
| 125 DCHECK(message_loop_->BelongsToCurrentThread()); | 121 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 126 return decoder_->HasOutputFrameAvailable(); | 122 return decoder_->HasOutputFrameAvailable(); |
| 127 } | 123 } |
| 128 | 124 |
| 129 void VideoFrameStream::Read(const ReadCB& read_cb) { | 125 void VideoFrameStream::Read(const ReadCB& read_cb) { |
| 130 DCHECK(message_loop_->BelongsToCurrentThread()); | 126 DCHECK(message_loop_->BelongsToCurrentThread()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 147 return VIDEO; | 143 return VIDEO; |
| 148 } | 144 } |
| 149 | 145 |
| 150 void VideoFrameStream::EnableBitstreamConverter() { | 146 void VideoFrameStream::EnableBitstreamConverter() { |
| 151 DCHECK(message_loop_->BelongsToCurrentThread()); | 147 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 152 stream_->EnableBitstreamConverter(); | 148 stream_->EnableBitstreamConverter(); |
| 153 } | 149 } |
| 154 | 150 |
| 155 void VideoFrameStream::OnDecoderSelected( | 151 void VideoFrameStream::OnDecoderSelected( |
| 156 scoped_ptr<VideoDecoder> selected_decoder, | 152 scoped_ptr<VideoDecoder> selected_decoder, |
| 157 const scoped_refptr<DecryptingDemuxerStream>& decrypting_demuxer_stream) { | 153 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream) { |
| 158 DCHECK(message_loop_->BelongsToCurrentThread()); | 154 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 159 DCHECK_EQ(state_, UNINITIALIZED); | 155 DCHECK_EQ(state_, UNINITIALIZED); |
| 160 DCHECK(!init_cb_.is_null()); | 156 DCHECK(!init_cb_.is_null()); |
| 161 | 157 |
| 162 if (!selected_decoder) { | 158 if (!selected_decoder) { |
| 163 state_ = UNINITIALIZED; | 159 state_ = UNINITIALIZED; |
| 164 base::ResetAndReturn(&init_cb_).Run(false, false); | 160 base::ResetAndReturn(&init_cb_).Run(false, false); |
| 165 } else { | 161 } else { |
| 166 decoder_ = selected_decoder.Pass(); | 162 decoder_ = selected_decoder.Pass(); |
| 167 decrypting_demuxer_stream_ = decrypting_demuxer_stream; | 163 decrypting_demuxer_stream_ = decrypting_demuxer_stream.Pass(); |
| 168 state_ = NORMAL; | 164 state_ = NORMAL; |
| 169 base::ResetAndReturn(&init_cb_).Run(true, decoder_->HasAlpha()); | 165 base::ResetAndReturn(&init_cb_).Run(true, decoder_->HasAlpha()); |
| 170 } | 166 } |
| 171 | 167 |
| 172 // Stop() called during initialization. | 168 // Stop() called during initialization. |
| 173 if (!stop_cb_.is_null()) { | 169 if (!stop_cb_.is_null()) { |
| 174 Stop(base::ResetAndReturn(&stop_cb_)); | 170 Stop(base::ResetAndReturn(&stop_cb_)); |
| 175 return; | 171 return; |
| 176 } | 172 } |
| 177 } | 173 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 void VideoFrameStream::OnDecoderStopped() { | 211 void VideoFrameStream::OnDecoderStopped() { |
| 216 DCHECK(message_loop_->BelongsToCurrentThread()); | 212 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 217 DCHECK_EQ(state_, NORMAL); | 213 DCHECK_EQ(state_, NORMAL); |
| 218 // If Stop() was called during pending read/reset, read/reset callback should | 214 // If Stop() was called during pending read/reset, read/reset callback should |
| 219 // be fired before the stop callback is fired. | 215 // be fired before the stop callback is fired. |
| 220 DCHECK(read_cb_.is_null()); | 216 DCHECK(read_cb_.is_null()); |
| 221 DCHECK(reset_cb_.is_null()); | 217 DCHECK(reset_cb_.is_null()); |
| 222 DCHECK(!stop_cb_.is_null()); | 218 DCHECK(!stop_cb_.is_null()); |
| 223 | 219 |
| 224 state_ = STOPPED; | 220 state_ = STOPPED; |
| 225 // Break the ref-count loop so we don't leak objects. | |
| 226 // TODO(scherkus): Make DemuxerStream and/or VideoDecoder not ref-counted so | |
| 227 // we don't need this here. See: http://crbug.com/173313 | |
| 228 stream_ = NULL; | |
|
acolwell GONE FROM CHROMIUM
2013/04/17 20:24:53
We don't still want to make stream_ == NULL?
scherkus (not reviewing)
2013/04/19 01:07:22
reverted
| |
| 229 decrypting_demuxer_stream_ = NULL; | |
| 230 decoder_.reset(); | 221 decoder_.reset(); |
| 222 decrypting_demuxer_stream_.reset(); | |
| 231 base::ResetAndReturn(&stop_cb_).Run(); | 223 base::ResetAndReturn(&stop_cb_).Run(); |
| 232 } | 224 } |
| 233 | 225 |
| 234 } // namespace media | 226 } // namespace media |
| OLD | NEW |