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 20 matching lines...) Expand all Loading... |
31 | 31 |
32 // Called whenever we receive notifications about pending data. | 32 // Called whenever we receive notifications about pending data. |
33 virtual void Process(int pending_data) OVERRIDE; | 33 virtual void Process(int pending_data) OVERRIDE; |
34 | 34 |
35 private: | 35 private: |
36 AudioRendererSink::RenderCallback* render_callback_; | 36 AudioRendererSink::RenderCallback* render_callback_; |
37 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 37 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
38 }; | 38 }; |
39 | 39 |
40 AudioDevice::AudioDevice( | 40 AudioDevice::AudioDevice( |
| 41 content::RenderView* render_view, |
41 const scoped_refptr<base::MessageLoopProxy>& io_loop) | 42 const scoped_refptr<base::MessageLoopProxy>& io_loop) |
42 : ScopedLoopObserver(io_loop), | 43 : ScopedLoopObserver(io_loop), |
| 44 render_view_(render_view), |
43 callback_(NULL), | 45 callback_(NULL), |
44 stream_id_(0), | 46 stream_id_(0), |
45 play_on_start_(true), | 47 play_on_start_(true), |
46 is_started_(false) { | 48 is_started_(false) { |
47 // Use the filter instance already created on the main render thread. | 49 // Use the filter instance already created on the main render thread. |
48 CHECK(AudioMessageFilter::Get()) << "Invalid audio message filter."; | 50 CHECK(AudioMessageFilter::Get()) << "Invalid audio message filter."; |
49 filter_ = AudioMessageFilter::Get(); | 51 filter_ = AudioMessageFilter::Get(); |
50 } | 52 } |
51 | 53 |
52 void AudioDevice::Initialize(const media::AudioParameters& params, | 54 void AudioDevice::Initialize(const media::AudioParameters& params, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 108 } |
107 | 109 |
108 void AudioDevice::CreateStreamOnIOThread(const media::AudioParameters& params) { | 110 void AudioDevice::CreateStreamOnIOThread(const media::AudioParameters& params) { |
109 DCHECK(message_loop()->BelongsToCurrentThread()); | 111 DCHECK(message_loop()->BelongsToCurrentThread()); |
110 // Make sure we don't create the stream more than once. | 112 // Make sure we don't create the stream more than once. |
111 DCHECK_EQ(0, stream_id_); | 113 DCHECK_EQ(0, stream_id_); |
112 if (stream_id_) | 114 if (stream_id_) |
113 return; | 115 return; |
114 | 116 |
115 stream_id_ = filter_->AddDelegate(this); | 117 stream_id_ = filter_->AddDelegate(this); |
116 Send(new AudioHostMsg_CreateStream(stream_id_, params)); | 118 // TODO(sailesh) |
| 119 Send(new AudioHostMsg_CreateStream(0, stream_id_, params)); |
117 } | 120 } |
118 | 121 |
119 void AudioDevice::PlayOnIOThread() { | 122 void AudioDevice::PlayOnIOThread() { |
120 DCHECK(message_loop()->BelongsToCurrentThread()); | 123 DCHECK(message_loop()->BelongsToCurrentThread()); |
121 if (stream_id_ && is_started_) | 124 if (stream_id_ && is_started_) |
122 Send(new AudioHostMsg_PlayStream(stream_id_)); | 125 Send(new AudioHostMsg_PlayStream(stream_id_)); |
123 else | 126 else |
124 play_on_start_ = true; | 127 play_on_start_ = true; |
125 } | 128 } |
126 | 129 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // Interleave, scale, and clip to int. | 275 // Interleave, scale, and clip to int. |
273 // TODO(crogers/vrk): Figure out a way to avoid the float -> int -> float | 276 // TODO(crogers/vrk): Figure out a way to avoid the float -> int -> float |
274 // conversions that happen in the <audio> and WebRTC scenarios. | 277 // conversions that happen in the <audio> and WebRTC scenarios. |
275 media::InterleaveFloatToInt(audio_data_, shared_memory_.memory(), | 278 media::InterleaveFloatToInt(audio_data_, shared_memory_.memory(), |
276 num_frames, audio_parameters_.bits_per_sample() / 8); | 279 num_frames, audio_parameters_.bits_per_sample() / 8); |
277 | 280 |
278 // Let the host know we are done. | 281 // Let the host know we are done. |
279 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, | 282 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, |
280 num_frames * audio_parameters_.GetBytesPerFrame()); | 283 num_frames * audio_parameters_.GetBytesPerFrame()); |
281 } | 284 } |
OLD | NEW |