webrtc_m130/webrtc/modules/video_capture/ensure_initialized.cc
fischman@webrtc.org f93021430d Remove self-assignment hacks that were added to avoid unused variable warnings.
Instead, appear to use the variables.

BUG=3152
R=wu@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5877 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-04-09 21:19:55 +00:00

63 lines
1.7 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.
#if !defined(ANDROID) || !defined(WEBRTC_CHROMIUM_BUILD)
namespace webrtc {
namespace videocapturemodule {
void EnsureInitialized() {}
} // namespace videocapturemodule
} // namespace webrtc
#else // !defined(ANDROID) || !defined(WEBRTC_CHROMIUM_BUILD)
#include <assert.h>
#include <pthread.h>
#include "base/android/jni_android.h"
// Handy alternative to assert() which suppresses unused-variable warnings when
// assert() is a no-op (i.e. in Release builds).
#ifdef NDEBUG
#define ASSERT(x) if (false && (x)); else
#else
#define ASSERT(x) assert(x)
#endif
namespace webrtc {
// Declared in webrtc/modules/video_capture/include/video_capture.h.
int32_t SetCaptureAndroidVM(JavaVM* javaVM);
namespace videocapturemodule {
static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT;
void EnsureInitializedOnce() {
JNIEnv* jni = ::base::android::AttachCurrentThread();
JavaVM* jvm = NULL;
int status = jni->GetJavaVM(&jvm);
ASSERT(status == 0);
status = webrtc::SetCaptureAndroidVM(jvm) == 0;
ASSERT(status);
}
void EnsureInitialized() {
int ret = pthread_once(&g_initialize_once, &EnsureInitializedOnce);
ASSERT(ret == 0);
}
} // namespace videocapturemodule
} // namespace webrtc
#endif // ANDROID & WEBRTC_CHROMIUM_BUILD