OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/audio/win/audio_low_latency_input_win.h" |
| 6 |
5 #include <windows.h> | 7 #include <windows.h> |
6 #include <mmsystem.h> | 8 #include <mmsystem.h> |
7 #include <stddef.h> | 9 #include <stddef.h> |
8 #include <stdint.h> | 10 #include <stdint.h> |
9 | 11 |
| 12 #include <memory> |
| 13 |
10 #include "base/environment.h" | 14 #include "base/environment.h" |
11 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
12 #include "base/macros.h" | 16 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
15 #include "base/path_service.h" | 18 #include "base/path_service.h" |
16 #include "base/test/test_timeouts.h" | 19 #include "base/test/test_timeouts.h" |
17 #include "base/win/scoped_com_initializer.h" | 20 #include "base/win/scoped_com_initializer.h" |
18 #include "media/audio/audio_io.h" | 21 #include "media/audio/audio_io.h" |
19 #include "media/audio/audio_manager_base.h" | 22 #include "media/audio/audio_manager_base.h" |
20 #include "media/audio/audio_unittest_util.h" | 23 #include "media/audio/audio_unittest_util.h" |
21 #include "media/audio/win/audio_low_latency_input_win.h" | |
22 #include "media/audio/win/core_audio_util_win.h" | 24 #include "media/audio/win/core_audio_util_win.h" |
23 #include "media/base/seekable_buffer.h" | 25 #include "media/base/seekable_buffer.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
26 | 28 |
27 using ::testing::_; | 29 using ::testing::_; |
28 using ::testing::AnyNumber; | 30 using ::testing::AnyNumber; |
29 using ::testing::AtLeast; | 31 using ::testing::AtLeast; |
30 using ::testing::Gt; | 32 using ::testing::Gt; |
31 using ::testing::NotNull; | 33 using ::testing::NotNull; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 base::CloseFile(binary_file_); | 126 base::CloseFile(binary_file_); |
125 } | 127 } |
126 | 128 |
127 // AudioInputStream::AudioInputCallback implementation. | 129 // AudioInputStream::AudioInputCallback implementation. |
128 void OnData(AudioInputStream* stream, | 130 void OnData(AudioInputStream* stream, |
129 const AudioBus* src, | 131 const AudioBus* src, |
130 uint32_t hardware_delay_bytes, | 132 uint32_t hardware_delay_bytes, |
131 double volume) override { | 133 double volume) override { |
132 EXPECT_EQ(bits_per_sample_, 16); | 134 EXPECT_EQ(bits_per_sample_, 16); |
133 const int num_samples = src->frames() * src->channels(); | 135 const int num_samples = src->frames() * src->channels(); |
134 scoped_ptr<int16_t> interleaved(new int16_t[num_samples]); | 136 std::unique_ptr<int16_t> interleaved(new int16_t[num_samples]); |
135 const int bytes_per_sample = sizeof(*interleaved); | 137 const int bytes_per_sample = sizeof(*interleaved); |
136 src->ToInterleaved(src->frames(), bytes_per_sample, interleaved.get()); | 138 src->ToInterleaved(src->frames(), bytes_per_sample, interleaved.get()); |
137 | 139 |
138 // Store data data in a temporary buffer to avoid making blocking | 140 // Store data data in a temporary buffer to avoid making blocking |
139 // fwrite() calls in the audio callback. The complete buffer will be | 141 // fwrite() calls in the audio callback. The complete buffer will be |
140 // written to file in the destructor. | 142 // written to file in the destructor. |
141 const int size = bytes_per_sample * num_samples; | 143 const int size = bytes_per_sample * num_samples; |
142 if (buffer_.Append((const uint8_t*)interleaved.get(), size)) { | 144 if (buffer_.Append((const uint8_t*)interleaved.get(), size)) { |
143 bytes_to_write_ += size; | 145 bytes_to_write_ += size; |
144 } | 146 } |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 WriteToFileAudioSink file_sink(file_name, aisw.bits_per_sample()); | 474 WriteToFileAudioSink file_sink(file_name, aisw.bits_per_sample()); |
473 VLOG(0) << ">> Speak into the default microphone while recording."; | 475 VLOG(0) << ">> Speak into the default microphone while recording."; |
474 ais->Start(&file_sink); | 476 ais->Start(&file_sink); |
475 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 477 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
476 ais->Stop(); | 478 ais->Stop(); |
477 VLOG(0) << ">> Recording has stopped."; | 479 VLOG(0) << ">> Recording has stopped."; |
478 ais.Close(); | 480 ais.Close(); |
479 } | 481 } |
480 | 482 |
481 } // namespace media | 483 } // namespace media |
OLD | NEW |