| 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 "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/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 DCHECK(!read_cb.is_null()); | 190 DCHECK(!read_cb.is_null()); |
| 191 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; | 191 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; |
| 192 | 192 |
| 193 // Return empty (end-of-stream) frames if decoding has finished. | 193 // Return empty (end-of-stream) frames if decoding has finished. |
| 194 if (state_ == kDecodeFinished) { | 194 if (state_ == kDecodeFinished) { |
| 195 read_cb.Run(kOk, scoped_refptr<Buffer>(new DataBuffer(0))); | 195 read_cb.Run(kOk, scoped_refptr<Buffer>(new DataBuffer(0))); |
| 196 return; | 196 return; |
| 197 } | 197 } |
| 198 | 198 |
| 199 if (!queued_audio_frames_.empty()) { | 199 if (!queued_audio_frames_.empty()) { |
| 200 if (queued_audio_frames_.front()->IsEndOfStream()) | 200 DCHECK(!queued_audio_frames_.front()->IsEndOfStream()); |
| 201 state_ = kDecodeFinished; | 201 DCHECK_GT(queued_audio_frames_.front()->GetDataSize(), 0); |
| 202 read_cb.Run(kOk, queued_audio_frames_.front()); | 202 read_cb.Run(kOk, queued_audio_frames_.front()); |
| 203 queued_audio_frames_.pop_front(); | 203 queued_audio_frames_.pop_front(); |
| 204 return; | 204 return; |
| 205 } | 205 } |
| 206 | 206 |
| 207 read_cb_ = read_cb; | 207 read_cb_ = read_cb; |
| 208 state_ = kPendingDemuxerRead; | 208 state_ = kPendingDemuxerRead; |
| 209 ReadFromDemuxerStream(); | 209 ReadFromDemuxerStream(); |
| 210 } | 210 } |
| 211 | 211 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 361 } |
| 362 | 362 |
| 363 DCHECK_EQ(status, Decryptor::kSuccess); | 363 DCHECK_EQ(status, Decryptor::kSuccess); |
| 364 queued_audio_frames_ = frames; | 364 queued_audio_frames_ = frames; |
| 365 | 365 |
| 366 scoped_refptr<Buffer> first_frame = queued_audio_frames_.front(); | 366 scoped_refptr<Buffer> first_frame = queued_audio_frames_.front(); |
| 367 queued_audio_frames_.pop_front(); | 367 queued_audio_frames_.pop_front(); |
| 368 // No frames returned in the list should be an end-of-stream (EOS) frame. | 368 // No frames returned in the list should be an end-of-stream (EOS) frame. |
| 369 // EOS frame should be returned separately as (kNeedMoreData, NULL). | 369 // EOS frame should be returned separately as (kNeedMoreData, NULL). |
| 370 DCHECK(!first_frame->IsEndOfStream()); | 370 DCHECK(!first_frame->IsEndOfStream()); |
| 371 DCHECK_GT(first_frame->GetDataSize(), 0); |
| 371 state_ = kIdle; | 372 state_ = kIdle; |
| 372 base::ResetAndReturn(&read_cb_).Run(kOk, first_frame); | 373 base::ResetAndReturn(&read_cb_).Run(kOk, first_frame); |
| 373 } | 374 } |
| 374 | 375 |
| 375 void DecryptingAudioDecoder::OnKeyAdded() { | 376 void DecryptingAudioDecoder::OnKeyAdded() { |
| 376 DCHECK(message_loop_->BelongsToCurrentThread()); | 377 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 377 | 378 |
| 378 if (state_ == kPendingDecode) { | 379 if (state_ == kPendingDecode) { |
| 379 key_added_while_pending_decode_ = true; | 380 key_added_while_pending_decode_ = true; |
| 380 return; | 381 return; |
| 381 } | 382 } |
| 382 | 383 |
| 383 if (state_ == kWaitingForKey) { | 384 if (state_ == kWaitingForKey) { |
| 384 state_ = kPendingDecode; | 385 state_ = kPendingDecode; |
| 385 DecodePendingBuffer(); | 386 DecodePendingBuffer(); |
| 386 } | 387 } |
| 387 } | 388 } |
| 388 | 389 |
| 389 void DecryptingAudioDecoder::DoReset() { | 390 void DecryptingAudioDecoder::DoReset() { |
| 390 DCHECK(init_cb_.is_null()); | 391 DCHECK(init_cb_.is_null()); |
| 391 DCHECK(read_cb_.is_null()); | 392 DCHECK(read_cb_.is_null()); |
| 392 state_ = kIdle; | 393 state_ = kIdle; |
| 393 base::ResetAndReturn(&reset_cb_).Run(); | 394 base::ResetAndReturn(&reset_cb_).Run(); |
| 394 } | 395 } |
| 395 | 396 |
| 396 } // namespace media | 397 } // namespace media |
| OLD | NEW |