| 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 16 matching lines...) Expand all Loading... |
| 27 // Out of sync of 100ms would be pretty noticeable and we should keep any | 27 // Out of sync of 100ms would be pretty noticeable and we should keep any |
| 28 // drift below that. | 28 // drift below that. |
| 29 const int64 kOutOfSyncThresholdInMilliseconds = 100; | 29 const int64 kOutOfSyncThresholdInMilliseconds = 100; |
| 30 return std::abs(timestamp_1.InMilliseconds() - timestamp_2.InMilliseconds()) > | 30 return std::abs(timestamp_1.InMilliseconds() - timestamp_2.InMilliseconds()) > |
| 31 kOutOfSyncThresholdInMilliseconds; | 31 kOutOfSyncThresholdInMilliseconds; |
| 32 } | 32 } |
| 33 | 33 |
| 34 DecryptingAudioDecoder::DecryptingAudioDecoder( | 34 DecryptingAudioDecoder::DecryptingAudioDecoder( |
| 35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 36 const scoped_refptr<MediaLog>& media_log, | 36 const scoped_refptr<MediaLog>& media_log, |
| 37 const SetCdmReadyCB& set_cdm_ready_cb, |
| 37 const base::Closure& waiting_for_decryption_key_cb) | 38 const base::Closure& waiting_for_decryption_key_cb) |
| 38 : task_runner_(task_runner), | 39 : task_runner_(task_runner), |
| 39 media_log_(media_log), | 40 media_log_(media_log), |
| 40 state_(kUninitialized), | 41 state_(kUninitialized), |
| 41 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb), | 42 waiting_for_decryption_key_cb_(waiting_for_decryption_key_cb), |
| 43 set_cdm_ready_cb_(set_cdm_ready_cb), |
| 42 decryptor_(NULL), | 44 decryptor_(NULL), |
| 43 key_added_while_decode_pending_(false), | 45 key_added_while_decode_pending_(false), |
| 44 weak_factory_(this) {} | 46 weak_factory_(this) {} |
| 45 | 47 |
| 46 std::string DecryptingAudioDecoder::GetDisplayName() const { | 48 std::string DecryptingAudioDecoder::GetDisplayName() const { |
| 47 return "DecryptingAudioDecoder"; | 49 return "DecryptingAudioDecoder"; |
| 48 } | 50 } |
| 49 | 51 |
| 50 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config, | 52 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config, |
| 51 const SetCdmReadyCB& set_cdm_ready_cb, | |
| 52 const InitCB& init_cb, | 53 const InitCB& init_cb, |
| 53 const OutputCB& output_cb) { | 54 const OutputCB& output_cb) { |
| 54 DVLOG(2) << "Initialize()"; | 55 DVLOG(2) << "Initialize()"; |
| 55 DCHECK(task_runner_->BelongsToCurrentThread()); | 56 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 56 DCHECK(decode_cb_.is_null()); | 57 DCHECK(decode_cb_.is_null()); |
| 57 DCHECK(reset_cb_.is_null()); | 58 DCHECK(reset_cb_.is_null()); |
| 58 | 59 |
| 59 weak_this_ = weak_factory_.GetWeakPtr(); | 60 weak_this_ = weak_factory_.GetWeakPtr(); |
| 60 init_cb_ = BindToCurrentLoop(init_cb); | 61 init_cb_ = BindToCurrentLoop(init_cb); |
| 61 output_cb_ = BindToCurrentLoop(output_cb); | 62 output_cb_ = BindToCurrentLoop(output_cb); |
| 62 | 63 |
| 63 if (!config.IsValidConfig()) { | 64 if (!config.IsValidConfig()) { |
| 64 DLOG(ERROR) << "Invalid audio stream config."; | 65 DLOG(ERROR) << "Invalid audio stream config."; |
| 65 base::ResetAndReturn(&init_cb_).Run(false); | 66 base::ResetAndReturn(&init_cb_).Run(false); |
| 66 return; | 67 return; |
| 67 } | 68 } |
| 68 | 69 |
| 69 // DecryptingAudioDecoder only accepts potentially encrypted stream. | 70 // DecryptingAudioDecoder only accepts potentially encrypted stream. |
| 70 if (!config.is_encrypted()) { | 71 if (!config.is_encrypted()) { |
| 71 base::ResetAndReturn(&init_cb_).Run(false); | 72 base::ResetAndReturn(&init_cb_).Run(false); |
| 72 return; | 73 return; |
| 73 } | 74 } |
| 74 | 75 |
| 75 config_ = config; | 76 config_ = config; |
| 76 | 77 |
| 77 if (state_ == kUninitialized) { | 78 if (state_ == kUninitialized) { |
| 78 DCHECK(!set_cdm_ready_cb.is_null()); | |
| 79 state_ = kDecryptorRequested; | 79 state_ = kDecryptorRequested; |
| 80 set_cdm_ready_cb_ = set_cdm_ready_cb; | |
| 81 set_cdm_ready_cb_.Run(BindToCurrentLoop( | 80 set_cdm_ready_cb_.Run(BindToCurrentLoop( |
| 82 base::Bind(&DecryptingAudioDecoder::SetCdm, weak_this_))); | 81 base::Bind(&DecryptingAudioDecoder::SetCdm, weak_this_))); |
| 83 return; | 82 return; |
| 84 } | 83 } |
| 85 | 84 |
| 86 // Reinitialization (i.e. upon a config change) | 85 // Reinitialization (i.e. upon a config change) |
| 87 decryptor_->DeinitializeDecoder(Decryptor::kAudio); | 86 decryptor_->DeinitializeDecoder(Decryptor::kAudio); |
| 88 InitializeDecoder(); | 87 InitializeDecoder(); |
| 89 } | 88 } |
| 90 | 89 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 } | 365 } |
| 367 | 366 |
| 368 frame->set_timestamp(current_time); | 367 frame->set_timestamp(current_time); |
| 369 timestamp_helper_->AddFrames(frame->frame_count()); | 368 timestamp_helper_->AddFrames(frame->frame_count()); |
| 370 | 369 |
| 371 output_cb_.Run(frame); | 370 output_cb_.Run(frame); |
| 372 } | 371 } |
| 373 } | 372 } |
| 374 | 373 |
| 375 } // namespace media | 374 } // namespace media |
| OLD | NEW |