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 #define CONTAINS_STRING(arg, x) (std::string::npos != (arg).find(x)) |
| 57 |
| 58 MATCHER(ReservedValueInSampleDependencyInfo, "") { |
| 59 return CONTAINS_STRING(arg, "Reserved value used in sample dependency info."); |
| 60 } |
| 61 |
52 class TrackRunIteratorTest : public testing::Test { | 62 class TrackRunIteratorTest : public testing::Test { |
53 public: | 63 public: |
54 TrackRunIteratorTest() : media_log_(new MediaLog()) { CreateMovie(); } | 64 TrackRunIteratorTest() : media_log_(new StrictMock<MockMediaLog>()) { |
| 65 CreateMovie(); |
| 66 } |
55 | 67 |
56 protected: | 68 protected: |
57 Movie moov_; | 69 Movie moov_; |
58 scoped_refptr<MediaLog> media_log_; | 70 scoped_refptr<StrictMock<MockMediaLog>> media_log_; |
59 scoped_ptr<TrackRunIterator> iter_; | 71 scoped_ptr<TrackRunIterator> iter_; |
60 | 72 |
61 void CreateMovie() { | 73 void CreateMovie() { |
62 moov_.header.timescale = 1000; | 74 moov_.header.timescale = 1000; |
63 moov_.tracks.resize(3); | 75 moov_.tracks.resize(3); |
64 moov_.extends.tracks.resize(2); | 76 moov_.extends.tracks.resize(2); |
65 moov_.tracks[0].header.track_id = 1; | 77 moov_.tracks[0].header.track_id = 1; |
66 moov_.tracks[0].media.header.timescale = kAudioScale; | 78 moov_.tracks[0].media.header.timescale = kAudioScale; |
67 SampleDescription& desc1 = | 79 SampleDescription& desc1 = |
68 moov_.tracks[0].media.information.sample_table.description; | 80 moov_.tracks[0].media.information.sample_table.description; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 394 |
383 ASSERT_TRUE(iter_->Init(moof)); | 395 ASSERT_TRUE(iter_->Init(moof)); |
384 EXPECT_EQ("1 KR KR KR KR KR KR KR KR KR KR", KeyframeAndRAPInfo(iter_.get())); | 396 EXPECT_EQ("1 KR KR KR KR KR KR KR KR KR KR", KeyframeAndRAPInfo(iter_.get())); |
385 | 397 |
386 iter_->AdvanceRun(); | 398 iter_->AdvanceRun(); |
387 EXPECT_EQ("2 KR P P P P P P P P P", KeyframeAndRAPInfo(iter_.get())); | 399 EXPECT_EQ("2 KR P P P P P P P P P", KeyframeAndRAPInfo(iter_.get())); |
388 } | 400 } |
389 | 401 |
390 // Verify that parsing fails if a reserved value is in the sample flags. | 402 // Verify that parsing fails if a reserved value is in the sample flags. |
391 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInSampleFlags) { | 403 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInSampleFlags) { |
| 404 EXPECT_MEDIA_LOG_STRING(ReservedValueInSampleDependencyInfo()); |
392 iter_.reset(new TrackRunIterator(&moov_, media_log_)); | 405 iter_.reset(new TrackRunIterator(&moov_, media_log_)); |
393 MovieFragment moof = CreateFragment(); | 406 MovieFragment moof = CreateFragment(); |
394 // Change the "depends on" field on one of the samples to a | 407 // Change the "depends on" field on one of the samples to a |
395 // reserved value. | 408 // reserved value. |
396 moof.tracks[1].runs[0].sample_flags[0] = ToSampleFlags("RS"); | 409 moof.tracks[1].runs[0].sample_flags[0] = ToSampleFlags("RS"); |
397 ASSERT_FALSE(iter_->Init(moof)); | 410 ASSERT_FALSE(iter_->Init(moof)); |
398 } | 411 } |
399 | 412 |
400 // Verify that parsing fails if a reserved value is in the default sample flags. | 413 // Verify that parsing fails if a reserved value is in the default sample flags. |
401 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInDefaultSampleFlags) { | 414 TEST_F(TrackRunIteratorTest, SampleInfoTest_ReservedInDefaultSampleFlags) { |
| 415 EXPECT_MEDIA_LOG_STRING(ReservedValueInSampleDependencyInfo()); |
402 iter_.reset(new TrackRunIterator(&moov_, media_log_)); | 416 iter_.reset(new TrackRunIterator(&moov_, media_log_)); |
403 MovieFragment moof = CreateFragment(); | 417 MovieFragment moof = CreateFragment(); |
404 // Set the default flag to contain a reserved "depends on" value. | 418 // Set the default flag to contain a reserved "depends on" value. |
405 moof.tracks[0].header.default_sample_flags = ToSampleFlags("RN"); | 419 moof.tracks[0].header.default_sample_flags = ToSampleFlags("RN"); |
406 ASSERT_FALSE(iter_->Init(moof)); | 420 ASSERT_FALSE(iter_->Init(moof)); |
407 } | 421 } |
408 | 422 |
409 TEST_F(TrackRunIteratorTest, ReorderingTest) { | 423 TEST_F(TrackRunIteratorTest, ReorderingTest) { |
410 // Test frame reordering and edit list support. The frames have the following | 424 // Test frame reordering and edit list support. The frames have the following |
411 // decode timestamps: | 425 // decode timestamps: |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 721 |
708 iter_->AdvanceRun(); | 722 iter_->AdvanceRun(); |
709 | 723 |
710 // Verify that nothing is marked as a random access point. | 724 // Verify that nothing is marked as a random access point. |
711 EXPECT_EQ("2 KR P PR P KR K", KeyframeAndRAPInfo(iter_.get())); | 725 EXPECT_EQ("2 KR P PR P KR K", KeyframeAndRAPInfo(iter_.get())); |
712 } | 726 } |
713 | 727 |
714 | 728 |
715 } // namespace mp4 | 729 } // namespace mp4 |
716 } // namespace media | 730 } // namespace media |
OLD | NEW |