webrtc_m130/webrtc/modules/video_capture/ensure_initialized.cc
andresp@webrtc.org 85ef770d92 Split video engine android initialization into each internal module initialization.
This is to later on allow targets to pick at link time if to include the external or internal implementation. In order to do that the video_engine cannot compile different based on which option is picked later on.

BUG=3768,3770
R=glaznev@webrtc.org, stefan@webrtc.org
TBR=henrike@webrtc.org, mflodman@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/25529004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7208 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-09-17 11:44:51 +00:00

50 lines
1.3 KiB
C++

/*
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// Platform-specific initialization bits, if any, go here.
#ifndef ANDROID
namespace webrtc {
namespace videocapturemodule {
void EnsureInitialized() {}
} // namespace videocapturemodule
} // namespace webrtc
#else
#include <pthread.h>
#include "base/android/jni_android.h"
#include "webrtc/base/checks.h"
#include "webrtc/modules/video_capture/video_capture_internal.h"
namespace webrtc {
namespace videocapturemodule {
static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT;
void EnsureInitializedOnce() {
JNIEnv* jni = ::base::android::AttachCurrentThread();
jobject context = ::base::android::GetApplicationContext();
JavaVM* jvm = NULL;
CHECK_EQ(0, jni->GetJavaVM(&jvm));
CHECK_EQ(0, webrtc::SetCaptureAndroidVM(jvm, context));
}
void EnsureInitialized() {
CHECK_EQ(0, pthread_once(&g_initialize_once, &EnsureInitializedOnce));
}
} // namespace videocapturemodule
} // namespace webrtc
#endif // !ANDROID