-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #184: Add webrtc video support to Hello World sample application
- Loading branch information
1 parent
0558ec0
commit 56175e4
Showing
7 changed files
with
155 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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<>(); | ||
|
@@ -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) { | ||
|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters