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 "media/base/android/media_codec_player.h" | 5 #include "media/base/android/media_codec_player.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 void MockDemuxerAndroid::PostConfigs(const DemuxerConfigs& configs) { | 508 void MockDemuxerAndroid::PostConfigs(const DemuxerConfigs& configs) { |
509 RUN_ON_MEDIA_THREAD(MockDemuxerAndroid, PostConfigs, configs); | 509 RUN_ON_MEDIA_THREAD(MockDemuxerAndroid, PostConfigs, configs); |
510 | 510 |
511 DVLOG(1) << "MockDemuxerAndroid::" << __FUNCTION__; | 511 DVLOG(1) << "MockDemuxerAndroid::" << __FUNCTION__; |
512 | 512 |
513 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | 513 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); |
514 | 514 |
515 if (client_) | 515 if (client_) |
516 client_->OnDemuxerConfigsAvailable(configs); | 516 client_->OnDemuxerConfigsAvailable(configs); |
517 else | 517 else |
518 pending_configs_ = base::WrapUnique(new DemuxerConfigs(configs)); | 518 pending_configs_ = base::MakeUnique<DemuxerConfigs>(configs); |
519 } | 519 } |
520 | 520 |
521 void MockDemuxerAndroid::PostInternalConfigs() { | 521 void MockDemuxerAndroid::PostInternalConfigs() { |
522 ASSERT_TRUE(audio_factory_ || video_factory_); | 522 ASSERT_TRUE(audio_factory_ || video_factory_); |
523 | 523 |
524 if (audio_factory_ && video_factory_) { | 524 if (audio_factory_ && video_factory_) { |
525 PostConfigs( | 525 PostConfigs( |
526 CreateAudioVideoConfigs(audio_factory_.get(), video_factory_.get())); | 526 CreateAudioVideoConfigs(audio_factory_.get(), video_factory_.get())); |
527 } else if (audio_factory_) { | 527 } else if (audio_factory_) { |
528 PostConfigs(audio_factory_->GetConfigs()); | 528 PostConfigs(audio_factory_->GetConfigs()); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 return WaitForCondition( | 706 return WaitForCondition( |
707 base::Bind(&MockMediaPlayerManager::IsPlaybackBeyondPosition, | 707 base::Bind(&MockMediaPlayerManager::IsPlaybackBeyondPosition, |
708 base::Unretained(&manager_), pts), | 708 base::Unretained(&manager_), pts), |
709 timeout); | 709 timeout); |
710 } | 710 } |
711 | 711 |
712 bool MediaCodecPlayerTest::StartVideoPlayback(base::TimeDelta duration, | 712 bool MediaCodecPlayerTest::StartVideoPlayback(base::TimeDelta duration, |
713 const char* test_name) { | 713 const char* test_name) { |
714 const base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); | 714 const base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); |
715 | 715 |
716 demuxer_->SetVideoFactory(base::WrapUnique(new VideoFactory(duration))); | 716 demuxer_->SetVideoFactory(base::MakeUnique<VideoFactory>(duration)); |
717 | 717 |
718 CreatePlayer(); | 718 CreatePlayer(); |
719 | 719 |
720 // Wait till the player is initialized on media thread. | 720 // Wait till the player is initialized on media thread. |
721 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, | 721 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, |
722 base::Unretained(demuxer_)))); | 722 base::Unretained(demuxer_)))); |
723 | 723 |
724 if (!demuxer_->IsInitialized()) { | 724 if (!demuxer_->IsInitialized()) { |
725 DVLOG(0) << test_name << ": demuxer is not initialized"; | 725 DVLOG(0) << test_name << ": demuxer is not initialized"; |
726 return false; | 726 return false; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 EXPECT_EQ(320, manager_.media_metadata_.width); | 938 EXPECT_EQ(320, manager_.media_metadata_.width); |
939 EXPECT_EQ(240, manager_.media_metadata_.height); | 939 EXPECT_EQ(240, manager_.media_metadata_.height); |
940 } | 940 } |
941 | 941 |
942 TEST_F(MediaCodecPlayerTest, DISABLED_AudioPlayTillCompletion) { | 942 TEST_F(MediaCodecPlayerTest, DISABLED_AudioPlayTillCompletion) { |
943 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 943 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
944 | 944 |
945 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1000); | 945 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1000); |
946 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(2000); | 946 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(2000); |
947 | 947 |
948 demuxer_->SetAudioFactory(base::WrapUnique(new AudioFactory(duration))); | 948 demuxer_->SetAudioFactory(base::MakeUnique<AudioFactory>(duration)); |
949 | 949 |
950 CreatePlayer(); | 950 CreatePlayer(); |
951 | 951 |
952 // Wait till the player is initialized on media thread. | 952 // Wait till the player is initialized on media thread. |
953 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, | 953 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, |
954 base::Unretained(demuxer_)))); | 954 base::Unretained(demuxer_)))); |
955 | 955 |
956 // Post configuration after the player has been initialized. | 956 // Post configuration after the player has been initialized. |
957 demuxer_->PostInternalConfigs(); | 957 demuxer_->PostInternalConfigs(); |
958 | 958 |
(...skipping 13 matching lines...) Expand all Loading... |
972 } | 972 } |
973 | 973 |
974 TEST_F(MediaCodecPlayerTest, AudioNoPermission) { | 974 TEST_F(MediaCodecPlayerTest, AudioNoPermission) { |
975 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 975 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
976 | 976 |
977 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1000); | 977 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1000); |
978 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); | 978 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); |
979 | 979 |
980 manager_.SetPlaybackAllowed(false); | 980 manager_.SetPlaybackAllowed(false); |
981 | 981 |
982 demuxer_->SetAudioFactory(base::WrapUnique(new AudioFactory(duration))); | 982 demuxer_->SetAudioFactory(base::MakeUnique<AudioFactory>(duration)); |
983 | 983 |
984 CreatePlayer(); | 984 CreatePlayer(); |
985 | 985 |
986 // Wait till the player is initialized on media thread. | 986 // Wait till the player is initialized on media thread. |
987 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, | 987 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, |
988 base::Unretained(demuxer_)))); | 988 base::Unretained(demuxer_)))); |
989 | 989 |
990 // Post configuration after the player has been initialized. | 990 // Post configuration after the player has been initialized. |
991 demuxer_->PostInternalConfigs(); | 991 demuxer_->PostInternalConfigs(); |
992 | 992 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 } | 1025 } |
1026 | 1026 |
1027 TEST_F(MediaCodecPlayerTest, VideoNoPermission) { | 1027 TEST_F(MediaCodecPlayerTest, VideoNoPermission) { |
1028 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1028 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
1029 | 1029 |
1030 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); | 1030 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(500); |
1031 const base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); | 1031 const base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); |
1032 | 1032 |
1033 manager_.SetPlaybackAllowed(false); | 1033 manager_.SetPlaybackAllowed(false); |
1034 | 1034 |
1035 demuxer_->SetVideoFactory(base::WrapUnique(new VideoFactory(duration))); | 1035 demuxer_->SetVideoFactory(base::MakeUnique<VideoFactory>(duration)); |
1036 | 1036 |
1037 CreatePlayer(); | 1037 CreatePlayer(); |
1038 | 1038 |
1039 // Wait till the player is initialized on media thread. | 1039 // Wait till the player is initialized on media thread. |
1040 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, | 1040 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, |
1041 base::Unretained(demuxer_)))); | 1041 base::Unretained(demuxer_)))); |
1042 | 1042 |
1043 SetVideoSurface(); | 1043 SetVideoSurface(); |
1044 | 1044 |
1045 // Post configuration after the player has been initialized. | 1045 // Post configuration after the player has been initialized. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 | 1117 |
1118 TEST_F(MediaCodecPlayerTest, DISABLED_AudioSeekThenPlay) { | 1118 TEST_F(MediaCodecPlayerTest, DISABLED_AudioSeekThenPlay) { |
1119 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1119 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
1120 | 1120 |
1121 // Issue Seek command immediately followed by Start. The playback should | 1121 // Issue Seek command immediately followed by Start. The playback should |
1122 // start at the seek position. | 1122 // start at the seek position. |
1123 | 1123 |
1124 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000); | 1124 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000); |
1125 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(500); | 1125 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(500); |
1126 | 1126 |
1127 demuxer_->SetAudioFactory(base::WrapUnique(new AudioFactory(duration))); | 1127 demuxer_->SetAudioFactory(base::MakeUnique<AudioFactory>(duration)); |
1128 | 1128 |
1129 CreatePlayer(); | 1129 CreatePlayer(); |
1130 | 1130 |
1131 // Post configuration. | 1131 // Post configuration. |
1132 demuxer_->PostInternalConfigs(); | 1132 demuxer_->PostInternalConfigs(); |
1133 | 1133 |
1134 // Seek and immediately start. | 1134 // Seek and immediately start. |
1135 player_->SeekTo(seek_position); | 1135 player_->SeekTo(seek_position); |
1136 player_->Start(); | 1136 player_->Start(); |
1137 | 1137 |
(...skipping 13 matching lines...) Expand all Loading... |
1151 TEST_F(MediaCodecPlayerTest, DISABLED_AudioSeekThenPlayThenConfig) { | 1151 TEST_F(MediaCodecPlayerTest, DISABLED_AudioSeekThenPlayThenConfig) { |
1152 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1152 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
1153 | 1153 |
1154 // Issue Seek command immediately followed by Start but without prior demuxer | 1154 // Issue Seek command immediately followed by Start but without prior demuxer |
1155 // configuration. Start should wait for configuration. After it has been | 1155 // configuration. Start should wait for configuration. After it has been |
1156 // posted the playback should start at the seek position. | 1156 // posted the playback should start at the seek position. |
1157 | 1157 |
1158 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000); | 1158 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(2000); |
1159 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(500); | 1159 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(500); |
1160 | 1160 |
1161 demuxer_->SetAudioFactory(base::WrapUnique(new AudioFactory(duration))); | 1161 demuxer_->SetAudioFactory(base::MakeUnique<AudioFactory>(duration)); |
1162 | 1162 |
1163 CreatePlayer(); | 1163 CreatePlayer(); |
1164 | 1164 |
1165 // Seek and immediately start. | 1165 // Seek and immediately start. |
1166 player_->SeekTo(seek_position); | 1166 player_->SeekTo(seek_position); |
1167 player_->Start(); | 1167 player_->Start(); |
1168 | 1168 |
1169 // Make sure the player is waiting. | 1169 // Make sure the player is waiting. |
1170 WaitForDelay(base::TimeDelta::FromMilliseconds(200)); | 1170 WaitForDelay(base::TimeDelta::FromMilliseconds(200)); |
1171 EXPECT_FALSE(player_->IsPlaying()); | 1171 EXPECT_FALSE(player_->IsPlaying()); |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 base::TimeDelta audio_duration = base::TimeDelta::FromMilliseconds(1100); | 1758 base::TimeDelta audio_duration = base::TimeDelta::FromMilliseconds(1100); |
1759 base::TimeDelta video_duration = base::TimeDelta::FromMilliseconds(900); | 1759 base::TimeDelta video_duration = base::TimeDelta::FromMilliseconds(900); |
1760 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); | 1760 base::TimeDelta seek_position = base::TimeDelta::FromMilliseconds(1000); |
1761 base::TimeDelta video_preroll_intvl = base::TimeDelta::FromMilliseconds(200); | 1761 base::TimeDelta video_preroll_intvl = base::TimeDelta::FromMilliseconds(200); |
1762 | 1762 |
1763 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); | 1763 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(800); |
1764 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(400); | 1764 base::TimeDelta preroll_timeout = base::TimeDelta::FromMilliseconds(400); |
1765 | 1765 |
1766 demuxer_->SetVideoPrerollInterval(video_preroll_intvl); | 1766 demuxer_->SetVideoPrerollInterval(video_preroll_intvl); |
1767 | 1767 |
1768 demuxer_->SetAudioFactory(base::WrapUnique(new AudioFactory(audio_duration))); | 1768 demuxer_->SetAudioFactory(base::MakeUnique<AudioFactory>(audio_duration)); |
1769 demuxer_->SetVideoFactory(base::WrapUnique(new VideoFactory(video_duration))); | 1769 demuxer_->SetVideoFactory(base::MakeUnique<VideoFactory>(video_duration)); |
1770 | 1770 |
1771 CreatePlayer(); | 1771 CreatePlayer(); |
1772 SetVideoSurface(); | 1772 SetVideoSurface(); |
1773 | 1773 |
1774 // Set special testing callback to receive PTS from decoders. | 1774 // Set special testing callback to receive PTS from decoders. |
1775 player_->SetDecodersTimeCallbackForTests( | 1775 player_->SetDecodersTimeCallbackForTests( |
1776 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, | 1776 base::Bind(&MockMediaPlayerManager::OnDecodersTimeUpdate, |
1777 base::Unretained(&manager_))); | 1777 base::Unretained(&manager_))); |
1778 | 1778 |
1779 // Wait till the player is initialized on media thread. | 1779 // Wait till the player is initialized on media thread. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 // Test that video only playback continues after video config change. | 1834 // Test that video only playback continues after video config change. |
1835 | 1835 |
1836 // Initialize video playback | 1836 // Initialize video playback |
1837 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); | 1837 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(1200); |
1838 base::TimeDelta config_change_position = | 1838 base::TimeDelta config_change_position = |
1839 base::TimeDelta::FromMilliseconds(1000); | 1839 base::TimeDelta::FromMilliseconds(1000); |
1840 | 1840 |
1841 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000); | 1841 base::TimeDelta start_timeout = base::TimeDelta::FromMilliseconds(2000); |
1842 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); | 1842 base::TimeDelta completion_timeout = base::TimeDelta::FromMilliseconds(3000); |
1843 | 1843 |
1844 demuxer_->SetVideoFactory(base::WrapUnique(new VideoFactory(duration))); | 1844 demuxer_->SetVideoFactory(base::MakeUnique<VideoFactory>(duration)); |
1845 | 1845 |
1846 demuxer_->video_factory()->RequestConfigChange(config_change_position); | 1846 demuxer_->video_factory()->RequestConfigChange(config_change_position); |
1847 | 1847 |
1848 CreatePlayer(); | 1848 CreatePlayer(); |
1849 SetVideoSurface(); | 1849 SetVideoSurface(); |
1850 | 1850 |
1851 // Wait till the player is initialized on media thread. | 1851 // Wait till the player is initialized on media thread. |
1852 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, | 1852 EXPECT_TRUE(WaitForCondition(base::Bind(&MockDemuxerAndroid::IsInitialized, |
1853 base::Unretained(demuxer_)))); | 1853 base::Unretained(demuxer_)))); |
1854 | 1854 |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2274 // TODO(timav): maybe we should not call the testing callback for | 2274 // TODO(timav): maybe we should not call the testing callback for |
2275 // kRenderAfterPreroll for video (for audio we already do not call). | 2275 // kRenderAfterPreroll for video (for audio we already do not call). |
2276 // EXPECT_TRUE(AlmostEqual(manager_.FirstFrameTime(DemuxerStream::AUDIO), | 2276 // EXPECT_TRUE(AlmostEqual(manager_.FirstFrameTime(DemuxerStream::AUDIO), |
2277 // manager_.FirstFrameTime(DemuxerStream::VIDEO), 50)); | 2277 // manager_.FirstFrameTime(DemuxerStream::VIDEO), 50)); |
2278 | 2278 |
2279 // The playback should start at |seek_position| | 2279 // The playback should start at |seek_position| |
2280 EXPECT_TRUE(AlmostEqual(seek_position, manager_.pts_stat_.min(), 25)); | 2280 EXPECT_TRUE(AlmostEqual(seek_position, manager_.pts_stat_.min(), 25)); |
2281 } | 2281 } |
2282 | 2282 |
2283 } // namespace media | 2283 } // namespace media |
OLD | NEW |