| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" |
| 8 #include "media/base/decoder_buffer.h" | 9 #include "media/base/decoder_buffer.h" |
| 9 #include "media/base/mock_filters.h" | 10 #include "media/base/mock_filters.h" |
| 10 #include "media/base/test_helpers.h" | 11 #include "media/base/test_helpers.h" |
| 11 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
| 12 #include "media/filters/fake_video_decoder.h" | 13 #include "media/filters/fake_video_decoder.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace media { | 16 namespace media { |
| 16 | 17 |
| 17 static const int kTotalBuffers = 12; | 18 static const int kTotalBuffers = 12; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 45 | 46 |
| 46 virtual ~FakeVideoDecoderTest() { | 47 virtual ~FakeVideoDecoderTest() { |
| 47 Destroy(); | 48 Destroy(); |
| 48 } | 49 } |
| 49 | 50 |
| 50 void InitializeWithConfigAndExpectResult(const VideoDecoderConfig& config, | 51 void InitializeWithConfigAndExpectResult(const VideoDecoderConfig& config, |
| 51 bool success) { | 52 bool success) { |
| 52 decoder_->Initialize( | 53 decoder_->Initialize( |
| 53 config, false, nullptr, NewExpectedBoolCB(success), | 54 config, false, nullptr, NewExpectedBoolCB(success), |
| 54 base::Bind(&FakeVideoDecoderTest::FrameReady, base::Unretained(this))); | 55 base::Bind(&FakeVideoDecoderTest::FrameReady, base::Unretained(this))); |
| 55 message_loop_.RunUntilIdle(); | 56 base::RunLoop().RunUntilIdle(); |
| 56 current_config_ = config; | 57 current_config_ = config; |
| 57 } | 58 } |
| 58 | 59 |
| 59 void Initialize() { | 60 void Initialize() { |
| 60 InitializeWithConfigAndExpectResult(TestVideoConfig::Normal(), true); | 61 InitializeWithConfigAndExpectResult(TestVideoConfig::Normal(), true); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void EnterPendingInitState() { | 64 void EnterPendingInitState() { |
| 64 decoder_->HoldNextInit(); | 65 decoder_->HoldNextInit(); |
| 65 Initialize(); | 66 Initialize(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void SatisfyInit() { | 69 void SatisfyInit() { |
| 69 decoder_->SatisfyInit(); | 70 decoder_->SatisfyInit(); |
| 70 message_loop_.RunUntilIdle(); | 71 base::RunLoop().RunUntilIdle(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 // Callback for VideoDecoder::Decode(). | 74 // Callback for VideoDecoder::Decode(). |
| 74 void DecodeDone(DecodeStatus status) { | 75 void DecodeDone(DecodeStatus status) { |
| 75 DCHECK_GT(pending_decode_requests_, 0); | 76 DCHECK_GT(pending_decode_requests_, 0); |
| 76 --pending_decode_requests_; | 77 --pending_decode_requests_; |
| 77 last_decode_status_ = status; | 78 last_decode_status_ = status; |
| 78 } | 79 } |
| 79 | 80 |
| 80 void FrameReady(const scoped_refptr<VideoFrame>& frame) { | 81 void FrameReady(const scoped_refptr<VideoFrame>& frame) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } else { | 130 } else { |
| 130 buffer = DecoderBuffer::CreateEOSBuffer(); | 131 buffer = DecoderBuffer::CreateEOSBuffer(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 ++num_input_buffers_; | 134 ++num_input_buffers_; |
| 134 ++pending_decode_requests_; | 135 ++pending_decode_requests_; |
| 135 | 136 |
| 136 decoder_->Decode( | 137 decoder_->Decode( |
| 137 buffer, | 138 buffer, |
| 138 base::Bind(&FakeVideoDecoderTest::DecodeDone, base::Unretained(this))); | 139 base::Bind(&FakeVideoDecoderTest::DecodeDone, base::Unretained(this))); |
| 139 message_loop_.RunUntilIdle(); | 140 base::RunLoop().RunUntilIdle(); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void ReadOneFrame() { | 143 void ReadOneFrame() { |
| 143 last_decoded_frame_ = NULL; | 144 last_decoded_frame_ = NULL; |
| 144 do { | 145 do { |
| 145 Decode(); | 146 Decode(); |
| 146 } while (!last_decoded_frame_.get() && pending_decode_requests_ == 0); | 147 } while (!last_decoded_frame_.get() && pending_decode_requests_ == 0); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void ReadAllFrames() { | 150 void ReadAllFrames() { |
| 150 do { | 151 do { |
| 151 Decode(); | 152 Decode(); |
| 152 } while (num_input_buffers_ <= kTotalBuffers); // All input buffers + EOS. | 153 } while (num_input_buffers_ <= kTotalBuffers); // All input buffers + EOS. |
| 153 } | 154 } |
| 154 | 155 |
| 155 void EnterPendingReadState() { | 156 void EnterPendingReadState() { |
| 156 // Pass the initial NOT_ENOUGH_DATA stage. | 157 // Pass the initial NOT_ENOUGH_DATA stage. |
| 157 ReadOneFrame(); | 158 ReadOneFrame(); |
| 158 decoder_->HoldDecode(); | 159 decoder_->HoldDecode(); |
| 159 ReadOneFrame(); | 160 ReadOneFrame(); |
| 160 ExpectReadResult(PENDING); | 161 ExpectReadResult(PENDING); |
| 161 } | 162 } |
| 162 | 163 |
| 163 void SatisfyDecodeAndExpect(CallbackResult result) { | 164 void SatisfyDecodeAndExpect(CallbackResult result) { |
| 164 decoder_->SatisfyDecode(); | 165 decoder_->SatisfyDecode(); |
| 165 message_loop_.RunUntilIdle(); | 166 base::RunLoop().RunUntilIdle(); |
| 166 ExpectReadResult(result); | 167 ExpectReadResult(result); |
| 167 } | 168 } |
| 168 | 169 |
| 169 void SatisfyRead() { | 170 void SatisfyRead() { |
| 170 SatisfyDecodeAndExpect(OK); | 171 SatisfyDecodeAndExpect(OK); |
| 171 } | 172 } |
| 172 | 173 |
| 173 // Callback for VideoDecoder::Reset(). | 174 // Callback for VideoDecoder::Reset(). |
| 174 void OnDecoderReset() { | 175 void OnDecoderReset() { |
| 175 DCHECK(is_reset_pending_); | 176 DCHECK(is_reset_pending_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 186 break; | 187 break; |
| 187 default: | 188 default: |
| 188 NOTREACHED(); | 189 NOTREACHED(); |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 | 192 |
| 192 void ResetAndExpect(CallbackResult result) { | 193 void ResetAndExpect(CallbackResult result) { |
| 193 is_reset_pending_ = true; | 194 is_reset_pending_ = true; |
| 194 decoder_->Reset(base::Bind(&FakeVideoDecoderTest::OnDecoderReset, | 195 decoder_->Reset(base::Bind(&FakeVideoDecoderTest::OnDecoderReset, |
| 195 base::Unretained(this))); | 196 base::Unretained(this))); |
| 196 message_loop_.RunUntilIdle(); | 197 base::RunLoop().RunUntilIdle(); |
| 197 ExpectResetResult(result); | 198 ExpectResetResult(result); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void EnterPendingResetState() { | 201 void EnterPendingResetState() { |
| 201 decoder_->HoldNextReset(); | 202 decoder_->HoldNextReset(); |
| 202 ResetAndExpect(PENDING); | 203 ResetAndExpect(PENDING); |
| 203 } | 204 } |
| 204 | 205 |
| 205 void SatisfyReset() { | 206 void SatisfyReset() { |
| 206 decoder_->SatisfyReset(); | 207 decoder_->SatisfyReset(); |
| 207 message_loop_.RunUntilIdle(); | 208 base::RunLoop().RunUntilIdle(); |
| 208 ExpectResetResult(OK); | 209 ExpectResetResult(OK); |
| 209 } | 210 } |
| 210 | 211 |
| 211 void Destroy() { | 212 void Destroy() { |
| 212 decoder_.reset(); | 213 decoder_.reset(); |
| 213 message_loop_.RunUntilIdle(); | 214 base::RunLoop().RunUntilIdle(); |
| 214 | 215 |
| 215 // All pending callbacks must have been fired. | 216 // All pending callbacks must have been fired. |
| 216 DCHECK_EQ(pending_decode_requests_, 0); | 217 DCHECK_EQ(pending_decode_requests_, 0); |
| 217 DCHECK(!is_reset_pending_); | 218 DCHECK(!is_reset_pending_); |
| 218 } | 219 } |
| 219 | 220 |
| 220 base::MessageLoop message_loop_; | 221 base::MessageLoop message_loop_; |
| 221 VideoDecoderConfig current_config_; | 222 VideoDecoderConfig current_config_; |
| 222 | 223 |
| 223 std::unique_ptr<FakeVideoDecoder> decoder_; | 224 std::unique_ptr<FakeVideoDecoder> decoder_; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 Initialize(); | 328 Initialize(); |
| 328 | 329 |
| 329 // Hold all decodes and satisfy one decode at a time. | 330 // Hold all decodes and satisfy one decode at a time. |
| 330 decoder_->HoldDecode(); | 331 decoder_->HoldDecode(); |
| 331 int num_decodes_satisfied = 0; | 332 int num_decodes_satisfied = 0; |
| 332 while (num_decoded_frames_ == 0) { | 333 while (num_decoded_frames_ == 0) { |
| 333 while (pending_decode_requests_ < decoder_->GetMaxDecodeRequests()) | 334 while (pending_decode_requests_ < decoder_->GetMaxDecodeRequests()) |
| 334 Decode(); | 335 Decode(); |
| 335 decoder_->SatisfySingleDecode(); | 336 decoder_->SatisfySingleDecode(); |
| 336 ++num_decodes_satisfied; | 337 ++num_decodes_satisfied; |
| 337 message_loop_.RunUntilIdle(); | 338 base::RunLoop().RunUntilIdle(); |
| 338 } | 339 } |
| 339 | 340 |
| 340 DCHECK_EQ(num_decoded_frames_, 1); | 341 DCHECK_EQ(num_decoded_frames_, 1); |
| 341 DCHECK_EQ(num_decodes_satisfied, GetParam().decoding_delay + 1); | 342 DCHECK_EQ(num_decodes_satisfied, GetParam().decoding_delay + 1); |
| 342 } | 343 } |
| 343 | 344 |
| 344 TEST_P(FakeVideoDecoderTest, Reinitialize) { | 345 TEST_P(FakeVideoDecoderTest, Reinitialize) { |
| 345 Initialize(); | 346 Initialize(); |
| 346 ReadOneFrame(); | 347 ReadOneFrame(); |
| 347 InitializeWithConfigAndExpectResult(TestVideoConfig::Large(), true); | 348 InitializeWithConfigAndExpectResult(TestVideoConfig::Large(), true); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 } | 423 } |
| 423 | 424 |
| 424 TEST_P(FakeVideoDecoderTest, Destroy_DuringPendingReadAndPendingReset) { | 425 TEST_P(FakeVideoDecoderTest, Destroy_DuringPendingReadAndPendingReset) { |
| 425 Initialize(); | 426 Initialize(); |
| 426 EnterPendingReadState(); | 427 EnterPendingReadState(); |
| 427 EnterPendingResetState(); | 428 EnterPendingResetState(); |
| 428 Destroy(); | 429 Destroy(); |
| 429 } | 430 } |
| 430 | 431 |
| 431 } // namespace media | 432 } // namespace media |
| OLD | NEW |