Chromium Code Reviews| 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" |
| 11 #include "content/common/child_process.h" | 11 #include "content/common/child_process.h" |
| 12 #include "content/common/media/audio_messages.h" | 12 #include "content/common/media/audio_messages.h" |
| 13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 14 #include "content/renderer/render_thread_impl.h" | 14 #include "content/renderer/media/audio_message_filter.h" |
| 15 #include "media/audio/audio_output_controller.h" | 15 #include "media/audio/audio_output_controller.h" |
| 16 #include "media/audio/audio_util.h" | 16 #include "media/audio/audio_util.h" |
| 17 | 17 |
| 18 using media::AudioRendererSink; | 18 using media::AudioRendererSink; |
| 19 | 19 |
| 20 // Takes care of invoking the render callback on the audio thread. | 20 // Takes care of invoking the render callback on the audio thread. |
| 21 // An instance of this class is created for each capture stream in | 21 // An instance of this class is created for each capture stream in |
| 22 // OnStreamCreated(). | 22 // OnStreamCreated(). |
| 23 class AudioDevice::AudioThreadCallback | 23 class AudioDevice::AudioThreadCallback |
| 24 : public AudioDeviceThread::Callback { | 24 : public AudioDeviceThread::Callback { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 39 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 39 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 AudioDevice::AudioDevice() | 42 AudioDevice::AudioDevice() |
| 43 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), | 43 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), |
| 44 callback_(NULL), | 44 callback_(NULL), |
| 45 volume_(1.0), | 45 volume_(1.0), |
| 46 stream_id_(0), | 46 stream_id_(0), |
| 47 play_on_start_(true), | 47 play_on_start_(true), |
| 48 is_started_(false) { | 48 is_started_(false) { |
| 49 filter_ = RenderThreadImpl::current()->audio_message_filter(); | 49 DVLOG(1) << "AudioDevice::AudioDevice()"; |
|
Chris Rogers
2012/06/25 20:05:17
I'd remove the DVLOG
henrika (OOO until Aug 14)
2012/06/26 11:17:27
Done.
| |
| 50 // Use the filter instance already created on the main render thread. | |
| 51 CHECK(AudioMessageFilter::current()) << "Invalid audio message filter."; | |
| 52 filter_ = AudioMessageFilter::current(); | |
| 50 } | 53 } |
| 51 | 54 |
| 52 AudioDevice::AudioDevice(const media::AudioParameters& params, | 55 AudioDevice::AudioDevice(AudioMessageFilter* filter) |
| 53 RenderCallback* callback) | |
| 54 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), | 56 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), |
| 55 audio_parameters_(params), | 57 callback_(NULL), |
| 56 callback_(callback), | |
| 57 volume_(1.0), | 58 volume_(1.0), |
| 59 filter_(filter), | |
| 58 stream_id_(0), | 60 stream_id_(0), |
| 59 play_on_start_(true), | 61 play_on_start_(true), |
| 60 is_started_(false) { | 62 is_started_(false) { |
| 61 filter_ = RenderThreadImpl::current()->audio_message_filter(); | 63 DVLOG(1) << "AudioDevice::AudioDevice(filter)"; |
|
Chris Rogers
2012/06/25 20:05:17
I'd remove the DVLOG
henrika (OOO until Aug 14)
2012/06/26 11:17:27
Done.
| |
| 64 CHECK(filter_) << "Invalid audio message filter."; | |
| 62 } | 65 } |
| 63 | 66 |
| 64 void AudioDevice::Initialize(const media::AudioParameters& params, | 67 void AudioDevice::Initialize(const media::AudioParameters& params, |
| 65 RenderCallback* callback) { | 68 RenderCallback* callback) { |
| 66 CHECK_EQ(0, stream_id_) << | 69 CHECK_EQ(0, stream_id_) << |
| 67 "AudioDevice::Initialize() must be called before Start()"; | 70 "AudioDevice::Initialize() must be called before Start()"; |
| 68 | 71 |
| 69 CHECK(!callback_); // Calling Initialize() twice? | 72 CHECK(!callback_); // Calling Initialize() twice? |
| 70 | 73 |
| 71 audio_parameters_ = params; | 74 audio_parameters_ = params; |
| 72 callback_ = callback; | 75 callback_ = callback; |
| 73 } | 76 } |
| 74 | 77 |
| 75 AudioDevice::~AudioDevice() { | 78 AudioDevice::~AudioDevice() { |
| 79 DVLOG(1) << "AudioDevice::~AudioDevice()"; | |
|
Chris Rogers
2012/06/25 20:05:17
I'd remove the DVLOG
henrika (OOO until Aug 14)
2012/06/26 11:17:27
Done.
| |
| 76 // The current design requires that the user calls Stop() before deleting | 80 // The current design requires that the user calls Stop() before deleting |
| 77 // this class. | 81 // this class. |
| 78 CHECK_EQ(0, stream_id_); | 82 CHECK_EQ(0, stream_id_); |
| 79 } | 83 } |
| 80 | 84 |
| 81 void AudioDevice::Start() { | 85 void AudioDevice::Start() { |
| 82 DCHECK(callback_) << "Initialize hasn't been called"; | 86 DCHECK(callback_) << "Initialize hasn't been called"; |
| 83 message_loop()->PostTask(FROM_HERE, | 87 message_loop()->PostTask(FROM_HERE, |
| 84 base::Bind(&AudioDevice::CreateStreamOnIOThread, this, | 88 base::Bind(&AudioDevice::CreateStreamOnIOThread, this, |
| 85 audio_parameters_)); | 89 audio_parameters_)); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 // TODO(crogers/vrk): Figure out a way to avoid the float -> int -> float | 296 // TODO(crogers/vrk): Figure out a way to avoid the float -> int -> float |
| 293 // conversions that happen in the <audio> and WebRTC scenarios. | 297 // conversions that happen in the <audio> and WebRTC scenarios. |
| 294 media::InterleaveFloatToInt(audio_data_, shared_memory_.memory(), | 298 media::InterleaveFloatToInt(audio_data_, shared_memory_.memory(), |
| 295 audio_parameters_.frames_per_buffer(), | 299 audio_parameters_.frames_per_buffer(), |
| 296 audio_parameters_.bits_per_sample() / 8); | 300 audio_parameters_.bits_per_sample() / 8); |
| 297 | 301 |
| 298 // Let the host know we are done. | 302 // Let the host know we are done. |
| 299 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, | 303 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, |
| 300 num_frames * audio_parameters_.GetBytesPerFrame()); | 304 num_frames * audio_parameters_.GetBytesPerFrame()); |
| 301 } | 305 } |
| OLD | NEW |