| 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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 } | 428 } |
| 429 | 429 |
| 430 DemuxerData CreateAbortedAck(bool is_audio) { | 430 DemuxerData CreateAbortedAck(bool is_audio) { |
| 431 DemuxerData data; | 431 DemuxerData data; |
| 432 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO; | 432 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO; |
| 433 data.access_units.resize(1); | 433 data.access_units.resize(1); |
| 434 data.access_units[0].status = DemuxerStream::kAborted; | 434 data.access_units[0].status = DemuxerStream::kAborted; |
| 435 return data; | 435 return data; |
| 436 } | 436 } |
| 437 | 437 |
| 438 bool HasData(bool is_audio) { |
| 439 return GetMediaDecoderJob(is_audio)->HasData(); |
| 440 } |
| 441 |
| 438 // Helper method for use at test start. It starts an audio decoder job and | 442 // Helper method for use at test start. It starts an audio decoder job and |
| 439 // immediately feeds it some data to decode. Then, without letting the decoder | 443 // immediately feeds it some data to decode. Then, without letting the decoder |
| 440 // job complete a decode cycle, it also starts player SeekTo(). Upon return, | 444 // job complete a decode cycle, it also starts player SeekTo(). Upon return, |
| 441 // the player should not yet have sent the DemuxerSeek IPC request, though | 445 // the player should not yet have sent the DemuxerSeek IPC request, though |
| 442 // seek event should be pending. The audio decoder job will also still be | 446 // seek event should be pending. The audio decoder job will also still be |
| 443 // decoding. | 447 // decoding. |
| 444 void StartAudioDecoderJobAndSeekToWhileDecoding( | 448 void StartAudioDecoderJobAndSeekToWhileDecoding( |
| 445 const base::TimeDelta& seek_time) { | 449 const base::TimeDelta& seek_time) { |
| 446 EXPECT_FALSE(GetMediaCodecBridge(true)); | 450 EXPECT_FALSE(GetMediaCodecBridge(true)); |
| 447 EXPECT_FALSE(player_.IsPlaying()); | 451 EXPECT_FALSE(player_.IsPlaying()); |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 message_loop_.RunUntilIdle(); | 1040 message_loop_.RunUntilIdle(); |
| 1037 | 1041 |
| 1038 // No further seek or data requests should have been received since the | 1042 // No further seek or data requests should have been received since the |
| 1039 // surface is empty. | 1043 // surface is empty. |
| 1040 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); | 1044 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); |
| 1041 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1045 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1042 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); | 1046 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); |
| 1043 | 1047 |
| 1044 // Playback resumes once a non-empty surface is passed. | 1048 // Playback resumes once a non-empty surface is passed. |
| 1045 CreateNextTextureAndSetVideoSurface(); | 1049 CreateNextTextureAndSetVideoSurface(); |
| 1046 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); | 1050 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); |
| 1051 while(demuxer_->num_browser_seek_requests() != 1) |
| 1052 message_loop_.RunUntilIdle(); |
| 1047 WaitForVideoDecodeDone(); | 1053 WaitForVideoDecodeDone(); |
| 1048 } | 1054 } |
| 1049 | 1055 |
| 1050 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) { | 1056 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) { |
| 1051 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1057 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1052 | 1058 |
| 1053 // Test that if video decoder is released while decoding, the resources will | 1059 // Test that if video decoder is released while decoding, the resources will |
| 1054 // not be immediately released. | 1060 // not be immediately released. |
| 1055 CreateNextTextureAndSetVideoSurface(); | 1061 CreateNextTextureAndSetVideoSurface(); |
| 1056 StartVideoDecoderJob(); | 1062 StartVideoDecoderJob(); |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 // Test that one browser seek is requested if player Release() + Start(), with | 1533 // Test that one browser seek is requested if player Release() + Start(), with |
| 1528 // video data received between Release() and Start(). | 1534 // video data received between Release() and Start(). |
| 1529 BrowserSeekPlayer(true); | 1535 BrowserSeekPlayer(true); |
| 1530 | 1536 |
| 1531 // Simulate browser seek is done and confirm player requests more data. | 1537 // Simulate browser seek is done and confirm player requests more data. |
| 1532 player_.OnDemuxerSeekDone(base::TimeDelta()); | 1538 player_.OnDemuxerSeekDone(base::TimeDelta()); |
| 1533 EXPECT_EQ(3, demuxer_->num_data_requests()); | 1539 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1534 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1540 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1535 } | 1541 } |
| 1536 | 1542 |
| 1543 TEST_F(MediaSourcePlayerTest, NoBrowserSeekWithKeyFrameInCache) { |
| 1544 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1545 |
| 1546 // Test that browser seek is not needed if a key frame is found in data |
| 1547 // cache. |
| 1548 CreateNextTextureAndSetVideoSurface(); |
| 1549 StartVideoDecoderJob(); |
| 1550 DemuxerData data = CreateReadFromDemuxerAckForVideo(false); |
| 1551 data.access_units[0].is_key_frame = true; |
| 1552 |
| 1553 // Simulate demuxer's response to the video data request. |
| 1554 player_.OnDemuxerDataAvailable(data); |
| 1555 |
| 1556 // Trigger decoder recreation later by changing surfaces. |
| 1557 CreateNextTextureAndSetVideoSurface(); |
| 1558 |
| 1559 // Wait for the media codec bridge to finish decoding and be reset. |
| 1560 WaitForVideoDecodeDone(); |
| 1561 EXPECT_FALSE(HasData(false)); |
| 1562 |
| 1563 // Send a non key frame to decoder so that decoder can continue. This will |
| 1564 // not trigger any browser seeks as the previous key frame is still in the |
| 1565 // buffer. |
| 1566 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); |
| 1567 WaitForVideoDecodeDone(); |
| 1568 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); |
| 1569 } |
| 1570 |
| 1537 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { | 1571 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { |
| 1538 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1572 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1539 | 1573 |
| 1540 // Test decoder job will preroll the media to the seek position. | 1574 // Test decoder job will preroll the media to the seek position. |
| 1541 StartAudioDecoderJob(); | 1575 StartAudioDecoderJob(); |
| 1542 | 1576 |
| 1543 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); | 1577 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); |
| 1544 EXPECT_TRUE(IsPrerolling(true)); | 1578 EXPECT_TRUE(IsPrerolling(true)); |
| 1545 PrerollDecoderToTime( | 1579 PrerollDecoderToTime( |
| 1546 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100), true); | 1580 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100), true); |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2322 // Wait for the metadata change. | 2356 // Wait for the metadata change. |
| 2323 while(manager_.num_metadata_changes() == 1) { | 2357 while(manager_.num_metadata_changes() == 1) { |
| 2324 player_.OnDemuxerDataAvailable(data); | 2358 player_.OnDemuxerDataAvailable(data); |
| 2325 WaitForVideoDecodeDone(); | 2359 WaitForVideoDecodeDone(); |
| 2326 } | 2360 } |
| 2327 EXPECT_EQ(2, manager_.num_metadata_changes()); | 2361 EXPECT_EQ(2, manager_.num_metadata_changes()); |
| 2328 WaitForVideoDecodeDone(); | 2362 WaitForVideoDecodeDone(); |
| 2329 } | 2363 } |
| 2330 | 2364 |
| 2331 } // namespace media | 2365 } // namespace media |
| OLD | NEW |