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 28 matching lines...) Expand all Loading... |
39 state_(kUninitialized), | 39 state_(kUninitialized), |
40 set_decryptor_ready_cb_(set_decryptor_ready_cb), | 40 set_decryptor_ready_cb_(set_decryptor_ready_cb), |
41 decryptor_(NULL), | 41 decryptor_(NULL), |
42 key_added_while_decode_pending_(false), | 42 key_added_while_decode_pending_(false), |
43 weak_factory_(this) {} | 43 weak_factory_(this) {} |
44 | 44 |
45 std::string DecryptingAudioDecoder::GetDisplayName() const { | 45 std::string DecryptingAudioDecoder::GetDisplayName() const { |
46 return "DecryptingAudioDecoder"; | 46 return "DecryptingAudioDecoder"; |
47 } | 47 } |
48 | 48 |
49 void DecryptingAudioDecoder::Initialize(const AudioDecoderConfig& config, | 49 void DecryptingAudioDecoder::Initialize( |
50 const PipelineStatusCB& status_cb, | 50 const AudioDecoderConfig& config, |
51 const OutputCB& output_cb) { | 51 const PipelineStatusCB& status_cb, |
| 52 const OutputCB& output_cb, |
| 53 const base::Closure& waiting_for_encryption_key_cb) { |
52 DVLOG(2) << "Initialize()"; | 54 DVLOG(2) << "Initialize()"; |
53 DCHECK(task_runner_->BelongsToCurrentThread()); | 55 DCHECK(task_runner_->BelongsToCurrentThread()); |
54 DCHECK(decode_cb_.is_null()); | 56 DCHECK(decode_cb_.is_null()); |
55 DCHECK(reset_cb_.is_null()); | 57 DCHECK(reset_cb_.is_null()); |
56 | 58 |
57 weak_this_ = weak_factory_.GetWeakPtr(); | 59 weak_this_ = weak_factory_.GetWeakPtr(); |
58 init_cb_ = BindToCurrentLoop(status_cb); | 60 init_cb_ = BindToCurrentLoop(status_cb); |
59 output_cb_ = BindToCurrentLoop(output_cb); | 61 output_cb_ = BindToCurrentLoop(output_cb); |
| 62 waiting_for_encryption_key_cb_ = waiting_for_encryption_key_cb; |
60 | 63 |
61 if (!config.IsValidConfig()) { | 64 if (!config.IsValidConfig()) { |
62 DLOG(ERROR) << "Invalid audio stream config."; | 65 DLOG(ERROR) << "Invalid audio stream config."; |
63 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_DECODE); | 66 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_DECODE); |
64 return; | 67 return; |
65 } | 68 } |
66 | 69 |
67 // DecryptingAudioDecoder only accepts potentially encrypted stream. | 70 // DecryptingAudioDecoder only accepts potentially encrypted stream. |
68 if (!config.is_encrypted()) { | 71 if (!config.is_encrypted()) { |
69 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); | 72 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 // pending buffer again when new key is added to the decryptor. | 284 // pending buffer again when new key is added to the decryptor. |
282 pending_buffer_to_decode_ = scoped_pending_buffer_to_decode; | 285 pending_buffer_to_decode_ = scoped_pending_buffer_to_decode; |
283 | 286 |
284 if (need_to_try_again_if_nokey_is_returned) { | 287 if (need_to_try_again_if_nokey_is_returned) { |
285 // The |state_| is still kPendingDecode. | 288 // The |state_| is still kPendingDecode. |
286 DecodePendingBuffer(); | 289 DecodePendingBuffer(); |
287 return; | 290 return; |
288 } | 291 } |
289 | 292 |
290 state_ = kWaitingForKey; | 293 state_ = kWaitingForKey; |
| 294 waiting_for_encryption_key_cb_.Run(); |
291 return; | 295 return; |
292 } | 296 } |
293 | 297 |
294 if (status == Decryptor::kNeedMoreData) { | 298 if (status == Decryptor::kNeedMoreData) { |
295 DVLOG(2) << "DeliverFrame() - kNeedMoreData"; | 299 DVLOG(2) << "DeliverFrame() - kNeedMoreData"; |
296 state_ = scoped_pending_buffer_to_decode->end_of_stream() ? kDecodeFinished | 300 state_ = scoped_pending_buffer_to_decode->end_of_stream() ? kDecodeFinished |
297 : kIdle; | 301 : kIdle; |
298 base::ResetAndReturn(&decode_cb_).Run(kOk); | 302 base::ResetAndReturn(&decode_cb_).Run(kOk); |
299 return; | 303 return; |
300 } | 304 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } | 360 } |
357 | 361 |
358 frame->set_timestamp(current_time); | 362 frame->set_timestamp(current_time); |
359 timestamp_helper_->AddFrames(frame->frame_count()); | 363 timestamp_helper_->AddFrames(frame->frame_count()); |
360 | 364 |
361 output_cb_.Run(frame); | 365 output_cb_.Run(frame); |
362 } | 366 } |
363 } | 367 } |
364 | 368 |
365 } // namespace media | 369 } // namespace media |
OLD | NEW |