blob: 69f22ede76ac6c1cb579fffcdf2daf7c6f8347ba [file] [log] [blame]
fischman@webrtc.orgb0b135e2014-04-09 01:18:32 +00001/*
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#if !defined(ANDROID) || !defined(WEBRTC_CHROMIUM_BUILD)
14
15namespace webrtc {
16namespace videocapturemodule {
17void EnsureInitialized() {}
18} // namespace videocapturemodule
19} // namespace webrtc
20
21#else // !defined(ANDROID) || !defined(WEBRTC_CHROMIUM_BUILD)
22
23#include <assert.h>
24#include <pthread.h>
25
26#include "base/android/jni_android.h"
27
28namespace webrtc {
29
30// Declared in webrtc/modules/video_capture/include/video_capture.h.
31int32_t SetCaptureAndroidVM(JavaVM* javaVM);
32
33namespace videocapturemodule {
34
35static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT;
36
37void EnsureInitializedOnce() {
38 JNIEnv* jni = ::base::android::AttachCurrentThread();
39 JavaVM* jvm = NULL;
40 int status = jni->GetJavaVM(&jvm);
41 assert(status == 0);
42 status = webrtc::SetCaptureAndroidVM(jvm) == 0;
43 assert(status);
44}
45
46void EnsureInitialized() {
47 int ret = pthread_once(&g_initialize_once, &EnsureInitializedOnce);
48 assert(ret == 0);
49}
50
51} // namespace videocapturemodule
52} // namespace webrtc
53
54#endif // ANDROID & WEBRTC_CHROMIUM_BUILD