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

Side by Side Diff: media/audio/android/opensles_output.cc

Issue 93233003: Mute audio when volume is zero on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: henrika@'s comment Created 7 years 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 "media/audio/android/opensles_output.h" 5 #include "media/audio/android/opensles_output.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/audio/android/audio_manager_android.h" 9 #include "media/audio/android/audio_manager_android.h"
10 10
(...skipping 10 matching lines...) Expand all
21 21
22 OpenSLESOutputStream::OpenSLESOutputStream(AudioManagerAndroid* manager, 22 OpenSLESOutputStream::OpenSLESOutputStream(AudioManagerAndroid* manager,
23 const AudioParameters& params) 23 const AudioParameters& params)
24 : audio_manager_(manager), 24 : audio_manager_(manager),
25 callback_(NULL), 25 callback_(NULL),
26 player_(NULL), 26 player_(NULL),
27 simple_buffer_queue_(NULL), 27 simple_buffer_queue_(NULL),
28 active_buffer_index_(0), 28 active_buffer_index_(0),
29 buffer_size_bytes_(0), 29 buffer_size_bytes_(0),
30 started_(false), 30 started_(false),
31 muted_(false),
31 volume_(1.0) { 32 volume_(1.0) {
32 DVLOG(2) << "OpenSLESOutputStream::OpenSLESOutputStream()"; 33 DVLOG(2) << "OpenSLESOutputStream::OpenSLESOutputStream()";
33 format_.formatType = SL_DATAFORMAT_PCM; 34 format_.formatType = SL_DATAFORMAT_PCM;
34 format_.numChannels = static_cast<SLuint32>(params.channels()); 35 format_.numChannels = static_cast<SLuint32>(params.channels());
35 // Provides sampling rate in milliHertz to OpenSLES. 36 // Provides sampling rate in milliHertz to OpenSLES.
36 format_.samplesPerSec = static_cast<SLuint32>(params.sample_rate() * 1000); 37 format_.samplesPerSec = static_cast<SLuint32>(params.sample_rate() * 1000);
37 format_.bitsPerSample = params.bits_per_sample(); 38 format_.bitsPerSample = params.bits_per_sample();
38 format_.containerSize = params.bits_per_sample(); 39 format_.containerSize = params.bits_per_sample();
39 format_.endianness = SL_BYTEORDER_LITTLEENDIAN; 40 format_.endianness = SL_BYTEORDER_LITTLEENDIAN;
40 if (format_.numChannels == 1) 41 if (format_.numChannels == 1)
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 return; 166 return;
166 } 167 }
167 volume_ = volume_float; 168 volume_ = volume_float;
168 } 169 }
169 170
170 void OpenSLESOutputStream::GetVolume(double* volume) { 171 void OpenSLESOutputStream::GetVolume(double* volume) {
171 DCHECK(thread_checker_.CalledOnValidThread()); 172 DCHECK(thread_checker_.CalledOnValidThread());
172 *volume = static_cast<double>(volume_); 173 *volume = static_cast<double>(volume_);
173 } 174 }
174 175
176 void OpenSLESOutputStream::SetMute(bool muted) {
177 DVLOG(2) << "OpenSLESOutputStream::SetMute(" << muted << ")";
178 DCHECK(thread_checker_.CalledOnValidThread());
179 muted_ = muted;
180 }
181
175 bool OpenSLESOutputStream::CreatePlayer() { 182 bool OpenSLESOutputStream::CreatePlayer() {
176 DCHECK(thread_checker_.CalledOnValidThread()); 183 DCHECK(thread_checker_.CalledOnValidThread());
177 DCHECK(!engine_object_.Get()); 184 DCHECK(!engine_object_.Get());
178 DCHECK(!player_object_.Get()); 185 DCHECK(!player_object_.Get());
179 DCHECK(!output_mixer_.Get()); 186 DCHECK(!output_mixer_.Get());
180 DCHECK(!player_); 187 DCHECK(!player_);
181 DCHECK(!simple_buffer_queue_); 188 DCHECK(!simple_buffer_queue_);
182 189
183 // Initializes the engine object with specific option. After working with the 190 // Initializes the engine object with specific option. After working with the
184 // object, we need to free the object and its resources. 191 // object, we need to free the object and its resources.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 int frames_filled = callback_->OnMoreData( 324 int frames_filled = callback_->OnMoreData(
318 audio_bus_.get(), AudioBuffersState(0, hardware_delay)); 325 audio_bus_.get(), AudioBuffersState(0, hardware_delay));
319 if (frames_filled <= 0) { 326 if (frames_filled <= 0) {
320 // Audio source is shutting down, or halted on error. 327 // Audio source is shutting down, or halted on error.
321 return; 328 return;
322 } 329 }
323 330
324 // Note: If the internal representation ever changes from 16-bit PCM to 331 // Note: If the internal representation ever changes from 16-bit PCM to
325 // raw float, the data must be clipped and sanitized since it may come 332 // raw float, the data must be clipped and sanitized since it may come
326 // from an untrusted source such as NaCl. 333 // from an untrusted source such as NaCl.
327 audio_bus_->Scale(volume_); 334 audio_bus_->Scale(muted_ ? 0.0f : volume_);
328 audio_bus_->ToInterleaved(frames_filled, 335 audio_bus_->ToInterleaved(frames_filled,
329 format_.bitsPerSample / 8, 336 format_.bitsPerSample / 8,
330 audio_data_[active_buffer_index_]); 337 audio_data_[active_buffer_index_]);
331 338
332 const int num_filled_bytes = 339 const int num_filled_bytes =
333 frames_filled * audio_bus_->channels() * format_.bitsPerSample / 8; 340 frames_filled * audio_bus_->channels() * format_.bitsPerSample / 8;
334 DCHECK_LE(static_cast<size_t>(num_filled_bytes), buffer_size_bytes_); 341 DCHECK_LE(static_cast<size_t>(num_filled_bytes), buffer_size_bytes_);
335 342
336 // Enqueue the buffer for playback. 343 // Enqueue the buffer for playback.
337 SLresult err = 344 SLresult err =
(...skipping 24 matching lines...) Expand all
362 } 369 }
363 } 370 }
364 371
365 void OpenSLESOutputStream::HandleError(SLresult error) { 372 void OpenSLESOutputStream::HandleError(SLresult error) {
366 DLOG(ERROR) << "OpenSLES Output error " << error; 373 DLOG(ERROR) << "OpenSLES Output error " << error;
367 if (callback_) 374 if (callback_)
368 callback_->OnError(this); 375 callback_->OnError(this);
369 } 376 }
370 377
371 } // namespace media 378 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/android/opensles_output.h ('k') | media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698