| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 EXPECT_EQ(audio_codec, kCodecAAC); | 278 EXPECT_EQ(audio_codec, kCodecAAC); |
| 279 | 279 |
| 280 configs.audio_sampling_rate = 48000; | 280 configs.audio_sampling_rate = 48000; |
| 281 uint8 aac_extra_data[] = { 0x13, 0x10 }; | 281 uint8 aac_extra_data[] = { 0x13, 0x10 }; |
| 282 configs.audio_extra_data = std::vector<uint8>( | 282 configs.audio_extra_data = std::vector<uint8>( |
| 283 aac_extra_data, | 283 aac_extra_data, |
| 284 aac_extra_data + 2); | 284 aac_extra_data + 2); |
| 285 return configs; | 285 return configs; |
| 286 } | 286 } |
| 287 | 287 |
| 288 DemuxerConfigs CreateVideoDemuxerConfigs(VideoCodec video_codec) { | 288 DemuxerConfigs CreateVideoDemuxerConfigs(bool use_larger_size) { |
| 289 DemuxerConfigs configs; | 289 DemuxerConfigs configs; |
| 290 configs.video_codec = video_codec; | 290 configs.video_codec = kCodecVP8; |
| 291 configs.video_size = gfx::Size(320, 240); | 291 configs.video_size = |
| 292 use_larger_size ? gfx::Size(640, 480) : gfx::Size(320, 240); |
| 292 configs.is_video_encrypted = false; | 293 configs.is_video_encrypted = false; |
| 293 configs.duration = kDefaultDuration; | 294 configs.duration = kDefaultDuration; |
| 294 return configs; | 295 return configs; |
| 295 } | 296 } |
| 296 | 297 |
| 297 DemuxerConfigs CreateAudioVideoDemuxerConfigs() { | 298 DemuxerConfigs CreateAudioVideoDemuxerConfigs() { |
| 298 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false); | 299 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false); |
| 299 configs.video_codec = kCodecVP8; | 300 configs.video_codec = kCodecVP8; |
| 300 configs.video_size = gfx::Size(320, 240); | 301 configs.video_size = gfx::Size(320, 240); |
| 301 configs.is_video_encrypted = false; | 302 configs.is_video_encrypted = false; |
| 302 return configs; | 303 return configs; |
| 303 } | 304 } |
| 304 | 305 |
| 305 DemuxerConfigs CreateDemuxerConfigs(bool have_audio, bool have_video) { | 306 DemuxerConfigs CreateDemuxerConfigs(bool have_audio, bool have_video) { |
| 306 DCHECK(have_audio || have_video); | 307 DCHECK(have_audio || have_video); |
| 307 | 308 |
| 308 if (have_audio && !have_video) | 309 if (have_audio && !have_video) |
| 309 return CreateAudioDemuxerConfigs(kCodecVorbis, false); | 310 return CreateAudioDemuxerConfigs(kCodecVorbis, false); |
| 310 | 311 |
| 311 if (have_video && !have_audio) | 312 if (have_video && !have_audio) |
| 312 return CreateVideoDemuxerConfigs(kCodecVP8); | 313 return CreateVideoDemuxerConfigs(false); |
| 313 | 314 |
| 314 return CreateAudioVideoDemuxerConfigs(); | 315 return CreateAudioVideoDemuxerConfigs(); |
| 315 } | 316 } |
| 316 | 317 |
| 317 // Starts an audio decoder job. | 318 // Starts an audio decoder job. |
| 318 void StartAudioDecoderJob() { | 319 void StartAudioDecoderJob() { |
| 319 Start(CreateAudioDemuxerConfigs(kCodecVorbis, false)); | 320 Start(CreateAudioDemuxerConfigs(kCodecVorbis, false)); |
| 320 } | 321 } |
| 321 | 322 |
| 322 // Starts a video decoder job. | 323 // Starts a video decoder job. |
| 323 void StartVideoDecoderJob() { | 324 void StartVideoDecoderJob() { |
| 324 Start(CreateVideoDemuxerConfigs(kCodecVP8)); | 325 Start(CreateVideoDemuxerConfigs(false)); |
| 325 } | 326 } |
| 326 | 327 |
| 327 // Starts decoding the data. | 328 // Starts decoding the data. |
| 328 void Start(const DemuxerConfigs& configs) { | 329 void Start(const DemuxerConfigs& configs) { |
| 329 EXPECT_EQ(demuxer_->num_data_requests(), 0); | 330 EXPECT_EQ(demuxer_->num_data_requests(), 0); |
| 330 player_.OnDemuxerConfigsAvailable(configs); | 331 player_.OnDemuxerConfigsAvailable(configs); |
| 331 player_.Start(); | 332 player_.Start(); |
| 332 | 333 |
| 333 EXPECT_TRUE(player_.IsPlaying()); | 334 EXPECT_TRUE(player_.IsPlaying()); |
| 334 int expected_num_requests = (player_.HasAudio() ? 1 : 0) + | 335 int expected_num_requests = (player_.HasAudio() ? 1 : 0) + |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 | 638 |
| 638 WaitForDecodeDone(is_audio, !is_audio); | 639 WaitForDecodeDone(is_audio, !is_audio); |
| 639 | 640 |
| 640 // We should have completed the prefetch phase at this point. | 641 // We should have completed the prefetch phase at this point. |
| 641 expected_num_data_requests++; | 642 expected_num_data_requests++; |
| 642 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); | 643 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); |
| 643 } | 644 } |
| 644 | 645 |
| 645 DemuxerConfigs configs = is_audio ? | 646 DemuxerConfigs configs = is_audio ? |
| 646 CreateAudioDemuxerConfigs(kCodecAAC, false) : | 647 CreateAudioDemuxerConfigs(kCodecAAC, false) : |
| 647 CreateVideoDemuxerConfigs(kCodecVP9); | 648 CreateVideoDemuxerConfigs(true); |
| 648 // Feed and decode access units with data for any units prior to | 649 // Feed and decode access units with data for any units prior to |
| 649 // |config_unit_index|, and a |kConfigChanged| unit at that index. | 650 // |config_unit_index|, and a |kConfigChanged| unit at that index. |
| 650 // Player should prepare to reconfigure the decoder job, and should request | 651 // Player should prepare to reconfigure the decoder job, and should request |
| 651 // new demuxer configs. | 652 // new demuxer configs. |
| 652 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( | 653 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( |
| 653 is_audio, config_unit_index, configs)); | 654 is_audio, config_unit_index, configs)); |
| 654 | 655 |
| 655 expected_num_data_requests++; | 656 expected_num_data_requests++; |
| 656 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); | 657 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); |
| 657 if (is_audio) | 658 if (is_audio) |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 // Test decoder job will resend a ReadFromDemuxer request after seek. | 910 // Test decoder job will resend a ReadFromDemuxer request after seek. |
| 910 StartAudioDecoderJob(); | 911 StartAudioDecoderJob(); |
| 911 SeekPlayerWithAbort(true, base::TimeDelta()); | 912 SeekPlayerWithAbort(true, base::TimeDelta()); |
| 912 } | 913 } |
| 913 | 914 |
| 914 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { | 915 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { |
| 915 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 916 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 916 | 917 |
| 917 // Test SetVideoSurface() will not cause an extra seek while the player is | 918 // Test SetVideoSurface() will not cause an extra seek while the player is |
| 918 // waiting for demuxer to indicate seek is done. | 919 // waiting for demuxer to indicate seek is done. |
| 919 player_.OnDemuxerConfigsAvailable(CreateVideoDemuxerConfigs(kCodecVP8)); | 920 player_.OnDemuxerConfigsAvailable( |
| 921 CreateVideoDemuxerConfigs(false)); |
| 920 | 922 |
| 921 // Initiate a seek. Skip requesting element seek of renderer. | 923 // Initiate a seek. Skip requesting element seek of renderer. |
| 922 // Instead behave as if the renderer has asked us to seek. | 924 // Instead behave as if the renderer has asked us to seek. |
| 923 player_.SeekTo(base::TimeDelta()); | 925 player_.SeekTo(base::TimeDelta()); |
| 924 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 926 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 925 | 927 |
| 926 CreateNextTextureAndSetVideoSurface(); | 928 CreateNextTextureAndSetVideoSurface(); |
| 927 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 929 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 928 player_.Start(); | 930 player_.Start(); |
| 929 | 931 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 // Decoder is created after data is received. | 1068 // Decoder is created after data is received. |
| 1067 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); | 1069 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); |
| 1068 EXPECT_TRUE(GetMediaCodecBridge(true)); | 1070 EXPECT_TRUE(GetMediaCodecBridge(true)); |
| 1069 } | 1071 } |
| 1070 | 1072 |
| 1071 TEST_F(MediaSourcePlayerTest, VideoOnlyStartAfterSeekFinish) { | 1073 TEST_F(MediaSourcePlayerTest, VideoOnlyStartAfterSeekFinish) { |
| 1072 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1074 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1073 | 1075 |
| 1074 // Test video decoder job will not start until pending seek event is handled. | 1076 // Test video decoder job will not start until pending seek event is handled. |
| 1075 CreateNextTextureAndSetVideoSurface(); | 1077 CreateNextTextureAndSetVideoSurface(); |
| 1076 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP8); | 1078 DemuxerConfigs configs = CreateVideoDemuxerConfigs(false); |
| 1077 player_.OnDemuxerConfigsAvailable(configs); | 1079 player_.OnDemuxerConfigsAvailable(configs); |
| 1078 | 1080 |
| 1079 // Initiate a seek. Skip requesting element seek of renderer. | 1081 // Initiate a seek. Skip requesting element seek of renderer. |
| 1080 // Instead behave as if the renderer has asked us to seek. | 1082 // Instead behave as if the renderer has asked us to seek. |
| 1081 player_.SeekTo(base::TimeDelta()); | 1083 player_.SeekTo(base::TimeDelta()); |
| 1082 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1084 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1083 | 1085 |
| 1084 player_.Start(); | 1086 player_.Start(); |
| 1085 EXPECT_EQ(0, demuxer_->num_data_requests()); | 1087 EXPECT_EQ(0, demuxer_->num_data_requests()); |
| 1086 | 1088 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1237 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1236 | 1238 |
| 1237 // Test that if one stream (audio) has completed decode of EOS and the other | 1239 // Test that if one stream (audio) has completed decode of EOS and the other |
| 1238 // stream (video) processes config change, that subsequent video EOS completes | 1240 // stream (video) processes config change, that subsequent video EOS completes |
| 1239 // A/V playback. | 1241 // A/V playback. |
| 1240 // Also tests that seeking+Start() after completing playback resumes playback. | 1242 // Also tests that seeking+Start() after completing playback resumes playback. |
| 1241 CreateNextTextureAndSetVideoSurface(); | 1243 CreateNextTextureAndSetVideoSurface(); |
| 1242 Start(CreateAudioVideoDemuxerConfigs()); | 1244 Start(CreateAudioVideoDemuxerConfigs()); |
| 1243 | 1245 |
| 1244 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS | 1246 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS |
| 1245 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP9); | 1247 DemuxerConfigs configs = CreateVideoDemuxerConfigs(true); |
| 1246 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( | 1248 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( |
| 1247 false, 0, configs)); // Video |kConfigChanged| as first unit. | 1249 false, 0, configs)); // Video |kConfigChanged| as first unit. |
| 1248 | 1250 |
| 1249 WaitForAudioVideoDecodeDone(); | 1251 WaitForAudioVideoDecodeDone(); |
| 1250 | 1252 |
| 1251 EXPECT_EQ(3, demuxer_->num_data_requests()); | 1253 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1252 | 1254 |
| 1253 // At no time after completing audio EOS decode, above, should the | 1255 // At no time after completing audio EOS decode, above, should the |
| 1254 // audio decoder job resume decoding. Send and decode video EOS. | 1256 // audio decoder job resume decoding. Send and decode video EOS. |
| 1255 VerifyPlaybackCompletesOnEOSDecode(true, false); | 1257 VerifyPlaybackCompletesOnEOSDecode(true, false); |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1660 WaitForAudioVideoDecodeDone(); | 1662 WaitForAudioVideoDecodeDone(); |
| 1661 | 1663 |
| 1662 // Simulate audio |kConfigChanged| prefetched as standalone access unit. | 1664 // Simulate audio |kConfigChanged| prefetched as standalone access unit. |
| 1663 DemuxerConfigs audio_configs = CreateAudioDemuxerConfigs(kCodecVorbis, true); | 1665 DemuxerConfigs audio_configs = CreateAudioDemuxerConfigs(kCodecVorbis, true); |
| 1664 player_.OnDemuxerDataAvailable( | 1666 player_.OnDemuxerDataAvailable( |
| 1665 CreateReadFromDemuxerAckWithConfigChanged(true, 0, audio_configs)); | 1667 CreateReadFromDemuxerAckWithConfigChanged(true, 0, audio_configs)); |
| 1666 | 1668 |
| 1667 // Simulate video |kConfigChanged| prefetched as standalone access unit. | 1669 // Simulate video |kConfigChanged| prefetched as standalone access unit. |
| 1668 player_.OnDemuxerDataAvailable( | 1670 player_.OnDemuxerDataAvailable( |
| 1669 CreateReadFromDemuxerAckWithConfigChanged( | 1671 CreateReadFromDemuxerAckWithConfigChanged( |
| 1670 false, 0, CreateVideoDemuxerConfigs(kCodecVP9))); | 1672 false, 0, CreateVideoDemuxerConfigs(true))); |
| 1671 EXPECT_EQ(6, demuxer_->num_data_requests()); | 1673 EXPECT_EQ(6, demuxer_->num_data_requests()); |
| 1672 EXPECT_TRUE(IsDrainingDecoder(true)); | 1674 EXPECT_TRUE(IsDrainingDecoder(true)); |
| 1673 EXPECT_TRUE(IsDrainingDecoder(false)); | 1675 EXPECT_TRUE(IsDrainingDecoder(false)); |
| 1674 | 1676 |
| 1675 // Waiting for decoder to finish draining. | 1677 // Waiting for decoder to finish draining. |
| 1676 while (IsDrainingDecoder(true) || IsDrainingDecoder(false)) | 1678 while (IsDrainingDecoder(true) || IsDrainingDecoder(false)) |
| 1677 message_loop_.RunUntilIdle(); | 1679 message_loop_.RunUntilIdle(); |
| 1678 } | 1680 } |
| 1679 | 1681 |
| 1680 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) { | 1682 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) { |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2084 // also verify that the job is successfully created if SetDrmBridge(), Start() | 2086 // also verify that the job is successfully created if SetDrmBridge(), Start() |
| 2085 // and eventually OnMediaCrypto() occur. This would increase test coverage of | 2087 // and eventually OnMediaCrypto() occur. This would increase test coverage of |
| 2086 // http://crbug.com/313470 and allow us to remove inspection of internal player | 2088 // http://crbug.com/313470 and allow us to remove inspection of internal player |
| 2087 // pending event state. See http://crbug.com/313860. | 2089 // pending event state. See http://crbug.com/313860. |
| 2088 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) { | 2090 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) { |
| 2089 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 2091 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 2090 | 2092 |
| 2091 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after | 2093 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after |
| 2092 // SetVideoSurface() for a player configured for encrypted video, when the | 2094 // SetVideoSurface() for a player configured for encrypted video, when the |
| 2093 // player has not yet received media crypto. | 2095 // player has not yet received media crypto. |
| 2094 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP8); | 2096 DemuxerConfigs configs = CreateVideoDemuxerConfigs(false); |
| 2095 configs.is_video_encrypted = true; | 2097 configs.is_video_encrypted = true; |
| 2096 | 2098 |
| 2097 player_.OnDemuxerConfigsAvailable(configs); | 2099 player_.OnDemuxerConfigsAvailable(configs); |
| 2098 CreateNextTextureAndSetVideoSurface(); | 2100 CreateNextTextureAndSetVideoSurface(); |
| 2099 EXPECT_FALSE(GetMediaCodecBridge(false)); | 2101 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 2100 } | 2102 } |
| 2101 | 2103 |
| 2102 TEST_F(MediaSourcePlayerTest, CurrentTimeUpdatedWhileDecoderStarved) { | 2104 TEST_F(MediaSourcePlayerTest, CurrentTimeUpdatedWhileDecoderStarved) { |
| 2103 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 2105 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 2104 | 2106 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2127 | 2129 |
| 2128 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, true); | 2130 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, true); |
| 2129 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged( | 2131 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged( |
| 2130 true, 0, configs); | 2132 true, 0, configs); |
| 2131 player_.OnDemuxerDataAvailable(data); | 2133 player_.OnDemuxerDataAvailable(data); |
| 2132 WaitForAudioDecodeDone(); | 2134 WaitForAudioDecodeDone(); |
| 2133 DecodeAudioDataUntilOutputBecomesAvailable(); | 2135 DecodeAudioDataUntilOutputBecomesAvailable(); |
| 2134 } | 2136 } |
| 2135 | 2137 |
| 2136 } // namespace media | 2138 } // namespace media |
| OLD | NEW |