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" |
| 11 #include "media/base/android/audio_decoder_job.h" | |
| 11 #include "media/base/android/media_codec_bridge.h" | 12 #include "media/base/android/media_codec_bridge.h" |
| 12 #include "media/base/android/media_drm_bridge.h" | 13 #include "media/base/android/media_drm_bridge.h" |
| 13 #include "media/base/android/media_player_manager.h" | 14 #include "media/base/android/media_player_manager.h" |
| 14 #include "media/base/android/media_source_player.h" | 15 #include "media/base/android/media_source_player.h" |
| 16 #include "media/base/android/video_decoder_job.h" | |
| 15 #include "media/base/bind_to_current_loop.h" | 17 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/base/decoder_buffer.h" | 18 #include "media/base/decoder_buffer.h" |
| 17 #include "media/base/test_data_util.h" | 19 #include "media/base/test_data_util.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "ui/gl/android/surface_texture.h" | 21 #include "ui/gl/android/surface_texture.h" |
| 20 | 22 |
| 21 namespace media { | 23 namespace media { |
| 22 | 24 |
| 23 // Helper macro to skip the test if MediaCodecBridge isn't available. | 25 // Helper macro to skip the test if MediaCodecBridge isn't available. |
| 24 #define SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE() \ | 26 #define SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE() \ |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 | 130 |
| 129 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager); | 131 DISALLOW_COPY_AND_ASSIGN(MockMediaPlayerManager); |
| 130 }; | 132 }; |
| 131 | 133 |
| 132 class MockDemuxerAndroid : public DemuxerAndroid { | 134 class MockDemuxerAndroid : public DemuxerAndroid { |
| 133 public: | 135 public: |
| 134 explicit MockDemuxerAndroid(base::MessageLoop* message_loop) | 136 explicit MockDemuxerAndroid(base::MessageLoop* message_loop) |
| 135 : message_loop_(message_loop), | 137 : message_loop_(message_loop), |
| 136 num_data_requests_(0), | 138 num_data_requests_(0), |
| 137 num_seek_requests_(0), | 139 num_seek_requests_(0), |
| 138 num_browser_seek_requests_(0), | 140 num_browser_seek_requests_(0) {} |
| 139 num_config_requests_(0) {} | |
| 140 virtual ~MockDemuxerAndroid() {} | 141 virtual ~MockDemuxerAndroid() {} |
| 141 | 142 |
| 142 virtual void Initialize(DemuxerAndroidClient* client) OVERRIDE {} | 143 virtual void Initialize(DemuxerAndroidClient* client) OVERRIDE {} |
| 143 virtual void RequestDemuxerConfigs() OVERRIDE { | |
| 144 num_config_requests_++; | |
| 145 } | |
| 146 virtual void RequestDemuxerData(DemuxerStream::Type type) OVERRIDE { | 144 virtual void RequestDemuxerData(DemuxerStream::Type type) OVERRIDE { |
| 147 num_data_requests_++; | 145 num_data_requests_++; |
| 148 if (message_loop_->is_running()) | 146 if (message_loop_->is_running()) |
| 149 message_loop_->Quit(); | 147 message_loop_->Quit(); |
| 150 } | 148 } |
| 151 virtual void RequestDemuxerSeek(const base::TimeDelta& time_to_seek, | 149 virtual void RequestDemuxerSeek(const base::TimeDelta& time_to_seek, |
| 152 bool is_browser_seek) OVERRIDE { | 150 bool is_browser_seek) OVERRIDE { |
| 153 num_seek_requests_++; | 151 num_seek_requests_++; |
| 154 if (is_browser_seek) | 152 if (is_browser_seek) |
| 155 num_browser_seek_requests_++; | 153 num_browser_seek_requests_++; |
| 156 } | 154 } |
| 157 | 155 |
| 158 int num_data_requests() const { return num_data_requests_; } | 156 int num_data_requests() const { return num_data_requests_; } |
| 159 int num_seek_requests() const { return num_seek_requests_; } | 157 int num_seek_requests() const { return num_seek_requests_; } |
| 160 int num_browser_seek_requests() const { return num_browser_seek_requests_; } | 158 int num_browser_seek_requests() const { return num_browser_seek_requests_; } |
| 161 int num_config_requests() const { return num_config_requests_; } | |
| 162 | 159 |
| 163 private: | 160 private: |
| 164 base::MessageLoop* message_loop_; | 161 base::MessageLoop* message_loop_; |
| 165 | 162 |
| 166 // The number of encoded data requests this object has seen. | 163 // The number of encoded data requests this object has seen. |
| 167 int num_data_requests_; | 164 int num_data_requests_; |
| 168 | 165 |
| 169 // The number of regular and browser seek requests this object has seen. | 166 // The number of regular and browser seek requests this object has seen. |
| 170 int num_seek_requests_; | 167 int num_seek_requests_; |
| 171 | 168 |
| 172 // The number of browser seek requests this object has seen. | 169 // The number of browser seek requests this object has seen. |
| 173 int num_browser_seek_requests_; | 170 int num_browser_seek_requests_; |
| 174 | 171 |
| 175 // The number of demuxer config requests this object has seen. | |
| 176 int num_config_requests_; | |
| 177 | |
| 178 DISALLOW_COPY_AND_ASSIGN(MockDemuxerAndroid); | 172 DISALLOW_COPY_AND_ASSIGN(MockDemuxerAndroid); |
| 179 }; | 173 }; |
| 180 | 174 |
| 181 class MediaSourcePlayerTest : public testing::Test { | 175 class MediaSourcePlayerTest : public testing::Test { |
| 182 public: | 176 public: |
| 183 MediaSourcePlayerTest() | 177 MediaSourcePlayerTest() |
| 184 : manager_(&message_loop_), | 178 : manager_(&message_loop_), |
| 185 demuxer_(new MockDemuxerAndroid(&message_loop_)), | 179 demuxer_(new MockDemuxerAndroid(&message_loop_)), |
| 186 player_(0, &manager_, | 180 player_(0, &manager_, |
| 187 base::Bind(&MockMediaPlayerManager::OnMediaResourcesRequested, | 181 base::Bind(&MockMediaPlayerManager::OnMediaResourcesRequested, |
| 188 base::Unretained(&manager_)), | 182 base::Unretained(&manager_)), |
| 189 base::Bind(&MockMediaPlayerManager::OnMediaResourcesReleased, | 183 base::Bind(&MockMediaPlayerManager::OnMediaResourcesReleased, |
| 190 base::Unretained(&manager_)), | 184 base::Unretained(&manager_)), |
| 191 scoped_ptr<DemuxerAndroid>(demuxer_)), | 185 scoped_ptr<DemuxerAndroid>(demuxer_)), |
| 192 decoder_callback_hook_executed_(false), | 186 decoder_callback_hook_executed_(false), |
| 193 surface_texture_a_is_next_(true) {} | 187 surface_texture_a_is_next_(true) {} |
| 194 virtual ~MediaSourcePlayerTest() {} | 188 virtual ~MediaSourcePlayerTest() {} |
| 195 | 189 |
| 196 protected: | 190 protected: |
| 197 // Get the decoder job from the MediaSourcePlayer. | 191 // Get the decoder job from the MediaSourcePlayer. |
| 198 MediaDecoderJob* GetMediaDecoderJob(bool is_audio) { | 192 MediaDecoderJob* GetMediaDecoderJob(bool is_audio) { |
| 199 if (is_audio) { | 193 if (is_audio) { |
| 200 return reinterpret_cast<MediaDecoderJob*>( | 194 return reinterpret_cast<MediaDecoderJob*>( |
| 201 player_.audio_decoder_job_.get()); | 195 player_.audio_decoder_job_.get()); |
| 202 } | 196 } |
| 203 return reinterpret_cast<MediaDecoderJob*>( | 197 return reinterpret_cast<MediaDecoderJob*>( |
| 204 player_.video_decoder_job_.get()); | 198 player_.video_decoder_job_.get()); |
| 205 } | 199 } |
| 206 | 200 |
| 201 // Get the MediaCodecBridge from the decoder job. | |
| 202 MediaCodecBridge* GetMediaCodecBridge(bool is_audio) { | |
| 203 if (is_audio) | |
| 204 return player_.audio_decoder_job_->media_codec_bridge_.get(); | |
| 205 return player_.video_decoder_job_->media_codec_bridge_.get(); | |
| 206 } | |
| 207 | |
| 207 // Get the per-job prerolling status from the MediaSourcePlayer's job matching | 208 // Get the per-job prerolling status from the MediaSourcePlayer's job matching |
| 208 // |is_audio|. Caller must guard against NPE if the player's job is NULL. | 209 // |is_audio|. Caller must guard against NPE if the player's job is NULL. |
| 209 bool IsPrerolling(bool is_audio) { | 210 bool IsPrerolling(bool is_audio) { |
| 210 return GetMediaDecoderJob(is_audio)->prerolling(); | 211 return GetMediaDecoderJob(is_audio)->prerolling_; |
| 211 } | 212 } |
| 212 | 213 |
| 213 // Get the preroll timestamp from the MediaSourcePlayer. | 214 // Get the preroll timestamp from the MediaSourcePlayer. |
| 214 base::TimeDelta GetPrerollTimestamp() { | 215 base::TimeDelta GetPrerollTimestamp() { |
| 215 return player_.preroll_timestamp_; | 216 return player_.preroll_timestamp_; |
| 216 } | 217 } |
| 217 | 218 |
| 218 // Simulate player has reached starvation timeout. | 219 // Simulate player has reached starvation timeout. |
| 219 void TriggerPlayerStarvation() { | 220 void TriggerPlayerStarvation() { |
| 220 player_.decoder_starvation_callback_.Cancel(); | 221 player_.decoder_starvation_callback_.Cancel(); |
| 221 player_.OnDecoderStarved(); | 222 player_.OnDecoderStarved(); |
| 222 } | 223 } |
| 223 | 224 |
| 224 // Release() the player. | 225 // Release() the player. |
| 225 void ReleasePlayer() { | 226 void ReleasePlayer() { |
| 226 EXPECT_TRUE(player_.IsPlaying()); | 227 EXPECT_TRUE(player_.IsPlaying()); |
| 227 player_.Release(); | 228 player_.Release(); |
| 228 EXPECT_FALSE(player_.IsPlaying()); | 229 EXPECT_FALSE(player_.IsPlaying()); |
| 229 EXPECT_FALSE(GetMediaDecoderJob(true)); | |
| 230 EXPECT_FALSE(GetMediaDecoderJob(false)); | |
| 231 } | 230 } |
| 232 | 231 |
| 233 // Upon the next successful decode callback, post a task to call Release() | 232 // Upon the next successful decode callback, post a task to call Release() |
| 234 // on the |player_|. TEST_F's do not have access to the private player | 233 // on the |player_|. TEST_F's do not have access to the private player |
| 235 // members, hence this helper method. | 234 // members, hence this helper method. |
| 236 // Prevent usage creep of MSP::set_decode_callback_for_testing() by | 235 // Prevent usage creep of MSP::set_decode_callback_for_testing() by |
| 237 // only using it for the ReleaseWithOnPrefetchDoneAlreadyPosted test. | 236 // only using it for the ReleaseWithOnPrefetchDoneAlreadyPosted test. |
| 238 void OnNextTestDecodeCallbackPostTaskToReleasePlayer() { | 237 void OnNextTestDecodeCallbackPostTaskToReleasePlayer() { |
| 239 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); | 238 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); |
| 240 player_.set_decode_callback_for_testing(media::BindToCurrentLoop( | 239 player_.set_decode_callback_for_testing(media::BindToCurrentLoop( |
| 241 base::Bind( | 240 base::Bind( |
| 242 &MediaSourcePlayerTest::ReleaseWithPendingPrefetchDoneVerification, | 241 &MediaSourcePlayerTest::ReleaseWithPendingPrefetchDoneVerification, |
| 243 base::Unretained(this)))); | 242 base::Unretained(this)))); |
| 244 } | 243 } |
| 245 | 244 |
| 246 // Asynch test callback posted upon decode completion to verify that a pending | 245 // Asynch test callback posted upon decode completion to verify that a pending |
| 247 // prefetch done event is cleared across |player_|'s Release(). This helps | 246 // prefetch done event is not cleared across |player_|'s Release(). This helps |
| 248 // ensure the ReleaseWithOnPrefetchDoneAlreadyPosted test scenario is met. | 247 // ensure the ReleaseWithOnPrefetchDoneAlreadyPosted test scenario is met. |
| 249 void ReleaseWithPendingPrefetchDoneVerification() { | 248 void ReleaseWithPendingPrefetchDoneVerification() { |
| 250 EXPECT_TRUE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING)); | 249 EXPECT_TRUE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING)); |
| 251 ReleasePlayer(); | 250 ReleasePlayer(); |
| 252 EXPECT_FALSE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING)); | 251 EXPECT_TRUE(player_.IsEventPending(player_.PREFETCH_DONE_EVENT_PENDING)); |
| 253 EXPECT_FALSE(decoder_callback_hook_executed_); | 252 EXPECT_FALSE(decoder_callback_hook_executed_); |
| 253 EXPECT_FALSE(GetMediaCodecBridge(true)); | |
| 254 decoder_callback_hook_executed_ = true; | 254 decoder_callback_hook_executed_ = true; |
| 255 } | 255 } |
| 256 | 256 |
| 257 // Inspect internal pending_event_ state of |player_|. This is for infrequent | |
| 258 // use by tests, only where required. | |
| 259 bool IsPendingSurfaceChange() { | |
| 260 return player_.IsEventPending(player_.SURFACE_CHANGE_EVENT_PENDING); | |
| 261 } | |
| 262 | |
| 263 DemuxerConfigs CreateAudioDemuxerConfigs(AudioCodec audio_codec) { | 257 DemuxerConfigs CreateAudioDemuxerConfigs(AudioCodec audio_codec) { |
| 264 DemuxerConfigs configs; | 258 DemuxerConfigs configs; |
| 265 configs.audio_codec = audio_codec; | 259 configs.audio_codec = audio_codec; |
| 266 configs.audio_channels = 2; | 260 configs.audio_channels = 2; |
| 267 configs.is_audio_encrypted = false; | 261 configs.is_audio_encrypted = false; |
| 268 configs.duration = kDefaultDuration; | 262 configs.duration = kDefaultDuration; |
| 269 | 263 |
| 270 if (audio_codec == kCodecVorbis) { | 264 if (audio_codec == kCodecVorbis) { |
| 271 configs.audio_sampling_rate = 44100; | 265 configs.audio_sampling_rate = 44100; |
| 272 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile( | 266 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile( |
| 273 "vorbis-extradata"); | 267 "vorbis-extradata"); |
| 274 configs.audio_extra_data = std::vector<uint8>( | 268 configs.audio_extra_data = std::vector<uint8>( |
| 275 buffer->data(), | 269 buffer->data(), |
| 276 buffer->data() + buffer->data_size()); | 270 buffer->data() + buffer->data_size()); |
| 277 return configs; | 271 return configs; |
| 278 } | 272 } |
| 279 | 273 |
| 280 // Other codecs are not yet supported by this helper. | 274 // Other codecs are not yet supported by this helper. |
| 281 EXPECT_EQ(audio_codec, kCodecAAC); | 275 EXPECT_EQ(audio_codec, kCodecAAC); |
| 282 | 276 |
| 283 configs.audio_sampling_rate = 48000; | 277 configs.audio_sampling_rate = 48000; |
| 284 uint8 aac_extra_data[] = { 0x13, 0x10 }; | 278 uint8 aac_extra_data[] = { 0x13, 0x10 }; |
| 285 configs.audio_extra_data = std::vector<uint8>( | 279 configs.audio_extra_data = std::vector<uint8>( |
| 286 aac_extra_data, | 280 aac_extra_data, |
| 287 aac_extra_data + 2); | 281 aac_extra_data + 2); |
| 288 return configs; | 282 return configs; |
| 289 } | 283 } |
| 290 | 284 |
| 291 DemuxerConfigs CreateVideoDemuxerConfigs() { | 285 DemuxerConfigs CreateVideoDemuxerConfigs(VideoCodec video_codec) { |
| 292 DemuxerConfigs configs; | 286 DemuxerConfigs configs; |
| 293 configs.video_codec = kCodecVP8; | 287 configs.video_codec = video_codec; |
| 294 configs.video_size = gfx::Size(320, 240); | 288 configs.video_size = gfx::Size(320, 240); |
| 295 configs.is_video_encrypted = false; | 289 configs.is_video_encrypted = false; |
| 296 configs.duration = kDefaultDuration; | 290 configs.duration = kDefaultDuration; |
| 297 return configs; | 291 return configs; |
| 298 } | 292 } |
| 299 | 293 |
| 300 DemuxerConfigs CreateAudioVideoDemuxerConfigs() { | 294 DemuxerConfigs CreateAudioVideoDemuxerConfigs() { |
| 301 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); | 295 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); |
| 302 configs.video_codec = kCodecVP8; | 296 configs.video_codec = kCodecVP8; |
| 303 configs.video_size = gfx::Size(320, 240); | 297 configs.video_size = gfx::Size(320, 240); |
| 304 configs.is_video_encrypted = false; | 298 configs.is_video_encrypted = false; |
| 305 return configs; | 299 return configs; |
| 306 } | 300 } |
| 307 | 301 |
| 308 DemuxerConfigs CreateDemuxerConfigs(bool have_audio, bool have_video) { | 302 DemuxerConfigs CreateDemuxerConfigs(bool have_audio, bool have_video) { |
| 309 DCHECK(have_audio || have_video); | 303 DCHECK(have_audio || have_video); |
| 310 | 304 |
| 311 if (have_audio && !have_video) | 305 if (have_audio && !have_video) |
| 312 return CreateAudioDemuxerConfigs(kCodecVorbis); | 306 return CreateAudioDemuxerConfigs(kCodecVorbis); |
| 313 | 307 |
| 314 if (have_video && !have_audio) | 308 if (have_video && !have_audio) |
| 315 return CreateVideoDemuxerConfigs(); | 309 return CreateVideoDemuxerConfigs(kCodecVP8); |
| 316 | 310 |
| 317 return CreateAudioVideoDemuxerConfigs(); | 311 return CreateAudioVideoDemuxerConfigs(); |
| 318 } | 312 } |
| 319 | 313 |
| 320 // Starts an audio decoder job. Verifies player behavior relative to | 314 // Starts an audio decoder job. Verifies player behavior relative to |
| 321 // |expect_player_requests_data|. | 315 // |expect_player_requests_data|. |
| 322 void StartAudioDecoderJob(bool expect_player_requests_data) { | 316 void StartAudioDecoderJob(bool expect_player_requests_data) { |
| 323 Start(CreateAudioDemuxerConfigs(kCodecVorbis), expect_player_requests_data); | 317 Start(CreateAudioDemuxerConfigs(kCodecVorbis), expect_player_requests_data); |
| 324 } | 318 } |
| 325 | 319 |
| 326 // Starts a video decoder job. Verifies player behavior relative to | 320 // Starts a video decoder job. Verifies player behavior relative to |
| 327 // |expect_player_requests_data|. | 321 // |expect_player_requests_data|. |
| 328 void StartVideoDecoderJob(bool expect_player_requests_data) { | 322 void StartVideoDecoderJob(bool expect_player_requests_data) { |
| 329 Start(CreateVideoDemuxerConfigs(), expect_player_requests_data); | 323 Start(CreateVideoDemuxerConfigs(kCodecVP8), expect_player_requests_data); |
| 330 } | 324 } |
| 331 | 325 |
| 332 // Starts decoding the data. Verifies player behavior relative to | 326 // Starts decoding the data. Verifies player behavior relative to |
| 333 // |expect_player_requests_data|. | 327 // |expect_player_requests_data|. |
| 334 void Start(const DemuxerConfigs& configs, bool expect_player_requests_data) { | 328 void Start(const DemuxerConfigs& configs, bool expect_player_requests_data) { |
| 335 bool has_audio = configs.audio_codec != kUnknownAudioCodec; | 329 bool has_audio = configs.audio_codec != kUnknownAudioCodec; |
| 336 bool has_video = configs.video_codec != kUnknownVideoCodec; | 330 bool has_video = configs.video_codec != kUnknownVideoCodec; |
| 337 int original_num_data_requests = demuxer_->num_data_requests(); | 331 int original_num_data_requests = demuxer_->num_data_requests(); |
| 338 int expected_request_delta = expect_player_requests_data ? | 332 int expected_request_delta = expect_player_requests_data ? |
| 339 ((has_audio ? 1 : 0) + (has_video ? 1 : 0)) : 0; | 333 ((has_audio ? 1 : 0) + (has_video ? 1 : 0)) : 0; |
| 340 | 334 |
| 341 player_.OnDemuxerConfigsAvailable(configs); | 335 player_.OnDemuxerConfigsAvailable(configs); |
| 342 player_.Start(); | 336 player_.Start(); |
| 343 | 337 |
| 344 EXPECT_TRUE(player_.IsPlaying()); | 338 EXPECT_TRUE(player_.IsPlaying()); |
| 345 EXPECT_EQ(original_num_data_requests + expected_request_delta, | 339 EXPECT_EQ(original_num_data_requests + expected_request_delta, |
| 346 demuxer_->num_data_requests()); | 340 demuxer_->num_data_requests()); |
| 347 | |
| 348 // Verify player has decoder job iff the config included the media type for | |
| 349 // the job and the player is expected to request data due to Start(), above. | |
| 350 EXPECT_EQ(expect_player_requests_data && has_audio, | |
| 351 GetMediaDecoderJob(true) != NULL); | |
| 352 EXPECT_EQ(expect_player_requests_data && has_video, | |
| 353 GetMediaDecoderJob(false) != NULL); | |
| 354 } | 341 } |
| 355 | 342 |
| 356 // Keeps decoding audio data until the decoder starts to output samples. | 343 // Keeps decoding audio data until the decoder starts to output samples. |
| 357 // Gives up if no audio output after decoding 10 frames. | 344 // Gives up if no audio output after decoding 10 frames. |
| 358 void DecodeAudioDataUntilOutputBecomesAvailable() { | 345 void DecodeAudioDataUntilOutputBecomesAvailable() { |
| 359 EXPECT_TRUE(player_.IsPlaying()); | 346 EXPECT_TRUE(player_.IsPlaying()); |
| 360 base::TimeDelta current_time = player_.GetCurrentTime(); | 347 base::TimeDelta current_time = player_.GetCurrentTime(); |
| 361 base::TimeDelta start_timestamp = current_time; | 348 base::TimeDelta start_timestamp = current_time; |
| 362 for (int i = 0; i < 10; ++i) { | 349 for (int i = 0; i < 10; ++i) { |
| 363 manager_.ResetTimestampUpdated(); | 350 manager_.ResetTimestampUpdated(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 } | 418 } |
| 432 | 419 |
| 433 // Helper method for use at test start. It starts an audio decoder job and | 420 // Helper method for use at test start. It starts an audio decoder job and |
| 434 // immediately feeds it some data to decode. Then, without letting the decoder | 421 // immediately feeds it some data to decode. Then, without letting the decoder |
| 435 // job complete a decode cycle, it also starts player SeekTo(). Upon return, | 422 // job complete a decode cycle, it also starts player SeekTo(). Upon return, |
| 436 // the player should not yet have sent the DemuxerSeek IPC request, though | 423 // the player should not yet have sent the DemuxerSeek IPC request, though |
| 437 // seek event should be pending. The audio decoder job will also still be | 424 // seek event should be pending. The audio decoder job will also still be |
| 438 // decoding. | 425 // decoding. |
| 439 void StartAudioDecoderJobAndSeekToWhileDecoding( | 426 void StartAudioDecoderJobAndSeekToWhileDecoding( |
| 440 const base::TimeDelta& seek_time) { | 427 const base::TimeDelta& seek_time) { |
| 441 EXPECT_FALSE(GetMediaDecoderJob(true)); | 428 EXPECT_FALSE(GetMediaCodecBridge(true)); |
| 442 EXPECT_FALSE(player_.IsPlaying()); | 429 EXPECT_FALSE(player_.IsPlaying()); |
| 443 EXPECT_EQ(0, demuxer_->num_data_requests()); | 430 EXPECT_EQ(0, demuxer_->num_data_requests()); |
| 444 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF()); | 431 EXPECT_EQ(0.0, GetPrerollTimestamp().InMillisecondsF()); |
| 445 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp()); | 432 EXPECT_EQ(player_.GetCurrentTime(), GetPrerollTimestamp()); |
| 446 StartAudioDecoderJob(true); | 433 StartAudioDecoderJob(true); |
| 447 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); | 434 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); |
| 448 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); | 435 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); |
| 449 EXPECT_EQ(2, demuxer_->num_data_requests()); | 436 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 450 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 437 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
| 451 player_.SeekTo(seek_time); | 438 player_.SeekTo(seek_time); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 468 player_.SeekTo(seek_time); | 455 player_.SeekTo(seek_time); |
| 469 | 456 |
| 470 // Verify that the seek does not occur until previously outstanding data | 457 // Verify that the seek does not occur until previously outstanding data |
| 471 // request is satisfied. | 458 // request is satisfied. |
| 472 EXPECT_EQ(original_num_seeks, demuxer_->num_seek_requests()); | 459 EXPECT_EQ(original_num_seeks, demuxer_->num_seek_requests()); |
| 473 | 460 |
| 474 // Simulate seeking causes the demuxer to abort the outstanding read | 461 // Simulate seeking causes the demuxer to abort the outstanding read |
| 475 // caused by the seek. | 462 // caused by the seek. |
| 476 player_.OnDemuxerDataAvailable(CreateAbortedAck(is_audio)); | 463 player_.OnDemuxerDataAvailable(CreateAbortedAck(is_audio)); |
| 477 | 464 |
| 465 // Wait for the decode job to finish so we can process the seek request. | |
| 466 WaitForDecodeDone(is_audio, !is_audio); | |
| 467 | |
| 478 // Verify that the seek is requested. | 468 // Verify that the seek is requested. |
| 479 EXPECT_EQ(original_num_seeks + 1, demuxer_->num_seek_requests()); | 469 EXPECT_EQ(original_num_seeks + 1, demuxer_->num_seek_requests()); |
| 480 | 470 |
| 481 // Send back the seek done notification. This should trigger the player to | 471 // Send back the seek done notification. This should trigger the player to |
| 482 // call OnReadFromDemuxer() again. | 472 // call OnReadFromDemuxer() again. |
| 483 EXPECT_EQ(original_num_data_requests, demuxer_->num_data_requests()); | 473 EXPECT_EQ(original_num_data_requests, demuxer_->num_data_requests()); |
| 484 player_.OnDemuxerSeekDone(kNoTimestamp()); | 474 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 485 EXPECT_EQ(original_num_data_requests + 1, demuxer_->num_data_requests()); | 475 EXPECT_EQ(original_num_data_requests + 1, demuxer_->num_data_requests()); |
| 486 | 476 |
| 487 // No other seek should have been requested. | 477 // No other seek should have been requested. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 512 base::TimeDelta::FromMilliseconds(current_timestamp); | 502 base::TimeDelta::FromMilliseconds(current_timestamp); |
| 513 player_.OnDemuxerDataAvailable(data); | 503 player_.OnDemuxerDataAvailable(data); |
| 514 EXPECT_TRUE(GetMediaDecoderJob(is_audio)->is_decoding()); | 504 EXPECT_TRUE(GetMediaDecoderJob(is_audio)->is_decoding()); |
| 515 EXPECT_EQ(target_timestamp, player_.GetCurrentTime()); | 505 EXPECT_EQ(target_timestamp, player_.GetCurrentTime()); |
| 516 current_timestamp += 30; | 506 current_timestamp += 30; |
| 517 WaitForDecodeDone(is_audio, !is_audio); | 507 WaitForDecodeDone(is_audio, !is_audio); |
| 518 } | 508 } |
| 519 EXPECT_LE(target_timestamp, player_.GetCurrentTime()); | 509 EXPECT_LE(target_timestamp, player_.GetCurrentTime()); |
| 520 } | 510 } |
| 521 | 511 |
| 522 DemuxerData CreateReadFromDemuxerAckWithConfigChanged(bool is_audio, | 512 DemuxerData CreateReadFromDemuxerAckWithConfigChanged( |
| 523 int config_unit_index) { | 513 bool is_audio, |
| 514 int config_unit_index, | |
| 515 const DemuxerConfigs& configs) { | |
| 524 DemuxerData data; | 516 DemuxerData data; |
| 525 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO; | 517 data.type = is_audio ? DemuxerStream::AUDIO : DemuxerStream::VIDEO; |
| 526 data.access_units.resize(config_unit_index + 1); | 518 data.access_units.resize(config_unit_index + 1); |
| 527 | 519 |
| 528 for (int i = 0; i < config_unit_index; ++i) | 520 for (int i = 0; i < config_unit_index; ++i) |
| 529 data.access_units[i] = CreateAccessUnitWithData(is_audio, i); | 521 data.access_units[i] = CreateAccessUnitWithData(is_audio, i); |
| 530 | 522 |
| 531 data.access_units[config_unit_index].status = DemuxerStream::kConfigChanged; | 523 data.access_units[config_unit_index].status = DemuxerStream::kConfigChanged; |
| 524 data.demuxer_configs.resize(1); | |
| 525 data.demuxer_configs[0] = configs; | |
| 532 return data; | 526 return data; |
| 533 } | 527 } |
| 534 | 528 |
| 535 // Valid only for video-only player tests. If |trigger_with_release_start| is | 529 // Valid only for video-only player tests. If |trigger_with_release_start| is |
| 536 // true, triggers the browser seek with a Release() + video data received + | 530 // true, triggers the browser seek with a Release() + video data received + |
| 537 // Start() with a new surface. If false, triggers the browser seek by | 531 // Start() with a new surface. If false, triggers the browser seek by |
| 538 // setting a new video surface after beginning decode of received video data. | 532 // setting a new video surface after beginning decode of received video data. |
| 539 // Such data receipt causes possibility that an I-frame is not next, and | 533 // Such data receipt causes possibility that an I-frame is not next, and |
| 540 // browser seek results once decode completes and surface change processing | 534 // browser seek results once decode completes and surface change processing |
| 541 // begins. | 535 // begins. |
| 542 void BrowserSeekPlayer(bool trigger_with_release_start) { | 536 void BrowserSeekPlayer(bool trigger_with_release_start) { |
| 543 int expected_num_data_requests = demuxer_->num_data_requests() + | 537 int expected_num_data_requests = demuxer_->num_data_requests() + 2; |
| 544 (trigger_with_release_start ? 1 : 2); | |
| 545 int expected_num_seek_requests = demuxer_->num_seek_requests(); | 538 int expected_num_seek_requests = demuxer_->num_seek_requests(); |
| 546 int expected_num_browser_seek_requests = | 539 int expected_num_browser_seek_requests = |
| 547 demuxer_->num_browser_seek_requests(); | 540 demuxer_->num_browser_seek_requests(); |
| 548 | 541 |
| 549 EXPECT_FALSE(GetMediaDecoderJob(false)); | |
| 550 CreateNextTextureAndSetVideoSurface(); | 542 CreateNextTextureAndSetVideoSurface(); |
| 551 StartVideoDecoderJob(true); | 543 StartVideoDecoderJob(true); |
| 552 | 544 |
| 553 if (trigger_with_release_start) { | 545 if (trigger_with_release_start) { |
| 546 // Consume the first frame, so that the next VideoDecoderJob will not | |
| 547 // inherit the I-frame from the previous decoder. | |
| 548 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | |
| 554 ReleasePlayer(); | 549 ReleasePlayer(); |
| 550 WaitForVideoDecodeDone(); | |
| 555 | 551 |
| 556 // Simulate demuxer's response to the video data request. The data will be | 552 // Simulate demuxer's response to the video data request. The data will be |
| 557 // discarded. | 553 // passed to the next MediaCodecBridge. |
| 558 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 554 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 559 EXPECT_FALSE(GetMediaDecoderJob(false)); | 555 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 560 EXPECT_FALSE(player_.IsPlaying()); | 556 EXPECT_FALSE(player_.IsPlaying()); |
| 561 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); | 557 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); |
| 562 | 558 |
| 563 CreateNextTextureAndSetVideoSurface(); | 559 CreateNextTextureAndSetVideoSurface(); |
| 564 StartVideoDecoderJob(false); | 560 StartVideoDecoderJob(false); |
| 565 EXPECT_FALSE(GetMediaDecoderJob(false)); | 561 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 562 | |
| 563 // Run the message loop so that prefetch will complete. | |
| 564 while (expected_num_seek_requests == demuxer_->num_seek_requests()) | |
| 565 message_loop_.RunUntilIdle(); | |
| 566 } else { | 566 } else { |
| 567 // Simulate demuxer's response to the video data request. | 567 // Simulate demuxer's response to the video data request. |
| 568 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 568 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 569 | 569 |
| 570 // While the decoder is decoding, trigger a browser seek by changing | 570 // While the decoder is decoding, trigger a browser seek by changing |
| 571 // surface. Demuxer does not know of browser seek in advance, so no | 571 // surface. Demuxer does not know of browser seek in advance, so no |
| 572 // |kAborted| data is required (though |kAborted| can certainly occur for | 572 // |kAborted| data is required (though |kAborted| can certainly occur for |
| 573 // any pending read in reality due to renderer preparing for a regular | 573 // any pending read in reality due to renderer preparing for a regular |
| 574 // seek). | 574 // seek). |
| 575 CreateNextTextureAndSetVideoSurface(); | 575 CreateNextTextureAndSetVideoSurface(); |
| 576 | 576 |
| 577 // Browser seek should not begin until decoding has completed. | 577 // Browser seek should not begin until decoding has completed. |
| 578 EXPECT_TRUE(GetMediaDecoderJob(false)); | 578 EXPECT_TRUE(GetMediaCodecBridge(false)); |
| 579 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); | 579 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); |
| 580 | 580 |
| 581 // Wait for the decoder job to finish decoding and be reset pending the | 581 // Wait for the decoder job to finish decoding and be reset pending the |
| 582 // browser seek. | 582 // browser seek. |
| 583 WaitForVideoDecodeDone(); | 583 WaitForVideoDecodeDone(); |
| 584 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 584 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 585 } | 585 } |
| 586 | 586 |
| 587 // Only one browser seek should have been initiated, and no further data | 587 // Only one browser seek should have been initiated, and no further data |
| 588 // should have been requested. | 588 // should have been requested. |
| 589 expected_num_seek_requests++; | 589 expected_num_seek_requests++; |
| 590 expected_num_browser_seek_requests++; | 590 expected_num_browser_seek_requests++; |
| 591 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); | 591 EXPECT_EQ(expected_num_seek_requests, demuxer_->num_seek_requests()); |
| 592 EXPECT_EQ(expected_num_browser_seek_requests, | 592 EXPECT_EQ(expected_num_browser_seek_requests, |
| 593 demuxer_->num_browser_seek_requests()); | 593 demuxer_->num_browser_seek_requests()); |
| 594 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); | 594 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); |
| 595 } | 595 } |
| 596 | 596 |
| 597 // Creates a new decoder job and feeds it data ending with a |kConfigChanged| | 597 // Creates a new decoder job and feeds it data ending with a |kConfigChanged| |
| 598 // access unit. If |config_unit_in_prefetch| is true, sends feeds the config | 598 // access unit. If |config_unit_in_prefetch| is true, sends feeds the config |
| 599 // change AU in response to the job's first read request (prefetch). If | 599 // change AU in response to the job's first read request (prefetch). If |
| 600 // false, regular data is fed and decoded prior to feeding the config change | 600 // false, regular data is fed and decoded prior to feeding the config change |
| 601 // AU in response to the second data request (after prefetch completed). | 601 // AU in response to the second data request (after prefetch completed). |
| 602 // |config_unit_index| controls which access unit is |kConfigChanged|. | 602 // |config_unit_index| controls which access unit is |kConfigChanged|. |
| 603 void StartConfigChange(bool is_audio, | 603 void SendConfigChangeToDecoder(bool is_audio, |
| 604 bool config_unit_in_prefetch, | 604 bool config_unit_in_prefetch, |
| 605 int config_unit_index) { | 605 int config_unit_index) { |
| 606 int expected_num_config_requests = demuxer_->num_config_requests(); | 606 EXPECT_FALSE(GetMediaCodecBridge(is_audio)); |
| 607 | |
| 608 EXPECT_FALSE(GetMediaDecoderJob(is_audio)); | |
| 609 if (is_audio) { | 607 if (is_audio) { |
| 610 StartAudioDecoderJob(true); | 608 StartAudioDecoderJob(true); |
| 611 } else { | 609 } else { |
| 612 CreateNextTextureAndSetVideoSurface(); | 610 CreateNextTextureAndSetVideoSurface(); |
| 613 StartVideoDecoderJob(true); | 611 StartVideoDecoderJob(true); |
| 614 } | 612 } |
| 615 | 613 |
| 616 int expected_num_data_requests = demuxer_->num_data_requests(); | 614 int expected_num_data_requests = demuxer_->num_data_requests(); |
| 617 | |
| 618 // Feed and decode a standalone access unit so the player exits prefetch. | 615 // Feed and decode a standalone access unit so the player exits prefetch. |
| 619 if (!config_unit_in_prefetch) { | 616 if (!config_unit_in_prefetch) { |
| 620 if (is_audio) | 617 if (is_audio) |
| 621 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); | 618 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); |
| 622 else | 619 else |
| 623 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 620 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 624 | 621 |
| 625 WaitForDecodeDone(is_audio, !is_audio); | 622 WaitForDecodeDone(is_audio, !is_audio); |
| 626 | 623 |
| 627 // We should have completed the prefetch phase at this point. | 624 // We should have completed the prefetch phase at this point. |
| 628 expected_num_data_requests++; | 625 expected_num_data_requests++; |
| 629 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); | 626 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); |
| 630 } | 627 } |
| 631 | 628 |
| 632 EXPECT_EQ(expected_num_config_requests, demuxer_->num_config_requests()); | 629 DemuxerConfigs configs = is_audio ? CreateAudioDemuxerConfigs(kCodecAAC) : |
| 633 | 630 CreateVideoDemuxerConfigs(kCodecVP9); |
| 634 // Feed and decode access units with data for any units prior to | 631 // Feed and decode access units with data for any units prior to |
| 635 // |config_unit_index|, and a |kConfigChanged| unit at that index. | 632 // |config_unit_index|, and a |kConfigChanged| unit at that index. |
| 636 // Player should prepare to reconfigure the decoder job, and should request | 633 // Player should prepare to reconfigure the decoder job, and should request |
| 637 // new demuxer configs. | 634 // new demuxer configs. |
| 638 player_.OnDemuxerDataAvailable( | 635 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( |
| 639 CreateReadFromDemuxerAckWithConfigChanged(is_audio, config_unit_index)); | 636 is_audio, config_unit_index, configs)); |
| 640 WaitForDecodeDone(is_audio, !is_audio); | |
| 641 | 637 |
| 642 expected_num_config_requests++; | 638 expected_num_data_requests++; |
| 643 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); | 639 EXPECT_EQ(expected_num_data_requests, demuxer_->num_data_requests()); |
| 644 EXPECT_EQ(expected_num_config_requests, demuxer_->num_config_requests()); | 640 if (is_audio) |
| 641 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); | |
| 642 else | |
| 643 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | |
| 644 } | |
| 645 | |
| 646 // Send a config change to the decoder job and drain the decoder so that the | |
| 647 // config change is processed. | |
| 648 void StartConfigChange(bool is_audio, | |
| 649 bool config_unit_in_prefetch, | |
| 650 int config_unit_index) { | |
| 651 SendConfigChangeToDecoder(is_audio, config_unit_in_prefetch, | |
| 652 config_unit_index); | |
| 653 int expected_num_data_requests = demuxer_->num_data_requests(); | |
| 654 // Run until decoder starts to request new data. | |
| 655 while(demuxer_->num_data_requests() == expected_num_data_requests) | |
|
wolenetz
2014/04/25 23:13:13
lint nit: Missing space before ( in while(
qinmin
2014/04/26 01:30:11
Done.
| |
| 656 message_loop_.RunUntilIdle(); | |
| 645 } | 657 } |
| 646 | 658 |
| 647 void CreateNextTextureAndSetVideoSurface() { | 659 void CreateNextTextureAndSetVideoSurface() { |
| 648 gfx::SurfaceTexture* surface_texture; | 660 gfx::SurfaceTexture* surface_texture; |
| 649 if (surface_texture_a_is_next_) { | 661 if (surface_texture_a_is_next_) { |
| 650 surface_texture_a_ = gfx::SurfaceTexture::Create(next_texture_id_++); | 662 surface_texture_a_ = gfx::SurfaceTexture::Create(next_texture_id_++); |
| 651 surface_texture = surface_texture_a_.get(); | 663 surface_texture = surface_texture_a_.get(); |
| 652 } else { | 664 } else { |
| 653 surface_texture_b_ = gfx::SurfaceTexture::Create(next_texture_id_++); | 665 surface_texture_b_ = gfx::SurfaceTexture::Create(next_texture_id_++); |
| 654 surface_texture = surface_texture_b_.get(); | 666 surface_texture = surface_texture_b_.get(); |
| 655 } | 667 } |
| 656 | 668 |
| 657 surface_texture_a_is_next_ = !surface_texture_a_is_next_; | 669 surface_texture_a_is_next_ = !surface_texture_a_is_next_; |
| 658 gfx::ScopedJavaSurface surface = gfx::ScopedJavaSurface(surface_texture); | 670 gfx::ScopedJavaSurface surface = gfx::ScopedJavaSurface(surface_texture); |
| 659 player_.SetVideoSurface(surface.Pass()); | 671 player_.SetVideoSurface(surface.Pass()); |
| 660 } | 672 } |
| 661 | 673 |
| 662 // Wait for one or both of the jobs to complete decoding. Decoder jobs are | 674 // Wait for one or both of the jobs to complete decoding. Decoder jobs are |
| 663 // assumed to exist for any stream whose decode completion is awaited. | 675 // assumed to exist for any stream whose decode completion is awaited. |
| 664 void WaitForDecodeDone(bool wait_for_audio, bool wait_for_video) { | 676 void WaitForDecodeDone(bool wait_for_audio, bool wait_for_video) { |
| 665 DCHECK(wait_for_audio || wait_for_video); | 677 DCHECK(wait_for_audio || wait_for_video); |
| 666 while ((wait_for_audio && GetMediaDecoderJob(true) && | 678 while ((wait_for_audio && GetMediaCodecBridge(true) && |
| 667 GetMediaDecoderJob(true)->HasData() && | 679 GetMediaDecoderJob(true)->HasData() && |
| 668 GetMediaDecoderJob(true)->is_decoding()) || | 680 GetMediaDecoderJob(true)->is_decoding()) || |
| 669 (wait_for_video && GetMediaDecoderJob(false) && | 681 (wait_for_video && GetMediaCodecBridge(false) && |
| 670 GetMediaDecoderJob(false)->HasData() && | 682 GetMediaDecoderJob(false)->HasData() && |
| 671 GetMediaDecoderJob(false)->is_decoding())) { | 683 GetMediaDecoderJob(false)->is_decoding())) { |
| 672 message_loop_.RunUntilIdle(); | 684 message_loop_.RunUntilIdle(); |
| 673 } | 685 } |
| 674 } | 686 } |
| 675 | 687 |
| 676 void WaitForAudioDecodeDone() { | 688 void WaitForAudioDecodeDone() { |
| 677 WaitForDecodeDone(true, false); | 689 WaitForDecodeDone(true, false); |
| 678 } | 690 } |
| 679 | 691 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 774 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 763 | 775 |
| 764 player_.OnDemuxerSeekDone(kNoTimestamp()); | 776 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 765 EXPECT_FALSE(manager_.playback_completed()); | 777 EXPECT_FALSE(manager_.playback_completed()); |
| 766 } | 778 } |
| 767 | 779 |
| 768 base::TimeTicks StartTimeTicks() { | 780 base::TimeTicks StartTimeTicks() { |
| 769 return player_.start_time_ticks_; | 781 return player_.start_time_ticks_; |
| 770 } | 782 } |
| 771 | 783 |
| 784 bool IsRequestingDemuxerData(bool is_audio) { | |
| 785 return GetMediaDecoderJob(is_audio)->is_requesting_demuxer_data_; | |
| 786 } | |
| 787 | |
| 788 bool IsDrainingDecoder(bool is_audio) { | |
| 789 return GetMediaDecoderJob(is_audio)->drain_decoder_; | |
| 790 } | |
| 791 | |
| 772 base::MessageLoop message_loop_; | 792 base::MessageLoop message_loop_; |
| 773 MockMediaPlayerManager manager_; | 793 MockMediaPlayerManager manager_; |
| 774 MockDemuxerAndroid* demuxer_; // Owned by |player_|. | 794 MockDemuxerAndroid* demuxer_; // Owned by |player_|. |
| 775 MediaSourcePlayer player_; | 795 MediaSourcePlayer player_; |
| 776 | 796 |
| 777 // Track whether a possibly async decoder callback test hook has run. | 797 // Track whether a possibly async decoder callback test hook has run. |
| 778 bool decoder_callback_hook_executed_; | 798 bool decoder_callback_hook_executed_; |
| 779 | 799 |
| 780 // We need to keep the surface texture while the decoder is actively decoding. | 800 // We need to keep the surface texture while the decoder is actively decoding. |
| 781 // Otherwise, it may trigger unexpected crashes on some devices. To switch | 801 // Otherwise, it may trigger unexpected crashes on some devices. To switch |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 803 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { | 823 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { |
| 804 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 824 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 805 | 825 |
| 806 // Test audio decoder job will not be created when failed to start the codec. | 826 // Test audio decoder job will not be created when failed to start the codec. |
| 807 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); | 827 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); |
| 808 // Replace with invalid |audio_extra_data| | 828 // Replace with invalid |audio_extra_data| |
| 809 configs.audio_extra_data.clear(); | 829 configs.audio_extra_data.clear(); |
| 810 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; | 830 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; |
| 811 configs.audio_extra_data.insert(configs.audio_extra_data.begin(), | 831 configs.audio_extra_data.insert(configs.audio_extra_data.begin(), |
| 812 invalid_codec_data, invalid_codec_data + 4); | 832 invalid_codec_data, invalid_codec_data + 4); |
| 813 Start(configs, false); | 833 // Prefetch() should happen before the decoder is created, so we should always |
| 834 // see data requests. | |
| 835 Start(configs, true); | |
| 814 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 836 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
| 815 } | 837 } |
| 816 | 838 |
| 817 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { | 839 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { |
| 818 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 840 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 819 | 841 |
| 820 // Test video decoder job will be created when surface is valid. | 842 // Test video decoder job will not be created until data is received. |
| 821 // Video decoder job will not be created until surface is available. | 843 StartVideoDecoderJob(true); |
| 822 StartVideoDecoderJob(false); | |
| 823 | 844 |
| 824 // Set both an initial and a later video surface without receiving any | 845 // Set both an initial and a later video surface without receiving any |
| 825 // demuxed data yet. | 846 // demuxed data yet. |
| 826 CreateNextTextureAndSetVideoSurface(); | 847 CreateNextTextureAndSetVideoSurface(); |
| 827 MediaDecoderJob* first_job = GetMediaDecoderJob(false); | 848 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 828 EXPECT_TRUE(first_job); | |
| 829 CreateNextTextureAndSetVideoSurface(); | 849 CreateNextTextureAndSetVideoSurface(); |
| 830 | 850 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 831 // Setting another surface will not create a new job until any pending | |
| 832 // read is satisfied (and job is no longer decoding). | |
| 833 EXPECT_EQ(first_job, GetMediaDecoderJob(false)); | |
| 834 | 851 |
| 835 // No seeks, even on setting surface, should have occurred. (Browser seeks can | 852 // No seeks, even on setting surface, should have occurred. (Browser seeks can |
| 836 // occur on setting surface, but only after previously receiving video data.) | 853 // occur on setting surface, but only after previously receiving video data.) |
| 837 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 854 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
| 838 | 855 |
| 839 // Note, the decoder job for the second surface set, above, will be created | 856 // Send the first input chunk and verify that decoder will be created. |
| 840 // only after the pending read is satisfied and decoded, and the resulting | 857 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 841 // browser seek is done. See BrowserSeek_* tests for this coverage. | 858 EXPECT_TRUE(GetMediaCodecBridge(false)); |
| 842 } | 859 } |
| 843 | 860 |
| 844 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { | 861 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { |
| 845 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 862 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 846 | 863 |
| 847 // Test video decoder job will not be created when surface is invalid. | 864 // Test video decoder job will not be created when surface is invalid. |
| 848 scoped_refptr<gfx::SurfaceTexture> surface_texture( | 865 scoped_refptr<gfx::SurfaceTexture> surface_texture( |
| 849 gfx::SurfaceTexture::Create(0)); | 866 gfx::SurfaceTexture::Create(0)); |
| 850 gfx::ScopedJavaSurface surface(surface_texture.get()); | 867 gfx::ScopedJavaSurface surface(surface_texture.get()); |
| 851 StartVideoDecoderJob(false); | 868 StartVideoDecoderJob(true); |
| 852 | 869 |
| 853 // Release the surface texture. | 870 // Release the surface texture. |
| 854 surface_texture = NULL; | 871 surface_texture = NULL; |
| 855 player_.SetVideoSurface(surface.Pass()); | 872 player_.SetVideoSurface(surface.Pass()); |
| 856 | 873 |
| 857 // Player should not seek the demuxer on setting initial surface. | 874 // Player should not seek the demuxer on setting initial surface. |
| 858 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 875 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
| 859 | 876 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 860 EXPECT_FALSE(GetMediaDecoderJob(false)); | |
| 861 EXPECT_EQ(0, demuxer_->num_data_requests()); | |
| 862 } | 877 } |
| 863 | 878 |
| 864 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) { | 879 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) { |
| 865 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 880 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 866 | 881 |
| 867 // Test decoder job will resend a ReadFromDemuxer request after seek. | 882 // Test decoder job will resend a ReadFromDemuxer request after seek. |
| 868 StartAudioDecoderJob(true); | 883 StartAudioDecoderJob(true); |
| 869 SeekPlayerWithAbort(true, base::TimeDelta()); | 884 SeekPlayerWithAbort(true, base::TimeDelta()); |
| 870 } | 885 } |
| 871 | 886 |
| 872 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { | 887 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { |
| 873 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 888 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 874 | 889 |
| 875 // Test SetVideoSurface() will not cause an extra seek while the player is | 890 // Test SetVideoSurface() will not cause an extra seek while the player is |
| 876 // waiting for demuxer to indicate seek is done. | 891 // waiting for demuxer to indicate seek is done. |
| 877 // Player is still waiting for SetVideoSurface(), so no request is sent. | 892 player_.OnDemuxerConfigsAvailable(CreateVideoDemuxerConfigs(kCodecVP8)); |
| 878 StartVideoDecoderJob(false); // Verifies no data requested. | |
| 879 | 893 |
| 880 // Initiate a seek. Skip requesting element seek of renderer. | 894 // Initiate a seek. Skip requesting element seek of renderer. |
| 881 // Instead behave as if the renderer has asked us to seek. | 895 // Instead behave as if the renderer has asked us to seek. |
| 882 EXPECT_EQ(0, demuxer_->num_seek_requests()); | |
| 883 player_.SeekTo(base::TimeDelta()); | 896 player_.SeekTo(base::TimeDelta()); |
| 884 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 897 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 885 | 898 |
| 886 CreateNextTextureAndSetVideoSurface(); | 899 CreateNextTextureAndSetVideoSurface(); |
| 887 EXPECT_FALSE(GetMediaDecoderJob(false)); | |
| 888 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 900 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 889 | 901 player_.Start(); |
| 890 // Reconfirm player has not yet requested data. | |
| 891 EXPECT_EQ(0, demuxer_->num_data_requests()); | |
| 892 | 902 |
| 893 // Send the seek done notification. The player should start requesting data. | 903 // Send the seek done notification. The player should start requesting data. |
| 894 player_.OnDemuxerSeekDone(kNoTimestamp()); | 904 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 895 EXPECT_TRUE(GetMediaDecoderJob(false)); | 905 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 896 EXPECT_EQ(1, demuxer_->num_data_requests()); | 906 EXPECT_EQ(1, demuxer_->num_data_requests()); |
| 907 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | |
| 908 EXPECT_TRUE(GetMediaCodecBridge(false)); | |
| 897 | 909 |
| 898 // Reconfirm exactly 1 seek request has been made of demuxer, and that it | 910 // Reconfirm exactly 1 seek request has been made of demuxer, and that it |
| 899 // was not a browser seek request. | 911 // was not a browser seek request. |
| 900 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 912 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 901 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); | 913 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); |
| 902 } | 914 } |
| 903 | 915 |
| 904 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) { | 916 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) { |
| 905 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 917 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 906 | 918 |
| 907 // Test MediaSourcePlayer can switch multiple surfaces during decoding. | 919 // Test MediaSourcePlayer can switch multiple surfaces during decoding. |
| 908 CreateNextTextureAndSetVideoSurface(); | 920 CreateNextTextureAndSetVideoSurface(); |
| 909 StartVideoDecoderJob(true); | 921 StartVideoDecoderJob(true); |
| 910 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 922 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
| 911 | 923 |
| 912 // Send the first input chunk. | 924 // Send the first input chunk. |
| 913 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 925 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 914 | 926 |
| 915 // While the decoder is decoding, change multiple surfaces. Pass an empty | 927 // While the decoder is decoding, change multiple surfaces. Pass an empty |
| 916 // surface first. | 928 // surface first. |
| 917 gfx::ScopedJavaSurface empty_surface; | 929 gfx::ScopedJavaSurface empty_surface; |
| 918 player_.SetVideoSurface(empty_surface.Pass()); | 930 player_.SetVideoSurface(empty_surface.Pass()); |
| 919 // Next, pass a new non-empty surface. | 931 // Next, pass a new non-empty surface. |
| 920 CreateNextTextureAndSetVideoSurface(); | 932 CreateNextTextureAndSetVideoSurface(); |
| 921 | 933 |
| 922 // Wait for the decoder job to finish decoding and be reset pending a browser | 934 // Wait for the decoder job to finish decoding and be reset pending a browser |
| 923 // seek. | 935 // seek. |
| 924 WaitForVideoDecodeDone(); | 936 WaitForVideoDecodeDone(); |
| 925 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 937 player_.OnDemuxerDataAvailable(CreateAbortedAck(false)); |
| 926 | 938 |
| 927 // Only one browser seek should have been initiated. No further data request | 939 // Only one browser seek should have been initiated. No further data request |
| 928 // should have been processed on |message_loop_| before surface change event | 940 // should have been processed on |message_loop_| before surface change event |
| 929 // became pending, above. | 941 // became pending, above. |
| 930 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); | 942 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); |
| 931 EXPECT_EQ(2, demuxer_->num_data_requests()); | 943 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 932 | 944 |
| 933 // Simulate browser seek is done and confirm player requests more data for new | 945 // Simulate browser seek is done and confirm player requests more data for new |
| 934 // video decoder job. | 946 // video decoder job. |
| 935 player_.OnDemuxerSeekDone(player_.GetCurrentTime()); | 947 player_.OnDemuxerSeekDone(player_.GetCurrentTime()); |
| 936 EXPECT_TRUE(GetMediaDecoderJob(false)); | 948 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 937 EXPECT_EQ(3, demuxer_->num_data_requests()); | 949 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 938 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 950 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 951 | |
| 952 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | |
| 953 EXPECT_TRUE(GetMediaCodecBridge(false)); | |
| 939 } | 954 } |
| 940 | 955 |
| 941 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) { | 956 TEST_F(MediaSourcePlayerTest, SetEmptySurfaceAndStarveWhileDecoding) { |
| 942 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 957 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 943 | 958 |
| 944 // Test player pauses if an empty surface is passed. | 959 // Test player pauses if an empty surface is passed. |
| 945 CreateNextTextureAndSetVideoSurface(); | 960 CreateNextTextureAndSetVideoSurface(); |
| 946 StartVideoDecoderJob(true); | 961 StartVideoDecoderJob(true); |
| 947 EXPECT_EQ(1, demuxer_->num_data_requests()); | 962 EXPECT_EQ(1, demuxer_->num_data_requests()); |
| 948 | 963 |
| 949 // Send the first input chunk. | 964 // Send the first input chunk. |
| 950 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 965 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 951 | 966 |
| 952 // While the decoder is decoding, pass an empty surface. | 967 // While the decoder is decoding, pass an empty surface. |
| 953 gfx::ScopedJavaSurface empty_surface; | 968 gfx::ScopedJavaSurface empty_surface; |
| 954 player_.SetVideoSurface(empty_surface.Pass()); | 969 player_.SetVideoSurface(empty_surface.Pass()); |
| 955 // Let the player starve. However, it should not issue any new data request in | 970 // Let the player starve. However, it should not issue any new data request in |
| 956 // this case. | 971 // this case. |
| 957 TriggerPlayerStarvation(); | 972 TriggerPlayerStarvation(); |
| 958 // Wait for the decoder job to finish decoding and be reset. | 973 // Wait for the decoder job to finish decoding and be reset. |
| 959 while (GetMediaDecoderJob(false)) | 974 while (GetMediaDecoderJob(false)->is_decoding()) |
| 960 message_loop_.RunUntilIdle(); | 975 message_loop_.RunUntilIdle(); |
| 961 | 976 |
| 962 // No further seek or data requests should have been received since the | 977 // No further seek or data requests should have been received since the |
| 963 // surface is empty. | 978 // surface is empty. |
| 964 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); | 979 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); |
| 965 EXPECT_EQ(2, demuxer_->num_data_requests()); | 980 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 966 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 981 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 967 | 982 |
| 968 // Playback resumes once a non-empty surface is passed. | 983 // Playback resumes once a non-empty surface is passed. |
| 969 CreateNextTextureAndSetVideoSurface(); | 984 CreateNextTextureAndSetVideoSurface(); |
| 970 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); | 985 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); |
| 971 } | 986 } |
| 972 | 987 |
| 973 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) { | 988 TEST_F(MediaSourcePlayerTest, ReleaseVideoDecoderResourcesWhileDecoding) { |
| 974 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 989 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 975 | 990 |
| 976 // Test that if video decoder is released while decoding, the resources will | 991 // Test that if video decoder is released while decoding, the resources will |
| 977 // not be immediately released. | 992 // not be immediately released. |
| 978 CreateNextTextureAndSetVideoSurface(); | 993 CreateNextTextureAndSetVideoSurface(); |
| 979 StartVideoDecoderJob(true); | 994 StartVideoDecoderJob(true); |
| 980 EXPECT_EQ(1, manager_.num_resources_requested()); | 995 // No resource is requested since there is no data to decode. |
| 996 EXPECT_EQ(0, manager_.num_resources_requested()); | |
| 981 ReleasePlayer(); | 997 ReleasePlayer(); |
| 982 // The resources will be immediately released since the decoder is idle. | 998 EXPECT_EQ(0, manager_.num_resources_released()); |
| 983 EXPECT_EQ(1, manager_.num_resources_released()); | |
| 984 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 999 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 985 | 1000 |
| 986 // Recreate the video decoder. | 1001 // Recreate the video decoder. |
| 987 CreateNextTextureAndSetVideoSurface(); | 1002 CreateNextTextureAndSetVideoSurface(); |
| 988 player_.Start(); | 1003 player_.Start(); |
| 989 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); | 1004 while (!GetMediaDecoderJob(false)->is_decoding()) |
| 990 player_.OnDemuxerSeekDone(base::TimeDelta()); | 1005 message_loop_.RunUntilIdle(); |
| 991 EXPECT_EQ(2, manager_.num_resources_requested()); | 1006 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); |
| 992 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 1007 EXPECT_EQ(1, manager_.num_resources_requested()); |
| 993 ReleasePlayer(); | 1008 ReleasePlayer(); |
| 994 // The resource is still held by the video decoder until it finishes decoding. | 1009 // The resource is still held by the video decoder until it finishes decoding. |
| 995 EXPECT_EQ(1, manager_.num_resources_released()); | 1010 EXPECT_EQ(0, manager_.num_resources_released()); |
| 996 // Wait for the decoder job to finish decoding and be reset. | 1011 // Wait for the decoder job to finish decoding and be reset. |
| 997 while (manager_.num_resources_released() != 2) | 1012 while (manager_.num_resources_released() != 1) |
| 998 message_loop_.RunUntilIdle(); | 1013 message_loop_.RunUntilIdle(); |
| 999 } | 1014 } |
| 1000 | 1015 |
| 1001 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) { | 1016 TEST_F(MediaSourcePlayerTest, AudioOnlyStartAfterSeekFinish) { |
| 1002 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1017 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1003 | 1018 |
| 1004 // Test audio decoder job will not start until pending seek event is handled. | 1019 // Test audio decoder job will not start until pending seek event is handled. |
| 1005 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); | 1020 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); |
| 1006 player_.OnDemuxerConfigsAvailable(configs); | 1021 player_.OnDemuxerConfigsAvailable(configs); |
| 1007 EXPECT_FALSE(GetMediaDecoderJob(true)); | |
| 1008 | 1022 |
| 1009 // Initiate a seek. Skip requesting element seek of renderer. | 1023 // Initiate a seek. Skip requesting element seek of renderer. |
| 1010 // Instead behave as if the renderer has asked us to seek. | 1024 // Instead behave as if the renderer has asked us to seek. |
| 1011 player_.SeekTo(base::TimeDelta()); | 1025 player_.SeekTo(base::TimeDelta()); |
| 1012 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1026 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1013 | 1027 |
| 1014 player_.Start(); | 1028 player_.Start(); |
| 1015 EXPECT_FALSE(GetMediaDecoderJob(true)); | |
| 1016 EXPECT_EQ(0, demuxer_->num_data_requests()); | 1029 EXPECT_EQ(0, demuxer_->num_data_requests()); |
| 1017 | 1030 |
| 1018 // Sending back the seek done notification. | 1031 // Sending back the seek done notification. |
| 1019 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1032 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1020 EXPECT_TRUE(GetMediaDecoderJob(true)); | 1033 EXPECT_FALSE(GetMediaCodecBridge(true)); |
| 1021 EXPECT_EQ(1, demuxer_->num_data_requests()); | 1034 EXPECT_EQ(1, demuxer_->num_data_requests()); |
| 1022 | 1035 |
| 1023 // Reconfirm exactly 1 seek request has been made of demuxer. | 1036 // Reconfirm exactly 1 seek request has been made of demuxer. |
| 1024 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1037 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1038 | |
| 1039 // Decoder is created after data is received. | |
| 1040 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); | |
| 1041 EXPECT_TRUE(GetMediaCodecBridge(true)); | |
| 1025 } | 1042 } |
| 1026 | 1043 |
| 1027 TEST_F(MediaSourcePlayerTest, VideoOnlyStartAfterSeekFinish) { | 1044 TEST_F(MediaSourcePlayerTest, VideoOnlyStartAfterSeekFinish) { |
| 1028 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1045 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1029 | 1046 |
| 1030 // Test video decoder job will not start until pending seek event is handled. | 1047 // Test video decoder job will not start until pending seek event is handled. |
| 1031 CreateNextTextureAndSetVideoSurface(); | 1048 CreateNextTextureAndSetVideoSurface(); |
| 1032 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); | 1049 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP8); |
| 1033 player_.OnDemuxerConfigsAvailable(configs); | 1050 player_.OnDemuxerConfigsAvailable(configs); |
| 1034 EXPECT_FALSE(GetMediaDecoderJob(false)); | |
| 1035 | 1051 |
| 1036 // Initiate a seek. Skip requesting element seek of renderer. | 1052 // Initiate a seek. Skip requesting element seek of renderer. |
| 1037 // Instead behave as if the renderer has asked us to seek. | 1053 // Instead behave as if the renderer has asked us to seek. |
| 1038 player_.SeekTo(base::TimeDelta()); | 1054 player_.SeekTo(base::TimeDelta()); |
| 1039 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1055 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1040 | 1056 |
| 1041 player_.Start(); | 1057 player_.Start(); |
| 1042 EXPECT_FALSE(GetMediaDecoderJob(false)); | |
| 1043 EXPECT_EQ(0, demuxer_->num_data_requests()); | 1058 EXPECT_EQ(0, demuxer_->num_data_requests()); |
| 1044 | 1059 |
| 1045 // Sending back the seek done notification. | 1060 // Sending back the seek done notification. |
| 1046 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1061 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1047 EXPECT_TRUE(GetMediaDecoderJob(false)); | 1062 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 1048 EXPECT_EQ(1, demuxer_->num_data_requests()); | 1063 EXPECT_EQ(1, demuxer_->num_data_requests()); |
| 1049 | 1064 |
| 1050 // Reconfirm exactly 1 seek request has been made of demuxer. | 1065 // Reconfirm exactly 1 seek request has been made of demuxer. |
| 1051 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1066 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1067 | |
| 1068 // Decoder is created after data is received. | |
| 1069 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | |
| 1070 EXPECT_TRUE(GetMediaCodecBridge(false)); | |
| 1052 } | 1071 } |
| 1053 | 1072 |
| 1054 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) { | 1073 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) { |
| 1055 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1074 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1056 | 1075 |
| 1057 // Test that if the decoding job is not fully stopped after Pause(), | 1076 // Test that if the decoding job is not fully stopped after Pause(), |
| 1058 // calling Start() will be a noop. | 1077 // calling Start() will be a noop. |
| 1059 StartAudioDecoderJob(true); | 1078 StartAudioDecoderJob(true); |
| 1060 | 1079 |
| 1061 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); | 1080 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1073 | 1092 |
| 1074 // Nothing happens when calling Start() again. | 1093 // Nothing happens when calling Start() again. |
| 1075 player_.Start(); | 1094 player_.Start(); |
| 1076 // Verify that Start() will not destroy and recreate the decoder job. | 1095 // Verify that Start() will not destroy and recreate the decoder job. |
| 1077 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); | 1096 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); |
| 1078 | 1097 |
| 1079 while (GetMediaDecoderJob(true)->is_decoding()) | 1098 while (GetMediaDecoderJob(true)->is_decoding()) |
| 1080 message_loop_.RunUntilIdle(); | 1099 message_loop_.RunUntilIdle(); |
| 1081 // The decoder job should finish and wait for data. | 1100 // The decoder job should finish and wait for data. |
| 1082 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1101 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1083 EXPECT_TRUE(GetMediaDecoderJob(true)->is_requesting_demuxer_data()); | 1102 EXPECT_TRUE(IsRequestingDemuxerData(true)); |
| 1084 } | 1103 } |
| 1085 | 1104 |
| 1086 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { | 1105 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { |
| 1087 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1106 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1088 | 1107 |
| 1089 // Test that when Start() is called, video decoder jobs will wait for audio | 1108 // Test that when Start() is called, video decoder jobs will wait for audio |
| 1090 // decoder job before start decoding the data. | 1109 // decoder job before start decoding the data. |
| 1091 CreateNextTextureAndSetVideoSurface(); | 1110 CreateNextTextureAndSetVideoSurface(); |
| 1092 Start(CreateAudioVideoDemuxerConfigs(), true); | 1111 Start(CreateAudioVideoDemuxerConfigs(), true); |
| 1093 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true); | 1112 MediaDecoderJob* audio_decoder_job = GetMediaDecoderJob(true); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1117 | 1136 |
| 1118 DecodeAudioDataUntilOutputBecomesAvailable(); | 1137 DecodeAudioDataUntilOutputBecomesAvailable(); |
| 1119 | 1138 |
| 1120 // The decoder job should finish and a new request will be sent. | 1139 // The decoder job should finish and a new request will be sent. |
| 1121 base::TimeTicks previous = StartTimeTicks(); | 1140 base::TimeTicks previous = StartTimeTicks(); |
| 1122 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); | 1141 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); |
| 1123 | 1142 |
| 1124 // Let the decoder starve. | 1143 // Let the decoder starve. |
| 1125 TriggerPlayerStarvation(); | 1144 TriggerPlayerStarvation(); |
| 1126 WaitForAudioDecodeDone(); | 1145 WaitForAudioDecodeDone(); |
| 1127 | 1146 EXPECT_TRUE(StartTimeTicks() == previous); |
| 1128 // Verify the start time ticks is cleared at this point because the | |
| 1129 // player is prefetching. | |
| 1130 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks()); | |
| 1131 | 1147 |
| 1132 // Send new data to the decoder so it can finish prefetching. This should | 1148 // Send new data to the decoder so it can finish prefetching. This should |
| 1133 // reset the start time ticks. | 1149 // reset the start time ticks. |
| 1134 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); | 1150 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); |
| 1135 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); | 1151 EXPECT_TRUE(StartTimeTicks() != previous); |
| 1136 | 1152 |
| 1137 base::TimeTicks current = StartTimeTicks(); | 1153 base::TimeTicks current = StartTimeTicks(); |
| 1138 EXPECT_LE(0, (current - previous).InMillisecondsF()); | 1154 EXPECT_LE(0, (current - previous).InMillisecondsF()); |
| 1139 } | 1155 } |
| 1140 | 1156 |
| 1141 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) { | 1157 TEST_F(MediaSourcePlayerTest, V_SecondAccessUnitIsEOSAndResumePlayAfterSeek) { |
| 1142 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1158 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1143 | 1159 |
| 1144 // Test MediaSourcePlayer can replay video after input EOS is reached. | 1160 // Test MediaSourcePlayer can replay video after input EOS is reached. |
| 1145 CreateNextTextureAndSetVideoSurface(); | 1161 CreateNextTextureAndSetVideoSurface(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1192 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1208 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1193 | 1209 |
| 1194 // Test that if one stream (audio) has completed decode of EOS and the other | 1210 // Test that if one stream (audio) has completed decode of EOS and the other |
| 1195 // stream (video) processes config change, that subsequent video EOS completes | 1211 // stream (video) processes config change, that subsequent video EOS completes |
| 1196 // A/V playback. | 1212 // A/V playback. |
| 1197 // Also tests that seeking+Start() after completing playback resumes playback. | 1213 // Also tests that seeking+Start() after completing playback resumes playback. |
| 1198 CreateNextTextureAndSetVideoSurface(); | 1214 CreateNextTextureAndSetVideoSurface(); |
| 1199 Start(CreateAudioVideoDemuxerConfigs(), true); | 1215 Start(CreateAudioVideoDemuxerConfigs(), true); |
| 1200 | 1216 |
| 1201 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS | 1217 player_.OnDemuxerDataAvailable(CreateEOSAck(true)); // Audio EOS |
| 1202 EXPECT_EQ(0, demuxer_->num_config_requests()); | 1218 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP9); |
| 1203 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( | 1219 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( |
| 1204 false, 0)); // Video |kConfigChanged| as first unit. | 1220 false, 0, configs)); // Video |kConfigChanged| as first unit. |
| 1205 | 1221 |
| 1206 WaitForAudioVideoDecodeDone(); | 1222 WaitForAudioVideoDecodeDone(); |
| 1207 | 1223 |
| 1208 EXPECT_EQ(1, demuxer_->num_config_requests()); | |
| 1209 EXPECT_EQ(2, demuxer_->num_data_requests()); | |
| 1210 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs()); | |
| 1211 EXPECT_EQ(3, demuxer_->num_data_requests()); | 1224 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1212 | 1225 |
| 1213 // At no time after completing audio EOS decode, above, should the | 1226 // At no time after completing audio EOS decode, above, should the |
| 1214 // audio decoder job resume decoding. Send and decode video EOS. | 1227 // audio decoder job resume decoding. Send and decode video EOS. |
| 1215 VerifyPlaybackCompletesOnEOSDecode(true, false); | 1228 VerifyPlaybackCompletesOnEOSDecode(true, false); |
| 1216 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); | 1229 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); |
| 1217 } | 1230 } |
| 1218 | 1231 |
| 1219 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) { | 1232 TEST_F(MediaSourcePlayerTest, VA_PlaybackCompletionAcrossConfigChange) { |
| 1220 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1233 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1221 | 1234 |
| 1222 // Test that if one stream (video) has completed decode of EOS and the other | 1235 // Test that if one stream (video) has completed decode of EOS and the other |
| 1223 // stream (audio) processes config change, that subsequent audio EOS completes | 1236 // stream (audio) processes config change, that subsequent audio EOS completes |
| 1224 // A/V playback. | 1237 // A/V playback. |
| 1225 // Also tests that seeking+Start() after completing playback resumes playback. | 1238 // Also tests that seeking+Start() after completing playback resumes playback. |
| 1226 CreateNextTextureAndSetVideoSurface(); | 1239 CreateNextTextureAndSetVideoSurface(); |
| 1227 Start(CreateAudioVideoDemuxerConfigs(), true); | 1240 Start(CreateAudioVideoDemuxerConfigs(), true); |
| 1228 | 1241 |
| 1229 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS | 1242 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); // Video EOS |
| 1230 EXPECT_EQ(0, demuxer_->num_config_requests()); | 1243 // Audio |kConfigChanged| as first unit. |
| 1231 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( | 1244 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckWithConfigChanged( |
| 1232 true, 0)); // Audio |kConfigChanged| as first unit. | 1245 true, 0, CreateAudioDemuxerConfigs(kCodecVorbis))); |
| 1233 | 1246 |
| 1234 WaitForAudioVideoDecodeDone(); | 1247 WaitForAudioVideoDecodeDone(); |
| 1235 | 1248 |
| 1236 // TODO(wolenetz/qinmin): Prevent redundant demuxer config request and change | |
| 1237 // expectation to 1 here. See http://crbug.com/325528. | |
| 1238 EXPECT_EQ(2, demuxer_->num_config_requests()); | |
| 1239 EXPECT_EQ(2, demuxer_->num_data_requests()); | |
| 1240 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs()); | |
| 1241 EXPECT_EQ(3, demuxer_->num_data_requests()); | 1249 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1242 | 1250 |
| 1243 // At no time after completing video EOS decode, above, should the | 1251 // At no time after completing video EOS decode, above, should the |
| 1244 // video decoder job resume decoding. Send and decode audio EOS. | 1252 // video decoder job resume decoding. Send and decode audio EOS. |
| 1245 VerifyPlaybackCompletesOnEOSDecode(true, true); | 1253 VerifyPlaybackCompletesOnEOSDecode(true, true); |
| 1246 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); | 1254 VerifyCompletedPlaybackResumesOnSeekPlusStart(true, true); |
| 1247 } | 1255 } |
| 1248 | 1256 |
| 1249 TEST_F(MediaSourcePlayerTest, AV_NoPrefetchForFinishedVideoOnAudioStarvation) { | 1257 TEST_F(MediaSourcePlayerTest, AV_NoPrefetchForFinishedVideoOnAudioStarvation) { |
| 1250 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1258 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1399 | 1407 |
| 1400 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) { | 1408 TEST_F(MediaSourcePlayerTest, BrowserSeek_RegularSeekPendsBrowserSeekDone) { |
| 1401 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1409 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1402 | 1410 |
| 1403 // Test that a browser seek, once started, delays a newly arrived regular | 1411 // Test that a browser seek, once started, delays a newly arrived regular |
| 1404 // SeekTo() request's demuxer seek until the browser seek is done. | 1412 // SeekTo() request's demuxer seek until the browser seek is done. |
| 1405 BrowserSeekPlayer(false); | 1413 BrowserSeekPlayer(false); |
| 1406 | 1414 |
| 1407 // Simulate renderer requesting a regular seek while browser seek in progress. | 1415 // Simulate renderer requesting a regular seek while browser seek in progress. |
| 1408 player_.SeekTo(base::TimeDelta()); | 1416 player_.SeekTo(base::TimeDelta()); |
| 1409 EXPECT_FALSE(GetMediaDecoderJob(false)); | |
| 1410 | 1417 |
| 1411 // Simulate browser seek is done. Confirm player requests the regular seek, | 1418 // Simulate browser seek is done. Confirm player requests the regular seek, |
| 1412 // still has no video decoder job configured, and has not requested any | 1419 // still has no video decoder job configured, and has not requested any |
| 1413 // further data since the surface change event became pending in | 1420 // further data since the surface change event became pending in |
| 1414 // BrowserSeekPlayer(). | 1421 // BrowserSeekPlayer(). |
| 1415 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1422 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1416 player_.OnDemuxerSeekDone(base::TimeDelta()); | 1423 player_.OnDemuxerSeekDone(base::TimeDelta()); |
| 1417 EXPECT_FALSE(GetMediaDecoderJob(false)); | |
| 1418 EXPECT_EQ(2, demuxer_->num_seek_requests()); | 1424 EXPECT_EQ(2, demuxer_->num_seek_requests()); |
| 1419 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); | 1425 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); |
| 1420 | 1426 |
| 1421 // Simulate regular seek is done and confirm player requests more data for | 1427 // Simulate regular seek is done and confirm player requests more data for |
| 1422 // new video decoder job. | 1428 // new video decoder job. |
| 1423 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1429 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1424 EXPECT_TRUE(GetMediaDecoderJob(false)); | 1430 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 1425 EXPECT_EQ(3, demuxer_->num_data_requests()); | 1431 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1426 EXPECT_EQ(2, demuxer_->num_seek_requests()); | 1432 EXPECT_EQ(2, demuxer_->num_seek_requests()); |
| 1433 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | |
| 1434 EXPECT_TRUE(GetMediaCodecBridge(false)); | |
| 1427 } | 1435 } |
| 1428 | 1436 |
| 1429 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) { | 1437 TEST_F(MediaSourcePlayerTest, BrowserSeek_InitialReleaseAndStart) { |
| 1430 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1438 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1431 | 1439 |
| 1432 // Test that browser seek is requested if player Release() + Start() occurs | 1440 // Test that browser seek is requested if player Release() + Start() occurs |
| 1433 // prior to receiving any data. | 1441 // prior to receiving any data. |
| 1434 CreateNextTextureAndSetVideoSurface(); | 1442 CreateNextTextureAndSetVideoSurface(); |
| 1435 StartVideoDecoderJob(true); | 1443 StartVideoDecoderJob(true); |
| 1436 ReleasePlayer(); | 1444 ReleasePlayer(); |
| 1437 | 1445 |
| 1438 // Pass a new non-empty surface. | 1446 // Pass a new non-empty surface. |
| 1439 CreateNextTextureAndSetVideoSurface(); | 1447 CreateNextTextureAndSetVideoSurface(); |
| 1440 | 1448 |
| 1441 player_.Start(); | 1449 player_.Start(); |
| 1442 | 1450 |
| 1443 // The new player won't be created until the pending data request is | 1451 // No data request is issued since there is still one pending. |
| 1444 // processed. | |
| 1445 EXPECT_EQ(1, demuxer_->num_data_requests()); | 1452 EXPECT_EQ(1, demuxer_->num_data_requests()); |
| 1446 EXPECT_FALSE(GetMediaDecoderJob(false)); | 1453 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 1447 | 1454 |
| 1448 // A browser seek should be requested. | 1455 // No browser seek is needed. |
| 1449 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 1456 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 1450 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); | 1457 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); |
| 1451 EXPECT_EQ(1, demuxer_->num_data_requests()); | 1458 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1452 } | 1459 } |
| 1453 | 1460 |
| 1454 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) { | 1461 TEST_F(MediaSourcePlayerTest, BrowserSeek_MidStreamReleaseAndStart) { |
| 1455 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1462 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1456 | 1463 |
| 1457 // Test that one browser seek is requested if player Release() + Start(), with | 1464 // Test that one browser seek is requested if player Release() + Start(), with |
| 1458 // video data received between Release() and Start(). | 1465 // video data received between Release() and Start(). |
| 1459 BrowserSeekPlayer(true); | 1466 BrowserSeekPlayer(true); |
| 1460 | 1467 |
| 1461 // Simulate browser seek is done and confirm player requests more data. | 1468 // Simulate browser seek is done and confirm player requests more data. |
| 1462 player_.OnDemuxerSeekDone(base::TimeDelta()); | 1469 player_.OnDemuxerSeekDone(base::TimeDelta()); |
| 1463 EXPECT_TRUE(GetMediaDecoderJob(false)); | 1470 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1464 EXPECT_EQ(2, demuxer_->num_data_requests()); | |
| 1465 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1471 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1466 } | 1472 } |
| 1467 | 1473 |
| 1468 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { | 1474 TEST_F(MediaSourcePlayerTest, PrerollAudioAfterSeek) { |
| 1469 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1475 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1470 | 1476 |
| 1471 // Test decoder job will preroll the media to the seek position. | 1477 // Test decoder job will preroll the media to the seek position. |
| 1472 StartAudioDecoderJob(true); | 1478 StartAudioDecoderJob(true); |
| 1473 | 1479 |
| 1474 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); | 1480 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1552 // While still prerolling, Release() and Start() the player. | 1558 // While still prerolling, Release() and Start() the player. |
| 1553 // TODO(qinmin): Simulation of multiple in-flight data requests (one from | 1559 // TODO(qinmin): Simulation of multiple in-flight data requests (one from |
| 1554 // before Release(), one from after Start()) is not included here, and | 1560 // before Release(), one from after Start()) is not included here, and |
| 1555 // neither is any data enqueued for later decode if it arrives after | 1561 // neither is any data enqueued for later decode if it arrives after |
| 1556 // Release() and before Start(). See http://crbug.com/306314. Assumption | 1562 // Release() and before Start(). See http://crbug.com/306314. Assumption |
| 1557 // for this test, to prevent flakiness until the bug is fixed, is the | 1563 // for this test, to prevent flakiness until the bug is fixed, is the |
| 1558 // first request's data arrives before Start(). Though that data is not | 1564 // first request's data arrives before Start(). Though that data is not |
| 1559 // seen by decoder, this assumption allows preroll continuation | 1565 // seen by decoder, this assumption allows preroll continuation |
| 1560 // verification and prevents multiple in-flight data requests. | 1566 // verification and prevents multiple in-flight data requests. |
| 1561 ReleasePlayer(); | 1567 ReleasePlayer(); |
| 1562 player_.OnDemuxerDataAvailable(data); | 1568 // The decoder is still decoding and will not be immediately released. |
| 1563 WaitForAudioDecodeDone(); | 1569 EXPECT_TRUE(GetMediaCodecBridge(true)); |
| 1564 EXPECT_FALSE(GetMediaDecoderJob(true)); | 1570 StartAudioDecoderJob(false); |
| 1565 StartAudioDecoderJob(true); | |
| 1566 } else { | 1571 } else { |
| 1567 player_.OnDemuxerDataAvailable(data); | 1572 player_.OnDemuxerDataAvailable(data); |
| 1568 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 1573 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
| 1569 WaitForAudioDecodeDone(); | 1574 WaitForAudioDecodeDone(); |
| 1570 } | 1575 } |
| 1571 EXPECT_TRUE(IsPrerolling(true)); | 1576 EXPECT_TRUE(IsPrerolling(true)); |
| 1572 } | 1577 } |
| 1573 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); | 1578 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); |
| 1574 EXPECT_TRUE(IsPrerolling(true)); | 1579 EXPECT_TRUE(IsPrerolling(true)); |
| 1575 | 1580 |
| 1576 // Send data after the seek position. | 1581 // Send data after the seek position. |
| 1577 PrerollDecoderToTime(true, target_timestamp, target_timestamp); | 1582 PrerollDecoderToTime(true, target_timestamp, target_timestamp); |
| 1578 } | 1583 } |
| 1579 | 1584 |
| 1580 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) { | 1585 TEST_F(MediaSourcePlayerTest, PrerollContinuesAcrossConfigChange) { |
| 1581 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1586 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1582 | 1587 |
| 1583 // Test decoder job will resume media prerolling if interrupted by | 1588 // Test decoder job will resume media prerolling if interrupted by |
| 1584 // |kConfigChanged| and OnDemuxerConfigsAvailable(). | 1589 // |kConfigChanged| and OnDemuxerConfigsAvailable(). |
| 1585 StartAudioDecoderJob(true); | 1590 StartAudioDecoderJob(true); |
| 1586 | 1591 |
| 1587 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); | 1592 SeekPlayerWithAbort(true, base::TimeDelta::FromMilliseconds(100)); |
| 1588 EXPECT_TRUE(IsPrerolling(true)); | 1593 EXPECT_TRUE(IsPrerolling(true)); |
| 1589 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1594 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1590 | 1595 |
| 1596 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); | |
| 1597 configs.audio_sampling_rate = 11025; | |
| 1598 | |
| 1591 // In response to data request, simulate that demuxer signals config change by | 1599 // In response to data request, simulate that demuxer signals config change by |
| 1592 // sending an AU with |kConfigChanged|. Player should prepare to reconfigure | 1600 // sending an AU with |kConfigChanged|. |
| 1593 // the audio decoder job, and should request new demuxer configs. | 1601 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged( |
| 1594 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); | 1602 true, 0, configs); |
| 1595 EXPECT_EQ(0, demuxer_->num_config_requests()); | |
| 1596 player_.OnDemuxerDataAvailable(data); | 1603 player_.OnDemuxerDataAvailable(data); |
| 1597 EXPECT_EQ(1, demuxer_->num_config_requests()); | |
| 1598 | |
| 1599 // Simulate arrival of new configs. | |
| 1600 player_.OnDemuxerConfigsAvailable(CreateAudioDemuxerConfigs(kCodecVorbis)); | |
| 1601 | 1604 |
| 1602 PrerollDecoderToTime( | 1605 PrerollDecoderToTime( |
| 1603 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); | 1606 true, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); |
| 1604 } | 1607 } |
| 1605 | 1608 |
| 1606 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) { | 1609 TEST_F(MediaSourcePlayerTest, SimultaneousAudioVideoConfigChange) { |
| 1607 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1610 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1608 | 1611 |
| 1609 // Test that the player allows simultaneous audio and video config change, | 1612 // Test that the player allows simultaneous audio and video config change, |
| 1610 // such as might occur during OnPrefetchDone() if next access unit for both | 1613 // such as might occur during OnPrefetchDone() if next access unit for both |
| 1611 // audio and video jobs is |kConfigChanged|. | 1614 // audio and video jobs is |kConfigChanged|. |
| 1612 CreateNextTextureAndSetVideoSurface(); | 1615 CreateNextTextureAndSetVideoSurface(); |
| 1613 Start(CreateAudioVideoDemuxerConfigs(), true); | 1616 Start(CreateAudioVideoDemuxerConfigs(), true); |
| 1614 MediaDecoderJob* first_audio_job = GetMediaDecoderJob(true); | 1617 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); |
| 1615 MediaDecoderJob* first_video_job = GetMediaDecoderJob(false); | 1618 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
| 1619 EXPECT_TRUE(GetMediaCodecBridge(true)); | |
| 1620 EXPECT_TRUE(GetMediaCodecBridge(false)); | |
| 1621 WaitForAudioVideoDecodeDone(); | |
| 1616 | 1622 |
| 1617 // Simulate audio |kConfigChanged| prefetched as standalone access unit. | 1623 // Simulate audio |kConfigChanged| prefetched as standalone access unit. |
| 1624 DemuxerConfigs audio_configs = CreateAudioDemuxerConfigs(kCodecVorbis); | |
| 1625 audio_configs.audio_sampling_rate = 11025; | |
| 1618 player_.OnDemuxerDataAvailable( | 1626 player_.OnDemuxerDataAvailable( |
| 1619 CreateReadFromDemuxerAckWithConfigChanged(true, 0)); | 1627 CreateReadFromDemuxerAckWithConfigChanged(true, 0, audio_configs)); |
| 1620 EXPECT_EQ(0, demuxer_->num_config_requests()); // No OnPrefetchDone() yet. | |
| 1621 | 1628 |
| 1622 // Simulate video |kConfigChanged| prefetched as standalone access unit. | 1629 // Simulate video |kConfigChanged| prefetched as standalone access unit. |
| 1623 player_.OnDemuxerDataAvailable( | 1630 player_.OnDemuxerDataAvailable( |
| 1624 CreateReadFromDemuxerAckWithConfigChanged(false, 0)); | 1631 CreateReadFromDemuxerAckWithConfigChanged( |
| 1625 EXPECT_EQ(1, demuxer_->num_config_requests()); // OnPrefetchDone() occurred. | 1632 false, 0, CreateVideoDemuxerConfigs(kCodecVP9))); |
| 1626 EXPECT_EQ(2, demuxer_->num_data_requests()); // No more data requested yet. | 1633 EXPECT_EQ(6, demuxer_->num_data_requests()); |
| 1634 EXPECT_TRUE(IsDrainingDecoder(true)); | |
| 1635 EXPECT_TRUE(IsDrainingDecoder(false)); | |
| 1627 | 1636 |
| 1628 // No job re-creation should occur until the requested configs arrive. | 1637 // Waiting for decoder to finish draining. |
| 1629 EXPECT_EQ(first_audio_job, GetMediaDecoderJob(true)); | 1638 while(IsDrainingDecoder(true) || IsDrainingDecoder(false)) |
|
wolenetz
2014/04/25 23:13:13
lint nit: Missing space before ( in while(
qinmin
2014/04/26 01:30:11
Done.
| |
| 1630 EXPECT_EQ(first_video_job, GetMediaDecoderJob(false)); | 1639 message_loop_.RunUntilIdle(); |
| 1631 | |
| 1632 player_.OnDemuxerConfigsAvailable(CreateAudioVideoDemuxerConfigs()); | |
| 1633 EXPECT_EQ(4, demuxer_->num_data_requests()); | |
| 1634 MediaDecoderJob* second_audio_job = GetMediaDecoderJob(true); | |
| 1635 MediaDecoderJob* second_video_job = GetMediaDecoderJob(false); | |
| 1636 EXPECT_NE(first_audio_job, second_audio_job); | |
| 1637 EXPECT_NE(first_video_job, second_video_job); | |
| 1638 EXPECT_TRUE(second_audio_job && second_video_job); | |
| 1639 | |
| 1640 // Confirm no further demuxer configs requested. | |
| 1641 EXPECT_EQ(1, demuxer_->num_config_requests()); | |
| 1642 } | 1640 } |
| 1643 | 1641 |
| 1644 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) { | 1642 TEST_F(MediaSourcePlayerTest, DemuxerConfigRequestedIfInPrefetchUnit0) { |
| 1645 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1643 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1646 | 1644 |
| 1647 // Test that the player detects need for and requests demuxer configs if | 1645 // Test that the player detects need for and requests demuxer configs if |
| 1648 // the |kConfigChanged| unit is the very first unit in the set of units | 1646 // the |kConfigChanged| unit is the very first unit in the set of units |
| 1649 // received in OnDemuxerDataAvailable() ostensibly while | 1647 // received in OnDemuxerDataAvailable() ostensibly while |
| 1650 // |PREFETCH_DONE_EVENT_PENDING|. | 1648 // |PREFETCH_DONE_EVENT_PENDING|. |
| 1651 StartConfigChange(true, true, 0); | 1649 StartConfigChange(true, true, 0); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1684 TEST_F(MediaSourcePlayerTest, BrowserSeek_PrerollAfterBrowserSeek) { | 1682 TEST_F(MediaSourcePlayerTest, BrowserSeek_PrerollAfterBrowserSeek) { |
| 1685 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1683 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1686 | 1684 |
| 1687 // Test decoder job will preroll the media to the actual seek position | 1685 // Test decoder job will preroll the media to the actual seek position |
| 1688 // resulting from a browser seek. | 1686 // resulting from a browser seek. |
| 1689 BrowserSeekPlayer(false); | 1687 BrowserSeekPlayer(false); |
| 1690 | 1688 |
| 1691 // Simulate browser seek is done, but to a later time than was requested. | 1689 // Simulate browser seek is done, but to a later time than was requested. |
| 1692 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100); | 1690 EXPECT_LT(player_.GetCurrentTime().InMillisecondsF(), 100); |
| 1693 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100)); | 1691 player_.OnDemuxerSeekDone(base::TimeDelta::FromMilliseconds(100)); |
| 1694 EXPECT_TRUE(GetMediaDecoderJob(false)); | 1692 // Because next AU is not I-frame, MediaCodecBridge will not be recreated. |
| 1693 EXPECT_FALSE(GetMediaCodecBridge(false)); | |
| 1695 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); | 1694 EXPECT_EQ(100.0, player_.GetCurrentTime().InMillisecondsF()); |
| 1696 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1695 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1697 EXPECT_EQ(3, demuxer_->num_data_requests()); | 1696 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1698 | 1697 |
| 1699 PrerollDecoderToTime( | 1698 PrerollDecoderToTime( |
| 1700 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); | 1699 false, base::TimeDelta(), base::TimeDelta::FromMilliseconds(100)); |
| 1701 } | 1700 } |
| 1702 | 1701 |
| 1703 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) { | 1702 TEST_F(MediaSourcePlayerTest, VideoDemuxerConfigChange) { |
| 1704 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1703 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1705 | 1704 |
| 1706 // Test that video config change notification results in request for demuxer | 1705 // Test that video config change notification results in request for demuxer |
| 1707 // configuration, and that a video decoder job results without any browser | 1706 // configuration, and that a video decoder job results without any browser |
| 1708 // seek necessary once the new demuxer config arrives. | 1707 // seek necessary once the new demuxer config arrives. |
| 1709 StartConfigChange(false, true, 1); | 1708 StartConfigChange(false, true, 1); |
| 1710 MediaDecoderJob* first_job = GetMediaDecoderJob(false); | |
| 1711 EXPECT_TRUE(first_job); | |
| 1712 EXPECT_EQ(1, demuxer_->num_data_requests()); | |
| 1713 EXPECT_EQ(1, demuxer_->num_config_requests()); | |
| 1714 | |
| 1715 // Simulate arrival of new configs. | |
| 1716 player_.OnDemuxerConfigsAvailable(CreateVideoDemuxerConfigs()); | |
| 1717 | 1709 |
| 1718 // New video decoder job should have been created and configured, without any | 1710 // New video decoder job should have been created and configured, without any |
| 1719 // browser seek. | 1711 // browser seek. |
| 1720 MediaDecoderJob* second_job = GetMediaDecoderJob(false); | 1712 EXPECT_TRUE(GetMediaCodecBridge(false)); |
| 1721 EXPECT_TRUE(second_job); | 1713 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1722 EXPECT_NE(first_job, second_job); | |
| 1723 EXPECT_EQ(2, demuxer_->num_data_requests()); | |
| 1724 EXPECT_EQ(1, demuxer_->num_config_requests()); | |
| 1725 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 1714 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
| 1726 } | 1715 } |
| 1727 | 1716 |
| 1728 TEST_F(MediaSourcePlayerTest, VideoConfigChangeContinuesAcrossSeek) { | 1717 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedBySeek) { |
| 1729 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1718 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1730 | 1719 |
| 1731 // Test if a demuxer config request is pending (due to previously receiving | 1720 // Test if a decoder is being drained while receiving a seek request, draining |
| 1732 // |kConfigChanged|), and a seek request arrives prior to demuxer configs, | 1721 // is canceled. |
| 1733 // then seek is processed first, followed by the decoder config change. | 1722 SendConfigChangeToDecoder(true, false, 0); |
| 1734 // This assumes the demuxer sends |kConfigChanged| read response prior to | 1723 EXPECT_TRUE(IsDrainingDecoder(true)); |
| 1735 // canceling any reads pending seek; no |kAborted| is involved in this test. | |
| 1736 StartConfigChange(false, false, 1); | |
| 1737 MediaDecoderJob* first_job = GetMediaDecoderJob(false); | |
| 1738 EXPECT_TRUE(first_job); | |
| 1739 EXPECT_EQ(1, demuxer_->num_config_requests()); | |
| 1740 EXPECT_EQ(2, demuxer_->num_data_requests()); | |
| 1741 EXPECT_EQ(0, demuxer_->num_seek_requests()); | |
| 1742 | 1724 |
| 1743 player_.SeekTo(base::TimeDelta::FromMilliseconds(100)); | 1725 player_.SeekTo(base::TimeDelta::FromMilliseconds(100)); |
| 1726 WaitForAudioDecodeDone(); | |
| 1727 player_.OnDemuxerSeekDone(kNoTimestamp()); | |
| 1744 | 1728 |
| 1745 // Verify that the seek is requested immediately. | |
| 1746 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1729 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1730 EXPECT_EQ(4, demuxer_->num_data_requests()); | |
| 1731 EXPECT_FALSE(IsDrainingDecoder(true)); | |
| 1732 } | |
| 1747 | 1733 |
| 1748 // Simulate unlikely delayed arrival of the demuxer configs, completing the | 1734 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedByRelease) { |
| 1749 // config change. | 1735 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1750 // TODO(wolenetz): Is it even possible for requested demuxer configs to be | |
| 1751 // delayed until after a SeekTo request arrives? | |
| 1752 player_.OnDemuxerConfigsAvailable(CreateVideoDemuxerConfigs()); | |
| 1753 | 1736 |
| 1754 MediaDecoderJob* second_job = GetMediaDecoderJob(false); | 1737 // Test if a decoder is being drained while receiving a release request, |
| 1755 EXPECT_NE(first_job, second_job); | 1738 // draining is canceled. |
| 1756 EXPECT_TRUE(second_job); | 1739 SendConfigChangeToDecoder(true, false, 0); |
| 1740 EXPECT_TRUE(IsDrainingDecoder(true)); | |
| 1757 | 1741 |
| 1758 // Send back the seek done notification. This should finish the seek and | 1742 ReleasePlayer(); |
| 1759 // trigger the player to request more data. | 1743 WaitForAudioDecodeDone(); |
| 1760 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1744 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1761 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1745 EXPECT_FALSE(IsDrainingDecoder(true)); |
| 1746 | |
| 1747 EXPECT_FALSE(GetMediaCodecBridge(true)); | |
| 1748 EXPECT_FALSE(player_.IsPlaying()); | |
| 1749 | |
| 1750 player_.Start(); | |
| 1751 EXPECT_TRUE(player_.IsPlaying()); | |
| 1762 EXPECT_EQ(3, demuxer_->num_data_requests()); | 1752 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1763 } | 1753 } |
| 1764 | 1754 |
| 1765 TEST_F(MediaSourcePlayerTest, NewSurfaceWhileChangingConfigs) { | 1755 TEST_F(MediaSourcePlayerTest, DecoderDrainInterruptedBySurfaceChange) { |
| 1766 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1756 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1767 | 1757 |
| 1768 // Test that no seek or duplicated demuxer config request results from a | 1758 // Test if a video decoder is being drained while surface changes, draining |
| 1769 // SetVideoSurface() that occurs while the player is expecting new demuxer | 1759 // is canceled. |
| 1770 // configs. This test may be good to keep beyond browser seek hack. | 1760 SendConfigChangeToDecoder(false, false, 0); |
| 1771 StartConfigChange(false, false, 1); | 1761 EXPECT_TRUE(IsDrainingDecoder(false)); |
| 1772 MediaDecoderJob* first_job = GetMediaDecoderJob(false); | |
| 1773 EXPECT_TRUE(first_job); | |
| 1774 EXPECT_EQ(1, demuxer_->num_config_requests()); | |
| 1775 EXPECT_EQ(2, demuxer_->num_data_requests()); | |
| 1776 | 1762 |
| 1777 CreateNextTextureAndSetVideoSurface(); | 1763 CreateNextTextureAndSetVideoSurface(); |
| 1764 WaitForVideoDecodeDone(); | |
| 1778 | 1765 |
| 1779 // Surface change processing (including decoder job re-creation) should | 1766 EXPECT_FALSE(IsDrainingDecoder(false)); |
| 1780 // not occur until the pending video config change is completed. | 1767 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 1781 EXPECT_EQ(first_job, GetMediaDecoderJob(false)); | 1768 EXPECT_TRUE(player_.IsPlaying()); |
| 1769 EXPECT_EQ(3, demuxer_->num_data_requests()); | |
| 1782 | 1770 |
| 1783 player_.OnDemuxerConfigsAvailable(CreateVideoDemuxerConfigs()); | 1771 // Finish the browser seek introduced by surface change. |
| 1784 MediaDecoderJob* second_job = GetMediaDecoderJob(false); | 1772 player_.OnDemuxerSeekDone(base::TimeDelta()); |
| 1785 EXPECT_NE(first_job, second_job); | 1773 EXPECT_EQ(4, demuxer_->num_data_requests()); |
| 1786 EXPECT_TRUE(second_job); | |
| 1787 | |
| 1788 EXPECT_EQ(3, demuxer_->num_data_requests()); | |
| 1789 EXPECT_EQ(1, demuxer_->num_config_requests()); | |
| 1790 EXPECT_EQ(0, demuxer_->num_seek_requests()); | |
| 1791 } | 1774 } |
| 1792 | 1775 |
| 1793 TEST_F(MediaSourcePlayerTest, | 1776 TEST_F(MediaSourcePlayerTest, |
| 1794 BrowserSeek_DecoderStarvationWhilePendingSurfaceChange) { | 1777 BrowserSeek_DecoderStarvationWhilePendingSurfaceChange) { |
| 1795 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1778 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1796 | 1779 |
| 1797 // Test video decoder starvation while handling a pending surface change | 1780 // Test video decoder starvation while handling a pending surface change |
| 1798 // should not cause any crashes. | 1781 // should not cause any crashes. |
| 1799 CreateNextTextureAndSetVideoSurface(); | 1782 CreateNextTextureAndSetVideoSurface(); |
| 1800 StartVideoDecoderJob(true); | 1783 StartVideoDecoderJob(true); |
| 1801 DemuxerData data = CreateReadFromDemuxerAckForVideo(); | 1784 DemuxerData data = CreateReadFromDemuxerAckForVideo(); |
| 1802 player_.OnDemuxerDataAvailable(data); | 1785 player_.OnDemuxerDataAvailable(data); |
| 1803 | 1786 |
| 1804 // Trigger a surface change and decoder starvation. | 1787 // Trigger a surface change and decoder starvation. |
| 1805 CreateNextTextureAndSetVideoSurface(); | 1788 CreateNextTextureAndSetVideoSurface(); |
| 1806 TriggerPlayerStarvation(); | 1789 TriggerPlayerStarvation(); |
| 1807 WaitForVideoDecodeDone(); | 1790 WaitForVideoDecodeDone(); |
| 1808 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); | 1791 EXPECT_EQ(0, demuxer_->num_browser_seek_requests()); |
| 1809 | 1792 |
| 1810 // Surface change should trigger a seek. | 1793 // Surface change should trigger a seek. |
| 1811 player_.OnDemuxerDataAvailable(data); | 1794 player_.OnDemuxerDataAvailable(data); |
| 1812 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); | 1795 EXPECT_EQ(1, demuxer_->num_browser_seek_requests()); |
| 1813 player_.OnDemuxerSeekDone(base::TimeDelta()); | 1796 player_.OnDemuxerSeekDone(base::TimeDelta()); |
| 1814 EXPECT_TRUE(GetMediaDecoderJob(false)); | 1797 // After seek is done, prefetch is handled first. MediaCodecBridge is not |
| 1798 // created at this moment. | |
| 1799 EXPECT_FALSE(GetMediaCodecBridge(false)); | |
| 1815 | 1800 |
| 1816 // A new data request should be sent. | 1801 // A new data request should be sent. |
| 1817 EXPECT_EQ(3, demuxer_->num_data_requests()); | 1802 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1818 } | 1803 } |
| 1819 | 1804 |
| 1820 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) { | 1805 TEST_F(MediaSourcePlayerTest, ReleaseWithOnPrefetchDoneAlreadyPosted) { |
| 1821 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1806 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1822 | 1807 |
| 1823 // Test if OnPrefetchDone() had already been posted before and is executed | 1808 // Test if OnPrefetchDone() had already been posted before and is executed |
| 1824 // after Release(), then player does not DCHECK. This test is fragile to | 1809 // after Release(), then player does not DCHECK. This test is fragile to |
| 1825 // change to MediaDecoderJob::Prefetch() implementation; it assumes task | 1810 // change to MediaDecoderJob::Prefetch() implementation; it assumes task |
| 1826 // is posted to run |prefetch_cb| if the job already HasData(). | 1811 // is posted to run |prefetch_cb| if the job already HasData(). |
| 1827 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test | 1812 // TODO(wolenetz): Remove MSP::set_decode_callback_for_testing() if this test |
| 1828 // becomes obsolete. See http://crbug.com/304234. | 1813 // becomes obsolete. See http://crbug.com/304234. |
| 1829 StartAudioDecoderJob(true); | 1814 StartAudioDecoderJob(true); |
| 1830 | 1815 |
| 1831 // Escape the original prefetch by decoding a single access unit. | 1816 // Escape the original prefetch by decoding a single access unit. |
| 1832 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); | 1817 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); |
| 1833 WaitForAudioDecodeDone(); | 1818 WaitForAudioDecodeDone(); |
| 1834 | 1819 |
| 1835 // Prime the job with a few more access units, so that a later prefetch, | 1820 // Prime the job with a few more access units, so that a later prefetch, |
| 1836 // triggered by starvation to simulate decoder underrun, can trivially | 1821 // triggered by starvation to simulate decoder underrun, can trivially |
| 1837 // post task to run OnPrefetchDone(). | 1822 // post task to run OnPrefetchDone(). |
| 1838 player_.OnDemuxerDataAvailable( | 1823 player_.OnDemuxerDataAvailable( |
| 1839 CreateReadFromDemuxerAckWithConfigChanged(true, 4)); | 1824 CreateReadFromDemuxerAckWithConfigChanged( |
| 1825 true, 4, CreateAudioDemuxerConfigs(kCodecVorbis))); | |
| 1840 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 1826 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
| 1841 | 1827 |
| 1842 // Simulate decoder underrun, so trivial prefetch starts while still decoding. | 1828 // Simulate decoder underrun, so trivial prefetch starts while still decoding. |
| 1843 // The prefetch and posting of OnPrefetchDone() will not occur until next | 1829 // The prefetch and posting of OnPrefetchDone() will not occur until next |
| 1844 // MediaDecoderCallBack() occurs. | 1830 // MediaDecoderCallBack() occurs. |
| 1845 TriggerPlayerStarvation(); | 1831 TriggerPlayerStarvation(); |
| 1846 | 1832 |
| 1847 // Upon the next successful decode callback, post a task to call Release() on | 1833 // Upon the next successful decode callback, post a task to call Release() on |
| 1848 // the |player_|, such that the trivial OnPrefetchDone() task posting also | 1834 // the |player_|, such that the trivial OnPrefetchDone() task posting also |
| 1849 // occurs and should execute after the Release(). | 1835 // occurs and should execute after the Release(). |
| 1850 OnNextTestDecodeCallbackPostTaskToReleasePlayer(); | 1836 OnNextTestDecodeCallbackPostTaskToReleasePlayer(); |
| 1851 | 1837 |
| 1852 WaitForAudioDecodeDone(); | 1838 WaitForAudioDecodeDone(); |
| 1853 EXPECT_TRUE(decoder_callback_hook_executed_); | |
| 1854 EXPECT_EQ(2, demuxer_->num_data_requests()); | |
| 1855 | 1839 |
| 1856 // Player should have no decoder job until after Start(). | 1840 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1857 StartAudioDecoderJob(true); | 1841 |
| 1842 // Player should not request any new data since the access units haven't | |
| 1843 // been fully decoded yet. | |
| 1844 StartAudioDecoderJob(false); | |
| 1858 } | 1845 } |
| 1859 | 1846 |
| 1860 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) { | 1847 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekAndDone) { |
| 1861 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1848 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1862 | 1849 |
| 1863 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request | 1850 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request |
| 1864 // has not yet been sent, then the seek request is sent after Release(). Also, | 1851 // has not yet been sent, then the seek request is sent after Release(). Also, |
| 1865 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player | 1852 // test if OnDemuxerSeekDone() occurs prior to next Start(), then the player |
| 1866 // will resume correct post-seek preroll upon Start(). | 1853 // will resume correct post-seek preroll upon Start(). |
| 1867 StartAudioDecoderJobAndSeekToWhileDecoding( | 1854 StartAudioDecoderJobAndSeekToWhileDecoding( |
| 1868 base::TimeDelta::FromMilliseconds(100)); | 1855 base::TimeDelta::FromMilliseconds(100)); |
| 1869 ReleasePlayer(); | 1856 ReleasePlayer(); |
| 1857 EXPECT_EQ(0, demuxer_->num_seek_requests()); | |
| 1858 WaitForAudioDecodeDone(); | |
| 1870 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1859 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1871 | 1860 |
| 1872 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1861 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1873 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1862 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1874 EXPECT_FALSE(GetMediaDecoderJob(true)); | 1863 EXPECT_FALSE(GetMediaCodecBridge(true)); |
| 1875 EXPECT_FALSE(player_.IsPlaying()); | 1864 EXPECT_FALSE(player_.IsPlaying()); |
| 1876 | 1865 |
| 1877 // Player should begin prefetch and resume preroll upon Start(). | 1866 // Player should begin prefetch and resume preroll upon Start(). |
| 1878 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1867 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1879 StartAudioDecoderJob(true); | 1868 StartAudioDecoderJob(true); |
| 1880 EXPECT_TRUE(IsPrerolling(true)); | 1869 EXPECT_TRUE(IsPrerolling(true)); |
| 1881 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1870 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1882 | 1871 |
| 1883 // No further seek should have been requested since Release(), above. | 1872 // No further seek should have been requested since Release(), above. |
| 1884 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1873 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1885 } | 1874 } |
| 1886 | 1875 |
| 1887 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) { | 1876 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenDemuxerSeekThenStart) { |
| 1888 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1877 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1889 | 1878 |
| 1890 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request | 1879 // Test if Release() occurs after SeekTo(), but the DemuxerSeek IPC request |
| 1891 // has not yet been sent, then the seek request is sent after Release(). Also, | 1880 // has not yet been sent, then the seek request is sent after Release(). Also, |
| 1892 // test if OnDemuxerSeekDone() does not occur until after the next Start(), | 1881 // test if OnDemuxerSeekDone() does not occur until after the next Start(), |
| 1893 // then the player remains pending seek done until (and resumes correct | 1882 // then the player remains pending seek done until (and resumes correct |
| 1894 // post-seek preroll after) OnDemuxerSeekDone(). | 1883 // post-seek preroll after) OnDemuxerSeekDone(). |
| 1895 StartAudioDecoderJobAndSeekToWhileDecoding( | 1884 StartAudioDecoderJobAndSeekToWhileDecoding( |
| 1896 base::TimeDelta::FromMilliseconds(100)); | 1885 base::TimeDelta::FromMilliseconds(100)); |
| 1897 ReleasePlayer(); | 1886 ReleasePlayer(); |
| 1898 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1887 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
| 1899 | 1888 |
| 1900 // Player should not prefetch upon Start() nor create the decoder job, due to | 1889 // Player should not prefetch upon Start() nor create the decoder job, due to |
| 1901 // awaiting DemuxerSeekDone. | 1890 // awaiting DemuxerSeekDone. |
| 1902 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1891 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1903 StartAudioDecoderJob(false); | 1892 StartAudioDecoderJob(false); |
| 1904 | 1893 |
| 1894 WaitForAudioDecodeDone(); | |
| 1895 EXPECT_EQ(1, demuxer_->num_seek_requests()); | |
| 1905 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1896 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1906 EXPECT_TRUE(GetMediaDecoderJob(true)); | 1897 EXPECT_TRUE(GetMediaDecoderJob(true)); |
| 1907 EXPECT_TRUE(IsPrerolling(true)); | 1898 EXPECT_TRUE(IsPrerolling(true)); |
| 1908 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1899 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1909 EXPECT_EQ(3, demuxer_->num_data_requests()); | 1900 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1910 | 1901 |
| 1911 // No further seek should have been requested since Release(), above. | 1902 // No further seek should have been requested since Release(), above. |
| 1912 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1903 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1913 } | 1904 } |
| 1914 | 1905 |
| 1915 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) { | 1906 TEST_F(MediaSourcePlayerTest, SeekToThenDemuxerSeekThenReleaseThenSeekDone) { |
| 1916 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1907 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1917 | 1908 |
| 1918 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC | 1909 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeek IPC |
| 1919 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the | 1910 // request and OnDemuxerSeekDone() arrives prior to the next Start(), then the |
| 1920 // player will resume correct post-seek preroll upon Start(). | 1911 // player will resume correct post-seek preroll upon Start(). |
| 1921 StartAudioDecoderJobAndSeekToWhileDecoding( | 1912 StartAudioDecoderJobAndSeekToWhileDecoding( |
| 1922 base::TimeDelta::FromMilliseconds(100)); | 1913 base::TimeDelta::FromMilliseconds(100)); |
| 1923 WaitForAudioDecodeDone(); | 1914 WaitForAudioDecodeDone(); |
| 1924 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1915 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1925 | 1916 |
| 1926 ReleasePlayer(); | 1917 ReleasePlayer(); |
| 1927 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1918 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1928 EXPECT_FALSE(player_.IsPlaying()); | 1919 EXPECT_FALSE(player_.IsPlaying()); |
| 1929 EXPECT_FALSE(GetMediaDecoderJob(true)); | 1920 EXPECT_FALSE(GetMediaCodecBridge(true)); |
| 1930 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1921 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1931 | 1922 |
| 1932 // Player should begin prefetch and resume preroll upon Start(). | 1923 // Player should begin prefetch and resume preroll upon Start(). |
| 1933 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1924 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1934 StartAudioDecoderJob(true); | 1925 StartAudioDecoderJob(true); |
| 1935 EXPECT_TRUE(IsPrerolling(true)); | 1926 EXPECT_TRUE(IsPrerolling(true)); |
| 1936 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1927 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1937 | 1928 |
| 1938 // No further seek should have been requested since before Release(), above. | 1929 // No further seek should have been requested since before Release(), above. |
| 1939 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1930 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1940 } | 1931 } |
| 1941 | 1932 |
| 1942 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) { | 1933 TEST_F(MediaSourcePlayerTest, SeekToThenReleaseThenStart) { |
| 1943 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1934 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1944 | 1935 |
| 1945 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC | 1936 // Test if Release() occurs after a SeekTo()'s subsequent DemuxerSeeK IPC |
| 1946 // request and OnDemuxerSeekDone() does not occur until after the next | 1937 // request and OnDemuxerSeekDone() does not occur until after the next |
| 1947 // Start(), then the player remains pending seek done until (and resumes | 1938 // Start(), then the player remains pending seek done until (and resumes |
| 1948 // correct post-seek preroll after) OnDemuxerSeekDone(). | 1939 // correct post-seek preroll after) OnDemuxerSeekDone(). |
| 1949 StartAudioDecoderJobAndSeekToWhileDecoding( | 1940 StartAudioDecoderJobAndSeekToWhileDecoding( |
| 1950 base::TimeDelta::FromMilliseconds(100)); | 1941 base::TimeDelta::FromMilliseconds(100)); |
| 1951 WaitForAudioDecodeDone(); | 1942 WaitForAudioDecodeDone(); |
| 1952 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1943 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1953 | 1944 |
| 1954 ReleasePlayer(); | 1945 ReleasePlayer(); |
| 1955 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1946 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 1956 StartAudioDecoderJob(false); | 1947 StartAudioDecoderJob(false); |
| 1957 | 1948 |
| 1958 player_.OnDemuxerSeekDone(kNoTimestamp()); | 1949 player_.OnDemuxerSeekDone(kNoTimestamp()); |
| 1959 EXPECT_TRUE(GetMediaDecoderJob(true)); | 1950 EXPECT_FALSE(GetMediaCodecBridge(true)); |
| 1960 EXPECT_TRUE(IsPrerolling(true)); | 1951 EXPECT_TRUE(IsPrerolling(true)); |
| 1961 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); | 1952 EXPECT_EQ(100.0, GetPrerollTimestamp().InMillisecondsF()); |
| 1962 EXPECT_EQ(3, demuxer_->num_data_requests()); | 1953 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1963 | 1954 |
| 1964 // No further seek should have been requested since before Release(), above. | 1955 // No further seek should have been requested since before Release(), above. |
| 1965 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 1956 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 1966 } | 1957 } |
| 1967 | 1958 |
| 1968 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenConfigsAvailable) { | 1959 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenConfigsAvailable) { |
| 1969 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1960 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1970 | 1961 |
| 1971 // Test if Release() occurs after |kConfigChanged| detected, new configs | 1962 // Test if Release() occurs after |kConfigChanged| is processed, new data |
| 1972 // requested of demuxer, and the requested configs arrive before the next | 1963 // requested of demuxer, and the requested data arrive before the next |
| 1973 // Start(), then the player completes the pending config change processing on | 1964 // Start(), then the player starts to decode the new data without any browser |
| 1974 // their receipt. | 1965 // seek. |
| 1975 StartConfigChange(true, true, 0); | 1966 StartConfigChange(true, true, 0); |
| 1976 ReleasePlayer(); | 1967 ReleasePlayer(); |
| 1977 | 1968 |
| 1978 player_.OnDemuxerConfigsAvailable(CreateAudioDemuxerConfigs(kCodecVorbis)); | 1969 EXPECT_TRUE(GetMediaCodecBridge(true)); |
| 1979 EXPECT_FALSE(GetMediaDecoderJob(true)); | |
| 1980 EXPECT_FALSE(player_.IsPlaying()); | 1970 EXPECT_FALSE(player_.IsPlaying()); |
| 1981 EXPECT_EQ(1, demuxer_->num_data_requests()); | 1971 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1972 player_.OnDemuxerDataAvailable( | |
| 1973 CreateReadFromDemuxerAckWithConfigChanged( | |
| 1974 true, 4, CreateAudioDemuxerConfigs(kCodecVorbis))); | |
| 1975 WaitForAudioDecodeDone(); | |
| 1976 EXPECT_FALSE(GetMediaCodecBridge(true)); | |
| 1982 | 1977 |
| 1983 // Player should resume upon Start(), even without further configs supplied. | 1978 // Player should resume upon Start(), even without further configs supplied. |
| 1984 player_.Start(); | 1979 player_.Start(); |
| 1985 EXPECT_TRUE(GetMediaDecoderJob(true)); | |
| 1986 EXPECT_TRUE(player_.IsPlaying()); | 1980 EXPECT_TRUE(player_.IsPlaying()); |
| 1987 EXPECT_EQ(2, demuxer_->num_data_requests()); | 1981 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 1988 | 1982 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
| 1989 // No further config request should have occurred since StartConfigChange(). | |
| 1990 EXPECT_EQ(1, demuxer_->num_config_requests()); | |
| 1991 } | 1983 } |
| 1992 | 1984 |
| 1993 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenStart) { | 1985 TEST_F(MediaSourcePlayerTest, ConfigChangedThenReleaseThenStart) { |
| 1994 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 1986 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 1995 | 1987 |
| 1996 // Test if Release() occurs after |kConfigChanged| detected, new configs | 1988 // Test if Release() occurs after |kConfigChanged| detected, new configs |
| 1997 // requested of demuxer, and the requested configs arrive after the next | 1989 // requested of demuxer, and the requested configs arrive after the next |
| 1998 // Start(), then the player pends job creation until the new configs arrive. | 1990 // Start(), then the player pends job creation until the new configs arrive. |
| 1999 StartConfigChange(true, true, 0); | 1991 StartConfigChange(true, true, 0); |
| 2000 ReleasePlayer(); | 1992 ReleasePlayer(); |
| 2001 | 1993 |
| 2002 player_.Start(); | 1994 player_.Start(); |
| 2003 EXPECT_TRUE(player_.IsPlaying()); | 1995 EXPECT_TRUE(player_.IsPlaying()); |
| 2004 EXPECT_FALSE(GetMediaDecoderJob(true)); | 1996 // The previous MediaCodecBridge still haven't finished decoding the data |
| 2005 EXPECT_EQ(1, demuxer_->num_data_requests()); | 1997 // yet. |
| 1998 EXPECT_TRUE(GetMediaCodecBridge(true)); | |
| 1999 EXPECT_EQ(3, demuxer_->num_data_requests()); | |
| 2006 | 2000 |
| 2007 player_.OnDemuxerConfigsAvailable(CreateAudioDemuxerConfigs(kCodecVorbis)); | 2001 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); |
| 2008 EXPECT_TRUE(GetMediaDecoderJob(true)); | 2002 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 2009 EXPECT_EQ(2, demuxer_->num_data_requests()); | 2003 WaitForAudioDecodeDone(); |
| 2010 | 2004 EXPECT_FALSE(GetMediaCodecBridge(true)); |
| 2011 // No further config request should have occurred since StartConfigChange(). | |
| 2012 EXPECT_EQ(1, demuxer_->num_config_requests()); | |
| 2013 } | 2005 } |
| 2014 | 2006 |
| 2015 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenDemuxerSeekDone) { | 2007 TEST_F(MediaSourcePlayerTest, BrowserSeek_ThenReleaseThenDemuxerSeekDone) { |
| 2016 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 2008 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 2017 | 2009 |
| 2018 // Test that Release() after a browser seek's DemuxerSeek IPC request has been | 2010 // Test that Release() after a browser seek's DemuxerSeek IPC request has been |
| 2019 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() occurs | 2011 // sent behaves similar to a regular seek: if OnDemuxerSeekDone() occurs |
| 2020 // before the next Start()+SetVideoSurface(), then the player will resume | 2012 // before the next Start()+SetVideoSurface(), then the player will resume |
| 2021 // correct post-seek preroll upon Start()+SetVideoSurface(). | 2013 // correct post-seek preroll upon Start()+SetVideoSurface(). |
| 2022 BrowserSeekPlayer(false); | 2014 BrowserSeekPlayer(false); |
| 2023 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); | 2015 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); |
| 2024 ReleasePlayer(); | 2016 ReleasePlayer(); |
| 2025 | 2017 |
| 2026 player_.OnDemuxerSeekDone(expected_preroll_timestamp); | 2018 player_.OnDemuxerSeekDone(expected_preroll_timestamp); |
| 2027 EXPECT_FALSE(player_.IsPlaying()); | 2019 EXPECT_FALSE(player_.IsPlaying()); |
| 2028 EXPECT_FALSE(GetMediaDecoderJob(false)); | 2020 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 2029 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); | 2021 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); |
| 2030 | 2022 |
| 2031 // Player should begin prefetch and resume preroll upon Start(). | 2023 // Player should begin prefetch and resume preroll upon Start(). |
| 2032 EXPECT_EQ(2, demuxer_->num_data_requests()); | 2024 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 2033 CreateNextTextureAndSetVideoSurface(); | 2025 CreateNextTextureAndSetVideoSurface(); |
| 2034 StartVideoDecoderJob(true); | 2026 StartVideoDecoderJob(true); |
| 2035 EXPECT_TRUE(IsPrerolling(false)); | 2027 EXPECT_TRUE(IsPrerolling(false)); |
| 2036 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); | 2028 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); |
| 2037 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); | 2029 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); |
| 2038 | 2030 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2050 // after) OnDemuxerSeekDone(). | 2042 // after) OnDemuxerSeekDone(). |
| 2051 BrowserSeekPlayer(false); | 2043 BrowserSeekPlayer(false); |
| 2052 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); | 2044 base::TimeDelta expected_preroll_timestamp = player_.GetCurrentTime(); |
| 2053 ReleasePlayer(); | 2045 ReleasePlayer(); |
| 2054 | 2046 |
| 2055 EXPECT_EQ(2, demuxer_->num_data_requests()); | 2047 EXPECT_EQ(2, demuxer_->num_data_requests()); |
| 2056 CreateNextTextureAndSetVideoSurface(); | 2048 CreateNextTextureAndSetVideoSurface(); |
| 2057 StartVideoDecoderJob(false); | 2049 StartVideoDecoderJob(false); |
| 2058 | 2050 |
| 2059 player_.OnDemuxerSeekDone(expected_preroll_timestamp); | 2051 player_.OnDemuxerSeekDone(expected_preroll_timestamp); |
| 2060 EXPECT_TRUE(GetMediaDecoderJob(false)); | 2052 // Prefetch takes place first, and the decoder is not created yet. |
| 2053 EXPECT_FALSE(GetMediaCodecBridge(false)); | |
| 2061 EXPECT_TRUE(IsPrerolling(false)); | 2054 EXPECT_TRUE(IsPrerolling(false)); |
| 2062 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); | 2055 EXPECT_EQ(expected_preroll_timestamp, GetPrerollTimestamp()); |
| 2063 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); | 2056 EXPECT_EQ(expected_preroll_timestamp, player_.GetCurrentTime()); |
| 2064 EXPECT_EQ(3, demuxer_->num_data_requests()); | 2057 EXPECT_EQ(3, demuxer_->num_data_requests()); |
| 2065 | 2058 |
| 2066 // No further seek should have been requested since BrowserSeekPlayer(). | 2059 // No further seek should have been requested since BrowserSeekPlayer(). |
| 2067 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 2060 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
| 2061 | |
| 2062 // Decoder will be created once data is received. | |
| 2063 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | |
| 2064 while (!GetMediaCodecBridge(false)) | |
| 2065 message_loop_.RunUntilIdle(); | |
| 2068 } | 2066 } |
| 2069 | 2067 |
| 2070 // TODO(xhwang): Once we add tests to cover DrmBridge, update this test to | 2068 // TODO(xhwang): Once we add tests to cover DrmBridge, update this test to |
| 2071 // also verify that the job is successfully created if SetDrmBridge(), Start() | 2069 // also verify that the job is successfully created if SetDrmBridge(), Start() |
| 2072 // and eventually OnMediaCrypto() occur. This would increase test coverage of | 2070 // and eventually OnMediaCrypto() occur. This would increase test coverage of |
| 2073 // http://crbug.com/313470 and allow us to remove inspection of internal player | 2071 // http://crbug.com/313470 and allow us to remove inspection of internal player |
| 2074 // pending event state. See http://crbug.com/313860. | 2072 // pending event state. See http://crbug.com/313860. |
| 2075 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) { | 2073 TEST_F(MediaSourcePlayerTest, SurfaceChangeClearedEvenIfMediaCryptoAbsent) { |
| 2076 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 2074 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 2077 | 2075 |
| 2078 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after | 2076 // Test that |SURFACE_CHANGE_EVENT_PENDING| is not pending after |
| 2079 // SetVideoSurface() for a player configured for encrypted video, when the | 2077 // SetVideoSurface() for a player configured for encrypted video, when the |
| 2080 // player has not yet received media crypto. | 2078 // player has not yet received media crypto. |
| 2081 DemuxerConfigs configs = CreateVideoDemuxerConfigs(); | 2079 DemuxerConfigs configs = CreateVideoDemuxerConfigs(kCodecVP8); |
| 2082 configs.is_video_encrypted = true; | 2080 configs.is_video_encrypted = true; |
| 2083 | 2081 |
| 2084 player_.OnDemuxerConfigsAvailable(configs); | 2082 player_.OnDemuxerConfigsAvailable(configs); |
| 2085 CreateNextTextureAndSetVideoSurface(); | 2083 CreateNextTextureAndSetVideoSurface(); |
| 2086 EXPECT_FALSE(IsPendingSurfaceChange()); | 2084 EXPECT_FALSE(GetMediaCodecBridge(false)); |
| 2087 EXPECT_FALSE(GetMediaDecoderJob(false)); | |
| 2088 } | 2085 } |
| 2089 | 2086 |
| 2090 TEST_F(MediaSourcePlayerTest, CurrentTimeUpdatedWhileDecoderStarved) { | 2087 TEST_F(MediaSourcePlayerTest, CurrentTimeUpdatedWhileDecoderStarved) { |
| 2091 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 2088 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 2092 | 2089 |
| 2093 // Test that current time is updated while decoder is starved. | 2090 // Test that current time is updated while decoder is starved. |
| 2094 StartAudioDecoderJob(true); | 2091 StartAudioDecoderJob(true); |
| 2095 DecodeAudioDataUntilOutputBecomesAvailable(); | 2092 DecodeAudioDataUntilOutputBecomesAvailable(); |
| 2096 | 2093 |
| 2097 // Trigger starvation while the decoder is decoding. | 2094 // Trigger starvation while the decoder is decoding. |
| 2098 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); | 2095 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); |
| 2099 manager_.ResetTimestampUpdated(); | 2096 manager_.ResetTimestampUpdated(); |
| 2100 TriggerPlayerStarvation(); | 2097 TriggerPlayerStarvation(); |
| 2101 WaitForAudioDecodeDone(); | 2098 WaitForAudioDecodeDone(); |
| 2102 | 2099 |
| 2103 // Current time should be updated. | 2100 // Current time should be updated. |
| 2104 EXPECT_TRUE(manager_.timestamp_updated()); | 2101 EXPECT_TRUE(manager_.timestamp_updated()); |
| 2105 } | 2102 } |
| 2106 | 2103 |
| 2107 TEST_F(MediaSourcePlayerTest, CurrentTimeKeepsIncreasingAfterConfigChange) { | 2104 TEST_F(MediaSourcePlayerTest, CurrentTimeKeepsIncreasingAfterConfigChange) { |
| 2108 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); | 2105 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE(); |
| 2109 | 2106 |
| 2110 // Test current time keep on increasing after audio config change. | 2107 // Test current time keep on increasing after audio config change. |
| 2111 // Test that current time is updated while decoder is starved. | 2108 // Test that current time is updated while decoder is starved. |
| 2112 StartAudioDecoderJob(true); | 2109 StartAudioDecoderJob(true); |
| 2113 | 2110 |
| 2114 DecodeAudioDataUntilOutputBecomesAvailable(); | 2111 DecodeAudioDataUntilOutputBecomesAvailable(); |
| 2115 | 2112 |
| 2116 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged(true, 0); | 2113 DemuxerConfigs configs = CreateAudioDemuxerConfigs(kCodecVorbis); |
| 2114 configs.audio_sampling_rate = 11025; | |
| 2115 DemuxerData data = CreateReadFromDemuxerAckWithConfigChanged( | |
| 2116 true, 0, configs); | |
| 2117 player_.OnDemuxerDataAvailable(data); | 2117 player_.OnDemuxerDataAvailable(data); |
| 2118 WaitForAudioDecodeDone(); | 2118 WaitForAudioDecodeDone(); |
| 2119 | |
| 2120 // Simulate arrival of new configs. | |
| 2121 player_.OnDemuxerConfigsAvailable(CreateAudioDemuxerConfigs(kCodecVorbis)); | |
| 2122 DecodeAudioDataUntilOutputBecomesAvailable(); | 2119 DecodeAudioDataUntilOutputBecomesAvailable(); |
| 2123 } | 2120 } |
| 2124 | 2121 |
| 2125 } // namespace media | 2122 } // namespace media |
| OLD | NEW |