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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "media/base/mock_media_log.h" |
9 #include "media/formats/mp4/box_definitions.h" | 10 #include "media/formats/mp4/box_definitions.h" |
10 #include "media/formats/mp4/rcheck.h" | 11 #include "media/formats/mp4/rcheck.h" |
11 #include "media/formats/mp4/track_run_iterator.h" | 12 #include "media/formats/mp4/track_run_iterator.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
| 16 using ::testing::StrictMock; |
| 17 |
14 // The sum of the elements in a vector initialized with SumAscending, | 18 // The sum of the elements in a vector initialized with SumAscending, |
15 // less the value of the last element. | 19 // less the value of the last element. |
16 static const int kSumAscending1 = 45; | 20 static const int kSumAscending1 = 45; |
17 | 21 |
18 static const int kAudioScale = 48000; | 22 static const int kAudioScale = 48000; |
19 static const int kVideoScale = 25; | 23 static const int kVideoScale = 25; |
20 | 24 |
21 static const uint8 kAuxInfo[] = { | 25 static const uint8 kAuxInfo[] = { |
22 0x41, 0x54, 0x65, 0x73, 0x74, 0x49, 0x76, 0x31, | 26 0x41, 0x54, 0x65, 0x73, 0x74, 0x49, 0x76, 0x31, |
23 0x41, 0x54, 0x65, 0x73, 0x74, 0x49, 0x76, 0x32, | 27 0x41, 0x54, 0x65, 0x73, 0x74, 0x49, 0x76, 0x32, |
(...skipping 18 matching lines...) Expand all Loading... |
42 }; | 46 }; |
43 | 47 |
44 static const uint8 kFragmentCencSampleGroupKeyId[] = { | 48 static const uint8 kFragmentCencSampleGroupKeyId[] = { |
45 0x6b, 0x46, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, | 49 0x6b, 0x46, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, |
46 0x74, 0x43, 0x65, 0x6e, 0x63, 0x53, 0x61, 0x6d | 50 0x74, 0x43, 0x65, 0x6e, 0x63, 0x53, 0x61, 0x6d |
47 }; | 51 }; |
48 | 52 |
49 namespace media { | 53 namespace media { |
50 namespace mp4 { | 54 namespace mp4 { |
51 | 55 |
| 56 MATCHER(ReservedValueInSampleDependencyInfo, "") { |
| 57 return CONTAINS_STRING(arg, "Reserved value used in sample dependency info."); |
| 58 } |
| 59 |
52 class TrackRunIteratorTest : public testing::Test { | 60 class TrackRunIteratorTest : public testing::Test { |
53 public: | 61 public: |
54 TrackRunIteratorTest() : media_log_(new MediaLog()) { CreateMovie(); } | 62 TrackRunIteratorTest() : media_log_(new StrictMock<MockMediaLog>()) { |
| 63 CreateMovie(); |
| 64 } |
55 | 65 |
56 protected: | 66 protected: |
57 Movie moov_; | 67 Movie moov_; |
58 scoped_refptr<MediaLog> media_log_; | 68 scoped_refptr<StrictMock<MockMediaLog>> media_log_; |
59 scoped_ptr<TrackRunIterator> iter_; | 69 scoped_ptr<TrackRunIterator> iter_; |
60 | 70 |
61 void CreateMovie() { | 71 void CreateMovie() { |
62 moov_.header.timescale = 1000; | 72 moov_.header.timescale = 1000; |
63 moov_.tracks.resize(3); | 73 moov_.tracks.resize(3); |
64 moov_.extends.tracks.resize(2); | 74 moov_.extends.tracks.resize(2); |
65 moov_.tracks[0].header.track_id = 1; | 75 moov_.tracks[0].header.track_id = 1; |
66 moov_.tracks[0].media.header.timescale = kAudioScale; | 76 moov_.tracks[0].media.header.timescale = kAudioScale; |
67 SampleDescription& desc1 = | 77 SampleDescription& desc1 = |
68 moov_.tracks[0].media.information.sample_table.description; | 78 moov_.tracks[0].media.information.sample_table.description; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 392 |
383 ASSERT_TRUE(iter_->Init(moof)); | 393 ASSERT_TRUE(iter_->Init(moof)); |
384 EXPECT_EQ("1 KR KR KR KR KR KR KR KR KR KR", KeyframeAndRAPInfo(iter_.get())); | 394 EXPECT_EQ("1 KR KR KR KR KR KR KR KR KR KR", KeyframeAndRAPInfo(iter_.get())); |
385 | 395 |
386 iter_->AdvanceRun(); | 396 iter_->AdvanceRun(); |
387 EXPECT_EQ("2 KR P P P P P P P P P", KeyframeAndRAPInfo(iter_.get())); | 397 EXPECT_EQ("2 KR P P P P P P P P P", KeyframeAndRAPInfo(iter_.get())); |
388 } | 398 } |
389 | 399 |
390 // Verify that parsing fails if a reserved value is in the sample flags. | 400 // Verify that parsing fails if a reserved value is in the sample flags. |
391 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInSampleFlags) { | 401 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInSampleFlags) { |
| 402 EXPECT_MEDIA_LOG(ReservedValueInSampleDependencyInfo()); |
392 iter_.reset(new TrackRunIterator(&moov_, media_log_)); | 403 iter_.reset(new TrackRunIterator(&moov_, media_log_)); |
393 MovieFragment moof = CreateFragment(); | 404 MovieFragment moof = CreateFragment(); |
394 // Change the "depends on" field on one of the samples to a | 405 // Change the "depends on" field on one of the samples to a |
395 // reserved value. | 406 // reserved value. |
396 moof.tracks[1].runs[0].sample_flags[0] = ToSampleFlags("RS"); | 407 moof.tracks[1].runs[0].sample_flags[0] = ToSampleFlags("RS"); |
397 ASSERT_FALSE(iter_->Init(moof)); | 408 ASSERT_FALSE(iter_->Init(moof)); |
398 } | 409 } |
399 | 410 |
400 // Verify that parsing fails if a reserved value is in the default sample flags. | 411 // Verify that parsing fails if a reserved value is in the default sample flags. |
401 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInDefaultSampleFlags) { | 412 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInDefaultSampleFlags) { |
| 413 EXPECT_MEDIA_LOG(ReservedValueInSampleDependencyInfo()); |
402 iter_.reset(new TrackRunIterator(&moov_, media_log_)); | 414 iter_.reset(new TrackRunIterator(&moov_, media_log_)); |
403 MovieFragment moof = CreateFragment(); | 415 MovieFragment moof = CreateFragment(); |
404 // Set the default flag to contain a reserved "depends on" value. | 416 // Set the default flag to contain a reserved "depends on" value. |
405 moof.tracks[0].header.default_sample_flags = ToSampleFlags("RN"); | 417 moof.tracks[0].header.default_sample_flags = ToSampleFlags("RN"); |
406 ASSERT_FALSE(iter_->Init(moof)); | 418 ASSERT_FALSE(iter_->Init(moof)); |
407 } | 419 } |
408 | 420 |
409 TEST_F(TrackRunIteratorTest, ReorderingTest) { | 421 TEST_F(TrackRunIteratorTest, ReorderingTest) { |
410 // Test frame reordering and edit list support. The frames have the following | 422 // Test frame reordering and edit list support. The frames have the following |
411 // decode timestamps: | 423 // decode timestamps: |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 719 |
708 iter_->AdvanceRun(); | 720 iter_->AdvanceRun(); |
709 | 721 |
710 // Verify that nothing is marked as a random access point. | 722 // Verify that nothing is marked as a random access point. |
711 EXPECT_EQ("2 KR P PR P KR K", KeyframeAndRAPInfo(iter_.get())); | 723 EXPECT_EQ("2 KR P PR P KR K", KeyframeAndRAPInfo(iter_.get())); |
712 } | 724 } |
713 | 725 |
714 | 726 |
715 } // namespace mp4 | 727 } // namespace mp4 |
716 } // namespace media | 728 } // namespace media |
OLD | NEW |