Chromium Code Reviews| 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 #include "media/filters/decrypting_demuxer_stream.h" | 5 #include "media/filters/decrypting_demuxer_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" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 const SetDecryptorReadyCB& set_decryptor_ready_cb) | 36 const SetDecryptorReadyCB& set_decryptor_ready_cb) |
| 37 : message_loop_(message_loop), | 37 : message_loop_(message_loop), |
| 38 weak_factory_(this), | 38 weak_factory_(this), |
| 39 state_(kUninitialized), | 39 state_(kUninitialized), |
| 40 demuxer_stream_(NULL), | 40 demuxer_stream_(NULL), |
| 41 set_decryptor_ready_cb_(set_decryptor_ready_cb), | 41 set_decryptor_ready_cb_(set_decryptor_ready_cb), |
| 42 decryptor_(NULL), | 42 decryptor_(NULL), |
| 43 key_added_while_decrypt_pending_(false) { | 43 key_added_while_decrypt_pending_(false) { |
| 44 } | 44 } |
| 45 | 45 |
| 46 void DecryptingDemuxerStream::Initialize( | 46 void DecryptingDemuxerStream::Initialize(DemuxerStream* stream, |
| 47 DemuxerStream* stream, | 47 const PipelineStatusCB& status_cb) { |
| 48 const PipelineStatusCB& status_cb) { | 48 DVLOG(2) << __FUNCTION__; |
| 49 DVLOG(2) << "Initialize()"; | |
| 50 DCHECK(message_loop_->BelongsToCurrentThread()); | 49 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 51 DCHECK_EQ(state_, kUninitialized) << state_; | 50 DCHECK_EQ(state_, kUninitialized) << state_; |
| 52 | 51 |
| 53 DCHECK(!demuxer_stream_); | 52 DCHECK(!demuxer_stream_); |
| 54 weak_this_ = weak_factory_.GetWeakPtr(); | 53 weak_this_ = weak_factory_.GetWeakPtr(); |
| 55 demuxer_stream_ = stream; | 54 demuxer_stream_ = stream; |
| 56 init_cb_ = status_cb; | 55 init_cb_ = BindToCurrentLoop(status_cb); |
| 57 | 56 |
| 58 InitializeDecoderConfig(); | 57 InitializeDecoderConfig(); |
| 59 | 58 |
| 60 state_ = kDecryptorRequested; | 59 state_ = kDecryptorRequested; |
| 61 set_decryptor_ready_cb_.Run( | 60 set_decryptor_ready_cb_.Run( |
| 62 BIND_TO_LOOP(&DecryptingDemuxerStream::SetDecryptor)); | 61 BIND_TO_LOOP(&DecryptingDemuxerStream::SetDecryptor)); |
| 63 } | 62 } |
| 64 | 63 |
| 65 void DecryptingDemuxerStream::Read(const ReadCB& read_cb) { | 64 void DecryptingDemuxerStream::Read(const ReadCB& read_cb) { |
| 66 DVLOG(3) << "Read()"; | 65 DVLOG(3) << __FUNCTION__; |
| 67 DCHECK(message_loop_->BelongsToCurrentThread()); | 66 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 68 DCHECK_EQ(state_, kIdle) << state_; | 67 DCHECK_EQ(state_, kIdle) << state_; |
| 69 DCHECK(!read_cb.is_null()); | 68 DCHECK(!read_cb.is_null()); |
| 70 CHECK(read_cb_.is_null()) << "Overlapping reads are not supported."; | 69 CHECK(read_cb_.is_null()) << "Overlapping reads are not supported."; |
| 71 | 70 |
| 72 read_cb_ = read_cb; | 71 read_cb_ = BindToCurrentLoop(read_cb); |
| 73 state_ = kPendingDemuxerRead; | 72 state_ = kPendingDemuxerRead; |
| 74 demuxer_stream_->Read( | 73 demuxer_stream_->Read( |
| 75 base::Bind(&DecryptingDemuxerStream::DecryptBuffer, weak_this_)); | 74 base::Bind(&DecryptingDemuxerStream::DecryptBuffer, weak_this_)); |
| 76 } | 75 } |
| 77 | 76 |
| 78 void DecryptingDemuxerStream::Reset(const base::Closure& closure) { | 77 void DecryptingDemuxerStream::Reset(const base::Closure& closure) { |
| 79 DVLOG(2) << "Reset() - state: " << state_; | 78 DVLOG(2) << __FUNCTION__ << " - state: " << state_; |
| 80 DCHECK(message_loop_->BelongsToCurrentThread()); | 79 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 81 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; | 80 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; |
| 82 DCHECK(init_cb_.is_null()); // No Reset() during pending initialization. | 81 DCHECK(init_cb_.is_null()); // No Reset() during pending initialization. |
| 83 DCHECK(reset_cb_.is_null()); | 82 DCHECK(reset_cb_.is_null()); |
| 84 | 83 |
| 85 reset_cb_ = BindToCurrentLoop(closure); | 84 reset_cb_ = BindToCurrentLoop(closure); |
| 86 | 85 |
| 87 decryptor_->CancelDecrypt(GetDecryptorStreamType()); | 86 decryptor_->CancelDecrypt(GetDecryptorStreamType()); |
| 88 | 87 |
| 89 // Reset() cannot complete if the read callback is still pending. | 88 // Reset() cannot complete if the read callback is still pending. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 119 | 118 |
| 120 DemuxerStream::Type DecryptingDemuxerStream::type() { | 119 DemuxerStream::Type DecryptingDemuxerStream::type() { |
| 121 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; | 120 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; |
| 122 return demuxer_stream_->type(); | 121 return demuxer_stream_->type(); |
| 123 } | 122 } |
| 124 | 123 |
| 125 void DecryptingDemuxerStream::EnableBitstreamConverter() { | 124 void DecryptingDemuxerStream::EnableBitstreamConverter() { |
| 126 demuxer_stream_->EnableBitstreamConverter(); | 125 demuxer_stream_->EnableBitstreamConverter(); |
| 127 } | 126 } |
| 128 | 127 |
| 129 DecryptingDemuxerStream::~DecryptingDemuxerStream() {} | 128 DecryptingDemuxerStream::~DecryptingDemuxerStream() { |
| 129 DVLOG(2) << __FUNCTION__; | |
| 130 if (!set_decryptor_ready_cb_.is_null()) { | |
| 131 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); | |
| 132 set_decryptor_ready_cb_.Reset(); | |
|
whywhat
2013/09/17 01:00:40
Hm, so you reset the callback, then call it and re
xhwang
2013/09/17 01:13:00
Good catch. Done.
| |
| 133 } | |
| 134 } | |
| 130 | 135 |
| 131 void DecryptingDemuxerStream::SetDecryptor(Decryptor* decryptor) { | 136 void DecryptingDemuxerStream::SetDecryptor(Decryptor* decryptor) { |
| 132 DVLOG(2) << "SetDecryptor()"; | 137 DVLOG(2) << __FUNCTION__; |
| 133 DCHECK(message_loop_->BelongsToCurrentThread()); | 138 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 134 DCHECK_EQ(state_, kDecryptorRequested) << state_; | 139 DCHECK_EQ(state_, kDecryptorRequested) << state_; |
| 135 DCHECK(!init_cb_.is_null()); | 140 DCHECK(!init_cb_.is_null()); |
| 136 DCHECK(!set_decryptor_ready_cb_.is_null()); | 141 DCHECK(!set_decryptor_ready_cb_.is_null()); |
| 137 | 142 |
| 138 set_decryptor_ready_cb_.Reset(); | 143 set_decryptor_ready_cb_.Reset(); |
| 139 | 144 |
| 140 if (!decryptor) { | 145 if (!decryptor) { |
| 146 state_ = kUninitialized; | |
| 141 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); | 147 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
|
xhwang
2013/09/17 00:53:49
The caller could destroy |this| and create a new o
whywhat
2013/09/17 01:00:40
I'd at least leave a comment in the code saying th
xhwang
2013/09/17 01:13:00
I am forcing the post. See line 55 in the new code
| |
| 142 state_ = kUninitialized; | |
| 143 return; | 148 return; |
| 144 } | 149 } |
| 145 | 150 |
| 146 decryptor_ = decryptor; | 151 decryptor_ = decryptor; |
| 147 | 152 |
| 148 decryptor_->RegisterNewKeyCB( | 153 decryptor_->RegisterNewKeyCB( |
| 149 GetDecryptorStreamType(), | 154 GetDecryptorStreamType(), |
| 150 BIND_TO_LOOP(&DecryptingDemuxerStream::OnKeyAdded)); | 155 BIND_TO_LOOP(&DecryptingDemuxerStream::OnKeyAdded)); |
| 151 | 156 |
| 152 state_ = kIdle; | 157 state_ = kIdle; |
| 153 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); | 158 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
| 154 } | 159 } |
| 155 | 160 |
| 156 void DecryptingDemuxerStream::DecryptBuffer( | 161 void DecryptingDemuxerStream::DecryptBuffer( |
| 157 DemuxerStream::Status status, | 162 DemuxerStream::Status status, |
| 158 const scoped_refptr<DecoderBuffer>& buffer) { | 163 const scoped_refptr<DecoderBuffer>& buffer) { |
| 159 DVLOG(3) << "DecryptBuffer()"; | 164 DVLOG(3) << __FUNCTION__; |
| 160 DCHECK(message_loop_->BelongsToCurrentThread()); | 165 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 161 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; | 166 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; |
| 162 DCHECK(!read_cb_.is_null()); | 167 DCHECK(!read_cb_.is_null()); |
| 163 DCHECK_EQ(buffer.get() != NULL, status == kOk) << status; | 168 DCHECK_EQ(buffer.get() != NULL, status == kOk) << status; |
| 164 | 169 |
| 165 if (!reset_cb_.is_null()) { | 170 if (!reset_cb_.is_null()) { |
| 166 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 171 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
| 167 DoReset(); | 172 DoReset(); |
| 168 return; | 173 return; |
| 169 } | 174 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 DCHECK_EQ(state_, kPendingDecrypt) << state_; | 210 DCHECK_EQ(state_, kPendingDecrypt) << state_; |
| 206 decryptor_->Decrypt( | 211 decryptor_->Decrypt( |
| 207 GetDecryptorStreamType(), | 212 GetDecryptorStreamType(), |
| 208 pending_buffer_to_decrypt_, | 213 pending_buffer_to_decrypt_, |
| 209 BIND_TO_LOOP(&DecryptingDemuxerStream::DeliverBuffer)); | 214 BIND_TO_LOOP(&DecryptingDemuxerStream::DeliverBuffer)); |
| 210 } | 215 } |
| 211 | 216 |
| 212 void DecryptingDemuxerStream::DeliverBuffer( | 217 void DecryptingDemuxerStream::DeliverBuffer( |
| 213 Decryptor::Status status, | 218 Decryptor::Status status, |
| 214 const scoped_refptr<DecoderBuffer>& decrypted_buffer) { | 219 const scoped_refptr<DecoderBuffer>& decrypted_buffer) { |
| 215 DVLOG(3) << "DeliverBuffer() - status: " << status; | 220 DVLOG(3) << __FUNCTION__ << " - status: " << status; |
| 216 DCHECK(message_loop_->BelongsToCurrentThread()); | 221 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 217 DCHECK_EQ(state_, kPendingDecrypt) << state_; | 222 DCHECK_EQ(state_, kPendingDecrypt) << state_; |
| 218 DCHECK_NE(status, Decryptor::kNeedMoreData); | 223 DCHECK_NE(status, Decryptor::kNeedMoreData); |
| 219 DCHECK(!read_cb_.is_null()); | 224 DCHECK(!read_cb_.is_null()); |
| 220 DCHECK(pending_buffer_to_decrypt_.get()); | 225 DCHECK(pending_buffer_to_decrypt_.get()); |
| 221 | 226 |
| 222 bool need_to_try_again_if_nokey = key_added_while_decrypt_pending_; | 227 bool need_to_try_again_if_nokey = key_added_while_decrypt_pending_; |
| 223 key_added_while_decrypt_pending_ = false; | 228 key_added_while_decrypt_pending_ = false; |
| 224 | 229 |
| 225 if (!reset_cb_.is_null()) { | 230 if (!reset_cb_.is_null()) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 break; | 329 break; |
| 325 } | 330 } |
| 326 | 331 |
| 327 default: | 332 default: |
| 328 NOTREACHED(); | 333 NOTREACHED(); |
| 329 return; | 334 return; |
| 330 } | 335 } |
| 331 } | 336 } |
| 332 | 337 |
| 333 } // namespace media | 338 } // namespace media |
| OLD | NEW |