blob: 469068a876a335c4ad8bcbb2c95ce6dc65a25990 [file] [log] [blame]
henrika@webrtc.org474d1eb2015-03-09 12:39:53 +00001/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/modules/audio_device/android/ensure_initialized.h"
12
13#include <pthread.h>
14
15#include "base/android/jni_android.h"
16#include "webrtc/base/checks.h"
17#include "webrtc/modules/audio_device/android/audio_device_template.h"
18#include "webrtc/modules/audio_device/android/audio_record_jni.h"
19#include "webrtc/modules/audio_device/android/audio_track_jni.h"
20#include "webrtc/modules/audio_device/android/opensles_input.h"
21#include "webrtc/modules/audio_device/android/opensles_output.h"
22
23namespace webrtc {
24namespace audiodevicemodule {
25
26static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT;
27
28void EnsureInitializedOnce() {
29 CHECK(::base::android::IsVMInitialized());
30 JNIEnv* jni = ::base::android::AttachCurrentThread();
31 JavaVM* jvm = NULL;
32 CHECK_EQ(0, jni->GetJavaVM(&jvm));
33 jobject context = ::base::android::GetApplicationContext();
34
35 // Provide JVM and context to Java and OpenSL ES implementations.
36 using AudioDeviceJava = AudioDeviceTemplate<AudioRecordJni, AudioTrackJni>;
37 AudioDeviceJava::SetAndroidAudioDeviceObjects(jvm, context);
38
39 // TODO(henrika): enable OpenSL ES when it has been refactored to avoid
40 // crashes.
41 // using AudioDeviceOpenSLES
42 // AudioDeviceTemplate<OpenSlesInput, OpenSlesOutput>;
43 // AudioDeviceOpenSLESInstance::SetAndroidAudioDeviceObjects(jvm, context);
44}
45
46void EnsureInitialized() {
47 CHECK_EQ(0, pthread_once(&g_initialize_once, &EnsureInitializedOnce));
48}
49
50} // namespace audiodevicemodule
51} // namespace webrtc