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 | |
fischman@webrtc.org | f930214 | 2014-04-09 21:19:55 +0000 | [diff] [blame] | 28 | // Handy alternative to assert() which suppresses unused-variable warnings when |
| 29 | // assert() is a no-op (i.e. in Release builds). |
| 30 | #ifdef NDEBUG |
| 31 | #define ASSERT(x) if (false && (x)); else |
| 32 | #else |
| 33 | #define ASSERT(x) assert(x) |
| 34 | #endif |
| 35 | |
fischman@webrtc.org | b0b135e | 2014-04-09 01:18:32 +0000 | [diff] [blame] | 36 | namespace webrtc { |
| 37 | |
| 38 | // Declared in webrtc/modules/video_capture/include/video_capture.h. |
fischman@webrtc.org | 9512719 | 2014-06-06 18:40:44 +0000 | [diff] [blame] | 39 | int32_t SetCaptureAndroidVM(JavaVM* javaVM, jobject g_context); |
fischman@webrtc.org | b0b135e | 2014-04-09 01:18:32 +0000 | [diff] [blame] | 40 | |
| 41 | namespace videocapturemodule { |
| 42 | |
| 43 | static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT; |
| 44 | |
| 45 | void EnsureInitializedOnce() { |
| 46 | JNIEnv* jni = ::base::android::AttachCurrentThread(); |
fischman@webrtc.org | 9512719 | 2014-06-06 18:40:44 +0000 | [diff] [blame] | 47 | jobject context = ::base::android::GetApplicationContext(); |
fischman@webrtc.org | b0b135e | 2014-04-09 01:18:32 +0000 | [diff] [blame] | 48 | JavaVM* jvm = NULL; |
| 49 | int status = jni->GetJavaVM(&jvm); |
fischman@webrtc.org | f930214 | 2014-04-09 21:19:55 +0000 | [diff] [blame] | 50 | ASSERT(status == 0); |
fischman@webrtc.org | 9512719 | 2014-06-06 18:40:44 +0000 | [diff] [blame] | 51 | status = webrtc::SetCaptureAndroidVM(jvm, context) == 0; |
fischman@webrtc.org | f930214 | 2014-04-09 21:19:55 +0000 | [diff] [blame] | 52 | ASSERT(status); |
fischman@webrtc.org | b0b135e | 2014-04-09 01:18:32 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void EnsureInitialized() { |
| 56 | int ret = pthread_once(&g_initialize_once, &EnsureInitializedOnce); |
fischman@webrtc.org | f930214 | 2014-04-09 21:19:55 +0000 | [diff] [blame] | 57 | ASSERT(ret == 0); |
fischman@webrtc.org | b0b135e | 2014-04-09 01:18:32 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | } // namespace videocapturemodule |
| 61 | } // namespace webrtc |
| 62 | |
| 63 | #endif // ANDROID & WEBRTC_CHROMIUM_BUILD |