Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 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_metadata_changes_(0), | |
| 48 timestamp_updated_(false) {} | 49 timestamp_updated_(false) {} |
| 49 virtual ~MockMediaPlayerManager() {} | 50 virtual ~MockMediaPlayerManager() {} |
| 50 | 51 |
| 51 // MediaPlayerManager implementation. | 52 // MediaPlayerManager implementation. |
| 52 virtual MediaResourceGetter* GetMediaResourceGetter() OVERRIDE { | 53 virtual MediaResourceGetter* GetMediaResourceGetter() OVERRIDE { |
| 53 return NULL; | 54 return NULL; |
| 54 } | 55 } |
| 55 virtual MediaUrlInterceptor* GetMediaUrlInterceptor() OVERRIDE { | 56 virtual MediaUrlInterceptor* GetMediaUrlInterceptor() OVERRIDE { |
| 56 return NULL; | 57 return NULL; |
| 57 } | 58 } |
| 58 virtual void OnTimeUpdate(int player_id, | 59 virtual void OnTimeUpdate(int player_id, |
| 59 base::TimeDelta current_time, | 60 base::TimeDelta current_time, |
| 60 base::TimeTicks current_time_ticks) OVERRIDE { | 61 base::TimeTicks current_time_ticks) OVERRIDE { |
| 61 timestamp_updated_ = true; | 62 timestamp_updated_ = true; |
| 62 } | 63 } |
| 63 virtual void OnMediaMetadataChanged( | 64 virtual void OnMediaMetadataChanged( |
| 64 int player_id, base::TimeDelta duration, int width, int height, | 65 int player_id, base::TimeDelta duration, int width, int height, |
| 65 bool success) OVERRIDE {} | 66 bool success) OVERRIDE { |
| 67 num_metadata_changes_++; | |
| 68 } | |
| 66 virtual void OnPlaybackComplete(int player_id) OVERRIDE { | 69 virtual void OnPlaybackComplete(int player_id) OVERRIDE { |
| 67 playback_completed_ = true; | 70 playback_completed_ = true; |
| 68 if (message_loop_->is_running()) | 71 if (message_loop_->is_running()) |
| 69 message_loop_->Quit(); | 72 message_loop_->Quit(); |
| 70 } | 73 } |
| 71 virtual void OnMediaInterrupted(int player_id) OVERRIDE {} | 74 virtual void OnMediaInterrupted(int player_id) OVERRIDE {} |
| 72 virtual void OnBufferingUpdate(int player_id, int percentage) OVERRIDE {} | 75 virtual void OnBufferingUpdate(int player_id, int percentage) OVERRIDE {} |
| 73 virtual void OnSeekComplete(int player_id, | 76 virtual void OnSeekComplete(int player_id, |
| 74 const base::TimeDelta& current_time) OVERRIDE {} | 77 const base::TimeDelta& current_time) OVERRIDE {} |
| 75 virtual void OnError(int player_id, int error) OVERRIDE {} | 78 virtual void OnError(int player_id, int error) OVERRIDE {} |
| 76 virtual void OnVideoSizeChanged(int player_id, int width, | 79 virtual void OnVideoSizeChanged(int player_id, int width, |
| 77 int height) OVERRIDE {} | 80 int height) OVERRIDE {} |
| 78 virtual MediaPlayerAndroid* GetFullscreenPlayer() OVERRIDE { return NULL; } | 81 virtual MediaPlayerAndroid* GetFullscreenPlayer() OVERRIDE { return NULL; } |
| 79 virtual MediaPlayerAndroid* GetPlayer(int player_id) OVERRIDE { return NULL; } | 82 virtual MediaPlayerAndroid* GetPlayer(int player_id) OVERRIDE { return NULL; } |
| 80 virtual void RequestFullScreen(int player_id) OVERRIDE {} | 83 virtual void RequestFullScreen(int player_id) OVERRIDE {} |
| 81 #if defined(VIDEO_HOLE) | 84 #if defined(VIDEO_HOLE) |
| 82 virtual bool ShouldUseVideoOverlayForEmbeddedEncryptedVideo() OVERRIDE { | 85 virtual bool ShouldUseVideoOverlayForEmbeddedEncryptedVideo() OVERRIDE { |
| 83 return false; | 86 return false; |
| 84 } | 87 } |
| 85 #endif // defined(VIDEO_HOLE) | 88 #endif // defined(VIDEO_HOLE) |
| 86 | 89 |
| 87 bool playback_completed() const { | 90 bool playback_completed() const { |
| 88 return playback_completed_; | 91 return playback_completed_; |
| 89 } | 92 } |
| 90 | 93 |
| 91 int num_resources_requested() const { | 94 int num_resources_requested() const { |
| 92 return num_resources_requested_; | 95 return num_resources_requested_; |
| 93 } | 96 } |
| 94 | 97 |
| 98 int num_metadata_changes() const { | |
| 99 return num_metadata_changes_; | |
| 100 } | |
| 101 | |
| 95 void OnMediaResourcesRequested(int player_id) { | 102 void OnMediaResourcesRequested(int player_id) { |
| 96 num_resources_requested_++; | 103 num_resources_requested_++; |
| 97 } | 104 } |
| 98 | 105 |
| 99 bool timestamp_updated() const { | 106 bool timestamp_updated() const { |
| 100 return timestamp_updated_; | 107 return timestamp_updated_; |
| 101 } | 108 } |
| 102 | 109 |
| 103 void ResetTimestampUpdated() { | 110 void ResetTimestampUpdated() { |
| 104 timestamp_updated_ = false; | 111 timestamp_updated_ = false; |
| 105 } | 112 } |
| 106 | 113 |
| 107 private: | 114 private: |
| 108 base::MessageLoop* message_loop_; | 115 base::MessageLoop* message_loop_; |
| 109 bool playback_completed_; | 116 bool playback_completed_; |
| 110 // The number of resource requests this object has seen. | 117 // The number of resource requests this object has seen. |
| 111 int num_resources_requested_; | 118 int num_resources_requested_; |
| 119 // The number of metadata changes reported by the player. | |
| 120 int num_metadata_changes_; | |
| 112 // Playback timestamp was updated. | 121 // Playback timestamp was updated. |
| 113 bool timestamp_updated_; | 122 bool timestamp_updated_; |
| 114 | 123 |
| 115 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager); | 124 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager); |
| 116 }; | 125 }; |
| 117 | 126 |
| 118 class MockDemuxerAndroid : public DemuxerAndroid { | 127 class MockDemuxerAndroid : public DemuxerAndroid { |
| 119 public: | 128 public: |
| 120 explicit MockDemuxerAndroid(base::MessageLoop* message_loop) | 129 explicit MockDemuxerAndroid(base::MessageLoop* message_loop) |
| 121 : message_loop_(message_loop), | 130 : message_loop_(message_loop), |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 configs.audio_extra_data = std::vector<uint8>( | 274 configs.audio_extra_data = std::vector<uint8>( |
| 266 aac_extra_data, | 275 aac_extra_data, |
| 267 aac_extra_data + 2); | 276 aac_extra_data + 2); |
| 268 return configs; | 277 return configs; |
| 269 } | 278 } |
| 270 | 279 |
| 271 DemuxerConfigs CreateVideoDemuxerConfigs(bool use_larger_size) { | 280 DemuxerConfigs CreateVideoDemuxerConfigs(bool use_larger_size) { |
| 272 DemuxerConfigs configs; | 281 DemuxerConfigs configs; |
| 273 configs.video_codec = kCodecVP8; | 282 configs.video_codec = kCodecVP8; |
| 274 configs.video_size = | 283 configs.video_size = |
| 275 use_larger_size ? gfx::Size(640, 480) : gfx::Size(320, 240); | 284 use_larger_size ? gfx::Size(640, 240) : gfx::Size(320, 240); |
| 276 configs.is_video_encrypted = false; | 285 configs.is_video_encrypted = false; |
| 277 configs.duration = kDefaultDuration; | 286 configs.duration = kDefaultDuration; |
| 278 return configs; | 287 return configs; |
| 279 } | 288 } |
| 280 | 289 |
| 281 DemuxerConfigs CreateAudioVideoDemuxerConfigs() { | 290 DemuxerConfigs CreateAudioVideoDemuxerConfigs() { |
| 282 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false); | 291 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, false); |
| 283 configs.video_codec = kCodecVP8; | 292 configs.video_codec = kCodecVP8; |
| 284 configs.video_size = gfx::Size(320, 240); | 293 configs.video_size = gfx::Size(320, 240); |
| 285 configs.is_video_encrypted = false; | 294 configs.is_video_encrypted = false; |
| (...skipping 1965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2251 DecodeAudioDataUntilOutputBecomesAvailable(); | 2260 DecodeAudioDataUntilOutputBecomesAvailable(); |
| 2252 | 2261 |
| 2253 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, true); | 2262 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis, true); |
| 2254 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged( | 2263 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged( |
| 2255 true, 0, configs); | 2264 true, 0, configs); |
| 2256 player_.OnDemuxerDataAvailable(data); | 2265 player_.OnDemuxerDataAvailable(data); |
| 2257 WaitForAudioDecodeDone(); | 2266 WaitForAudioDecodeDone(); |
| 2258 DecodeAudioDataUntilOutputBecomesAvailable(); | 2267 DecodeAudioDataUntilOutputBecomesAvailable(); |
| 2259 } | 2268 } |
| 2260 | 2269 |
| 2270 TEST_F(MediaSourcePlayerTest, VideoMetadataChangeAfterConfigChange) { | |
| 2271 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | |
| 2272 | |
| 2273 // Test that after a config change, metadata change will be happen | |
| 2274 // after decoder is drained. | |
| 2275 StartConfigChange(false, true, 2, false); | |
| 2276 EXPECT_EQ(1, manager_.num_metadata_changes()); | |
| 2277 EXPECT_FALSE(IsDrainingDecoder(false)); | |
| 2278 | |
| 2279 // Create video data with new resolutions. | |
| 2280 DemuxerData data = CreateReadFromDemuxerAckForVideo(); | |
| 2281 AccessUnit unit; | |
| 2282 unit.status = DemuxerStream::kOk; | |
| 2283 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vp8-I-frame-640x240"); | |
| 2284 unit.data = std::vector<uint8>( | |
| 2285 buffer->data(), buffer->data() + buffer->data_size()); | |
| 2286 data.access_units[0] = unit; | |
| 2287 | |
| 2288 // Wait for the metadata change. | |
| 2289 while(manager_.num_metadata_changes() == 1) { | |
|
wolenetz
2014/10/08 19:41:33
Do we need this while()? Or is WaitForVideoDecodeD
qinmin
2014/10/08 22:52:41
When the format changes, we don't know how long th
| |
| 2290 player_.OnDemuxerDataAvailable(data); | |
| 2291 WaitForVideoDecodeDone(); | |
| 2292 } | |
| 2293 EXPECT_EQ(2, manager_.num_metadata_changes()); | |
| 2294 } | |
| 2295 | |
| 2261 } // namespace media | 2296 } // namespace media |
| OLD | NEW |