From 85ef770d92bb8b632bcdf73847c42c1461bd8922 Mon Sep 17 00:00:00 2001 From: "andresp@webrtc.org" Date: Wed, 17 Sep 2014 11:44:51 +0000 Subject: [PATCH] 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 --- .../app/webrtc/java/jni/peerconnection_jni.cc | 8 +++-- .../android/media_demo/jni/on_load.cc | 15 ++++++---- .../video_capture/ensure_initialized.cc | 30 +++++-------------- .../video_capture/include/video_capture.h | 8 ----- .../include/video_capture_factory.h | 4 --- .../modules/video_capture/video_capture.gypi | 7 +++++ .../video_capture/video_capture_internal.h | 27 +++++++++++++++++ .../android/video_render_android_impl.cc | 7 ++--- .../video_render/video_render_internal.h | 27 +++++++++++++++++ webrtc/video_engine/include/vie_base.h | 9 ------ .../auto_test/source/vie_autotest_android.cc | 7 +++-- webrtc/video_engine/vie_impl.cc | 21 ------------- 12 files changed, 93 insertions(+), 77 deletions(-) create mode 100644 webrtc/modules/video_capture/video_capture_internal.h create mode 100644 webrtc/modules/video_render/video_render_internal.h diff --git a/talk/app/webrtc/java/jni/peerconnection_jni.cc b/talk/app/webrtc/java/jni/peerconnection_jni.cc index de1836d9d..9a7c8ad58 100644 --- a/talk/app/webrtc/java/jni/peerconnection_jni.cc +++ b/talk/app/webrtc/java/jni/peerconnection_jni.cc @@ -90,6 +90,8 @@ #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) #include +#include "webrtc/modules/video_capture/video_capture_internal.h" +#include "webrtc/modules/video_render/video_render_internal.h" #include "webrtc/system_wrappers/interface/logcat_trace_context.h" #include "webrtc/system_wrappers/interface/tick_util.h" using webrtc::CodecSpecificInfo; @@ -2765,8 +2767,10 @@ JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)( CHECK(g_jvm) << "JNI_OnLoad failed to run?"; bool failure = false; if (!factory_static_initialized) { - if (initialize_video) - failure |= webrtc::VideoEngine::SetAndroidObjects(g_jvm, context); + if (initialize_video) { + failure |= webrtc::SetCaptureAndroidVM(g_jvm, context); + failure |= webrtc::SetRenderAndroidVM(g_jvm); + } if (initialize_audio) failure |= webrtc::VoiceEngine::SetAndroidObjects(g_jvm, jni, context); factory_static_initialized = true; diff --git a/webrtc/examples/android/media_demo/jni/on_load.cc b/webrtc/examples/android/media_demo/jni/on_load.cc index 9fc4ca92b..fd7717170 100644 --- a/webrtc/examples/android/media_demo/jni/on_load.cc +++ b/webrtc/examples/android/media_demo/jni/on_load.cc @@ -15,7 +15,8 @@ #include "webrtc/examples/android/media_demo/jni/jni_helpers.h" #include "webrtc/examples/android/media_demo/jni/video_engine_jni.h" #include "webrtc/examples/android/media_demo/jni/voice_engine_jni.h" -#include "webrtc/video_engine/include/vie_base.h" +#include "webrtc/modules/video_capture/video_capture_internal.h" +#include "webrtc/modules/video_render/video_render_internal.h" #include "webrtc/voice_engine/include/voe_base.h" // Macro for native functions that can be found by way of jni-auto discovery. @@ -38,8 +39,10 @@ JOWW(void, NativeWebRtcContextRegistry_register)( jobject context) { webrtc_examples::SetVoeDeviceObjects(g_vm); webrtc_examples::SetVieDeviceObjects(g_vm); - CHECK(webrtc::VideoEngine::SetAndroidObjects(g_vm, context) == 0, - "Failed to register android objects to video engine"); + CHECK(webrtc::SetCaptureAndroidVM(g_vm, context) == 0, + "Failed to register android objects to video capture"); + CHECK(webrtc::SetRenderAndroidVM(g_vm) == 0, + "Failed to register android objects to video render"); CHECK(webrtc::VoiceEngine::SetAndroidObjects(g_vm, jni, context) == 0, "Failed to register android objects to voice engine"); } @@ -47,8 +50,10 @@ JOWW(void, NativeWebRtcContextRegistry_register)( JOWW(void, NativeWebRtcContextRegistry_unRegister)( JNIEnv* jni, jclass) { - CHECK(webrtc::VideoEngine::SetAndroidObjects(NULL, NULL) == 0, - "Failed to unregister android objects from video engine"); + CHECK(webrtc::SetCaptureAndroidVM(NULL, NULL) == 0, + "Failed to unregister android objects from video capture"); + CHECK(webrtc::SetRenderAndroidVM(NULL) == 0, + "Failed to unregister android objects from video render"); CHECK(webrtc::VoiceEngine::SetAndroidObjects(NULL, NULL, NULL) == 0, "Failed to unregister android objects from voice engine"); webrtc_examples::ClearVieDeviceObjects(); diff --git a/webrtc/modules/video_capture/ensure_initialized.cc b/webrtc/modules/video_capture/ensure_initialized.cc index 65c9a8dbe..9d43d9f1b 100644 --- a/webrtc/modules/video_capture/ensure_initialized.cc +++ b/webrtc/modules/video_capture/ensure_initialized.cc @@ -10,7 +10,7 @@ // Platform-specific initialization bits, if any, go here. -#if !defined(ANDROID) || !defined(WEBRTC_CHROMIUM_BUILD) +#ifndef ANDROID namespace webrtc { namespace videocapturemodule { @@ -18,26 +18,15 @@ void EnsureInitialized() {} } // namespace videocapturemodule } // namespace webrtc -#else // !defined(ANDROID) || !defined(WEBRTC_CHROMIUM_BUILD) +#else -#include #include #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 +#include "webrtc/base/checks.h" +#include "webrtc/modules/video_capture/video_capture_internal.h" namespace webrtc { - -// Declared in webrtc/modules/video_capture/include/video_capture.h. -int32_t SetCaptureAndroidVM(JavaVM* javaVM, jobject g_context); - namespace videocapturemodule { static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT; @@ -46,18 +35,15 @@ void EnsureInitializedOnce() { JNIEnv* jni = ::base::android::AttachCurrentThread(); jobject context = ::base::android::GetApplicationContext(); JavaVM* jvm = NULL; - int status = jni->GetJavaVM(&jvm); - ASSERT(status == 0); - status = webrtc::SetCaptureAndroidVM(jvm, context) == 0; - ASSERT(status); + CHECK_EQ(0, jni->GetJavaVM(&jvm)); + CHECK_EQ(0, webrtc::SetCaptureAndroidVM(jvm, context)); } void EnsureInitialized() { - int ret = pthread_once(&g_initialize_once, &EnsureInitializedOnce); - ASSERT(ret == 0); + CHECK_EQ(0, pthread_once(&g_initialize_once, &EnsureInitializedOnce)); } } // namespace videocapturemodule } // namespace webrtc -#endif // ANDROID & WEBRTC_CHROMIUM_BUILD +#endif // !ANDROID diff --git a/webrtc/modules/video_capture/include/video_capture.h b/webrtc/modules/video_capture/include/video_capture.h index 7398af604..6e728d152 100644 --- a/webrtc/modules/video_capture/include/video_capture.h +++ b/webrtc/modules/video_capture/include/video_capture.h @@ -14,16 +14,8 @@ #include "webrtc/modules/interface/module.h" #include "webrtc/modules/video_capture/include/video_capture_defines.h" -#ifdef ANDROID -#include -#endif - namespace webrtc { -#if defined(ANDROID) -int32_t SetCaptureAndroidVM(JavaVM* javaVM, jobject context); -#endif - class VideoCaptureModule: public RefCountedModule { public: // Interface for receiving information about available camera devices. diff --git a/webrtc/modules/video_capture/include/video_capture_factory.h b/webrtc/modules/video_capture/include/video_capture_factory.h index ec92d31e1..f78437d1a 100644 --- a/webrtc/modules/video_capture/include/video_capture_factory.h +++ b/webrtc/modules/video_capture/include/video_capture_factory.h @@ -36,10 +36,6 @@ class VideoCaptureFactory { static VideoCaptureModule::DeviceInfo* CreateDeviceInfo( const int32_t id); -#ifdef WEBRTC_ANDROID - static int32_t SetAndroidObjects(void* javaVM, void* javaContext); -#endif - private: ~VideoCaptureFactory(); }; diff --git a/webrtc/modules/video_capture/video_capture.gypi b/webrtc/modules/video_capture/video_capture.gypi index 3e83ab3f7..68d419680 100644 --- a/webrtc/modules/video_capture/video_capture.gypi +++ b/webrtc/modules/video_capture/video_capture.gypi @@ -187,6 +187,13 @@ 'dependencies': [ '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code', ], + # Need to disable error due to the line in + # base/android/jni_android.h triggering it: + # const BASE_EXPORT jobject GetApplicationContext() + # error: type qualifiers ignored on function return type + 'cflags': [ + '-Wno-ignored-qualifiers', + ], }], ['OS=="mac"', { 'dependencies': [ diff --git a/webrtc/modules/video_capture/video_capture_internal.h b/webrtc/modules/video_capture/video_capture_internal.h new file mode 100644 index 000000000..1a90af130 --- /dev/null +++ b/webrtc/modules/video_capture/video_capture_internal.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012 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. + */ + +#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_VIDEO_CAPTURE_INTERNAL_H_ +#define WEBRTC_MODULES_VIDEO_CAPTURE_VIDEO_CAPTURE_INTERNAL_H_ + +#ifdef ANDROID +#include + +namespace webrtc { + +// In order to be able to use the internal webrtc video capture +// for android, the jvm objects must be set via this method. +int32_t SetCaptureAndroidVM(JavaVM* javaVM, jobject context); + +} // namespace webrtc + +#endif // ANDROID + +#endif // WEBRTC_MODULES_VIDEO_CAPTURE_VIDEO_CAPTURE_INTERNAL_H_ diff --git a/webrtc/modules/video_render/android/video_render_android_impl.cc b/webrtc/modules/video_render/android/video_render_android_impl.cc index 27a264ac0..20694b656 100644 --- a/webrtc/modules/video_render/android/video_render_android_impl.cc +++ b/webrtc/modules/video_render/android/video_render_android_impl.cc @@ -10,6 +10,7 @@ #include "webrtc/modules/video_render/android/video_render_android_impl.h" +#include "webrtc/modules/video_render/video_render_internal.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/event_wrapper.h" #include "webrtc/system_wrappers/interface/thread_wrapper.h" @@ -29,13 +30,11 @@ namespace webrtc { JavaVM* VideoRenderAndroid::g_jvm = NULL; -#if defined(WEBRTC_ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) -int32_t SetRenderAndroidVM(void* javaVM) { +int32_t SetRenderAndroidVM(JavaVM* javaVM) { WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, -1, "%s", __FUNCTION__); - VideoRenderAndroid::g_jvm = (JavaVM*)javaVM; + VideoRenderAndroid::g_jvm = javaVM; return 0; } -#endif VideoRenderAndroid::VideoRenderAndroid( const int32_t id, diff --git a/webrtc/modules/video_render/video_render_internal.h b/webrtc/modules/video_render/video_render_internal.h new file mode 100644 index 000000000..0508c1a70 --- /dev/null +++ b/webrtc/modules/video_render/video_render_internal.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012 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. + */ + +#ifndef WEBRTC_MODULES_VIDEO_RENDER_VIDEO_RENDER_INTERNAL_H_ +#define WEBRTC_MODULES_VIDEO_RENDER_VIDEO_RENDER_INTERNAL_H_ + +#ifdef ANDROID +#include + +namespace webrtc { + +// In order to be able to use the internal webrtc video render +// for android, the jvm objects must be set via this method. +int32_t SetRenderAndroidVM(JavaVM* javaVM); + +} // namespace webrtc + +#endif // ANDROID + +#endif // WEBRTC_MODULES_VIDEO_RENDER_VIDEO_RENDER_INTERNAL_H_ diff --git a/webrtc/video_engine/include/vie_base.h b/webrtc/video_engine/include/vie_base.h index 236257060..4e619e586 100644 --- a/webrtc/video_engine/include/vie_base.h +++ b/webrtc/video_engine/include/vie_base.h @@ -21,10 +21,6 @@ #include "webrtc/common_types.h" -#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) -#include -#endif - namespace webrtc { class Config; @@ -142,11 +138,6 @@ class WEBRTC_DLLEXPORT VideoEngine { // user receives callbacks for generated trace messages. static int SetTraceCallback(TraceCallback* callback); -#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) - // Android specific. - static int SetAndroidObjects(JavaVM* java_vm, jobject context); -#endif - protected: VideoEngine() {} virtual ~VideoEngine() {} diff --git a/webrtc/video_engine/test/auto_test/source/vie_autotest_android.cc b/webrtc/video_engine/test/auto_test/source/vie_autotest_android.cc index ac0dd17ee..ced235f6b 100644 --- a/webrtc/video_engine/test/auto_test/source/vie_autotest_android.cc +++ b/webrtc/video_engine/test/auto_test/source/vie_autotest_android.cc @@ -13,15 +13,18 @@ #include #include -#include "webrtc/video_engine/test/auto_test/interface/vie_autotest.h" +#include "webrtc/modules/video_capture/video_capture_internal.h" +#include "webrtc/modules/video_render/video_render_internal.h" #include "webrtc/video_engine/test/auto_test/interface/vie_autotest_defines.h" +#include "webrtc/video_engine/test/auto_test/interface/vie_autotest.h" int ViEAutoTestAndroid::RunAutotest(int testSelection, int subTestSelection, void* window1, void* window2, JavaVM* javaVM, void* env, void* context) { ViEAutoTest vieAutoTest(window1, window2); ViETest::Log("RunAutoTest(%d, %d)", testSelection, subTestSelection); - webrtc::VideoEngine::SetAndroidObjects(javaVM, static_cast(context)); + webrtc::SetCaptureAndroidVM(javaVM, static_cast(context)); + webrtc::SetRenderAndroidVM(javaVM); #ifndef WEBRTC_ANDROID_OPENSLES // voice engine calls into ADM directly webrtc::VoiceEngine::SetAndroidObjects(javaVM, env, context); diff --git a/webrtc/video_engine/vie_impl.cc b/webrtc/video_engine/vie_impl.cc index 3cdf5da2f..79f033b4e 100644 --- a/webrtc/video_engine/vie_impl.cc +++ b/webrtc/video_engine/vie_impl.cc @@ -14,11 +14,6 @@ #include "webrtc/system_wrappers/interface/logging.h" #include "webrtc/system_wrappers/interface/trace.h" -#ifdef WEBRTC_ANDROID -#include "webrtc/modules/video_capture/include/video_capture_factory.h" -#include "webrtc/modules/video_render/include/video_render.h" -#endif - namespace webrtc { enum { kModuleId = 0 }; @@ -139,20 +134,4 @@ int VideoEngine::SetTraceCallback(TraceCallback* callback) { return Trace::SetTraceCallback(callback); } -#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) -int VideoEngine::SetAndroidObjects(JavaVM* javaVM, jobject context) { - LOG_F(LS_INFO); - - if (SetCaptureAndroidVM(javaVM, context) != 0) { - LOG(LS_ERROR) << "Could not set capture Android VM"; - return -1; - } - if (SetRenderAndroidVM(javaVM) != 0) { - LOG(LS_ERROR) << "Could not set render Android VM"; - return -1; - } - return 0; -} -#endif - } // namespace webrtc