Chromium Code Reviews| 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 <string> | |
| 6 | |
| 7 #include "media/base/mock_media_log.h" | |
| 5 #include "media/formats/mp4/aac.h" | 8 #include "media/formats/mp4/aac.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 6 | 11 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 12 using ::testing::InSequence; |
| 13 using ::testing::StrictMock; | |
| 8 | 14 |
| 9 namespace media { | 15 namespace media { |
| 10 | 16 |
| 11 namespace mp4 { | 17 namespace mp4 { |
| 12 | 18 |
| 19 #define CONTAINS_STRING(arg, x) (std::string::npos != (arg).find(x)) | |
|
chcunningham
2015/08/19 19:36:18
We define this 3 places now (including sbs tests).
wolenetz
2015/08/24 20:13:52
Done (here and in prerequisite CL, since it had so
| |
| 20 | |
| 21 MATCHER_P(AudioCodecLog, codec_string, "") { | |
| 22 return CONTAINS_STRING(arg, "Audio codec: " + std::string(codec_string)); | |
| 23 } | |
| 24 | |
| 13 class AACTest : public testing::Test { | 25 class AACTest : public testing::Test { |
| 14 public: | 26 public: |
| 27 AACTest() : media_log_(new StrictMock<MockMediaLog>()) {} | |
| 28 | |
| 15 bool Parse(const std::vector<uint8>& data) { | 29 bool Parse(const std::vector<uint8>& data) { |
| 16 return aac_.Parse(data, new MediaLog()); | 30 return aac_.Parse(data, media_log_); |
| 17 } | 31 } |
| 18 | 32 |
| 33 scoped_refptr<StrictMock<MockMediaLog>> media_log_; | |
| 19 AAC aac_; | 34 AAC aac_; |
| 20 }; | 35 }; |
| 21 | 36 |
| 22 TEST_F(AACTest, BasicProfileTest) { | 37 TEST_F(AACTest, BasicProfileTest) { |
| 23 uint8 buffer[] = {0x12, 0x10}; | 38 uint8 buffer[] = {0x12, 0x10}; |
| 24 std::vector<uint8> data; | 39 std::vector<uint8> data; |
| 25 | 40 |
| 26 data.assign(buffer, buffer + sizeof(buffer)); | 41 data.assign(buffer, buffer + sizeof(buffer)); |
| 27 | 42 |
| 43 EXPECT_MEDIA_LOG_STRING(AudioCodecLog("mp4a.40.2")); | |
| 44 | |
| 28 EXPECT_TRUE(Parse(data)); | 45 EXPECT_TRUE(Parse(data)); |
| 29 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100); | 46 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100); |
| 30 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 47 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 31 } | 48 } |
| 32 | 49 |
| 33 TEST_F(AACTest, ExtensionTest) { | 50 TEST_F(AACTest, ExtensionTest) { |
| 34 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; | 51 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; |
| 35 std::vector<uint8> data; | 52 std::vector<uint8> data; |
| 36 | 53 |
| 37 data.assign(buffer, buffer + sizeof(buffer)); | 54 data.assign(buffer, buffer + sizeof(buffer)); |
| 38 | 55 |
| 56 EXPECT_MEDIA_LOG_STRING(AudioCodecLog("mp4a.40.2")); | |
| 57 | |
| 39 EXPECT_TRUE(Parse(data)); | 58 EXPECT_TRUE(Parse(data)); |
| 40 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); | 59 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); |
| 41 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 60 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 42 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 61 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 43 } | 62 } |
| 44 | 63 |
| 45 // Test implicit SBR with mono channel config. | 64 // Test implicit SBR with mono channel config. |
| 46 // Mono channel layout should only be reported if SBR is not | 65 // Mono channel layout should only be reported if SBR is not |
| 47 // specified. Otherwise stereo should be reported. | 66 // specified. Otherwise stereo should be reported. |
| 48 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing. | 67 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing. |
| 49 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) { | 68 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) { |
| 50 uint8 buffer[] = {0x13, 0x08}; | 69 uint8 buffer[] = {0x13, 0x08}; |
| 51 std::vector<uint8> data; | 70 std::vector<uint8> data; |
| 52 | 71 |
| 53 data.assign(buffer, buffer + sizeof(buffer)); | 72 data.assign(buffer, buffer + sizeof(buffer)); |
| 54 | 73 |
| 74 EXPECT_MEDIA_LOG_STRING(AudioCodecLog("mp4a.40.2")); | |
| 75 | |
| 55 EXPECT_TRUE(Parse(data)); | 76 EXPECT_TRUE(Parse(data)); |
| 56 | 77 |
| 57 // Test w/o implict SBR. | 78 // Test w/o implict SBR. |
| 58 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); | 79 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); |
| 59 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); | 80 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); |
| 60 | 81 |
| 61 // Test implicit SBR. | 82 // Test implicit SBR. |
| 62 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 83 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 63 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); | 84 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); |
| 64 } | 85 } |
| 65 | 86 |
| 66 // Tests implicit SBR with a stereo channel config. | 87 // Tests implicit SBR with a stereo channel config. |
| 67 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) { | 88 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) { |
| 68 uint8 buffer[] = {0x13, 0x10}; | 89 uint8 buffer[] = {0x13, 0x10}; |
| 69 std::vector<uint8> data; | 90 std::vector<uint8> data; |
| 70 | 91 |
| 71 data.assign(buffer, buffer + sizeof(buffer)); | 92 data.assign(buffer, buffer + sizeof(buffer)); |
| 72 | 93 |
| 94 EXPECT_MEDIA_LOG_STRING(AudioCodecLog("mp4a.40.2")); | |
| 95 | |
| 73 EXPECT_TRUE(Parse(data)); | 96 EXPECT_TRUE(Parse(data)); |
| 74 | 97 |
| 75 // Test w/o implict SBR. | 98 // Test w/o implict SBR. |
| 76 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); | 99 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); |
| 77 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 100 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 78 | 101 |
| 79 // Test implicit SBR. | 102 // Test implicit SBR. |
| 80 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 103 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 81 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); | 104 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); |
| 82 } | 105 } |
| 83 | 106 |
| 84 TEST_F(AACTest, SixChannelTest) { | 107 TEST_F(AACTest, SixChannelTest) { |
| 85 uint8 buffer[] = {0x11, 0xb0}; | 108 uint8 buffer[] = {0x11, 0xb0}; |
| 86 std::vector<uint8> data; | 109 std::vector<uint8> data; |
| 87 | 110 |
| 88 data.assign(buffer, buffer + sizeof(buffer)); | 111 data.assign(buffer, buffer + sizeof(buffer)); |
| 89 | 112 |
| 113 EXPECT_MEDIA_LOG_STRING(AudioCodecLog("mp4a.40.2")); | |
| 114 | |
| 90 EXPECT_TRUE(Parse(data)); | 115 EXPECT_TRUE(Parse(data)); |
| 91 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); | 116 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); |
| 92 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK); | 117 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK); |
| 93 } | 118 } |
| 94 | 119 |
| 95 TEST_F(AACTest, DataTooShortTest) { | 120 TEST_F(AACTest, DataTooShortTest) { |
| 96 std::vector<uint8> data; | 121 std::vector<uint8> data; |
| 97 | 122 |
| 98 EXPECT_FALSE(Parse(data)); | 123 EXPECT_FALSE(Parse(data)); |
| 99 | 124 |
| 100 data.push_back(0x12); | 125 data.push_back(0x12); |
| 101 EXPECT_FALSE(Parse(data)); | 126 EXPECT_FALSE(Parse(data)); |
| 102 } | 127 } |
| 103 | 128 |
| 104 TEST_F(AACTest, IncorrectProfileTest) { | 129 TEST_F(AACTest, IncorrectProfileTest) { |
| 130 InSequence s; | |
| 105 uint8 buffer[] = {0x0, 0x08}; | 131 uint8 buffer[] = {0x0, 0x08}; |
| 106 std::vector<uint8> data; | 132 std::vector<uint8> data; |
| 107 | 133 |
| 108 data.assign(buffer, buffer + sizeof(buffer)); | 134 data.assign(buffer, buffer + sizeof(buffer)); |
| 109 | 135 |
| 136 EXPECT_MEDIA_LOG_STRING(AudioCodecLog("mp4a.40.0")); | |
| 110 EXPECT_FALSE(Parse(data)); | 137 EXPECT_FALSE(Parse(data)); |
| 111 | 138 |
| 112 data[0] = 0x08; | 139 data[0] = 0x08; |
| 140 EXPECT_MEDIA_LOG_STRING(AudioCodecLog("mp4a.40.1")); | |
| 113 EXPECT_TRUE(Parse(data)); | 141 EXPECT_TRUE(Parse(data)); |
| 114 | 142 |
| 115 data[0] = 0x28; | 143 data[0] = 0x28; |
| 144 // No media log for this profile 5, since not enough bits are in |data| to | |
| 145 // first parse profile 5's extension frequency index. | |
| 116 EXPECT_FALSE(Parse(data)); | 146 EXPECT_FALSE(Parse(data)); |
| 117 } | 147 } |
| 118 | 148 |
| 119 TEST_F(AACTest, IncorrectFrequencyTest) { | 149 TEST_F(AACTest, IncorrectFrequencyTest) { |
| 120 uint8 buffer[] = {0x0f, 0x88}; | 150 uint8 buffer[] = {0x0f, 0x88}; |
| 121 std::vector<uint8> data; | 151 std::vector<uint8> data; |
| 122 | 152 |
| 123 data.assign(buffer, buffer + sizeof(buffer)); | 153 data.assign(buffer, buffer + sizeof(buffer)); |
| 124 | 154 |
| 125 EXPECT_FALSE(Parse(data)); | 155 EXPECT_FALSE(Parse(data)); |
| 126 | 156 |
| 127 data[0] = 0x0e; | 157 data[0] = 0x0e; |
| 128 data[1] = 0x08; | 158 data[1] = 0x08; |
| 159 EXPECT_MEDIA_LOG_STRING(AudioCodecLog("mp4a.40.1")); | |
| 129 EXPECT_TRUE(Parse(data)); | 160 EXPECT_TRUE(Parse(data)); |
| 130 } | 161 } |
| 131 | 162 |
| 132 TEST_F(AACTest, IncorrectChannelTest) { | 163 TEST_F(AACTest, IncorrectChannelTest) { |
| 133 uint8 buffer[] = {0x0e, 0x00}; | 164 uint8 buffer[] = {0x0e, 0x00}; |
| 134 std::vector<uint8> data; | 165 std::vector<uint8> data; |
| 135 | 166 |
| 136 data.assign(buffer, buffer + sizeof(buffer)); | 167 data.assign(buffer, buffer + sizeof(buffer)); |
| 137 | 168 |
| 169 EXPECT_MEDIA_LOG_STRING(AudioCodecLog("mp4a.40.1")).Times(2); | |
|
chcunningham
2015/08/19 19:36:18
Do you know why we do it twice here? Not your faul
wolenetz
2015/08/24 20:13:52
The intrinsic parse sequence emits the AudioCodecL
| |
| 170 | |
| 138 EXPECT_FALSE(Parse(data)); | 171 EXPECT_FALSE(Parse(data)); |
| 139 | 172 |
| 140 data[1] = 0x08; | 173 data[1] = 0x08; |
| 141 EXPECT_TRUE(Parse(data)); | 174 EXPECT_TRUE(Parse(data)); |
| 142 } | 175 } |
| 143 | 176 |
| 144 } // namespace mp4 | 177 } // namespace mp4 |
| 145 | 178 |
| 146 } // namespace media | 179 } // namespace media |
| OLD | NEW |