Add an example app for Android native API.

The app is a simple loopback demo demonstrating the usage of Android
native API. This is an initial version and I will add support for
HW codecs etc. in the future.

Bug: webrtc:8769
Change-Id: Ifb6209769dabeb8ca3185b969a1ef8afd6d84390
Reviewed-on: https://webrtc-review.googlesource.com/60540
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22385}
This commit is contained in:
Sami Kalliomäki
2018-03-08 16:43:16 +01:00
committed by Commit Bot
parent 0dd7435abc
commit 3e77afd0d2
15 changed files with 710 additions and 18 deletions

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2018 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.
*/
package org.webrtc.examples.androidnativeapi;
import android.os.Handler;
import android.os.HandlerThread;
import org.webrtc.NativeClassQualifiedName;
import org.webrtc.VideoSink;
public class CallClient {
private static final String TAG = "CallClient";
private final HandlerThread thread;
private final Handler handler;
private long nativeClient;
public CallClient() {
thread = new HandlerThread(TAG + "Thread");
thread.start();
handler = new Handler(thread.getLooper());
handler.post(() -> { nativeClient = nativeCreateClient(); });
}
public void call(VideoSink localSink, VideoSink remoteSink) {
handler.post(() -> { nativeCall(nativeClient, localSink, remoteSink); });
}
public void hangup() {
handler.post(() -> { nativeHangup(nativeClient); });
}
public void close() {
handler.post(() -> {
nativeDelete(nativeClient);
nativeClient = 0;
});
thread.quitSafely();
}
private static native long nativeCreateClient();
@NativeClassQualifiedName("webrtc_examples::AndroidCallClient")
private static native void nativeCall(long nativePtr, VideoSink localSink, VideoSink remoteSink);
@NativeClassQualifiedName("webrtc_examples::AndroidCallClient")
private static native void nativeHangup(long nativePtr);
@NativeClassQualifiedName("webrtc_examples::AndroidCallClient")
private static native void nativeDelete(long nativePtr);
}

View File

@ -0,0 +1,80 @@
/*
* Copyright (c) 2018 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.
*/
package org.webrtc.examples.androidnativeapi;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import org.webrtc.ContextUtils;
import org.webrtc.EglBase;
import org.webrtc.GlRectDrawer;
import org.webrtc.SurfaceViewRenderer;
public class MainActivity extends Activity {
private CallClient callClient;
private EglBase eglBase;
private SurfaceViewRenderer localRenderer;
private SurfaceViewRenderer remoteRenderer;
@Override
protected void onCreate(Bundle savedInstance) {
ContextUtils.initialize(getApplicationContext());
super.onCreate(savedInstance);
setContentView(R.layout.activity_main);
System.loadLibrary("examples_androidnativeapi_jni");
callClient = new CallClient();
Button callButton = (Button) findViewById(R.id.call_button);
callButton.setOnClickListener((view) -> { callClient.call(localRenderer, remoteRenderer); });
Button hangupButton = (Button) findViewById(R.id.hangup_button);
hangupButton.setOnClickListener((view) -> { callClient.hangup(); });
}
@Override
protected void onStart() {
super.onStart();
eglBase = EglBase.create(null /* sharedContext */, EglBase.CONFIG_PLAIN);
localRenderer = (SurfaceViewRenderer) findViewById(R.id.local_renderer);
remoteRenderer = (SurfaceViewRenderer) findViewById(R.id.remote_renderer);
localRenderer.init(eglBase.getEglBaseContext(), null /* rendererEvents */, EglBase.CONFIG_PLAIN,
new GlRectDrawer());
remoteRenderer.init(eglBase.getEglBaseContext(), null /* rendererEvents */,
EglBase.CONFIG_PLAIN, new GlRectDrawer());
}
@Override
protected void onStop() {
callClient.hangup();
localRenderer.release();
remoteRenderer.release();
eglBase.release();
localRenderer = null;
remoteRenderer = null;
eglBase = null;
super.onStop();
}
@Override
protected void onDestroy() {
callClient.close();
callClient = null;
super.onDestroy();
}
}