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> | 5 #include <string> |
6 | 6 |
7 #include "media/base/mock_media_log.h" | 7 #include "media/base/mock_media_log.h" |
8 #include "media/formats/mp4/aac.h" | 8 #include "media/formats/mp4/aac.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 using ::testing::InSequence; | 12 using ::testing::InSequence; |
13 using ::testing::StrictMock; | 13 using ::testing::StrictMock; |
14 using ::testing::AllOf; | |
14 | 15 |
15 namespace media { | 16 namespace media { |
16 | 17 |
17 namespace mp4 { | 18 namespace mp4 { |
18 | 19 |
19 MATCHER_P(AudioCodecLog, codec_string, "") { | 20 MATCHER_P(AudioCodecLog, codec_string, "") { |
20 return CONTAINS_STRING(arg, "Audio codec: " + std::string(codec_string)); | 21 return CONTAINS_STRING(arg, "Audio codec: " + std::string(codec_string)); |
21 } | 22 } |
22 | 23 |
24 MATCHER_P(AudioSamplingFrequencyLog, codec_string, "") { | |
wolenetz
2015/09/01 21:22:37
nit: s/codec/frequency/
msu.koo
2015/09/11 23:57:23
Done.
| |
25 return CONTAINS_STRING(arg, | |
26 "Sampling frequency: " + std::string(codec_string)); | |
wolenetz
2015/09/01 21:22:37
nit ditto
msu.koo
2015/09/11 23:57:23
Done.
| |
27 } | |
28 | |
29 MATCHER_P(AudioExtensionSamplingFrequencyLog, codec_string, "") { | |
wolenetz
2015/09/01 21:22:37
nit: s/codec/extension/
msu.koo
2015/09/11 23:57:23
Done.
| |
30 return CONTAINS_STRING( | |
31 arg, "Sampling frequency(Extension): " + std::string(codec_string)); | |
wolenetz
2015/09/01 21:22:37
nit ditto
msu.koo
2015/09/11 23:57:23
Done.
| |
32 } | |
33 | |
34 MATCHER_P(AudioChannelLayoutLog, codec_string, "") { | |
wolenetz
2015/09/01 21:22:37
nit: s/codec/layout/
msu.koo
2015/09/11 23:57:23
Done.
| |
35 return CONTAINS_STRING(arg, "Channel layout: " + std::string(codec_string)); | |
wolenetz
2015/09/01 21:22:37
nit ditto
msu.koo
2015/09/11 23:57:23
Done.
| |
36 } | |
37 | |
23 class AACTest : public testing::Test { | 38 class AACTest : public testing::Test { |
24 public: | 39 public: |
25 AACTest() : media_log_(new StrictMock<MockMediaLog>()) {} | 40 AACTest() : media_log_(new StrictMock<MockMediaLog>()) {} |
26 | 41 |
27 bool Parse(const std::vector<uint8>& data) { | 42 bool Parse(const std::vector<uint8>& data) { |
28 return aac_.Parse(data, media_log_); | 43 return aac_.Parse(data, media_log_); |
29 } | 44 } |
30 | 45 |
31 scoped_refptr<StrictMock<MockMediaLog>> media_log_; | 46 scoped_refptr<StrictMock<MockMediaLog>> media_log_; |
32 AAC aac_; | 47 AAC aac_; |
33 }; | 48 }; |
34 | 49 |
35 TEST_F(AACTest, BasicProfileTest) { | 50 TEST_F(AACTest, BasicProfileTest) { |
36 uint8 buffer[] = {0x12, 0x10}; | 51 uint8 buffer[] = {0x12, 0x10}; |
37 std::vector<uint8> data; | 52 std::vector<uint8> data; |
38 | 53 |
39 data.assign(buffer, buffer + sizeof(buffer)); | 54 data.assign(buffer, buffer + sizeof(buffer)); |
40 | 55 |
41 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | 56 EXPECT_MEDIA_LOG(AllOf(AudioCodecLog("mp4a.40.2"), |
wolenetz
2015/09/01 21:22:37
Neat usage of AllOf. I like it. However, we really
msu.koo
2015/09/11 05:15:37
Thank you for your review.
I also considered about
wolenetz
2015/09/14 23:17:57
Thanks. The new delimiters in the matchers are suf
| |
42 | 57 AudioSamplingFrequencyLog("44100"), |
58 AudioExtensionSamplingFrequencyLog("0"), | |
59 AudioChannelLayoutLog("3"))); | |
43 EXPECT_TRUE(Parse(data)); | 60 EXPECT_TRUE(Parse(data)); |
44 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100); | 61 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100); |
45 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 62 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
46 } | 63 } |
47 | 64 |
48 TEST_F(AACTest, ExtensionTest) { | 65 TEST_F(AACTest, ExtensionTest) { |
49 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; | 66 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; |
50 std::vector<uint8> data; | 67 std::vector<uint8> data; |
51 | 68 |
52 data.assign(buffer, buffer + sizeof(buffer)); | 69 data.assign(buffer, buffer + sizeof(buffer)); |
53 | 70 |
54 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | 71 EXPECT_MEDIA_LOG(AllOf(AudioCodecLog("mp4a.40.2"), |
55 | 72 AudioSamplingFrequencyLog("24000"), |
73 AudioExtensionSamplingFrequencyLog("48000"), | |
74 AudioChannelLayoutLog("3"))); | |
56 EXPECT_TRUE(Parse(data)); | 75 EXPECT_TRUE(Parse(data)); |
57 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); | 76 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); |
58 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 77 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
59 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 78 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
60 } | 79 } |
61 | 80 |
62 // Test implicit SBR with mono channel config. | 81 // Test implicit SBR with mono channel config. |
63 // Mono channel layout should only be reported if SBR is not | 82 // Mono channel layout should only be reported if SBR is not |
64 // specified. Otherwise stereo should be reported. | 83 // specified. Otherwise stereo should be reported. |
65 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing. | 84 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing. |
66 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) { | 85 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) { |
67 uint8 buffer[] = {0x13, 0x08}; | 86 uint8 buffer[] = {0x13, 0x08}; |
68 std::vector<uint8> data; | 87 std::vector<uint8> data; |
69 | 88 |
70 data.assign(buffer, buffer + sizeof(buffer)); | 89 data.assign(buffer, buffer + sizeof(buffer)); |
71 | 90 |
72 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | 91 EXPECT_MEDIA_LOG(AllOf(AudioCodecLog("mp4a.40.2"), |
73 | 92 AudioSamplingFrequencyLog("24000"), |
93 AudioExtensionSamplingFrequencyLog("0"), | |
94 AudioChannelLayoutLog("2"))); | |
74 EXPECT_TRUE(Parse(data)); | 95 EXPECT_TRUE(Parse(data)); |
75 | 96 |
76 // Test w/o implict SBR. | 97 // Test w/o implict SBR. |
77 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); | 98 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); |
78 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); | 99 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); |
79 | 100 |
80 // Test implicit SBR. | 101 // Test implicit SBR. |
81 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 102 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
82 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); | 103 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); |
83 } | 104 } |
84 | 105 |
85 // Tests implicit SBR with a stereo channel config. | 106 // Tests implicit SBR with a stereo channel config. |
86 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) { | 107 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) { |
87 uint8 buffer[] = {0x13, 0x10}; | 108 uint8 buffer[] = {0x13, 0x10}; |
88 std::vector<uint8> data; | 109 std::vector<uint8> data; |
89 | 110 |
90 data.assign(buffer, buffer + sizeof(buffer)); | 111 data.assign(buffer, buffer + sizeof(buffer)); |
91 | 112 |
92 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | 113 EXPECT_MEDIA_LOG(AllOf(AudioCodecLog("mp4a.40.2"), |
93 | 114 AudioSamplingFrequencyLog("24000"), |
115 AudioExtensionSamplingFrequencyLog("0"), | |
116 AudioChannelLayoutLog("3"))); | |
94 EXPECT_TRUE(Parse(data)); | 117 EXPECT_TRUE(Parse(data)); |
95 | 118 |
96 // Test w/o implict SBR. | 119 // Test w/o implict SBR. |
97 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); | 120 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); |
98 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 121 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
99 | 122 |
100 // Test implicit SBR. | 123 // Test implicit SBR. |
101 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 124 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
102 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); | 125 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); |
103 } | 126 } |
104 | 127 |
105 TEST_F(AACTest, SixChannelTest) { | 128 TEST_F(AACTest, SixChannelTest) { |
106 uint8 buffer[] = {0x11, 0xb0}; | 129 uint8 buffer[] = {0x11, 0xb0}; |
107 std::vector<uint8> data; | 130 std::vector<uint8> data; |
108 | 131 |
109 data.assign(buffer, buffer + sizeof(buffer)); | 132 data.assign(buffer, buffer + sizeof(buffer)); |
110 | 133 |
111 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | 134 EXPECT_MEDIA_LOG(AllOf(AudioCodecLog("mp4a.40.2"), |
112 | 135 AudioSamplingFrequencyLog("48000"), |
136 AudioExtensionSamplingFrequencyLog("0"), | |
137 AudioChannelLayoutLog("12"))); | |
113 EXPECT_TRUE(Parse(data)); | 138 EXPECT_TRUE(Parse(data)); |
114 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); | 139 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); |
115 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK); | 140 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK); |
116 } | 141 } |
117 | 142 |
118 TEST_F(AACTest, DataTooShortTest) { | 143 TEST_F(AACTest, DataTooShortTest) { |
119 std::vector<uint8> data; | 144 std::vector<uint8> data; |
120 | 145 |
121 EXPECT_FALSE(Parse(data)); | 146 EXPECT_FALSE(Parse(data)); |
122 | 147 |
123 data.push_back(0x12); | 148 data.push_back(0x12); |
124 EXPECT_FALSE(Parse(data)); | 149 EXPECT_FALSE(Parse(data)); |
125 } | 150 } |
126 | 151 |
127 TEST_F(AACTest, IncorrectProfileTest) { | 152 TEST_F(AACTest, IncorrectProfileTest) { |
128 InSequence s; | 153 InSequence s; |
129 uint8 buffer[] = {0x0, 0x08}; | 154 uint8 buffer[] = {0x0, 0x08}; |
130 std::vector<uint8> data; | 155 std::vector<uint8> data; |
131 | 156 |
132 data.assign(buffer, buffer + sizeof(buffer)); | 157 data.assign(buffer, buffer + sizeof(buffer)); |
133 | |
134 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.0")); | |
135 EXPECT_FALSE(Parse(data)); | 158 EXPECT_FALSE(Parse(data)); |
136 | 159 |
137 data[0] = 0x08; | 160 data[0] = 0x08; |
138 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1")); | 161 EXPECT_MEDIA_LOG(AllOf(AudioCodecLog("mp4a.40.1"), |
162 AudioSamplingFrequencyLog("96000"), | |
163 AudioExtensionSamplingFrequencyLog("0"), | |
164 AudioChannelLayoutLog("2"))); | |
139 EXPECT_TRUE(Parse(data)); | 165 EXPECT_TRUE(Parse(data)); |
140 | 166 |
141 data[0] = 0x28; | 167 data[0] = 0x28; |
142 // No media log for this profile 5, since not enough bits are in |data| to | 168 // No media log for this profile 5, since not enough bits are in |data| to |
143 // first parse profile 5's extension frequency index. | 169 // first parse profile 5's extension frequency index. |
144 EXPECT_FALSE(Parse(data)); | 170 EXPECT_FALSE(Parse(data)); |
145 } | 171 } |
146 | 172 |
147 TEST_F(AACTest, IncorrectFrequencyTest) { | 173 TEST_F(AACTest, IncorrectFrequencyTest) { |
148 uint8 buffer[] = {0x0f, 0x88}; | 174 uint8 buffer[] = {0x0f, 0x88}; |
149 std::vector<uint8> data; | 175 std::vector<uint8> data; |
150 | 176 |
151 data.assign(buffer, buffer + sizeof(buffer)); | 177 data.assign(buffer, buffer + sizeof(buffer)); |
152 | |
153 EXPECT_FALSE(Parse(data)); | 178 EXPECT_FALSE(Parse(data)); |
154 | 179 |
155 data[0] = 0x0e; | 180 data[0] = 0x0e; |
156 data[1] = 0x08; | 181 data[1] = 0x08; |
157 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1")); | 182 EXPECT_MEDIA_LOG(AllOf(AudioCodecLog("mp4a.40.1"), |
183 AudioSamplingFrequencyLog("7350"), | |
184 AudioExtensionSamplingFrequencyLog("0"), | |
185 AudioChannelLayoutLog("2"))); | |
158 EXPECT_TRUE(Parse(data)); | 186 EXPECT_TRUE(Parse(data)); |
159 } | 187 } |
160 | 188 |
161 TEST_F(AACTest, IncorrectChannelTest) { | 189 TEST_F(AACTest, IncorrectChannelTest) { |
162 uint8 buffer[] = {0x0e, 0x00}; | 190 uint8 buffer[] = {0x0e, 0x00}; |
163 std::vector<uint8> data; | 191 std::vector<uint8> data; |
164 | 192 |
165 data.assign(buffer, buffer + sizeof(buffer)); | 193 data.assign(buffer, buffer + sizeof(buffer)); |
166 | |
167 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1")).Times(2); | |
168 | |
169 EXPECT_FALSE(Parse(data)); | 194 EXPECT_FALSE(Parse(data)); |
170 | 195 |
171 data[1] = 0x08; | 196 data[1] = 0x08; |
197 EXPECT_MEDIA_LOG(AllOf(AudioCodecLog("mp4a.40.1"), | |
198 AudioSamplingFrequencyLog("7350"), | |
199 AudioExtensionSamplingFrequencyLog("0"), | |
200 AudioChannelLayoutLog("2"))); | |
172 EXPECT_TRUE(Parse(data)); | 201 EXPECT_TRUE(Parse(data)); |
173 } | 202 } |
174 | 203 |
175 } // namespace mp4 | 204 } // namespace mp4 |
176 | 205 |
177 } // namespace media | 206 } // namespace media |
OLD | NEW |