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 implements AppRTCClient.SignalingEven
ts, | 57 public class CallActivity extends Activity implements AppRTCClient.SignalingEven
ts, |
46 PeerConnectionClient.PeerC
onnectionEvents, | 58 PeerConnectionClient.PeerC
onnectionEvents, |
47 CallFragment.OnCallEvents
{ | 59 CallFragment.OnCallEvents
{ |
48 public static final String EXTRA_ROOMID = "org.appspot.apprtc.ROOMID"; | 60 public static final String EXTRA_ROOMID = "org.appspot.apprtc.ROOMID"; |
49 public static final String EXTRA_LOOPBACK = "org.appspot.apprtc.LOOPBACK"; | 61 public static final String EXTRA_LOOPBACK = "org.appspot.apprtc.LOOPBACK"; |
(...skipping 15 matching lines...) Expand all Loading... |
65 public static final String EXTRA_AECDUMP_ENABLED = "org.appspot.apprtc.AECDUMP
"; | 77 public static final String EXTRA_AECDUMP_ENABLED = "org.appspot.apprtc.AECDUMP
"; |
66 public static final String EXTRA_OPENSLES_ENABLED = "org.appspot.apprtc.OPENSL
ES"; | 78 public static final String EXTRA_OPENSLES_ENABLED = "org.appspot.apprtc.OPENSL
ES"; |
67 public static final String EXTRA_DISABLE_BUILT_IN_AEC = "org.appspot.apprtc.DI
SABLE_BUILT_IN_AEC"; | 79 public static final String EXTRA_DISABLE_BUILT_IN_AEC = "org.appspot.apprtc.DI
SABLE_BUILT_IN_AEC"; |
68 public static final String EXTRA_DISABLE_BUILT_IN_AGC = "org.appspot.apprtc.DI
SABLE_BUILT_IN_AGC"; | 80 public static final String EXTRA_DISABLE_BUILT_IN_AGC = "org.appspot.apprtc.DI
SABLE_BUILT_IN_AGC"; |
69 public static final String EXTRA_DISABLE_BUILT_IN_NS = "org.appspot.apprtc.DIS
ABLE_BUILT_IN_NS"; | 81 public static final String EXTRA_DISABLE_BUILT_IN_NS = "org.appspot.apprtc.DIS
ABLE_BUILT_IN_NS"; |
70 public static final String EXTRA_ENABLE_LEVEL_CONTROL = "org.appspot.apprtc.EN
ABLE_LEVEL_CONTROL"; | 82 public static final String EXTRA_ENABLE_LEVEL_CONTROL = "org.appspot.apprtc.EN
ABLE_LEVEL_CONTROL"; |
71 public static final String EXTRA_DISPLAY_HUD = "org.appspot.apprtc.DISPLAY_HUD
"; | 83 public static final String EXTRA_DISPLAY_HUD = "org.appspot.apprtc.DISPLAY_HUD
"; |
72 public static final String EXTRA_TRACING = "org.appspot.apprtc.TRACING"; | 84 public static final String EXTRA_TRACING = "org.appspot.apprtc.TRACING"; |
73 public static final String EXTRA_CMDLINE = "org.appspot.apprtc.CMDLINE"; | 85 public static final String EXTRA_CMDLINE = "org.appspot.apprtc.CMDLINE"; |
74 public static final String EXTRA_RUNTIME = "org.appspot.apprtc.RUNTIME"; | 86 public static final String EXTRA_RUNTIME = "org.appspot.apprtc.RUNTIME"; |
| 87 public static final String EXTRA_VIDEO_FILE_AS_CAMERA = "org.appspot.apprtc.VI
DEO_FILE_AS_CAMERA"; |
| 88 public static final String EXTRA_SAVE_REMOTE_VIDEO_TO_FILE = |
| 89 "org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE"; |
| 90 public static final String EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_WIDTH = |
| 91 "org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE_WIDTH"; |
| 92 public static final String EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_HEIGHT = |
| 93 "org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE_HEIGHT"; |
| 94 public static final String EXTRA_USE_VALUES_FROM_INTENT = |
| 95 "org.appspot.apprtc.USE_VALUES_FROM_INTENT"; |
75 private static final String TAG = "CallRTCClient"; | 96 private static final String TAG = "CallRTCClient"; |
76 | 97 |
77 // List of mandatory application permissions. | 98 // List of mandatory application permissions. |
78 private static final String[] MANDATORY_PERMISSIONS = {"android.permission.MOD
IFY_AUDIO_SETTINGS", | 99 private static final String[] MANDATORY_PERMISSIONS = {"android.permission.MOD
IFY_AUDIO_SETTINGS", |
79 "android.permission.RECORD_AUDIO", "android.permission.INTERNET"}; | 100 "android.permission.RECORD_AUDIO", "android.permission.INTERNET"}; |
80 | 101 |
81 // Peer connection statistics callback period in ms. | 102 // Peer connection statistics callback period in ms. |
82 private static final int STAT_CALLBACK_PERIOD = 1000; | 103 private static final int STAT_CALLBACK_PERIOD = 1000; |
83 // Local preview screen position before call is connected. | 104 // Local preview screen position before call is connected. |
84 private static final int LOCAL_X_CONNECTING = 0; | 105 private static final int LOCAL_X_CONNECTING = 0; |
85 private static final int LOCAL_Y_CONNECTING = 0; | 106 private static final int LOCAL_Y_CONNECTING = 0; |
86 private static final int LOCAL_WIDTH_CONNECTING = 100; | 107 private static final int LOCAL_WIDTH_CONNECTING = 100; |
87 private static final int LOCAL_HEIGHT_CONNECTING = 100; | 108 private static final int LOCAL_HEIGHT_CONNECTING = 100; |
88 // Local preview screen position after call is connected. | 109 // Local preview screen position after call is connected. |
89 private static final int LOCAL_X_CONNECTED = 72; | 110 private static final int LOCAL_X_CONNECTED = 72; |
90 private static final int LOCAL_Y_CONNECTED = 72; | 111 private static final int LOCAL_Y_CONNECTED = 72; |
91 private static final int LOCAL_WIDTH_CONNECTED = 25; | 112 private static final int LOCAL_WIDTH_CONNECTED = 25; |
92 private static final int LOCAL_HEIGHT_CONNECTED = 25; | 113 private static final int LOCAL_HEIGHT_CONNECTED = 25; |
93 // Remote video screen position | 114 // Remote video screen position |
94 private static final int REMOTE_X = 0; | 115 private static final int REMOTE_X = 0; |
95 private static final int REMOTE_Y = 0; | 116 private static final int REMOTE_Y = 0; |
96 private static final int REMOTE_WIDTH = 100; | 117 private static final int REMOTE_WIDTH = 100; |
97 private static final int REMOTE_HEIGHT = 100; | 118 private static final int REMOTE_HEIGHT = 100; |
98 private PeerConnectionClient peerConnectionClient = null; | 119 private PeerConnectionClient peerConnectionClient = null; |
99 private AppRTCClient appRtcClient; | 120 private AppRTCClient appRtcClient; |
100 private SignalingParameters signalingParameters; | 121 private SignalingParameters signalingParameters; |
101 private AppRTCAudioManager audioManager = null; | 122 private AppRTCAudioManager audioManager = null; |
102 private EglBase rootEglBase; | 123 private EglBase rootEglBase; |
103 private SurfaceViewRenderer localRender; | 124 private SurfaceViewRenderer localRender; |
104 private SurfaceViewRenderer remoteRender; | 125 private SurfaceViewRenderer remoteRenderScreen; |
| 126 private VideoFileRenderer videoFileRenderer; |
| 127 private final List<VideoRenderer.Callbacks> remoteRenderers = |
| 128 new ArrayList<VideoRenderer.Callbacks>(); |
105 private PercentFrameLayout localRenderLayout; | 129 private PercentFrameLayout localRenderLayout; |
106 private PercentFrameLayout remoteRenderLayout; | 130 private PercentFrameLayout remoteRenderLayout; |
107 private ScalingType scalingType; | 131 private ScalingType scalingType; |
108 private Toast logToast; | 132 private Toast logToast; |
109 private boolean commandLineRun; | 133 private boolean commandLineRun; |
110 private int runTimeMs; | 134 private int runTimeMs; |
111 private boolean activityRunning; | 135 private boolean activityRunning; |
112 private RoomConnectionParameters roomConnectionParameters; | 136 private RoomConnectionParameters roomConnectionParameters; |
113 private PeerConnectionParameters peerConnectionParameters; | 137 private PeerConnectionParameters peerConnectionParameters; |
114 private boolean iceConnected; | 138 private boolean iceConnected; |
(...skipping 21 matching lines...) Expand all Loading... |
136 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NA
VIGATION | 160 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NA
VIGATION |
137 | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
; | 161 | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
; |
138 setContentView(R.layout.activity_call); | 162 setContentView(R.layout.activity_call); |
139 | 163 |
140 iceConnected = false; | 164 iceConnected = false; |
141 signalingParameters = null; | 165 signalingParameters = null; |
142 scalingType = ScalingType.SCALE_ASPECT_FILL; | 166 scalingType = ScalingType.SCALE_ASPECT_FILL; |
143 | 167 |
144 // Create UI controls. | 168 // Create UI controls. |
145 localRender = (SurfaceViewRenderer) findViewById(R.id.local_video_view); | 169 localRender = (SurfaceViewRenderer) findViewById(R.id.local_video_view); |
146 remoteRender = (SurfaceViewRenderer) findViewById(R.id.remote_video_view); | 170 remoteRenderScreen = (SurfaceViewRenderer) findViewById(R.id.remote_video_vi
ew); |
147 localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layou
t); | 171 localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layou
t); |
148 remoteRenderLayout = (PercentFrameLayout) findViewById(R.id.remote_video_lay
out); | 172 remoteRenderLayout = (PercentFrameLayout) findViewById(R.id.remote_video_lay
out); |
149 callFragment = new CallFragment(); | 173 callFragment = new CallFragment(); |
150 hudFragment = new HudFragment(); | 174 hudFragment = new HudFragment(); |
151 | 175 |
152 // Show/hide call control fragment on view click. | 176 // Show/hide call control fragment on view click. |
153 View.OnClickListener listener = new View.OnClickListener() { | 177 View.OnClickListener listener = new View.OnClickListener() { |
154 @Override | 178 @Override |
155 public void onClick(View view) { | 179 public void onClick(View view) { |
156 toggleCallControlFragmentVisibility(); | 180 toggleCallControlFragmentVisibility(); |
157 } | 181 } |
158 }; | 182 }; |
159 | 183 |
160 localRender.setOnClickListener(listener); | 184 localRender.setOnClickListener(listener); |
161 remoteRender.setOnClickListener(listener); | 185 remoteRenderScreen.setOnClickListener(listener); |
| 186 remoteRenderers.add(remoteRenderScreen); |
| 187 |
| 188 final Intent intent = getIntent(); |
162 | 189 |
163 // Create video renderers. | 190 // Create video renderers. |
164 rootEglBase = EglBase.create(); | 191 rootEglBase = EglBase.create(); |
165 localRender.init(rootEglBase.getEglBaseContext(), null); | 192 localRender.init(rootEglBase.getEglBaseContext(), null); |
166 remoteRender.init(rootEglBase.getEglBaseContext(), null); | 193 String saveRemoteVideoToFile = intent.getStringExtra(EXTRA_SAVE_REMOTE_VIDEO
_TO_FILE); |
| 194 |
| 195 // When saveRemoteVideoToFile is set we save the video from the remote to a
file. |
| 196 if (saveRemoteVideoToFile != null) { |
| 197 int videoOutWidth = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_WID
TH, 0); |
| 198 int videoOutHeight = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_HE
IGHT, 0); |
| 199 try { |
| 200 videoFileRenderer = new VideoFileRenderer( |
| 201 saveRemoteVideoToFile, videoOutWidth, videoOutHeight, rootEglBase.ge
tEglBaseContext()); |
| 202 remoteRenderers.add(videoFileRenderer); |
| 203 } catch (IOException e) { |
| 204 throw new RuntimeException( |
| 205 "Failed to open video file for output: " + saveRemoteVideoToFile, e)
; |
| 206 } |
| 207 } |
| 208 remoteRenderScreen.init(rootEglBase.getEglBaseContext(), null); |
| 209 |
167 localRender.setZOrderMediaOverlay(true); | 210 localRender.setZOrderMediaOverlay(true); |
168 updateVideoView(); | 211 updateVideoView(); |
169 | 212 |
170 // Check for mandatory permissions. | 213 // Check for mandatory permissions. |
171 for (String permission : MANDATORY_PERMISSIONS) { | 214 for (String permission : MANDATORY_PERMISSIONS) { |
172 if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_
GRANTED) { | 215 if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_
GRANTED) { |
173 logAndToast("Permission " + permission + " is not granted"); | 216 logAndToast("Permission " + permission + " is not granted"); |
174 setResult(RESULT_CANCELED); | 217 setResult(RESULT_CANCELED); |
175 finish(); | 218 finish(); |
176 return; | 219 return; |
177 } | 220 } |
178 } | 221 } |
179 | 222 |
180 // Get Intent parameters. | |
181 final Intent intent = getIntent(); | |
182 Uri roomUri = intent.getData(); | 223 Uri roomUri = intent.getData(); |
183 if (roomUri == null) { | 224 if (roomUri == null) { |
184 logAndToast(getString(R.string.missing_url)); | 225 logAndToast(getString(R.string.missing_url)); |
185 Log.e(TAG, "Didn't get any URL in intent!"); | 226 Log.e(TAG, "Didn't get any URL in intent!"); |
186 setResult(RESULT_CANCELED); | 227 setResult(RESULT_CANCELED); |
187 finish(); | 228 finish(); |
188 return; | 229 return; |
189 } | 230 } |
| 231 |
| 232 // Get Intent parameters. |
190 String roomId = intent.getStringExtra(EXTRA_ROOMID); | 233 String roomId = intent.getStringExtra(EXTRA_ROOMID); |
| 234 Log.d(TAG, "Room ID: " + roomId); |
191 if (roomId == null || roomId.length() == 0) { | 235 if (roomId == null || roomId.length() == 0) { |
192 logAndToast(getString(R.string.missing_url)); | 236 logAndToast(getString(R.string.missing_url)); |
193 Log.e(TAG, "Incorrect room ID in intent!"); | 237 Log.e(TAG, "Incorrect room ID in intent!"); |
194 setResult(RESULT_CANCELED); | 238 setResult(RESULT_CANCELED); |
195 finish(); | 239 finish(); |
196 return; | 240 return; |
197 } | 241 } |
198 | 242 |
199 boolean loopback = intent.getBooleanExtra(EXTRA_LOOPBACK, false); | 243 boolean loopback = intent.getBooleanExtra(EXTRA_LOOPBACK, false); |
200 boolean tracing = intent.getBooleanExtra(EXTRA_TRACING, false); | 244 boolean tracing = intent.getBooleanExtra(EXTRA_TRACING, false); |
201 | 245 |
202 boolean useCamera2 = | |
203 Camera2Enumerator.isSupported(this) && intent.getBooleanExtra(EXTRA_CAME
RA2, true); | |
204 | |
205 peerConnectionParameters = | 246 peerConnectionParameters = |
206 new PeerConnectionParameters(intent.getBooleanExtra(EXTRA_VIDEO_CALL, tr
ue), loopback, | 247 new PeerConnectionParameters(intent.getBooleanExtra(EXTRA_VIDEO_CALL, tr
ue), loopback, |
207 tracing, useCamera2, intent.getIntExtra(EXTRA_VIDEO_WIDTH, 0), | 248 tracing, intent.getIntExtra(EXTRA_VIDEO_WIDTH, 0), |
208 intent.getIntExtra(EXTRA_VIDEO_HEIGHT, 0), intent.getIntExtra(EXTRA_
VIDEO_FPS, 0), | 249 intent.getIntExtra(EXTRA_VIDEO_HEIGHT, 0), intent.getIntExtra(EXTRA_
VIDEO_FPS, 0), |
209 intent.getIntExtra(EXTRA_VIDEO_BITRATE, 0), intent.getStringExtra(EX
TRA_VIDEOCODEC), | 250 intent.getIntExtra(EXTRA_VIDEO_BITRATE, 0), intent.getStringExtra(EX
TRA_VIDEOCODEC), |
210 intent.getBooleanExtra(EXTRA_HWCODEC_ENABLED, true), | 251 intent.getBooleanExtra(EXTRA_HWCODEC_ENABLED, true), |
211 intent.getBooleanExtra(EXTRA_CAPTURETOTEXTURE_ENABLED, false), | |
212 intent.getIntExtra(EXTRA_AUDIO_BITRATE, 0), intent.getStringExtra(EX
TRA_AUDIOCODEC), | 252 intent.getIntExtra(EXTRA_AUDIO_BITRATE, 0), intent.getStringExtra(EX
TRA_AUDIOCODEC), |
213 intent.getBooleanExtra(EXTRA_NOAUDIOPROCESSING_ENABLED, false), | 253 intent.getBooleanExtra(EXTRA_NOAUDIOPROCESSING_ENABLED, false), |
214 intent.getBooleanExtra(EXTRA_AECDUMP_ENABLED, false), | 254 intent.getBooleanExtra(EXTRA_AECDUMP_ENABLED, false), |
215 intent.getBooleanExtra(EXTRA_OPENSLES_ENABLED, false), | 255 intent.getBooleanExtra(EXTRA_OPENSLES_ENABLED, false), |
216 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_AEC, false), | 256 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_AEC, false), |
217 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_AGC, false), | 257 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_AGC, false), |
218 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_NS, false), | 258 intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_NS, false), |
219 intent.getBooleanExtra(EXTRA_ENABLE_LEVEL_CONTROL, false)); | 259 intent.getBooleanExtra(EXTRA_ENABLE_LEVEL_CONTROL, false)); |
220 commandLineRun = intent.getBooleanExtra(EXTRA_CMDLINE, false); | 260 commandLineRun = intent.getBooleanExtra(EXTRA_CMDLINE, false); |
221 runTimeMs = intent.getIntExtra(EXTRA_RUNTIME, 0); | 261 runTimeMs = intent.getIntExtra(EXTRA_RUNTIME, 0); |
222 | 262 |
| 263 Log.d(TAG, "VIDEO_FILE: '" + intent.getStringExtra(EXTRA_VIDEO_FILE_AS_CAMER
A) + "'"); |
| 264 |
223 // Create connection client. Use DirectRTCClient if room name is an IP other
wise use the | 265 // Create connection client. Use DirectRTCClient if room name is an IP other
wise use the |
224 // standard WebSocketRTCClient. | 266 // standard WebSocketRTCClient. |
225 if (loopback || !DirectRTCClient.IP_PATTERN.matcher(roomId).matches()) { | 267 if (loopback || !DirectRTCClient.IP_PATTERN.matcher(roomId).matches()) { |
226 appRtcClient = new WebSocketRTCClient(this); | 268 appRtcClient = new WebSocketRTCClient(this); |
227 } else { | 269 } else { |
228 Log.i(TAG, "Using DirectRTCClient because room name looks like an IP."); | 270 Log.i(TAG, "Using DirectRTCClient because room name looks like an IP."); |
229 appRtcClient = new DirectRTCClient(this); | 271 appRtcClient = new DirectRTCClient(this); |
230 } | 272 } |
231 // Create connection parameters. | 273 // Create connection parameters. |
232 roomConnectionParameters = new RoomConnectionParameters(roomUri.toString(),
roomId, loopback); | 274 roomConnectionParameters = new RoomConnectionParameters(roomUri.toString(),
roomId, loopback); |
(...skipping 25 matching lines...) Expand all Loading... |
258 peerConnectionClient = PeerConnectionClient.getInstance(); | 300 peerConnectionClient = PeerConnectionClient.getInstance(); |
259 if (loopback) { | 301 if (loopback) { |
260 PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(
); | 302 PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(
); |
261 options.networkIgnoreMask = 0; | 303 options.networkIgnoreMask = 0; |
262 peerConnectionClient.setPeerConnectionFactoryOptions(options); | 304 peerConnectionClient.setPeerConnectionFactoryOptions(options); |
263 } | 305 } |
264 peerConnectionClient.createPeerConnectionFactory( | 306 peerConnectionClient.createPeerConnectionFactory( |
265 CallActivity.this, peerConnectionParameters, CallActivity.this); | 307 CallActivity.this, peerConnectionParameters, CallActivity.this); |
266 } | 308 } |
267 | 309 |
| 310 private boolean useCamera2() { |
| 311 return Camera2Enumerator.isSupported() && getIntent().getBooleanExtra(EXTRA_
CAMERA2, true); |
| 312 } |
| 313 |
| 314 private boolean captureToTexture() { |
| 315 return getIntent().getBooleanExtra(EXTRA_CAPTURETOTEXTURE_ENABLED, false); |
| 316 } |
| 317 |
| 318 private VideoCapturer createCameraCapturer(CameraEnumerator enumerator) { |
| 319 final String[] deviceNames = enumerator.getDeviceNames(); |
| 320 |
| 321 // First, try to find front facing camera |
| 322 Logging.d(TAG, "Looking for front facing cameras."); |
| 323 for (String deviceName : deviceNames) { |
| 324 if (enumerator.isFrontFacing(deviceName)) { |
| 325 Logging.d(TAG, "Creating front facing camera capturer."); |
| 326 VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null
); |
| 327 |
| 328 if (videoCapturer != null) { |
| 329 return videoCapturer; |
| 330 } |
| 331 } |
| 332 } |
| 333 |
| 334 // Front facing camera not found, try something else |
| 335 Logging.d(TAG, "Looking for other cameras."); |
| 336 for (String deviceName : deviceNames) { |
| 337 if (!enumerator.isFrontFacing(deviceName)) { |
| 338 Logging.d(TAG, "Creating other camera capturer."); |
| 339 VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null
); |
| 340 |
| 341 if (videoCapturer != null) { |
| 342 return videoCapturer; |
| 343 } |
| 344 } |
| 345 } |
| 346 |
| 347 return null; |
| 348 } |
| 349 |
268 // Activity interfaces | 350 // Activity interfaces |
269 @Override | 351 @Override |
270 public void onPause() { | 352 public void onPause() { |
271 super.onPause(); | 353 super.onPause(); |
272 activityRunning = false; | 354 activityRunning = false; |
273 if (peerConnectionClient != null) { | 355 if (peerConnectionClient != null) { |
274 peerConnectionClient.stopVideoSource(); | 356 peerConnectionClient.stopVideoSource(); |
275 } | 357 } |
276 cpuMonitor.pause(); | 358 cpuMonitor.pause(); |
277 } | 359 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } else { | 428 } else { |
347 ft.hide(callFragment); | 429 ft.hide(callFragment); |
348 ft.hide(hudFragment); | 430 ft.hide(hudFragment); |
349 } | 431 } |
350 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); | 432 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
351 ft.commit(); | 433 ft.commit(); |
352 } | 434 } |
353 | 435 |
354 private void updateVideoView() { | 436 private void updateVideoView() { |
355 remoteRenderLayout.setPosition(REMOTE_X, REMOTE_Y, REMOTE_WIDTH, REMOTE_HEIG
HT); | 437 remoteRenderLayout.setPosition(REMOTE_X, REMOTE_Y, REMOTE_WIDTH, REMOTE_HEIG
HT); |
356 remoteRender.setScalingType(scalingType); | 438 remoteRenderScreen.setScalingType(scalingType); |
357 remoteRender.setMirror(false); | 439 remoteRenderScreen.setMirror(false); |
358 | 440 |
359 if (iceConnected) { | 441 if (iceConnected) { |
360 localRenderLayout.setPosition( | 442 localRenderLayout.setPosition( |
361 LOCAL_X_CONNECTED, LOCAL_Y_CONNECTED, LOCAL_WIDTH_CONNECTED, LOCAL_HEI
GHT_CONNECTED); | 443 LOCAL_X_CONNECTED, LOCAL_Y_CONNECTED, LOCAL_WIDTH_CONNECTED, LOCAL_HEI
GHT_CONNECTED); |
362 localRender.setScalingType(ScalingType.SCALE_ASPECT_FIT); | 444 localRender.setScalingType(ScalingType.SCALE_ASPECT_FIT); |
363 } else { | 445 } else { |
364 localRenderLayout.setPosition( | 446 localRenderLayout.setPosition( |
365 LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING, LOCAL_WIDTH_CONNECTING, LOCAL_
HEIGHT_CONNECTING); | 447 LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING, LOCAL_WIDTH_CONNECTING, LOCAL_
HEIGHT_CONNECTING); |
366 localRender.setScalingType(scalingType); | 448 localRender.setScalingType(scalingType); |
367 } | 449 } |
368 localRender.setMirror(true); | 450 localRender.setMirror(true); |
369 | 451 |
370 localRender.requestLayout(); | 452 localRender.requestLayout(); |
371 remoteRender.requestLayout(); | 453 remoteRenderScreen.requestLayout(); |
372 } | 454 } |
373 | 455 |
374 private void startCall() { | 456 private void startCall() { |
375 if (appRtcClient == null) { | 457 if (appRtcClient == null) { |
376 Log.e(TAG, "AppRTC client is not allocated for a call."); | 458 Log.e(TAG, "AppRTC client is not allocated for a call."); |
377 return; | 459 return; |
378 } | 460 } |
379 callStartedTimeMs = System.currentTimeMillis(); | 461 callStartedTimeMs = System.currentTimeMillis(); |
380 | 462 |
381 // Start room connection. | 463 // Start room connection. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 appRtcClient = null; | 507 appRtcClient = null; |
426 } | 508 } |
427 if (peerConnectionClient != null) { | 509 if (peerConnectionClient != null) { |
428 peerConnectionClient.close(); | 510 peerConnectionClient.close(); |
429 peerConnectionClient = null; | 511 peerConnectionClient = null; |
430 } | 512 } |
431 if (localRender != null) { | 513 if (localRender != null) { |
432 localRender.release(); | 514 localRender.release(); |
433 localRender = null; | 515 localRender = null; |
434 } | 516 } |
435 if (remoteRender != null) { | 517 if (videoFileRenderer != null) { |
436 remoteRender.release(); | 518 videoFileRenderer.release(); |
437 remoteRender = null; | 519 videoFileRenderer = null; |
| 520 } |
| 521 if (remoteRenderScreen != null) { |
| 522 remoteRenderScreen.release(); |
| 523 remoteRenderScreen = null; |
438 } | 524 } |
439 if (audioManager != null) { | 525 if (audioManager != null) { |
440 audioManager.close(); | 526 audioManager.close(); |
441 audioManager = null; | 527 audioManager = null; |
442 } | 528 } |
443 if (iceConnected && !isError) { | 529 if (iceConnected && !isError) { |
444 setResult(RESULT_OK); | 530 setResult(RESULT_OK); |
445 } else { | 531 } else { |
446 setResult(RESULT_CANCELED); | 532 setResult(RESULT_CANCELED); |
447 } | 533 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 @Override | 571 @Override |
486 public void run() { | 572 public void run() { |
487 if (!isError) { | 573 if (!isError) { |
488 isError = true; | 574 isError = true; |
489 disconnectWithErrorMessage(description); | 575 disconnectWithErrorMessage(description); |
490 } | 576 } |
491 } | 577 } |
492 }); | 578 }); |
493 } | 579 } |
494 | 580 |
| 581 private VideoCapturer createVideoCapturer() { |
| 582 VideoCapturer videoCapturer = null; |
| 583 String videoFileAsCamera = getIntent().getStringExtra(EXTRA_VIDEO_FILE_AS_CA
MERA); |
| 584 if (videoFileAsCamera != null) { |
| 585 try { |
| 586 videoCapturer = new FileVideoCapturer(videoFileAsCamera); |
| 587 } catch (IOException e) { |
| 588 reportError("Failed to open video file for emulated camera"); |
| 589 return null; |
| 590 } |
| 591 } else if (useCamera2()) { |
| 592 if (!captureToTexture()) { |
| 593 reportError(getString(R.string.camera2_texture_only_error)); |
| 594 return null; |
| 595 } |
| 596 |
| 597 Logging.d(TAG, "Creating capturer using camera2 API."); |
| 598 videoCapturer = createCameraCapturer(new Camera2Enumerator(this)); |
| 599 } else { |
| 600 Logging.d(TAG, "Creating capturer using camera1 API."); |
| 601 videoCapturer = createCameraCapturer(new Camera1Enumerator(captureToTextur
e())); |
| 602 } |
| 603 if (videoCapturer == null) { |
| 604 reportError("Failed to open camera"); |
| 605 return null; |
| 606 } |
| 607 return videoCapturer; |
| 608 } |
| 609 |
495 // -----Implementation of AppRTCClient.AppRTCSignalingEvents --------------- | 610 // -----Implementation of AppRTCClient.AppRTCSignalingEvents --------------- |
496 // All callbacks are invoked from websocket signaling looper thread and | 611 // All callbacks are invoked from websocket signaling looper thread and |
497 // are routed to UI thread. | 612 // are routed to UI thread. |
498 private void onConnectedToRoomInternal(final SignalingParameters params) { | 613 private void onConnectedToRoomInternal(final SignalingParameters params) { |
499 final long delta = System.currentTimeMillis() - callStartedTimeMs; | 614 final long delta = System.currentTimeMillis() - callStartedTimeMs; |
500 | 615 |
501 signalingParameters = params; | 616 signalingParameters = params; |
502 logAndToast("Creating peer connection, delay=" + delta + "ms"); | 617 logAndToast("Creating peer connection, delay=" + delta + "ms"); |
503 peerConnectionClient.createPeerConnection( | 618 VideoCapturer videoCapturer = null; |
504 rootEglBase.getEglBaseContext(), localRender, remoteRender, signalingPar
ameters); | 619 if (peerConnectionParameters.videoCallEnabled) { |
| 620 videoCapturer = createVideoCapturer(); |
| 621 } |
| 622 peerConnectionClient.createPeerConnection(rootEglBase.getEglBaseContext(), l
ocalRender, |
| 623 remoteRenderers, videoCapturer, signalingParameters); |
505 | 624 |
506 if (signalingParameters.initiator) { | 625 if (signalingParameters.initiator) { |
507 logAndToast("Creating OFFER..."); | 626 logAndToast("Creating OFFER..."); |
508 // Create offer. Offer SDP will be sent to answering client in | 627 // Create offer. Offer SDP will be sent to answering client in |
509 // PeerConnectionEvents.onLocalDescription event. | 628 // PeerConnectionEvents.onLocalDescription event. |
510 peerConnectionClient.createOffer(); | 629 peerConnectionClient.createOffer(); |
511 } else { | 630 } else { |
512 if (params.offerSdp != null) { | 631 if (params.offerSdp != null) { |
513 peerConnectionClient.setRemoteDescription(params.offerSdp); | 632 peerConnectionClient.setRemoteDescription(params.offerSdp); |
514 logAndToast("Creating ANSWER..."); | 633 logAndToast("Creating ANSWER..."); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 } | 808 } |
690 } | 809 } |
691 }); | 810 }); |
692 } | 811 } |
693 | 812 |
694 @Override | 813 @Override |
695 public void onPeerConnectionError(final String description) { | 814 public void onPeerConnectionError(final String description) { |
696 reportError(description); | 815 reportError(description); |
697 } | 816 } |
698 } | 817 } |
OLD | NEW |