Skip to content

Commit

Permalink
Split video engine android initialization into each internal module i…
Browse files Browse the repository at this point in the history
…nitialization.

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
  • Loading branch information
andresusanopinto committed Sep 17, 2014
1 parent ab990ae commit 85ef770
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 77 deletions.
8 changes: 6 additions & 2 deletions talk/app/webrtc/java/jni/peerconnection_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@

#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
#include <android/log.h>
#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;
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions webrtc/examples/android/media_demo/jni/on_load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -38,17 +39,21 @@ 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");
}

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();
Expand Down
30 changes: 8 additions & 22 deletions webrtc/modules/video_capture/ensure_initialized.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,23 @@

// Platform-specific initialization bits, if any, go here.

#if !defined(ANDROID) || !defined(WEBRTC_CHROMIUM_BUILD)
#ifndef ANDROID

namespace webrtc {
namespace videocapturemodule {
void EnsureInitialized() {}
} // namespace videocapturemodule
} // namespace webrtc

#else // !defined(ANDROID) || !defined(WEBRTC_CHROMIUM_BUILD)
#else

#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
#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;
Expand All @@ -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
8 changes: 0 additions & 8 deletions webrtc/modules/video_capture/include/video_capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@
#include "webrtc/modules/interface/module.h"
#include "webrtc/modules/video_capture/include/video_capture_defines.h"

#ifdef ANDROID
#include <jni.h>
#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.
Expand Down
4 changes: 0 additions & 4 deletions webrtc/modules/video_capture/include/video_capture_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
7 changes: 7 additions & 0 deletions webrtc/modules/video_capture/video_capture.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down
27 changes: 27 additions & 0 deletions webrtc/modules/video_capture/video_capture_internal.h
Original file line number Diff line number Diff line change
@@ -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 <jni.h>

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_
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions webrtc/modules/video_render/video_render_internal.h
Original file line number Diff line number Diff line change
@@ -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 <jni.h>

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_
9 changes: 0 additions & 9 deletions webrtc/video_engine/include/vie_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

#include "webrtc/common_types.h"

#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
#include <jni.h>
#endif

namespace webrtc {

class Config;
Expand Down Expand Up @@ -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() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
#include <android/log.h>
#include <stdio.h>

#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<jobject>(context));
webrtc::SetCaptureAndroidVM(javaVM, static_cast<jobject>(context));
webrtc::SetRenderAndroidVM(javaVM);
#ifndef WEBRTC_ANDROID_OPENSLES
// voice engine calls into ADM directly
webrtc::VoiceEngine::SetAndroidObjects(javaVM, env, context);
Expand Down
21 changes: 0 additions & 21 deletions webrtc/video_engine/vie_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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

0 comments on commit 85ef770

Please sign in to comment.