Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Side by Side Diff: trunk/src/media/audio/win/audio_low_latency_input_win_unittest.cc

Issue 105823009: Revert 239280 "Move more file_util functions to base namespace." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // Allocate space for ~10 seconds of data @ 48kHz in stereo: 93 // Allocate space for ~10 seconds of data @ 48kHz in stereo:
94 // 2 bytes per sample, 2 channels, 10ms @ 48kHz, 10 seconds <=> 1920000 bytes. 94 // 2 bytes per sample, 2 channels, 10ms @ 48kHz, 10 seconds <=> 1920000 bytes.
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_ = base::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 VLOG(0) << ">> Output file: " << file_path.value() << " has been created."; 105 VLOG(0) << ">> Output file: " << file_path.value() << " has been created.";
106 } 106 }
107 107
108 virtual ~WriteToFileAudioSink() { 108 virtual ~WriteToFileAudioSink() {
109 size_t bytes_written = 0; 109 size_t bytes_written = 0;
110 while (bytes_written < bytes_to_write_) { 110 while (bytes_written < bytes_to_write_) {
111 const uint8* chunk; 111 const uint8* chunk;
112 int chunk_size; 112 int chunk_size;
113 113
114 // Stop writing if no more data is available. 114 // Stop writing if no more data is available.
115 if (!buffer_.GetCurrentChunk(&chunk, &chunk_size)) 115 if (!buffer_.GetCurrentChunk(&chunk, &chunk_size))
116 break; 116 break;
117 117
118 // Write recorded data chunk to the file and prepare for next chunk. 118 // Write recorded data chunk to the file and prepare for next chunk.
119 fwrite(chunk, 1, chunk_size, binary_file_); 119 fwrite(chunk, 1, chunk_size, binary_file_);
120 buffer_.Seek(chunk_size); 120 buffer_.Seek(chunk_size);
121 bytes_written += chunk_size; 121 bytes_written += chunk_size;
122 } 122 }
123 base::CloseFile(binary_file_); 123 file_util::CloseFile(binary_file_);
124 } 124 }
125 125
126 // AudioInputStream::AudioInputCallback implementation. 126 // AudioInputStream::AudioInputCallback implementation.
127 virtual void OnData(AudioInputStream* stream, 127 virtual void OnData(AudioInputStream* stream,
128 const uint8* src, 128 const uint8* src,
129 uint32 size, 129 uint32 size,
130 uint32 hardware_delay_bytes, 130 uint32 hardware_delay_bytes,
131 double volume) { 131 double volume) {
132 // Store data data in a temporary buffer to avoid making blocking 132 // Store data data in a temporary buffer to avoid making blocking
133 // fwrite() calls in the audio callback. The complete buffer will be 133 // fwrite() calls in the audio callback. The complete buffer will be
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 WriteToFileAudioSink file_sink(file_name); 504 WriteToFileAudioSink file_sink(file_name);
505 VLOG(0) << ">> Speak into the default microphone while recording."; 505 VLOG(0) << ">> Speak into the default microphone while recording.";
506 ais->Start(&file_sink); 506 ais->Start(&file_sink);
507 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); 507 base::PlatformThread::Sleep(TestTimeouts::action_timeout());
508 ais->Stop(); 508 ais->Stop();
509 VLOG(0) << ">> Recording has stopped."; 509 VLOG(0) << ">> Recording has stopped.";
510 ais.Close(); 510 ais.Close();
511 } 511 }
512 512
513 } // namespace media 513 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698