Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / media / formats / mp4 / aac_unittest.cc
blob264727f38c3e7ab8f19ee999cf50d40eb0355568
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
3 // found in the LICENSE file.
5 #include <string>
7 #include "media/base/mock_media_log.h"
8 #include "media/formats/mp4/aac.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using ::testing::InSequence;
13 using ::testing::StrictMock;
15 namespace media {
17 namespace mp4 {
19 MATCHER_P(AudioCodecLog, codec_string, "") {
20 return CONTAINS_STRING(arg, "Audio codec: " + std::string(codec_string));
23 class AACTest : public testing::Test {
24 public:
25 AACTest() : media_log_(new StrictMock<MockMediaLog>()) {}
27 bool Parse(const std::vector<uint8>& data) {
28 return aac_.Parse(data, media_log_);
31 scoped_refptr<StrictMock<MockMediaLog>> media_log_;
32 AAC aac_;
35 TEST_F(AACTest, BasicProfileTest) {
36 uint8 buffer[] = {0x12, 0x10};
37 std::vector<uint8> data;
39 data.assign(buffer, buffer + sizeof(buffer));
41 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2"));
43 EXPECT_TRUE(Parse(data));
44 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100);
45 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO);
48 TEST_F(AACTest, ExtensionTest) {
49 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80};
50 std::vector<uint8> data;
52 data.assign(buffer, buffer + sizeof(buffer));
54 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2"));
56 EXPECT_TRUE(Parse(data));
57 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000);
58 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000);
59 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO);
62 // Test implicit SBR with mono channel config.
63 // Mono channel layout should only be reported if SBR is not
64 // specified. Otherwise stereo should be reported.
65 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing.
66 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) {
67 uint8 buffer[] = {0x13, 0x08};
68 std::vector<uint8> data;
70 data.assign(buffer, buffer + sizeof(buffer));
72 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2"));
74 EXPECT_TRUE(Parse(data));
76 // Test w/o implict SBR.
77 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000);
78 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO);
80 // Test implicit SBR.
81 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000);
82 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO);
85 // Tests implicit SBR with a stereo channel config.
86 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) {
87 uint8 buffer[] = {0x13, 0x10};
88 std::vector<uint8> data;
90 data.assign(buffer, buffer + sizeof(buffer));
92 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2"));
94 EXPECT_TRUE(Parse(data));
96 // Test w/o implict SBR.
97 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000);
98 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO);
100 // Test implicit SBR.
101 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000);
102 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO);
105 TEST_F(AACTest, SixChannelTest) {
106 uint8 buffer[] = {0x11, 0xb0};
107 std::vector<uint8> data;
109 data.assign(buffer, buffer + sizeof(buffer));
111 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2"));
113 EXPECT_TRUE(Parse(data));
114 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000);
115 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK);
118 TEST_F(AACTest, DataTooShortTest) {
119 std::vector<uint8> data;
121 EXPECT_FALSE(Parse(data));
123 data.push_back(0x12);
124 EXPECT_FALSE(Parse(data));
127 TEST_F(AACTest, IncorrectProfileTest) {
128 InSequence s;
129 uint8 buffer[] = {0x0, 0x08};
130 std::vector<uint8> data;
132 data.assign(buffer, buffer + sizeof(buffer));
134 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.0"));
135 EXPECT_FALSE(Parse(data));
137 data[0] = 0x08;
138 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1"));
139 EXPECT_TRUE(Parse(data));
141 data[0] = 0x28;
142 // No media log for this profile 5, since not enough bits are in |data| to
143 // first parse profile 5's extension frequency index.
144 EXPECT_FALSE(Parse(data));
147 TEST_F(AACTest, IncorrectFrequencyTest) {
148 uint8 buffer[] = {0x0f, 0x88};
149 std::vector<uint8> data;
151 data.assign(buffer, buffer + sizeof(buffer));
153 EXPECT_FALSE(Parse(data));
155 data[0] = 0x0e;
156 data[1] = 0x08;
157 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1"));
158 EXPECT_TRUE(Parse(data));
161 TEST_F(AACTest, IncorrectChannelTest) {
162 uint8 buffer[] = {0x0e, 0x00};
163 std::vector<uint8> data;
165 data.assign(buffer, buffer + sizeof(buffer));
167 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1")).Times(2);
169 EXPECT_FALSE(Parse(data));
171 data[1] = 0x08;
172 EXPECT_TRUE(Parse(data));
175 } // namespace mp4
177 } // namespace media