| 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/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/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| 11 #include "media/base/bind_to_current_loop.h" | 11 #include "media/base/bind_to_current_loop.h" |
| 12 #include "media/base/test_helpers.h" | 12 #include "media/base/test_helpers.h" |
| 13 | 13 |
| 14 namespace media { | 14 namespace media { |
| 15 | 15 |
| 16 FakeVideoDecoder::FakeVideoDecoder(int decoding_delay, | 16 FakeVideoDecoder::FakeVideoDecoder(int decoding_delay, |
| 17 int max_parallel_decoding_requests) | 17 int max_parallel_decoding_requests) |
| 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 state_(STATE_UNINITIALIZED), | 20 state_(STATE_UNINITIALIZED), |
| 21 hold_decode_(false), | 21 hold_decode_(false), |
| 22 total_bytes_decoded_(0), | 22 total_bytes_decoded_(0), |
| 23 weak_factory_(this) { | 23 weak_factory_(this) { |
| 24 DCHECK_GE(decoding_delay, 0); | 24 DCHECK_GE(decoding_delay, 0); |
| 25 } | 25 } |
| 26 | 26 |
| 27 FakeVideoDecoder::~FakeVideoDecoder() { | 27 FakeVideoDecoder::~FakeVideoDecoder() { |
| 28 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 28 DCHECK(thread_checker_.CalledOnValidThread()); |
| 29 |
| 30 if (state_ == STATE_UNINITIALIZED) |
| 31 return; |
| 32 |
| 33 if (!init_cb_.IsNull()) |
| 34 SatisfyInit(); |
| 35 if (!held_decode_callbacks_.empty()) |
| 36 SatisfyDecode(); |
| 37 if (!reset_cb_.IsNull()) |
| 38 SatisfyReset(); |
| 39 |
| 40 decoded_frames_.clear(); |
| 29 } | 41 } |
| 30 | 42 |
| 31 void FakeVideoDecoder::Initialize(const VideoDecoderConfig& config, | 43 void FakeVideoDecoder::Initialize(const VideoDecoderConfig& config, |
| 32 bool low_delay, | 44 bool low_delay, |
| 33 const PipelineStatusCB& status_cb, | 45 const PipelineStatusCB& status_cb, |
| 34 const OutputCB& output_cb) { | 46 const OutputCB& output_cb) { |
| 35 DCHECK(thread_checker_.CalledOnValidThread()); | 47 DCHECK(thread_checker_.CalledOnValidThread()); |
| 36 DCHECK(config.IsValidConfig()); | 48 DCHECK(config.IsValidConfig()); |
| 37 DCHECK(held_decode_callbacks_.empty()) | 49 DCHECK(held_decode_callbacks_.empty()) |
| 38 << "No reinitialization during pending decode."; | 50 << "No reinitialization during pending decode."; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 57 void FakeVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, | 69 void FakeVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 58 const DecodeCB& decode_cb) { | 70 const DecodeCB& decode_cb) { |
| 59 DCHECK(thread_checker_.CalledOnValidThread()); | 71 DCHECK(thread_checker_.CalledOnValidThread()); |
| 60 DCHECK(reset_cb_.IsNull()); | 72 DCHECK(reset_cb_.IsNull()); |
| 61 DCHECK_LE(decoded_frames_.size(), | 73 DCHECK_LE(decoded_frames_.size(), |
| 62 decoding_delay_ + held_decode_callbacks_.size()); | 74 decoding_delay_ + held_decode_callbacks_.size()); |
| 63 DCHECK_LT(static_cast<int>(held_decode_callbacks_.size()), | 75 DCHECK_LT(static_cast<int>(held_decode_callbacks_.size()), |
| 64 max_parallel_decoding_requests_); | 76 max_parallel_decoding_requests_); |
| 65 | 77 |
| 66 int buffer_size = buffer->end_of_stream() ? 0 : buffer->data_size(); | 78 int buffer_size = buffer->end_of_stream() ? 0 : buffer->data_size(); |
| 67 DecodeCB wrapped_decode_cb = | 79 DecodeCB wrapped_decode_cb = base::Bind(&FakeVideoDecoder::OnFrameDecoded, |
| 68 BindToCurrentLoop(base::Bind(&FakeVideoDecoder::OnFrameDecoded, | 80 weak_factory_.GetWeakPtr(), |
| 69 weak_factory_.GetWeakPtr(), | 81 buffer_size, |
| 70 buffer_size, decode_cb)); | 82 BindToCurrentLoop(decode_cb)); |
| 71 | 83 |
| 72 if (state_ == STATE_ERROR) { | 84 if (state_ == STATE_ERROR) { |
| 73 wrapped_decode_cb.Run(kDecodeError); | 85 wrapped_decode_cb.Run(kDecodeError); |
| 74 return; | 86 return; |
| 75 } | 87 } |
| 76 | 88 |
| 77 if (buffer->end_of_stream()) { | 89 if (buffer->end_of_stream()) { |
| 78 state_ = STATE_END_OF_STREAM; | 90 state_ = STATE_END_OF_STREAM; |
| 79 } else { | 91 } else { |
| 80 DCHECK(VerifyFakeVideoBufferForTest(buffer, current_config_)); | 92 DCHECK(VerifyFakeVideoBufferForTest(buffer, current_config_)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 93 reset_cb_.SetCallback(BindToCurrentLoop(closure)); | 105 reset_cb_.SetCallback(BindToCurrentLoop(closure)); |
| 94 decoded_frames_.clear(); | 106 decoded_frames_.clear(); |
| 95 | 107 |
| 96 // Defer the reset if a decode is pending. | 108 // Defer the reset if a decode is pending. |
| 97 if (!held_decode_callbacks_.empty()) | 109 if (!held_decode_callbacks_.empty()) |
| 98 return; | 110 return; |
| 99 | 111 |
| 100 DoReset(); | 112 DoReset(); |
| 101 } | 113 } |
| 102 | 114 |
| 103 void FakeVideoDecoder::Stop() { | |
| 104 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 105 | |
| 106 if (!init_cb_.IsNull()) | |
| 107 SatisfyInit(); | |
| 108 if (!held_decode_callbacks_.empty()) | |
| 109 SatisfyDecode(); | |
| 110 if (!reset_cb_.IsNull()) | |
| 111 SatisfyReset(); | |
| 112 | |
| 113 decoded_frames_.clear(); | |
| 114 state_ = STATE_UNINITIALIZED; | |
| 115 } | |
| 116 | |
| 117 void FakeVideoDecoder::HoldNextInit() { | 115 void FakeVideoDecoder::HoldNextInit() { |
| 118 DCHECK(thread_checker_.CalledOnValidThread()); | 116 DCHECK(thread_checker_.CalledOnValidThread()); |
| 119 init_cb_.HoldCallback(); | 117 init_cb_.HoldCallback(); |
| 120 } | 118 } |
| 121 | 119 |
| 122 void FakeVideoDecoder::HoldDecode() { | 120 void FakeVideoDecoder::HoldDecode() { |
| 123 DCHECK(thread_checker_.CalledOnValidThread()); | 121 DCHECK(thread_checker_.CalledOnValidThread()); |
| 124 hold_decode_ = true; | 122 hold_decode_ = true; |
| 125 } | 123 } |
| 126 | 124 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 234 |
| 237 void FakeVideoDecoder::DoReset() { | 235 void FakeVideoDecoder::DoReset() { |
| 238 DCHECK(thread_checker_.CalledOnValidThread()); | 236 DCHECK(thread_checker_.CalledOnValidThread()); |
| 239 DCHECK(held_decode_callbacks_.empty()); | 237 DCHECK(held_decode_callbacks_.empty()); |
| 240 DCHECK(!reset_cb_.IsNull()); | 238 DCHECK(!reset_cb_.IsNull()); |
| 241 | 239 |
| 242 reset_cb_.RunOrHold(); | 240 reset_cb_.RunOrHold(); |
| 243 } | 241 } |
| 244 | 242 |
| 245 } // namespace media | 243 } // namespace media |
| OLD | NEW |