Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 import android.content.pm.PackageManager; | 22 import android.content.pm.PackageManager; |
| 23 import android.net.Uri; | 23 import android.net.Uri; |
| 24 import android.os.Bundle; | 24 import android.os.Bundle; |
| 25 import android.os.Handler; | 25 import android.os.Handler; |
| 26 import android.util.Log; | 26 import android.util.Log; |
| 27 import android.view.View; | 27 import android.view.View; |
| 28 import android.view.Window; | 28 import android.view.Window; |
| 29 import android.view.WindowManager.LayoutParams; | 29 import android.view.WindowManager.LayoutParams; |
| 30 import android.widget.Toast; | 30 import android.widget.Toast; |
| 31 | 31 |
| 32 import java.io.IOException; | |
| 33 import java.lang.RuntimeException; | |
| 34 import java.util.ArrayList; | |
| 35 import java.util.List; | |
| 36 | |
| 37 import org.webrtc.Camera1Enumerator; | |
| 32 import org.webrtc.Camera2Enumerator; | 38 import org.webrtc.Camera2Enumerator; |
| 39 import org.webrtc.CameraEnumerator; | |
| 33 import org.webrtc.EglBase; | 40 import org.webrtc.EglBase; |
| 41 import org.webrtc.FileVideoCapturer; | |
| 42 import org.webrtc.VideoFileRenderer; | |
| 34 import org.webrtc.IceCandidate; | 43 import org.webrtc.IceCandidate; |
| 44 import org.webrtc.Logging; | |
| 35 import org.webrtc.PeerConnectionFactory; | 45 import org.webrtc.PeerConnectionFactory; |
| 36 import org.webrtc.RendererCommon.ScalingType; | 46 import org.webrtc.RendererCommon.ScalingType; |
| 37 import org.webrtc.SessionDescription; | 47 import org.webrtc.SessionDescription; |
| 38 import org.webrtc.StatsReport; | 48 import org.webrtc.StatsReport; |
| 39 import org.webrtc.SurfaceViewRenderer; | 49 import org.webrtc.SurfaceViewRenderer; |
| 50 import org.webrtc.VideoCapturer; | |
| 51 import org.webrtc.VideoRenderer; | |
| 40 | 52 |
| 41 /** | 53 /** |
| 42 * Activity for peer connection call setup, call waiting | 54 * Activity for peer connection call setup, call waiting |
| 43 * and call view. | 55 * and call view. |
| 44 */ | 56 */ |
| 45 public class CallActivity extends Activity | 57 public class CallActivity extends Activity |
| 46 implements AppRTCClient.SignalingEvents, | 58 implements AppRTCClient.SignalingEvents, |
| 47 PeerConnectionClient.PeerConnectionEvents, | 59 PeerConnectionClient.PeerConnectionEvents, |
| 48 CallFragment.OnCallEvents { | 60 CallFragment.OnCallEvents { |
| 49 | 61 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 "org.appspot.apprtc.DISABLE_BUILT_IN_NS"; | 101 "org.appspot.apprtc.DISABLE_BUILT_IN_NS"; |
| 90 public static final String EXTRA_ENABLE_LEVEL_CONTROL = | 102 public static final String EXTRA_ENABLE_LEVEL_CONTROL = |
| 91 "org.appspot.apprtc.ENABLE_LEVEL_CONTROL"; | 103 "org.appspot.apprtc.ENABLE_LEVEL_CONTROL"; |
| 92 public static final String EXTRA_DISPLAY_HUD = | 104 public static final String EXTRA_DISPLAY_HUD = |
| 93 "org.appspot.apprtc.DISPLAY_HUD"; | 105 "org.appspot.apprtc.DISPLAY_HUD"; |
| 94 public static final String EXTRA_TRACING = "org.appspot.apprtc.TRACING"; | 106 public static final String EXTRA_TRACING = "org.appspot.apprtc.TRACING"; |
| 95 public static final String EXTRA_CMDLINE = | 107 public static final String EXTRA_CMDLINE = |
| 96 "org.appspot.apprtc.CMDLINE"; | 108 "org.appspot.apprtc.CMDLINE"; |
| 97 public static final String EXTRA_RUNTIME = | 109 public static final String EXTRA_RUNTIME = |
| 98 "org.appspot.apprtc.RUNTIME"; | 110 "org.appspot.apprtc.RUNTIME"; |
| 111 public static final String EXTRA_VIDEO_FILE_AS_CAMERA = | |
| 112 "org.appspot.apprtc.VIDEO_FILE_AS_CAMERA"; | |
|
sakal
2016/10/05 13:28:41
Please correct the indentation on this and followi
mandermo
2016/10/07 11:33:41
Done.
| |
| 113 public static final String EXTRA_SAVE_REMOTE_VIDEO_TO_FILE = | |
| 114 "org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE"; | |
| 115 public static final String EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_WIDTH = | |
| 116 "org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE_WIDTH"; | |
| 117 public static final String EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_HEIGHT = | |
| 118 "org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE_HEIGHT"; | |
| 119 public static final String EXTRA_USE_VALUES_FROM_INTENT = | |
| 120 "org.appspot.apprtc.USE_VALUES_FROM_INTENT"; | |
| 99 private static final String TAG = "CallRTCClient"; | 121 private static final String TAG = "CallRTCClient"; |
| 100 | 122 |
| 101 // List of mandatory application permissions. | 123 // List of mandatory application permissions. |
| 102 private static final String[] MANDATORY_PERMISSIONS = { | 124 private static final String[] MANDATORY_PERMISSIONS = { |
| 103 "android.permission.MODIFY_AUDIO_SETTINGS", | 125 "android.permission.MODIFY_AUDIO_SETTINGS", |
| 104 "android.permission.RECORD_AUDIO", | 126 "android.permission.RECORD_AUDIO", |
| 105 "android.permission.INTERNET" | 127 "android.permission.INTERNET" |
| 106 }; | 128 }; |
| 107 | 129 |
| 108 // Peer connection statistics callback period in ms. | 130 // Peer connection statistics callback period in ms. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 121 private static final int REMOTE_X = 0; | 143 private static final int REMOTE_X = 0; |
| 122 private static final int REMOTE_Y = 0; | 144 private static final int REMOTE_Y = 0; |
| 123 private static final int REMOTE_WIDTH = 100; | 145 private static final int REMOTE_WIDTH = 100; |
| 124 private static final int REMOTE_HEIGHT = 100; | 146 private static final int REMOTE_HEIGHT = 100; |
| 125 private PeerConnectionClient peerConnectionClient = null; | 147 private PeerConnectionClient peerConnectionClient = null; |
| 126 private AppRTCClient appRtcClient; | 148 private AppRTCClient appRtcClient; |
| 127 private SignalingParameters signalingParameters; | 149 private SignalingParameters signalingParameters; |
| 128 private AppRTCAudioManager audioManager = null; | 150 private AppRTCAudioManager audioManager = null; |
| 129 private EglBase rootEglBase; | 151 private EglBase rootEglBase; |
| 130 private SurfaceViewRenderer localRender; | 152 private SurfaceViewRenderer localRender; |
| 131 private SurfaceViewRenderer remoteRender; | 153 private SurfaceViewRenderer remoteRenderScreen; |
| 154 private VideoFileRenderer videoFileRenderer; | |
| 155 private List<VideoRenderer.Callbacks> remoteRenders = new ArrayList<VideoRende rer.Callbacks>(); | |
|
sakal
2016/10/05 13:28:41
final
mandermo
2016/10/07 11:33:40
Made remoteRenders final and changed name to remot
| |
| 132 private PercentFrameLayout localRenderLayout; | 156 private PercentFrameLayout localRenderLayout; |
| 133 private PercentFrameLayout remoteRenderLayout; | 157 private PercentFrameLayout remoteRenderLayout; |
| 134 private ScalingType scalingType; | 158 private ScalingType scalingType; |
| 135 private Toast logToast; | 159 private Toast logToast; |
| 136 private boolean commandLineRun; | 160 private boolean commandLineRun; |
| 137 private int runTimeMs; | 161 private int runTimeMs; |
| 138 private boolean activityRunning; | 162 private boolean activityRunning; |
| 139 private RoomConnectionParameters roomConnectionParameters; | 163 private RoomConnectionParameters roomConnectionParameters; |
| 140 private PeerConnectionParameters peerConnectionParameters; | 164 private PeerConnectionParameters peerConnectionParameters; |
| 141 private boolean iceConnected; | 165 private boolean iceConnected; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 169 | View.SYSTEM_UI_FLAG_FULLSCREEN | 193 | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 170 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); | 194 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); |
| 171 setContentView(R.layout.activity_call); | 195 setContentView(R.layout.activity_call); |
| 172 | 196 |
| 173 iceConnected = false; | 197 iceConnected = false; |
| 174 signalingParameters = null; | 198 signalingParameters = null; |
| 175 scalingType = ScalingType.SCALE_ASPECT_FILL; | 199 scalingType = ScalingType.SCALE_ASPECT_FILL; |
| 176 | 200 |
| 177 // Create UI controls. | 201 // Create UI controls. |
| 178 localRender = (SurfaceViewRenderer) findViewById(R.id.local_video_view); | 202 localRender = (SurfaceViewRenderer) findViewById(R.id.local_video_view); |
| 179 remoteRender = (SurfaceViewRenderer) findViewById(R.id.remote_video_view); | 203 remoteRenderScreen = (SurfaceViewRenderer) findViewById(R.id.remote_video_vi ew); |
| 180 localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layou t); | 204 localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layou t); |
| 181 remoteRenderLayout = (PercentFrameLayout) findViewById(R.id.remote_video_lay out); | 205 remoteRenderLayout = (PercentFrameLayout) findViewById(R.id.remote_video_lay out); |
| 182 callFragment = new CallFragment(); | 206 callFragment = new CallFragment(); |
| 183 hudFragment = new HudFragment(); | 207 hudFragment = new HudFragment(); |
| 184 | 208 |
| 185 // Show/hide call control fragment on view click. | 209 // Show/hide call control fragment on view click. |
| 186 View.OnClickListener listener = new View.OnClickListener() { | 210 View.OnClickListener listener = new View.OnClickListener() { |
| 187 @Override | 211 @Override |
| 188 public void onClick(View view) { | 212 public void onClick(View view) { |
| 189 toggleCallControlFragmentVisibility(); | 213 toggleCallControlFragmentVisibility(); |
| 190 } | 214 } |
| 191 }; | 215 }; |
| 192 | 216 |
| 193 localRender.setOnClickListener(listener); | 217 localRender.setOnClickListener(listener); |
| 194 remoteRender.setOnClickListener(listener); | 218 remoteRenderScreen.setOnClickListener(listener); |
| 219 remoteRenders.add(remoteRenderScreen); | |
| 220 | |
| 221 final Intent intent = getIntent(); | |
| 195 | 222 |
| 196 // Create video renderers. | 223 // Create video renderers. |
| 197 rootEglBase = EglBase.create(); | 224 rootEglBase = EglBase.create(); |
| 198 localRender.init(rootEglBase.getEglBaseContext(), null); | 225 localRender.init(rootEglBase.getEglBaseContext(), null); |
| 199 remoteRender.init(rootEglBase.getEglBaseContext(), null); | 226 String saveRemoteVideoToFile = intent.getStringExtra(EXTRA_SAVE_REMOTE_VIDEO _TO_FILE); |
| 227 | |
| 228 // When saveRemoveToFile is set we save the video from the remote to a file. | |
|
sakal
2016/10/05 13:28:41
saveRemoveToFile -> saveRemoteVideoToFile
mandermo
2016/10/07 11:33:41
Done.
| |
| 229 if (saveRemoteVideoToFile != null) { | |
| 230 int videoOutWidth = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_WID TH, 0); | |
| 231 int videoOutHeight = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_HE IGHT, 0); | |
| 232 try { | |
| 233 videoFileRenderer = new VideoFileRenderer( | |
| 234 saveRemoteVideoToFile, videoOutWidth, videoOutHeight, | |
| 235 rootEglBase.getEglBaseContext()); | |
| 236 remoteRenders.add(videoFileRenderer); | |
| 237 } catch (IOException e) { | |
| 238 throw new RuntimeException("Failed to open video file for output: " + sa veRemoteVideoToFile, e); | |
| 239 } | |
| 240 } | |
| 241 remoteRenderScreen.init(rootEglBase.getEglBaseContext(), null); | |
| 242 | |
| 200 localRender.setZOrderMediaOverlay(true); | 243 localRender.setZOrderMediaOverlay(true); |
| 201 updateVideoView(); | 244 updateVideoView(); |
| 202 | 245 |
| 203 // Check for mandatory permissions. | 246 // Check for mandatory permissions. |
| 204 for (String permission : MANDATORY_PERMISSIONS) { | 247 for (String permission : MANDATORY_PERMISSIONS) { |
| 205 if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_ GRANTED) { | 248 if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_ GRANTED) { |
| 206 logAndToast("Permission " + permission + " is not granted"); | 249 logAndToast("Permission " + permission + " is not granted"); |
| 207 setResult(RESULT_CANCELED); | 250 setResult(RESULT_CANCELED); |
| 208 finish(); | 251 finish(); |
| 209 return; | 252 return; |
| 210 } | 253 } |
| 211 } | 254 } |
| 212 | 255 |
| 213 // Get Intent parameters. | 256 // Get Intent parameters. |
|
sakal
2016/10/05 13:28:41
nit: move comment
mandermo
2016/10/07 11:33:41
Moved to before String roomId = intent.getStringEx
| |
| 214 final Intent intent = getIntent(); | |
| 215 Uri roomUri = intent.getData(); | 257 Uri roomUri = intent.getData(); |
| 216 if (roomUri == null) { | 258 if (roomUri == null) { |
| 217 logAndToast(getString(R.string.missing_url)); | 259 logAndToast(getString(R.string.missing_url)); |
| 218 Log.e(TAG, "Didn't get any URL in intent!"); | 260 Log.e(TAG, "Didn't get any URL in intent!"); |
| 219 setResult(RESULT_CANCELED); | 261 setResult(RESULT_CANCELED); |
| 220 finish(); | 262 finish(); |
| 221 return; | 263 return; |
| 222 } | 264 } |
| 223 String roomId = intent.getStringExtra(EXTRA_ROOMID); | 265 String roomId = intent.getStringExtra(EXTRA_ROOMID); |
| 266 Log.d(TAG, "Room ID: " + roomId); | |
| 224 if (roomId == null || roomId.length() == 0) { | 267 if (roomId == null || roomId.length() == 0) { |
| 225 logAndToast(getString(R.string.missing_url)); | 268 logAndToast(getString(R.string.missing_url)); |
| 226 Log.e(TAG, "Incorrect room ID in intent!"); | 269 Log.e(TAG, "Incorrect room ID in intent!"); |
| 227 setResult(RESULT_CANCELED); | 270 setResult(RESULT_CANCELED); |
| 228 finish(); | 271 finish(); |
| 229 return; | 272 return; |
| 230 } | 273 } |
| 231 | 274 |
| 232 boolean loopback = intent.getBooleanExtra(EXTRA_LOOPBACK, false); | 275 boolean loopback = intent.getBooleanExtra(EXTRA_LOOPBACK, false); |
| 233 boolean tracing = intent.getBooleanExtra(EXTRA_TRACING, false); | 276 boolean tracing = intent.getBooleanExtra(EXTRA_TRACING, false); |
| 234 | 277 |
| 235 boolean useCamera2 = Camera2Enumerator.isSupported() | |
| 236 && intent.getBooleanExtra(EXTRA_CAMERA2, true); | |
| 237 | |
| 238 peerConnectionParameters = new PeerConnectionParameters( | 278 peerConnectionParameters = new PeerConnectionParameters( |
| 239 intent.getBooleanExtra(EXTRA_VIDEO_CALL, true), | 279 intent.getBooleanExtra(EXTRA_VIDEO_CALL, true), |
| 240 loopback, | 280 loopback, |
| 241 tracing, | 281 tracing, |
| 242 useCamera2, | |
| 243 intent.getIntExtra(EXTRA_VIDEO_WIDTH, 0), | 282 intent.getIntExtra(EXTRA_VIDEO_WIDTH, 0), |
| 244 intent.getIntExtra(EXTRA_VIDEO_HEIGHT, 0), | 283 intent.getIntExtra(EXTRA_VIDEO_HEIGHT, 0), |
| 245 intent.getIntExtra(EXTRA_VIDEO_FPS, 0), | 284 intent.getIntExtra(EXTRA_VIDEO_FPS, 0), |
| 246 intent.getIntExtra(EXTRA_VIDEO_BITRATE, 0), | 285 intent.getIntExtra(EXTRA_VIDEO_BITRATE, 0), |
| 247 intent.getStringExtra(EXTRA_VIDEOCODEC), | 286 intent.getStringExtra(EXTRA_VIDEOCODEC), |
| 248 intent.getBooleanExtra(EXTRA_HWCODEC_ENABLED, true), | 287 intent.getBooleanExtra(EXTRA_HWCODEC_ENABLED, true), |
| 249 intent.getBooleanExtra(EXTRA_CAPTURETOTEXTURE_ENABLED, false), | |
| 250 intent.getIntExtra(EXTRA_AUDIO_BITRATE, 0), | 288 intent.getIntExtra(EXTRA_AUDIO_BITRATE, 0), |
| 251 intent.getStringExtra(EXTRA_AUDIOCODEC), | 289 intent.getStringExtra(EXTRA_AUDIOCODEC), |
| 252 intent.getBooleanExtra(EXTRA_NOAUDIOPROCESSING_ENABLED, false), | 290 intent.getBooleanExtra(EXTRA_NOAUDIOPROCESSING_ENABLED, false), |
| 253 intent.getBooleanExtra(EXTRA_AECDUMP_ENABLED, false), | 291 intent.getBooleanExtra(EXTRA_AECDUMP_ENABLED, false), |
| 254 intent.getBooleanExtra(EXTRA_OPENSLES_ENABLED, false), | 292 intent.getBooleanExtra(EXTRA_OPENSLES_ENABLED, false), |
| 255 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_AEC, false), | 293 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_AEC, false), |
| 256 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_AGC, false), | 294 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_AGC, false), |
| 257 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_NS, false), | 295 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_NS, false), |
| 258 intent.getBooleanExtra(EXTRA_ENABLE_LEVEL_CONTROL, false)); | 296 intent.getBooleanExtra(EXTRA_ENABLE_LEVEL_CONTROL, false)); |
| 259 commandLineRun = intent.getBooleanExtra(EXTRA_CMDLINE, false); | |
| 260 runTimeMs = intent.getIntExtra(EXTRA_RUNTIME, 0); | 297 runTimeMs = intent.getIntExtra(EXTRA_RUNTIME, 0); |
| 261 | 298 |
| 299 Log.d(TAG, "VIDEO_FILE: '" + intent.getStringExtra(EXTRA_VIDEO_FILE_AS_CAMER A) + "'"); | |
| 300 | |
| 262 // Create connection client. Use DirectRTCClient if room name is an IP other wise use the | 301 // Create connection client. Use DirectRTCClient if room name is an IP other wise use the |
| 263 // standard WebSocketRTCClient. | 302 // standard WebSocketRTCClient. |
| 264 if (loopback || !DirectRTCClient.IP_PATTERN.matcher(roomId).matches()) { | 303 if (loopback || !DirectRTCClient.IP_PATTERN.matcher(roomId).matches()) { |
| 265 appRtcClient = new WebSocketRTCClient(this); | 304 appRtcClient = new WebSocketRTCClient(this); |
| 266 } else { | 305 } else { |
| 267 Log.i(TAG, "Using DirectRTCClient because room name looks like an IP."); | 306 Log.i(TAG, "Using DirectRTCClient because room name looks like an IP."); |
| 268 appRtcClient = new DirectRTCClient(this); | 307 appRtcClient = new DirectRTCClient(this); |
| 269 } | 308 } |
| 270 // Create connection parameters. | 309 // Create connection parameters. |
| 271 roomConnectionParameters = new RoomConnectionParameters( | 310 roomConnectionParameters = new RoomConnectionParameters( |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 298 peerConnectionClient = PeerConnectionClient.getInstance(); | 337 peerConnectionClient = PeerConnectionClient.getInstance(); |
| 299 if (loopback) { | 338 if (loopback) { |
| 300 PeerConnectionFactory.Options options = new PeerConnectionFactory.Options( ); | 339 PeerConnectionFactory.Options options = new PeerConnectionFactory.Options( ); |
| 301 options.networkIgnoreMask = 0; | 340 options.networkIgnoreMask = 0; |
| 302 peerConnectionClient.setPeerConnectionFactoryOptions(options); | 341 peerConnectionClient.setPeerConnectionFactoryOptions(options); |
| 303 } | 342 } |
| 304 peerConnectionClient.createPeerConnectionFactory( | 343 peerConnectionClient.createPeerConnectionFactory( |
| 305 CallActivity.this, peerConnectionParameters, CallActivity.this); | 344 CallActivity.this, peerConnectionParameters, CallActivity.this); |
| 306 } | 345 } |
| 307 | 346 |
| 347 private boolean useCamera2() { | |
| 348 return Camera2Enumerator.isSupported() | |
| 349 && getIntent().getBooleanExtra(EXTRA_CAMERA2, true); | |
| 350 } | |
| 351 | |
| 352 private boolean captureToTexture() { | |
| 353 return getIntent().getBooleanExtra(EXTRA_CAPTURETOTEXTURE_ENABLED, false); | |
| 354 } | |
| 355 | |
| 356 private VideoCapturer createCapturer(CameraEnumerator enumerator) { | |
|
sakal
2016/10/05 13:28:41
nit: rename to createCameraCapturer
mandermo
2016/10/07 11:33:41
Done. Change name of createVideoCapturer in PeerCo
| |
| 357 final String[] deviceNames = enumerator.getDeviceNames(); | |
| 358 | |
| 359 // First, try to find front facing camera | |
| 360 Logging.d(TAG, "Looking for front facing cameras."); | |
| 361 for (String deviceName : deviceNames) { | |
| 362 if (enumerator.isFrontFacing(deviceName)) { | |
| 363 Logging.d(TAG, "Creating front facing camera capturer."); | |
| 364 VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null ); | |
| 365 | |
| 366 if (videoCapturer != null) { | |
| 367 return videoCapturer; | |
| 368 } | |
| 369 } | |
| 370 } | |
| 371 | |
| 372 // Front facing camera not found, try something else | |
| 373 Logging.d(TAG, "Looking for other cameras."); | |
| 374 for (String deviceName : deviceNames) { | |
| 375 if (!enumerator.isFrontFacing(deviceName)) { | |
| 376 Logging.d(TAG, "Creating other camera capturer."); | |
| 377 VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null ); | |
| 378 | |
| 379 if (videoCapturer != null) { | |
| 380 return videoCapturer; | |
| 381 } | |
| 382 } | |
| 383 } | |
| 384 | |
| 385 return null; | |
| 386 } | |
| 387 | |
| 308 // Activity interfaces | 388 // Activity interfaces |
| 309 @Override | 389 @Override |
| 310 public void onPause() { | 390 public void onPause() { |
| 311 super.onPause(); | 391 super.onPause(); |
| 312 activityRunning = false; | 392 activityRunning = false; |
| 313 if (peerConnectionClient != null) { | 393 if (peerConnectionClient != null) { |
| 314 peerConnectionClient.stopVideoSource(); | 394 peerConnectionClient.stopVideoSource(); |
| 315 } | 395 } |
| 316 cpuMonitor.pause(); | 396 cpuMonitor.pause(); |
| 317 } | 397 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 } else { | 466 } else { |
| 387 ft.hide(callFragment); | 467 ft.hide(callFragment); |
| 388 ft.hide(hudFragment); | 468 ft.hide(hudFragment); |
| 389 } | 469 } |
| 390 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); | 470 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
| 391 ft.commit(); | 471 ft.commit(); |
| 392 } | 472 } |
| 393 | 473 |
| 394 private void updateVideoView() { | 474 private void updateVideoView() { |
| 395 remoteRenderLayout.setPosition(REMOTE_X, REMOTE_Y, REMOTE_WIDTH, REMOTE_HEIG HT); | 475 remoteRenderLayout.setPosition(REMOTE_X, REMOTE_Y, REMOTE_WIDTH, REMOTE_HEIG HT); |
| 396 remoteRender.setScalingType(scalingType); | 476 remoteRenderScreen.setScalingType(scalingType); |
| 397 remoteRender.setMirror(false); | 477 remoteRenderScreen.setMirror(false); |
| 398 | 478 |
| 399 if (iceConnected) { | 479 if (iceConnected) { |
| 400 localRenderLayout.setPosition( | 480 localRenderLayout.setPosition( |
| 401 LOCAL_X_CONNECTED, LOCAL_Y_CONNECTED, LOCAL_WIDTH_CONNECTED, LOCAL_HEI GHT_CONNECTED); | 481 LOCAL_X_CONNECTED, LOCAL_Y_CONNECTED, LOCAL_WIDTH_CONNECTED, LOCAL_HEI GHT_CONNECTED); |
| 402 localRender.setScalingType(ScalingType.SCALE_ASPECT_FIT); | 482 localRender.setScalingType(ScalingType.SCALE_ASPECT_FIT); |
| 403 } else { | 483 } else { |
| 404 localRenderLayout.setPosition( | 484 localRenderLayout.setPosition( |
| 405 LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING, LOCAL_WIDTH_CONNECTING, LOCAL_ HEIGHT_CONNECTING); | 485 LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING, LOCAL_WIDTH_CONNECTING, LOCAL_ HEIGHT_CONNECTING); |
| 406 localRender.setScalingType(scalingType); | 486 localRender.setScalingType(scalingType); |
| 407 } | 487 } |
| 408 localRender.setMirror(true); | 488 localRender.setMirror(true); |
| 409 | 489 |
| 410 localRender.requestLayout(); | 490 localRender.requestLayout(); |
| 411 remoteRender.requestLayout(); | 491 remoteRenderScreen.requestLayout(); |
| 412 } | 492 } |
| 413 | 493 |
| 414 private void startCall() { | 494 private void startCall() { |
| 415 if (appRtcClient == null) { | 495 if (appRtcClient == null) { |
| 416 Log.e(TAG, "AppRTC client is not allocated for a call."); | 496 Log.e(TAG, "AppRTC client is not allocated for a call."); |
| 417 return; | 497 return; |
| 418 } | 498 } |
| 419 callStartedTimeMs = System.currentTimeMillis(); | 499 callStartedTimeMs = System.currentTimeMillis(); |
| 420 | 500 |
| 421 // Start room connection. | 501 // Start room connection. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 appRtcClient = null; | 547 appRtcClient = null; |
| 468 } | 548 } |
| 469 if (peerConnectionClient != null) { | 549 if (peerConnectionClient != null) { |
| 470 peerConnectionClient.close(); | 550 peerConnectionClient.close(); |
| 471 peerConnectionClient = null; | 551 peerConnectionClient = null; |
| 472 } | 552 } |
| 473 if (localRender != null) { | 553 if (localRender != null) { |
| 474 localRender.release(); | 554 localRender.release(); |
| 475 localRender = null; | 555 localRender = null; |
| 476 } | 556 } |
| 477 if (remoteRender != null) { | 557 if (videoFileRenderer != null) { |
| 478 remoteRender.release(); | 558 videoFileRenderer.release(); |
| 479 remoteRender = null; | 559 videoFileRenderer = null; |
| 560 } | |
| 561 if (remoteRenderScreen != null) { | |
| 562 remoteRenderScreen.release(); | |
| 563 remoteRenderScreen = null; | |
| 480 } | 564 } |
| 481 if (audioManager != null) { | 565 if (audioManager != null) { |
| 482 audioManager.close(); | 566 audioManager.close(); |
| 483 audioManager = null; | 567 audioManager = null; |
| 484 } | 568 } |
| 485 if (iceConnected && !isError) { | 569 if (iceConnected && !isError) { |
| 486 setResult(RESULT_OK); | 570 setResult(RESULT_OK); |
| 487 } else { | 571 } else { |
| 488 setResult(RESULT_CANCELED); | 572 setResult(RESULT_CANCELED); |
| 489 } | 573 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 @Override | 608 @Override |
| 525 public void run() { | 609 public void run() { |
| 526 if (!isError) { | 610 if (!isError) { |
| 527 isError = true; | 611 isError = true; |
| 528 disconnectWithErrorMessage(description); | 612 disconnectWithErrorMessage(description); |
| 529 } | 613 } |
| 530 } | 614 } |
| 531 }); | 615 }); |
| 532 } | 616 } |
| 533 | 617 |
| 618 private VideoCapturer createVideoCapturer() { | |
| 619 VideoCapturer videoCapturer = null; | |
| 620 String videoFileAsCamera = getIntent().getStringExtra(EXTRA_VIDEO_FILE_AS_CA MERA); | |
| 621 if (videoFileAsCamera != null) { | |
| 622 videoCapturer = FileVideoCapturer.create( | |
| 623 videoFileAsCamera); | |
| 624 | |
| 625 if (videoCapturer == null) { | |
| 626 reportError("Failed to open video file for emulated camera"); | |
| 627 return null; | |
| 628 } | |
| 629 } else if (useCamera2()) { | |
| 630 if (!captureToTexture()) { | |
| 631 reportError(getString(R.string.camera2_texture_only_error)); | |
| 632 return null; | |
| 633 } | |
| 634 | |
| 635 Logging.d(TAG, "Creating capturer using camera2 API."); | |
| 636 videoCapturer = createCapturer(new Camera2Enumerator(this)); | |
| 637 } else { | |
| 638 Logging.d(TAG, "Creating capturer using camera1 API."); | |
| 639 videoCapturer = createCapturer(new Camera1Enumerator(captureToTexture())); | |
| 640 } | |
| 641 if (videoCapturer == null) { | |
| 642 reportError("Failed to open camera"); | |
| 643 return null; | |
| 644 } | |
| 645 return videoCapturer; | |
| 646 } | |
| 647 | |
| 534 // -----Implementation of AppRTCClient.AppRTCSignalingEvents --------------- | 648 // -----Implementation of AppRTCClient.AppRTCSignalingEvents --------------- |
| 535 // All callbacks are invoked from websocket signaling looper thread and | 649 // All callbacks are invoked from websocket signaling looper thread and |
| 536 // are routed to UI thread. | 650 // are routed to UI thread. |
| 537 private void onConnectedToRoomInternal(final SignalingParameters params) { | 651 private void onConnectedToRoomInternal(final SignalingParameters params) { |
| 538 final long delta = System.currentTimeMillis() - callStartedTimeMs; | 652 final long delta = System.currentTimeMillis() - callStartedTimeMs; |
| 539 | 653 |
| 540 signalingParameters = params; | 654 signalingParameters = params; |
| 541 logAndToast("Creating peer connection, delay=" + delta + "ms"); | 655 logAndToast("Creating peer connection, delay=" + delta + "ms"); |
| 656 VideoCapturer videoCapturer = null; | |
| 657 if (peerConnectionParameters.videoCallEnabled) { | |
| 658 videoCapturer = createVideoCapturer(); | |
| 659 } | |
| 542 peerConnectionClient.createPeerConnection(rootEglBase.getEglBaseContext(), | 660 peerConnectionClient.createPeerConnection(rootEglBase.getEglBaseContext(), |
| 543 localRender, remoteRender, signalingParameters); | 661 localRender, remoteRenders, videoCapturer, signalingParameters); |
| 544 | 662 |
| 545 if (signalingParameters.initiator) { | 663 if (signalingParameters.initiator) { |
| 546 logAndToast("Creating OFFER..."); | 664 logAndToast("Creating OFFER..."); |
| 547 // Create offer. Offer SDP will be sent to answering client in | 665 // Create offer. Offer SDP will be sent to answering client in |
| 548 // PeerConnectionEvents.onLocalDescription event. | 666 // PeerConnectionEvents.onLocalDescription event. |
| 549 peerConnectionClient.createOffer(); | 667 peerConnectionClient.createOffer(); |
| 550 } else { | 668 } else { |
| 551 if (params.offerSdp != null) { | 669 if (params.offerSdp != null) { |
| 552 peerConnectionClient.setRemoteDescription(params.offerSdp); | 670 peerConnectionClient.setRemoteDescription(params.offerSdp); |
| 553 logAndToast("Creating ANSWER..."); | 671 logAndToast("Creating ANSWER..."); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 729 } | 847 } |
| 730 } | 848 } |
| 731 }); | 849 }); |
| 732 } | 850 } |
| 733 | 851 |
| 734 @Override | 852 @Override |
| 735 public void onPeerConnectionError(final String description) { | 853 public void onPeerConnectionError(final String description) { |
| 736 reportError(description); | 854 reportError(description); |
| 737 } | 855 } |
| 738 } | 856 } |
| OLD | NEW |