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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 AudioDevice::~AudioDevice() { | 82 AudioDevice::~AudioDevice() { |
83 // The current design requires that the user calls Stop() before deleting | 83 // The current design requires that the user calls Stop() before deleting |
84 // this class. | 84 // this class. |
85 CHECK_EQ(0, stream_id_); | 85 CHECK_EQ(0, stream_id_); |
86 } | 86 } |
87 | 87 |
88 void AudioDevice::Start() { | 88 void AudioDevice::Start() { |
89 DCHECK(callback_) << "Initialize hasn't been called"; | 89 DCHECK(callback_) << "Initialize hasn't been called"; |
90 message_loop()->PostTask(FROM_HERE, | 90 message_loop()->PostTask(FROM_HERE, |
91 base::Bind(&AudioDevice::InitializeOnIOThread, this, audio_parameters_)); | 91 base::Bind(&AudioDevice::CreateStreamOnIOThread, this, |
| 92 audio_parameters_)); |
92 } | 93 } |
93 | 94 |
94 void AudioDevice::Stop() { | 95 void AudioDevice::Stop() { |
95 { | 96 { |
96 base::AutoLock auto_lock(audio_thread_lock_); | 97 base::AutoLock auto_lock(audio_thread_lock_); |
97 audio_thread_.Stop(MessageLoop::current()); | 98 audio_thread_.Stop(MessageLoop::current()); |
98 } | 99 } |
99 | 100 |
100 message_loop()->PostTask(FROM_HERE, | 101 message_loop()->PostTask(FROM_HERE, |
101 base::Bind(&AudioDevice::ShutDownOnIOThread, this)); | 102 base::Bind(&AudioDevice::ShutDownOnIOThread, this)); |
(...skipping 21 matching lines...) Expand all Loading... |
123 volume_ = volume; | 124 volume_ = volume; |
124 | 125 |
125 return true; | 126 return true; |
126 } | 127 } |
127 | 128 |
128 void AudioDevice::GetVolume(double* volume) { | 129 void AudioDevice::GetVolume(double* volume) { |
129 // Return a locally cached version of the current scaling factor. | 130 // Return a locally cached version of the current scaling factor. |
130 *volume = volume_; | 131 *volume = volume_; |
131 } | 132 } |
132 | 133 |
133 void AudioDevice::InitializeOnIOThread(const media::AudioParameters& params) { | 134 void AudioDevice::CreateStreamOnIOThread(const media::AudioParameters& params) { |
134 DCHECK(message_loop()->BelongsToCurrentThread()); | 135 DCHECK(message_loop()->BelongsToCurrentThread()); |
135 // Make sure we don't create the stream more than once. | 136 // Make sure we don't create the stream more than once. |
136 DCHECK_EQ(0, stream_id_); | 137 DCHECK_EQ(0, stream_id_); |
137 if (stream_id_) | 138 if (stream_id_) |
138 return; | 139 return; |
139 | 140 |
140 stream_id_ = filter_->AddDelegate(this); | 141 stream_id_ = filter_->AddDelegate(this); |
141 Send(new AudioHostMsg_CreateStream(stream_id_, params)); | 142 Send(new AudioHostMsg_CreateStream(stream_id_, params)); |
142 } | 143 } |
143 | 144 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 // to the browser process as float, so we don't lose precision for | 301 // to the browser process as float, so we don't lose precision for |
301 // audio hardware which has better than 16bit precision. | 302 // audio hardware which has better than 16bit precision. |
302 int16* data = reinterpret_cast<int16*>(shared_memory_.memory()); | 303 int16* data = reinterpret_cast<int16*>(shared_memory_.memory()); |
303 media::InterleaveFloatToInt16(audio_data_, data, | 304 media::InterleaveFloatToInt16(audio_data_, data, |
304 audio_parameters_.frames_per_buffer()); | 305 audio_parameters_.frames_per_buffer()); |
305 | 306 |
306 // Let the host know we are done. | 307 // Let the host know we are done. |
307 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, | 308 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, |
308 num_frames * audio_parameters_.channels() * sizeof(data[0])); | 309 num_frames * audio_parameters_.channels() * sizeof(data[0])); |
309 } | 310 } |
OLD | NEW |