| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/fake_video_decoder.h" | 5 #include "media/filters/fake_video_decoder.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "media/base/bind_to_current_loop.h" | 8 #include "media/base/bind_to_current_loop.h" |
| 9 #include "media/base/test_helpers.h" | 9 #include "media/base/test_helpers.h" |
| 10 | 10 |
| 11 namespace media { | 11 namespace media { |
| 12 | 12 |
| 13 FakeVideoDecoder::FakeVideoDecoder(const std::string& decoder_name, | 13 FakeVideoDecoder::FakeVideoDecoder(const std::string& decoder_name, |
| 14 int decoding_delay, | 14 int decoding_delay, |
| 15 int max_parallel_decoding_requests, | 15 int max_parallel_decoding_requests, |
| 16 const BytesDecodedCB& bytes_decoded_cb) | 16 const BytesDecodedCB& bytes_decoded_cb) |
| 17 : decoder_name_(decoder_name), | 17 : decoder_name_(decoder_name), |
| 18 decoding_delay_(decoding_delay), | 18 decoding_delay_(decoding_delay), |
| 19 max_parallel_decoding_requests_(max_parallel_decoding_requests), | 19 max_parallel_decoding_requests_(max_parallel_decoding_requests), |
| 20 bytes_decoded_cb_(bytes_decoded_cb), | 20 bytes_decoded_cb_(bytes_decoded_cb), |
| 21 state_(STATE_UNINITIALIZED), | 21 state_(STATE_UNINITIALIZED), |
| 22 hold_decode_(false), | 22 hold_decode_(false), |
| 23 total_bytes_decoded_(0), | 23 total_bytes_decoded_(0), |
| 24 fail_to_initialize_(false), | 24 fail_to_initialize_(false), |
| 25 weak_factory_(this) { | 25 weak_factory_(this) { |
| 26 DVLOG(1) << __func__; | 26 DVLOG(1) << decoder_name_ << ": " << __func__; |
| 27 DCHECK_GE(decoding_delay, 0); | 27 DCHECK_GE(decoding_delay, 0); |
| 28 } | 28 } |
| 29 | 29 |
| 30 FakeVideoDecoder::~FakeVideoDecoder() { | 30 FakeVideoDecoder::~FakeVideoDecoder() { |
| 31 DVLOG(1) << __func__; | 31 DVLOG(1) << decoder_name_ << ": " << __func__; |
| 32 DCHECK(thread_checker_.CalledOnValidThread()); | 32 DCHECK(thread_checker_.CalledOnValidThread()); |
| 33 | 33 |
| 34 if (state_ == STATE_UNINITIALIZED) | 34 if (state_ == STATE_UNINITIALIZED) |
| 35 return; | 35 return; |
| 36 | 36 |
| 37 if (!init_cb_.IsNull()) | 37 if (!init_cb_.IsNull()) |
| 38 SatisfyInit(); | 38 SatisfyInit(); |
| 39 if (!held_decode_callbacks_.empty()) | 39 if (!held_decode_callbacks_.empty()) |
| 40 SatisfyDecode(); | 40 SatisfyDecode(); |
| 41 if (!reset_cb_.IsNull()) | 41 if (!reset_cb_.IsNull()) |
| 42 SatisfyReset(); | 42 SatisfyReset(); |
| 43 | 43 |
| 44 decoded_frames_.clear(); | 44 decoded_frames_.clear(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void FakeVideoDecoder::EnableEncryptedConfigSupport() { | 47 void FakeVideoDecoder::EnableEncryptedConfigSupport() { |
| 48 supports_encrypted_config_ = true; | 48 supports_encrypted_config_ = true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 std::string FakeVideoDecoder::GetDisplayName() const { | 51 std::string FakeVideoDecoder::GetDisplayName() const { |
| 52 return decoder_name_; | 52 return decoder_name_; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void FakeVideoDecoder::Initialize(const VideoDecoderConfig& config, | 55 void FakeVideoDecoder::Initialize(const VideoDecoderConfig& config, |
| 56 bool low_delay, | 56 bool low_delay, |
| 57 CdmContext* cdm_context, | 57 CdmContext* cdm_context, |
| 58 const InitCB& init_cb, | 58 const InitCB& init_cb, |
| 59 const OutputCB& output_cb) { | 59 const OutputCB& output_cb) { |
| 60 DVLOG(1) << __func__; | 60 DVLOG(1) << __func__ << "(" << decoder_name_ << ")"; |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); | 61 DCHECK(thread_checker_.CalledOnValidThread()); |
| 62 DCHECK(config.IsValidConfig()); | 62 DCHECK(config.IsValidConfig()); |
| 63 DCHECK(held_decode_callbacks_.empty()) | 63 DCHECK(held_decode_callbacks_.empty()) |
| 64 << "No reinitialization during pending decode."; | 64 << "No reinitialization during pending decode."; |
| 65 DCHECK(reset_cb_.IsNull()) << "No reinitialization during pending reset."; | 65 DCHECK(reset_cb_.IsNull()) << "No reinitialization during pending reset."; |
| 66 | 66 |
| 67 current_config_ = config; | 67 current_config_ = config; |
| 68 init_cb_.SetCallback(BindToCurrentLoop(init_cb)); | 68 init_cb_.SetCallback(BindToCurrentLoop(init_cb)); |
| 69 | 69 |
| 70 // Don't need BindToCurrentLoop() because |output_cb_| is only called from | 70 // Don't need BindToCurrentLoop() because |output_cb_| is only called from |
| 71 // RunDecodeCallback() which is posted from Decode(). | 71 // RunDecodeCallback() which is posted from Decode(). |
| 72 output_cb_ = output_cb; | 72 output_cb_ = output_cb; |
| 73 | 73 |
| 74 if (!decoded_frames_.empty()) { | 74 if (!decoded_frames_.empty()) { |
| 75 DVLOG(1) << "Decoded frames dropped during reinitialization."; | 75 DVLOG(1) << "Decoded frames dropped during reinitialization."; |
| 76 decoded_frames_.clear(); | 76 decoded_frames_.clear(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 if (config.is_encrypted() && (!supports_encrypted_config_ || !cdm_context)) { | 79 if (config.is_encrypted() && (!supports_encrypted_config_ || !cdm_context)) { |
| 80 DVLOG(1) << "Encrypted config not supported."; | 80 DVLOG(1) << "Encrypted config not supported."; |
| 81 fail_to_initialize_ = true; | 81 fail_to_initialize_ = true; |
| 82 } | 82 } |
| 83 | 83 |
| 84 if (fail_to_initialize_) { | 84 if (fail_to_initialize_) { |
| 85 DVLOG(1) << decoder_name_ << ": Initialization failed."; |
| 85 state_ = STATE_ERROR; | 86 state_ = STATE_ERROR; |
| 86 init_cb_.RunOrHold(false); | 87 init_cb_.RunOrHold(false); |
| 87 } else { | 88 } else { |
| 89 DVLOG(1) << decoder_name_ << ": Initialization succeeded."; |
| 88 state_ = STATE_NORMAL; | 90 state_ = STATE_NORMAL; |
| 89 init_cb_.RunOrHold(true); | 91 init_cb_.RunOrHold(true); |
| 90 } | 92 } |
| 91 } | 93 } |
| 92 | 94 |
| 93 void FakeVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, | 95 void FakeVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 94 const DecodeCB& decode_cb) { | 96 const DecodeCB& decode_cb) { |
| 95 DCHECK(thread_checker_.CalledOnValidThread()); | 97 DCHECK(thread_checker_.CalledOnValidThread()); |
| 96 DCHECK(reset_cb_.IsNull()); | 98 DCHECK(reset_cb_.IsNull()); |
| 97 DCHECK_LE(decoded_frames_.size(), | 99 DCHECK_LE(decoded_frames_.size(), |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 268 |
| 267 void FakeVideoDecoder::DoReset() { | 269 void FakeVideoDecoder::DoReset() { |
| 268 DCHECK(thread_checker_.CalledOnValidThread()); | 270 DCHECK(thread_checker_.CalledOnValidThread()); |
| 269 DCHECK(held_decode_callbacks_.empty()); | 271 DCHECK(held_decode_callbacks_.empty()); |
| 270 DCHECK(!reset_cb_.IsNull()); | 272 DCHECK(!reset_cb_.IsNull()); |
| 271 | 273 |
| 272 reset_cb_.RunOrHold(); | 274 reset_cb_.RunOrHold(); |
| 273 } | 275 } |
| 274 | 276 |
| 275 } // namespace media | 277 } // namespace media |
| OLD | NEW |