OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "media/base/audio_decoder_config.h" | 6 #include "media/base/audio_decoder_config.h" |
7 #include "media/base/mock_callback.h" | 7 #include "media/base/mock_callback.h" |
8 #include "media/base/mock_demuxer_host.h" | 8 #include "media/base/mock_demuxer_host.h" |
9 #include "media/base/test_data_util.h" | 9 #include "media/base/test_data_util.h" |
10 #include "media/filters/chunk_demuxer.h" | 10 #include "media/filters/chunk_demuxer.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 // The size of TrackEntry element in test file "webm_vp8_track_entry" starts at | 32 // The size of TrackEntry element in test file "webm_vp8_track_entry" starts at |
33 // index 1 and spans 8 bytes. | 33 // index 1 and spans 8 bytes. |
34 static const int kVideoTrackSizeOffset = 1; | 34 static const int kVideoTrackSizeOffset = 1; |
35 static const int kVideoTrackSizeWidth = 8; | 35 static const int kVideoTrackSizeWidth = 8; |
36 static const int kVideoTrackEntryHeaderSize = kVideoTrackSizeOffset + | 36 static const int kVideoTrackEntryHeaderSize = kVideoTrackSizeOffset + |
37 kVideoTrackSizeWidth; | 37 kVideoTrackSizeWidth; |
38 | 38 |
39 static const int kVideoTrackNum = 1; | 39 static const int kVideoTrackNum = 1; |
40 static const int kAudioTrackNum = 2; | 40 static const int kAudioTrackNum = 2; |
41 | 41 |
| 42 static const int kAudioBlockDuration = 23; |
| 43 static const int kVideoBlockDuration = 33; |
| 44 |
42 static const char* kSourceId = "SourceId"; | 45 static const char* kSourceId = "SourceId"; |
43 | 46 |
44 base::TimeDelta kDefaultDuration() { | 47 base::TimeDelta kDefaultDuration() { |
45 return base::TimeDelta::FromMilliseconds(201224); | 48 return base::TimeDelta::FromMilliseconds(201224); |
46 } | 49 } |
47 | 50 |
48 // Write an integer into buffer in the form of vint that spans 8 bytes. | 51 // Write an integer into buffer in the form of vint that spans 8 bytes. |
49 // The data pointed by |buffer| should be at least 8 bytes long. | 52 // The data pointed by |buffer| should be at least 8 bytes long. |
50 // |number| should be in the range 0 <= number < 0x00FFFFFFFFFFFFFF. | 53 // |number| should be in the range 0 <= number < 0x00FFFFFFFFFFFFFF. |
51 static void WriteInt64(uint8* buffer, int64 number) { | 54 static void WriteInt64(uint8* buffer, int64 number) { |
52 DCHECK(number >= 0 && number < GG_LONGLONG(0x00FFFFFFFFFFFFFF)); | 55 DCHECK(number >= 0 && number < GG_LONGLONG(0x00FFFFFFFFFFFFFF)); |
53 buffer[0] = 0x01; | 56 buffer[0] = 0x01; |
54 int64 tmp = number; | 57 int64 tmp = number; |
55 for (int i = 7; i > 0; i--) { | 58 for (int i = 7; i > 0; i--) { |
56 buffer[i] = tmp & 0xff; | 59 buffer[i] = tmp & 0xff; |
57 tmp >>= 8; | 60 tmp >>= 8; |
58 } | 61 } |
59 } | 62 } |
60 | 63 |
61 MATCHER_P(HasTimestamp, timestamp_in_ms, "") { | 64 MATCHER_P(HasTimestamp, timestamp_in_ms, "") { |
62 return !arg->IsEndOfStream() && | 65 return arg && !arg->IsEndOfStream() && |
63 arg->GetTimestamp().InMilliseconds() == timestamp_in_ms; | 66 arg->GetTimestamp().InMilliseconds() == timestamp_in_ms; |
64 } | 67 } |
65 | 68 |
66 static void OnReadDone(const base::TimeDelta& expected_time, | 69 static void OnReadDone(const base::TimeDelta& expected_time, |
67 bool* called, | 70 bool* called, |
68 const scoped_refptr<Buffer>& buffer) { | 71 const scoped_refptr<Buffer>& buffer) { |
69 EXPECT_EQ(expected_time, buffer->GetTimestamp()); | 72 EXPECT_EQ(expected_time, buffer->GetTimestamp()); |
70 *called = true; | 73 *called = true; |
71 } | 74 } |
72 | 75 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 173 } |
171 | 174 |
172 ChunkDemuxer::Status AddId() { | 175 ChunkDemuxer::Status AddId() { |
173 std::vector<std::string> codecs(2); | 176 std::vector<std::string> codecs(2); |
174 codecs[0] = "vp8"; | 177 codecs[0] = "vp8"; |
175 codecs[1] = "vorbis"; | 178 codecs[1] = "vorbis"; |
176 return demuxer_->AddId(kSourceId, "video/webm", codecs); | 179 return demuxer_->AddId(kSourceId, "video/webm", codecs); |
177 } | 180 } |
178 | 181 |
179 bool AppendData(const uint8* data, size_t length) { | 182 bool AppendData(const uint8* data, size_t length) { |
| 183 CHECK(length); |
180 EXPECT_CALL(host_, SetBufferedBytes(_)).Times(AnyNumber()); | 184 EXPECT_CALL(host_, SetBufferedBytes(_)).Times(AnyNumber()); |
181 EXPECT_CALL(host_, SetNetworkActivity(true)) | 185 EXPECT_CALL(host_, SetNetworkActivity(true)) |
182 .Times(AnyNumber()); | 186 .Times(AnyNumber()); |
183 return demuxer_->AppendData(kSourceId, data, length); | 187 return demuxer_->AppendData(kSourceId, data, length); |
184 } | 188 } |
185 | 189 |
186 bool AppendDataInPieces(const uint8* data, size_t length) { | 190 bool AppendDataInPieces(const uint8* data, size_t length) { |
187 return AppendDataInPieces(data, length, 7); | 191 return AppendDataInPieces(data, length, 7); |
188 } | 192 } |
189 | 193 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 EXPECT_CALL(*client_, DemuxerClosed()); | 250 EXPECT_CALL(*client_, DemuxerClosed()); |
247 demuxer_->Shutdown(); | 251 demuxer_->Shutdown(); |
248 } | 252 } |
249 } | 253 } |
250 | 254 |
251 void AddSimpleBlock(ClusterBuilder* cb, int track_num, int64 timecode) { | 255 void AddSimpleBlock(ClusterBuilder* cb, int track_num, int64 timecode) { |
252 uint8 data[] = { 0x00 }; | 256 uint8 data[] = { 0x00 }; |
253 cb->AddSimpleBlock(track_num, timecode, 0, data, sizeof(data)); | 257 cb->AddSimpleBlock(track_num, timecode, 0, data, sizeof(data)); |
254 } | 258 } |
255 | 259 |
256 void AddSimpleBlock(ClusterBuilder* cb, int track_num, int64 timecode, | 260 scoped_ptr<Cluster> GenerateCluster(int timecode, int block_count) { |
257 int size) { | 261 CHECK_GT(block_count, 0); |
| 262 |
| 263 int size = 10; |
258 scoped_array<uint8> data(new uint8[size]); | 264 scoped_array<uint8> data(new uint8[size]); |
259 cb->AddSimpleBlock(track_num, timecode, 0, data.get(), size); | 265 |
| 266 ClusterBuilder cb; |
| 267 cb.SetClusterTimecode(timecode); |
| 268 int audio_timecode = timecode; |
| 269 int video_timecode = timecode + 1; |
| 270 |
| 271 if (block_count == 1) { |
| 272 cb.AddBlockGroup(kAudioTrackNum, audio_timecode, kAudioBlockDuration, 0, |
| 273 data.get(), size); |
| 274 return cb.Finish(); |
| 275 } |
| 276 |
| 277 // Create simple blocks for everything except the last 2 blocks. |
| 278 for (int i = 0; i < block_count - 2; i++) { |
| 279 if (audio_timecode <= video_timecode) { |
| 280 cb.AddSimpleBlock(kAudioTrackNum, audio_timecode, 0, data.get(), size); |
| 281 audio_timecode += kAudioBlockDuration; |
| 282 continue; |
| 283 } |
| 284 |
| 285 cb.AddSimpleBlock(kVideoTrackNum, video_timecode, 0, data.get(), size); |
| 286 video_timecode += kVideoBlockDuration; |
| 287 } |
| 288 |
| 289 // Make the last 2 blocks BlockGroups so that they don't get delayed by the |
| 290 // block duration calculation logic. |
| 291 if (audio_timecode <= video_timecode) { |
| 292 cb.AddBlockGroup(kAudioTrackNum, audio_timecode, kAudioBlockDuration, 0, |
| 293 data.get(), size); |
| 294 cb.AddBlockGroup(kVideoTrackNum, video_timecode, kVideoBlockDuration, 0, |
| 295 data.get(), size); |
| 296 } else { |
| 297 cb.AddBlockGroup(kVideoTrackNum, video_timecode, kVideoBlockDuration, 0, |
| 298 data.get(), size); |
| 299 cb.AddBlockGroup(kAudioTrackNum, audio_timecode, kAudioBlockDuration, 0, |
| 300 data.get(), size); |
| 301 } |
| 302 |
| 303 return cb.Finish(); |
| 304 } |
| 305 |
| 306 void GenerateExpectedReads(int timecode, int block_count, |
| 307 DemuxerStream* audio, |
| 308 DemuxerStream* video) { |
| 309 CHECK_GT(block_count, 0); |
| 310 int audio_timecode = timecode; |
| 311 int video_timecode = timecode + 1; |
| 312 |
| 313 if (block_count == 1) { |
| 314 ExpectRead(audio, audio_timecode); |
| 315 return; |
| 316 } |
| 317 |
| 318 for (int i = 0; i < block_count; i++) { |
| 319 if (audio_timecode <= video_timecode) { |
| 320 ExpectRead(audio, audio_timecode); |
| 321 audio_timecode += kAudioBlockDuration; |
| 322 continue; |
| 323 } |
| 324 |
| 325 ExpectRead(video, video_timecode); |
| 326 video_timecode += kVideoBlockDuration; |
| 327 } |
260 } | 328 } |
261 | 329 |
262 MOCK_METHOD1(ReadDone, void(const scoped_refptr<Buffer>&)); | 330 MOCK_METHOD1(ReadDone, void(const scoped_refptr<Buffer>&)); |
263 | 331 |
264 void ExpectRead(DemuxerStream* stream, int64 timestamp_in_ms) { | 332 void ExpectRead(DemuxerStream* stream, int64 timestamp_in_ms) { |
265 EXPECT_CALL(*this, ReadDone(HasTimestamp(timestamp_in_ms))); | 333 EXPECT_CALL(*this, ReadDone(HasTimestamp(timestamp_in_ms))); |
266 stream->Read(base::Bind(&ChunkDemuxerTest::ReadDone, | 334 stream->Read(base::Bind(&ChunkDemuxerTest::ReadDone, |
267 base::Unretained(this))); | 335 base::Unretained(this))); |
268 } | 336 } |
269 | 337 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 477 |
410 InSequence s; | 478 InSequence s; |
411 | 479 |
412 EXPECT_CALL(*this, Checkpoint(1)); | 480 EXPECT_CALL(*this, Checkpoint(1)); |
413 | 481 |
414 demuxer_->Seek(base::TimeDelta::FromSeconds(0), | 482 demuxer_->Seek(base::TimeDelta::FromSeconds(0), |
415 NewExpectedStatusCB(PIPELINE_OK)); | 483 NewExpectedStatusCB(PIPELINE_OK)); |
416 | 484 |
417 EXPECT_CALL(*this, Checkpoint(2)); | 485 EXPECT_CALL(*this, Checkpoint(2)); |
418 | 486 |
419 ClusterBuilder cb; | 487 scoped_ptr<Cluster> cluster(GenerateCluster(0, 4)); |
420 cb.SetClusterTimecode(0); | |
421 AddSimpleBlock(&cb, kVideoTrackNum, 0); | |
422 scoped_ptr<Cluster> cluster(cb.Finish()); | |
423 | 488 |
424 Checkpoint(1); | 489 Checkpoint(1); |
425 | 490 |
426 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); | 491 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); |
427 | 492 |
428 Checkpoint(2); | 493 Checkpoint(2); |
429 } | 494 } |
430 | 495 |
431 // Test the case where a Seek() is requested while the parser | 496 // Test the case where a Seek() is requested while the parser |
432 // is in the middle of cluster. This is to verify that the parser | 497 // is in the middle of cluster. This is to verify that the parser |
433 // resets itself on seek and is in the right state when data from | 498 // resets itself on seek and is in the right state when data from |
434 // the new seek point arrives. | 499 // the new seek point arrives. |
435 TEST_F(ChunkDemuxerTest, TestSeekWhileParsingCluster) { | 500 TEST_F(ChunkDemuxerTest, TestSeekWhileParsingCluster) { |
436 ASSERT_TRUE(InitDemuxer(true, true, false)); | 501 ASSERT_TRUE(InitDemuxer(true, true, false)); |
437 | 502 |
438 scoped_refptr<DemuxerStream> audio = | 503 scoped_refptr<DemuxerStream> audio = |
439 demuxer_->GetStream(DemuxerStream::AUDIO); | 504 demuxer_->GetStream(DemuxerStream::AUDIO); |
440 scoped_refptr<DemuxerStream> video = | 505 scoped_refptr<DemuxerStream> video = |
441 demuxer_->GetStream(DemuxerStream::VIDEO); | 506 demuxer_->GetStream(DemuxerStream::VIDEO); |
442 | 507 |
443 InSequence s; | 508 InSequence s; |
444 | 509 |
445 ClusterBuilder cb; | 510 scoped_ptr<Cluster> cluster_a(GenerateCluster(0, 6)); |
446 cb.SetClusterTimecode(0); | 511 scoped_ptr<Cluster> cluster_b(GenerateCluster(5000, 6)); |
447 AddSimpleBlock(&cb, kAudioTrackNum, 1); | |
448 AddSimpleBlock(&cb, kVideoTrackNum, 2); | |
449 AddSimpleBlock(&cb, kAudioTrackNum, 10); | |
450 AddSimpleBlock(&cb, kVideoTrackNum, 20); | |
451 scoped_ptr<Cluster> cluster_a(cb.Finish()); | |
452 | |
453 cb.SetClusterTimecode(5000); | |
454 AddSimpleBlock(&cb, kAudioTrackNum, 5000); | |
455 AddSimpleBlock(&cb, kVideoTrackNum, 5005); | |
456 AddSimpleBlock(&cb, kAudioTrackNum, 5007); | |
457 AddSimpleBlock(&cb, kVideoTrackNum, 5035); | |
458 scoped_ptr<Cluster> cluster_b(cb.Finish()); | |
459 | 512 |
460 // Append all but the last byte so that everything but | 513 // Append all but the last byte so that everything but |
461 // the last block can be parsed. | 514 // the last block can be parsed. |
462 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size() - 1)); | 515 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size() - 1)); |
463 | 516 |
464 ExpectRead(audio, 1); | 517 ExpectRead(audio, 0); |
465 ExpectRead(video, 2); | 518 ExpectRead(video, 1); |
466 ExpectRead(audio, 10); | 519 ExpectRead(audio, kAudioBlockDuration); |
| 520 // Note: We skip trying to read a video buffer here because computing |
| 521 // the duration for this block relies on successfully parsing the last block |
| 522 // in the cluster the cluster. |
| 523 ExpectRead(audio, 2 * kAudioBlockDuration); |
467 | 524 |
468 demuxer_->FlushData(); | 525 demuxer_->FlushData(); |
469 demuxer_->Seek(base::TimeDelta::FromSeconds(5), | 526 demuxer_->Seek(base::TimeDelta::FromSeconds(5), |
470 NewExpectedStatusCB(PIPELINE_OK)); | 527 NewExpectedStatusCB(PIPELINE_OK)); |
471 | 528 |
472 | 529 |
473 // Append the new cluster and verify that only the blocks | 530 // Append the new cluster and verify that only the blocks |
474 // in the new cluster are returned. | 531 // in the new cluster are returned. |
475 ASSERT_TRUE(AppendData(cluster_b->data(), cluster_b->size())); | 532 ASSERT_TRUE(AppendData(cluster_b->data(), cluster_b->size())); |
476 ExpectRead(audio, 5000); | 533 GenerateExpectedReads(5000, 6, audio, video); |
477 ExpectRead(video, 5005); | |
478 ExpectRead(audio, 5007); | |
479 ExpectRead(video, 5035); | |
480 } | 534 } |
481 | 535 |
482 // Test the case where AppendData() is called before Init(). | 536 // Test the case where AppendData() is called before Init(). |
483 TEST_F(ChunkDemuxerTest, TestAppendDataBeforeInit) { | 537 TEST_F(ChunkDemuxerTest, TestAppendDataBeforeInit) { |
484 scoped_array<uint8> info_tracks; | 538 scoped_array<uint8> info_tracks; |
485 int info_tracks_size = 0; | 539 int info_tracks_size = 0; |
486 CreateInfoTracks(true, true, false, &info_tracks, &info_tracks_size); | 540 CreateInfoTracks(true, true, false, &info_tracks, &info_tracks_size); |
487 | 541 |
488 EXPECT_FALSE(demuxer_->AppendData(kSourceId, info_tracks.get(), | 542 EXPECT_FALSE(demuxer_->AppendData(kSourceId, info_tracks.get(), |
489 info_tracks_size)); | 543 info_tracks_size)); |
490 } | 544 } |
491 | 545 |
492 // Make sure Read() callbacks are dispatched with the proper data. | 546 // Make sure Read() callbacks are dispatched with the proper data. |
493 TEST_F(ChunkDemuxerTest, TestRead) { | 547 TEST_F(ChunkDemuxerTest, TestRead) { |
494 ASSERT_TRUE(InitDemuxer(true, true, false)); | 548 ASSERT_TRUE(InitDemuxer(true, true, false)); |
495 | 549 |
496 scoped_refptr<DemuxerStream> audio = | 550 scoped_refptr<DemuxerStream> audio = |
497 demuxer_->GetStream(DemuxerStream::AUDIO); | 551 demuxer_->GetStream(DemuxerStream::AUDIO); |
498 scoped_refptr<DemuxerStream> video = | 552 scoped_refptr<DemuxerStream> video = |
499 demuxer_->GetStream(DemuxerStream::VIDEO); | 553 demuxer_->GetStream(DemuxerStream::VIDEO); |
500 | 554 |
501 bool audio_read_done = false; | 555 bool audio_read_done = false; |
502 bool video_read_done = false; | 556 bool video_read_done = false; |
503 audio->Read(base::Bind(&OnReadDone, | 557 audio->Read(base::Bind(&OnReadDone, |
504 base::TimeDelta::FromMilliseconds(32), | 558 base::TimeDelta::FromMilliseconds(0), |
505 &audio_read_done)); | 559 &audio_read_done)); |
506 | 560 |
507 video->Read(base::Bind(&OnReadDone, | 561 video->Read(base::Bind(&OnReadDone, |
508 base::TimeDelta::FromMilliseconds(123), | 562 base::TimeDelta::FromMilliseconds(1), |
509 &video_read_done)); | 563 &video_read_done)); |
510 | 564 |
511 ClusterBuilder cb; | 565 scoped_ptr<Cluster> cluster(GenerateCluster(0, 4)); |
512 cb.SetClusterTimecode(0); | |
513 AddSimpleBlock(&cb, kAudioTrackNum, 32); | |
514 AddSimpleBlock(&cb, kVideoTrackNum, 123); | |
515 scoped_ptr<Cluster> cluster(cb.Finish()); | |
516 | 566 |
517 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); | 567 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); |
518 | 568 |
519 EXPECT_TRUE(audio_read_done); | 569 EXPECT_TRUE(audio_read_done); |
520 EXPECT_TRUE(video_read_done); | 570 EXPECT_TRUE(video_read_done); |
521 } | 571 } |
522 | 572 |
523 TEST_F(ChunkDemuxerTest, TestOutOfOrderClusters) { | 573 TEST_F(ChunkDemuxerTest, TestOutOfOrderClusters) { |
524 ASSERT_TRUE(InitDemuxer(true, true, false)); | 574 ASSERT_TRUE(InitDemuxer(true, true, false)); |
525 | 575 |
526 ClusterBuilder cb; | 576 scoped_ptr<Cluster> cluster_a(GenerateCluster(10, 4)); |
527 | |
528 cb.SetClusterTimecode(10); | |
529 AddSimpleBlock(&cb, kAudioTrackNum, 10); | |
530 AddSimpleBlock(&cb, kVideoTrackNum, 10); | |
531 AddSimpleBlock(&cb, kAudioTrackNum, 33); | |
532 AddSimpleBlock(&cb, kVideoTrackNum, 43); | |
533 scoped_ptr<Cluster> cluster_a(cb.Finish()); | |
534 | 577 |
535 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size())); | 578 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size())); |
536 | 579 |
537 // Cluster B starts before cluster_a and has data | 580 // Cluster B starts before cluster_a and has data |
538 // that overlaps. | 581 // that overlaps. |
539 cb.SetClusterTimecode(5); | 582 scoped_ptr<Cluster> cluster_b(GenerateCluster(5, 4)); |
540 AddSimpleBlock(&cb, kAudioTrackNum, 5); | |
541 AddSimpleBlock(&cb, kVideoTrackNum, 7); | |
542 AddSimpleBlock(&cb, kAudioTrackNum, 28); | |
543 AddSimpleBlock(&cb, kVideoTrackNum, 40); | |
544 scoped_ptr<Cluster> cluster_b(cb.Finish()); | |
545 | 583 |
546 // Make sure that AppendData() fails because this cluster data | 584 // Make sure that AppendData() fails because this cluster data |
547 // is before previous data. | 585 // is before previous data. |
548 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 586 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
549 ASSERT_TRUE(AppendData(cluster_b->data(), cluster_b->size())); | 587 ASSERT_TRUE(AppendData(cluster_b->data(), cluster_b->size())); |
550 | 588 |
551 // Verify that AppendData() doesn't accept more data now. | 589 // Verify that AppendData() doesn't accept more data now. |
552 cb.SetClusterTimecode(45); | 590 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); |
553 AddSimpleBlock(&cb, kAudioTrackNum, 45); | |
554 AddSimpleBlock(&cb, kVideoTrackNum, 45); | |
555 scoped_ptr<Cluster> cluster_c(cb.Finish()); | |
556 EXPECT_FALSE(demuxer_->AppendData(kSourceId, cluster_c->data(), | 591 EXPECT_FALSE(demuxer_->AppendData(kSourceId, cluster_c->data(), |
557 cluster_c->size())); | 592 cluster_c->size())); |
558 } | 593 } |
559 | 594 |
560 TEST_F(ChunkDemuxerTest, TestNonMonotonicButAboveClusterTimecode) { | 595 TEST_F(ChunkDemuxerTest, TestNonMonotonicButAboveClusterTimecode) { |
561 ASSERT_TRUE(InitDemuxer(true, true, false)); | 596 ASSERT_TRUE(InitDemuxer(true, true, false)); |
562 | 597 |
563 ClusterBuilder cb; | 598 ClusterBuilder cb; |
564 | 599 |
565 // Test the case where block timecodes are not monotonically | 600 // Test the case where block timecodes are not monotonically |
566 // increasing but stay above the cluster timecode. | 601 // increasing but stay above the cluster timecode. |
567 cb.SetClusterTimecode(5); | 602 cb.SetClusterTimecode(5); |
568 AddSimpleBlock(&cb, kAudioTrackNum, 5); | 603 AddSimpleBlock(&cb, kAudioTrackNum, 5); |
569 AddSimpleBlock(&cb, kVideoTrackNum, 10); | 604 AddSimpleBlock(&cb, kVideoTrackNum, 10); |
570 AddSimpleBlock(&cb, kAudioTrackNum, 7); | 605 AddSimpleBlock(&cb, kAudioTrackNum, 7); |
571 AddSimpleBlock(&cb, kVideoTrackNum, 15); | 606 AddSimpleBlock(&cb, kVideoTrackNum, 15); |
572 scoped_ptr<Cluster> cluster_a(cb.Finish()); | 607 scoped_ptr<Cluster> cluster_a(cb.Finish()); |
573 | 608 |
574 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 609 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
575 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size())); | 610 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size())); |
576 | 611 |
577 // Verify that AppendData() doesn't accept more data now. | 612 // Verify that AppendData() doesn't accept more data now. |
578 cb.SetClusterTimecode(20); | 613 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); |
579 AddSimpleBlock(&cb, kAudioTrackNum, 20); | |
580 AddSimpleBlock(&cb, kVideoTrackNum, 20); | |
581 scoped_ptr<Cluster> cluster_b(cb.Finish()); | |
582 EXPECT_FALSE(demuxer_->AppendData(kSourceId, cluster_b->data(), | 614 EXPECT_FALSE(demuxer_->AppendData(kSourceId, cluster_b->data(), |
583 cluster_b->size())); | 615 cluster_b->size())); |
584 } | 616 } |
585 | 617 |
586 TEST_F(ChunkDemuxerTest, TestBackwardsAndBeforeClusterTimecode) { | 618 TEST_F(ChunkDemuxerTest, TestBackwardsAndBeforeClusterTimecode) { |
587 ASSERT_TRUE(InitDemuxer(true, true, false)); | 619 ASSERT_TRUE(InitDemuxer(true, true, false)); |
588 | 620 |
589 ClusterBuilder cb; | 621 ClusterBuilder cb; |
590 | 622 |
591 // Test timecodes going backwards and including values less than the cluster | 623 // Test timecodes going backwards and including values less than the cluster |
592 // timecode. | 624 // timecode. |
593 cb.SetClusterTimecode(5); | 625 cb.SetClusterTimecode(5); |
594 AddSimpleBlock(&cb, kAudioTrackNum, 5); | 626 AddSimpleBlock(&cb, kAudioTrackNum, 5); |
595 AddSimpleBlock(&cb, kVideoTrackNum, 5); | 627 AddSimpleBlock(&cb, kVideoTrackNum, 5); |
596 AddSimpleBlock(&cb, kAudioTrackNum, 3); | 628 AddSimpleBlock(&cb, kAudioTrackNum, 3); |
597 AddSimpleBlock(&cb, kVideoTrackNum, 3); | 629 AddSimpleBlock(&cb, kVideoTrackNum, 3); |
598 scoped_ptr<Cluster> cluster_a(cb.Finish()); | 630 scoped_ptr<Cluster> cluster_a(cb.Finish()); |
599 | 631 |
600 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 632 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
601 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size())); | 633 ASSERT_TRUE(AppendData(cluster_a->data(), cluster_a->size())); |
602 | 634 |
603 // Verify that AppendData() doesn't accept more data now. | 635 // Verify that AppendData() doesn't accept more data now. |
604 cb.SetClusterTimecode(6); | 636 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); |
605 AddSimpleBlock(&cb, kAudioTrackNum, 6); | |
606 AddSimpleBlock(&cb, kVideoTrackNum, 6); | |
607 scoped_ptr<Cluster> cluster_b(cb.Finish()); | |
608 EXPECT_FALSE(demuxer_->AppendData(kSourceId, cluster_b->data(), | 637 EXPECT_FALSE(demuxer_->AppendData(kSourceId, cluster_b->data(), |
609 cluster_b->size())); | 638 cluster_b->size())); |
610 } | 639 } |
611 | 640 |
612 | 641 |
613 TEST_F(ChunkDemuxerTest, TestPerStreamMonotonicallyIncreasingTimestamps) { | 642 TEST_F(ChunkDemuxerTest, TestPerStreamMonotonicallyIncreasingTimestamps) { |
614 ASSERT_TRUE(InitDemuxer(true, true, false)); | 643 ASSERT_TRUE(InitDemuxer(true, true, false)); |
615 | 644 |
616 ClusterBuilder cb; | 645 ClusterBuilder cb; |
617 | 646 |
(...skipping 26 matching lines...) Expand all Loading... |
644 | 673 |
645 cb.SetClusterTimecode(5); | 674 cb.SetClusterTimecode(5); |
646 AddSimpleBlock(&cb, kAudioTrackNum, 5); | 675 AddSimpleBlock(&cb, kAudioTrackNum, 5); |
647 AddSimpleBlock(&cb, kVideoTrackNum, 7); | 676 AddSimpleBlock(&cb, kVideoTrackNum, 7); |
648 scoped_ptr<Cluster> cluster_b(cb.Finish()); | 677 scoped_ptr<Cluster> cluster_b(cb.Finish()); |
649 | 678 |
650 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 679 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
651 ASSERT_TRUE(AppendData(cluster_b->data(), cluster_b->size())); | 680 ASSERT_TRUE(AppendData(cluster_b->data(), cluster_b->size())); |
652 | 681 |
653 // Verify that AppendData() doesn't accept more data now. | 682 // Verify that AppendData() doesn't accept more data now. |
654 cb.SetClusterTimecode(10); | 683 scoped_ptr<Cluster> cluster_c(GenerateCluster(10, 2)); |
655 AddSimpleBlock(&cb, kAudioTrackNum, 10); | |
656 AddSimpleBlock(&cb, kVideoTrackNum, 10); | |
657 scoped_ptr<Cluster> cluster_c(cb.Finish()); | |
658 EXPECT_FALSE(demuxer_->AppendData(kSourceId, cluster_c->data(), | 684 EXPECT_FALSE(demuxer_->AppendData(kSourceId, cluster_c->data(), |
659 cluster_c->size())); | 685 cluster_c->size())); |
660 } | 686 } |
661 | 687 |
662 // Test the case where a cluster is passed to AppendData() before | 688 // Test the case where a cluster is passed to AppendData() before |
663 // INFO & TRACKS data. | 689 // INFO & TRACKS data. |
664 TEST_F(ChunkDemuxerTest, TestClusterBeforeInfoTracks) { | 690 TEST_F(ChunkDemuxerTest, TestClusterBeforeInfoTracks) { |
665 EXPECT_CALL(*client_, DemuxerOpened(_)); | 691 EXPECT_CALL(*client_, DemuxerOpened(_)); |
666 demuxer_->Initialize( | 692 demuxer_->Initialize( |
667 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN)); | 693 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN)); |
668 | 694 |
669 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); | 695 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); |
670 | 696 |
671 ClusterBuilder cb; | 697 scoped_ptr<Cluster> cluster(GenerateCluster(0, 1)); |
672 cb.SetClusterTimecode(0); | |
673 AddSimpleBlock(&cb, kVideoTrackNum, 0); | |
674 scoped_ptr<Cluster> cluster(cb.Finish()); | |
675 | 698 |
676 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); | 699 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); |
677 } | 700 } |
678 | 701 |
679 // Test cases where we get an EndOfStream() call during initialization. | 702 // Test cases where we get an EndOfStream() call during initialization. |
680 TEST_F(ChunkDemuxerTest, TestEOSDuringInit) { | 703 TEST_F(ChunkDemuxerTest, TestEOSDuringInit) { |
681 EXPECT_CALL(*client_, DemuxerOpened(_)); | 704 EXPECT_CALL(*client_, DemuxerOpened(_)); |
682 demuxer_->Initialize( | 705 demuxer_->Initialize( |
683 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN)); | 706 &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_OPEN)); |
684 demuxer_->EndOfStream(PIPELINE_OK); | 707 demuxer_->EndOfStream(PIPELINE_OK); |
685 } | 708 } |
686 | 709 |
687 TEST_F(ChunkDemuxerTest, TestDecodeErrorEndOfStream) { | 710 TEST_F(ChunkDemuxerTest, TestDecodeErrorEndOfStream) { |
688 ASSERT_TRUE(InitDemuxer(true, true, false)); | 711 ASSERT_TRUE(InitDemuxer(true, true, false)); |
689 | 712 |
690 ClusterBuilder cb; | 713 scoped_ptr<Cluster> cluster(GenerateCluster(0, 4)); |
691 cb.SetClusterTimecode(0); | |
692 AddSimpleBlock(&cb, kAudioTrackNum, 0); | |
693 AddSimpleBlock(&cb, kVideoTrackNum, 0); | |
694 AddSimpleBlock(&cb, kAudioTrackNum, 23); | |
695 AddSimpleBlock(&cb, kVideoTrackNum, 33); | |
696 scoped_ptr<Cluster> cluster(cb.Finish()); | |
697 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); | 714 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); |
698 | 715 |
699 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 716 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
700 demuxer_->EndOfStream(PIPELINE_ERROR_DECODE); | 717 demuxer_->EndOfStream(PIPELINE_ERROR_DECODE); |
701 } | 718 } |
702 | 719 |
703 TEST_F(ChunkDemuxerTest, TestNetworkErrorEndOfStream) { | 720 TEST_F(ChunkDemuxerTest, TestNetworkErrorEndOfStream) { |
704 ASSERT_TRUE(InitDemuxer(true, true, false)); | 721 ASSERT_TRUE(InitDemuxer(true, true, false)); |
705 | 722 |
706 ClusterBuilder cb; | 723 scoped_ptr<Cluster> cluster(GenerateCluster(0, 4)); |
707 cb.SetClusterTimecode(0); | |
708 AddSimpleBlock(&cb, kAudioTrackNum, 0); | |
709 AddSimpleBlock(&cb, kVideoTrackNum, 0); | |
710 AddSimpleBlock(&cb, kAudioTrackNum, 23); | |
711 AddSimpleBlock(&cb, kVideoTrackNum, 33); | |
712 scoped_ptr<Cluster> cluster(cb.Finish()); | |
713 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); | 724 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); |
714 | 725 |
715 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_NETWORK)); | 726 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_NETWORK)); |
716 demuxer_->EndOfStream(PIPELINE_ERROR_NETWORK); | 727 demuxer_->EndOfStream(PIPELINE_ERROR_NETWORK); |
717 } | 728 } |
718 | 729 |
719 // Helper class to reduce duplicate code when testing end of stream | 730 // Helper class to reduce duplicate code when testing end of stream |
720 // Read() behavior. | 731 // Read() behavior. |
721 class EndOfStreamHelper { | 732 class EndOfStreamHelper { |
722 public: | 733 public: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 demuxer_->GetStream(DemuxerStream::AUDIO); | 784 demuxer_->GetStream(DemuxerStream::AUDIO); |
774 scoped_refptr<DemuxerStream> video = | 785 scoped_refptr<DemuxerStream> video = |
775 demuxer_->GetStream(DemuxerStream::VIDEO); | 786 demuxer_->GetStream(DemuxerStream::VIDEO); |
776 | 787 |
777 bool audio_read_done_1 = false; | 788 bool audio_read_done_1 = false; |
778 bool video_read_done_1 = false; | 789 bool video_read_done_1 = false; |
779 EndOfStreamHelper end_of_stream_helper_1(demuxer_); | 790 EndOfStreamHelper end_of_stream_helper_1(demuxer_); |
780 EndOfStreamHelper end_of_stream_helper_2(demuxer_); | 791 EndOfStreamHelper end_of_stream_helper_2(demuxer_); |
781 | 792 |
782 audio->Read(base::Bind(&OnReadDone, | 793 audio->Read(base::Bind(&OnReadDone, |
783 base::TimeDelta::FromMilliseconds(32), | 794 base::TimeDelta::FromMilliseconds(0), |
784 &audio_read_done_1)); | 795 &audio_read_done_1)); |
785 | 796 |
786 video->Read(base::Bind(&OnReadDone, | 797 video->Read(base::Bind(&OnReadDone, |
787 base::TimeDelta::FromMilliseconds(123), | 798 base::TimeDelta::FromMilliseconds(1), |
788 &video_read_done_1)); | 799 &video_read_done_1)); |
789 | 800 |
790 end_of_stream_helper_1.RequestReads(); | 801 end_of_stream_helper_1.RequestReads(); |
791 end_of_stream_helper_2.RequestReads(); | 802 end_of_stream_helper_2.RequestReads(); |
792 | 803 |
793 ClusterBuilder cb; | 804 scoped_ptr<Cluster> cluster(GenerateCluster(0, 2)); |
794 cb.SetClusterTimecode(0); | |
795 AddSimpleBlock(&cb, kAudioTrackNum, 32); | |
796 AddSimpleBlock(&cb, kVideoTrackNum, 123); | |
797 scoped_ptr<Cluster> cluster(cb.Finish()); | |
798 | 805 |
799 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); | 806 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); |
800 | 807 |
801 EXPECT_TRUE(audio_read_done_1); | 808 EXPECT_TRUE(audio_read_done_1); |
802 EXPECT_TRUE(video_read_done_1); | 809 EXPECT_TRUE(video_read_done_1); |
803 end_of_stream_helper_1.CheckIfReadDonesWereCalled(false); | 810 end_of_stream_helper_1.CheckIfReadDonesWereCalled(false); |
804 end_of_stream_helper_2.CheckIfReadDonesWereCalled(false); | 811 end_of_stream_helper_2.CheckIfReadDonesWereCalled(false); |
805 | 812 |
806 demuxer_->EndOfStream(PIPELINE_OK); | 813 demuxer_->EndOfStream(PIPELINE_OK); |
807 | 814 |
(...skipping 11 matching lines...) Expand all Loading... |
819 scoped_refptr<DemuxerStream> video = | 826 scoped_refptr<DemuxerStream> video = |
820 demuxer_->GetStream(DemuxerStream::VIDEO); | 827 demuxer_->GetStream(DemuxerStream::VIDEO); |
821 | 828 |
822 bool audio_read_done_1 = false; | 829 bool audio_read_done_1 = false; |
823 bool video_read_done_1 = false; | 830 bool video_read_done_1 = false; |
824 EndOfStreamHelper end_of_stream_helper_1(demuxer_); | 831 EndOfStreamHelper end_of_stream_helper_1(demuxer_); |
825 EndOfStreamHelper end_of_stream_helper_2(demuxer_); | 832 EndOfStreamHelper end_of_stream_helper_2(demuxer_); |
826 EndOfStreamHelper end_of_stream_helper_3(demuxer_); | 833 EndOfStreamHelper end_of_stream_helper_3(demuxer_); |
827 | 834 |
828 audio->Read(base::Bind(&OnReadDone, | 835 audio->Read(base::Bind(&OnReadDone, |
829 base::TimeDelta::FromMilliseconds(32), | 836 base::TimeDelta::FromMilliseconds(0), |
830 &audio_read_done_1)); | 837 &audio_read_done_1)); |
831 | 838 |
832 video->Read(base::Bind(&OnReadDone, | 839 video->Read(base::Bind(&OnReadDone, |
833 base::TimeDelta::FromMilliseconds(123), | 840 base::TimeDelta::FromMilliseconds(1), |
834 &video_read_done_1)); | 841 &video_read_done_1)); |
835 | 842 |
836 end_of_stream_helper_1.RequestReads(); | 843 end_of_stream_helper_1.RequestReads(); |
837 | 844 |
838 ClusterBuilder cb; | 845 scoped_ptr<Cluster> cluster(GenerateCluster(0, 2)); |
839 cb.SetClusterTimecode(0); | |
840 AddSimpleBlock(&cb, kAudioTrackNum, 32); | |
841 AddSimpleBlock(&cb, kVideoTrackNum, 123); | |
842 scoped_ptr<Cluster> cluster(cb.Finish()); | |
843 | 846 |
844 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); | 847 ASSERT_TRUE(AppendData(cluster->data(), cluster->size())); |
845 | 848 |
846 EXPECT_TRUE(audio_read_done_1); | 849 EXPECT_TRUE(audio_read_done_1); |
847 EXPECT_TRUE(video_read_done_1); | 850 EXPECT_TRUE(video_read_done_1); |
848 end_of_stream_helper_1.CheckIfReadDonesWereCalled(false); | 851 end_of_stream_helper_1.CheckIfReadDonesWereCalled(false); |
849 | 852 |
850 demuxer_->EndOfStream(PIPELINE_OK); | 853 demuxer_->EndOfStream(PIPELINE_OK); |
851 | 854 |
852 end_of_stream_helper_1.CheckIfReadDonesWereCalled(true); | 855 end_of_stream_helper_1.CheckIfReadDonesWereCalled(true); |
(...skipping 13 matching lines...) Expand all Loading... |
866 EXPECT_CALL(*client_, DemuxerOpened(_)); | 869 EXPECT_CALL(*client_, DemuxerOpened(_)); |
867 demuxer_->Initialize( | 870 demuxer_->Initialize( |
868 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK)); | 871 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK)); |
869 | 872 |
870 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); | 873 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); |
871 | 874 |
872 scoped_array<uint8> info_tracks; | 875 scoped_array<uint8> info_tracks; |
873 int info_tracks_size = 0; | 876 int info_tracks_size = 0; |
874 CreateInfoTracks(true, true, false, &info_tracks, &info_tracks_size); | 877 CreateInfoTracks(true, true, false, &info_tracks, &info_tracks_size); |
875 | 878 |
876 ClusterBuilder cb; | 879 scoped_ptr<Cluster> cluster_a(GenerateCluster(0, 4)); |
877 cb.SetClusterTimecode(0); | 880 scoped_ptr<Cluster> cluster_b(GenerateCluster(68, 4)); |
878 AddSimpleBlock(&cb, kAudioTrackNum, 32, 512); | |
879 AddSimpleBlock(&cb, kVideoTrackNum, 123, 1024); | |
880 scoped_ptr<Cluster> cluster_a(cb.Finish()); | |
881 | |
882 cb.SetClusterTimecode(125); | |
883 AddSimpleBlock(&cb, kAudioTrackNum, 125, 2048); | |
884 AddSimpleBlock(&cb, kVideoTrackNum, 150, 2048); | |
885 scoped_ptr<Cluster> cluster_b(cb.Finish()); | |
886 | 881 |
887 size_t buffer_size = info_tracks_size + cluster_a->size() + cluster_b->size(); | 882 size_t buffer_size = info_tracks_size + cluster_a->size() + cluster_b->size(); |
888 scoped_array<uint8> buffer(new uint8[buffer_size]); | 883 scoped_array<uint8> buffer(new uint8[buffer_size]); |
889 uint8* dst = buffer.get(); | 884 uint8* dst = buffer.get(); |
890 memcpy(dst, info_tracks.get(), info_tracks_size); | 885 memcpy(dst, info_tracks.get(), info_tracks_size); |
891 dst += info_tracks_size; | 886 dst += info_tracks_size; |
892 | 887 |
893 memcpy(dst, cluster_a->data(), cluster_a->size()); | 888 memcpy(dst, cluster_a->data(), cluster_a->size()); |
894 dst += cluster_a->size(); | 889 dst += cluster_a->size(); |
895 | 890 |
896 memcpy(dst, cluster_b->data(), cluster_b->size()); | 891 memcpy(dst, cluster_b->data(), cluster_b->size()); |
897 dst += cluster_b->size(); | 892 dst += cluster_b->size(); |
898 | 893 |
899 ASSERT_TRUE(AppendDataInPieces(buffer.get(), buffer_size)); | 894 ASSERT_TRUE(AppendDataInPieces(buffer.get(), buffer_size)); |
900 | 895 |
901 scoped_refptr<DemuxerStream> audio = | 896 scoped_refptr<DemuxerStream> audio = |
902 demuxer_->GetStream(DemuxerStream::AUDIO); | 897 demuxer_->GetStream(DemuxerStream::AUDIO); |
903 scoped_refptr<DemuxerStream> video = | 898 scoped_refptr<DemuxerStream> video = |
904 demuxer_->GetStream(DemuxerStream::VIDEO); | 899 demuxer_->GetStream(DemuxerStream::VIDEO); |
905 | 900 |
906 ASSERT_TRUE(audio); | 901 ASSERT_TRUE(audio); |
907 ASSERT_TRUE(video); | 902 ASSERT_TRUE(video); |
908 | 903 |
909 bool audio_read_done = false; | 904 GenerateExpectedReads(0, 4, audio, video); |
910 bool video_read_done = false; | 905 GenerateExpectedReads(68, 4, audio, video); |
911 audio->Read(base::Bind(&OnReadDone, | |
912 base::TimeDelta::FromMilliseconds(32), | |
913 &audio_read_done)); | |
914 | |
915 video->Read(base::Bind(&OnReadDone, | |
916 base::TimeDelta::FromMilliseconds(123), | |
917 &video_read_done)); | |
918 | |
919 EXPECT_TRUE(audio_read_done); | |
920 EXPECT_TRUE(video_read_done); | |
921 | |
922 audio_read_done = false; | |
923 video_read_done = false; | |
924 audio->Read(base::Bind(&OnReadDone, | |
925 base::TimeDelta::FromMilliseconds(125), | |
926 &audio_read_done)); | |
927 | |
928 video->Read(base::Bind(&OnReadDone, | |
929 base::TimeDelta::FromMilliseconds(150), | |
930 &video_read_done)); | |
931 | |
932 EXPECT_TRUE(audio_read_done); | |
933 EXPECT_TRUE(video_read_done); | |
934 } | 906 } |
935 | 907 |
936 TEST_F(ChunkDemuxerTest, TestWebMFile_AudioAndVideo) { | 908 TEST_F(ChunkDemuxerTest, TestWebMFile_AudioAndVideo) { |
937 struct BufferTimestamps buffer_timestamps[] = { | 909 struct BufferTimestamps buffer_timestamps[] = { |
938 {0, 0}, | 910 {0, 0}, |
939 {33, 3}, | 911 {33, 3}, |
940 {67, 6}, | 912 {67, 6}, |
941 {100, 9}, | 913 {100, 9}, |
942 {133, 12}, | 914 {133, 12}, |
943 {kSkip, kSkip}, | 915 {kSkip, kSkip}, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 }; | 958 }; |
987 | 959 |
988 ASSERT_TRUE(ParseWebMFile("bear-320x240-video-only.webm", buffer_timestamps, | 960 ASSERT_TRUE(ParseWebMFile("bear-320x240-video-only.webm", buffer_timestamps, |
989 base::TimeDelta::FromMilliseconds(2703))); | 961 base::TimeDelta::FromMilliseconds(2703))); |
990 } | 962 } |
991 | 963 |
992 // Verify that we output buffers before the entire cluster has been parsed. | 964 // Verify that we output buffers before the entire cluster has been parsed. |
993 TEST_F(ChunkDemuxerTest, TestIncrementalClusterParsing) { | 965 TEST_F(ChunkDemuxerTest, TestIncrementalClusterParsing) { |
994 ASSERT_TRUE(InitDemuxer(true, true, false)); | 966 ASSERT_TRUE(InitDemuxer(true, true, false)); |
995 | 967 |
996 ClusterBuilder cb; | 968 scoped_ptr<Cluster> cluster(GenerateCluster(0, 6)); |
997 cb.SetClusterTimecode(0); | |
998 AddSimpleBlock(&cb, kAudioTrackNum, 0, 10); | |
999 AddSimpleBlock(&cb, kVideoTrackNum, 1, 10); | |
1000 AddSimpleBlock(&cb, kVideoTrackNum, 2, 10); | |
1001 AddSimpleBlock(&cb, kAudioTrackNum, 3, 10); | |
1002 scoped_ptr<Cluster> cluster(cb.Finish()); | |
1003 | |
1004 scoped_refptr<DemuxerStream> audio = | 969 scoped_refptr<DemuxerStream> audio = |
1005 demuxer_->GetStream(DemuxerStream::AUDIO); | 970 demuxer_->GetStream(DemuxerStream::AUDIO); |
1006 scoped_refptr<DemuxerStream> video = | 971 scoped_refptr<DemuxerStream> video = |
1007 demuxer_->GetStream(DemuxerStream::VIDEO); | 972 demuxer_->GetStream(DemuxerStream::VIDEO); |
1008 | 973 |
1009 bool audio_read_done = false; | 974 bool audio_read_done = false; |
1010 bool video_read_done = false; | 975 bool video_read_done = false; |
1011 audio->Read(base::Bind(&OnReadDone, | 976 audio->Read(base::Bind(&OnReadDone, |
1012 base::TimeDelta::FromMilliseconds(0), | 977 base::TimeDelta::FromMilliseconds(0), |
1013 &audio_read_done)); | 978 &audio_read_done)); |
(...skipping 21 matching lines...) Expand all Loading... |
1035 for (; i < cluster->size() && !video_read_done; ++i) { | 1000 for (; i < cluster->size() && !video_read_done; ++i) { |
1036 ASSERT_TRUE(AppendData(cluster->data() + i, 1)); | 1001 ASSERT_TRUE(AppendData(cluster->data() + i, 1)); |
1037 } | 1002 } |
1038 | 1003 |
1039 EXPECT_TRUE(video_read_done); | 1004 EXPECT_TRUE(video_read_done); |
1040 EXPECT_LT(i, cluster->size()); | 1005 EXPECT_LT(i, cluster->size()); |
1041 | 1006 |
1042 audio_read_done = false; | 1007 audio_read_done = false; |
1043 video_read_done = false; | 1008 video_read_done = false; |
1044 audio->Read(base::Bind(&OnReadDone, | 1009 audio->Read(base::Bind(&OnReadDone, |
1045 base::TimeDelta::FromMilliseconds(3), | 1010 base::TimeDelta::FromMilliseconds(23), |
1046 &audio_read_done)); | 1011 &audio_read_done)); |
1047 | 1012 |
1048 video->Read(base::Bind(&OnReadDone, | 1013 video->Read(base::Bind(&OnReadDone, |
1049 base::TimeDelta::FromMilliseconds(2), | 1014 base::TimeDelta::FromMilliseconds(34), |
1050 &video_read_done)); | 1015 &video_read_done)); |
1051 | 1016 |
1052 // Make sure the reads haven't completed yet. | 1017 // Make sure the reads haven't completed yet. |
1053 EXPECT_FALSE(audio_read_done); | 1018 EXPECT_FALSE(audio_read_done); |
1054 EXPECT_FALSE(video_read_done); | 1019 EXPECT_FALSE(video_read_done); |
1055 | 1020 |
1056 // Append the remaining data. | 1021 // Append the remaining data. |
| 1022 ASSERT_LT(i, cluster->size()); |
1057 ASSERT_TRUE(AppendData(cluster->data() + i, cluster->size() - i)); | 1023 ASSERT_TRUE(AppendData(cluster->data() + i, cluster->size() - i)); |
1058 | 1024 |
1059 EXPECT_TRUE(audio_read_done); | 1025 EXPECT_TRUE(audio_read_done); |
1060 EXPECT_TRUE(video_read_done); | 1026 EXPECT_TRUE(video_read_done); |
1061 } | 1027 } |
1062 | 1028 |
1063 | 1029 |
1064 TEST_F(ChunkDemuxerTest, TestParseErrorDuringInit) { | 1030 TEST_F(ChunkDemuxerTest, TestParseErrorDuringInit) { |
1065 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 1031 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
1066 | 1032 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 | 1064 |
1099 std::vector<std::string> codecs(1); | 1065 std::vector<std::string> codecs(1); |
1100 codecs[0] = "vp8"; | 1066 codecs[0] = "vp8"; |
1101 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs), | 1067 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs), |
1102 ChunkDemuxer::kOk); | 1068 ChunkDemuxer::kOk); |
1103 | 1069 |
1104 ASSERT_TRUE(AppendInfoTracks(true, true, false)); | 1070 ASSERT_TRUE(AppendInfoTracks(true, true, false)); |
1105 } | 1071 } |
1106 | 1072 |
1107 } // namespace media | 1073 } // namespace media |
OLD | NEW |