| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/environment.h" | 6 #include "base/environment.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
| 9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
| 10 #include "media/audio/audio_io.h" | 10 #include "media/audio/audio_io.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 fwrite(chunk, 1, chunk_size, file_); | 68 fwrite(chunk, 1, chunk_size, file_); |
| 69 buffer_.Seek(chunk_size); | 69 buffer_.Seek(chunk_size); |
| 70 bytes_written += chunk_size; | 70 bytes_written += chunk_size; |
| 71 } | 71 } |
| 72 fclose(file_); | 72 fclose(file_); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // AudioInputStream::AudioInputCallback implementation. | 75 // AudioInputStream::AudioInputCallback implementation. |
| 76 virtual void OnData(AudioInputStream* stream, | 76 virtual void OnData(AudioInputStream* stream, |
| 77 const uint8* src, uint32 size, | 77 const uint8* src, uint32 size, |
| 78 uint32 hardware_delay_bytes, double volume) { | 78 uint32 hardware_delay_bytes, double volume) OVERRIDE { |
| 79 // Store data data in a temporary buffer to avoid making blocking | 79 // Store data data in a temporary buffer to avoid making blocking |
| 80 // fwrite() calls in the audio callback. The complete buffer will be | 80 // fwrite() calls in the audio callback. The complete buffer will be |
| 81 // written to file in the destructor. | 81 // written to file in the destructor. |
| 82 if (buffer_.Append(src, size)) { | 82 if (buffer_.Append(src, size)) { |
| 83 bytes_to_write_ += size; | 83 bytes_to_write_ += size; |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual void OnClose(AudioInputStream* stream) {} | 87 virtual void OnClose(AudioInputStream* stream) OVERRIDE {} |
| 88 virtual void OnError(AudioInputStream* stream, int code) {} | 88 virtual void OnError(AudioInputStream* stream, int code) OVERRIDE {} |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 media::SeekableBuffer buffer_; | 91 media::SeekableBuffer buffer_; |
| 92 FILE* file_; | 92 FILE* file_; |
| 93 int bytes_to_write_; | 93 int bytes_to_write_; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 class MacAudioInputTest : public testing::Test { | 96 class MacAudioInputTest : public testing::Test { |
| 97 protected: | 97 protected: |
| 98 MacAudioInputTest() : audio_manager_(AudioManager::Create()) {} | 98 MacAudioInputTest() : audio_manager_(AudioManager::Create()) {} |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 WriteToFileAudioSink file_sink(file_name); | 308 WriteToFileAudioSink file_sink(file_name); |
| 309 fprintf(stderr, " >> Speak into the mic while recording...\n"); | 309 fprintf(stderr, " >> Speak into the mic while recording...\n"); |
| 310 ais->Start(&file_sink); | 310 ais->Start(&file_sink); |
| 311 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 311 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
| 312 ais->Stop(); | 312 ais->Stop(); |
| 313 fprintf(stderr, " >> Recording has stopped.\n"); | 313 fprintf(stderr, " >> Recording has stopped.\n"); |
| 314 ais->Close(); | 314 ais->Close(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 } // namespace media | 317 } // namespace media |
| OLD | NEW |