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

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

Issue 12571006: Add MODIFY_AUDIO_SETTINGS permission in Android manifest and implementation in audio manager. (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 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
« no previous file with comments | « media/audio/android/opensles_output.h ('k') | testing/android/AndroidManifest.xml » ('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/opensles_output.h" 5 #include "media/audio/android/opensles_output.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/audio/audio_util.h" 8 #include "media/audio/audio_util.h"
9 #include "media/audio/android/audio_manager_android.h" 9 #include "media/audio/android/audio_manager_android.h"
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 OpenSLESOutputStream::~OpenSLESOutputStream() { 43 OpenSLESOutputStream::~OpenSLESOutputStream() {
44 DCHECK(!engine_object_.Get()); 44 DCHECK(!engine_object_.Get());
45 DCHECK(!player_object_.Get()); 45 DCHECK(!player_object_.Get());
46 DCHECK(!output_mixer_.Get()); 46 DCHECK(!output_mixer_.Get());
47 DCHECK(!player_); 47 DCHECK(!player_);
48 DCHECK(!simple_buffer_queue_); 48 DCHECK(!simple_buffer_queue_);
49 DCHECK(!audio_data_[0]); 49 DCHECK(!audio_data_[0]);
50 } 50 }
51 51
52 void OpenSLESOutputStream::SetAudioMode() {
53 JNIEnv* env = base::android::AttachCurrentThread();
54 DCHECK(env);
55
56 jobject j_context = base::android::GetApplicationContext();
57 DCHECK(j_context);
58
59 // context.getSystemService(Context.AUDIO_SERVICE).
Yaron 2013/03/09 00:31:18 We're no longer taking patches with hand-written J
60 jstring audio_service_string = env->NewStringUTF("audio");
61 jclass context_class = env->GetObjectClass(j_context);
Yaron 2013/03/09 00:31:18 Examle for why we say this: you're currently leaki
62 CHECK(context_class);
63 jmethodID method = env->GetMethodID(
64 context_class, "getSystemService",
65 "(Ljava/lang/String;)Ljava/lang/Object;");
66 CHECK(method);
67 jobject j_am = env->CallObjectMethod(j_context, method,
68 audio_service_string);
69 CHECK(j_am);
70 jclass j_am_class = env->GetObjectClass(j_am);
71 CHECK(j_am_class);
72
73 // AudioManager.MODE_IN_COMMUNICATION.
74 jclass cls = env->FindClass("android/media/AudioManager");
75 CHECK(cls);
76 jfieldID field = env->GetStaticFieldID(
77 cls,
78 "MODE_IN_COMMUNICATION",
79 "I");
80 CHECK(field);
81 jint am_mode = env->GetStaticIntField(cls, field);
82 CHECK(am_mode);
83 env->DeleteLocalRef(cls);
84
85 // audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION)
86 jmethodID setmode_method = env->GetMethodID(j_am_class, "setMode", "(I)V");
87 CHECK(setmode_method);
88 env->CallVoidMethod(j_am, setmode_method, am_mode);
89 base::android::CheckException(env);
90 }
91
52 bool OpenSLESOutputStream::Open() { 92 bool OpenSLESOutputStream::Open() {
53 if (engine_object_.Get()) 93 if (engine_object_.Get())
54 return false; 94 return false;
55 95
56 if (!CreatePlayer()) 96 if (!CreatePlayer())
57 return false; 97 return false;
58 98
99 SetAudioMode();
100
59 SetupAudioBuffer(); 101 SetupAudioBuffer();
60 102
61 return true; 103 return true;
62 } 104 }
63 105
64 void OpenSLESOutputStream::Start(AudioSourceCallback* callback) { 106 void OpenSLESOutputStream::Start(AudioSourceCallback* callback) {
65 DCHECK(callback); 107 DCHECK(callback);
66 DCHECK(player_); 108 DCHECK(player_);
67 DCHECK(simple_buffer_queue_); 109 DCHECK(simple_buffer_queue_);
68 if (started_) 110 if (started_)
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 346 }
305 } 347 }
306 348
307 void OpenSLESOutputStream::HandleError(SLresult error) { 349 void OpenSLESOutputStream::HandleError(SLresult error) {
308 DLOG(ERROR) << "OpenSLES error " << error; 350 DLOG(ERROR) << "OpenSLES error " << error;
309 if (callback_) 351 if (callback_)
310 callback_->OnError(this, error); 352 callback_->OnError(this, error);
311 } 353 }
312 354
313 } // namespace media 355 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/android/opensles_output.h ('k') | testing/android/AndroidManifest.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698