Chromium Code Reviews| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 demuxer_->num_data_requests()); | 332 demuxer_->num_data_requests()); |
| 333 | 333 |
| 334 // Verify player has decoder job iff the config included the media type for | 334 // Verify player has decoder job iff the config included the media type for |
| 335 // the job and the player is expected to request data due to Start(), above. | 335 // the job and the player is expected to request data due to Start(), above. |
| 336 EXPECT_EQ(expect_player_requests_data && has_audio, | 336 EXPECT_EQ(expect_player_requests_data && has_audio, |
| 337 GetMediaDecoderJob(true) != NULL); | 337 GetMediaDecoderJob(true) != NULL); |
| 338 EXPECT_EQ(expect_player_requests_data && has_video, | 338 EXPECT_EQ(expect_player_requests_data && has_video, |
| 339 GetMediaDecoderJob(false) != NULL); | 339 GetMediaDecoderJob(false) != NULL); |
| 340 } | 340 } |
| 341 | 341 |
| 342 // Keeps decoding audio data until the AudioTrack's buffer is full and the | |
| 343 // system starts to render the decoded audio. | |
| 344 void DecodeAudioDataUntilAudioBufferBecomesFull() { | |
| 345 EXPECT_TRUE(player_.IsPlaying()); | |
| 346 int i = 0; | |
| 347 while (true) { | |
|
wolenetz
2014/04/15 20:40:22
Is there a reasonable cap on number of decode iter
qinmin
2014/04/15 21:53:05
It takes about 5-7 frames for the AudioTrack to st
| |
| 348 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); | |
| 349 WaitForAudioDecodeDone(); | |
| 350 if (player_.GetCurrentTime().InMilliseconds() > 0) | |
|
wolenetz
2014/04/15 20:40:22
I think a delta check not just > 0 here would be g
qinmin
2014/04/15 21:53:05
Done.
| |
| 351 break; | |
| 352 if (i < 3) | |
| 353 ++i; | |
| 354 } | |
| 355 } | |
| 356 | |
| 342 AccessUnit CreateAccessUnitWithData(bool is_audio, int audio_packet_id) { | 357 AccessUnit CreateAccessUnitWithData(bool is_audio, int audio_packet_id) { |
| 343 AccessUnit unit; | 358 AccessUnit unit; |
| 344 | 359 |
| 345 unit.status = DemuxerStream::kOk; | 360 unit.status = DemuxerStream::kOk; |
| 346 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile( | 361 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile( |
| 347 is_audio ? base::StringPrintf("vorbis-packet-%d", audio_packet_id) | 362 is_audio ? base::StringPrintf("vorbis-packet-%d", audio_packet_id) |
| 348 : "vp8-I-frame-320x240"); | 363 : "vp8-I-frame-320x240"); |
| 349 unit.data = std::vector<uint8>( | 364 unit.data = std::vector<uint8>( |
| 350 buffer->data(), buffer->data() + buffer->data_size()); | 365 buffer->data(), buffer->data() + buffer->data_size()); |
| 351 | 366 |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1070 // No seeks should have occurred. | 1085 // No seeks should have occurred. |
| 1071 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 1086 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
| 1072 } | 1087 } |
| 1073 | 1088 |
| 1074 TEST_F(MediaSourcePlayerTest, StartTimeTicksResetAfterDecoderUnderruns) { | 1089 TEST_F(MediaSourcePlayerTest, StartTimeTicksResetAfterDecoderUnderruns) { |
| 1075 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1090 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1076 | 1091 |
| 1077 // Test start time ticks will reset after decoder job underruns. | 1092 // Test start time ticks will reset after decoder job underruns. |
| 1078 StartAudioDecoderJob(true); | 1093 StartAudioDecoderJob(true); |
| 1079 | 1094 |
| 1080 // For the first couple chunks, the decoder job may return | 1095 DecodeAudioDataUntilAudioBufferBecomesFull(); |
| 1081 // DECODE_FORMAT_CHANGED status instead of DECODE_SUCCEEDED status. Decode | |
| 1082 // more frames to guarantee that DECODE_SUCCEEDED will be returned. | |
| 1083 for (int i = 0; i < 4; ++i) { | |
| 1084 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); | |
| 1085 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | |
| 1086 // Decode data until decoder started requesting new data again. | |
| 1087 WaitForAudioDecodeDone(); | |
| 1088 } | |
| 1089 | 1096 |
| 1090 // The decoder job should finish and a new request will be sent. | 1097 // The decoder job should finish and a new request will be sent. |
| 1091 EXPECT_EQ(5, demuxer_->num_data_requests()); | |
| 1092 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 1098 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
| 1093 base::TimeTicks previous = StartTimeTicks(); | 1099 base::TimeTicks previous = StartTimeTicks(); |
| 1094 | 1100 |
| 1095 // Let the decoder starve. | 1101 // Let the decoder starve. |
| 1096 TriggerPlayerStarvation(); | 1102 TriggerPlayerStarvation(); |
| 1097 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); | 1103 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); |
| 1098 WaitForAudioDecodeDone(); | 1104 WaitForAudioDecodeDone(); |
| 1099 | 1105 |
| 1100 // Verify the start time ticks is cleared at this point because the | 1106 // Verify the start time ticks is cleared at this point because the |
| 1101 // player is prefetching. | 1107 // player is prefetching. |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1465 TEST_F(MediaSourcePlayerTest, SeekingAfterCompletingPrerollRestartsPreroll) { | 1471 TEST_F(MediaSourcePlayerTest, SeekingAfterCompletingPrerollRestartsPreroll) { |
| 1466 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1472 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1467 | 1473 |
| 1468 // Test decoder job will begin prerolling upon seek, when it was not | 1474 // Test decoder job will begin prerolling upon seek, when it was not |
| 1469 // prerolling prior to the seek. | 1475 // prerolling prior to the seek. |
| 1470 StartAudioDecoderJob(true); | 1476 StartAudioDecoderJob(true); |
| 1471 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); | 1477 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); |
| 1472 EXPECT_TRUE(IsPrerolling(true)); | 1478 EXPECT_TRUE(IsPrerolling(true)); |
| 1473 | 1479 |
| 1474 // Complete the initial preroll by feeding data to the decoder. | 1480 // Complete the initial preroll by feeding data to the decoder. |
| 1475 for (int i = 0; i < 4; ++i) { | 1481 DecodeAudioDataUntilAudioBufferBecomesFull(); |
| 1476 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); | |
| 1477 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | |
| 1478 WaitForAudioDecodeDone(); | |
| 1479 } | |
| 1480 EXPECT_LT(0.0, player_.GetCurrentTime().InMillisecondsF()); | |
| 1481 EXPECT_FALSE(IsPrerolling(true)); | 1482 EXPECT_FALSE(IsPrerolling(true)); |
| 1482 | 1483 |
| 1483 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(500)); | 1484 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(500)); |
| 1484 | 1485 |
| 1485 // Prerolling should have begun again. | 1486 // Prerolling should have begun again. |
| 1486 EXPECT_TRUE(IsPrerolling(true)); | 1487 EXPECT_TRUE(IsPrerolling(true)); |
| 1487 EXPECT_EQ(500.0, GetPrerollTimestamp().InMillisecondsF()); | 1488 EXPECT_EQ(500.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1488 | 1489 |
| 1489 // Send data at and after the seek position. Prerolling should complete. | 1490 // Send data at and after the seek position. Prerolling should complete. |
| 1490 for (int i = 0; i < 4; ++i) { | 1491 for (int i = 0; i < 4; ++i) { |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2060 // player has not yet received media crypto. | 2061 // player has not yet received media crypto. |
| 2061 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); | 2062 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); |
| 2062 configs.is_video_encrypted = true; | 2063 configs.is_video_encrypted = true; |
| 2063 | 2064 |
| 2064 player_.OnDemuxerConfigsAvailable(configs); | 2065 player_.OnDemuxerConfigsAvailable(configs); |
| 2065 CreateNextTextureAndSetVideoSurface(); | 2066 CreateNextTextureAndSetVideoSurface(); |
| 2066 EXPECT_FALSE(IsPendingSurfaceChange()); | 2067 EXPECT_FALSE(IsPendingSurfaceChange()); |
| 2067 EXPECT_FALSE(GetMediaDecoderJob(false)); | 2068 EXPECT_FALSE(GetMediaDecoderJob(false)); |
| 2068 } | 2069 } |
| 2069 | 2070 |
| 2071 TEST_F(MediaSourcePlayerTest, CurrentTimeUpdatedWhileDecoderStarved) { | |
| 2072 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | |
| 2073 | |
| 2074 // Test that current time is updated while decoder is starved. | |
| 2075 StartAudioDecoderJob(true); | |
| 2076 DecodeAudioDataUntilAudioBufferBecomesFull(); | |
| 2077 base::TimeDelta current_time = player_.GetCurrentTime(); | |
| 2078 | |
| 2079 // Trigger starvation while the decoder is decoding. | |
| 2080 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); | |
| 2081 TriggerPlayerStarvation(); | |
| 2082 WaitForAudioDecodeDone(); | |
| 2083 | |
| 2084 // Current time should be updated. | |
| 2085 EXPECT_LT(current_time.InMillisecondsF(), | |
| 2086 player_.GetCurrentTime().InMillisecondsF()); | |
| 2087 } | |
| 2088 | |
| 2089 TEST_F(MediaSourcePlayerTest, CurrentTimeKeepsIncreasingAfterConfigChange) { | |
| 2090 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | |
| 2091 | |
| 2092 // Test current time keep on increasing after audio config change. | |
| 2093 // Test that current time is updated while decoder is starved. | |
| 2094 StartAudioDecoderJob(true); | |
| 2095 | |
| 2096 DecodeAudioDataUntilAudioBufferBecomesFull(); | |
| 2097 base::TimeDelta current_time = player_.GetCurrentTime(); | |
| 2098 | |
| 2099 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); | |
| 2100 player_.OnDemuxerDataAvailable(data); | |
| 2101 WaitForAudioDecodeDone(); | |
| 2102 | |
| 2103 // Simulate arrival of new configs. | |
| 2104 player_.OnDemuxerConfigsAvailable(CreateAudioDemuxerConfigs(kCodecVorbis)); | |
| 2105 for (int i = 0; i < 4; ++i) { | |
| 2106 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); | |
| 2107 WaitForAudioDecodeDone(); | |
| 2108 base::TimeDelta new_current_time = player_.GetCurrentTime(); | |
| 2109 EXPECT_LE(current_time.InMillisecondsF(), | |
| 2110 new_current_time.InMillisecondsF()); | |
| 2111 current_time = new_current_time; | |
| 2112 } | |
| 2113 } | |
| 2114 | |
| 2070 } // namespace media | 2115 } // namespace media |
| OLD | NEW |