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" | |
15 #include "media/audio/audio_output_controller.h" | 14 #include "media/audio/audio_output_controller.h" |
16 #include "media/audio/audio_util.h" | 15 #include "media/audio/audio_util.h" |
17 | 16 |
18 using media::AudioRendererSink; | 17 using media::AudioRendererSink; |
19 | 18 |
20 // Takes care of invoking the render callback on the audio thread. | 19 // Takes care of invoking the render callback on the audio thread. |
21 // An instance of this class is created for each capture stream in | 20 // An instance of this class is created for each capture stream in |
22 // OnStreamCreated(). | 21 // OnStreamCreated(). |
23 class AudioDevice::AudioThreadCallback | 22 class AudioDevice::AudioThreadCallback |
24 : public AudioDeviceThread::Callback { | 23 : public AudioDeviceThread::Callback { |
(...skipping 14 matching lines...) Expand all Loading... |
39 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 38 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
40 }; | 39 }; |
41 | 40 |
42 AudioDevice::AudioDevice() | 41 AudioDevice::AudioDevice() |
43 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), | 42 : ScopedLoopObserver(ChildProcess::current()->io_message_loop()), |
44 callback_(NULL), | 43 callback_(NULL), |
45 volume_(1.0), | 44 volume_(1.0), |
46 stream_id_(0), | 45 stream_id_(0), |
47 play_on_start_(true), | 46 play_on_start_(true), |
48 is_started_(false) { | 47 is_started_(false) { |
49 filter_ = RenderThreadImpl::current()->audio_message_filter(); | 48 // Use the filter instance already created on the main render thread. |
50 } | 49 CHECK(AudioMessageFilter::current()) << "Invalid audio message filter."; |
51 | 50 filter_ = AudioMessageFilter::current(); |
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 |