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_audio_decoder.h" | 5 #include "media/filters/decrypting_audio_decoder.h" | 
| 6 | 6 | 
| 7 #include <cstdlib> | 7 #include <cstdlib> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" | 
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 state_ = kPendingDemuxerRead; | 227 state_ = kPendingDemuxerRead; | 
| 228 ReadFromDemuxerStream(); | 228 ReadFromDemuxerStream(); | 
| 229 } | 229 } | 
| 230 | 230 | 
| 231 void DecryptingAudioDecoder::ReadFromDemuxerStream() { | 231 void DecryptingAudioDecoder::ReadFromDemuxerStream() { | 
| 232 DCHECK(message_loop_->BelongsToCurrentThread()); | 232 DCHECK(message_loop_->BelongsToCurrentThread()); | 
| 233 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; | 233 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; | 
| 234 DCHECK(!read_cb_.is_null()); | 234 DCHECK(!read_cb_.is_null()); | 
| 235 | 235 | 
| 236 demuxer_stream_->Read( | 236 demuxer_stream_->Read( | 
| 237 base::Bind(&DecryptingAudioDecoder::DecryptAndDecodeBuffer, this)); | 237 base::Bind(&DecryptingAudioDecoder::DoDecryptAndDecodeBuffer, this)); | 
| 238 } | |
| 239 | |
| 240 void DecryptingAudioDecoder::DecryptAndDecodeBuffer( | |
| 241 DemuxerStream::Status status, | |
| 242 const scoped_refptr<DecoderBuffer>& buffer) { | |
| 243 // In theory, we don't need to force post the task here, because we do a | |
| 
 
scherkus (not reviewing)
2012/11/19 19:11:16
xhwang: let me know if you want to keep this (alth
 
xhwang
2012/11/20 17:54:34
Nop, I don't see a reason to keep it now :) Thanks
 
 | |
| 244 // force task post in DeliverFrame(). Therefore, even if | |
| 245 // demuxer_stream_->Read() execute the read callback on the same execution | |
| 246 // stack we are still fine. But it looks like a force post task makes the | |
| 247 // logic more understandable and manageable, so why not? | |
| 248 message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 249 &DecryptingAudioDecoder::DoDecryptAndDecodeBuffer, this, status, buffer)); | |
| 250 } | 238 } | 
| 251 | 239 | 
| 252 void DecryptingAudioDecoder::DoDecryptAndDecodeBuffer( | 240 void DecryptingAudioDecoder::DoDecryptAndDecodeBuffer( | 
| 253 DemuxerStream::Status status, | 241 DemuxerStream::Status status, | 
| 254 const scoped_refptr<DecoderBuffer>& buffer) { | 242 const scoped_refptr<DecoderBuffer>& buffer) { | 
| 243 if (!message_loop_->BelongsToCurrentThread()) { | |
| 244 message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 245 &DecryptingAudioDecoder::DoDecryptAndDecodeBuffer, this, | |
| 246 status, buffer)); | |
| 247 return; | |
| 248 } | |
| 249 | |
| 255 DVLOG(3) << "DoDecryptAndDecodeBuffer()"; | 250 DVLOG(3) << "DoDecryptAndDecodeBuffer()"; | 
| 256 DCHECK(message_loop_->BelongsToCurrentThread()); | |
| 257 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; | 251 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; | 
| 258 DCHECK(!read_cb_.is_null()); | 252 DCHECK(!read_cb_.is_null()); | 
| 259 DCHECK_EQ(buffer != NULL, status == DemuxerStream::kOk) << status; | 253 DCHECK_EQ(buffer != NULL, status == DemuxerStream::kOk) << status; | 
| 260 | 254 | 
| 261 if (!reset_cb_.is_null()) { | 255 if (!reset_cb_.is_null()) { | 
| 262 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 256 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 
| 263 DoReset(); | 257 DoReset(); | 
| 264 return; | 258 return; | 
| 265 } | 259 } | 
| 266 | 260 | 
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 | 450 | 
| 457 base::TimeDelta DecryptingAudioDecoder::NumberOfSamplesToDuration( | 451 base::TimeDelta DecryptingAudioDecoder::NumberOfSamplesToDuration( | 
| 458 int number_of_samples) const { | 452 int number_of_samples) const { | 
| 459 DCHECK(samples_per_second_); | 453 DCHECK(samples_per_second_); | 
| 460 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * | 454 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond * | 
| 461 number_of_samples / | 455 number_of_samples / | 
| 462 samples_per_second_); | 456 samples_per_second_); | 
| 463 } | 457 } | 
| 464 | 458 | 
| 465 } // namespace media | 459 } // namespace media | 
| OLD | NEW |