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

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

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

Powered by Google App Engine
This is Rietveld 408576698