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" |
scherkus (not reviewing)
2012/06/26 23:34:30
nit: we include this in the .h
henrika (OOO until Aug 14)
2012/06/27 08:23:16
Done.
| |
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 // Use the filter instance already created on the main render thread. |
50 } | 50 CHECK(AudioMessageFilter::current()) << "Invalid audio message filter."; |
51 | 51 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 } | 52 } |
63 | 53 |
64 void AudioDevice::Initialize(const media::AudioParameters& params, | 54 void AudioDevice::Initialize(const media::AudioParameters& params, |
65 RenderCallback* callback) { | 55 RenderCallback* callback) { |
66 CHECK_EQ(0, stream_id_) << | 56 CHECK_EQ(0, stream_id_) << |
67 "AudioDevice::Initialize() must be called before Start()"; | 57 "AudioDevice::Initialize() must be called before Start()"; |
68 | 58 |
69 CHECK(!callback_); // Calling Initialize() twice? | 59 CHECK(!callback_); // Calling Initialize() twice? |
70 | 60 |
71 audio_parameters_ = params; | 61 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 | 282 // TODO(crogers/vrk): Figure out a way to avoid the float -> int -> float |
293 // conversions that happen in the <audio> and WebRTC scenarios. | 283 // conversions that happen in the <audio> and WebRTC scenarios. |
294 media::InterleaveFloatToInt(audio_data_, shared_memory_.memory(), | 284 media::InterleaveFloatToInt(audio_data_, shared_memory_.memory(), |
295 audio_parameters_.frames_per_buffer(), | 285 audio_parameters_.frames_per_buffer(), |
296 audio_parameters_.bits_per_sample() / 8); | 286 audio_parameters_.bits_per_sample() / 8); |
297 | 287 |
298 // Let the host know we are done. | 288 // Let the host know we are done. |
299 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, | 289 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, |
300 num_frames * audio_parameters_.GetBytesPerFrame()); | 290 num_frames * audio_parameters_.GetBytesPerFrame()); |
301 } | 291 } |
OLD | NEW |