| 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 23 matching lines...) Expand all Loading... |
| 34 virtual void Process(int pending_data) OVERRIDE; | 34 virtual void Process(int pending_data) OVERRIDE; |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 AudioRendererSink::RenderCallback* render_callback_; | 37 AudioRendererSink::RenderCallback* render_callback_; |
| 38 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 38 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 AudioDevice::AudioDevice() | 41 AudioDevice::AudioDevice() |
| 42 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), | 42 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), |
| 43 callback_(NULL), | 43 callback_(NULL), |
| 44 volume_(1.0), | |
| 45 stream_id_(0), | 44 stream_id_(0), |
| 46 play_on_start_(true), | 45 play_on_start_(true), |
| 47 is_started_(false) { | 46 is_started_(false) { |
| 48 // Use the filter instance already created on the main render thread. | 47 // Use the filter instance already created on the main render thread. |
| 49 CHECK(AudioMessageFilter::Get()) << "Invalid audio message filter."; | 48 CHECK(AudioMessageFilter::Get()) << "Invalid audio message filter."; |
| 50 filter_ = AudioMessageFilter::Get(); | 49 filter_ = AudioMessageFilter::Get(); |
| 51 } | 50 } |
| 52 | 51 |
| 53 void AudioDevice::Initialize(const media::AudioParameters& params, | 52 void AudioDevice::Initialize(const media::AudioParameters& params, |
| 54 RenderCallback* callback) { | 53 RenderCallback* callback) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 95 |
| 97 bool AudioDevice::SetVolume(double volume) { | 96 bool AudioDevice::SetVolume(double volume) { |
| 98 if (volume < 0 || volume > 1.0) | 97 if (volume < 0 || volume > 1.0) |
| 99 return false; | 98 return false; |
| 100 | 99 |
| 101 if (!message_loop()->PostTask(FROM_HERE, | 100 if (!message_loop()->PostTask(FROM_HERE, |
| 102 base::Bind(&AudioDevice::SetVolumeOnIOThread, this, volume))) { | 101 base::Bind(&AudioDevice::SetVolumeOnIOThread, this, volume))) { |
| 103 return false; | 102 return false; |
| 104 } | 103 } |
| 105 | 104 |
| 106 volume_ = volume; | |
| 107 | |
| 108 return true; | 105 return true; |
| 109 } | 106 } |
| 110 | 107 |
| 111 void AudioDevice::GetVolume(double* volume) { | |
| 112 // Return a locally cached version of the current scaling factor. | |
| 113 *volume = volume_; | |
| 114 } | |
| 115 | |
| 116 void AudioDevice::CreateStreamOnIOThread(const media::AudioParameters& params) { | 108 void AudioDevice::CreateStreamOnIOThread(const media::AudioParameters& params) { |
| 117 DCHECK(message_loop()->BelongsToCurrentThread()); | 109 DCHECK(message_loop()->BelongsToCurrentThread()); |
| 118 // Make sure we don't create the stream more than once. | 110 // Make sure we don't create the stream more than once. |
| 119 DCHECK_EQ(0, stream_id_); | 111 DCHECK_EQ(0, stream_id_); |
| 120 if (stream_id_) | 112 if (stream_id_) |
| 121 return; | 113 return; |
| 122 | 114 |
| 123 stream_id_ = filter_->AddDelegate(this); | 115 stream_id_ = filter_->AddDelegate(this); |
| 124 Send(new AudioHostMsg_CreateStream(stream_id_, params)); | 116 Send(new AudioHostMsg_CreateStream(stream_id_, params)); |
| 125 } | 117 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 // TODO(crogers/vrk): Figure out a way to avoid the float -> int -> float | 273 // TODO(crogers/vrk): Figure out a way to avoid the float -> int -> float |
| 282 // conversions that happen in the <audio> and WebRTC scenarios. | 274 // conversions that happen in the <audio> and WebRTC scenarios. |
| 283 media::InterleaveFloatToInt(audio_data_, shared_memory_.memory(), | 275 media::InterleaveFloatToInt(audio_data_, shared_memory_.memory(), |
| 284 audio_parameters_.frames_per_buffer(), | 276 audio_parameters_.frames_per_buffer(), |
| 285 audio_parameters_.bits_per_sample() / 8); | 277 audio_parameters_.bits_per_sample() / 8); |
| 286 | 278 |
| 287 // Let the host know we are done. | 279 // Let the host know we are done. |
| 288 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, | 280 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, |
| 289 num_frames * audio_parameters_.GetBytesPerFrame()); | 281 num_frames * audio_parameters_.GetBytesPerFrame()); |
| 290 } | 282 } |
| OLD | NEW |