| 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 "content/renderer/media/audio_device.h" | 5 #include "content/renderer/media/audio_device.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 void AudioDevice::Initialize(size_t buffer_size, | 57 void AudioDevice::Initialize(size_t buffer_size, |
| 58 int channels, | 58 int channels, |
| 59 double sample_rate, | 59 double sample_rate, |
| 60 AudioParameters::Format latency_format, | 60 AudioParameters::Format latency_format, |
| 61 RenderCallback* callback) { | 61 RenderCallback* callback) { |
| 62 CHECK_EQ(0, stream_id_) << | 62 CHECK_EQ(0, stream_id_) << |
| 63 "AudioDevice::Initialize() must be called before Start()"; | 63 "AudioDevice::Initialize() must be called before Start()"; |
| 64 | 64 |
| 65 CHECK(!is_initialized_); |
| 66 |
| 65 buffer_size_ = buffer_size; | 67 buffer_size_ = buffer_size; |
| 66 channels_ = channels; | 68 channels_ = channels; |
| 67 sample_rate_ = sample_rate; | 69 sample_rate_ = sample_rate; |
| 68 latency_format_ = latency_format; | 70 latency_format_ = latency_format; |
| 69 callback_ = callback; | 71 callback_ = callback; |
| 70 | 72 |
| 71 // Cleanup from any previous initialization. | 73 // Cleanup from any previous initialization. |
| 72 for (size_t i = 0; i < audio_data_.size(); ++i) | 74 for (size_t i = 0; i < audio_data_.size(); ++i) |
| 73 delete [] audio_data_[i]; | 75 delete [] audio_data_[i]; |
| 74 | 76 |
| 75 audio_data_.reserve(channels); | 77 audio_data_.reserve(channels); |
| 76 for (int i = 0; i < channels; ++i) { | 78 for (int i = 0; i < channels; ++i) { |
| 77 float* channel_data = new float[buffer_size]; | 79 float* channel_data = new float[buffer_size]; |
| 78 audio_data_.push_back(channel_data); | 80 audio_data_.push_back(channel_data); |
| 79 } | 81 } |
| 80 | 82 |
| 81 is_initialized_ = true; | 83 is_initialized_ = true; |
| 82 } | 84 } |
| 83 | 85 |
| 84 bool AudioDevice::IsInitialized() { | |
| 85 return is_initialized_; | |
| 86 } | |
| 87 | |
| 88 AudioDevice::~AudioDevice() { | 86 AudioDevice::~AudioDevice() { |
| 89 // The current design requires that the user calls Stop() before deleting | 87 // The current design requires that the user calls Stop() before deleting |
| 90 // this class. | 88 // this class. |
| 91 CHECK_EQ(0, stream_id_); | 89 CHECK_EQ(0, stream_id_); |
| 92 for (int i = 0; i < channels_; ++i) | 90 for (int i = 0; i < channels_; ++i) |
| 93 delete [] audio_data_[i]; | 91 delete [] audio_data_[i]; |
| 94 } | 92 } |
| 95 | 93 |
| 96 void AudioDevice::Start() { | 94 void AudioDevice::Start() { |
| 97 AudioParameters params; | 95 AudioParameters params; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // Synchronize with OnLowLatencyCreated(). | 343 // Synchronize with OnLowLatencyCreated(). |
| 346 base::AutoLock auto_lock(lock_); | 344 base::AutoLock auto_lock(lock_); |
| 347 if (audio_thread_.get()) { | 345 if (audio_thread_.get()) { |
| 348 // Close the socket to terminate the main thread function in the | 346 // Close the socket to terminate the main thread function in the |
| 349 // audio thread. | 347 // audio thread. |
| 350 audio_socket_->Close(); | 348 audio_socket_->Close(); |
| 351 audio_thread_->Join(); | 349 audio_thread_->Join(); |
| 352 audio_thread_.reset(NULL); | 350 audio_thread_.reset(NULL); |
| 353 } | 351 } |
| 354 } | 352 } |
| OLD | NEW |