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 { |
| 25 public: | 25 public: |
| 26 AudioThreadCallback(const media::AudioParameters& audio_parameters, | 26 AudioThreadCallback(const media::AudioParameters& audio_parameters, |
| 27 base::SharedMemoryHandle memory, | 27 base::SharedMemoryHandle memory, |
| 28 int memory_length, | 28 int memory_length, |
| 29 AudioRendererSink::RenderCallback* render_callback); | 29 AudioRendererSink::RenderCallback* render_callback); |
| 30 virtual ~AudioThreadCallback(); | 30 virtual ~AudioThreadCallback(); |
| 31 | 31 |
| 32 virtual void MapSharedMemory() OVERRIDE; | 32 virtual void MapSharedMemory() OVERRIDE; |
| 33 | 33 |
| 34 // Called whenever we receive notifications about pending data. | 34 // Called whenever we receive notifications about pending data. |
| 35 virtual void Process(int pending_data) OVERRIDE; | 35 virtual void Process(int pending_data) OVERRIDE; |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 AudioRendererSink::RenderCallback* render_callback_; | 38 AudioRendererSink::RenderCallback* render_callback_; |
| 39 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 39 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 AudioDevice::AudioDevice() | 42 AudioDevice::AudioDevice(AudioMessageFilter* filter) |
|
Chris Rogers
2012/06/14 17:41:44
This is leaking internal implementation details fo
| |
| 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 filter_(filter), | |
| 46 stream_id_(0), | 47 stream_id_(0), |
| 47 play_on_start_(true), | 48 play_on_start_(true), |
| 48 is_started_(false) { | 49 is_started_(false) { |
| 49 filter_ = RenderThreadImpl::current()->audio_message_filter(); | 50 CHECK(filter_) << "Invalid audio message filter."; |
| 50 } | |
| 51 | |
| 52 AudioDevice::AudioDevice(const media::AudioParameters& params, | |
| 53 RenderCallback* callback) | |
| 54 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), | |
| 55 audio_parameters_(params), | |
| 56 callback_(callback), | |
| 57 volume_(1.0), | |
| 58 stream_id_(0), | |
| 59 play_on_start_(true), | |
| 60 is_started_(false) { | |
| 61 filter_ = RenderThreadImpl::current()->audio_message_filter(); | |
| 62 } | 51 } |
| 63 | 52 |
| 64 void AudioDevice::Initialize(const media::AudioParameters& params, | 53 void AudioDevice::Initialize(const media::AudioParameters& params, |
| 65 RenderCallback* callback) { | 54 RenderCallback* callback) { |
| 66 CHECK_EQ(0, stream_id_) << | 55 CHECK_EQ(0, stream_id_) << |
| 67 "AudioDevice::Initialize() must be called before Start()"; | 56 "AudioDevice::Initialize() must be called before Start()"; |
| 68 | 57 |
| 69 CHECK(!callback_); // Calling Initialize() twice? | 58 CHECK(!callback_); // Calling Initialize() twice? |
| 70 | 59 |
| 71 audio_parameters_ = params; | 60 audio_parameters_ = params; |
| (...skipping 220 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 | 281 // TODO(crogers/vrk): Figure out a way to avoid the float -> int -> float |
| 293 // conversions that happen in the <audio> and WebRTC scenarios. | 282 // conversions that happen in the <audio> and WebRTC scenarios. |
| 294 media::InterleaveFloatToInt(audio_data_, shared_memory_.memory(), | 283 media::InterleaveFloatToInt(audio_data_, shared_memory_.memory(), |
| 295 audio_parameters_.frames_per_buffer(), | 284 audio_parameters_.frames_per_buffer(), |
| 296 audio_parameters_.bits_per_sample() / 8); | 285 audio_parameters_.bits_per_sample() / 8); |
| 297 | 286 |
| 298 // Let the host know we are done. | 287 // Let the host know we are done. |
| 299 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, | 288 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, |
| 300 num_frames * audio_parameters_.GetBytesPerFrame()); | 289 num_frames * audio_parameters_.GetBytesPerFrame()); |
| 301 } | 290 } |
| OLD | NEW |