Skip to content

Commit

Permalink
Fixes #184: Add webrtc video support to Hello World sample application
Browse files Browse the repository at this point in the history
  • Loading branch information
atsakiridis committed Sep 8, 2015
1 parent 0558ec0 commit 56175e4
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 28 deletions.
1 change: 1 addition & 0 deletions Examples/restcomm-helloworld/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
2 changes: 1 addition & 1 deletion Examples/restcomm-helloworld/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
versionName "1.0.0-BETA2#1"
}
buildTypes {
release {
Expand Down
11 changes: 11 additions & 0 deletions Examples/restcomm-helloworld/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.telestax.restcomm_helloworld" >

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@drawable/icon_144x144"
Expand All @@ -10,6 +19,8 @@
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenOrientation="portrait"
android:launchMode= "singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
//import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.content.Intent;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.view.View.OnClickListener;
import java.util.HashMap;
Expand All @@ -18,21 +21,62 @@
import org.mobicents.restcomm.android.client.sdk.RCDevice;
import org.mobicents.restcomm.android.client.sdk.RCDeviceListener;
import org.mobicents.restcomm.android.client.sdk.RCPresenceEvent;
import org.webrtc.VideoRenderer;
import org.webrtc.VideoRendererGui;
import org.webrtc.VideoTrack;

public class MainActivity extends Activity implements RCDeviceListener, RCConnectionListener, OnClickListener {

private RCDevice device;
private RCConnection connection, pendingConnection;
private HashMap<String, String> params;
private HashMap<String, Object> params;
private static final String TAG = "MainActivity";

private GLSurfaceView videoView;
private VideoRenderer.Callbacks localRender = null;
private VideoRenderer.Callbacks remoteRender = null;
private boolean videoReady = false;
VideoTrack localVideoTrack, remoteVideoTrack;
VideoRenderer localVideoRenderer, remoteVideoRenderer;

// Local preview screen position before call is connected.
private static final int LOCAL_X_CONNECTING = 0;
private static final int LOCAL_Y_CONNECTING = 0;
private static final int LOCAL_WIDTH_CONNECTING = 100;
private static final int LOCAL_HEIGHT_CONNECTING = 100;
// Local preview screen position after call is connected.
private static final int LOCAL_X_CONNECTED = 72;
private static final int LOCAL_Y_CONNECTED = 2;
private static final int LOCAL_WIDTH_CONNECTED = 25;
private static final int LOCAL_HEIGHT_CONNECTED = 25;
// Remote video screen position
private static final int REMOTE_X = 0;
private static final int REMOTE_Y = 0;
private static final int REMOTE_WIDTH = 100;
private static final int REMOTE_HEIGHT = 100;
private VideoRendererGui.ScalingType scalingType;

// UI elements
Button btnDial;
Button btnHangup;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set window styles for fullscreen-window size. Needs to be done before
// adding content.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

setContentView(R.layout.activity_main);

// initialize UI
Expand All @@ -41,36 +85,57 @@ protected void onCreate(Bundle savedInstanceState) {
btnHangup = (Button)findViewById(R.id.button_hangup);
btnHangup.setOnClickListener(this);

RCClient.initialize(getApplicationContext(), new RCClient.RCInitListener()
{
public void onInitialized()
{
RCClient.initialize(getApplicationContext(), new RCClient.RCInitListener() {
public void onInitialized() {
Log.i(TAG, "RCClient initialized");

}

public void onError(Exception exception)
{
public void onError(Exception exception) {
Log.e(TAG, "RCClient initialization error");
}
});

// TODO: we don't support capability tokens yet so let's use an empty string
device = RCClient.createDevice("", this);
params = new HashMap<String, Object>();
// CHANGEME: update the IP address to your Restcomm instance
params.put("pref_proxy_ip", "23.23.228.238");
params.put("pref_proxy_port", "5080");
params.put("pref_sip_user", "bob");
params.put("pref_sip_password", "1234");
device = RCClient.createDevice(params, this);
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
// we don't have a separate activity for the calls, so use the same intent both for calls and messages
device.setPendingIntents(intent, intent);

connection = null;
// Setup video stuff
scalingType = VideoRendererGui.ScalingType.SCALE_ASPECT_FILL;
videoView = (GLSurfaceView) findViewById(R.id.glview_call);
// Create video renderers.
VideoRendererGui.setView(videoView, new Runnable() {
@Override
public void run() {
videoContextReady();
}
});
remoteRender = VideoRendererGui.create(
REMOTE_X, REMOTE_Y,
REMOTE_WIDTH, REMOTE_HEIGHT, scalingType, false);
localRender = VideoRendererGui.create(
LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING,
LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING, scalingType, true);
}

params = new HashMap<String, String>();
// CHANGEME: update the IP address to your Restcomm instance
params.put("pref_proxy_ip", "54.225.212.193");
params.put("pref_proxy_port", "5080");
params.put("pref_sip_user", "bob");
params.put("pref_sip_password", "1234");
// register on startup
device.updateParams(params);
@Override
protected void onDestroy() {
super.onDestroy();
// The activity is about to be destroyed.
Log.i(TAG, "%% onDestroy");
RCClient.shutdown();
device = null;
}

private void videoContextReady()
{
videoReady = true;
}

@Override
Expand Down Expand Up @@ -106,7 +171,8 @@ public void onClick(View view) {
HashMap<String, Object> connectParams = new HashMap<String, Object>();
// CHANGEME: update the IP address to your Restcomm instance. Also, you can update the number
// from '1235' to any Restcomm application you wish to reach
connectParams.put("username", "sip:[email protected]:5080");
connectParams.put("username", "sip:[email protected]:5080");
connectParams.put("video-enabled", true);

// if you want to add custom SIP headers, please uncomment this
//HashMap<String, String> sipHeaders = new HashMap<>();
Expand Down Expand Up @@ -194,6 +260,22 @@ public void onDisconnected(RCConnection connection)
Log.i(TAG, "RCConnection disconnected");
this.connection = null;
pendingConnection = null;

// reside local renderer to take up all screen now that the call is over
VideoRendererGui.update(localRender,
LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING,
LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING, scalingType, true);

if (localVideoTrack != null) {

localVideoTrack.removeRenderer(localVideoRenderer);
localVideoTrack = null;
}

if (remoteVideoTrack != null) {
remoteVideoTrack.removeRenderer(remoteVideoRenderer);
remoteVideoTrack = null;
}
}

public void onDisconnected(RCConnection connection, int errorCode, String errorText) {
Expand All @@ -214,6 +296,34 @@ public void onDeclined(RCConnection connection) {
this.connection = null;
pendingConnection = null;
}
public void onReceiveLocalVideo(RCConnection connection, VideoTrack videoTrack) {
Log.v(TAG, "onReceiveLocalVideo(), VideoTrack: " + videoTrack);
if (videoTrack != null) {
//show media on screen
videoTrack.setEnabled(true);
localVideoRenderer = new VideoRenderer(localRender);
videoTrack.addRenderer(localVideoRenderer);
localVideoTrack = videoTrack;
}
}


public void onReceiveRemoteVideo(RCConnection connection, VideoTrack videoTrack) {
Log.v(TAG, "onReceiveRemoteVideo(), VideoTrack: " + videoTrack);
if (videoTrack != null) {
//show media on screen
videoTrack.setEnabled(true);
remoteVideoRenderer = new VideoRenderer(remoteRender);
videoTrack.addRenderer(remoteVideoRenderer);

VideoRendererGui.update(remoteRender,
REMOTE_X, REMOTE_Y,
REMOTE_WIDTH, REMOTE_HEIGHT, scalingType, false);
VideoRendererGui.update(localRender,
LOCAL_X_CONNECTED, LOCAL_Y_CONNECTED,
LOCAL_WIDTH_CONNECTED, LOCAL_HEIGHT_CONNECTED,
VideoRendererGui.ScalingType.SCALE_ASPECT_FIT, true);

remoteVideoTrack = videoTrack;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
android:layout_height="match_parent"
tools:context=".MainActivity">

<android.opengl.GLSurfaceView
android:id="@+id/glview_call"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dial"
android:id="@+id/button_dial"
android:minWidth="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
Expand All @@ -19,6 +23,7 @@
android:layout_height="wrap_content"
android:text="Hang up"
android:id="@+id/button_hangup"
android:minWidth="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":restcomm.android.client.sdk" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../Examples/restcomm-messenger" external.system.id="GRADLE" external.system.module.group="restcomm-messenger" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":restcomm.android.client.sdk" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../Examples/restcomm-helloworld" external.system.id="GRADLE" external.system.module.group="restcomm-helloworld" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down
2 changes: 1 addition & 1 deletion sipua/sipua.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":sipua" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../Examples/restcomm-messenger" external.system.id="GRADLE" external.system.module.group="restcomm-messenger" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":sipua" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../Examples/restcomm-helloworld" external.system.id="GRADLE" external.system.module.group="restcomm-helloworld" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down

0 comments on commit 56175e4

Please sign in to comment.