Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(854)

Side by Side Diff: media/formats/mp4/aac_unittest.cc

Issue 1317063003: Reland of MSE: Verify MediaLog events created by existing MP4 unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@more_mockmedialog_testing_webm
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/formats/mp4/box_reader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 MATCHER_P(AudioCodecLog, codec_string, "") {
20 return CONTAINS_STRING(arg, "Audio codec: " + std::string(codec_string));
21 }
22
13 class AACTest : public testing::Test { 23 class AACTest : public testing::Test {
14 public: 24 public:
25 AACTest() : media_log_(new StrictMock<MockMediaLog>()) {}
26
15 bool Parse(const std::vector<uint8>& data) { 27 bool Parse(const std::vector<uint8>& data) {
16 return aac_.Parse(data, new MediaLog()); 28 return aac_.Parse(data, media_log_);
17 } 29 }
18 30
31 scoped_refptr<StrictMock<MockMediaLog>> media_log_;
19 AAC aac_; 32 AAC aac_;
20 }; 33 };
21 34
22 TEST_F(AACTest, BasicProfileTest) { 35 TEST_F(AACTest, BasicProfileTest) {
23 uint8 buffer[] = {0x12, 0x10}; 36 uint8 buffer[] = {0x12, 0x10};
24 std::vector<uint8> data; 37 std::vector<uint8> data;
25 38
26 data.assign(buffer, buffer + sizeof(buffer)); 39 data.assign(buffer, buffer + sizeof(buffer));
27 40
41 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2"));
42
28 EXPECT_TRUE(Parse(data)); 43 EXPECT_TRUE(Parse(data));
29 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100); 44 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100);
30 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); 45 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO);
31 } 46 }
32 47
33 TEST_F(AACTest, ExtensionTest) { 48 TEST_F(AACTest, ExtensionTest) {
34 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; 49 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80};
35 std::vector<uint8> data; 50 std::vector<uint8> data;
36 51
37 data.assign(buffer, buffer + sizeof(buffer)); 52 data.assign(buffer, buffer + sizeof(buffer));
38 53
54 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2"));
55
39 EXPECT_TRUE(Parse(data)); 56 EXPECT_TRUE(Parse(data));
40 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); 57 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000);
41 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); 58 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000);
42 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); 59 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO);
43 } 60 }
44 61
45 // Test implicit SBR with mono channel config. 62 // Test implicit SBR with mono channel config.
46 // Mono channel layout should only be reported if SBR is not 63 // Mono channel layout should only be reported if SBR is not
47 // specified. Otherwise stereo should be reported. 64 // specified. Otherwise stereo should be reported.
48 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing. 65 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing.
49 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) { 66 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) {
50 uint8 buffer[] = {0x13, 0x08}; 67 uint8 buffer[] = {0x13, 0x08};
51 std::vector<uint8> data; 68 std::vector<uint8> data;
52 69
53 data.assign(buffer, buffer + sizeof(buffer)); 70 data.assign(buffer, buffer + sizeof(buffer));
54 71
72 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2"));
73
55 EXPECT_TRUE(Parse(data)); 74 EXPECT_TRUE(Parse(data));
56 75
57 // Test w/o implict SBR. 76 // Test w/o implict SBR.
58 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); 77 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000);
59 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); 78 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO);
60 79
61 // Test implicit SBR. 80 // Test implicit SBR.
62 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); 81 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000);
63 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); 82 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO);
64 } 83 }
65 84
66 // Tests implicit SBR with a stereo channel config. 85 // Tests implicit SBR with a stereo channel config.
67 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) { 86 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) {
68 uint8 buffer[] = {0x13, 0x10}; 87 uint8 buffer[] = {0x13, 0x10};
69 std::vector<uint8> data; 88 std::vector<uint8> data;
70 89
71 data.assign(buffer, buffer + sizeof(buffer)); 90 data.assign(buffer, buffer + sizeof(buffer));
72 91
92 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2"));
93
73 EXPECT_TRUE(Parse(data)); 94 EXPECT_TRUE(Parse(data));
74 95
75 // Test w/o implict SBR. 96 // Test w/o implict SBR.
76 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); 97 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000);
77 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); 98 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO);
78 99
79 // Test implicit SBR. 100 // Test implicit SBR.
80 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); 101 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000);
81 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); 102 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO);
82 } 103 }
83 104
84 TEST_F(AACTest, SixChannelTest) { 105 TEST_F(AACTest, SixChannelTest) {
85 uint8 buffer[] = {0x11, 0xb0}; 106 uint8 buffer[] = {0x11, 0xb0};
86 std::vector<uint8> data; 107 std::vector<uint8> data;
87 108
88 data.assign(buffer, buffer + sizeof(buffer)); 109 data.assign(buffer, buffer + sizeof(buffer));
89 110
111 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2"));
112
90 EXPECT_TRUE(Parse(data)); 113 EXPECT_TRUE(Parse(data));
91 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); 114 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000);
92 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK); 115 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK);
93 } 116 }
94 117
95 TEST_F(AACTest, DataTooShortTest) { 118 TEST_F(AACTest, DataTooShortTest) {
96 std::vector<uint8> data; 119 std::vector<uint8> data;
97 120
98 EXPECT_FALSE(Parse(data)); 121 EXPECT_FALSE(Parse(data));
99 122
100 data.push_back(0x12); 123 data.push_back(0x12);
101 EXPECT_FALSE(Parse(data)); 124 EXPECT_FALSE(Parse(data));
102 } 125 }
103 126
104 TEST_F(AACTest, IncorrectProfileTest) { 127 TEST_F(AACTest, IncorrectProfileTest) {
128 InSequence s;
105 uint8 buffer[] = {0x0, 0x08}; 129 uint8 buffer[] = {0x0, 0x08};
106 std::vector<uint8> data; 130 std::vector<uint8> data;
107 131
108 data.assign(buffer, buffer + sizeof(buffer)); 132 data.assign(buffer, buffer + sizeof(buffer));
109 133
134 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.0"));
110 EXPECT_FALSE(Parse(data)); 135 EXPECT_FALSE(Parse(data));
111 136
112 data[0] = 0x08; 137 data[0] = 0x08;
138 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1"));
113 EXPECT_TRUE(Parse(data)); 139 EXPECT_TRUE(Parse(data));
114 140
115 data[0] = 0x28; 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.
116 EXPECT_FALSE(Parse(data)); 144 EXPECT_FALSE(Parse(data));
117 } 145 }
118 146
119 TEST_F(AACTest, IncorrectFrequencyTest) { 147 TEST_F(AACTest, IncorrectFrequencyTest) {
120 uint8 buffer[] = {0x0f, 0x88}; 148 uint8 buffer[] = {0x0f, 0x88};
121 std::vector<uint8> data; 149 std::vector<uint8> data;
122 150
123 data.assign(buffer, buffer + sizeof(buffer)); 151 data.assign(buffer, buffer + sizeof(buffer));
124 152
125 EXPECT_FALSE(Parse(data)); 153 EXPECT_FALSE(Parse(data));
126 154
127 data[0] = 0x0e; 155 data[0] = 0x0e;
128 data[1] = 0x08; 156 data[1] = 0x08;
157 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1"));
129 EXPECT_TRUE(Parse(data)); 158 EXPECT_TRUE(Parse(data));
130 } 159 }
131 160
132 TEST_F(AACTest, IncorrectChannelTest) { 161 TEST_F(AACTest, IncorrectChannelTest) {
133 uint8 buffer[] = {0x0e, 0x00}; 162 uint8 buffer[] = {0x0e, 0x00};
134 std::vector<uint8> data; 163 std::vector<uint8> data;
135 164
136 data.assign(buffer, buffer + sizeof(buffer)); 165 data.assign(buffer, buffer + sizeof(buffer));
137 166
167 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1")).Times(2);
168
138 EXPECT_FALSE(Parse(data)); 169 EXPECT_FALSE(Parse(data));
139 170
140 data[1] = 0x08; 171 data[1] = 0x08;
141 EXPECT_TRUE(Parse(data)); 172 EXPECT_TRUE(Parse(data));
142 } 173 }
143 174
144 } // namespace mp4 175 } // namespace mp4
145 176
146 } // namespace media 177 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/formats/mp4/box_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698