Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: content/renderer/media/audio_device.cc

Issue 9826023: Merge AudioRendererImpl and AudioRendererBase; add NullAudioSink (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 AudioDevice::~AudioDevice() { 75 AudioDevice::~AudioDevice() {
76 // The current design requires that the user calls Stop() before deleting 76 // The current design requires that the user calls Stop() before deleting
77 // this class. 77 // this class.
78 CHECK_EQ(0, stream_id_); 78 CHECK_EQ(0, stream_id_);
79 } 79 }
80 80
81 void AudioDevice::Start() { 81 void AudioDevice::Start() {
82 DCHECK(callback_) << "Initialize hasn't been called"; 82 DCHECK(callback_) << "Initialize hasn't been called";
83 message_loop()->PostTask(FROM_HERE, 83 message_loop()->PostTask(FROM_HERE,
84 base::Bind(&AudioDevice::InitializeOnIOThread, this, audio_parameters_)); 84 base::Bind(&AudioDevice::CreateStreamOnIOThread, this,
85 audio_parameters_));
85 } 86 }
86 87
87 void AudioDevice::Stop() { 88 void AudioDevice::Stop() {
88 { 89 {
89 base::AutoLock auto_lock(audio_thread_lock_); 90 base::AutoLock auto_lock(audio_thread_lock_);
90 audio_thread_.Stop(MessageLoop::current()); 91 audio_thread_.Stop(MessageLoop::current());
91 } 92 }
92 93
93 message_loop()->PostTask(FROM_HERE, 94 message_loop()->PostTask(FROM_HERE,
94 base::Bind(&AudioDevice::ShutDownOnIOThread, this)); 95 base::Bind(&AudioDevice::ShutDownOnIOThread, this));
(...skipping 21 matching lines...) Expand all
116 volume_ = volume; 117 volume_ = volume;
117 118
118 return true; 119 return true;
119 } 120 }
120 121
121 void AudioDevice::GetVolume(double* volume) { 122 void AudioDevice::GetVolume(double* volume) {
122 // Return a locally cached version of the current scaling factor. 123 // Return a locally cached version of the current scaling factor.
123 *volume = volume_; 124 *volume = volume_;
124 } 125 }
125 126
126 void AudioDevice::InitializeOnIOThread(const media::AudioParameters& params) { 127 void AudioDevice::CreateStreamOnIOThread(const media::AudioParameters& params) {
127 DCHECK(message_loop()->BelongsToCurrentThread()); 128 DCHECK(message_loop()->BelongsToCurrentThread());
128 // Make sure we don't create the stream more than once. 129 // Make sure we don't create the stream more than once.
129 DCHECK_EQ(0, stream_id_); 130 DCHECK_EQ(0, stream_id_);
130 if (stream_id_) 131 if (stream_id_)
131 return; 132 return;
132 133
133 stream_id_ = filter_->AddDelegate(this); 134 stream_id_ = filter_->AddDelegate(this);
134 Send(new AudioHostMsg_CreateStream(stream_id_, params)); 135 Send(new AudioHostMsg_CreateStream(stream_id_, params));
135 } 136 }
136 137
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // to the browser process as float, so we don't lose precision for 294 // to the browser process as float, so we don't lose precision for
294 // audio hardware which has better than 16bit precision. 295 // audio hardware which has better than 16bit precision.
295 int16* data = reinterpret_cast<int16*>(shared_memory_.memory()); 296 int16* data = reinterpret_cast<int16*>(shared_memory_.memory());
296 media::InterleaveFloatToInt16(audio_data_, data, 297 media::InterleaveFloatToInt16(audio_data_, data,
297 audio_parameters_.frames_per_buffer()); 298 audio_parameters_.frames_per_buffer());
298 299
299 // Let the host know we are done. 300 // Let the host know we are done.
300 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_, 301 media::SetActualDataSizeInBytes(&shared_memory_, memory_length_,
301 num_frames * audio_parameters_.channels() * sizeof(data[0])); 302 num_frames * audio_parameters_.channels() * sizeof(data[0]));
302 } 303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698