Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java

Issue 1257043004: AppRTCDemo: Render each video in a separate SurfaceView (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Change license header for PercentFrameLayout.java Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 package org.appspot.apprtc; 11 package org.appspot.apprtc;
12 12
13 import org.appspot.apprtc.AppRTCClient.RoomConnectionParameters; 13 import org.appspot.apprtc.AppRTCClient.RoomConnectionParameters;
14 import org.appspot.apprtc.AppRTCClient.SignalingParameters; 14 import org.appspot.apprtc.AppRTCClient.SignalingParameters;
15 import org.appspot.apprtc.PeerConnectionClient.PeerConnectionParameters; 15 import org.appspot.apprtc.PeerConnectionClient.PeerConnectionParameters;
16 import org.appspot.apprtc.util.LooperExecutor; 16 import org.appspot.apprtc.util.LooperExecutor;
17 17
18 import android.app.Activity; 18 import android.app.Activity;
19 import android.app.AlertDialog; 19 import android.app.AlertDialog;
20 import android.app.FragmentTransaction; 20 import android.app.FragmentTransaction;
21 import android.content.DialogInterface; 21 import android.content.DialogInterface;
22 import android.content.Intent; 22 import android.content.Intent;
23 import android.content.pm.PackageManager; 23 import android.content.pm.PackageManager;
24 import android.net.Uri; 24 import android.net.Uri;
25 import android.opengl.GLSurfaceView; 25 import android.opengl.GLSurfaceView;
26 import android.os.Bundle; 26 import android.os.Bundle;
27 import android.os.Handler;
27 import android.util.Log; 28 import android.util.Log;
28 import android.view.View; 29 import android.view.View;
29 import android.view.Window; 30 import android.view.Window;
30 import android.view.WindowManager.LayoutParams; 31 import android.view.WindowManager.LayoutParams;
31 import android.widget.Toast; 32 import android.widget.Toast;
32 33
34 import org.webrtc.EglBase;
33 import org.webrtc.IceCandidate; 35 import org.webrtc.IceCandidate;
34 import org.webrtc.SessionDescription; 36 import org.webrtc.SessionDescription;
35 import org.webrtc.StatsReport; 37 import org.webrtc.StatsReport;
36 import org.webrtc.VideoRenderer; 38 import org.webrtc.SurfaceViewRenderer;
37 import org.webrtc.VideoRendererGui; 39 import org.webrtc.RendererCommon.ScalingType;
38 import org.webrtc.VideoRendererGui.ScalingType;
39 40
40 /** 41 /**
41 * Activity for peer connection call setup, call waiting 42 * Activity for peer connection call setup, call waiting
42 * and call view. 43 * and call view.
43 */ 44 */
44 public class CallActivity extends Activity 45 public class CallActivity extends Activity
45 implements AppRTCClient.SignalingEvents, 46 implements AppRTCClient.SignalingEvents,
46 PeerConnectionClient.PeerConnectionEvents, 47 PeerConnectionClient.PeerConnectionEvents,
47 CallFragment.OnCallEvents { 48 CallFragment.OnCallEvents {
48 49
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // Remote video screen position 103 // Remote video screen position
103 private static final int REMOTE_X = 0; 104 private static final int REMOTE_X = 0;
104 private static final int REMOTE_Y = 0; 105 private static final int REMOTE_Y = 0;
105 private static final int REMOTE_WIDTH = 100; 106 private static final int REMOTE_WIDTH = 100;
106 private static final int REMOTE_HEIGHT = 100; 107 private static final int REMOTE_HEIGHT = 100;
107 108
108 private PeerConnectionClient peerConnectionClient = null; 109 private PeerConnectionClient peerConnectionClient = null;
109 private AppRTCClient appRtcClient; 110 private AppRTCClient appRtcClient;
110 private SignalingParameters signalingParameters; 111 private SignalingParameters signalingParameters;
111 private AppRTCAudioManager audioManager = null; 112 private AppRTCAudioManager audioManager = null;
112 private VideoRenderer.Callbacks localRender; 113 private EglBase rootEglBase;
113 private VideoRenderer.Callbacks remoteRender; 114 private SurfaceViewRenderer localRender;
115 private SurfaceViewRenderer remoteRender;
116 private PercentFrameLayout localRenderLayout;
117 private PercentFrameLayout remoteRenderLayout;
114 private ScalingType scalingType; 118 private ScalingType scalingType;
115 private Toast logToast; 119 private Toast logToast;
116 private boolean commandLineRun; 120 private boolean commandLineRun;
117 private int runTimeMs; 121 private int runTimeMs;
118 private boolean activityRunning; 122 private boolean activityRunning;
119 private RoomConnectionParameters roomConnectionParameters; 123 private RoomConnectionParameters roomConnectionParameters;
120 private PeerConnectionParameters peerConnectionParameters; 124 private PeerConnectionParameters peerConnectionParameters;
121 private boolean iceConnected; 125 private boolean iceConnected;
122 private boolean isError; 126 private boolean isError;
123 private boolean callControlFragmentVisible = true; 127 private boolean callControlFragmentVisible = true;
124 private long callStartedTimeMs = 0; 128 private long callStartedTimeMs = 0;
125 129
126 // Controls 130 // Controls
127 private GLSurfaceView videoView;
128 CallFragment callFragment; 131 CallFragment callFragment;
129 HudFragment hudFragment; 132 HudFragment hudFragment;
130 133
131 @Override 134 @Override
132 public void onCreate(Bundle savedInstanceState) { 135 public void onCreate(Bundle savedInstanceState) {
133 super.onCreate(savedInstanceState); 136 super.onCreate(savedInstanceState);
134 Thread.setDefaultUncaughtExceptionHandler( 137 Thread.setDefaultUncaughtExceptionHandler(
135 new UnhandledExceptionHandler(this)); 138 new UnhandledExceptionHandler(this));
136 139
137 // Set window styles for fullscreen-window size. Needs to be done before 140 // Set window styles for fullscreen-window size. Needs to be done before
138 // adding content. 141 // adding content.
139 requestWindowFeature(Window.FEATURE_NO_TITLE); 142 requestWindowFeature(Window.FEATURE_NO_TITLE);
140 getWindow().addFlags( 143 getWindow().addFlags(
141 LayoutParams.FLAG_FULLSCREEN 144 LayoutParams.FLAG_FULLSCREEN
142 | LayoutParams.FLAG_KEEP_SCREEN_ON 145 | LayoutParams.FLAG_KEEP_SCREEN_ON
143 | LayoutParams.FLAG_DISMISS_KEYGUARD 146 | LayoutParams.FLAG_DISMISS_KEYGUARD
144 | LayoutParams.FLAG_SHOW_WHEN_LOCKED 147 | LayoutParams.FLAG_SHOW_WHEN_LOCKED
145 | LayoutParams.FLAG_TURN_SCREEN_ON); 148 | LayoutParams.FLAG_TURN_SCREEN_ON);
146 getWindow().getDecorView().setSystemUiVisibility( 149 getWindow().getDecorView().setSystemUiVisibility(
147 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 150 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
148 | View.SYSTEM_UI_FLAG_FULLSCREEN 151 | View.SYSTEM_UI_FLAG_FULLSCREEN
149 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); 152 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
150 setContentView(R.layout.activity_call); 153 setContentView(R.layout.activity_call);
151 154
152 iceConnected = false; 155 iceConnected = false;
153 signalingParameters = null; 156 signalingParameters = null;
154 scalingType = ScalingType.SCALE_ASPECT_FILL; 157 scalingType = ScalingType.SCALE_ASPECT_FILL;
155 158
156 // Create UI controls. 159 // Create UI controls.
157 videoView = (GLSurfaceView) findViewById(R.id.glview_call); 160 localRender = (SurfaceViewRenderer) findViewById(R.id.local_video_view);
161 remoteRender = (SurfaceViewRenderer) findViewById(R.id.remote_video_view);
162 localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layou t);
163 remoteRenderLayout = (PercentFrameLayout) findViewById(R.id.remote_video_lay out);
158 callFragment = new CallFragment(); 164 callFragment = new CallFragment();
159 hudFragment = new HudFragment(); 165 hudFragment = new HudFragment();
160 166
161 // Create video renderers.
162 VideoRendererGui.setView(videoView, new Runnable() {
163 @Override
164 public void run() {
165 createPeerConnectionFactory();
166 }
167 });
168 remoteRender = VideoRendererGui.create(
169 REMOTE_X, REMOTE_Y,
170 REMOTE_WIDTH, REMOTE_HEIGHT, scalingType, false);
171 localRender = VideoRendererGui.create(
172 LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING,
173 LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING, scalingType, true);
174
175 // Show/hide call control fragment on view click. 167 // Show/hide call control fragment on view click.
176 videoView.setOnClickListener(new View.OnClickListener() { 168 View.OnClickListener listener = new View.OnClickListener() {
177 @Override 169 @Override
178 public void onClick(View view) { 170 public void onClick(View view) {
179 toggleCallControlFragmentVisibility(); 171 toggleCallControlFragmentVisibility();
180 } 172 }
181 }); 173 };
174 localRender.setOnClickListener(listener);
175 remoteRender.setOnClickListener(listener);
176
177 // Create video renderers.
178 rootEglBase = new EglBase();
179 localRender.init(rootEglBase.getContext());
180 remoteRender.init(rootEglBase.getContext());
181 localRender.setZOrderMediaOverlay(true);
182 updateVideoView();
182 183
183 // Check for mandatory permissions. 184 // Check for mandatory permissions.
184 for (String permission : MANDATORY_PERMISSIONS) { 185 for (String permission : MANDATORY_PERMISSIONS) {
185 if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_ GRANTED) { 186 if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_ GRANTED) {
186 logAndToast("Permission " + permission + " is not granted"); 187 logAndToast("Permission " + permission + " is not granted");
187 setResult(RESULT_CANCELED); 188 setResult(RESULT_CANCELED);
188 finish(); 189 finish();
189 return; 190 return;
190 } 191 }
191 } 192 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 hudFragment.setArguments(intent.getExtras()); 236 hudFragment.setArguments(intent.getExtras());
236 // Activate call and HUD fragments and start the call. 237 // Activate call and HUD fragments and start the call.
237 FragmentTransaction ft = getFragmentManager().beginTransaction(); 238 FragmentTransaction ft = getFragmentManager().beginTransaction();
238 ft.add(R.id.call_fragment_container, callFragment); 239 ft.add(R.id.call_fragment_container, callFragment);
239 ft.add(R.id.hud_fragment_container, hudFragment); 240 ft.add(R.id.hud_fragment_container, hudFragment);
240 ft.commit(); 241 ft.commit();
241 startCall(); 242 startCall();
242 243
243 // For command line execution run connection for <runTimeMs> and exit. 244 // For command line execution run connection for <runTimeMs> and exit.
244 if (commandLineRun && runTimeMs > 0) { 245 if (commandLineRun && runTimeMs > 0) {
245 videoView.postDelayed(new Runnable() { 246 (new Handler()).postDelayed(new Runnable() {
246 public void run() { 247 public void run() {
247 disconnect(); 248 disconnect();
248 } 249 }
249 }, runTimeMs); 250 }, runTimeMs);
250 } 251 }
252 createPeerConnectionFactory();
251 } 253 }
252 254
253 // Activity interfaces 255 // Activity interfaces
254 @Override 256 @Override
255 public void onPause() { 257 public void onPause() {
256 super.onPause(); 258 super.onPause();
257 videoView.onPause();
258 activityRunning = false; 259 activityRunning = false;
259 if (peerConnectionClient != null) { 260 if (peerConnectionClient != null) {
260 peerConnectionClient.stopVideoSource(); 261 peerConnectionClient.stopVideoSource();
261 } 262 }
262 } 263 }
263 264
264 @Override 265 @Override
265 public void onResume() { 266 public void onResume() {
266 super.onResume(); 267 super.onResume();
267 videoView.onResume();
268 activityRunning = true; 268 activityRunning = true;
269 if (peerConnectionClient != null) { 269 if (peerConnectionClient != null) {
270 peerConnectionClient.startVideoSource(); 270 peerConnectionClient.startVideoSource();
271 } 271 }
272 } 272 }
273 273
274 @Override 274 @Override
275 protected void onDestroy() { 275 protected void onDestroy() {
276 disconnect(); 276 disconnect();
277 super.onDestroy(); 277 super.onDestroy();
278 if (logToast != null) { 278 if (logToast != null) {
279 logToast.cancel(); 279 logToast.cancel();
280 } 280 }
281 activityRunning = false; 281 activityRunning = false;
282 localRender.release();
283 localRender = null;
284 remoteRender.release();
285 remoteRender = null;
286 rootEglBase.release();
287 rootEglBase = null;
282 } 288 }
283 289
284 // CallFragment.OnCallEvents interface implementation. 290 // CallFragment.OnCallEvents interface implementation.
285 @Override 291 @Override
286 public void onCallHangUp() { 292 public void onCallHangUp() {
287 disconnect(); 293 disconnect();
288 } 294 }
289 295
290 @Override 296 @Override
291 public void onCameraSwitch() { 297 public void onCameraSwitch() {
(...skipping 21 matching lines...) Expand all
313 ft.show(hudFragment); 319 ft.show(hudFragment);
314 } else { 320 } else {
315 ft.hide(callFragment); 321 ft.hide(callFragment);
316 ft.hide(hudFragment); 322 ft.hide(hudFragment);
317 } 323 }
318 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 324 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
319 ft.commit(); 325 ft.commit();
320 } 326 }
321 327
322 private void updateVideoView() { 328 private void updateVideoView() {
323 VideoRendererGui.update(remoteRender, 329 remoteRenderLayout.setPosition(REMOTE_X, REMOTE_Y, REMOTE_WIDTH, REMOTE_HEIG HT);
324 REMOTE_X, REMOTE_Y, 330 remoteRender.setScalingType(scalingType);
325 REMOTE_WIDTH, REMOTE_HEIGHT, scalingType, false); 331 remoteRender.setMirror(false);
332
326 if (iceConnected) { 333 if (iceConnected) {
327 VideoRendererGui.update(localRender, 334 localRenderLayout.setPosition(
328 LOCAL_X_CONNECTED, LOCAL_Y_CONNECTED, 335 LOCAL_X_CONNECTED, LOCAL_Y_CONNECTED, LOCAL_WIDTH_CONNECTED, LOCAL_HEI GHT_CONNECTED);
329 LOCAL_WIDTH_CONNECTED, LOCAL_HEIGHT_CONNECTED, 336 localRender.setScalingType(ScalingType.SCALE_ASPECT_FIT);
330 ScalingType.SCALE_ASPECT_FIT, true);
331 } else { 337 } else {
332 VideoRendererGui.update(localRender, 338 localRenderLayout.setPosition(
333 LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING, 339 LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING, LOCAL_WIDTH_CONNECTING, LOCAL_ HEIGHT_CONNECTING);
334 LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING, scalingType, true); 340 localRender.setScalingType(scalingType);
335 } 341 }
342 localRender.setMirror(true);
343
344 localRender.requestLayout();
345 remoteRender.requestLayout();
336 } 346 }
337 347
338 private void startCall() { 348 private void startCall() {
339 if (appRtcClient == null) { 349 if (appRtcClient == null) {
340 Log.e(TAG, "AppRTC client is not allocated for a call."); 350 Log.e(TAG, "AppRTC client is not allocated for a call.");
341 return; 351 return;
342 } 352 }
343 callStartedTimeMs = System.currentTimeMillis(); 353 callStartedTimeMs = System.currentTimeMillis();
344 354
345 // Start room connection. 355 // Start room connection.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // Create peer connection factory when EGL context is ready. 393 // Create peer connection factory when EGL context is ready.
384 private void createPeerConnectionFactory() { 394 private void createPeerConnectionFactory() {
385 runOnUiThread(new Runnable() { 395 runOnUiThread(new Runnable() {
386 @Override 396 @Override
387 public void run() { 397 public void run() {
388 if (peerConnectionClient == null) { 398 if (peerConnectionClient == null) {
389 final long delta = System.currentTimeMillis() - callStartedTimeMs; 399 final long delta = System.currentTimeMillis() - callStartedTimeMs;
390 Log.d(TAG, "Creating peer connection factory, delay=" + delta + "ms"); 400 Log.d(TAG, "Creating peer connection factory, delay=" + delta + "ms");
391 peerConnectionClient = PeerConnectionClient.getInstance(); 401 peerConnectionClient = PeerConnectionClient.getInstance();
392 peerConnectionClient.createPeerConnectionFactory(CallActivity.this, 402 peerConnectionClient.createPeerConnectionFactory(CallActivity.this,
393 VideoRendererGui.getEGLContext(), peerConnectionParameters, 403 rootEglBase.getContext(), peerConnectionParameters,
394 CallActivity.this); 404 CallActivity.this);
395 } 405 }
396 if (signalingParameters != null) { 406 if (signalingParameters != null) {
397 Log.w(TAG, "EGL context is ready after room connection."); 407 Log.w(TAG, "EGL context is ready after room connection.");
398 onConnectedToRoomInternal(signalingParameters); 408 onConnectedToRoomInternal(signalingParameters);
399 } 409 }
400 } 410 }
401 }); 411 });
402 } 412 }
403 413
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 } 648 }
639 } 649 }
640 }); 650 });
641 } 651 }
642 652
643 @Override 653 @Override
644 public void onPeerConnectionError(final String description) { 654 public void onPeerConnectionError(final String description) {
645 reportError(description); 655 reportError(description);
646 } 656 }
647 } 657 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698