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

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

Issue 534063002: Remove OnMediaResourcesReleased callback passed to MediaPlayerAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make ReleaseMediaResources non-virtual Created 6 years, 3 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 // TODO(wolenetz/qinmin): Simplify tests with more effective mock usage, and 38 // TODO(wolenetz/qinmin): Simplify tests with more effective mock usage, and
39 // fix flaky pointer-based MDJ inequality testing. See http://crbug.com/327839. 39 // fix flaky pointer-based MDJ inequality testing. See http://crbug.com/327839.
40 40
41 // Mock of MediaPlayerManager for testing purpose. 41 // Mock of MediaPlayerManager for testing purpose.
42 class MockMediaPlayerManager : public MediaPlayerManager { 42 class MockMediaPlayerManager : public MediaPlayerManager {
43 public: 43 public:
44 explicit MockMediaPlayerManager(base::MessageLoop* message_loop) 44 explicit MockMediaPlayerManager(base::MessageLoop* message_loop)
45 : message_loop_(message_loop), 45 : message_loop_(message_loop),
46 playback_completed_(false), 46 playback_completed_(false),
47 num_resources_requested_(0), 47 num_resources_requested_(0),
48 num_resources_released_(0),
49 timestamp_updated_(false) {} 48 timestamp_updated_(false) {}
50 virtual ~MockMediaPlayerManager() {} 49 virtual ~MockMediaPlayerManager() {}
51 50
52 // MediaPlayerManager implementation. 51 // MediaPlayerManager implementation.
53 virtual MediaResourceGetter* GetMediaResourceGetter() OVERRIDE { 52 virtual MediaResourceGetter* GetMediaResourceGetter() OVERRIDE {
54 return NULL; 53 return NULL;
55 } 54 }
56 virtual MediaUrlInterceptor* GetMediaUrlInterceptor() OVERRIDE { 55 virtual MediaUrlInterceptor* GetMediaUrlInterceptor() OVERRIDE {
57 return NULL; 56 return NULL;
58 } 57 }
(...skipping 26 matching lines...) Expand all
85 #endif // defined(VIDEO_HOLE) 84 #endif // defined(VIDEO_HOLE)
86 85
87 bool playback_completed() const { 86 bool playback_completed() const {
88 return playback_completed_; 87 return playback_completed_;
89 } 88 }
90 89
91 int num_resources_requested() const { 90 int num_resources_requested() const {
92 return num_resources_requested_; 91 return num_resources_requested_;
93 } 92 }
94 93
95 int num_resources_released() const {
96 return num_resources_released_;
97 }
98
99 void OnMediaResourcesRequested(int player_id) { 94 void OnMediaResourcesRequested(int player_id) {
100 num_resources_requested_++; 95 num_resources_requested_++;
101 } 96 }
102 97
103 void OnMediaResourcesReleased(int player_id) {
104 num_resources_released_++;
105 }
106
107 bool timestamp_updated() const { 98 bool timestamp_updated() const {
108 return timestamp_updated_; 99 return timestamp_updated_;
109 } 100 }
110 101
111 void ResetTimestampUpdated() { 102 void ResetTimestampUpdated() {
112 timestamp_updated_ = false; 103 timestamp_updated_ = false;
113 } 104 }
114 105
115 private: 106 private:
116 base::MessageLoop* message_loop_; 107 base::MessageLoop* message_loop_;
117 bool playback_completed_; 108 bool playback_completed_;
118 // The number of resource requests this object has seen. 109 // The number of resource requests this object has seen.
119 int num_resources_requested_; 110 int num_resources_requested_;
120 // The number of released resources.
121 int num_resources_released_;
122 // Playback timestamp was updated. 111 // Playback timestamp was updated.
123 bool timestamp_updated_; 112 bool timestamp_updated_;
124 113
125 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager); 114 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager);
126 }; 115 };
127 116
128 class MockDemuxerAndroid : public DemuxerAndroid { 117 class MockDemuxerAndroid : public DemuxerAndroid {
129 public: 118 public:
130 explicit MockDemuxerAndroid(base::MessageLoop* message_loop) 119 explicit MockDemuxerAndroid(base::MessageLoop* message_loop)
131 : message_loop_(message_loop), 120 : message_loop_(message_loop),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 }; 156 };
168 157
169 class MediaSourcePlayerTest : public testing::Test { 158 class MediaSourcePlayerTest : public testing::Test {
170 public: 159 public:
171 MediaSourcePlayerTest() 160 MediaSourcePlayerTest()
172 : manager_(&message_loop_), 161 : manager_(&message_loop_),
173 demuxer_(new MockDemuxerAndroid(&message_loop_)), 162 demuxer_(new MockDemuxerAndroid(&message_loop_)),
174 player_(0, &manager_, 163 player_(0, &manager_,
175 base::Bind(&MockMediaPlayerManager::OnMediaResourcesRequested, 164 base::Bind(&MockMediaPlayerManager::OnMediaResourcesRequested,
176 base::Unretained(&manager_)), 165 base::Unretained(&manager_)),
177 base::Bind(&MockMediaPlayerManager::OnMediaResourcesReleased,
178 base::Unretained(&manager_)),
179 scoped_ptr<DemuxerAndroid>(demuxer_), 166 scoped_ptr<DemuxerAndroid>(demuxer_),
180 GURL()), 167 GURL()),
181 decoder_callback_hook_executed_(false), 168 decoder_callback_hook_executed_(false),
182 surface_texture_a_is_next_(true) {} 169 surface_texture_a_is_next_(true) {}
183 virtual ~MediaSourcePlayerTest() {} 170 virtual ~MediaSourcePlayerTest() {}
184 171
185 protected: 172 protected:
186 // Get the decoder job from the MediaSourcePlayer. The return value must not 173 // Get the decoder job from the MediaSourcePlayer. The return value must not
187 // be NULL. 174 // be NULL.
188 MediaDecoderJob* GetMediaDecoderJob(bool is_audio) { 175 MediaDecoderJob* GetMediaDecoderJob(bool is_audio) {
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) { 1018 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) {
1032 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1019 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1033 1020
1034 // Test that if video decoder is released while decoding, the resources will 1021 // Test that if video decoder is released while decoding, the resources will
1035 // not be immediately released. 1022 // not be immediately released.
1036 CreateNextTextureAndSetVideoSurface(); 1023 CreateNextTextureAndSetVideoSurface();
1037 StartVideoDecoderJob(); 1024 StartVideoDecoderJob();
1038 // No resource is requested since there is no data to decode. 1025 // No resource is requested since there is no data to decode.
1039 EXPECT_EQ(0, manager_.num_resources_requested()); 1026 EXPECT_EQ(0, manager_.num_resources_requested());
1040 ReleasePlayer(); 1027 ReleasePlayer();
1041 EXPECT_EQ(0, manager_.num_resources_released());
1042 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); 1028 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo());
1043 1029
1044 // Recreate the video decoder. 1030 // Recreate the video decoder.
1045 CreateNextTextureAndSetVideoSurface(); 1031 CreateNextTextureAndSetVideoSurface();
1046 player_.Start(); 1032 player_.Start();
1047 while (!GetMediaDecoderJob(false)->is_decoding()) 1033 while (!GetMediaDecoderJob(false)->is_decoding())
1048 message_loop_.RunUntilIdle(); 1034 message_loop_.RunUntilIdle();
1049 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); 1035 EXPECT_EQ(0, demuxer_->num_browser_seek_requests());
1050 EXPECT_EQ(1, manager_.num_resources_requested()); 1036 EXPECT_EQ(1, manager_.num_resources_requested());
1051 ReleasePlayer(); 1037 ReleasePlayer();
1052 // The resource is still held by the video decoder until it finishes decoding.
1053 EXPECT_EQ(0, manager_.num_resources_released());
1054 // Wait for the media codec bridge to finish decoding and be reset. 1038 // Wait for the media codec bridge to finish decoding and be reset.
1055 while (manager_.num_resources_released() != 1) 1039 while (GetMediaDecoderJob(false)->is_decoding())
1056 message_loop_.RunUntilIdle(); 1040 message_loop_.RunUntilIdle();
1057 } 1041 }
1058 1042
1059 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) { 1043 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) {
1060 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1044 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1061 1045
1062 // Test audio decoder job will not start until pending seek event is handled. 1046 // Test audio decoder job will not start until pending seek event is handled.
1063 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false); 1047 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false);
1064 player_.OnDemuxerConfigsAvailable(configs); 1048 player_.OnDemuxerConfigsAvailable(configs);
1065 1049
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 1780
1797 // New video codec should have been created and configured, without any 1781 // New video codec should have been created and configured, without any
1798 // browser seek. 1782 // browser seek.
1799 EXPECT_TRUE(GetMediaCodecBridge(false)); 1783 EXPECT_TRUE(GetMediaCodecBridge(false));
1800 EXPECT_EQ(3, demuxer_->num_data_requests()); 1784 EXPECT_EQ(3, demuxer_->num_data_requests());
1801 EXPECT_EQ(0, demuxer_->num_seek_requests()); 1785 EXPECT_EQ(0, demuxer_->num_seek_requests());
1802 1786
1803 // 2 codecs should have been created, one before the config change, and one 1787 // 2 codecs should have been created, one before the config change, and one
1804 // after it. 1788 // after it.
1805 EXPECT_EQ(2, manager_.num_resources_requested()); 1789 EXPECT_EQ(2, manager_.num_resources_requested());
1806 EXPECT_EQ(1, manager_.num_resources_released());
1807 } 1790 }
1808 1791
1809 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChangeWithAdaptivePlayback) { 1792 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChangeWithAdaptivePlayback) {
1810 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); 1793 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
1811 1794
1812 // Test that if codec supports adaptive playback, no new codec should be 1795 // Test that if codec supports adaptive playback, no new codec should be
1813 // created beyond the one used to decode the prefetch media data prior to 1796 // created beyond the one used to decode the prefetch media data prior to
1814 // the kConfigChanged. 1797 // the kConfigChanged.
1815 StartConfigChange(false, true, 1, true); 1798 StartConfigChange(false, true, 1, true);
1816 1799
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 2182
2200 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, true); 2183 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, true);
2201 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged( 2184 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(
2202 true, 0, configs); 2185 true, 0, configs);
2203 player_.OnDemuxerDataAvailable(data); 2186 player_.OnDemuxerDataAvailable(data);
2204 WaitForAudioDecodeDone(); 2187 WaitForAudioDecodeDone();
2205 DecodeAudioDataUntilOutputBecomesAvailable(); 2188 DecodeAudioDataUntilOutputBecomesAvailable();
2206 } 2189 }
2207 2190
2208 } // namespace media 2191 } // 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