| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 static const size_t kMaxBufferSize = 2 * 2 * 480 * 100 * 10; | 95 static const size_t kMaxBufferSize = 2 * 2 * 480 * 100 * 10; |
| 96 | 96 |
| 97 explicit WriteToFileAudioSink(const char* file_name) | 97 explicit WriteToFileAudioSink(const char* file_name) |
| 98 : buffer_(0, kMaxBufferSize), | 98 : buffer_(0, kMaxBufferSize), |
| 99 bytes_to_write_(0) { | 99 bytes_to_write_(0) { |
| 100 base::FilePath file_path; | 100 base::FilePath file_path; |
| 101 EXPECT_TRUE(PathService::Get(base::DIR_EXE, &file_path)); | 101 EXPECT_TRUE(PathService::Get(base::DIR_EXE, &file_path)); |
| 102 file_path = file_path.AppendASCII(file_name); | 102 file_path = file_path.AppendASCII(file_name); |
| 103 binary_file_ = file_util::OpenFile(file_path, "wb"); | 103 binary_file_ = file_util::OpenFile(file_path, "wb"); |
| 104 DLOG_IF(ERROR, !binary_file_) << "Failed to open binary PCM data file."; | 104 DLOG_IF(ERROR, !binary_file_) << "Failed to open binary PCM data file."; |
| 105 LOG(INFO) << ">> Output file: " << file_path.value() | 105 VLOG(0) << ">> Output file: " << file_path.value() << " has been created."; |
| 106 << " has been created."; | |
| 107 } | 106 } |
| 108 | 107 |
| 109 virtual ~WriteToFileAudioSink() { | 108 virtual ~WriteToFileAudioSink() { |
| 110 size_t bytes_written = 0; | 109 size_t bytes_written = 0; |
| 111 while (bytes_written < bytes_to_write_) { | 110 while (bytes_written < bytes_to_write_) { |
| 112 const uint8* chunk; | 111 const uint8* chunk; |
| 113 int chunk_size; | 112 int chunk_size; |
| 114 | 113 |
| 115 // Stop writing if no more data is available. | 114 // Stop writing if no more data is available. |
| 116 if (!buffer_.GetCurrentChunk(&chunk, &chunk_size)) | 115 if (!buffer_.GetCurrentChunk(&chunk, &chunk_size)) |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 493 |
| 495 // Name of the output PCM file containing captured data. The output file | 494 // Name of the output PCM file containing captured data. The output file |
| 496 // will be stored in the directory containing 'media_unittests.exe'. | 495 // will be stored in the directory containing 'media_unittests.exe'. |
| 497 // Example of full name: \src\build\Debug\out_stereo_10sec.pcm. | 496 // Example of full name: \src\build\Debug\out_stereo_10sec.pcm. |
| 498 const char* file_name = "out_stereo_10sec.pcm"; | 497 const char* file_name = "out_stereo_10sec.pcm"; |
| 499 | 498 |
| 500 AudioInputStreamWrapper aisw(audio_manager.get()); | 499 AudioInputStreamWrapper aisw(audio_manager.get()); |
| 501 ScopedAudioInputStream ais(aisw.Create()); | 500 ScopedAudioInputStream ais(aisw.Create()); |
| 502 EXPECT_TRUE(ais->Open()); | 501 EXPECT_TRUE(ais->Open()); |
| 503 | 502 |
| 504 LOG(INFO) << ">> Sample rate: " << aisw.sample_rate() << " [Hz]"; | 503 VLOG(0) << ">> Sample rate: " << aisw.sample_rate() << " [Hz]"; |
| 505 WriteToFileAudioSink file_sink(file_name); | 504 WriteToFileAudioSink file_sink(file_name); |
| 506 LOG(INFO) << ">> Speak into the default microphone while recording."; | 505 VLOG(0) << ">> Speak into the default microphone while recording."; |
| 507 ais->Start(&file_sink); | 506 ais->Start(&file_sink); |
| 508 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 507 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
| 509 ais->Stop(); | 508 ais->Stop(); |
| 510 LOG(INFO) << ">> Recording has stopped."; | 509 VLOG(0) << ">> Recording has stopped."; |
| 511 ais.Close(); | 510 ais.Close(); |
| 512 } | 511 } |
| 513 | 512 |
| 514 } // namespace media | 513 } // namespace media |
| OLD | NEW |