Chromium Code Reviews| 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 4 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 5 #define _USE_MATH_DEFINES | 5 #define _USE_MATH_DEFINES |
| 6 | 6 |
| 7 #include "media/audio/simple_sources.h" | 7 #include "media/audio/simple_sources.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <cmath> | 12 #include <cmath> |
| 13 | 13 |
| 14 #include "base/files/file.h" | 14 #include "base/files/file.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "media/audio/sounds/wav_audio_handler.h" | 17 #include "media/audio/sounds/wav_audio_handler.h" |
| 18 #include "media/base/audio_bus.h" | 18 #include "media/base/audio_bus.h" |
| 19 | 19 |
| 20 namespace media { | 20 namespace media { |
| 21 namespace { | 21 namespace { |
| 22 // Opens |wav_filename|, reads it and loads it as a wav file. This function will | 22 // Opens |wav_filename|, reads it and loads it as a wav file. This function will |
| 23 // return a null pointer if we can't read the file or if it's malformed. The | 23 // return a null pointer if we can't read the file or if it's malformed. The |
| 24 // caller takes ownership of the returned data. The size of the data is stored | 24 // caller takes ownership of the returned data. The size of the data is stored |
| 25 // in |read_length|. | 25 // in |read_length|. |
| 26 scoped_ptr<char[]> ReadWavFile(const base::FilePath& wav_filename, | 26 std::unique_ptr<char[]> ReadWavFile(const base::FilePath& wav_filename, |
| 27 size_t* read_length) { | 27 size_t* read_length) { |
| 28 base::File wav_file( | 28 base::File wav_file( |
| 29 wav_filename, base::File::FLAG_OPEN | base::File::FLAG_READ); | 29 wav_filename, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 30 if (!wav_file.IsValid()) { | 30 if (!wav_file.IsValid()) { |
| 31 LOG(ERROR) << "Failed to read " << wav_filename.value() | 31 LOG(ERROR) << "Failed to read " << wav_filename.value() |
| 32 << " as input to the fake device."; | 32 << " as input to the fake device."; |
| 33 return nullptr; | 33 return nullptr; |
| 34 } | 34 } |
| 35 | 35 |
| 36 size_t wav_file_length = wav_file.GetLength(); | 36 size_t wav_file_length = wav_file.GetLength(); |
| 37 if (wav_file_length == 0u) { | 37 if (wav_file_length == 0u) { |
| 38 LOG(ERROR) << "Input file to fake device is empty: " | 38 LOG(ERROR) << "Input file to fake device is empty: " |
| 39 << wav_filename.value(); | 39 << wav_filename.value(); |
| 40 return nullptr; | 40 return nullptr; |
| 41 } | 41 } |
| 42 | 42 |
| 43 scoped_ptr<char[]> data(new char[wav_file_length]); | 43 std::unique_ptr<char[]> data(new char[wav_file_length]); |
|
danakj
2016/04/22 22:47:37
include memory
dcheng
2016/04/22 23:13:20
Already in related header.
| |
| 44 size_t read_bytes = wav_file.Read(0, data.get(), wav_file_length); | 44 size_t read_bytes = wav_file.Read(0, data.get(), wav_file_length); |
| 45 if (read_bytes != wav_file_length) { | 45 if (read_bytes != wav_file_length) { |
| 46 LOG(ERROR) << "Failed to read all bytes of " << wav_filename.value(); | 46 LOG(ERROR) << "Failed to read all bytes of " << wav_filename.value(); |
| 47 return nullptr; | 47 return nullptr; |
| 48 } | 48 } |
| 49 *read_length = wav_file_length; | 49 *read_length = wav_file_length; |
| 50 return data; | 50 return data; |
| 51 } | 51 } |
| 52 | 52 |
| 53 // These values are based on experiments for local-to-local | 53 // These values are based on experiments for local-to-local |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 } | 298 } |
| 299 | 299 |
| 300 void BeepingSource::OnError(AudioOutputStream* stream) { | 300 void BeepingSource::OnError(AudioOutputStream* stream) { |
| 301 } | 301 } |
| 302 | 302 |
| 303 void BeepingSource::BeepOnce() { | 303 void BeepingSource::BeepOnce() { |
| 304 g_beep_context.Pointer()->SetBeepOnce(true); | 304 g_beep_context.Pointer()->SetBeepOnce(true); |
| 305 } | 305 } |
| 306 | 306 |
| 307 } // namespace media | 307 } // namespace media |
| OLD | NEW |