fischman@webrtc.org | b0b135e | 2014-04-09 01:18:32 +0000 | [diff] [blame^] | 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 | #if !defined(ANDROID) || !defined(WEBRTC_CHROMIUM_BUILD) |
| 14 | |
| 15 | namespace webrtc { |
| 16 | namespace videocapturemodule { |
| 17 | void 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 | |
| 28 | namespace webrtc { |
| 29 | |
| 30 | // Declared in webrtc/modules/video_capture/include/video_capture.h. |
| 31 | int32_t SetCaptureAndroidVM(JavaVM* javaVM); |
| 32 | |
| 33 | namespace videocapturemodule { |
| 34 | |
| 35 | static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT; |
| 36 | |
| 37 | void 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 | |
| 46 | void 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 |