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

Side by Side Diff: media/audio/android/audio_manager_android.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
« no previous file with comments | « media/audio/android/audio_manager_android.h ('k') | media/audio/android/opensles_output.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/audio_manager_android.h" 5 #include "media/audio/android/audio_manager_android.h"
6 6
7 #include "base/android/build_info.h" 7 #include "base/android/build_info.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 AudioManager* CreateAudioManager() { 45 AudioManager* CreateAudioManager() {
46 return new AudioManagerAndroid(); 46 return new AudioManagerAndroid();
47 } 47 }
48 48
49 AudioManagerAndroid::AudioManagerAndroid() { 49 AudioManagerAndroid::AudioManagerAndroid() {
50 SetMaxOutputStreamsAllowed(kMaxOutputStreams); 50 SetMaxOutputStreamsAllowed(kMaxOutputStreams);
51 51
52 j_audio_manager_.Reset( 52 j_audio_manager_.Reset(
53 Java_AudioManagerAndroid_createAudioManagerAndroid( 53 Java_AudioManagerAndroid_createAudioManagerAndroid(
54 base::android::AttachCurrentThread(), 54 base::android::AttachCurrentThread(),
55 base::android::GetApplicationContext())); 55 base::android::GetApplicationContext(),
56 reinterpret_cast<intptr_t>(this)));
56 Init(); 57 Init();
57 } 58 }
58 59
59 AudioManagerAndroid::~AudioManagerAndroid() { 60 AudioManagerAndroid::~AudioManagerAndroid() {
60 Close(); 61 Close();
61 Shutdown(); 62 Shutdown();
62 } 63 }
63 64
64 bool AudioManagerAndroid::HasAudioOutputDevices() { 65 bool AudioManagerAndroid::HasAudioOutputDevices() {
65 return true; 66 return true;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( 119 AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream(
119 const AudioParameters& params, 120 const AudioParameters& params,
120 const std::string& device_id, 121 const std::string& device_id,
121 const std::string& input_device_id) { 122 const std::string& input_device_id) {
122 AudioOutputStream* stream = 123 AudioOutputStream* stream =
123 AudioManagerBase::MakeAudioOutputStream(params, std::string(), 124 AudioManagerBase::MakeAudioOutputStream(params, std::string(),
124 std::string()); 125 std::string());
125 if (stream && output_stream_count() == 1) { 126 if (stream && output_stream_count() == 1) {
126 SetAudioMode(kAudioModeInCommunication); 127 SetAudioMode(kAudioModeInCommunication);
127 } 128 }
129
130 {
131 base::AutoLock lock(streams_lock_);
132 streams_.insert(static_cast<OpenSLESOutputStream*>(stream));
133 }
134
128 return stream; 135 return stream;
129 } 136 }
130 137
131 AudioInputStream* AudioManagerAndroid::MakeAudioInputStream( 138 AudioInputStream* AudioManagerAndroid::MakeAudioInputStream(
132 const AudioParameters& params, const std::string& device_id) { 139 const AudioParameters& params, const std::string& device_id) {
133 AudioInputStream* stream = 140 AudioInputStream* stream =
134 AudioManagerBase::MakeAudioInputStream(params, device_id); 141 AudioManagerBase::MakeAudioInputStream(params, device_id);
135 return stream; 142 return stream;
136 } 143 }
137 144
138 void AudioManagerAndroid::ReleaseOutputStream(AudioOutputStream* stream) { 145 void AudioManagerAndroid::ReleaseOutputStream(AudioOutputStream* stream) {
139 AudioManagerBase::ReleaseOutputStream(stream); 146 AudioManagerBase::ReleaseOutputStream(stream);
140 if (!output_stream_count()) { 147 if (!output_stream_count()) {
141 SetAudioMode(kAudioModeNormal); 148 SetAudioMode(kAudioModeNormal);
142 } 149 }
150 base::AutoLock lock(streams_lock_);
151 streams_.erase(static_cast<OpenSLESOutputStream*>(stream));
143 } 152 }
144 153
145 void AudioManagerAndroid::ReleaseInputStream(AudioInputStream* stream) { 154 void AudioManagerAndroid::ReleaseInputStream(AudioInputStream* stream) {
146 AudioManagerBase::ReleaseInputStream(stream); 155 AudioManagerBase::ReleaseInputStream(stream);
147 } 156 }
148 157
149 AudioOutputStream* AudioManagerAndroid::MakeLinearOutputStream( 158 AudioOutputStream* AudioManagerAndroid::MakeLinearOutputStream(
150 const AudioParameters& params) { 159 const AudioParameters& params) {
151 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); 160 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format());
152 return new OpenSLESOutputStream(this, params); 161 return new OpenSLESOutputStream(this, params);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 base::android::AttachCurrentThread(), 239 base::android::AttachCurrentThread(),
231 j_audio_manager_.obj()); 240 j_audio_manager_.obj());
232 } 241 }
233 242
234 void AudioManagerAndroid::Close() { 243 void AudioManagerAndroid::Close() {
235 Java_AudioManagerAndroid_close( 244 Java_AudioManagerAndroid_close(
236 base::android::AttachCurrentThread(), 245 base::android::AttachCurrentThread(),
237 j_audio_manager_.obj()); 246 j_audio_manager_.obj());
238 } 247 }
239 248
249 void AudioManagerAndroid::SetMute(JNIEnv* env, jobject obj, jboolean muted) {
250 GetMessageLoop()->PostTask(
251 FROM_HERE,
252 base::Bind(
253 &AudioManagerAndroid::DoSetMuteOnAudioThread,
254 base::Unretained(this),
255 muted));
256 }
257
258 void AudioManagerAndroid::DoSetMuteOnAudioThread(bool muted) {
259 base::AutoLock lock(streams_lock_);
260 for (OutputStreams::iterator it = streams_.begin();
261 it != streams_.end(); ++it) {
262 (*it)->SetMute(muted);
263 }
264 }
265
240 void AudioManagerAndroid::SetAudioMode(int mode) { 266 void AudioManagerAndroid::SetAudioMode(int mode) {
241 Java_AudioManagerAndroid_setMode( 267 Java_AudioManagerAndroid_setMode(
242 base::android::AttachCurrentThread(), 268 base::android::AttachCurrentThread(),
243 j_audio_manager_.obj(), mode); 269 j_audio_manager_.obj(), mode);
244 } 270 }
245 271
246 void AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { 272 void AudioManagerAndroid::SetAudioDevice(const std::string& device_id) {
247 JNIEnv* env = AttachCurrentThread(); 273 JNIEnv* env = AttachCurrentThread();
248 274
249 // Send the unique device ID to the Java audio manager and make the 275 // Send the unique device ID to the Java audio manager and make the
(...skipping 19 matching lines...) Expand all
269 j_audio_manager_.obj()); 295 j_audio_manager_.obj());
270 } 296 }
271 297
272 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { 298 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() {
273 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( 299 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize(
274 base::android::AttachCurrentThread(), 300 base::android::AttachCurrentThread(),
275 j_audio_manager_.obj()); 301 j_audio_manager_.obj());
276 } 302 }
277 303
278 } // namespace media 304 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/android/audio_manager_android.h ('k') | media/audio/android/opensles_output.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698