| 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 #include <cmath> | 6 #include <cmath> |
| 7 | 7 |
| 8 #include "media/audio/simple_sources.h" | 8 #include "media/audio/simple_sources.h" |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 size_t read_bytes = wav_file.Read(0, reinterpret_cast<char*>(wav_file_data), | 42 size_t read_bytes = wav_file.Read(0, reinterpret_cast<char*>(wav_file_data), |
| 43 wav_file_length); | 43 wav_file_length); |
| 44 if (read_bytes != wav_file_length) { | 44 if (read_bytes != wav_file_length) { |
| 45 LOG(ERROR) << "Failed to read all bytes of " << wav_filename.value(); | 45 LOG(ERROR) << "Failed to read all bytes of " << wav_filename.value(); |
| 46 return nullptr; | 46 return nullptr; |
| 47 } | 47 } |
| 48 *file_length = wav_file_length; | 48 *file_length = wav_file_length; |
| 49 return scoped_ptr<uint8[]>(wav_file_data); | 49 return scoped_ptr<uint8[]>(wav_file_data); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Opens |wav_filename|, reads it and loads it as a wav file. This function will | |
| 53 // bluntly trigger CHECKs if we can't read the file or if it's malformed. | |
| 54 static scoped_ptr<WavAudioHandler> CreateWavAudioHandler( | |
| 55 const base::FilePath& wav_filename, const uint8* wav_file_data, | |
| 56 size_t wav_file_length, const AudioParameters& expected_params) { | |
| 57 base::StringPiece wav_data(reinterpret_cast<const char*>(wav_file_data), | |
| 58 wav_file_length); | |
| 59 scoped_ptr<WavAudioHandler> wav_audio_handler(new WavAudioHandler(wav_data)); | |
| 60 return wav_audio_handler.Pass(); | |
| 61 } | |
| 62 | |
| 63 // These values are based on experiments for local-to-local | 52 // These values are based on experiments for local-to-local |
| 64 // PeerConnection to demonstrate audio/video synchronization. | 53 // PeerConnection to demonstrate audio/video synchronization. |
| 65 static const int kBeepDurationMilliseconds = 20; | 54 static const int kBeepDurationMilliseconds = 20; |
| 66 static const int kBeepFrequency = 400; | 55 static const int kBeepFrequency = 400; |
| 67 | 56 |
| 68 // Intervals between two automatic beeps. | 57 // Intervals between two automatic beeps. |
| 69 static const int kAutomaticBeepIntervalInMs = 500; | 58 static const int kAutomaticBeepIntervalInMs = 500; |
| 70 | 59 |
| 71 // Automatic beep will be triggered every |kAutomaticBeepIntervalInMs| unless | 60 // Automatic beep will be triggered every |kAutomaticBeepIntervalInMs| unless |
| 72 // users explicitly call BeepOnce(), which will disable the automatic beep. | 61 // users explicitly call BeepOnce(), which will disable the automatic beep. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 return; | 161 return; |
| 173 | 162 |
| 174 // Read the file, and put its data in a scoped_ptr so it gets deleted later. | 163 // Read the file, and put its data in a scoped_ptr so it gets deleted later. |
| 175 size_t file_length = 0; | 164 size_t file_length = 0; |
| 176 wav_file_data_ = ReadWavFile(path_to_wav_file, &file_length); | 165 wav_file_data_ = ReadWavFile(path_to_wav_file, &file_length); |
| 177 if (!wav_file_data_) { | 166 if (!wav_file_data_) { |
| 178 load_failed_ = true; | 167 load_failed_ = true; |
| 179 return; | 168 return; |
| 180 } | 169 } |
| 181 | 170 |
| 182 wav_audio_handler_ = CreateWavAudioHandler( | 171 // Attempt to create a handler with this data. If the data is invalid, return. |
| 183 path_to_wav_file, wav_file_data_.get(), file_length, params_); | 172 wav_audio_handler_ = WavAudioHandler::Create(base::StringPiece( |
| 173 reinterpret_cast<const char*>(wav_file_data_.get()), file_length)); |
| 174 if (!wav_audio_handler_) { |
| 175 LOG(ERROR) << "WAV data could be read but is not valid"; |
| 176 load_failed_ = true; |
| 177 return; |
| 178 } |
| 184 | 179 |
| 185 // Hook us up so we pull in data from the file into the converter. We need to | 180 // Hook us up so we pull in data from the file into the converter. We need to |
| 186 // modify the wav file's audio parameters since we'll be reading small slices | 181 // modify the wav file's audio parameters since we'll be reading small slices |
| 187 // of it at a time and not the whole thing (like 10 ms at a time). | 182 // of it at a time and not the whole thing (like 10 ms at a time). |
| 188 AudioParameters file_audio_slice( | 183 AudioParameters file_audio_slice( |
| 189 AudioParameters::AUDIO_PCM_LOW_LATENCY, | 184 AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 190 GuessChannelLayout(wav_audio_handler_->num_channels()), | 185 GuessChannelLayout(wav_audio_handler_->num_channels()), |
| 191 wav_audio_handler_->sample_rate(), wav_audio_handler_->bits_per_sample(), | 186 wav_audio_handler_->sample_rate(), wav_audio_handler_->bits_per_sample(), |
| 192 params_.frames_per_buffer()); | 187 params_.frames_per_buffer()); |
| 193 | 188 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 290 } |
| 296 | 291 |
| 297 void BeepingSource::OnError(AudioOutputStream* stream) { | 292 void BeepingSource::OnError(AudioOutputStream* stream) { |
| 298 } | 293 } |
| 299 | 294 |
| 300 void BeepingSource::BeepOnce() { | 295 void BeepingSource::BeepOnce() { |
| 301 g_beep_context.Pointer()->SetBeepOnce(true); | 296 g_beep_context.Pointer()->SetBeepOnce(true); |
| 302 } | 297 } |
| 303 | 298 |
| 304 } // namespace media | 299 } // namespace media |
| OLD | NEW |