Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: media/base/android/media_source_player_unittest.cc

Issue 1372203002: Throttle media decoding after excessive Android media server crashes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new infobar text per UI review Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/android/media_source_player.cc ('k') | media/base/android/video_decoder_job.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 38
39 // TODO(wolenetz/qinmin): Simplify tests with more effective mock usage, and 39 // TODO(wolenetz/qinmin): Simplify tests with more effective mock usage, and
40 // fix flaky pointer-based MDJ inequality testing. See http://crbug.com/327839. 40 // fix flaky pointer-based MDJ inequality testing. See http://crbug.com/327839.
41 41
42 // Mock of MediaPlayerManager for testing purpose. 42 // Mock of MediaPlayerManager for testing purpose.
43 class MockMediaPlayerManager : public MediaPlayerManager { 43 class MockMediaPlayerManager : public MediaPlayerManager {
44 public: 44 public:
45 explicit MockMediaPlayerManager(base::MessageLoop* message_loop) 45 explicit MockMediaPlayerManager(base::MessageLoop* message_loop)
46 : message_loop_(message_loop), 46 : message_loop_(message_loop),
47 playback_completed_(false), 47 playback_completed_(false),
48 num_resources_requested_(0),
49 num_metadata_changes_(0), 48 num_metadata_changes_(0),
50 timestamp_updated_(false), 49 timestamp_updated_(false),
51 allow_play_(true) {} 50 allow_play_(true) {}
52 ~MockMediaPlayerManager() override {} 51 ~MockMediaPlayerManager() override {}
53 52
54 // MediaPlayerManager implementation. 53 // MediaPlayerManager implementation.
55 MediaResourceGetter* GetMediaResourceGetter() override { return NULL; } 54 MediaResourceGetter* GetMediaResourceGetter() override { return NULL; }
56 MediaUrlInterceptor* GetMediaUrlInterceptor() override { return NULL; } 55 MediaUrlInterceptor* GetMediaUrlInterceptor() override { return NULL; }
57 void OnTimeUpdate(int player_id, 56 void OnTimeUpdate(int player_id,
58 base::TimeDelta current_time, 57 base::TimeDelta current_time,
(...skipping 14 matching lines...) Expand all
73 } 72 }
74 void OnMediaInterrupted(int player_id) override {} 73 void OnMediaInterrupted(int player_id) override {}
75 void OnBufferingUpdate(int player_id, int percentage) override {} 74 void OnBufferingUpdate(int player_id, int percentage) override {}
76 void OnSeekComplete(int player_id, 75 void OnSeekComplete(int player_id,
77 const base::TimeDelta& current_time) override {} 76 const base::TimeDelta& current_time) override {}
78 void OnError(int player_id, int error) override {} 77 void OnError(int player_id, int error) override {}
79 void OnVideoSizeChanged(int player_id, int width, int height) override {} 78 void OnVideoSizeChanged(int player_id, int width, int height) override {}
80 void OnWaitingForDecryptionKey(int player_id) override {} 79 void OnWaitingForDecryptionKey(int player_id) override {}
81 MediaPlayerAndroid* GetFullscreenPlayer() override { return NULL; } 80 MediaPlayerAndroid* GetFullscreenPlayer() override { return NULL; }
82 MediaPlayerAndroid* GetPlayer(int player_id) override { return NULL; } 81 MediaPlayerAndroid* GetPlayer(int player_id) override { return NULL; }
82 void OnDecorderResourcesReleased(int player_id) {}
83 83
84 bool RequestPlay(int player_id, base::TimeDelta duration) override { 84 bool RequestPlay(int player_id, base::TimeDelta duration) override {
85 return allow_play_; 85 return allow_play_;
86 } 86 }
87 87
88 bool playback_completed() const { 88 bool playback_completed() const {
89 return playback_completed_; 89 return playback_completed_;
90 } 90 }
91 91
92 int num_resources_requested() const {
93 return num_resources_requested_;
94 }
95
96 int num_metadata_changes() const { 92 int num_metadata_changes() const {
97 return num_metadata_changes_; 93 return num_metadata_changes_;
98 } 94 }
99 95
100 void OnMediaResourcesRequested(int player_id) {
101 num_resources_requested_++;
102 }
103
104 bool timestamp_updated() const { 96 bool timestamp_updated() const {
105 return timestamp_updated_; 97 return timestamp_updated_;
106 } 98 }
107 99
108 void ResetTimestampUpdated() { 100 void ResetTimestampUpdated() {
109 timestamp_updated_ = false; 101 timestamp_updated_ = false;
110 } 102 }
111 103
112 void set_allow_play(bool value) { 104 void set_allow_play(bool value) {
113 allow_play_ = value; 105 allow_play_ = value;
114 } 106 }
115 107
116 private: 108 private:
117 base::MessageLoop* message_loop_; 109 base::MessageLoop* message_loop_;
118 bool playback_completed_; 110 bool playback_completed_;
119 // The number of resource requests this object has seen.
120 int num_resources_requested_;
121 // The number of metadata changes reported by the player. 111 // The number of metadata changes reported by the player.
122 int num_metadata_changes_; 112 int num_metadata_changes_;
123 // Playback timestamp was updated. 113 // Playback timestamp was updated.
124 bool timestamp_updated_; 114 bool timestamp_updated_;
125 // Whether the manager will allow players that request playing. 115 // Whether the manager will allow players that request playing.
126 bool allow_play_; 116 bool allow_play_;
127 117
128 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager); 118 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager);
129 }; 119 };
130 120
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 158
169 DISALLOW_COPY_AND_ASSIGN(MockDemuxerAndroid); 159 DISALLOW_COPY_AND_ASSIGN(MockDemuxerAndroid);
170 }; 160 };
171 161
172 class MediaSourcePlayerTest : public testing::Test { 162 class MediaSourcePlayerTest : public testing::Test {
173 public: 163 public:
174 MediaSourcePlayerTest() 164 MediaSourcePlayerTest()
175 : manager_(&message_loop_), 165 : manager_(&message_loop_),
176 demuxer_(new MockDemuxerAndroid(&message_loop_)), 166 demuxer_(new MockDemuxerAndroid(&message_loop_)),
177 player_(0, &manager_, 167 player_(0, &manager_,
178 base::Bind(&MockMediaPlayerManager::OnMediaResourcesRequested, 168 base::Bind(&MockMediaPlayerManager::OnDecorderResourcesReleased,
179 base::Unretained(&manager_)), 169 base::Unretained(&manager_)),
180 scoped_ptr<DemuxerAndroid>(demuxer_), 170 scoped_ptr<DemuxerAndroid>(demuxer_),
181 GURL()), 171 GURL()),
182 decoder_callback_hook_executed_(false), 172 decoder_callback_hook_executed_(false),
183 surface_texture_a_is_next_(true) {} 173 surface_texture_a_is_next_(true) {}
184 174
185 ~MediaSourcePlayerTest() override {} 175 ~MediaSourcePlayerTest() override {}
186 176
187 protected: 177 protected:
188 // Get the decoder job from the MediaSourcePlayer. The return value must not 178 // Get the decoder job from the MediaSourcePlayer. The return value must not
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 WaitForVideoDecodeDone(); 1049 WaitForVideoDecodeDone();
1060 } 1050 }
1061 1051
1062 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) { 1052 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) {
1063 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1053 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1064 1054
1065 // Test that if video decoder is released while decoding, the resources will 1055 // Test that if video decoder is released while decoding, the resources will
1066 // not be immediately released. 1056 // not be immediately released.
1067 CreateNextTextureAndSetVideoSurface(); 1057 CreateNextTextureAndSetVideoSurface();
1068 StartVideoDecoderJob(); 1058 StartVideoDecoderJob();
1069 // No resource is requested since there is no data to decode.
1070 EXPECT_EQ(0, manager_.num_resources_requested());
1071 ReleasePlayer(); 1059 ReleasePlayer();
1072 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false)); 1060 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo(false));
1073 1061
1074 // Recreate the video decoder. 1062 // Recreate the video decoder.
1075 CreateNextTextureAndSetVideoSurface(); 1063 CreateNextTextureAndSetVideoSurface();
1076 player_.Start(); 1064 player_.Start();
1077 while (!GetMediaDecoderJob(false)->is_decoding()) 1065 while (!GetMediaDecoderJob(false)->is_decoding())
1078 message_loop_.RunUntilIdle(); 1066 message_loop_.RunUntilIdle();
1079 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 1067 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
1080 EXPECT_EQ(1, manager_.num_resources_requested());
1081 ReleasePlayer(); 1068 ReleasePlayer();
1082 // Wait for the media codec bridge to finish decoding and be reset. 1069 // Wait for the media codec bridge to finish decoding and be reset.
1083 while (GetMediaDecoderJob(false)->is_decoding()) 1070 while (GetMediaDecoderJob(false)->is_decoding())
1084 message_loop_.RunUntilIdle(); 1071 message_loop_.RunUntilIdle();
1085 } 1072 }
1086 1073
1087 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) { 1074 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) {
1088 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1075 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1089 1076
1090 // Test audio decoder job will not start until pending seek event is handled. 1077 // Test audio decoder job will not start until pending seek event is handled.
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 1919
1933 // Test that video config change notification results in creating a new 1920 // Test that video config change notification results in creating a new
1934 // video codec without any browser seek. 1921 // video codec without any browser seek.
1935 StartConfigChange(false, true, 1, false); 1922 StartConfigChange(false, true, 1, false);
1936 1923
1937 // New video codec should have been created and configured, without any 1924 // New video codec should have been created and configured, without any
1938 // browser seek. 1925 // browser seek.
1939 EXPECT_TRUE(GetMediaCodecBridge(false)); 1926 EXPECT_TRUE(GetMediaCodecBridge(false));
1940 EXPECT_EQ(3, demuxer_->num_data_requests()); 1927 EXPECT_EQ(3, demuxer_->num_data_requests());
1941 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1928 EXPECT_EQ(0, demuxer_->num_seek_requests());
1942
1943 // 2 codecs should have been created, one before the config change, and one
1944 // after it.
1945 EXPECT_EQ(2, manager_.num_resources_requested());
1946 WaitForVideoDecodeDone(); 1929 WaitForVideoDecodeDone();
1947 } 1930 }
1948 1931
1949 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChangeWithAdaptivePlayback) { 1932 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChangeWithAdaptivePlayback) {
1950 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1933 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1951 1934
1952 // Test that if codec supports adaptive playback, no new codec should be 1935 // Test that if codec supports adaptive playback, no new codec should be
1953 // created beyond the one used to decode the prefetch media data prior to 1936 // created beyond the one used to decode the prefetch media data prior to
1954 // the kConfigChanged. 1937 // the kConfigChanged.
1955 StartConfigChange(false, true, 1, true); 1938 StartConfigChange(false, true, 1, true);
1956 1939
1957 // No browser seek should be needed. 1940 // No browser seek should be needed.
1958 EXPECT_TRUE(GetMediaCodecBridge(false)); 1941 EXPECT_TRUE(GetMediaCodecBridge(false));
1959 EXPECT_EQ(3, demuxer_->num_data_requests()); 1942 EXPECT_EQ(3, demuxer_->num_data_requests());
1960 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1943 EXPECT_EQ(0, demuxer_->num_seek_requests());
1961
1962 // Only 1 codec should have been created so far.
1963 EXPECT_EQ(1, manager_.num_resources_requested());
1964 WaitForVideoDecodeDone(); 1944 WaitForVideoDecodeDone();
1965 } 1945 }
1966 1946
1967 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedBySeek) { 1947 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedBySeek) {
1968 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1948 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1969 1949
1970 // Test if a decoder is being drained while receiving a seek request, draining 1950 // Test if a decoder is being drained while receiving a seek request, draining
1971 // is canceled. 1951 // is canceled.
1972 SendConfigChangeToDecoder(true, false, 0, false); 1952 SendConfigChangeToDecoder(true, false, 0, false);
1973 EXPECT_TRUE(IsDrainingDecoder(true)); 1953 EXPECT_TRUE(IsDrainingDecoder(true));
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
2406 2386
2407 EXPECT_EQ(demuxer_->num_data_requests(), 0); 2387 EXPECT_EQ(demuxer_->num_data_requests(), 0);
2408 player_.OnDemuxerConfigsAvailable(CreateDemuxerConfigs(true, true)); 2388 player_.OnDemuxerConfigsAvailable(CreateDemuxerConfigs(true, true));
2409 2389
2410 manager_.set_allow_play(true); 2390 manager_.set_allow_play(true);
2411 player_.Start(); 2391 player_.Start();
2412 EXPECT_TRUE(player_.IsPlaying()); 2392 EXPECT_TRUE(player_.IsPlaying());
2413 } 2393 }
2414 2394
2415 } // namespace media 2395 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_source_player.cc ('k') | media/base/android/video_decoder_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698