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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // the recorded data is stored on a raw binary data file. | 49 // the recorded data is stored on a raw binary data file. |
50 class WriteToFileAudioSink : public AudioInputStream::AudioInputCallback { | 50 class WriteToFileAudioSink : public AudioInputStream::AudioInputCallback { |
51 public: | 51 public: |
52 // Allocate space for ~10 seconds of data @ 48kHz in stereo: | 52 // Allocate space for ~10 seconds of data @ 48kHz in stereo: |
53 // 2 bytes per sample, 2 channels, 10ms @ 48kHz, 10 seconds <=> 1920000 bytes. | 53 // 2 bytes per sample, 2 channels, 10ms @ 48kHz, 10 seconds <=> 1920000 bytes. |
54 static const size_t kMaxBufferSize = 2 * 2 * 480 * 100 * 10; | 54 static const size_t kMaxBufferSize = 2 * 2 * 480 * 100 * 10; |
55 | 55 |
56 explicit WriteToFileAudioSink(const char* file_name) | 56 explicit WriteToFileAudioSink(const char* file_name) |
57 : buffer_(0, kMaxBufferSize), | 57 : buffer_(0, kMaxBufferSize), |
58 bytes_to_write_(0) { | 58 bytes_to_write_(0) { |
59 FilePath file_path; | 59 base::FilePath file_path; |
60 EXPECT_TRUE(PathService::Get(base::DIR_EXE, &file_path)); | 60 EXPECT_TRUE(PathService::Get(base::DIR_EXE, &file_path)); |
61 file_path = file_path.AppendASCII(file_name); | 61 file_path = file_path.AppendASCII(file_name); |
62 binary_file_ = file_util::OpenFile(file_path, "wb"); | 62 binary_file_ = file_util::OpenFile(file_path, "wb"); |
63 DLOG_IF(ERROR, !binary_file_) << "Failed to open binary PCM data file."; | 63 DLOG_IF(ERROR, !binary_file_) << "Failed to open binary PCM data file."; |
64 LOG(INFO) << ">> Output file: " << file_path.value() | 64 LOG(INFO) << ">> Output file: " << file_path.value() |
65 << " has been created."; | 65 << " has been created."; |
66 } | 66 } |
67 | 67 |
68 virtual ~WriteToFileAudioSink() { | 68 virtual ~WriteToFileAudioSink() { |
69 size_t bytes_written = 0; | 69 size_t bytes_written = 0; |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 WriteToFileAudioSink file_sink(file_name); | 396 WriteToFileAudioSink file_sink(file_name); |
397 LOG(INFO) << ">> Speak into the default microphone while recording."; | 397 LOG(INFO) << ">> Speak into the default microphone while recording."; |
398 ais->Start(&file_sink); | 398 ais->Start(&file_sink); |
399 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 399 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
400 ais->Stop(); | 400 ais->Stop(); |
401 LOG(INFO) << ">> Recording has stopped."; | 401 LOG(INFO) << ">> Recording has stopped."; |
402 ais->Close(); | 402 ais->Close(); |
403 } | 403 } |
404 | 404 |
405 } // namespace media | 405 } // namespace media |
OLD | NEW |