| OLD | NEW |
| 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" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 #include <stdint.h> | 8 #include <stdint.h> |
| 7 | 9 |
| 10 #include <memory> |
| 11 |
| 8 #include "base/logging.h" | 12 #include "base/logging.h" |
| 9 #include "base/macros.h" | 13 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 12 #include "media/base/mock_media_log.h" | 15 #include "media/base/mock_media_log.h" |
| 13 #include "media/formats/mp4/box_definitions.h" | 16 #include "media/formats/mp4/box_definitions.h" |
| 14 #include "media/formats/mp4/rcheck.h" | 17 #include "media/formats/mp4/rcheck.h" |
| 15 #include "media/formats/mp4/track_run_iterator.h" | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 20 |
| 19 using ::testing::StrictMock; | 21 using ::testing::StrictMock; |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // The sum of the elements in a vector initialized with SumAscending, | 25 // The sum of the elements in a vector initialized with SumAscending, |
| 24 // less the value of the last element. | 26 // less the value of the last element. |
| 25 const int kSumAscending1 = 45; | 27 const int kSumAscending1 = 45; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 108 |
| 107 class TrackRunIteratorTest : public testing::Test { | 109 class TrackRunIteratorTest : public testing::Test { |
| 108 public: | 110 public: |
| 109 TrackRunIteratorTest() : media_log_(new StrictMock<MockMediaLog>()) { | 111 TrackRunIteratorTest() : media_log_(new StrictMock<MockMediaLog>()) { |
| 110 CreateMovie(); | 112 CreateMovie(); |
| 111 } | 113 } |
| 112 | 114 |
| 113 protected: | 115 protected: |
| 114 Movie moov_; | 116 Movie moov_; |
| 115 scoped_refptr<StrictMock<MockMediaLog>> media_log_; | 117 scoped_refptr<StrictMock<MockMediaLog>> media_log_; |
| 116 scoped_ptr<TrackRunIterator> iter_; | 118 std::unique_ptr<TrackRunIterator> iter_; |
| 117 | 119 |
| 118 void CreateMovie() { | 120 void CreateMovie() { |
| 119 moov_.header.timescale = 1000; | 121 moov_.header.timescale = 1000; |
| 120 moov_.tracks.resize(3); | 122 moov_.tracks.resize(3); |
| 121 moov_.extends.tracks.resize(2); | 123 moov_.extends.tracks.resize(2); |
| 122 moov_.tracks[0].header.track_id = 1; | 124 moov_.tracks[0].header.track_id = 1; |
| 123 moov_.tracks[0].media.header.timescale = kAudioScale; | 125 moov_.tracks[0].media.header.timescale = kAudioScale; |
| 124 SampleDescription& desc1 = | 126 SampleDescription& desc1 = |
| 125 moov_.tracks[0].media.information.sample_table.description; | 127 moov_.tracks[0].media.information.sample_table.description; |
| 126 AudioSampleEntry aud_desc; | 128 AudioSampleEntry aud_desc; |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 // data_offset. | 571 // data_offset. |
| 570 iter_->AdvanceRun(); | 572 iter_->AdvanceRun(); |
| 571 EXPECT_EQ(iter_->track_id(), 2u); | 573 EXPECT_EQ(iter_->track_id(), 2u); |
| 572 | 574 |
| 573 EXPECT_TRUE(iter_->is_encrypted()); | 575 EXPECT_TRUE(iter_->is_encrypted()); |
| 574 // No need to cache aux info as it is already available in SampleEncryption. | 576 // No need to cache aux info as it is already available in SampleEncryption. |
| 575 EXPECT_FALSE(iter_->AuxInfoNeedsToBeCached()); | 577 EXPECT_FALSE(iter_->AuxInfoNeedsToBeCached()); |
| 576 EXPECT_EQ(iter_->aux_info_size(), 0); | 578 EXPECT_EQ(iter_->aux_info_size(), 0); |
| 577 EXPECT_EQ(iter_->sample_offset(), 200); | 579 EXPECT_EQ(iter_->sample_offset(), 200); |
| 578 EXPECT_EQ(iter_->GetMaxClearOffset(), moof.tracks[1].runs[0].data_offset); | 580 EXPECT_EQ(iter_->GetMaxClearOffset(), moof.tracks[1].runs[0].data_offset); |
| 579 scoped_ptr<DecryptConfig> config = iter_->GetDecryptConfig(); | 581 std::unique_ptr<DecryptConfig> config = iter_->GetDecryptConfig(); |
| 580 EXPECT_EQ( | 582 EXPECT_EQ( |
| 581 std::string(reinterpret_cast<const char*>(kKeyId), arraysize(kKeyId)), | 583 std::string(reinterpret_cast<const char*>(kKeyId), arraysize(kKeyId)), |
| 582 config->key_id()); | 584 config->key_id()); |
| 583 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv1), arraysize(kIv1)), | 585 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv1), arraysize(kIv1)), |
| 584 config->iv()); | 586 config->iv()); |
| 585 EXPECT_EQ(config->subsamples().size(), 0u); | 587 EXPECT_EQ(config->subsamples().size(), 0u); |
| 586 iter_->AdvanceSample(); | 588 iter_->AdvanceSample(); |
| 587 config = iter_->GetDecryptConfig(); | 589 config = iter_->GetDecryptConfig(); |
| 588 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv2), arraysize(kIv2)), | 590 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv2), arraysize(kIv2)), |
| 589 config->iv()); | 591 config->iv()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 613 // data_offset. | 615 // data_offset. |
| 614 iter_->AdvanceRun(); | 616 iter_->AdvanceRun(); |
| 615 EXPECT_EQ(iter_->track_id(), 2u); | 617 EXPECT_EQ(iter_->track_id(), 2u); |
| 616 | 618 |
| 617 EXPECT_TRUE(iter_->is_encrypted()); | 619 EXPECT_TRUE(iter_->is_encrypted()); |
| 618 // No need to cache aux info as it is already available in SampleEncryption. | 620 // No need to cache aux info as it is already available in SampleEncryption. |
| 619 EXPECT_FALSE(iter_->AuxInfoNeedsToBeCached()); | 621 EXPECT_FALSE(iter_->AuxInfoNeedsToBeCached()); |
| 620 EXPECT_EQ(iter_->aux_info_size(), 0); | 622 EXPECT_EQ(iter_->aux_info_size(), 0); |
| 621 EXPECT_EQ(iter_->sample_offset(), 200); | 623 EXPECT_EQ(iter_->sample_offset(), 200); |
| 622 EXPECT_EQ(iter_->GetMaxClearOffset(), moof.tracks[1].runs[0].data_offset); | 624 EXPECT_EQ(iter_->GetMaxClearOffset(), moof.tracks[1].runs[0].data_offset); |
| 623 scoped_ptr<DecryptConfig> config = iter_->GetDecryptConfig(); | 625 std::unique_ptr<DecryptConfig> config = iter_->GetDecryptConfig(); |
| 624 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv1), arraysize(kIv1)), | 626 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv1), arraysize(kIv1)), |
| 625 config->iv()); | 627 config->iv()); |
| 626 EXPECT_EQ(config->subsamples().size(), 1u); | 628 EXPECT_EQ(config->subsamples().size(), 1u); |
| 627 EXPECT_EQ(config->subsamples()[0].clear_bytes, 1u); | 629 EXPECT_EQ(config->subsamples()[0].clear_bytes, 1u); |
| 628 EXPECT_EQ(config->subsamples()[0].cypher_bytes, 2u); | 630 EXPECT_EQ(config->subsamples()[0].cypher_bytes, 2u); |
| 629 iter_->AdvanceSample(); | 631 iter_->AdvanceSample(); |
| 630 config = iter_->GetDecryptConfig(); | 632 config = iter_->GetDecryptConfig(); |
| 631 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv3), arraysize(kIv3)), | 633 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv3), arraysize(kIv3)), |
| 632 config->iv()); | 634 config->iv()); |
| 633 EXPECT_EQ(config->subsamples().size(), 2u); | 635 EXPECT_EQ(config->subsamples().size(), 2u); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 654 EXPECT_EQ(static_cast<uint32_t>(iter_->aux_info_size()), arraysize(kAuxInfo)); | 656 EXPECT_EQ(static_cast<uint32_t>(iter_->aux_info_size()), arraysize(kAuxInfo)); |
| 655 EXPECT_EQ(iter_->aux_info_offset(), 50); | 657 EXPECT_EQ(iter_->aux_info_offset(), 50); |
| 656 EXPECT_EQ(iter_->GetMaxClearOffset(), 50); | 658 EXPECT_EQ(iter_->GetMaxClearOffset(), 50); |
| 657 EXPECT_FALSE(iter_->CacheAuxInfo(NULL, 0)); | 659 EXPECT_FALSE(iter_->CacheAuxInfo(NULL, 0)); |
| 658 EXPECT_FALSE(iter_->CacheAuxInfo(kAuxInfo, 3)); | 660 EXPECT_FALSE(iter_->CacheAuxInfo(kAuxInfo, 3)); |
| 659 EXPECT_TRUE(iter_->AuxInfoNeedsToBeCached()); | 661 EXPECT_TRUE(iter_->AuxInfoNeedsToBeCached()); |
| 660 EXPECT_TRUE(iter_->CacheAuxInfo(kAuxInfo, arraysize(kAuxInfo))); | 662 EXPECT_TRUE(iter_->CacheAuxInfo(kAuxInfo, arraysize(kAuxInfo))); |
| 661 EXPECT_FALSE(iter_->AuxInfoNeedsToBeCached()); | 663 EXPECT_FALSE(iter_->AuxInfoNeedsToBeCached()); |
| 662 EXPECT_EQ(iter_->sample_offset(), 200); | 664 EXPECT_EQ(iter_->sample_offset(), 200); |
| 663 EXPECT_EQ(iter_->GetMaxClearOffset(), moof.tracks[0].runs[0].data_offset); | 665 EXPECT_EQ(iter_->GetMaxClearOffset(), moof.tracks[0].runs[0].data_offset); |
| 664 scoped_ptr<DecryptConfig> config = iter_->GetDecryptConfig(); | 666 std::unique_ptr<DecryptConfig> config = iter_->GetDecryptConfig(); |
| 665 EXPECT_EQ( | 667 EXPECT_EQ( |
| 666 std::string(reinterpret_cast<const char*>(kKeyId), arraysize(kKeyId)), | 668 std::string(reinterpret_cast<const char*>(kKeyId), arraysize(kKeyId)), |
| 667 config->key_id()); | 669 config->key_id()); |
| 668 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv1), arraysize(kIv1)), | 670 EXPECT_EQ(std::string(reinterpret_cast<const char*>(kIv1), arraysize(kIv1)), |
| 669 config->iv()); | 671 config->iv()); |
| 670 EXPECT_TRUE(config->subsamples().empty()); | 672 EXPECT_TRUE(config->subsamples().empty()); |
| 671 iter_->AdvanceSample(); | 673 iter_->AdvanceSample(); |
| 672 config = iter_->GetDecryptConfig(); | 674 config = iter_->GetDecryptConfig(); |
| 673 EXPECT_EQ(config->subsamples().size(), 2u); | 675 EXPECT_EQ(config->subsamples().size(), 2u); |
| 674 EXPECT_EQ(config->subsamples()[0].clear_bytes, 1u); | 676 EXPECT_EQ(config->subsamples()[0].clear_bytes, 1u); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 MovieFragment moof = CreateFragment(); | 770 MovieFragment moof = CreateFragment(); |
| 769 moof.tracks[0].runs.resize(1); | 771 moof.tracks[0].runs.resize(1); |
| 770 AddAuxInfoHeaders(50, &moof.tracks[0]); | 772 AddAuxInfoHeaders(50, &moof.tracks[0]); |
| 771 AddAuxInfoHeaders(50, &moof.tracks[1]); | 773 AddAuxInfoHeaders(50, &moof.tracks[1]); |
| 772 moof.tracks[0].auxiliary_size.default_sample_info_size = 8; | 774 moof.tracks[0].auxiliary_size.default_sample_info_size = 8; |
| 773 | 775 |
| 774 ASSERT_TRUE(iter_->Init(moof)); | 776 ASSERT_TRUE(iter_->Init(moof)); |
| 775 EXPECT_EQ(iter_->track_id(), 1u); | 777 EXPECT_EQ(iter_->track_id(), 1u); |
| 776 EXPECT_EQ(iter_->aux_info_offset(), 50); | 778 EXPECT_EQ(iter_->aux_info_offset(), 50); |
| 777 EXPECT_TRUE(iter_->CacheAuxInfo(kAuxInfo, arraysize(kAuxInfo))); | 779 EXPECT_TRUE(iter_->CacheAuxInfo(kAuxInfo, arraysize(kAuxInfo))); |
| 778 scoped_ptr<DecryptConfig> config = iter_->GetDecryptConfig(); | 780 std::unique_ptr<DecryptConfig> config = iter_->GetDecryptConfig(); |
| 779 ASSERT_EQ(arraysize(kIv1), config->iv().size()); | 781 ASSERT_EQ(arraysize(kIv1), config->iv().size()); |
| 780 EXPECT_TRUE(!memcmp(kIv1, config->iv().data(), config->iv().size())); | 782 EXPECT_TRUE(!memcmp(kIv1, config->iv().data(), config->iv().size())); |
| 781 iter_->AdvanceSample(); | 783 iter_->AdvanceSample(); |
| 782 EXPECT_EQ(iter_->GetMaxClearOffset(), 50); | 784 EXPECT_EQ(iter_->GetMaxClearOffset(), 50); |
| 783 iter_->AdvanceRun(); | 785 iter_->AdvanceRun(); |
| 784 EXPECT_EQ(iter_->GetMaxClearOffset(), 50); | 786 EXPECT_EQ(iter_->GetMaxClearOffset(), 50); |
| 785 EXPECT_EQ(iter_->aux_info_offset(), 50); | 787 EXPECT_EQ(iter_->aux_info_offset(), 50); |
| 786 EXPECT_TRUE(iter_->CacheAuxInfo(kAuxInfo, arraysize(kAuxInfo))); | 788 EXPECT_TRUE(iter_->CacheAuxInfo(kAuxInfo, arraysize(kAuxInfo))); |
| 787 EXPECT_EQ(iter_->GetMaxClearOffset(), 200); | 789 EXPECT_EQ(iter_->GetMaxClearOffset(), 200); |
| 788 ASSERT_EQ(arraysize(kIv1), config->iv().size()); | 790 ASSERT_EQ(arraysize(kIv1), config->iv().size()); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 // no dependents, but we occasionally encounter media where all samples are | 874 // no dependents, but we occasionally encounter media where all samples are |
| 873 // marked "sync" and we must rely on combining the two flags to pick out the | 875 // marked "sync" and we must rely on combining the two flags to pick out the |
| 874 // true key frames. See http://crbug.com/310712 and http://crbug.com/507916. | 876 // true key frames. See http://crbug.com/310712 and http://crbug.com/507916. |
| 875 // Realiably knowing the keyframes for video is also critical to SPS PPS | 877 // Realiably knowing the keyframes for video is also critical to SPS PPS |
| 876 // insertion. | 878 // insertion. |
| 877 EXPECT_EQ("2 K P P P K P", KeyframeAndRAPInfo(iter_.get())); | 879 EXPECT_EQ("2 K P P P K P", KeyframeAndRAPInfo(iter_.get())); |
| 878 } | 880 } |
| 879 | 881 |
| 880 } // namespace mp4 | 882 } // namespace mp4 |
| 881 } // namespace media | 883 } // namespace media |
| OLD | NEW |