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

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

Issue 23620012: Fix MediaSourcePlayer unittests and minor code cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bug introduced by code in the rebase. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/android/media_source_player.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 if (!MediaCodecBridge::IsAvailable()) 270 if (!MediaCodecBridge::IsAvailable())
271 return; 271 return;
272 272
273 // Test decoder job will resend a ReadFromDemuxer request after seek. 273 // Test decoder job will resend a ReadFromDemuxer request after seek.
274 StartAudioDecoderJob(); 274 StartAudioDecoderJob();
275 EXPECT_TRUE(NULL != GetMediaDecoderJob(true)); 275 EXPECT_TRUE(NULL != GetMediaDecoderJob(true));
276 EXPECT_EQ(1, manager_->num_requests()); 276 EXPECT_EQ(1, manager_->num_requests());
277 277
278 // Initiate a seek 278 // Initiate a seek
279 player_->SeekTo(base::TimeDelta()); 279 player_->SeekTo(base::TimeDelta());
280
281 // Verify that the seek does not occur until the initial prefetch
282 // completes.
283 EXPECT_EQ(0u, manager_->last_seek_request_id());
284
285 // Simulate aborted read caused by the seek. This aborts the initial
286 // prefetch.
287 DemuxerData data;
288 data.type = DemuxerStream::AUDIO;
289 data.access_units.resize(1);
290 data.access_units[0].status = DemuxerStream::kAborted;
291 player_->ReadFromDemuxerAck(data);
292
293 // Verify that the seek is requested now that the initial prefetch
294 // has completed.
280 EXPECT_EQ(1u, manager_->last_seek_request_id()); 295 EXPECT_EQ(1u, manager_->last_seek_request_id());
296
281 // Sending back the seek ACK, this should trigger the player to call 297 // Sending back the seek ACK, this should trigger the player to call
282 // OnReadFromDemuxer() again. 298 // OnReadFromDemuxer() again.
283 player_->OnSeekRequestAck(manager_->last_seek_request_id()); 299 player_->OnSeekRequestAck(manager_->last_seek_request_id());
284 EXPECT_EQ(2, manager_->num_requests()); 300 EXPECT_EQ(2, manager_->num_requests());
285 } 301 }
286 302
287 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) { 303 TEST_F(MediaSourcePlayerTest, SetSurfaceWhileSeeking) {
288 if (!MediaCodecBridge::IsAvailable()) 304 if (!MediaCodecBridge::IsAvailable())
289 return; 305 return;
290 306
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // DECODE_FORMAT_CHANGED status instead of DECODE_SUCCEEDED status. Decode 445 // DECODE_FORMAT_CHANGED status instead of DECODE_SUCCEEDED status. Decode
430 // more frames to guarantee that DECODE_SUCCEEDED will be returned. 446 // more frames to guarantee that DECODE_SUCCEEDED will be returned.
431 for (int i = 0; i < 4; ++i) { 447 for (int i = 0; i < 4; ++i) {
432 player_->ReadFromDemuxerAck(CreateReadFromDemuxerAckForAudio(i)); 448 player_->ReadFromDemuxerAck(CreateReadFromDemuxerAckForAudio(i));
433 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding()); 449 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
434 manager_->message_loop()->Run(); 450 manager_->message_loop()->Run();
435 } 451 }
436 452
437 // The decoder job should finish and a new request will be sent. 453 // The decoder job should finish and a new request will be sent.
438 EXPECT_EQ(5, manager_->num_requests()); 454 EXPECT_EQ(5, manager_->num_requests());
439 EXPECT_FALSE(GetMediaDecoderJob(true)->is_decoding()); 455 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
440 base::TimeTicks previous = StartTimeTicks(); 456 base::TimeTicks previous = StartTimeTicks();
441 457
442 // Let the decoder timeout and execute the OnDecoderStarved() callback. 458 // Let the decoder timeout and execute the OnDecoderStarved() callback.
443 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); 459 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
460
461 EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());
462 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks());
444 manager_->message_loop()->RunUntilIdle(); 463 manager_->message_loop()->RunUntilIdle();
445 464
446 // Send new data to the decoder. This should reset the start time ticks. 465 // Send new data to the decoder so it can finish the currently
447 player_->ReadFromDemuxerAck(CreateEOSAck(true)); 466 // pending decode.
467 player_->ReadFromDemuxerAck(CreateReadFromDemuxerAckForAudio(3));
468 while(GetMediaDecoderJob(true)->is_decoding())
469 manager_->message_loop()->RunUntilIdle();
470
471 // Verify the start time ticks is cleared at this point because the
472 // player is prefetching.
473 EXPECT_TRUE(StartTimeTicks() == base::TimeTicks());
474
475 // Send new data to the decoder so it can finish prefetching. This should
476 // reset the start time ticks.
477 player_->ReadFromDemuxerAck(CreateReadFromDemuxerAckForAudio(3));
478 EXPECT_TRUE(StartTimeTicks() != base::TimeTicks());
479
448 base::TimeTicks current = StartTimeTicks(); 480 base::TimeTicks current = StartTimeTicks();
449 EXPECT_LE(100.0, (current - previous).InMillisecondsF()); 481 EXPECT_LE(100.0, (current - previous).InMillisecondsF());
450 } 482 }
451 483
452 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterInputEOS) { 484 TEST_F(MediaSourcePlayerTest, NoRequestForDataAfterInputEOS) {
453 if (!MediaCodecBridge::IsAvailable()) 485 if (!MediaCodecBridge::IsAvailable())
454 return; 486 return;
455 487
456 // Test MediaSourcePlayer will not request for new data after input EOS is 488 // Test MediaSourcePlayer will not request for new data after input EOS is
457 // reached. 489 // reached.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 542
511 std::vector<std::string> codec_avc(1, "avc1"); 543 std::vector<std::string> codec_avc(1, "avc1");
512 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L3", "video/mp4", codec_avc)); 544 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L3", "video/mp4", codec_avc));
513 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L1", "video/mp4", codec_avc)); 545 EXPECT_FALSE(IsTypeSupported(invalid_uuid, "L1", "video/mp4", codec_avc));
514 } 546 }
515 547
516 // TODO(xhwang): Are these IsTypeSupported tests device specific? 548 // TODO(xhwang): Are these IsTypeSupported tests device specific?
517 // TODO(xhwang): Add more IsTypeSupported tests. 549 // TODO(xhwang): Add more IsTypeSupported tests.
518 550
519 } // namespace media 551 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_source_player.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698