OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_device/fine_audio_buffer.h" | 11 #include "webrtc/modules/audio_device/fine_audio_buffer.h" |
12 | 12 |
13 #include <limits.h> | 13 #include <limits.h> |
14 #include <memory> | 14 #include <memory> |
15 | 15 |
16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webrtc/base/scoped_ptr.h" | |
19 #include "webrtc/modules/audio_device/mock_audio_device_buffer.h" | 18 #include "webrtc/modules/audio_device/mock_audio_device_buffer.h" |
20 | 19 |
21 using ::testing::_; | 20 using ::testing::_; |
22 using ::testing::AtLeast; | 21 using ::testing::AtLeast; |
23 using ::testing::InSequence; | 22 using ::testing::InSequence; |
24 using ::testing::Return; | 23 using ::testing::Return; |
25 | 24 |
26 namespace webrtc { | 25 namespace webrtc { |
27 | 26 |
28 // The fake audio data is 0,1,..SCHAR_MAX-1,0,1,... This is to make it easy | 27 // The fake audio data is 0,1,..SCHAR_MAX-1,0,1,... This is to make it easy |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 110 } |
112 EXPECT_CALL(audio_device_buffer, SetVQEData(_, _, _)) | 111 EXPECT_CALL(audio_device_buffer, SetVQEData(_, _, _)) |
113 .Times(kNumberOfUpdateBufferCalls - 1); | 112 .Times(kNumberOfUpdateBufferCalls - 1); |
114 EXPECT_CALL(audio_device_buffer, DeliverRecordedData()) | 113 EXPECT_CALL(audio_device_buffer, DeliverRecordedData()) |
115 .Times(kNumberOfUpdateBufferCalls - 1) | 114 .Times(kNumberOfUpdateBufferCalls - 1) |
116 .WillRepeatedly(Return(kSamplesPer10Ms)); | 115 .WillRepeatedly(Return(kSamplesPer10Ms)); |
117 | 116 |
118 FineAudioBuffer fine_buffer(&audio_device_buffer, kFrameSizeBytes, | 117 FineAudioBuffer fine_buffer(&audio_device_buffer, kFrameSizeBytes, |
119 sample_rate); | 118 sample_rate); |
120 | 119 |
121 rtc::scoped_ptr<int8_t[]> out_buffer; | 120 std::unique_ptr<int8_t[]> out_buffer; |
122 out_buffer.reset(new int8_t[fine_buffer.RequiredPlayoutBufferSizeBytes()]); | 121 out_buffer.reset(new int8_t[fine_buffer.RequiredPlayoutBufferSizeBytes()]); |
123 rtc::scoped_ptr<int8_t[]> in_buffer; | 122 std::unique_ptr<int8_t[]> in_buffer; |
124 in_buffer.reset(new int8_t[kFrameSizeBytes]); | 123 in_buffer.reset(new int8_t[kFrameSizeBytes]); |
125 for (int i = 0; i < kNumberOfFrames; ++i) { | 124 for (int i = 0; i < kNumberOfFrames; ++i) { |
126 fine_buffer.GetPlayoutData(out_buffer.get()); | 125 fine_buffer.GetPlayoutData(out_buffer.get()); |
127 EXPECT_TRUE(VerifyBuffer(out_buffer.get(), i, kFrameSizeBytes)); | 126 EXPECT_TRUE(VerifyBuffer(out_buffer.get(), i, kFrameSizeBytes)); |
128 UpdateInputBuffer(in_buffer.get(), i, kFrameSizeBytes); | 127 UpdateInputBuffer(in_buffer.get(), i, kFrameSizeBytes); |
129 fine_buffer.DeliverRecordedData(in_buffer.get(), kFrameSizeBytes, 0, 0); | 128 fine_buffer.DeliverRecordedData(in_buffer.get(), kFrameSizeBytes, 0, 0); |
130 } | 129 } |
131 } | 130 } |
132 | 131 |
133 TEST(FineBufferTest, BufferLessThan10ms) { | 132 TEST(FineBufferTest, BufferLessThan10ms) { |
134 const int kSampleRate = 44100; | 133 const int kSampleRate = 44100; |
135 const int kSamplesPer10Ms = kSampleRate * 10 / 1000; | 134 const int kSamplesPer10Ms = kSampleRate * 10 / 1000; |
136 const int kFrameSizeSamples = kSamplesPer10Ms - 50; | 135 const int kFrameSizeSamples = kSamplesPer10Ms - 50; |
137 RunFineBufferTest(kSampleRate, kFrameSizeSamples); | 136 RunFineBufferTest(kSampleRate, kFrameSizeSamples); |
138 } | 137 } |
139 | 138 |
140 TEST(FineBufferTest, GreaterThan10ms) { | 139 TEST(FineBufferTest, GreaterThan10ms) { |
141 const int kSampleRate = 44100; | 140 const int kSampleRate = 44100; |
142 const int kSamplesPer10Ms = kSampleRate * 10 / 1000; | 141 const int kSamplesPer10Ms = kSampleRate * 10 / 1000; |
143 const int kFrameSizeSamples = kSamplesPer10Ms + 50; | 142 const int kFrameSizeSamples = kSamplesPer10Ms + 50; |
144 RunFineBufferTest(kSampleRate, kFrameSizeSamples); | 143 RunFineBufferTest(kSampleRate, kFrameSizeSamples); |
145 } | 144 } |
146 | 145 |
147 } // namespace webrtc | 146 } // namespace webrtc |
OLD | NEW |