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

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

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

Powered by Google App Engine
This is Rietveld 408576698