PeerConnection(android): allow initializing either (or neither) of {Voice,Video}Engine.

Enables applications that don't want to pay the init/startup cost or request
extra permissions (e.g. audio-only app, or DataChannel-only app).

BUG=3234

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6164 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
fischman@webrtc.org
2014-05-14 22:00:50 +00:00
parent ef5a752c29
commit a150bc9bbf
3 changed files with 13 additions and 5 deletions

View File

@@ -1892,10 +1892,13 @@ JOW(jlong, PeerConnectionFactory_nativeCreateObserver)(
#ifdef ANDROID #ifdef ANDROID
JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)( JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)(
JNIEnv* jni, jclass, jobject context) { JNIEnv* jni, jclass, jobject context,
jboolean initialize_audio, jboolean initialize_video) {
CHECK(g_jvm, "JNI_OnLoad failed to run?"); CHECK(g_jvm, "JNI_OnLoad failed to run?");
bool failure = false; bool failure = false;
if (initialize_video)
failure |= webrtc::VideoEngine::SetAndroidObjects(g_jvm); failure |= webrtc::VideoEngine::SetAndroidObjects(g_jvm);
if (initialize_audio)
failure |= webrtc::VoiceEngine::SetAndroidObjects(g_jvm, jni, context); failure |= webrtc::VoiceEngine::SetAndroidObjects(g_jvm, jni, context);
return !failure; return !failure;
} }

View File

@@ -43,7 +43,11 @@ public class PeerConnectionFactory {
// |context| is an android.content.Context object, but we keep it untyped here // |context| is an android.content.Context object, but we keep it untyped here
// to allow building on non-Android platforms. // to allow building on non-Android platforms.
public static native boolean initializeAndroidGlobals(Object context); // Callers may specify either |initializeAudio| or |initializeVideo| as false
// to skip initializing the respective engine (and avoid the need for the
// respective permissions).
public static native boolean initializeAndroidGlobals(
Object context, boolean initializeAudio, boolean initializeVideo);
public PeerConnectionFactory() { public PeerConnectionFactory() {
nativeFactory = nativeCreatePeerConnectionFactory(); nativeFactory = nativeCreatePeerConnectionFactory();

View File

@@ -125,7 +125,8 @@ public class AppRTCDemoActivity extends Activity
addContentView(hudView, hudLayout); addContentView(hudView, hudLayout);
if (!factoryStaticInitialized) { if (!factoryStaticInitialized) {
abortUnless(PeerConnectionFactory.initializeAndroidGlobals(this), abortUnless(PeerConnectionFactory.initializeAndroidGlobals(
this, true, true),
"Failed to initializeAndroidGlobals"); "Failed to initializeAndroidGlobals");
factoryStaticInitialized = true; factoryStaticInitialized = true;
} }