| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
| 8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
| 9 #include "media/base/android/media_codec_audio_decoder.h" | 9 #include "media/base/android/media_codec_audio_decoder.h" |
| 10 #include "media/base/android/media_codec_bridge.h" | 10 #include "media/base/android/media_codec_bridge.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 void CreateAudioDecoder(); | 142 void CreateAudioDecoder(); |
| 143 void CreateVideoDecoder(); | 143 void CreateVideoDecoder(); |
| 144 void SetVideoSurface(); | 144 void SetVideoSurface(); |
| 145 void SetStopRequestAtTime(const base::TimeDelta& time) { | 145 void SetStopRequestAtTime(const base::TimeDelta& time) { |
| 146 stop_request_time_ = time; | 146 stop_request_time_ = time; |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Decoder callbacks. | 149 // Decoder callbacks. |
| 150 void OnDataRequested(); | 150 void OnDataRequested(); |
| 151 void OnStarvation() { is_starved_ = true; } | 151 void OnStarvation() { is_starved_ = true; } |
| 152 void OnPrerollDone() { decoder_->ResumeAfterPreroll(); } |
| 152 void OnStopDone() { is_stopped_ = true; } | 153 void OnStopDone() { is_stopped_ = true; } |
| 153 void OnError() {} | 154 void OnError() {} |
| 154 void OnUpdateCurrentTime(base::TimeDelta now_playing, | 155 void OnUpdateCurrentTime(base::TimeDelta now_playing, |
| 155 base::TimeDelta last_buffered) { | 156 base::TimeDelta last_buffered) { |
| 156 // Add the |last_buffered| value for PTS. For video it is the same as | 157 // Add the |last_buffered| value for PTS. For video it is the same as |
| 157 // |now_playing| and is equal to PTS, for audio |last_buffered| should | 158 // |now_playing| and is equal to PTS, for audio |last_buffered| should |
| 158 // exceed PTS. | 159 // exceed PTS. |
| 159 pts_stat_.AddValue(last_buffered); | 160 pts_stat_.AddValue(last_buffered); |
| 160 | 161 |
| 161 if (stop_request_time_ != kNoTimestamp() && | 162 if (stop_request_time_ != kNoTimestamp() && |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 225 |
| 225 DCHECK(!timer.IsRunning()); | 226 DCHECK(!timer.IsRunning()); |
| 226 return false; | 227 return false; |
| 227 } | 228 } |
| 228 | 229 |
| 229 void MediaCodecDecoderTest::CreateAudioDecoder() { | 230 void MediaCodecDecoderTest::CreateAudioDecoder() { |
| 230 decoder_ = scoped_ptr<MediaCodecDecoder>(new MediaCodecAudioDecoder( | 231 decoder_ = scoped_ptr<MediaCodecDecoder>(new MediaCodecAudioDecoder( |
| 231 task_runner_, base::Bind(&MediaCodecDecoderTest::OnDataRequested, | 232 task_runner_, base::Bind(&MediaCodecDecoderTest::OnDataRequested, |
| 232 base::Unretained(this)), | 233 base::Unretained(this)), |
| 233 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), | 234 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), |
| 235 base::Bind(&MediaCodecDecoderTest::OnPrerollDone, base::Unretained(this)), |
| 234 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), | 236 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), |
| 235 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), | 237 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), |
| 236 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, | 238 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, |
| 237 base::Unretained(this)))); | 239 base::Unretained(this)))); |
| 238 | 240 |
| 239 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, | 241 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, |
| 240 base::Unretained(decoder_.get())); | 242 base::Unretained(decoder_.get())); |
| 241 } | 243 } |
| 242 | 244 |
| 243 void MediaCodecDecoderTest::CreateVideoDecoder() { | 245 void MediaCodecDecoderTest::CreateVideoDecoder() { |
| 244 decoder_ = scoped_ptr<MediaCodecDecoder>(new MediaCodecVideoDecoder( | 246 decoder_ = scoped_ptr<MediaCodecDecoder>(new MediaCodecVideoDecoder( |
| 245 task_runner_, base::Bind(&MediaCodecDecoderTest::OnDataRequested, | 247 task_runner_, base::Bind(&MediaCodecDecoderTest::OnDataRequested, |
| 246 base::Unretained(this)), | 248 base::Unretained(this)), |
| 247 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), | 249 base::Bind(&MediaCodecDecoderTest::OnStarvation, base::Unretained(this)), |
| 250 base::Bind(&MediaCodecDecoderTest::OnPrerollDone, base::Unretained(this)), |
| 248 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), | 251 base::Bind(&MediaCodecDecoderTest::OnStopDone, base::Unretained(this)), |
| 249 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), | 252 base::Bind(&MediaCodecDecoderTest::OnError, base::Unretained(this)), |
| 250 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, | 253 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime, |
| 251 base::Unretained(this)), | 254 base::Unretained(this)), |
| 252 base::Bind(&MediaCodecDecoderTest::OnVideoSizeChanged, | 255 base::Bind(&MediaCodecDecoderTest::OnVideoSizeChanged, |
| 253 base::Unretained(this)), | 256 base::Unretained(this)), |
| 254 base::Bind(&MediaCodecDecoderTest::OnVideoCodecCreated, | 257 base::Bind(&MediaCodecDecoderTest::OnVideoCodecCreated, |
| 255 base::Unretained(this)))); | 258 base::Unretained(this)))); |
| 256 | 259 |
| 257 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, | 260 data_available_cb_ = base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable, |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 EXPECT_TRUE(decoder_->Start(base::TimeDelta::FromMilliseconds(0))); | 486 EXPECT_TRUE(decoder_->Start(base::TimeDelta::FromMilliseconds(0))); |
| 484 | 487 |
| 485 EXPECT_TRUE(WaitForCondition( | 488 EXPECT_TRUE(WaitForCondition( |
| 486 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)), | 489 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)), |
| 487 timeout)); | 490 timeout)); |
| 488 | 491 |
| 489 EXPECT_TRUE(decoder_->IsStopped()); | 492 EXPECT_TRUE(decoder_->IsStopped()); |
| 490 EXPECT_TRUE(decoder_->IsCompleted()); | 493 EXPECT_TRUE(decoder_->IsCompleted()); |
| 491 | 494 |
| 492 // Last buffered timestamp should be no less than PTS. | 495 // Last buffered timestamp should be no less than PTS. |
| 493 EXPECT_EQ(22, pts_stat_.num_values()); | 496 // The number of hits in pts_stat_ depends on the preroll implementation. |
| 497 // We might not report the time for the first buffer after preroll that |
| 498 // is written to the audio track. pts_stat_.num_values() is either 21 or 22. |
| 499 EXPECT_LE(21, pts_stat_.num_values()); |
| 494 EXPECT_LE(data_factory_->last_pts(), pts_stat_.max()); | 500 EXPECT_LE(data_factory_->last_pts(), pts_stat_.max()); |
| 495 } | 501 } |
| 496 | 502 |
| 497 TEST_F(MediaCodecDecoderTest, VideoPlayTillCompletion) { | 503 TEST_F(MediaCodecDecoderTest, VideoPlayTillCompletion) { |
| 498 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 504 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 499 | 505 |
| 500 CreateVideoDecoder(); | 506 CreateVideoDecoder(); |
| 501 | 507 |
| 502 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); | 508 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); |
| 503 // The first output frame might come out with significant delay. Apparently | 509 // The first output frame might come out with significant delay. Apparently |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 decoder_->RequestToStop(); | 647 decoder_->RequestToStop(); |
| 642 | 648 |
| 643 EXPECT_TRUE(WaitForCondition( | 649 EXPECT_TRUE(WaitForCondition( |
| 644 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)))); | 650 base::Bind(&MediaCodecDecoderTest::is_stopped, base::Unretained(this)))); |
| 645 | 651 |
| 646 EXPECT_TRUE(decoder_->IsStopped()); | 652 EXPECT_TRUE(decoder_->IsStopped()); |
| 647 EXPECT_FALSE(decoder_->IsCompleted()); | 653 EXPECT_FALSE(decoder_->IsCompleted()); |
| 648 } | 654 } |
| 649 | 655 |
| 650 } // namespace media | 656 } // namespace media |
| OLD | NEW |