Chromium Code Reviews| 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 DCHECK(!is_initialized_); | |
|
acolwell GONE FROM CHROMIUM
2011/12/21 22:53:56
Should this be a CHECK() ? Do we really want to tr
Chris Rogers
2011/12/22 00:54:33
Done.
| |
| 64 if (is_initialized_) | |
|
acolwell GONE FROM CHROMIUM
2011/12/21 22:53:56
I don't think this should be here. We should eithe
Chris Rogers
2011/12/22 00:54:33
Done.
| |
| 65 return; | |
| 66 | |
| 63 buffer_size_ = buffer_size; | 67 buffer_size_ = buffer_size; |
| 64 channels_ = channels; | 68 channels_ = channels; |
| 65 sample_rate_ = sample_rate; | 69 sample_rate_ = sample_rate; |
| 66 latency_format_ = latency_format; | 70 latency_format_ = latency_format; |
| 67 callback_ = callback; | 71 callback_ = callback; |
| 68 | 72 |
| 69 // Cleanup from any previous initialization. | 73 // Cleanup from any previous initialization. |
| 70 for (size_t i = 0; i < audio_data_.size(); ++i) | 74 for (size_t i = 0; i < audio_data_.size(); ++i) |
| 71 delete [] audio_data_[i]; | 75 delete [] audio_data_[i]; |
| 72 | 76 |
| 73 audio_data_.reserve(channels); | 77 audio_data_.reserve(channels); |
| 74 for (int i = 0; i < channels; ++i) { | 78 for (int i = 0; i < channels; ++i) { |
| 75 float* channel_data = new float[buffer_size]; | 79 float* channel_data = new float[buffer_size]; |
| 76 audio_data_.push_back(channel_data); | 80 audio_data_.push_back(channel_data); |
| 77 } | 81 } |
| 78 | 82 |
| 79 is_initialized_ = true; | 83 is_initialized_ = true; |
| 80 } | 84 } |
| 81 | 85 |
| 82 bool AudioDevice::IsInitialized() { | |
| 83 return is_initialized_; | |
| 84 } | |
| 85 | |
| 86 AudioDevice::~AudioDevice() { | 86 AudioDevice::~AudioDevice() { |
| 87 // The current design requires that the user calls Stop() before deleting | 87 // The current design requires that the user calls Stop() before deleting |
| 88 // this class. | 88 // this class. |
| 89 CHECK_EQ(0, stream_id_); | 89 CHECK_EQ(0, stream_id_); |
| 90 for (int i = 0; i < channels_; ++i) | 90 for (int i = 0; i < channels_; ++i) |
| 91 delete [] audio_data_[i]; | 91 delete [] audio_data_[i]; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void AudioDevice::Start() { | 94 void AudioDevice::Start() { |
| 95 AudioParameters params; | 95 AudioParameters params; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 if (audio_thread_.get()) { | 335 if (audio_thread_.get()) { |
| 336 // Close the socket handler to terminate the main thread function in the | 336 // Close the socket handler to terminate the main thread function in the |
| 337 // audio thread. | 337 // audio thread. |
| 338 { | 338 { |
| 339 base::SyncSocket socket(socket_handle_); | 339 base::SyncSocket socket(socket_handle_); |
| 340 } | 340 } |
| 341 audio_thread_->Join(); | 341 audio_thread_->Join(); |
| 342 audio_thread_.reset(NULL); | 342 audio_thread_.reset(NULL); |
| 343 } | 343 } |
| 344 } | 344 } |
| OLD | NEW |