| 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_video_decoder.h" | 5 #include "media/filters/decrypting_video_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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" |
| 11 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 12 #include "media/base/bind_to_loop.h" | 13 #include "media/base/bind_to_loop.h" |
| 13 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
| 14 #include "media/base/decryptor.h" | 15 #include "media/base/decryptor.h" |
| 15 #include "media/base/demuxer_stream.h" | 16 #include "media/base/demuxer_stream.h" |
| 16 #include "media/base/pipeline.h" | 17 #include "media/base/pipeline.h" |
| 17 #include "media/base/video_decoder_config.h" | 18 #include "media/base/video_decoder_config.h" |
| 18 #include "media/base/video_frame.h" | 19 #include "media/base/video_frame.h" |
| 19 | 20 |
| 20 namespace media { | 21 namespace media { |
| 21 | 22 |
| 22 #define BIND_TO_LOOP(function) \ | 23 #define BIND_TO_LOOP(function) \ |
| 23 media::BindToLoop(message_loop_, base::Bind(function, this)) | 24 media::BindToLoop(message_loop_, base::Bind(function, this)) |
| 24 | 25 |
| 25 DecryptingVideoDecoder::DecryptingVideoDecoder( | 26 DecryptingVideoDecoder::DecryptingVideoDecoder( |
| 26 const MessageLoopFactoryCB& message_loop_factory_cb, | 27 const MessageLoopFactoryCB& message_loop_factory_cb, |
| 27 const RequestDecryptorNotificationCB& request_decryptor_notification_cb) | 28 const RequestDecryptorNotificationCB& request_decryptor_notification_cb) |
| 28 : message_loop_factory_cb_(message_loop_factory_cb), | 29 : message_loop_factory_cb_(message_loop_factory_cb), |
| 29 state_(kUninitialized), | 30 state_(kUninitialized), |
| 30 request_decryptor_notification_cb_(request_decryptor_notification_cb), | 31 request_decryptor_notification_cb_(request_decryptor_notification_cb), |
| 31 decryptor_(NULL), | 32 decryptor_(NULL), |
| 32 key_added_while_pending_decode_(false), | 33 key_added_while_decode_pending_(false), |
| 33 trace_id_(0) { | 34 trace_id_(0) { |
| 34 } | 35 } |
| 35 | 36 |
| 36 void DecryptingVideoDecoder::Initialize( | 37 void DecryptingVideoDecoder::Initialize( |
| 37 const scoped_refptr<DemuxerStream>& stream, | 38 const scoped_refptr<DemuxerStream>& stream, |
| 38 const PipelineStatusCB& status_cb, | 39 const PipelineStatusCB& status_cb, |
| 39 const StatisticsCB& statistics_cb) { | 40 const StatisticsCB& statistics_cb) { |
| 40 DCHECK(!message_loop_); | 41 DCHECK(!message_loop_); |
| 41 message_loop_ = base::ResetAndReturn(&message_loop_factory_cb_).Run(); | 42 message_loop_ = base::ResetAndReturn(&message_loop_factory_cb_).Run(); |
| 42 message_loop_->PostTask(FROM_HERE, base::Bind( | 43 message_loop_->PostTask(FROM_HERE, base::Bind( |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 TRACE_EVENT_ASYNC_END0( | 326 TRACE_EVENT_ASYNC_END0( |
| 326 "eme", "DecryptingVideoDecoder::DecodePendingBuffer", trace_id_); | 327 "eme", "DecryptingVideoDecoder::DecodePendingBuffer", trace_id_); |
| 327 | 328 |
| 328 if (state_ == kStopped) | 329 if (state_ == kStopped) |
| 329 return; | 330 return; |
| 330 | 331 |
| 331 DCHECK_EQ(state_, kPendingDecode) << state_; | 332 DCHECK_EQ(state_, kPendingDecode) << state_; |
| 332 DCHECK(!read_cb_.is_null()); | 333 DCHECK(!read_cb_.is_null()); |
| 333 DCHECK(pending_buffer_to_decode_); | 334 DCHECK(pending_buffer_to_decode_); |
| 334 | 335 |
| 335 bool need_to_try_again_if_nokey_is_returned = key_added_while_pending_decode_; | 336 bool need_to_try_again_if_nokey_is_returned = key_added_while_decode_pending_; |
| 336 key_added_while_pending_decode_ = false; | 337 key_added_while_decode_pending_ = false; |
| 337 | 338 |
| 338 scoped_refptr<DecoderBuffer> scoped_pending_buffer_to_decode = | 339 scoped_refptr<DecoderBuffer> scoped_pending_buffer_to_decode = |
| 339 pending_buffer_to_decode_; | 340 pending_buffer_to_decode_; |
| 340 pending_buffer_to_decode_ = NULL; | 341 pending_buffer_to_decode_ = NULL; |
| 341 | 342 |
| 342 if (!reset_cb_.is_null()) { | 343 if (!reset_cb_.is_null()) { |
| 343 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); | 344 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); |
| 344 DoReset(); | 345 DoReset(); |
| 345 return; | 346 return; |
| 346 } | 347 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 DCHECK(!frame->IsEndOfStream()); | 397 DCHECK(!frame->IsEndOfStream()); |
| 397 state_ = kIdle; | 398 state_ = kIdle; |
| 398 base::ResetAndReturn(&read_cb_).Run(kOk, frame); | 399 base::ResetAndReturn(&read_cb_).Run(kOk, frame); |
| 399 } | 400 } |
| 400 | 401 |
| 401 void DecryptingVideoDecoder::OnKeyAdded() { | 402 void DecryptingVideoDecoder::OnKeyAdded() { |
| 402 DVLOG(2) << "OnKeyAdded()"; | 403 DVLOG(2) << "OnKeyAdded()"; |
| 403 DCHECK(message_loop_->BelongsToCurrentThread()); | 404 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 404 | 405 |
| 405 if (state_ == kPendingDecode) { | 406 if (state_ == kPendingDecode) { |
| 406 key_added_while_pending_decode_ = true; | 407 key_added_while_decode_pending_ = true; |
| 407 return; | 408 return; |
| 408 } | 409 } |
| 409 | 410 |
| 410 if (state_ == kWaitingForKey) { | 411 if (state_ == kWaitingForKey) { |
| 411 state_ = kPendingDecode; | 412 state_ = kPendingDecode; |
| 412 DecodePendingBuffer(); | 413 DecodePendingBuffer(); |
| 413 } | 414 } |
| 414 } | 415 } |
| 415 | 416 |
| 416 void DecryptingVideoDecoder::DoReset() { | 417 void DecryptingVideoDecoder::DoReset() { |
| 417 DCHECK(init_cb_.is_null()); | 418 DCHECK(init_cb_.is_null()); |
| 418 DCHECK(read_cb_.is_null()); | 419 DCHECK(read_cb_.is_null()); |
| 419 state_ = kIdle; | 420 state_ = kIdle; |
| 420 base::ResetAndReturn(&reset_cb_).Run(); | 421 base::ResetAndReturn(&reset_cb_).Run(); |
| 421 } | 422 } |
| 422 | 423 |
| 423 } // namespace media | 424 } // namespace media |
| OLD | NEW |