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