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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 import org.webrtc.MediaConstraints; | 26 import org.webrtc.MediaConstraints; |
27 import org.webrtc.MediaConstraints.KeyValuePair; | 27 import org.webrtc.MediaConstraints.KeyValuePair; |
28 import org.webrtc.MediaStream; | 28 import org.webrtc.MediaStream; |
29 import org.webrtc.PeerConnection; | 29 import org.webrtc.PeerConnection; |
30 import org.webrtc.PeerConnection.IceConnectionState; | 30 import org.webrtc.PeerConnection.IceConnectionState; |
31 import org.webrtc.PeerConnectionFactory; | 31 import org.webrtc.PeerConnectionFactory; |
32 import org.webrtc.SdpObserver; | 32 import org.webrtc.SdpObserver; |
33 import org.webrtc.SessionDescription; | 33 import org.webrtc.SessionDescription; |
34 import org.webrtc.StatsObserver; | 34 import org.webrtc.StatsObserver; |
35 import org.webrtc.StatsReport; | 35 import org.webrtc.StatsReport; |
| 36 import org.webrtc.CameraVideoCapturer; |
| 37 import org.webrtc.VideoCapturer; |
36 import org.webrtc.VideoCapturerAndroid; | 38 import org.webrtc.VideoCapturerAndroid; |
| 39 import org.webrtc.VideoCapturerAndroid2; |
37 import org.webrtc.VideoRenderer; | 40 import org.webrtc.VideoRenderer; |
38 import org.webrtc.VideoSource; | 41 import org.webrtc.VideoSource; |
39 import org.webrtc.VideoTrack; | 42 import org.webrtc.VideoTrack; |
40 import org.webrtc.voiceengine.WebRtcAudioManager; | 43 import org.webrtc.voiceengine.WebRtcAudioManager; |
41 import org.webrtc.voiceengine.WebRtcAudioUtils; | 44 import org.webrtc.voiceengine.WebRtcAudioUtils; |
42 | 45 |
43 import java.io.File; | 46 import java.io.File; |
44 import java.io.IOException; | 47 import java.io.IOException; |
45 import java.util.EnumSet; | 48 import java.util.EnumSet; |
46 import java.util.LinkedList; | 49 import java.util.LinkedList; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 private static final int HD_VIDEO_HEIGHT = 720; | 89 private static final int HD_VIDEO_HEIGHT = 720; |
87 private static final int MAX_VIDEO_WIDTH = 1280; | 90 private static final int MAX_VIDEO_WIDTH = 1280; |
88 private static final int MAX_VIDEO_HEIGHT = 1280; | 91 private static final int MAX_VIDEO_HEIGHT = 1280; |
89 private static final int MAX_VIDEO_FPS = 30; | 92 private static final int MAX_VIDEO_FPS = 30; |
90 | 93 |
91 private static final PeerConnectionClient instance = new PeerConnectionClient(
); | 94 private static final PeerConnectionClient instance = new PeerConnectionClient(
); |
92 private final PCObserver pcObserver = new PCObserver(); | 95 private final PCObserver pcObserver = new PCObserver(); |
93 private final SDPObserver sdpObserver = new SDPObserver(); | 96 private final SDPObserver sdpObserver = new SDPObserver(); |
94 private final ScheduledExecutorService executor; | 97 private final ScheduledExecutorService executor; |
95 | 98 |
| 99 private Context context; |
96 private PeerConnectionFactory factory; | 100 private PeerConnectionFactory factory; |
97 private PeerConnection peerConnection; | 101 private PeerConnection peerConnection; |
98 PeerConnectionFactory.Options options = null; | 102 PeerConnectionFactory.Options options = null; |
99 private VideoSource videoSource; | 103 private VideoSource videoSource; |
100 private boolean videoCallEnabled; | 104 private boolean videoCallEnabled; |
101 private boolean preferIsac; | 105 private boolean preferIsac; |
102 private String preferredVideoCodec; | 106 private String preferredVideoCodec; |
103 private boolean videoSourceStopped; | 107 private boolean videoSourceStopped; |
104 private boolean isError; | 108 private boolean isError; |
105 private Timer statsTimer; | 109 private Timer statsTimer; |
106 private VideoRenderer.Callbacks localRender; | 110 private VideoRenderer.Callbacks localRender; |
107 private VideoRenderer.Callbacks remoteRender; | 111 private VideoRenderer.Callbacks remoteRender; |
108 private SignalingParameters signalingParameters; | 112 private SignalingParameters signalingParameters; |
109 private MediaConstraints pcConstraints; | 113 private MediaConstraints pcConstraints; |
110 private MediaConstraints videoConstraints; | 114 private MediaConstraints videoConstraints; |
111 private MediaConstraints audioConstraints; | 115 private MediaConstraints audioConstraints; |
112 private ParcelFileDescriptor aecDumpFileDescriptor; | 116 private ParcelFileDescriptor aecDumpFileDescriptor; |
113 private MediaConstraints sdpMediaConstraints; | 117 private MediaConstraints sdpMediaConstraints; |
114 private PeerConnectionParameters peerConnectionParameters; | 118 private PeerConnectionParameters peerConnectionParameters; |
115 // Queued remote ICE candidates are consumed only after both local and | 119 // Queued remote ICE candidates are consumed only after both local and |
116 // remote descriptions are set. Similarly local ICE candidates are sent to | 120 // remote descriptions are set. Similarly local ICE candidates are sent to |
117 // remote peer after both local and remote description are set. | 121 // remote peer after both local and remote description are set. |
118 private LinkedList<IceCandidate> queuedRemoteCandidates; | 122 private LinkedList<IceCandidate> queuedRemoteCandidates; |
119 private PeerConnectionEvents events; | 123 private PeerConnectionEvents events; |
120 private boolean isInitiator; | 124 private boolean isInitiator; |
121 private SessionDescription localSdp; // either offer or answer SDP | 125 private SessionDescription localSdp; // either offer or answer SDP |
122 private MediaStream mediaStream; | 126 private MediaStream mediaStream; |
123 private int numberOfCameras; | 127 private int numberOfCameras; |
124 private VideoCapturerAndroid videoCapturer; | 128 private CameraVideoCapturer videoCapturer; |
125 // enableVideo is set to true if video should be rendered and sent. | 129 // enableVideo is set to true if video should be rendered and sent. |
126 private boolean renderVideo; | 130 private boolean renderVideo; |
127 private VideoTrack localVideoTrack; | 131 private VideoTrack localVideoTrack; |
128 private VideoTrack remoteVideoTrack; | 132 private VideoTrack remoteVideoTrack; |
129 // enableAudio is set to true if audio should be sent. | 133 // enableAudio is set to true if audio should be sent. |
130 private boolean enableAudio; | 134 private boolean enableAudio; |
131 private AudioTrack localAudioTrack; | 135 private AudioTrack localAudioTrack; |
132 | 136 |
133 /** | 137 /** |
134 * Peer connection parameters. | 138 * Peer connection parameters. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 244 } |
241 | 245 |
242 public void createPeerConnectionFactory( | 246 public void createPeerConnectionFactory( |
243 final Context context, | 247 final Context context, |
244 final PeerConnectionParameters peerConnectionParameters, | 248 final PeerConnectionParameters peerConnectionParameters, |
245 final PeerConnectionEvents events) { | 249 final PeerConnectionEvents events) { |
246 this.peerConnectionParameters = peerConnectionParameters; | 250 this.peerConnectionParameters = peerConnectionParameters; |
247 this.events = events; | 251 this.events = events; |
248 videoCallEnabled = peerConnectionParameters.videoCallEnabled; | 252 videoCallEnabled = peerConnectionParameters.videoCallEnabled; |
249 // Reset variables to initial states. | 253 // Reset variables to initial states. |
| 254 this.context = null; |
250 factory = null; | 255 factory = null; |
251 peerConnection = null; | 256 peerConnection = null; |
252 preferIsac = false; | 257 preferIsac = false; |
253 videoSourceStopped = false; | 258 videoSourceStopped = false; |
254 isError = false; | 259 isError = false; |
255 queuedRemoteCandidates = null; | 260 queuedRemoteCandidates = null; |
256 localSdp = null; // either offer or answer SDP | 261 localSdp = null; // either offer or answer SDP |
257 mediaStream = null; | 262 mediaStream = null; |
258 videoCapturer = null; | 263 videoCapturer = null; |
259 renderVideo = true; | 264 renderVideo = true; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 357 } |
353 | 358 |
354 // Create peer connection factory. | 359 // Create peer connection factory. |
355 if (!PeerConnectionFactory.initializeAndroidGlobals(context, true, true, | 360 if (!PeerConnectionFactory.initializeAndroidGlobals(context, true, true, |
356 peerConnectionParameters.videoCodecHwAcceleration)) { | 361 peerConnectionParameters.videoCodecHwAcceleration)) { |
357 events.onPeerConnectionError("Failed to initializeAndroidGlobals"); | 362 events.onPeerConnectionError("Failed to initializeAndroidGlobals"); |
358 } | 363 } |
359 if (options != null) { | 364 if (options != null) { |
360 Log.d(TAG, "Factory networkIgnoreMask option: " + options.networkIgnoreMas
k); | 365 Log.d(TAG, "Factory networkIgnoreMask option: " + options.networkIgnoreMas
k); |
361 } | 366 } |
| 367 this.context = context; |
362 factory = new PeerConnectionFactory(options); | 368 factory = new PeerConnectionFactory(options); |
363 Log.d(TAG, "Peer connection factory created."); | 369 Log.d(TAG, "Peer connection factory created."); |
364 } | 370 } |
365 | 371 |
366 private void createMediaConstraintsInternal() { | 372 private void createMediaConstraintsInternal() { |
367 // Create peer connection constraints. | 373 // Create peer connection constraints. |
368 pcConstraints = new MediaConstraints(); | 374 pcConstraints = new MediaConstraints(); |
369 // Enable DTLS for normal calls and disable for loopback calls. | 375 // Enable DTLS for normal calls and disable for loopback calls. |
370 if (peerConnectionParameters.loopback) { | 376 if (peerConnectionParameters.loopback) { |
371 pcConstraints.optional.add( | 377 pcConstraints.optional.add( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 496 |
491 mediaStream = factory.createLocalMediaStream("ARDAMS"); | 497 mediaStream = factory.createLocalMediaStream("ARDAMS"); |
492 if (videoCallEnabled) { | 498 if (videoCallEnabled) { |
493 String cameraDeviceName = CameraEnumerationAndroid.getDeviceName(0); | 499 String cameraDeviceName = CameraEnumerationAndroid.getDeviceName(0); |
494 String frontCameraDeviceName = | 500 String frontCameraDeviceName = |
495 CameraEnumerationAndroid.getNameOfFrontFacingDevice(); | 501 CameraEnumerationAndroid.getNameOfFrontFacingDevice(); |
496 if (numberOfCameras > 1 && frontCameraDeviceName != null) { | 502 if (numberOfCameras > 1 && frontCameraDeviceName != null) { |
497 cameraDeviceName = frontCameraDeviceName; | 503 cameraDeviceName = frontCameraDeviceName; |
498 } | 504 } |
499 Log.d(TAG, "Opening camera: " + cameraDeviceName); | 505 Log.d(TAG, "Opening camera: " + cameraDeviceName); |
500 videoCapturer = VideoCapturerAndroid.create(cameraDeviceName, null, | 506 videoCapturer = new VideoCapturerAndroid2(context, "1", null); |
501 peerConnectionParameters.captureToTexture); | |
502 if (videoCapturer == null) { | 507 if (videoCapturer == null) { |
503 reportError("Failed to open camera"); | 508 reportError("Failed to open camera"); |
504 return; | 509 return; |
505 } | 510 } |
506 mediaStream.addTrack(createVideoTrack(videoCapturer)); | 511 mediaStream.addTrack(createVideoTrack(videoCapturer)); |
507 } | 512 } |
508 | 513 |
509 mediaStream.addTrack(createAudioTrack()); | 514 mediaStream.addTrack(createAudioTrack()); |
510 peerConnection.addStream(mediaStream); | 515 peerConnection.addStream(mediaStream); |
511 | 516 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 } | 776 } |
772 | 777 |
773 private AudioTrack createAudioTrack() { | 778 private AudioTrack createAudioTrack() { |
774 localAudioTrack = factory.createAudioTrack( | 779 localAudioTrack = factory.createAudioTrack( |
775 AUDIO_TRACK_ID, | 780 AUDIO_TRACK_ID, |
776 factory.createAudioSource(audioConstraints)); | 781 factory.createAudioSource(audioConstraints)); |
777 localAudioTrack.setEnabled(enableAudio); | 782 localAudioTrack.setEnabled(enableAudio); |
778 return localAudioTrack; | 783 return localAudioTrack; |
779 } | 784 } |
780 | 785 |
781 private VideoTrack createVideoTrack(VideoCapturerAndroid capturer) { | 786 private VideoTrack createVideoTrack(VideoCapturer capturer) { |
782 videoSource = factory.createVideoSource(capturer, videoConstraints); | 787 videoSource = factory.createVideoSource(capturer, videoConstraints); |
783 | 788 |
784 localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource); | 789 localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource); |
785 localVideoTrack.setEnabled(renderVideo); | 790 localVideoTrack.setEnabled(renderVideo); |
786 localVideoTrack.addRenderer(new VideoRenderer(localRender)); | 791 localVideoTrack.addRenderer(new VideoRenderer(localRender)); |
787 return localVideoTrack; | 792 return localVideoTrack; |
788 } | 793 } |
789 | 794 |
790 private static String setStartBitrate(String codec, boolean isVideoCodec, | 795 private static String setStartBitrate(String codec, boolean isVideoCodec, |
791 String sdpDescription, int bitrateKbps) { | 796 String sdpDescription, int bitrateKbps) { |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 public void onCreateFailure(final String error) { | 1141 public void onCreateFailure(final String error) { |
1137 reportError("createSDP error: " + error); | 1142 reportError("createSDP error: " + error); |
1138 } | 1143 } |
1139 | 1144 |
1140 @Override | 1145 @Override |
1141 public void onSetFailure(final String error) { | 1146 public void onSetFailure(final String error) { |
1142 reportError("setSDP error: " + error); | 1147 reportError("setSDP error: " + error); |
1143 } | 1148 } |
1144 } | 1149 } |
1145 } | 1150 } |
OLD | NEW |