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

Side by Side Diff: media/formats/mp4/track_run_iterator_unittest.cc

Issue 2815303006: Convert MediaLog from being ref counted to owned by WebMediaPlayer. (Closed)
Patch Set: Actually fix fuzzers. Created 3 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "media/formats/mp4/track_run_iterator.h" 5 #include "media/formats/mp4/track_run_iterator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 namespace media { 144 namespace media {
145 namespace mp4 { 145 namespace mp4 {
146 146
147 MATCHER(ReservedValueInSampleDependencyInfo, "") { 147 MATCHER(ReservedValueInSampleDependencyInfo, "") {
148 return CONTAINS_STRING(arg, "Reserved value used in sample dependency info."); 148 return CONTAINS_STRING(arg, "Reserved value used in sample dependency info.");
149 } 149 }
150 150
151 class TrackRunIteratorTest : public testing::Test { 151 class TrackRunIteratorTest : public testing::Test {
152 public: 152 public:
153 TrackRunIteratorTest() : media_log_(new StrictMock<MockMediaLog>()) { 153 TrackRunIteratorTest() { CreateMovie(); }
154 CreateMovie();
155 }
156 154
157 protected: 155 protected:
156 StrictMock<MockMediaLog> media_log_;
158 Movie moov_; 157 Movie moov_;
159 scoped_refptr<StrictMock<MockMediaLog>> media_log_;
160 std::unique_ptr<TrackRunIterator> iter_; 158 std::unique_ptr<TrackRunIterator> iter_;
161 159
162 void CreateMovie() { 160 void CreateMovie() {
163 moov_.header.timescale = 1000; 161 moov_.header.timescale = 1000;
164 moov_.tracks.resize(3); 162 moov_.tracks.resize(3);
165 moov_.extends.tracks.resize(2); 163 moov_.extends.tracks.resize(2);
166 moov_.tracks[0].header.track_id = 1; 164 moov_.tracks[0].header.track_id = 1;
167 moov_.tracks[0].media.header.timescale = kAudioScale; 165 moov_.tracks[0].media.header.timescale = kAudioScale;
168 SampleDescription& desc1 = 166 SampleDescription& desc1 =
169 moov_.tracks[0].media.information.sample_table.description; 167 moov_.tracks[0].media.information.sample_table.description;
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 477 }
480 478
481 void SetAscending(std::vector<uint32_t>* vec) { 479 void SetAscending(std::vector<uint32_t>* vec) {
482 vec->resize(10); 480 vec->resize(10);
483 for (size_t i = 0; i < vec->size(); i++) 481 for (size_t i = 0; i < vec->size(); i++)
484 (*vec)[i] = i+1; 482 (*vec)[i] = i+1;
485 } 483 }
486 }; 484 };
487 485
488 TEST_F(TrackRunIteratorTest, NoRunsTest) { 486 TEST_F(TrackRunIteratorTest, NoRunsTest) {
489 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 487 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
490 ASSERT_TRUE(iter_->Init(MovieFragment())); 488 ASSERT_TRUE(iter_->Init(MovieFragment()));
491 EXPECT_FALSE(iter_->IsRunValid()); 489 EXPECT_FALSE(iter_->IsRunValid());
492 EXPECT_FALSE(iter_->IsSampleValid()); 490 EXPECT_FALSE(iter_->IsSampleValid());
493 } 491 }
494 492
495 TEST_F(TrackRunIteratorTest, BasicOperationTest) { 493 TEST_F(TrackRunIteratorTest, BasicOperationTest) {
496 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 494 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
497 MovieFragment moof = CreateFragment(); 495 MovieFragment moof = CreateFragment();
498 496
499 // Test that runs are sorted correctly, and that properties of the initial 497 // Test that runs are sorted correctly, and that properties of the initial
500 // sample of the first run are correct 498 // sample of the first run are correct
501 ASSERT_TRUE(iter_->Init(moof)); 499 ASSERT_TRUE(iter_->Init(moof));
502 EXPECT_TRUE(iter_->IsRunValid()); 500 EXPECT_TRUE(iter_->IsRunValid());
503 EXPECT_FALSE(iter_->is_encrypted()); 501 EXPECT_FALSE(iter_->is_encrypted());
504 EXPECT_EQ(iter_->track_id(), 1u); 502 EXPECT_EQ(iter_->track_id(), 1u);
505 EXPECT_EQ(iter_->sample_offset(), 100); 503 EXPECT_EQ(iter_->sample_offset(), 100);
506 EXPECT_EQ(iter_->sample_size(), 1); 504 EXPECT_EQ(iter_->sample_size(), 1);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 moof.tracks[0].header.default_sample_size, 541 moof.tracks[0].header.default_sample_size,
544 iter_->sample_offset()); 542 iter_->sample_offset());
545 iter_->AdvanceRun(); 543 iter_->AdvanceRun();
546 EXPECT_FALSE(iter_->IsRunValid()); 544 EXPECT_FALSE(iter_->IsRunValid());
547 } 545 }
548 546
549 TEST_F(TrackRunIteratorTest, TrackExtendsDefaultsTest) { 547 TEST_F(TrackRunIteratorTest, TrackExtendsDefaultsTest) {
550 moov_.extends.tracks[0].default_sample_duration = 50; 548 moov_.extends.tracks[0].default_sample_duration = 50;
551 moov_.extends.tracks[0].default_sample_size = 3; 549 moov_.extends.tracks[0].default_sample_size = 3;
552 moov_.extends.tracks[0].default_sample_flags = ToSampleFlags("UN"); 550 moov_.extends.tracks[0].default_sample_flags = ToSampleFlags("UN");
553 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 551 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
554 MovieFragment moof = CreateFragment(); 552 MovieFragment moof = CreateFragment();
555 moof.tracks[0].header.has_default_sample_flags = false; 553 moof.tracks[0].header.has_default_sample_flags = false;
556 moof.tracks[0].header.default_sample_size = 0; 554 moof.tracks[0].header.default_sample_size = 0;
557 moof.tracks[0].header.default_sample_duration = 0; 555 moof.tracks[0].header.default_sample_duration = 0;
558 moof.tracks[0].runs[0].sample_sizes.clear(); 556 moof.tracks[0].runs[0].sample_sizes.clear();
559 ASSERT_TRUE(iter_->Init(moof)); 557 ASSERT_TRUE(iter_->Init(moof));
560 iter_->AdvanceSample(); 558 iter_->AdvanceSample();
561 EXPECT_FALSE(iter_->is_keyframe()); 559 EXPECT_FALSE(iter_->is_keyframe());
562 EXPECT_EQ(iter_->sample_size(), 3); 560 EXPECT_EQ(iter_->sample_size(), 3);
563 EXPECT_EQ(iter_->sample_offset(), moof.tracks[0].runs[0].data_offset + 3); 561 EXPECT_EQ(iter_->sample_offset(), moof.tracks[0].runs[0].data_offset + 3);
564 EXPECT_EQ(iter_->duration(), TimeDeltaFromRational(50, kAudioScale)); 562 EXPECT_EQ(iter_->duration(), TimeDeltaFromRational(50, kAudioScale));
565 EXPECT_EQ(iter_->dts(), DecodeTimestampFromRational(50, kAudioScale)); 563 EXPECT_EQ(iter_->dts(), DecodeTimestampFromRational(50, kAudioScale));
566 } 564 }
567 565
568 TEST_F(TrackRunIteratorTest, FirstSampleFlagTest) { 566 TEST_F(TrackRunIteratorTest, FirstSampleFlagTest) {
569 // Ensure that keyframes are flagged correctly in the face of BMFF boxes which 567 // Ensure that keyframes are flagged correctly in the face of BMFF boxes which
570 // explicitly specify the flags for the first sample in a run and rely on 568 // explicitly specify the flags for the first sample in a run and rely on
571 // defaults for all subsequent samples 569 // defaults for all subsequent samples
572 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 570 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
573 MovieFragment moof = CreateFragment(); 571 MovieFragment moof = CreateFragment();
574 moof.tracks[1].header.has_default_sample_flags = true; 572 moof.tracks[1].header.has_default_sample_flags = true;
575 moof.tracks[1].header.default_sample_flags = ToSampleFlags("UN"); 573 moof.tracks[1].header.default_sample_flags = ToSampleFlags("UN");
576 SetFlagsOnSamples("US", &moof.tracks[1].runs[0]); 574 SetFlagsOnSamples("US", &moof.tracks[1].runs[0]);
577 575
578 ASSERT_TRUE(iter_->Init(moof)); 576 ASSERT_TRUE(iter_->Init(moof));
579 EXPECT_EQ("1 K K K K K K K K K K", KeyframeAndRAPInfo(iter_.get())); 577 EXPECT_EQ("1 K K K K K K K K K K", KeyframeAndRAPInfo(iter_.get()));
580 578
581 iter_->AdvanceRun(); 579 iter_->AdvanceRun();
582 EXPECT_EQ("2 K P P P P P P P P P", KeyframeAndRAPInfo(iter_.get())); 580 EXPECT_EQ("2 K P P P P P P P P P", KeyframeAndRAPInfo(iter_.get()));
583 } 581 }
584 582
585 // Verify that parsing fails if a reserved value is in the sample flags. 583 // Verify that parsing fails if a reserved value is in the sample flags.
586 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInSampleFlags) { 584 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInSampleFlags) {
587 EXPECT_MEDIA_LOG(ReservedValueInSampleDependencyInfo()); 585 EXPECT_MEDIA_LOG(ReservedValueInSampleDependencyInfo());
588 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 586 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
589 MovieFragment moof = CreateFragment(); 587 MovieFragment moof = CreateFragment();
590 // Change the "depends on" field on one of the samples to a 588 // Change the "depends on" field on one of the samples to a
591 // reserved value. 589 // reserved value.
592 moof.tracks[1].runs[0].sample_flags[0] = ToSampleFlags("RS"); 590 moof.tracks[1].runs[0].sample_flags[0] = ToSampleFlags("RS");
593 ASSERT_FALSE(iter_->Init(moof)); 591 ASSERT_FALSE(iter_->Init(moof));
594 } 592 }
595 593
596 // Verify that parsing fails if a reserved value is in the default sample flags. 594 // Verify that parsing fails if a reserved value is in the default sample flags.
597 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInDefaultSampleFlags) { 595 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInDefaultSampleFlags) {
598 EXPECT_MEDIA_LOG(ReservedValueInSampleDependencyInfo()); 596 EXPECT_MEDIA_LOG(ReservedValueInSampleDependencyInfo());
599 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 597 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
600 MovieFragment moof = CreateFragment(); 598 MovieFragment moof = CreateFragment();
601 // Set the default flag to contain a reserved "depends on" value. 599 // Set the default flag to contain a reserved "depends on" value.
602 moof.tracks[0].header.default_sample_flags = ToSampleFlags("RN"); 600 moof.tracks[0].header.default_sample_flags = ToSampleFlags("RN");
603 ASSERT_FALSE(iter_->Init(moof)); 601 ASSERT_FALSE(iter_->Init(moof));
604 } 602 }
605 603
606 TEST_F(TrackRunIteratorTest, ReorderingTest) { 604 TEST_F(TrackRunIteratorTest, ReorderingTest) {
607 // Test frame reordering and edit list support. The frames have the following 605 // Test frame reordering and edit list support. The frames have the following
608 // decode timestamps: 606 // decode timestamps:
609 // 607 //
610 // 0ms 40ms 120ms 240ms 608 // 0ms 40ms 120ms 240ms
611 // | 0 | 1 - | 2 - - | 609 // | 0 | 1 - | 2 - - |
612 // 610 //
613 // ...and these composition timestamps, after edit list adjustment: 611 // ...and these composition timestamps, after edit list adjustment:
614 // 612 //
615 // 0ms 40ms 160ms 240ms 613 // 0ms 40ms 160ms 240ms
616 // | 0 | 2 - - | 1 - | 614 // | 0 | 2 - - | 1 - |
617 615
618 // Create an edit list with one entry, with an initial start time of 80ms 616 // Create an edit list with one entry, with an initial start time of 80ms
619 // (that is, 2 / kVideoTimescale) and a duration of zero (which is treated as 617 // (that is, 2 / kVideoTimescale) and a duration of zero (which is treated as
620 // infinite according to 14496-12:2012). This will cause the first 80ms of the 618 // infinite according to 14496-12:2012). This will cause the first 80ms of the
621 // media timeline - which will be empty, due to CTS biasing - to be discarded. 619 // media timeline - which will be empty, due to CTS biasing - to be discarded.
622 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 620 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
623 EditListEntry entry; 621 EditListEntry entry;
624 entry.segment_duration = 0; 622 entry.segment_duration = 0;
625 entry.media_time = 2; 623 entry.media_time = 2;
626 entry.media_rate_integer = 1; 624 entry.media_rate_integer = 1;
627 entry.media_rate_fraction = 0; 625 entry.media_rate_fraction = 0;
628 moov_.tracks[1].edit.list.edits.push_back(entry); 626 moov_.tracks[1].edit.list.edits.push_back(entry);
629 627
630 // Add CTS offsets. Without bias, the CTS offsets for the first three frames 628 // Add CTS offsets. Without bias, the CTS offsets for the first three frames
631 // would simply be [0, 3, -2]. Since CTS offsets should be non-negative for 629 // would simply be [0, 3, -2]. Since CTS offsets should be non-negative for
632 // maximum compatibility, these values are biased up to [2, 5, 0], and the 630 // maximum compatibility, these values are biased up to [2, 5, 0], and the
(...skipping 16 matching lines...) Expand all
649 EXPECT_EQ(iter_->dts(), DecodeTimestampFromRational(1, kVideoScale)); 647 EXPECT_EQ(iter_->dts(), DecodeTimestampFromRational(1, kVideoScale));
650 EXPECT_EQ(iter_->cts(), TimeDeltaFromRational(4, kVideoScale)); 648 EXPECT_EQ(iter_->cts(), TimeDeltaFromRational(4, kVideoScale));
651 EXPECT_EQ(iter_->duration(), TimeDeltaFromRational(2, kVideoScale)); 649 EXPECT_EQ(iter_->duration(), TimeDeltaFromRational(2, kVideoScale));
652 iter_->AdvanceSample(); 650 iter_->AdvanceSample();
653 EXPECT_EQ(iter_->dts(), DecodeTimestampFromRational(3, kVideoScale)); 651 EXPECT_EQ(iter_->dts(), DecodeTimestampFromRational(3, kVideoScale));
654 EXPECT_EQ(iter_->cts(), TimeDeltaFromRational(1, kVideoScale)); 652 EXPECT_EQ(iter_->cts(), TimeDeltaFromRational(1, kVideoScale));
655 EXPECT_EQ(iter_->duration(), TimeDeltaFromRational(3, kVideoScale)); 653 EXPECT_EQ(iter_->duration(), TimeDeltaFromRational(3, kVideoScale));
656 } 654 }
657 655
658 TEST_F(TrackRunIteratorTest, IgnoreUnknownAuxInfoTest) { 656 TEST_F(TrackRunIteratorTest, IgnoreUnknownAuxInfoTest) {
659 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 657 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
660 MovieFragment moof = CreateFragment(); 658 MovieFragment moof = CreateFragment();
661 moof.tracks[1].auxiliary_offset.offsets.push_back(50); 659 moof.tracks[1].auxiliary_offset.offsets.push_back(50);
662 moof.tracks[1].auxiliary_size.default_sample_info_size = 2; 660 moof.tracks[1].auxiliary_size.default_sample_info_size = 2;
663 moof.tracks[1].auxiliary_size.sample_count = 2; 661 moof.tracks[1].auxiliary_size.sample_count = 2;
664 moof.tracks[1].runs[0].sample_count = 2; 662 moof.tracks[1].runs[0].sample_count = 2;
665 ASSERT_TRUE(iter_->Init(moof)); 663 ASSERT_TRUE(iter_->Init(moof));
666 iter_->AdvanceRun(); 664 iter_->AdvanceRun();
667 EXPECT_FALSE(iter_->AuxInfoNeedsToBeCached()); 665 EXPECT_FALSE(iter_->AuxInfoNeedsToBeCached());
668 } 666 }
669 667
670 TEST_F(TrackRunIteratorTest, 668 TEST_F(TrackRunIteratorTest,
671 DecryptConfigTestWithSampleEncryptionAndNoSubsample) { 669 DecryptConfigTestWithSampleEncryptionAndNoSubsample) {
672 AddEncryption(&moov_.tracks[1]); 670 AddEncryption(&moov_.tracks[1]);
673 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 671 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
674 672
675 MovieFragment moof = CreateFragment(); 673 MovieFragment moof = CreateFragment();
676 AddSampleEncryption(!SampleEncryption::kUseSubsampleEncryption, 674 AddSampleEncryption(!SampleEncryption::kUseSubsampleEncryption,
677 &moof.tracks[1]); 675 &moof.tracks[1]);
678 676
679 ASSERT_TRUE(iter_->Init(moof)); 677 ASSERT_TRUE(iter_->Init(moof));
680 // The run for track 2 will be the second, which is parsed according to 678 // The run for track 2 will be the second, which is parsed according to
681 // data_offset. 679 // data_offset.
682 iter_->AdvanceRun(); 680 iter_->AdvanceRun();
683 EXPECT_EQ(iter_->track_id(), 2u); 681 EXPECT_EQ(iter_->track_id(), 2u);
(...skipping 14 matching lines...) Expand all
698 iter_->AdvanceSample(); 696 iter_->AdvanceSample();
699 config = iter_->GetDecryptConfig(); 697 config = iter_->GetDecryptConfig();
700 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv2), arraysize(kIv2)), 698 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv2), arraysize(kIv2)),
701 config->iv()); 699 config->iv());
702 EXPECT_EQ(config->subsamples().size(), 0u); 700 EXPECT_EQ(config->subsamples().size(), 0u);
703 } 701 }
704 702
705 TEST_F(TrackRunIteratorTest, 703 TEST_F(TrackRunIteratorTest,
706 DecryptConfigTestWithSampleEncryptionAndSubsample) { 704 DecryptConfigTestWithSampleEncryptionAndSubsample) {
707 AddEncryption(&moov_.tracks[1]); 705 AddEncryption(&moov_.tracks[1]);
708 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 706 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
709 707
710 MovieFragment moof = CreateFragment(); 708 MovieFragment moof = CreateFragment();
711 AddSampleEncryption(SampleEncryption::kUseSubsampleEncryption, 709 AddSampleEncryption(SampleEncryption::kUseSubsampleEncryption,
712 &moof.tracks[1]); 710 &moof.tracks[1]);
713 const SampleToGroupEntry kSampleToGroupTable[] = { 711 const SampleToGroupEntry kSampleToGroupTable[] = {
714 // Associated with the second entry in SampleGroupDescription Box. 712 // Associated with the second entry in SampleGroupDescription Box.
715 // With Iv size 8 bytes. 713 // With Iv size 8 bytes.
716 {1, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 2}, 714 {1, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 2},
717 // Associated with the third entry in SampleGroupDescription Box. 715 // Associated with the third entry in SampleGroupDescription Box.
718 // With Iv size 16 bytes. 716 // With Iv size 16 bytes.
(...skipping 25 matching lines...) Expand all
744 config->iv()); 742 config->iv());
745 EXPECT_EQ(config->subsamples().size(), 2u); 743 EXPECT_EQ(config->subsamples().size(), 2u);
746 EXPECT_EQ(config->subsamples()[0].clear_bytes, 1u); 744 EXPECT_EQ(config->subsamples()[0].clear_bytes, 1u);
747 EXPECT_EQ(config->subsamples()[0].cypher_bytes, 2u); 745 EXPECT_EQ(config->subsamples()[0].cypher_bytes, 2u);
748 EXPECT_EQ(config->subsamples()[1].clear_bytes, 3u); 746 EXPECT_EQ(config->subsamples()[1].clear_bytes, 3u);
749 EXPECT_EQ(config->subsamples()[1].cypher_bytes, 4u); 747 EXPECT_EQ(config->subsamples()[1].cypher_bytes, 4u);
750 } 748 }
751 749
752 TEST_F(TrackRunIteratorTest, DecryptConfigTestWithAuxInfo) { 750 TEST_F(TrackRunIteratorTest, DecryptConfigTestWithAuxInfo) {
753 AddEncryption(&moov_.tracks[1]); 751 AddEncryption(&moov_.tracks[1]);
754 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 752 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
755 753
756 MovieFragment moof = CreateFragment(); 754 MovieFragment moof = CreateFragment();
757 AddAuxInfoHeaders(50, &moof.tracks[1]); 755 AddAuxInfoHeaders(50, &moof.tracks[1]);
758 756
759 ASSERT_TRUE(iter_->Init(moof)); 757 ASSERT_TRUE(iter_->Init(moof));
760 758
761 // The run for track 2 will be first, since its aux info offset is the first 759 // The run for track 2 will be first, since its aux info offset is the first
762 // element in the file. 760 // element in the file.
763 EXPECT_EQ(iter_->track_id(), 2u); 761 EXPECT_EQ(iter_->track_id(), 2u);
764 EXPECT_TRUE(iter_->is_encrypted()); 762 EXPECT_TRUE(iter_->is_encrypted());
(...skipping 26 matching lines...) Expand all
791 MovieFragment moof = CreateFragment(); 789 MovieFragment moof = CreateFragment();
792 790
793 const SampleToGroupEntry kSampleToGroupTable[] = { 791 const SampleToGroupEntry kSampleToGroupTable[] = {
794 // Associated with the second entry in SampleGroupDescription Box. 792 // Associated with the second entry in SampleGroupDescription Box.
795 {1, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 2}, 793 {1, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 2},
796 // Associated with the first entry in SampleGroupDescription Box. 794 // Associated with the first entry in SampleGroupDescription Box.
797 {1, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 1}}; 795 {1, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 1}};
798 AddCencSampleGroup(&moov_.tracks[0], &moof.tracks[0], kSampleToGroupTable, 796 AddCencSampleGroup(&moov_.tracks[0], &moof.tracks[0], kSampleToGroupTable,
799 arraysize(kSampleToGroupTable)); 797 arraysize(kSampleToGroupTable));
800 798
801 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 799 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
802 ASSERT_TRUE(InitMoofWithArbitraryAuxInfo(&moof)); 800 ASSERT_TRUE(InitMoofWithArbitraryAuxInfo(&moof));
803 801
804 std::string cenc_sample_group_key_id( 802 std::string cenc_sample_group_key_id(
805 kFragmentCencSampleGroupKeyId, 803 kFragmentCencSampleGroupKeyId,
806 kFragmentCencSampleGroupKeyId + arraysize(kFragmentCencSampleGroupKeyId)); 804 kFragmentCencSampleGroupKeyId + arraysize(kFragmentCencSampleGroupKeyId));
807 // The first sample is encrypted and the second sample is unencrypted. 805 // The first sample is encrypted and the second sample is unencrypted.
808 EXPECT_TRUE(iter_->is_encrypted()); 806 EXPECT_TRUE(iter_->is_encrypted());
809 EXPECT_EQ(cenc_sample_group_key_id, iter_->GetDecryptConfig()->key_id()); 807 EXPECT_EQ(cenc_sample_group_key_id, iter_->GetDecryptConfig()->key_id());
810 iter_->AdvanceSample(); 808 iter_->AdvanceSample();
811 EXPECT_FALSE(iter_->is_encrypted()); 809 EXPECT_FALSE(iter_->is_encrypted());
(...skipping 10 matching lines...) Expand all
822 {2, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 2}, 820 {2, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 2},
823 // Associated with the default values specified in TrackEncryption Box. 821 // Associated with the default values specified in TrackEncryption Box.
824 {1, 0}, 822 {1, 0},
825 // Associated with the 1st entry in fragment SampleGroupDescription Box. 823 // Associated with the 1st entry in fragment SampleGroupDescription Box.
826 {3, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 1}, 824 {3, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 1},
827 // Associated with the 1st entry in track SampleGroupDescription Box. 825 // Associated with the 1st entry in track SampleGroupDescription Box.
828 {2, 1}}; 826 {2, 1}};
829 AddCencSampleGroup(&moov_.tracks[0], &moof.tracks[0], kSampleToGroupTable, 827 AddCencSampleGroup(&moov_.tracks[0], &moof.tracks[0], kSampleToGroupTable,
830 arraysize(kSampleToGroupTable)); 828 arraysize(kSampleToGroupTable));
831 829
832 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 830 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
833 ASSERT_TRUE(InitMoofWithArbitraryAuxInfo(&moof)); 831 ASSERT_TRUE(InitMoofWithArbitraryAuxInfo(&moof));
834 832
835 std::string track_encryption_key_id(kKeyId, kKeyId + arraysize(kKeyId)); 833 std::string track_encryption_key_id(kKeyId, kKeyId + arraysize(kKeyId));
836 std::string track_cenc_sample_group_key_id( 834 std::string track_cenc_sample_group_key_id(
837 kTrackCencSampleGroupKeyId, 835 kTrackCencSampleGroupKeyId,
838 kTrackCencSampleGroupKeyId + arraysize(kTrackCencSampleGroupKeyId)); 836 kTrackCencSampleGroupKeyId + arraysize(kTrackCencSampleGroupKeyId));
839 std::string fragment_cenc_sample_group_key_id( 837 std::string fragment_cenc_sample_group_key_id(
840 kFragmentCencSampleGroupKeyId, 838 kFragmentCencSampleGroupKeyId,
841 kFragmentCencSampleGroupKeyId + arraysize(kFragmentCencSampleGroupKeyId)); 839 kFragmentCencSampleGroupKeyId + arraysize(kFragmentCencSampleGroupKeyId));
842 840
(...skipping 25 matching lines...) Expand all
868 // The remaining samples should be associated with the default values 866 // The remaining samples should be associated with the default values
869 // specified in TrackEncryption Box. 867 // specified in TrackEncryption Box.
870 EXPECT_TRUE(iter_->is_encrypted()); 868 EXPECT_TRUE(iter_->is_encrypted());
871 EXPECT_EQ(track_encryption_key_id, iter_->GetDecryptConfig()->key_id()); 869 EXPECT_EQ(track_encryption_key_id, iter_->GetDecryptConfig()->key_id());
872 } 870 }
873 871
874 // It is legal for aux info blocks to be shared among multiple formats. 872 // It is legal for aux info blocks to be shared among multiple formats.
875 TEST_F(TrackRunIteratorTest, SharedAuxInfoTest) { 873 TEST_F(TrackRunIteratorTest, SharedAuxInfoTest) {
876 AddEncryption(&moov_.tracks[0]); 874 AddEncryption(&moov_.tracks[0]);
877 AddEncryption(&moov_.tracks[1]); 875 AddEncryption(&moov_.tracks[1]);
878 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 876 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
879 877
880 MovieFragment moof = CreateFragment(); 878 MovieFragment moof = CreateFragment();
881 moof.tracks[0].runs.resize(1); 879 moof.tracks[0].runs.resize(1);
882 AddAuxInfoHeaders(50, &moof.tracks[0]); 880 AddAuxInfoHeaders(50, &moof.tracks[0]);
883 AddAuxInfoHeaders(50, &moof.tracks[1]); 881 AddAuxInfoHeaders(50, &moof.tracks[1]);
884 moof.tracks[0].auxiliary_size.default_sample_info_size = 8; 882 moof.tracks[0].auxiliary_size.default_sample_info_size = 8;
885 883
886 ASSERT_TRUE(iter_->Init(moof)); 884 ASSERT_TRUE(iter_->Init(moof));
887 EXPECT_EQ(iter_->track_id(), 1u); 885 EXPECT_EQ(iter_->track_id(), 1u);
888 EXPECT_EQ(iter_->aux_info_offset(), 50); 886 EXPECT_EQ(iter_->aux_info_offset(), 50);
(...skipping 21 matching lines...) Expand all
910 // unreasonable behavior demonstrated here: 908 // unreasonable behavior demonstrated here:
911 // byte 50: track 2, run 1 aux info 909 // byte 50: track 2, run 1 aux info
912 // byte 100: track 1, run 1 data 910 // byte 100: track 1, run 1 data
913 // byte 200: track 2, run 1 data 911 // byte 200: track 2, run 1 data
914 // byte 201: track 1, run 2 aux info (*inside* track 2, run 1 data) 912 // byte 201: track 1, run 2 aux info (*inside* track 2, run 1 data)
915 // byte 10000: track 1, run 2 data 913 // byte 10000: track 1, run 2 data
916 // byte 20000: track 1, run 1 aux info 914 // byte 20000: track 1, run 1 aux info
917 TEST_F(TrackRunIteratorTest, UnexpectedOrderingTest) { 915 TEST_F(TrackRunIteratorTest, UnexpectedOrderingTest) {
918 AddEncryption(&moov_.tracks[0]); 916 AddEncryption(&moov_.tracks[0]);
919 AddEncryption(&moov_.tracks[1]); 917 AddEncryption(&moov_.tracks[1]);
920 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 918 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
921 919
922 MovieFragment moof = CreateFragment(); 920 MovieFragment moof = CreateFragment();
923 AddAuxInfoHeaders(20000, &moof.tracks[0]); 921 AddAuxInfoHeaders(20000, &moof.tracks[0]);
924 moof.tracks[0].auxiliary_offset.offsets.push_back(201); 922 moof.tracks[0].auxiliary_offset.offsets.push_back(201);
925 moof.tracks[0].auxiliary_size.sample_count += 2; 923 moof.tracks[0].auxiliary_size.sample_count += 2;
926 moof.tracks[0].auxiliary_size.default_sample_info_size = 8; 924 moof.tracks[0].auxiliary_size.default_sample_info_size = 8;
927 moof.tracks[0].runs[1].sample_count = 2; 925 moof.tracks[0].runs[1].sample_count = 2;
928 AddAuxInfoHeaders(50, &moof.tracks[1]); 926 AddAuxInfoHeaders(50, &moof.tracks[1]);
929 moof.tracks[1].runs[0].sample_sizes[0] = 5; 927 moof.tracks[1].runs[0].sample_sizes[0] = 5;
930 928
(...skipping 23 matching lines...) Expand all
954 TEST_F(TrackRunIteratorTest, KeyFrameFlagCombinations) { 952 TEST_F(TrackRunIteratorTest, KeyFrameFlagCombinations) {
955 // Setup both audio and video tracks to each have 6 samples covering all the 953 // Setup both audio and video tracks to each have 6 samples covering all the
956 // combinations of mp4 "sync sample" and "depends on" relationships. 954 // combinations of mp4 "sync sample" and "depends on" relationships.
957 MovieFragment moof = CreateFragment(); 955 MovieFragment moof = CreateFragment();
958 moof.tracks[0].runs.resize(1); 956 moof.tracks[0].runs.resize(1);
959 moof.tracks[1].runs.resize(1); 957 moof.tracks[1].runs.resize(1);
960 moof.tracks[0].runs[0].sample_count = 6; 958 moof.tracks[0].runs[0].sample_count = 6;
961 moof.tracks[1].runs[0].sample_count = 6; 959 moof.tracks[1].runs[0].sample_count = 6;
962 SetFlagsOnSamples("US UN OS ON NS NN", &moof.tracks[0].runs[0]); 960 SetFlagsOnSamples("US UN OS ON NS NN", &moof.tracks[0].runs[0]);
963 SetFlagsOnSamples("US UN OS ON NS NN", &moof.tracks[1].runs[0]); 961 SetFlagsOnSamples("US UN OS ON NS NN", &moof.tracks[1].runs[0]);
964 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 962 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
965 963
966 ASSERT_TRUE(iter_->Init(moof)); 964 ASSERT_TRUE(iter_->Init(moof));
967 EXPECT_TRUE(iter_->IsRunValid()); 965 EXPECT_TRUE(iter_->IsRunValid());
968 966
969 // Keyframes should be marked according to downstream's expectations that 967 // Keyframes should be marked according to downstream's expectations that
970 // keyframes serve as points of random access for seeking. 968 // keyframes serve as points of random access for seeking.
971 969
972 // For audio, any sync sample should be marked as a key frame. Whether a 970 // For audio, any sync sample should be marked as a key frame. Whether a
973 // sample "depends on" other samples is not considered. Unlike video samples, 971 // sample "depends on" other samples is not considered. Unlike video samples,
974 // audio samples are often marked as depending on other samples but are still 972 // audio samples are often marked as depending on other samples but are still
(...skipping 10 matching lines...) Expand all
985 // marked "sync" and we must rely on combining the two flags to pick out the 983 // marked "sync" and we must rely on combining the two flags to pick out the
986 // true key frames. See http://crbug.com/310712 and http://crbug.com/507916. 984 // true key frames. See http://crbug.com/310712 and http://crbug.com/507916.
987 // Realiably knowing the keyframes for video is also critical to SPS PPS 985 // Realiably knowing the keyframes for video is also critical to SPS PPS
988 // insertion. 986 // insertion.
989 EXPECT_EQ("2 K P P P K P", KeyframeAndRAPInfo(iter_.get())); 987 EXPECT_EQ("2 K P P P K P", KeyframeAndRAPInfo(iter_.get()));
990 } 988 }
991 989
992 #if BUILDFLAG(ENABLE_CBCS_ENCRYPTION_SCHEME) 990 #if BUILDFLAG(ENABLE_CBCS_ENCRYPTION_SCHEME)
993 TEST_F(TrackRunIteratorTest, DecryptConfigTestWithConstantIvNoAuxInfo) { 991 TEST_F(TrackRunIteratorTest, DecryptConfigTestWithConstantIvNoAuxInfo) {
994 AddEncryptionCbcs(&moov_.tracks[1]); 992 AddEncryptionCbcs(&moov_.tracks[1]);
995 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 993 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
996 994
997 MovieFragment moof = CreateFragment(); 995 MovieFragment moof = CreateFragment();
998 996
999 ASSERT_TRUE(iter_->Init(moof)); 997 ASSERT_TRUE(iter_->Init(moof));
1000 998
1001 // The run for track 2 will be the second. 999 // The run for track 2 will be the second.
1002 iter_->AdvanceRun(); 1000 iter_->AdvanceRun();
1003 EXPECT_EQ(iter_->track_id(), 2u); 1001 EXPECT_EQ(iter_->track_id(), 2u);
1004 EXPECT_TRUE(iter_->is_encrypted()); 1002 EXPECT_TRUE(iter_->is_encrypted());
1005 ASSERT_FALSE(iter_->AuxInfoNeedsToBeCached()); 1003 ASSERT_FALSE(iter_->AuxInfoNeedsToBeCached());
(...skipping 27 matching lines...) Expand all
1033 {1, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 2}, 1031 {1, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 2},
1034 // Associated with the default values specified in TrackEncryption Box. 1032 // Associated with the default values specified in TrackEncryption Box.
1035 {1, 0}, 1033 {1, 0},
1036 // Associated with the 1st entry in fragment SampleGroupDescription Box. 1034 // Associated with the 1st entry in fragment SampleGroupDescription Box.
1037 {1, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 1}, 1035 {1, SampleToGroupEntry::kFragmentGroupDescriptionIndexBase + 1},
1038 // Associated with the 1st entry in track SampleGroupDescription Box. 1036 // Associated with the 1st entry in track SampleGroupDescription Box.
1039 {1, 1}}; 1037 {1, 1}};
1040 AddCencSampleGroup(&moov_.tracks[1], &moof.tracks[1], kSampleToGroupTable, 1038 AddCencSampleGroup(&moov_.tracks[1], &moof.tracks[1], kSampleToGroupTable,
1041 arraysize(kSampleToGroupTable)); 1039 arraysize(kSampleToGroupTable));
1042 AddConstantIvsToCencSampleGroup(&moov_.tracks[1], &moof.tracks[1]); 1040 AddConstantIvsToCencSampleGroup(&moov_.tracks[1], &moof.tracks[1]);
1043 iter_.reset(new TrackRunIterator(&moov_, media_log_)); 1041 iter_.reset(new TrackRunIterator(&moov_, &media_log_));
1044 ASSERT_TRUE(iter_->Init(moof)); 1042 ASSERT_TRUE(iter_->Init(moof));
1045 1043
1046 // The run for track 2 will be the second. 1044 // The run for track 2 will be the second.
1047 iter_->AdvanceRun(); 1045 iter_->AdvanceRun();
1048 1046
1049 std::string track_encryption_iv(kIv3, kIv3 + arraysize(kIv3)); 1047 std::string track_encryption_iv(kIv3, kIv3 + arraysize(kIv3));
1050 std::string track_cenc_sample_group_iv(kIv4, kIv4 + arraysize(kIv4)); 1048 std::string track_cenc_sample_group_iv(kIv4, kIv4 + arraysize(kIv4));
1051 std::string fragment_cenc_sample_group_iv(kIv5, kIv5 + arraysize(kIv5)); 1049 std::string fragment_cenc_sample_group_iv(kIv5, kIv5 + arraysize(kIv5));
1052 1050
1053 for (size_t i = 0; i < kSampleToGroupTable[0].sample_count; ++i) { 1051 for (size_t i = 0; i < kSampleToGroupTable[0].sample_count; ++i) {
(...skipping 22 matching lines...) Expand all
1076 // The remaining samples should be associated with the default values 1074 // The remaining samples should be associated with the default values
1077 // specified in TrackEncryption Box. 1075 // specified in TrackEncryption Box.
1078 EXPECT_TRUE(iter_->is_encrypted()); 1076 EXPECT_TRUE(iter_->is_encrypted());
1079 EXPECT_EQ(track_encryption_iv, iter_->GetDecryptConfig()->iv()); 1077 EXPECT_EQ(track_encryption_iv, iter_->GetDecryptConfig()->iv());
1080 } 1078 }
1081 1079
1082 #endif 1080 #endif
1083 1081
1084 } // namespace mp4 1082 } // namespace mp4
1085 } // namespace media 1083 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698