| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/environment.h" | 9 #include "base/environment.h" |
| 8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 10 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 11 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 12 #include "media/audio/audio_io.h" | 14 #include "media/audio/audio_io.h" |
| 13 #include "media/audio/audio_manager_base.h" | 15 #include "media/audio/audio_manager_base.h" |
| 14 #include "media/audio/audio_unittest_util.h" | 16 #include "media/audio/audio_unittest_util.h" |
| 15 #include "media/audio/mac/audio_low_latency_input_mac.h" | 17 #include "media/audio/mac/audio_low_latency_input_mac.h" |
| 16 #include "media/base/seekable_buffer.h" | 18 #include "media/base/seekable_buffer.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 77 } |
| 76 fclose(file_); | 78 fclose(file_); |
| 77 } | 79 } |
| 78 | 80 |
| 79 // AudioInputStream::AudioInputCallback implementation. | 81 // AudioInputStream::AudioInputCallback implementation. |
| 80 void OnData(AudioInputStream* stream, | 82 void OnData(AudioInputStream* stream, |
| 81 const AudioBus* src, | 83 const AudioBus* src, |
| 82 uint32_t hardware_delay_bytes, | 84 uint32_t hardware_delay_bytes, |
| 83 double volume) override { | 85 double volume) override { |
| 84 const int num_samples = src->frames() * src->channels(); | 86 const int num_samples = src->frames() * src->channels(); |
| 85 scoped_ptr<int16_t> interleaved(new int16_t[num_samples]); | 87 std::unique_ptr<int16_t> interleaved(new int16_t[num_samples]); |
| 86 const int bytes_per_sample = sizeof(*interleaved); | 88 const int bytes_per_sample = sizeof(*interleaved); |
| 87 src->ToInterleaved(src->frames(), bytes_per_sample, interleaved.get()); | 89 src->ToInterleaved(src->frames(), bytes_per_sample, interleaved.get()); |
| 88 | 90 |
| 89 // Store data data in a temporary buffer to avoid making blocking | 91 // Store data data in a temporary buffer to avoid making blocking |
| 90 // fwrite() calls in the audio callback. The complete buffer will be | 92 // fwrite() calls in the audio callback. The complete buffer will be |
| 91 // written to file in the destructor. | 93 // written to file in the destructor. |
| 92 const int size = bytes_per_sample * num_samples; | 94 const int size = bytes_per_sample * num_samples; |
| 93 if (buffer_.Append((const uint8_t*)interleaved.get(), size)) { | 95 if (buffer_.Append((const uint8_t*)interleaved.get(), size)) { |
| 94 bytes_to_write_ += size; | 96 bytes_to_write_ += size; |
| 95 } | 97 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 WriteToFileAudioSink file_sink(file_name); | 269 WriteToFileAudioSink file_sink(file_name); |
| 268 fprintf(stderr, " >> Speak into the mic while recording...\n"); | 270 fprintf(stderr, " >> Speak into the mic while recording...\n"); |
| 269 ais->Start(&file_sink); | 271 ais->Start(&file_sink); |
| 270 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 272 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
| 271 ais->Stop(); | 273 ais->Stop(); |
| 272 fprintf(stderr, " >> Recording has stopped.\n"); | 274 fprintf(stderr, " >> Recording has stopped.\n"); |
| 273 ais->Close(); | 275 ais->Close(); |
| 274 } | 276 } |
| 275 | 277 |
| 276 } // namespace media | 278 } // namespace media |
| OLD | NEW |