| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 void AudioDevice::Initialize(size_t buffer_size, | 55 void AudioDevice::Initialize(size_t buffer_size, |
| 56 int channels, | 56 int channels, |
| 57 double sample_rate, | 57 double sample_rate, |
| 58 AudioParameters::Format latency_format, | 58 AudioParameters::Format latency_format, |
| 59 RenderCallback* callback) { | 59 RenderCallback* callback) { |
| 60 CHECK_EQ(0, stream_id_) << | 60 CHECK_EQ(0, stream_id_) << |
| 61 "AudioDevice::Initialize() must be called before Start()"; | 61 "AudioDevice::Initialize() must be called before Start()"; |
| 62 | 62 |
| 63 CHECK(!is_initialized_); |
| 64 |
| 63 buffer_size_ = buffer_size; | 65 buffer_size_ = buffer_size; |
| 64 channels_ = channels; | 66 channels_ = channels; |
| 65 sample_rate_ = sample_rate; | 67 sample_rate_ = sample_rate; |
| 66 latency_format_ = latency_format; | 68 latency_format_ = latency_format; |
| 67 callback_ = callback; | 69 callback_ = callback; |
| 68 | 70 |
| 69 // Cleanup from any previous initialization. | 71 // Cleanup from any previous initialization. |
| 70 for (size_t i = 0; i < audio_data_.size(); ++i) | 72 for (size_t i = 0; i < audio_data_.size(); ++i) |
| 71 delete [] audio_data_[i]; | 73 delete [] audio_data_[i]; |
| 72 | 74 |
| 73 audio_data_.reserve(channels); | 75 audio_data_.reserve(channels); |
| 74 for (int i = 0; i < channels; ++i) { | 76 for (int i = 0; i < channels; ++i) { |
| 75 float* channel_data = new float[buffer_size]; | 77 float* channel_data = new float[buffer_size]; |
| 76 audio_data_.push_back(channel_data); | 78 audio_data_.push_back(channel_data); |
| 77 } | 79 } |
| 78 | 80 |
| 79 is_initialized_ = true; | 81 is_initialized_ = true; |
| 80 } | 82 } |
| 81 | 83 |
| 82 bool AudioDevice::IsInitialized() { | |
| 83 return is_initialized_; | |
| 84 } | |
| 85 | |
| 86 AudioDevice::~AudioDevice() { | 84 AudioDevice::~AudioDevice() { |
| 87 // The current design requires that the user calls Stop() before deleting | 85 // The current design requires that the user calls Stop() before deleting |
| 88 // this class. | 86 // this class. |
| 89 CHECK_EQ(0, stream_id_); | 87 CHECK_EQ(0, stream_id_); |
| 90 for (int i = 0; i < channels_; ++i) | 88 for (int i = 0; i < channels_; ++i) |
| 91 delete [] audio_data_[i]; | 89 delete [] audio_data_[i]; |
| 92 } | 90 } |
| 93 | 91 |
| 94 void AudioDevice::Start() { | 92 void AudioDevice::Start() { |
| 95 AudioParameters params; | 93 AudioParameters params; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 if (audio_thread_.get()) { | 342 if (audio_thread_.get()) { |
| 345 // Close the socket handler to terminate the main thread function in the | 343 // Close the socket handler to terminate the main thread function in the |
| 346 // audio thread. | 344 // audio thread. |
| 347 { | 345 { |
| 348 base::SyncSocket socket(socket_handle_); | 346 base::SyncSocket socket(socket_handle_); |
| 349 } | 347 } |
| 350 audio_thread_->Join(); | 348 audio_thread_->Join(); |
| 351 audio_thread_.reset(NULL); | 349 audio_thread_.reset(NULL); |
| 352 } | 350 } |
| 353 } | 351 } |
| OLD | NEW |