| 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 "media/base/android/media_source_player.h" | 5 #include "media/base/android/media_source_player.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 } | 698 } |
| 699 | 699 |
| 700 void EnableAdaptiveVideoPlayback(bool enable) { | 700 void EnableAdaptiveVideoPlayback(bool enable) { |
| 701 EXPECT_TRUE(GetMediaCodecBridge(false)); | 701 EXPECT_TRUE(GetMediaCodecBridge(false)); |
| 702 static_cast<VideoCodecBridge*>(GetMediaCodecBridge(false))-> | 702 static_cast<VideoCodecBridge*>(GetMediaCodecBridge(false))-> |
| 703 set_adaptive_playback_supported_for_testing( | 703 set_adaptive_playback_supported_for_testing( |
| 704 enable ? 1 : 0); | 704 enable ? 1 : 0); |
| 705 } | 705 } |
| 706 | 706 |
| 707 void CreateNextTextureAndSetVideoSurface() { | 707 void CreateNextTextureAndSetVideoSurface() { |
| 708 gfx::SurfaceTexture* surface_texture; | 708 gl::SurfaceTexture* surface_texture; |
| 709 if (surface_texture_a_is_next_) { | 709 if (surface_texture_a_is_next_) { |
| 710 surface_texture_a_ = gfx::SurfaceTexture::Create(next_texture_id_++); | 710 surface_texture_a_ = gl::SurfaceTexture::Create(next_texture_id_++); |
| 711 surface_texture = surface_texture_a_.get(); | 711 surface_texture = surface_texture_a_.get(); |
| 712 } else { | 712 } else { |
| 713 surface_texture_b_ = gfx::SurfaceTexture::Create(next_texture_id_++); | 713 surface_texture_b_ = gl::SurfaceTexture::Create(next_texture_id_++); |
| 714 surface_texture = surface_texture_b_.get(); | 714 surface_texture = surface_texture_b_.get(); |
| 715 } | 715 } |
| 716 | 716 |
| 717 surface_texture_a_is_next_ = !surface_texture_a_is_next_; | 717 surface_texture_a_is_next_ = !surface_texture_a_is_next_; |
| 718 gfx::ScopedJavaSurface surface = gfx::ScopedJavaSurface(surface_texture); | 718 gl::ScopedJavaSurface surface = gl::ScopedJavaSurface(surface_texture); |
| 719 player_.SetVideoSurface(std::move(surface)); | 719 player_.SetVideoSurface(std::move(surface)); |
| 720 } | 720 } |
| 721 | 721 |
| 722 // Wait for one or both of the jobs to complete decoding. Media codec bridges | 722 // Wait for one or both of the jobs to complete decoding. Media codec bridges |
| 723 // are assumed to exist for any stream whose decode completion is awaited. | 723 // are assumed to exist for any stream whose decode completion is awaited. |
| 724 void WaitForDecodeDone(bool wait_for_audio, bool wait_for_video) { | 724 void WaitForDecodeDone(bool wait_for_audio, bool wait_for_video) { |
| 725 DCHECK(wait_for_audio || wait_for_video); | 725 DCHECK(wait_for_audio || wait_for_video); |
| 726 while ((wait_for_audio && GetMediaCodecBridge(true) && | 726 while ((wait_for_audio && GetMediaCodecBridge(true) && |
| 727 GetMediaDecoderJob(true)->HasData() && | 727 GetMediaDecoderJob(true)->HasData() && |
| 728 GetMediaDecoderJob(true)->is_decoding()) || | 728 GetMediaDecoderJob(true)->is_decoding()) || |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 // Track whether a possibly async decoder callback test hook has run. | 846 // Track whether a possibly async decoder callback test hook has run. |
| 847 bool decoder_callback_hook_executed_; | 847 bool decoder_callback_hook_executed_; |
| 848 | 848 |
| 849 // We need to keep the surface texture while the decoder is actively decoding. | 849 // We need to keep the surface texture while the decoder is actively decoding. |
| 850 // Otherwise, it may trigger unexpected crashes on some devices. To switch | 850 // Otherwise, it may trigger unexpected crashes on some devices. To switch |
| 851 // surfaces, tests need to create a new surface texture without releasing | 851 // surfaces, tests need to create a new surface texture without releasing |
| 852 // their previous one. In CreateNextTextureAndSetVideoSurface(), we toggle | 852 // their previous one. In CreateNextTextureAndSetVideoSurface(), we toggle |
| 853 // between two surface textures, only replacing the N-2 texture. Assumption is | 853 // between two surface textures, only replacing the N-2 texture. Assumption is |
| 854 // that no more than N-1 texture is in use by decoder when | 854 // that no more than N-1 texture is in use by decoder when |
| 855 // CreateNextTextureAndSetVideoSurface() is called. | 855 // CreateNextTextureAndSetVideoSurface() is called. |
| 856 scoped_refptr<gfx::SurfaceTexture> surface_texture_a_; | 856 scoped_refptr<gl::SurfaceTexture> surface_texture_a_; |
| 857 scoped_refptr<gfx::SurfaceTexture> surface_texture_b_; | 857 scoped_refptr<gl::SurfaceTexture> surface_texture_b_; |
| 858 bool surface_texture_a_is_next_; | 858 bool surface_texture_a_is_next_; |
| 859 int next_texture_id_; | 859 int next_texture_id_; |
| 860 | 860 |
| 861 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest); | 861 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayerTest); |
| 862 }; | 862 }; |
| 863 | 863 |
| 864 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) { | 864 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithValidConfig) { |
| 865 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 865 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 866 | 866 |
| 867 // Test audio codec will be created when valid configs and data are passed to | 867 // Test audio codec will be created when valid configs and data are passed to |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 // Send the first input chunk and verify that decoder will be created. | 910 // Send the first input chunk and verify that decoder will be created. |
| 911 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); | 911 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); |
| 912 EXPECT_TRUE(GetMediaCodecBridge(false)); | 912 EXPECT_TRUE(GetMediaCodecBridge(false)); |
| 913 WaitForVideoDecodeDone(); | 913 WaitForVideoDecodeDone(); |
| 914 } | 914 } |
| 915 | 915 |
| 916 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { | 916 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { |
| 917 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 917 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 918 | 918 |
| 919 // Test video codec will not be created when surface is invalid. | 919 // Test video codec will not be created when surface is invalid. |
| 920 scoped_refptr<gfx::SurfaceTexture> surface_texture( | 920 scoped_refptr<gl::SurfaceTexture> surface_texture( |
| 921 gfx::SurfaceTexture::Create(0)); | 921 gl::SurfaceTexture::Create(0)); |
| 922 gfx::ScopedJavaSurface surface(surface_texture.get()); | 922 gl::ScopedJavaSurface surface(surface_texture.get()); |
| 923 StartVideoDecoderJob(); | 923 StartVideoDecoderJob(); |
| 924 | 924 |
| 925 // Release the surface texture. | 925 // Release the surface texture. |
| 926 surface_texture = NULL; | 926 surface_texture = NULL; |
| 927 player_.SetVideoSurface(std::move(surface)); | 927 player_.SetVideoSurface(std::move(surface)); |
| 928 | 928 |
| 929 // Player should not seek the demuxer on setting initial surface. | 929 // Player should not seek the demuxer on setting initial surface. |
| 930 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 930 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
| 931 EXPECT_EQ(1, demuxer_->num_data_requests()); | 931 EXPECT_EQ(1, demuxer_->num_data_requests()); |
| 932 | 932 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 // Test MediaSourcePlayer can switch multiple surfaces during decoding. | 981 // Test MediaSourcePlayer can switch multiple surfaces during decoding. |
| 982 CreateNextTextureAndSetVideoSurface(); | 982 CreateNextTextureAndSetVideoSurface(); |
| 983 StartVideoDecoderJob(); | 983 StartVideoDecoderJob(); |
| 984 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 984 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
| 985 | 985 |
| 986 // Send the first input chunk. | 986 // Send the first input chunk. |
| 987 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); | 987 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); |
| 988 | 988 |
| 989 // While the decoder is decoding, change multiple surfaces. Pass an empty | 989 // While the decoder is decoding, change multiple surfaces. Pass an empty |
| 990 // surface first. | 990 // surface first. |
| 991 gfx::ScopedJavaSurface empty_surface; | 991 gl::ScopedJavaSurface empty_surface; |
| 992 player_.SetVideoSurface(std::move(empty_surface)); | 992 player_.SetVideoSurface(std::move(empty_surface)); |
| 993 // Next, pass a new non-empty surface. | 993 // Next, pass a new non-empty surface. |
| 994 CreateNextTextureAndSetVideoSurface(); | 994 CreateNextTextureAndSetVideoSurface(); |
| 995 | 995 |
| 996 // Wait for the media codec bridge to finish decoding and be reset pending a | 996 // Wait for the media codec bridge to finish decoding and be reset pending a |
| 997 // browser seek. | 997 // browser seek. |
| 998 WaitForVideoDecodeDone(); | 998 WaitForVideoDecodeDone(); |
| 999 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); | 999 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); |
| 1000 | 1000 |
| 1001 // Only one browser seek should have been initiated. No further data request | 1001 // Only one browser seek should have been initiated. No further data request |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1022 | 1022 |
| 1023 // Test player pauses if an empty surface is passed. | 1023 // Test player pauses if an empty surface is passed. |
| 1024 CreateNextTextureAndSetVideoSurface(); | 1024 CreateNextTextureAndSetVideoSurface(); |
| 1025 StartVideoDecoderJob(); | 1025 StartVideoDecoderJob(); |
| 1026 EXPECT_EQ(1, demuxer_->num_data_requests()); | 1026 EXPECT_EQ(1, demuxer_->num_data_requests()); |
| 1027 | 1027 |
| 1028 // Send the first input chunk. | 1028 // Send the first input chunk. |
| 1029 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); | 1029 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); |
| 1030 | 1030 |
| 1031 // While the decoder is decoding, pass an empty surface. | 1031 // While the decoder is decoding, pass an empty surface. |
| 1032 gfx::ScopedJavaSurface empty_surface; | 1032 gl::ScopedJavaSurface empty_surface; |
| 1033 player_.SetVideoSurface(std::move(empty_surface)); | 1033 player_.SetVideoSurface(std::move(empty_surface)); |
| 1034 // Let the player starve. However, it should not issue any new data request in | 1034 // Let the player starve. However, it should not issue any new data request in |
| 1035 // this case. | 1035 // this case. |
| 1036 TriggerPlayerStarvation(); | 1036 TriggerPlayerStarvation(); |
| 1037 // Wait for the media codec bridge to finish decoding and be reset. | 1037 // Wait for the media codec bridge to finish decoding and be reset. |
| 1038 while (GetMediaDecoderJob(false)->is_decoding()) | 1038 while (GetMediaDecoderJob(false)->is_decoding()) |
| 1039 message_loop_.RunUntilIdle(); | 1039 message_loop_.RunUntilIdle(); |
| 1040 | 1040 |
| 1041 // No further seek or data requests should have been received since the | 1041 // No further seek or data requests should have been received since the |
| 1042 // surface is empty. | 1042 // surface is empty. |
| (...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2418 | 2418 |
| 2419 EXPECT_EQ(demuxer_->num_data_requests(), 0); | 2419 EXPECT_EQ(demuxer_->num_data_requests(), 0); |
| 2420 player_.OnDemuxerConfigsAvailable(CreateDemuxerConfigs(true, true)); | 2420 player_.OnDemuxerConfigsAvailable(CreateDemuxerConfigs(true, true)); |
| 2421 | 2421 |
| 2422 manager_.set_allow_play(true); | 2422 manager_.set_allow_play(true); |
| 2423 player_.Start(); | 2423 player_.Start(); |
| 2424 EXPECT_TRUE(player_.IsPlaying()); | 2424 EXPECT_TRUE(player_.IsPlaying()); |
| 2425 } | 2425 } |
| 2426 | 2426 |
| 2427 } // namespace media | 2427 } // namespace media |
| OLD | NEW |