OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 package org.appspot.apprtc; | 11 package org.appspot.apprtc; |
12 | 12 |
13 import org.appspot.apprtc.AppRTCClient.SignalingParameters; | 13 import org.appspot.apprtc.AppRTCClient.SignalingParameters; |
14 | 14 |
15 import android.content.Context; | 15 import android.content.Context; |
16 import android.os.Environment; | 16 import android.os.Environment; |
17 import android.os.ParcelFileDescriptor; | 17 import android.os.ParcelFileDescriptor; |
18 import android.util.Log; | 18 import android.util.Log; |
19 | 19 |
20 import org.webrtc.AudioSource; | 20 import org.webrtc.AudioSource; |
21 import org.webrtc.AudioTrack; | 21 import org.webrtc.AudioTrack; |
22 import org.webrtc.Camera1Enumerator; | |
23 import org.webrtc.Camera2Enumerator; | |
24 import org.webrtc.CameraEnumerationAndroid; | |
25 import org.webrtc.CameraEnumerator; | |
26 import org.webrtc.CameraVideoCapturer; | 22 import org.webrtc.CameraVideoCapturer; |
27 import org.webrtc.DataChannel; | 23 import org.webrtc.DataChannel; |
28 import org.webrtc.EglBase; | 24 import org.webrtc.EglBase; |
29 import org.webrtc.IceCandidate; | 25 import org.webrtc.IceCandidate; |
30 import org.webrtc.Logging; | 26 import org.webrtc.Logging; |
31 import org.webrtc.MediaConstraints; | 27 import org.webrtc.MediaConstraints; |
32 import org.webrtc.MediaStream; | 28 import org.webrtc.MediaStream; |
33 import org.webrtc.PeerConnection; | 29 import org.webrtc.PeerConnection; |
34 import org.webrtc.PeerConnection.IceConnectionState; | 30 import org.webrtc.PeerConnection.IceConnectionState; |
35 import org.webrtc.PeerConnectionFactory; | 31 import org.webrtc.PeerConnectionFactory; |
36 import org.webrtc.RtpParameters; | 32 import org.webrtc.RtpParameters; |
37 import org.webrtc.RtpSender; | 33 import org.webrtc.RtpSender; |
38 import org.webrtc.SdpObserver; | 34 import org.webrtc.SdpObserver; |
39 import org.webrtc.SessionDescription; | 35 import org.webrtc.SessionDescription; |
40 import org.webrtc.StatsObserver; | 36 import org.webrtc.StatsObserver; |
41 import org.webrtc.StatsReport; | 37 import org.webrtc.StatsReport; |
42 import org.webrtc.VideoCapturer; | 38 import org.webrtc.VideoCapturer; |
43 import org.webrtc.VideoRenderer; | 39 import org.webrtc.VideoRenderer; |
44 import org.webrtc.VideoCapturerAndroid; | |
45 import org.webrtc.CameraVideoCapturer; | |
46 import org.webrtc.FileVideoCapturer; | |
47 import org.webrtc.VideoSource; | 40 import org.webrtc.VideoSource; |
48 import org.webrtc.VideoTrack; | 41 import org.webrtc.VideoTrack; |
49 import org.webrtc.voiceengine.WebRtcAudioManager; | 42 import org.webrtc.voiceengine.WebRtcAudioManager; |
50 import org.webrtc.voiceengine.WebRtcAudioUtils; | 43 import org.webrtc.voiceengine.WebRtcAudioUtils; |
51 | 44 |
52 import java.io.File; | 45 import java.io.File; |
53 import java.io.IOException; | 46 import java.io.IOException; |
54 import java.util.Collections; | 47 import java.util.Collections; |
55 import java.util.EnumSet; | 48 import java.util.EnumSet; |
56 import java.util.LinkedList; | 49 import java.util.LinkedList; |
(...skipping 66 matching lines...) Loading... |
123 private MediaConstraints sdpMediaConstraints; | 116 private MediaConstraints sdpMediaConstraints; |
124 private PeerConnectionParameters peerConnectionParameters; | 117 private PeerConnectionParameters peerConnectionParameters; |
125 // Queued remote ICE candidates are consumed only after both local and | 118 // Queued remote ICE candidates are consumed only after both local and |
126 // remote descriptions are set. Similarly local ICE candidates are sent to | 119 // remote descriptions are set. Similarly local ICE candidates are sent to |
127 // remote peer after both local and remote description are set. | 120 // remote peer after both local and remote description are set. |
128 private LinkedList<IceCandidate> queuedRemoteCandidates; | 121 private LinkedList<IceCandidate> queuedRemoteCandidates; |
129 private PeerConnectionEvents events; | 122 private PeerConnectionEvents events; |
130 private boolean isInitiator; | 123 private boolean isInitiator; |
131 private SessionDescription localSdp; // either offer or answer SDP | 124 private SessionDescription localSdp; // either offer or answer SDP |
132 private MediaStream mediaStream; | 125 private MediaStream mediaStream; |
133 private int numberOfCameras; | |
134 private VideoCapturer videoCapturer; | 126 private VideoCapturer videoCapturer; |
135 // enableVideo is set to true if video should be rendered and sent. | 127 // enableVideo is set to true if video should be rendered and sent. |
136 private boolean renderVideo; | 128 private boolean renderVideo; |
137 private VideoTrack localVideoTrack; | 129 private VideoTrack localVideoTrack; |
138 private VideoTrack remoteVideoTrack; | 130 private VideoTrack remoteVideoTrack; |
139 private RtpSender localVideoSender; | 131 private RtpSender localVideoSender; |
140 // enableAudio is set to true if audio should be sent. | 132 // enableAudio is set to true if audio should be sent. |
141 private boolean enableAudio; | 133 private boolean enableAudio; |
142 private AudioTrack localAudioTrack; | 134 private AudioTrack localAudioTrack; |
143 | 135 |
(...skipping 265 matching lines...) Loading... |
409 // Enable DTLS for normal calls and disable for loopback calls. | 401 // Enable DTLS for normal calls and disable for loopback calls. |
410 if (peerConnectionParameters.loopback) { | 402 if (peerConnectionParameters.loopback) { |
411 pcConstraints.optional.add( | 403 pcConstraints.optional.add( |
412 new MediaConstraints.KeyValuePair(DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT,
"false")); | 404 new MediaConstraints.KeyValuePair(DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT,
"false")); |
413 } else { | 405 } else { |
414 pcConstraints.optional.add( | 406 pcConstraints.optional.add( |
415 new MediaConstraints.KeyValuePair(DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT,
"true")); | 407 new MediaConstraints.KeyValuePair(DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT,
"true")); |
416 } | 408 } |
417 | 409 |
418 // Check if there is a camera on device and disable video call if not. | 410 // Check if there is a camera on device and disable video call if not. |
419 numberOfCameras = CameraEnumerationAndroid.getDeviceCount(); | 411 if (videoCapturer == null) { |
420 if (numberOfCameras == 0) { | |
421 Log.w(TAG, "No camera on device. Switch to audio only call."); | 412 Log.w(TAG, "No camera on device. Switch to audio only call."); |
422 videoCallEnabled = false; | 413 videoCallEnabled = false; |
423 } | 414 } |
424 // Create video constraints if video call is enabled. | 415 // Create video constraints if video call is enabled. |
425 if (videoCallEnabled) { | 416 if (videoCallEnabled) { |
426 videoWidth = peerConnectionParameters.videoWidth; | 417 videoWidth = peerConnectionParameters.videoWidth; |
427 videoHeight = peerConnectionParameters.videoHeight; | 418 videoHeight = peerConnectionParameters.videoHeight; |
428 videoFps = peerConnectionParameters.videoFps; | 419 videoFps = peerConnectionParameters.videoFps; |
429 | 420 |
430 // If video resolution is not specified, default to HD. | 421 // If video resolution is not specified, default to HD. |
(...skipping 526 matching lines...) Loading... |
957 Log.d(TAG, "Add " + queuedRemoteCandidates.size() + " remote candidates"); | 948 Log.d(TAG, "Add " + queuedRemoteCandidates.size() + " remote candidates"); |
958 for (IceCandidate candidate : queuedRemoteCandidates) { | 949 for (IceCandidate candidate : queuedRemoteCandidates) { |
959 peerConnection.addIceCandidate(candidate); | 950 peerConnection.addIceCandidate(candidate); |
960 } | 951 } |
961 queuedRemoteCandidates = null; | 952 queuedRemoteCandidates = null; |
962 } | 953 } |
963 } | 954 } |
964 | 955 |
965 private void switchCameraInternal() { | 956 private void switchCameraInternal() { |
966 if (videoCapturer instanceof CameraVideoCapturer) { | 957 if (videoCapturer instanceof CameraVideoCapturer) { |
967 if (!videoCallEnabled || numberOfCameras < 2 || isError || videoCapturer =
= null) { | 958 if (!videoCallEnabled || isError || videoCapturer == null) { |
968 Log.e(TAG, "Failed to switch camera. Video: " + videoCallEnabled + ". Er
ror : " + isError | 959 Log.e(TAG, "Failed to switch camera. Video: " + videoCallEnabled + ". Er
ror : " + isError); |
969 + ". Number of cameras: " + numberOfCameras); | |
970 return; // No video is sent or only one camera is available or error hap
pened. | 960 return; // No video is sent or only one camera is available or error hap
pened. |
971 } | 961 } |
972 Log.d(TAG, "Switch camera"); | 962 Log.d(TAG, "Switch camera"); |
973 CameraVideoCapturer cameraVideoCapturer = (CameraVideoCapturer) videoCaptu
rer; | 963 CameraVideoCapturer cameraVideoCapturer = (CameraVideoCapturer) videoCaptu
rer; |
974 cameraVideoCapturer.switchCamera(null); | 964 cameraVideoCapturer.switchCamera(null); |
975 } else { | 965 } else { |
976 Log.d(TAG, "Will not switch camera, video caputurer is not a camera"); | 966 Log.d(TAG, "Will not switch camera, video caputurer is not a camera"); |
977 } | 967 } |
978 } | 968 } |
979 | 969 |
(...skipping 197 matching lines...) Loading... |
1177 public void onCreateFailure(final String error) { | 1167 public void onCreateFailure(final String error) { |
1178 reportError("createSDP error: " + error); | 1168 reportError("createSDP error: " + error); |
1179 } | 1169 } |
1180 | 1170 |
1181 @Override | 1171 @Override |
1182 public void onSetFailure(final String error) { | 1172 public void onSetFailure(final String error) { |
1183 reportError("setSDP error: " + error); | 1173 reportError("setSDP error: " + error); |
1184 } | 1174 } |
1185 } | 1175 } |
1186 } | 1176 } |
OLD | NEW |