33//import android.support.v7.app.ActionBarActivity;
44import android .app .Activity ;
55import android .content .Intent ;
6+ import android .opengl .GLSurfaceView ;
67import android .os .Bundle ;
78import android .view .Menu ;
89import android .view .MenuItem ;
910import android .view .View ;
1011import android .util .Log ;
12+ import android .view .Window ;
13+ import android .view .WindowManager ;
1114import android .widget .Button ;
1215import android .view .View .OnClickListener ;
1316import java .util .HashMap ;
1821import org .mobicents .restcomm .android .client .sdk .RCDevice ;
1922import org .mobicents .restcomm .android .client .sdk .RCDeviceListener ;
2023import org .mobicents .restcomm .android .client .sdk .RCPresenceEvent ;
24+ import org .webrtc .VideoRenderer ;
25+ import org .webrtc .VideoRendererGui ;
26+ import org .webrtc .VideoTrack ;
2127
2228public class MainActivity extends Activity implements RCDeviceListener , RCConnectionListener , OnClickListener {
2329
2430 private RCDevice device ;
2531 private RCConnection connection , pendingConnection ;
26- private HashMap <String , String > params ;
32+ private HashMap <String , Object > params ;
2733 private static final String TAG = "MainActivity" ;
2834
35+ private GLSurfaceView videoView ;
36+ private VideoRenderer .Callbacks localRender = null ;
37+ private VideoRenderer .Callbacks remoteRender = null ;
38+ private boolean videoReady = false ;
39+ VideoTrack localVideoTrack , remoteVideoTrack ;
40+ VideoRenderer localVideoRenderer , remoteVideoRenderer ;
41+
42+ // Local preview screen position before call is connected.
43+ private static final int LOCAL_X_CONNECTING = 0 ;
44+ private static final int LOCAL_Y_CONNECTING = 0 ;
45+ private static final int LOCAL_WIDTH_CONNECTING = 100 ;
46+ private static final int LOCAL_HEIGHT_CONNECTING = 100 ;
47+ // Local preview screen position after call is connected.
48+ private static final int LOCAL_X_CONNECTED = 72 ;
49+ private static final int LOCAL_Y_CONNECTED = 2 ;
50+ private static final int LOCAL_WIDTH_CONNECTED = 25 ;
51+ private static final int LOCAL_HEIGHT_CONNECTED = 25 ;
52+ // Remote video screen position
53+ private static final int REMOTE_X = 0 ;
54+ private static final int REMOTE_Y = 0 ;
55+ private static final int REMOTE_WIDTH = 100 ;
56+ private static final int REMOTE_HEIGHT = 100 ;
57+ private VideoRendererGui .ScalingType scalingType ;
58+
2959 // UI elements
3060 Button btnDial ;
3161 Button btnHangup ;
3262
3363 @ Override
3464 protected void onCreate (Bundle savedInstanceState ) {
3565 super .onCreate (savedInstanceState );
66+ // Set window styles for fullscreen-window size. Needs to be done before
67+ // adding content.
68+ requestWindowFeature (Window .FEATURE_NO_TITLE );
69+ getWindow ().addFlags (
70+ WindowManager .LayoutParams .FLAG_FULLSCREEN
71+ | WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON
72+ | WindowManager .LayoutParams .FLAG_DISMISS_KEYGUARD
73+ | WindowManager .LayoutParams .FLAG_SHOW_WHEN_LOCKED
74+ | WindowManager .LayoutParams .FLAG_TURN_SCREEN_ON );
75+ getWindow ().getDecorView ().setSystemUiVisibility (
76+ View .SYSTEM_UI_FLAG_HIDE_NAVIGATION
77+ | View .SYSTEM_UI_FLAG_FULLSCREEN
78+ | View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY );
79+
3680 setContentView (R .layout .activity_main );
3781
3882 // initialize UI
@@ -41,36 +85,57 @@ protected void onCreate(Bundle savedInstanceState) {
4185 btnHangup = (Button )findViewById (R .id .button_hangup );
4286 btnHangup .setOnClickListener (this );
4387
44- RCClient .initialize (getApplicationContext (), new RCClient .RCInitListener ()
45- {
46- public void onInitialized ()
47- {
88+ RCClient .initialize (getApplicationContext (), new RCClient .RCInitListener () {
89+ public void onInitialized () {
4890 Log .i (TAG , "RCClient initialized" );
49-
5091 }
5192
52- public void onError (Exception exception )
53- {
93+ public void onError (Exception exception ) {
5494 Log .e (TAG , "RCClient initialization error" );
5595 }
5696 });
5797
58- // TODO: we don't support capability tokens yet so let's use an empty string
59- device = RCClient .createDevice ("" , this );
98+ params = new HashMap <String , Object >();
99+ // CHANGEME: update the IP address to your Restcomm instance
100+ params .put ("pref_proxy_ip" , "23.23.228.238" );
101+ params .put ("pref_proxy_port" , "5080" );
102+ params .put ("pref_sip_user" , "bob" );
103+ params .put ("pref_sip_password" , "1234" );
104+ device = RCClient .createDevice (params , this );
60105 Intent intent = new Intent (getApplicationContext (), MainActivity .class );
61106 // we don't have a separate activity for the calls, so use the same intent both for calls and messages
62107 device .setPendingIntents (intent , intent );
63108
64- connection = null ;
109+ // Setup video stuff
110+ scalingType = VideoRendererGui .ScalingType .SCALE_ASPECT_FILL ;
111+ videoView = (GLSurfaceView ) findViewById (R .id .glview_call );
112+ // Create video renderers.
113+ VideoRendererGui .setView (videoView , new Runnable () {
114+ @ Override
115+ public void run () {
116+ videoContextReady ();
117+ }
118+ });
119+ remoteRender = VideoRendererGui .create (
120+ REMOTE_X , REMOTE_Y ,
121+ REMOTE_WIDTH , REMOTE_HEIGHT , scalingType , false );
122+ localRender = VideoRendererGui .create (
123+ LOCAL_X_CONNECTING , LOCAL_Y_CONNECTING ,
124+ LOCAL_WIDTH_CONNECTING , LOCAL_HEIGHT_CONNECTING , scalingType , true );
125+ }
65126
66- params = new HashMap <String , String >();
67- // CHANGEME: update the IP address to your Restcomm instance
68- params .put ("pref_proxy_ip" , "54.225.212.193" );
69- params .put ("pref_proxy_port" , "5080" );
70- params .put ("pref_sip_user" , "bob" );
71- params .put ("pref_sip_password" , "1234" );
72- // register on startup
73- device .updateParams (params );
127+ @ Override
128+ protected void onDestroy () {
129+ super .onDestroy ();
130+ // The activity is about to be destroyed.
131+ Log .i (TAG , "%% onDestroy" );
132+ RCClient .shutdown ();
133+ device = null ;
134+ }
135+
136+ private void videoContextReady ()
137+ {
138+ videoReady = true ;
74139 }
75140
76141 @ Override
@@ -106,7 +171,8 @@ public void onClick(View view) {
106171 HashMap <String , Object > connectParams = new HashMap <String , Object >();
107172 // CHANGEME: update the IP address to your Restcomm instance. Also, you can update the number
108173 // from '1235' to any Restcomm application you wish to reach
109- connectParams .
put (
"username" ,
"sip:[email protected] :5080" );
174+ connectParams .
put (
"username" ,
"sip:[email protected] :5080" );
175+ connectParams .put ("video-enabled" , true );
110176
111177 // if you want to add custom SIP headers, please uncomment this
112178 //HashMap<String, String> sipHeaders = new HashMap<>();
@@ -194,6 +260,22 @@ public void onDisconnected(RCConnection connection)
194260 Log .i (TAG , "RCConnection disconnected" );
195261 this .connection = null ;
196262 pendingConnection = null ;
263+
264+ // reside local renderer to take up all screen now that the call is over
265+ VideoRendererGui .update (localRender ,
266+ LOCAL_X_CONNECTING , LOCAL_Y_CONNECTING ,
267+ LOCAL_WIDTH_CONNECTING , LOCAL_HEIGHT_CONNECTING , scalingType , true );
268+
269+ if (localVideoTrack != null ) {
270+
271+ localVideoTrack .removeRenderer (localVideoRenderer );
272+ localVideoTrack = null ;
273+ }
274+
275+ if (remoteVideoTrack != null ) {
276+ remoteVideoTrack .removeRenderer (remoteVideoRenderer );
277+ remoteVideoTrack = null ;
278+ }
197279 }
198280
199281 public void onDisconnected (RCConnection connection , int errorCode , String errorText ) {
@@ -214,6 +296,34 @@ public void onDeclined(RCConnection connection) {
214296 this .connection = null ;
215297 pendingConnection = null ;
216298 }
299+ public void onReceiveLocalVideo (RCConnection connection , VideoTrack videoTrack ) {
300+ Log .v (TAG , "onReceiveLocalVideo(), VideoTrack: " + videoTrack );
301+ if (videoTrack != null ) {
302+ //show media on screen
303+ videoTrack .setEnabled (true );
304+ localVideoRenderer = new VideoRenderer (localRender );
305+ videoTrack .addRenderer (localVideoRenderer );
306+ localVideoTrack = videoTrack ;
307+ }
308+ }
217309
218-
310+ public void onReceiveRemoteVideo (RCConnection connection , VideoTrack videoTrack ) {
311+ Log .v (TAG , "onReceiveRemoteVideo(), VideoTrack: " + videoTrack );
312+ if (videoTrack != null ) {
313+ //show media on screen
314+ videoTrack .setEnabled (true );
315+ remoteVideoRenderer = new VideoRenderer (remoteRender );
316+ videoTrack .addRenderer (remoteVideoRenderer );
317+
318+ VideoRendererGui .update (remoteRender ,
319+ REMOTE_X , REMOTE_Y ,
320+ REMOTE_WIDTH , REMOTE_HEIGHT , scalingType , false );
321+ VideoRendererGui .update (localRender ,
322+ LOCAL_X_CONNECTED , LOCAL_Y_CONNECTED ,
323+ LOCAL_WIDTH_CONNECTED , LOCAL_HEIGHT_CONNECTED ,
324+ VideoRendererGui .ScalingType .SCALE_ASPECT_FIT , true );
325+
326+ remoteVideoTrack = videoTrack ;
327+ }
328+ }
219329}
0 commit comments