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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "media/base/android/media_codec_bridge.h" | 10 #include "media/base/android/media_codec_bridge.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 return; | 235 return; |
236 } | 236 } |
237 | 237 |
238 // Test audio decoder job will be created when codec is successfully started. | 238 // Test audio decoder job will be created when codec is successfully started. |
239 StartAudioDecoderJob(); | 239 StartAudioDecoderJob(); |
240 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); | 240 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); |
241 EXPECT_EQ(1, demuxer_->num_data_requests()); | 241 EXPECT_EQ(1, demuxer_->num_data_requests()); |
242 } | 242 } |
243 | 243 |
244 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { | 244 TEST_F(MediaSourcePlayerTest, StartAudioDecoderWithInvalidConfig) { |
245 if (!MediaCodecBridge::IsAvailable()) { | |
246 LOG(INFO) << "Could not run test - not supported on device."; | |
247 return; | |
248 } | |
249 | |
250 // Test audio decoder job will not be created when failed to start the codec. | 245 // Test audio decoder job will not be created when failed to start the codec. |
251 DemuxerConfigs configs; | 246 DemuxerConfigs configs; |
252 configs.audio_codec = kCodecVorbis; | 247 configs.audio_codec = kCodecVorbis; |
253 configs.audio_channels = 2; | 248 configs.audio_channels = 2; |
254 configs.audio_sampling_rate = 44100; | 249 configs.audio_sampling_rate = 44100; |
255 configs.is_audio_encrypted = false; | 250 configs.is_audio_encrypted = false; |
256 configs.duration_ms = kDefaultDurationInMs; | 251 configs.duration_ms = kDefaultDurationInMs; |
257 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; | 252 uint8 invalid_codec_data[] = { 0x00, 0xff, 0xff, 0xff, 0xff }; |
258 configs.audio_extra_data.insert(configs.audio_extra_data.begin(), | 253 configs.audio_extra_data.insert(configs.audio_extra_data.begin(), |
259 invalid_codec_data, invalid_codec_data + 4); | 254 invalid_codec_data, invalid_codec_data + 4); |
260 Start(configs); | 255 Start(configs); |
261 EXPECT_EQ(NULL, GetMediaDecoderJob(true)); | 256 EXPECT_EQ(NULL, GetMediaDecoderJob(true)); |
262 EXPECT_EQ(0, demuxer_->num_data_requests()); | 257 EXPECT_EQ(0, demuxer_->num_data_requests()); |
263 } | 258 } |
264 | 259 |
265 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { | 260 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithValidSurface) { |
266 if (!MediaCodecBridge::IsAvailable()) { | |
267 LOG(INFO) << "Could not run test - not supported on device."; | |
268 return; | |
269 } | |
270 | |
271 // Test video decoder job will be created when surface is valid. | 261 // Test video decoder job will be created when surface is valid. |
272 StartVideoDecoderJob(); | 262 StartVideoDecoderJob(); |
273 // Video decoder job will not be created until surface is available. | 263 // Video decoder job will not be created until surface is available. |
274 EXPECT_EQ(NULL, GetMediaDecoderJob(false)); | 264 EXPECT_EQ(NULL, GetMediaDecoderJob(false)); |
275 EXPECT_EQ(0, demuxer_->num_data_requests()); | 265 EXPECT_EQ(0, demuxer_->num_data_requests()); |
276 | 266 |
277 CreateAndSetVideoSurface(); | 267 CreateAndSetVideoSurface(); |
278 | 268 |
279 // Player should not seek the demuxer on setting initial surface. | 269 // Player should not seek the demuxer on setting initial surface. |
280 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 270 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
281 | 271 |
282 // The decoder job should be ready now. | 272 // The decoder job should be ready now. |
283 EXPECT_TRUE(NULL != GetMediaDecoderJob(false)); | 273 EXPECT_TRUE(NULL != GetMediaDecoderJob(false)); |
284 EXPECT_EQ(1, demuxer_->num_data_requests()); | 274 EXPECT_EQ(1, demuxer_->num_data_requests()); |
285 } | 275 } |
286 | 276 |
287 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { | 277 TEST_F(MediaSourcePlayerTest, StartVideoCodecWithInvalidSurface) { |
288 if (!MediaCodecBridge::IsAvailable()) { | |
289 LOG(INFO) << "Could not run test - not supported on device."; | |
290 return; | |
291 } | |
292 | |
293 // Test video decoder job will be created when surface is valid. | 278 // Test video decoder job will be created when surface is valid. |
294 scoped_refptr<gfx::SurfaceTexture> surface_texture( | 279 scoped_refptr<gfx::SurfaceTexture> surface_texture( |
295 new gfx::SurfaceTexture(0)); | 280 new gfx::SurfaceTexture(0)); |
296 gfx::ScopedJavaSurface surface(surface_texture.get()); | 281 gfx::ScopedJavaSurface surface(surface_texture.get()); |
297 StartVideoDecoderJob(); | 282 StartVideoDecoderJob(); |
298 // Video decoder job will not be created until surface is available. | 283 // Video decoder job will not be created until surface is available. |
299 EXPECT_EQ(NULL, GetMediaDecoderJob(false)); | 284 EXPECT_EQ(NULL, GetMediaDecoderJob(false)); |
300 EXPECT_EQ(0, demuxer_->num_data_requests()); | 285 EXPECT_EQ(0, demuxer_->num_data_requests()); |
301 | 286 |
302 // Release the surface texture. | 287 // Release the surface texture. |
303 surface_texture = NULL; | 288 surface_texture = NULL; |
304 player_.SetVideoSurface(surface.Pass()); | 289 player_.SetVideoSurface(surface.Pass()); |
305 | 290 |
306 // Player should not seek the demuxer on setting initial surface. | 291 // Player should not seek the demuxer on setting initial surface. |
307 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 292 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
308 | 293 |
309 EXPECT_EQ(NULL, GetMediaDecoderJob(false)); | 294 EXPECT_EQ(NULL, GetMediaDecoderJob(false)); |
310 EXPECT_EQ(0, demuxer_->num_data_requests()); | 295 EXPECT_EQ(0, demuxer_->num_data_requests()); |
311 } | 296 } |
312 | 297 |
313 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) { | 298 TEST_F(MediaSourcePlayerTest, ReadFromDemuxerAfterSeek) { |
314 if (!MediaCodecBridge::IsAvailable()) { | |
315 LOG(INFO) << "Could not run test - not supported on device."; | |
316 return; | |
317 } | |
318 | |
319 // Test decoder job will resend a ReadFromDemuxer request after seek. | 299 // Test decoder job will resend a ReadFromDemuxer request after seek. |
320 StartAudioDecoderJob(); | 300 StartAudioDecoderJob(); |
321 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); | 301 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); |
322 EXPECT_EQ(1, demuxer_->num_data_requests()); | 302 EXPECT_EQ(1, demuxer_->num_data_requests()); |
323 | 303 |
324 // Initiate a seek. Skip the round-trip of requesting seek from renderer. | 304 // Initiate a seek. Skip the round-trip of requesting seek from renderer. |
325 // Instead behave as if the renderer has asked us to seek. | 305 // Instead behave as if the renderer has asked us to seek. |
326 player_.SeekTo(base::TimeDelta()); | 306 player_.SeekTo(base::TimeDelta()); |
327 | 307 |
328 // Verify that the seek does not occur until the initial prefetch | 308 // Verify that the seek does not occur until the initial prefetch |
(...skipping 15 matching lines...) Expand all Loading... |
344 // Sending back the seek done notification. This should trigger the player to | 324 // Sending back the seek done notification. This should trigger the player to |
345 // call OnReadFromDemuxer() again. | 325 // call OnReadFromDemuxer() again. |
346 player_.OnDemuxerSeekDone(); | 326 player_.OnDemuxerSeekDone(); |
347 EXPECT_EQ(2, demuxer_->num_data_requests()); | 327 EXPECT_EQ(2, demuxer_->num_data_requests()); |
348 | 328 |
349 // Reconfirm exactly 1 seek request has been made of demuxer. | 329 // Reconfirm exactly 1 seek request has been made of demuxer. |
350 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 330 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
351 } | 331 } |
352 | 332 |
353 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { | 333 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { |
354 if (!MediaCodecBridge::IsAvailable()) { | |
355 LOG(INFO) << "Could not run test - not supported on device."; | |
356 return; | |
357 } | |
358 | |
359 // Test SetVideoSurface() will not cause an extra seek while the player is | 334 // Test SetVideoSurface() will not cause an extra seek while the player is |
360 // waiting for demuxer to indicate seek is done. | 335 // waiting for demuxer to indicate seek is done. |
361 StartVideoDecoderJob(); | 336 StartVideoDecoderJob(); |
362 // Player is still waiting for SetVideoSurface(), so no request is sent. | 337 // Player is still waiting for SetVideoSurface(), so no request is sent. |
363 EXPECT_EQ(0, demuxer_->num_data_requests()); | 338 EXPECT_EQ(0, demuxer_->num_data_requests()); |
364 | 339 |
365 // Initiate a seek. Skip the round-trip of requesting seek from renderer. | 340 // Initiate a seek. Skip the round-trip of requesting seek from renderer. |
366 // Instead behave as if the renderer has asked us to seek. | 341 // Instead behave as if the renderer has asked us to seek. |
367 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 342 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
368 player_.SeekTo(base::TimeDelta()); | 343 player_.SeekTo(base::TimeDelta()); |
369 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 344 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
370 | 345 |
371 CreateAndSetVideoSurface(); | 346 CreateAndSetVideoSurface(); |
372 EXPECT_TRUE(NULL == GetMediaDecoderJob(false)); | 347 EXPECT_TRUE(NULL == GetMediaDecoderJob(false)); |
373 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 348 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
374 | 349 |
375 // Reconfirm player has not yet requested data. | 350 // Reconfirm player has not yet requested data. |
376 EXPECT_EQ(0, demuxer_->num_data_requests()); | 351 EXPECT_EQ(0, demuxer_->num_data_requests()); |
377 | 352 |
378 // Send the seek done notification. The player should start requesting data. | 353 // Send the seek done notification. The player should start requesting data. |
379 player_.OnDemuxerSeekDone(); | 354 player_.OnDemuxerSeekDone(); |
380 EXPECT_TRUE(NULL != GetMediaDecoderJob(false)); | 355 EXPECT_TRUE(NULL != GetMediaDecoderJob(false)); |
381 EXPECT_EQ(1, demuxer_->num_data_requests()); | 356 EXPECT_EQ(1, demuxer_->num_data_requests()); |
382 | 357 |
383 // Reconfirm exactly 1 seek request has been made of demuxer. | 358 // Reconfirm exactly 1 seek request has been made of demuxer. |
384 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 359 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
385 } | 360 } |
386 | 361 |
387 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) { | 362 TEST_F(MediaSourcePlayerTest, ChangeMultipleSurfaceWhileDecoding) { |
388 if (!MediaCodecBridge::IsAvailable()) { | |
389 LOG(INFO) << "Could not run test - not supported on device."; | |
390 return; | |
391 } | |
392 | |
393 // Test MediaSourcePlayer can switch multiple surfaces during decoding. | 363 // Test MediaSourcePlayer can switch multiple surfaces during decoding. |
394 CreateAndSetVideoSurface(); | 364 CreateAndSetVideoSurface(); |
395 StartVideoDecoderJob(); | 365 StartVideoDecoderJob(); |
396 EXPECT_EQ(1, demuxer_->num_data_requests()); | 366 EXPECT_EQ(1, demuxer_->num_data_requests()); |
397 | 367 |
398 // Send the first input chunk. | 368 // Send the first input chunk. |
399 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 369 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
400 | 370 |
401 // While the decoder is decoding, change multiple surfaces. Pass an empty | 371 // While the decoder is decoding, change multiple surfaces. Pass an empty |
402 // surface first. | 372 // surface first. |
403 gfx::ScopedJavaSurface empty_surface; | 373 gfx::ScopedJavaSurface empty_surface; |
404 player_.SetVideoSurface(empty_surface.Pass()); | 374 player_.SetVideoSurface(empty_surface.Pass()); |
405 // Pass a new non-empty surface. | 375 // Pass a new non-empty surface. |
406 CreateAndSetVideoSurface(); | 376 CreateAndSetVideoSurface(); |
407 | 377 |
408 // Wait for the decoder job to finish decoding. | 378 // Wait for the decoder job to finish decoding. |
409 while(GetMediaDecoderJob(false)->is_decoding()) | 379 while(GetMediaDecoderJob(false)->is_decoding()) |
410 message_loop_.RunUntilIdle(); | 380 message_loop_.RunUntilIdle(); |
411 // A seek should be initiated to request Iframe. | 381 // A seek should be initiated to request Iframe. |
412 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 382 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
413 EXPECT_EQ(1, demuxer_->num_data_requests()); | 383 EXPECT_EQ(1, demuxer_->num_data_requests()); |
414 } | 384 } |
415 | 385 |
416 TEST_F(MediaSourcePlayerTest, StartAfterSeekFinish) { | 386 TEST_F(MediaSourcePlayerTest, StartAfterSeekFinish) { |
417 if (!MediaCodecBridge::IsAvailable()) { | |
418 LOG(INFO) << "Could not run test - not supported on device."; | |
419 return; | |
420 } | |
421 | |
422 // Test decoder job will not start until all pending seek event is handled. | 387 // Test decoder job will not start until all pending seek event is handled. |
423 DemuxerConfigs configs; | 388 DemuxerConfigs configs; |
424 configs.audio_codec = kCodecVorbis; | 389 configs.audio_codec = kCodecVorbis; |
425 configs.audio_channels = 2; | 390 configs.audio_channels = 2; |
426 configs.audio_sampling_rate = 44100; | 391 configs.audio_sampling_rate = 44100; |
427 configs.is_audio_encrypted = false; | 392 configs.is_audio_encrypted = false; |
428 configs.duration_ms = kDefaultDurationInMs; | 393 configs.duration_ms = kDefaultDurationInMs; |
429 player_.OnDemuxerConfigsAvailable(configs); | 394 player_.OnDemuxerConfigsAvailable(configs); |
430 EXPECT_EQ(NULL, GetMediaDecoderJob(true)); | 395 EXPECT_EQ(NULL, GetMediaDecoderJob(true)); |
431 EXPECT_EQ(0, demuxer_->num_data_requests()); | 396 EXPECT_EQ(0, demuxer_->num_data_requests()); |
(...skipping 10 matching lines...) Expand all Loading... |
442 // Sending back the seek done notification. | 407 // Sending back the seek done notification. |
443 player_.OnDemuxerSeekDone(); | 408 player_.OnDemuxerSeekDone(); |
444 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); | 409 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); |
445 EXPECT_EQ(1, demuxer_->num_data_requests()); | 410 EXPECT_EQ(1, demuxer_->num_data_requests()); |
446 | 411 |
447 // Reconfirm exactly 1 seek request has been made of demuxer. | 412 // Reconfirm exactly 1 seek request has been made of demuxer. |
448 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 413 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
449 } | 414 } |
450 | 415 |
451 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) { | 416 TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) { |
452 if (!MediaCodecBridge::IsAvailable()) { | |
453 LOG(INFO) << "Could not run test - not supported on device."; | |
454 return; | |
455 } | |
456 | |
457 // Test that if the decoding job is not fully stopped after Pause(), | 417 // Test that if the decoding job is not fully stopped after Pause(), |
458 // calling Start() will be a noop. | 418 // calling Start() will be a noop. |
459 StartAudioDecoderJob(); | 419 StartAudioDecoderJob(); |
460 | 420 |
461 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); | 421 MediaDecoderJob* decoder_job = GetMediaDecoderJob(true); |
462 EXPECT_TRUE(NULL != decoder_job); | 422 EXPECT_TRUE(NULL != decoder_job); |
463 EXPECT_EQ(1, demuxer_->num_data_requests()); | 423 EXPECT_EQ(1, demuxer_->num_data_requests()); |
464 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); | 424 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); |
465 | 425 |
466 // Sending data to player. | 426 // Sending data to player. |
(...skipping 11 matching lines...) Expand all Loading... |
478 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); | 438 EXPECT_EQ(decoder_job, GetMediaDecoderJob(true)); |
479 EXPECT_EQ(1, demuxer_->num_data_requests()); | 439 EXPECT_EQ(1, demuxer_->num_data_requests()); |
480 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 440 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
481 message_loop_.Run(); | 441 message_loop_.Run(); |
482 // The decoder job should finish and a new request will be sent. | 442 // The decoder job should finish and a new request will be sent. |
483 EXPECT_EQ(2, demuxer_->num_data_requests()); | 443 EXPECT_EQ(2, demuxer_->num_data_requests()); |
484 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); | 444 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); |
485 } | 445 } |
486 | 446 |
487 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { | 447 TEST_F(MediaSourcePlayerTest, DecoderJobsCannotStartWithoutAudio) { |
488 if (!MediaCodecBridge::IsAvailable()) { | |
489 LOG(INFO) << "Could not run test - not supported on device."; | |
490 return; | |
491 } | |
492 | |
493 // Test that when Start() is called, video decoder jobs will wait for audio | 448 // Test that when Start() is called, video decoder jobs will wait for audio |
494 // decoder job before start decoding the data. | 449 // decoder job before start decoding the data. |
495 DemuxerConfigs configs; | 450 DemuxerConfigs configs; |
496 configs.audio_codec = kCodecVorbis; | 451 configs.audio_codec = kCodecVorbis; |
497 configs.audio_channels = 2; | 452 configs.audio_channels = 2; |
498 configs.audio_sampling_rate = 44100; | 453 configs.audio_sampling_rate = 44100; |
499 configs.is_audio_encrypted = false; | 454 configs.is_audio_encrypted = false; |
500 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vorbis-extradata"); | 455 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vorbis-extradata"); |
501 configs.audio_extra_data = std::vector<uint8>( | 456 configs.audio_extra_data = std::vector<uint8>( |
502 buffer->data(), | 457 buffer->data(), |
(...skipping 20 matching lines...) Expand all Loading... |
523 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 478 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
524 EXPECT_FALSE(video_decoder_job->is_decoding()); | 479 EXPECT_FALSE(video_decoder_job->is_decoding()); |
525 | 480 |
526 // Sending audio data to player, both decoders should start now. | 481 // Sending audio data to player, both decoders should start now. |
527 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); | 482 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); |
528 EXPECT_TRUE(audio_decoder_job->is_decoding()); | 483 EXPECT_TRUE(audio_decoder_job->is_decoding()); |
529 EXPECT_TRUE(video_decoder_job->is_decoding()); | 484 EXPECT_TRUE(video_decoder_job->is_decoding()); |
530 } | 485 } |
531 | 486 |
532 TEST_F(MediaSourcePlayerTest, StartTimeTicksResetAfterDecoderUnderruns) { | 487 TEST_F(MediaSourcePlayerTest, StartTimeTicksResetAfterDecoderUnderruns) { |
533 if (!MediaCodecBridge::IsAvailable()) { | |
534 LOG(INFO) << "Could not run test - not supported on device."; | |
535 return; | |
536 } | |
537 | |
538 // Test start time ticks will reset after decoder job underruns. | 488 // Test start time ticks will reset after decoder job underruns. |
539 StartAudioDecoderJob(); | 489 StartAudioDecoderJob(); |
540 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); | 490 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); |
541 EXPECT_EQ(1, demuxer_->num_data_requests()); | 491 EXPECT_EQ(1, demuxer_->num_data_requests()); |
542 // For the first couple chunks, the decoder job may return | 492 // For the first couple chunks, the decoder job may return |
543 // DECODE_FORMAT_CHANGED status instead of DECODE_SUCCEEDED status. Decode | 493 // DECODE_FORMAT_CHANGED status instead of DECODE_SUCCEEDED status. Decode |
544 // more frames to guarantee that DECODE_SUCCEEDED will be returned. | 494 // more frames to guarantee that DECODE_SUCCEEDED will be returned. |
545 for (int i = 0; i < 4; ++i) { | 495 for (int i = 0; i < 4; ++i) { |
546 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); | 496 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(i)); |
547 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 497 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
(...skipping 25 matching lines...) Expand all Loading... |
573 // Send new data to the decoder so it can finish prefetching. This should | 523 // Send new data to the decoder so it can finish prefetching. This should |
574 // reset the start time ticks. | 524 // reset the start time ticks. |
575 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); | 525 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(3)); |
576 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); | 526 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks()); |
577 | 527 |
578 base::TimeTicks current = StartTimeTicks(); | 528 base::TimeTicks current = StartTimeTicks(); |
579 EXPECT_LE(100.0, (current - previous).InMillisecondsF()); | 529 EXPECT_LE(100.0, (current - previous).InMillisecondsF()); |
580 } | 530 } |
581 | 531 |
582 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterInputEOS) { | 532 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterInputEOS) { |
583 if (!MediaCodecBridge::IsAvailable()) { | |
584 LOG(INFO) << "Could not run test - not supported on device."; | |
585 return; | |
586 } | |
587 | |
588 // Test MediaSourcePlayer will not request for new data after input EOS is | 533 // Test MediaSourcePlayer will not request for new data after input EOS is |
589 // reached. | 534 // reached. |
590 CreateAndSetVideoSurface(); | 535 CreateAndSetVideoSurface(); |
591 StartVideoDecoderJob(); | 536 StartVideoDecoderJob(); |
592 // Player should not seek the demuxer on setting initial surface. | 537 // Player should not seek the demuxer on setting initial surface. |
593 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 538 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
594 | 539 |
595 EXPECT_EQ(1, demuxer_->num_data_requests()); | 540 EXPECT_EQ(1, demuxer_->num_data_requests()); |
596 // Send the first input chunk. | 541 // Send the first input chunk. |
597 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); | 542 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForVideo()); |
598 message_loop_.Run(); | 543 message_loop_.Run(); |
599 EXPECT_EQ(2, demuxer_->num_data_requests()); | 544 EXPECT_EQ(2, demuxer_->num_data_requests()); |
600 | 545 |
601 // Send EOS. | 546 // Send EOS. |
602 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); | 547 player_.OnDemuxerDataAvailable(CreateEOSAck(false)); |
603 message_loop_.Run(); | 548 message_loop_.Run(); |
604 // No more request for data should be made. | 549 // No more request for data should be made. |
605 EXPECT_EQ(2, demuxer_->num_data_requests()); | 550 EXPECT_EQ(2, demuxer_->num_data_requests()); |
606 } | 551 } |
607 | 552 |
608 TEST_F(MediaSourcePlayerTest, ReplayAfterInputEOS) { | 553 TEST_F(MediaSourcePlayerTest, ReplayAfterInputEOS) { |
609 if (!MediaCodecBridge::IsAvailable()) { | |
610 LOG(INFO) << "Could not run test - not supported on device."; | |
611 return; | |
612 } | |
613 | |
614 // Test MediaSourcePlayer can replay after input EOS is | 554 // Test MediaSourcePlayer can replay after input EOS is |
615 // reached. | 555 // reached. |
616 CreateAndSetVideoSurface(); | 556 CreateAndSetVideoSurface(); |
617 StartVideoDecoderJob(); | 557 StartVideoDecoderJob(); |
618 | 558 |
619 // Player should not seek the demuxer on setting initial surface. | 559 // Player should not seek the demuxer on setting initial surface. |
620 EXPECT_EQ(0, demuxer_->num_seek_requests()); | 560 EXPECT_EQ(0, demuxer_->num_seek_requests()); |
621 | 561 |
622 EXPECT_EQ(1, demuxer_->num_data_requests()); | 562 EXPECT_EQ(1, demuxer_->num_data_requests()); |
623 // Send the first input chunk. | 563 // Send the first input chunk. |
(...skipping 11 matching lines...) Expand all Loading... |
635 // Instead behave as if the renderer has asked us to seek. | 575 // Instead behave as if the renderer has asked us to seek. |
636 player_.SeekTo(base::TimeDelta()); | 576 player_.SeekTo(base::TimeDelta()); |
637 StartVideoDecoderJob(); | 577 StartVideoDecoderJob(); |
638 EXPECT_EQ(1, demuxer_->num_seek_requests()); | 578 EXPECT_EQ(1, demuxer_->num_seek_requests()); |
639 player_.OnDemuxerSeekDone(); | 579 player_.OnDemuxerSeekDone(); |
640 // Seek/Play after EOS should request more data. | 580 // Seek/Play after EOS should request more data. |
641 EXPECT_EQ(3, demuxer_->num_data_requests()); | 581 EXPECT_EQ(3, demuxer_->num_data_requests()); |
642 } | 582 } |
643 | 583 |
644 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterAbort) { | 584 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterAbort) { |
645 if (!MediaCodecBridge::IsAvailable()) { | |
646 LOG(INFO) << "Could not run test - not supported on device."; | |
647 return; | |
648 } | |
649 | |
650 // Test that the decoder will request new data after receiving an aborted | 585 // Test that the decoder will request new data after receiving an aborted |
651 // access unit. | 586 // access unit. |
652 StartAudioDecoderJob(); | 587 StartAudioDecoderJob(); |
653 EXPECT_EQ(1, demuxer_->num_data_requests()); | 588 EXPECT_EQ(1, demuxer_->num_data_requests()); |
654 | 589 |
655 // Send an aborted access unit. | 590 // Send an aborted access unit. |
656 DemuxerData data; | 591 DemuxerData data; |
657 data.type = DemuxerStream::AUDIO; | 592 data.type = DemuxerStream::AUDIO; |
658 data.access_units.resize(1); | 593 data.access_units.resize(1); |
659 data.access_units[0].status = DemuxerStream::kAborted; | 594 data.access_units[0].status = DemuxerStream::kAborted; |
660 player_.OnDemuxerDataAvailable(data); | 595 player_.OnDemuxerDataAvailable(data); |
661 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); | 596 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); |
662 // Wait for the decoder job to finish decoding. | 597 // Wait for the decoder job to finish decoding. |
663 while(GetMediaDecoderJob(true)->is_decoding()) | 598 while(GetMediaDecoderJob(true)->is_decoding()) |
664 message_loop_.RunUntilIdle(); | 599 message_loop_.RunUntilIdle(); |
665 | 600 |
666 // No request will be sent for new data. | 601 // No request will be sent for new data. |
667 EXPECT_EQ(1, demuxer_->num_data_requests()); | 602 EXPECT_EQ(1, demuxer_->num_data_requests()); |
668 } | 603 } |
669 | 604 |
670 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) { | 605 TEST_F(MediaSourcePlayerTest, DemuxerDataArrivesAfterRelease) { |
671 if (!MediaCodecBridge::IsAvailable()) { | |
672 LOG(INFO) << "Could not run test - not supported on device."; | |
673 return; | |
674 } | |
675 | |
676 // Test that the decoder should not crash if demuxer data arrives after | 606 // Test that the decoder should not crash if demuxer data arrives after |
677 // Release(). | 607 // Release(). |
678 StartAudioDecoderJob(); | 608 StartAudioDecoderJob(); |
679 EXPECT_TRUE(player_.IsPlaying()); | 609 EXPECT_TRUE(player_.IsPlaying()); |
680 EXPECT_EQ(1, demuxer_->num_data_requests()); | 610 EXPECT_EQ(1, demuxer_->num_data_requests()); |
681 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); | 611 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); |
682 | 612 |
683 player_.Release(); | 613 player_.Release(); |
684 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); | 614 player_.OnDemuxerDataAvailable(CreateReadFromDemuxerAckForAudio(0)); |
685 | 615 |
686 // The decoder job should have been released. | 616 // The decoder job should have been released. |
687 EXPECT_FALSE(player_.IsPlaying()); | 617 EXPECT_FALSE(player_.IsPlaying()); |
688 EXPECT_EQ(1, demuxer_->num_data_requests()); | 618 EXPECT_EQ(1, demuxer_->num_data_requests()); |
689 } | 619 } |
690 | 620 |
691 // TODO(xhwang): Enable this test when the test devices are updated. | 621 // TODO(xhwang): Enable this test when the test devices are updated. |
692 TEST_F(MediaSourcePlayerTest, DISABLED_IsTypeSupported_Widevine) { | 622 TEST_F(MediaSourcePlayerTest, DISABLED_IsTypeSupported_Widevine) { |
693 if (!MediaCodecBridge::IsAvailable() || !MediaDrmBridge::IsAvailable()) { | 623 if (!MediaDrmBridge::IsAvailable()) { |
694 LOG(INFO) << "Could not run test - not supported on device."; | 624 LOG(INFO) << "Could not run test - not supported on device."; |
695 return; | 625 return; |
696 } | 626 } |
697 | 627 |
698 uint8 kWidevineUUID[] = { 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | 628 uint8 kWidevineUUID[] = { 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, |
699 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | 629 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; |
700 | 630 |
701 std::vector<uint8> widevine_uuid(kWidevineUUID, | 631 std::vector<uint8> widevine_uuid(kWidevineUUID, |
702 kWidevineUUID + arraysize(kWidevineUUID)); | 632 kWidevineUUID + arraysize(kWidevineUUID)); |
703 | 633 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 // Clean this up after we have a solution to specifying decoding mode. | 665 // Clean this up after we have a solution to specifying decoding mode. |
736 EXPECT_TRUE(IsTypeSupported(widevine_uuid, "L3", kAudioWebM, codec_vorbis)); | 666 EXPECT_TRUE(IsTypeSupported(widevine_uuid, "L3", kAudioWebM, codec_vorbis)); |
737 IsTypeSupported(widevine_uuid, "L1", kAudioWebM, codec_vorbis); | 667 IsTypeSupported(widevine_uuid, "L1", kAudioWebM, codec_vorbis); |
738 | 668 |
739 EXPECT_TRUE( | 669 EXPECT_TRUE( |
740 IsTypeSupported(widevine_uuid, "L3", kVideoWebM, codec_vp8_vorbis)); | 670 IsTypeSupported(widevine_uuid, "L3", kVideoWebM, codec_vp8_vorbis)); |
741 IsTypeSupported(widevine_uuid, "L1", kVideoWebM, codec_vp8_vorbis); | 671 IsTypeSupported(widevine_uuid, "L1", kVideoWebM, codec_vp8_vorbis); |
742 } | 672 } |
743 | 673 |
744 TEST_F(MediaSourcePlayerTest, IsTypeSupported_InvalidUUID) { | 674 TEST_F(MediaSourcePlayerTest, IsTypeSupported_InvalidUUID) { |
745 if (!MediaCodecBridge::IsAvailable() || !MediaDrmBridge::IsAvailable()) { | 675 if (!MediaDrmBridge::IsAvailable()) { |
746 LOG(INFO) << "Could not run test - not supported on device."; | 676 LOG(INFO) << "Could not run test - not supported on device."; |
747 return; | 677 return; |
748 } | 678 } |
749 | 679 |
750 uint8 kInvalidUUID[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 680 uint8 kInvalidUUID[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
751 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; | 681 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; |
752 | 682 |
753 std::vector<uint8> invalid_uuid(kInvalidUUID, | 683 std::vector<uint8> invalid_uuid(kInvalidUUID, |
754 kInvalidUUID + arraysize(kInvalidUUID)); | 684 kInvalidUUID + arraysize(kInvalidUUID)); |
755 | 685 |
756 std::vector<std::string> codec_avc(1, "avc1"); | 686 std::vector<std::string> codec_avc(1, "avc1"); |
757 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L3", kVideoMp4, codec_avc)); | 687 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L3", kVideoMp4, codec_avc)); |
758 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L1", kVideoMp4, codec_avc)); | 688 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L1", kVideoMp4, codec_avc)); |
759 } | 689 } |
760 | 690 |
761 // TODO(xhwang): Are these IsTypeSupported tests device specific? | 691 // TODO(xhwang): Are these IsTypeSupported tests device specific? |
762 // TODO(xhwang): Add more IsTypeSupported tests. | 692 // TODO(xhwang): Add more IsTypeSupported tests. |
763 // TODO(wolenetz): Add tests around second SetVideoSurface, once fix to reach | 693 // TODO(wolenetz): Add tests around second SetVideoSurface, once fix to reach |
764 // next I-frame is correct. | 694 // next I-frame is correct. |
765 | 695 |
766 } // namespace media | 696 } // namespace media |
OLD | NEW |