OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 const std::string& file_name) | 211 const std::string& file_name) |
212 : event_(event), params_(params) { | 212 : event_(event), params_(params) { |
213 // Allocate space for ~10 seconds of data. | 213 // Allocate space for ~10 seconds of data. |
214 const int kMaxBufferSize = 10 * params.GetBytesPerSecond(); | 214 const int kMaxBufferSize = 10 * params.GetBytesPerSecond(); |
215 buffer_.reset(new media::SeekableBuffer(0, kMaxBufferSize)); | 215 buffer_.reset(new media::SeekableBuffer(0, kMaxBufferSize)); |
216 | 216 |
217 // Open up the binary file which will be written to in the destructor. | 217 // Open up the binary file which will be written to in the destructor. |
218 base::FilePath file_path; | 218 base::FilePath file_path; |
219 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); | 219 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); |
220 file_path = file_path.AppendASCII(file_name.c_str()); | 220 file_path = file_path.AppendASCII(file_name.c_str()); |
221 binary_file_ = file_util::OpenFile(file_path, "wb"); | 221 binary_file_ = base::OpenFile(file_path, "wb"); |
222 DLOG_IF(ERROR, !binary_file_) << "Failed to open binary PCM data file."; | 222 DLOG_IF(ERROR, !binary_file_) << "Failed to open binary PCM data file."; |
223 VLOG(0) << "Writing to file: " << file_path.value().c_str(); | 223 VLOG(0) << "Writing to file: " << file_path.value().c_str(); |
224 } | 224 } |
225 | 225 |
226 virtual ~FileAudioSink() { | 226 virtual ~FileAudioSink() { |
227 int bytes_written = 0; | 227 int bytes_written = 0; |
228 while (bytes_written < buffer_->forward_capacity()) { | 228 while (bytes_written < buffer_->forward_capacity()) { |
229 const uint8* chunk; | 229 const uint8* chunk; |
230 int chunk_size; | 230 int chunk_size; |
231 | 231 |
232 // Stop writing if no more data is available. | 232 // Stop writing if no more data is available. |
233 if (!buffer_->GetCurrentChunk(&chunk, &chunk_size)) | 233 if (!buffer_->GetCurrentChunk(&chunk, &chunk_size)) |
234 break; | 234 break; |
235 | 235 |
236 // Write recorded data chunk to the file and prepare for next chunk. | 236 // Write recorded data chunk to the file and prepare for next chunk. |
237 // TODO(henrika): use file_util:: instead. | 237 // TODO(henrika): use file_util:: instead. |
238 fwrite(chunk, 1, chunk_size, binary_file_); | 238 fwrite(chunk, 1, chunk_size, binary_file_); |
239 buffer_->Seek(chunk_size); | 239 buffer_->Seek(chunk_size); |
240 bytes_written += chunk_size; | 240 bytes_written += chunk_size; |
241 } | 241 } |
242 file_util::CloseFile(binary_file_); | 242 base::CloseFile(binary_file_); |
243 } | 243 } |
244 | 244 |
245 // AudioInputStream::AudioInputCallback implementation. | 245 // AudioInputStream::AudioInputCallback implementation. |
246 virtual void OnData(AudioInputStream* stream, | 246 virtual void OnData(AudioInputStream* stream, |
247 const uint8* src, | 247 const uint8* src, |
248 uint32 size, | 248 uint32 size, |
249 uint32 hardware_delay_bytes, | 249 uint32 hardware_delay_bytes, |
250 double volume) OVERRIDE { | 250 double volume) OVERRIDE { |
251 // Store data data in a temporary buffer to avoid making blocking | 251 // Store data data in a temporary buffer to avoid making blocking |
252 // fwrite() calls in the audio callback. The complete buffer will be | 252 // fwrite() calls in the audio callback. The complete buffer will be |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 fflush(stdout); | 760 fflush(stdout); |
761 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 761 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
762 printf("\n"); | 762 printf("\n"); |
763 aos->Stop(); | 763 aos->Stop(); |
764 ais->Stop(); | 764 ais->Stop(); |
765 aos->Close(); | 765 aos->Close(); |
766 ais->Close(); | 766 ais->Close(); |
767 } | 767 } |
768 | 768 |
769 } // namespace media | 769 } // namespace media |
OLD | NEW |