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