1/* 2 * Copyright (c) 2014 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// Platform-specific initialization bits, if any, go here. 12 13#ifndef ANDROID 14 15namespace webrtc { 16namespace videocapturemodule { 17void EnsureInitialized() {} 18} // namespace videocapturemodule 19} // namespace webrtc 20 21#else 22 23#include <pthread.h> 24 25#include "base/android/jni_android.h" 26#include "webrtc/base/checks.h" 27#include "webrtc/modules/video_capture/video_capture_internal.h" 28 29namespace webrtc { 30namespace videocapturemodule { 31 32static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT; 33 34void EnsureInitializedOnce() { 35 JNIEnv* jni = ::base::android::AttachCurrentThread(); 36 jobject context = ::base::android::GetApplicationContext(); 37 JavaVM* jvm = NULL; 38 CHECK_EQ(0, jni->GetJavaVM(&jvm)); 39 CHECK_EQ(0, webrtc::SetCaptureAndroidVM(jvm, context)); 40} 41 42void EnsureInitialized() { 43 CHECK_EQ(0, pthread_once(&g_initialize_once, &EnsureInitializedOnce)); 44} 45 46} // namespace videocapturemodule 47} // namespace webrtc 48 49#endif // !ANDROID 50