Chromium Code Reviews| 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 23 matching lines...) Expand all Loading... | |
| 34 import org.webrtc.PeerConnection.IceConnectionState; | 34 import org.webrtc.PeerConnection.IceConnectionState; |
| 35 import org.webrtc.PeerConnectionFactory; | 35 import org.webrtc.PeerConnectionFactory; |
| 36 import org.webrtc.RtpParameters; | 36 import org.webrtc.RtpParameters; |
| 37 import org.webrtc.RtpSender; | 37 import org.webrtc.RtpSender; |
| 38 import org.webrtc.SdpObserver; | 38 import org.webrtc.SdpObserver; |
| 39 import org.webrtc.SessionDescription; | 39 import org.webrtc.SessionDescription; |
| 40 import org.webrtc.StatsObserver; | 40 import org.webrtc.StatsObserver; |
| 41 import org.webrtc.StatsReport; | 41 import org.webrtc.StatsReport; |
| 42 import org.webrtc.VideoCapturer; | 42 import org.webrtc.VideoCapturer; |
| 43 import org.webrtc.VideoRenderer; | 43 import org.webrtc.VideoRenderer; |
| 44 import org.webrtc.VideoCapturerAndroid; | |
| 45 import org.webrtc.CameraVideoCapturer; | |
| 46 import org.webrtc.FileVideoCapturer; | |
| 44 import org.webrtc.VideoSource; | 47 import org.webrtc.VideoSource; |
| 45 import org.webrtc.VideoTrack; | 48 import org.webrtc.VideoTrack; |
| 46 import org.webrtc.voiceengine.WebRtcAudioManager; | 49 import org.webrtc.voiceengine.WebRtcAudioManager; |
| 47 import org.webrtc.voiceengine.WebRtcAudioUtils; | 50 import org.webrtc.voiceengine.WebRtcAudioUtils; |
| 48 | 51 |
| 49 import java.io.File; | 52 import java.io.File; |
| 50 import java.io.IOException; | 53 import java.io.IOException; |
| 54 import java.util.Collections; | |
| 51 import java.util.EnumSet; | 55 import java.util.EnumSet; |
| 52 import java.util.LinkedList; | 56 import java.util.LinkedList; |
| 57 import java.util.List; | |
| 53 import java.util.Timer; | 58 import java.util.Timer; |
| 54 import java.util.TimerTask; | 59 import java.util.TimerTask; |
| 55 import java.util.concurrent.Executors; | 60 import java.util.concurrent.Executors; |
| 56 import java.util.concurrent.ScheduledExecutorService; | 61 import java.util.concurrent.ScheduledExecutorService; |
| 57 import java.util.regex.Matcher; | 62 import java.util.regex.Matcher; |
| 58 import java.util.regex.Pattern; | 63 import java.util.regex.Pattern; |
| 59 | 64 |
| 60 /** | 65 /** |
| 61 * Peer connection client implementation. | 66 * Peer connection client implementation. |
| 62 * | 67 * |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 PeerConnectionFactory.Options options = null; | 106 PeerConnectionFactory.Options options = null; |
| 102 private AudioSource audioSource; | 107 private AudioSource audioSource; |
| 103 private VideoSource videoSource; | 108 private VideoSource videoSource; |
| 104 private boolean videoCallEnabled; | 109 private boolean videoCallEnabled; |
| 105 private boolean preferIsac; | 110 private boolean preferIsac; |
| 106 private String preferredVideoCodec; | 111 private String preferredVideoCodec; |
| 107 private boolean videoCapturerStopped; | 112 private boolean videoCapturerStopped; |
| 108 private boolean isError; | 113 private boolean isError; |
| 109 private Timer statsTimer; | 114 private Timer statsTimer; |
| 110 private VideoRenderer.Callbacks localRender; | 115 private VideoRenderer.Callbacks localRender; |
| 111 private VideoRenderer.Callbacks remoteRender; | 116 private List<VideoRenderer.Callbacks> remoteRenders; |
| 112 private SignalingParameters signalingParameters; | 117 private SignalingParameters signalingParameters; |
| 113 private MediaConstraints pcConstraints; | 118 private MediaConstraints pcConstraints; |
| 114 private int videoWidth; | 119 private int videoWidth; |
| 115 private int videoHeight; | 120 private int videoHeight; |
| 116 private int videoFps; | 121 private int videoFps; |
| 117 private MediaConstraints audioConstraints; | 122 private MediaConstraints audioConstraints; |
| 118 private ParcelFileDescriptor aecDumpFileDescriptor; | 123 private ParcelFileDescriptor aecDumpFileDescriptor; |
| 119 private MediaConstraints sdpMediaConstraints; | 124 private MediaConstraints sdpMediaConstraints; |
| 120 private PeerConnectionParameters peerConnectionParameters; | 125 private PeerConnectionParameters peerConnectionParameters; |
| 121 // Queued remote ICE candidates are consumed only after both local and | 126 // Queued remote ICE candidates are consumed only after both local and |
| 122 // remote descriptions are set. Similarly local ICE candidates are sent to | 127 // remote descriptions are set. Similarly local ICE candidates are sent to |
| 123 // remote peer after both local and remote description are set. | 128 // remote peer after both local and remote description are set. |
| 124 private LinkedList<IceCandidate> queuedRemoteCandidates; | 129 private LinkedList<IceCandidate> queuedRemoteCandidates; |
| 125 private PeerConnectionEvents events; | 130 private PeerConnectionEvents events; |
| 126 private boolean isInitiator; | 131 private boolean isInitiator; |
| 127 private SessionDescription localSdp; // either offer or answer SDP | 132 private SessionDescription localSdp; // either offer or answer SDP |
| 128 private MediaStream mediaStream; | 133 private MediaStream mediaStream; |
| 129 private int numberOfCameras; | 134 private int numberOfCameras; |
| 130 private CameraVideoCapturer videoCapturer; | 135 private VideoCapturer videoCapturer; |
| 131 // enableVideo is set to true if video should be rendered and sent. | 136 // enableVideo is set to true if video should be rendered and sent. |
| 132 private boolean renderVideo; | 137 private boolean renderVideo; |
| 133 private VideoTrack localVideoTrack; | 138 private VideoTrack localVideoTrack; |
| 134 private VideoTrack remoteVideoTrack; | 139 private VideoTrack remoteVideoTrack; |
| 135 private RtpSender localVideoSender; | 140 private RtpSender localVideoSender; |
| 136 // enableAudio is set to true if audio should be sent. | 141 // enableAudio is set to true if audio should be sent. |
| 137 private boolean enableAudio; | 142 private boolean enableAudio; |
| 138 private AudioTrack localAudioTrack; | 143 private AudioTrack localAudioTrack; |
| 139 | 144 |
| 140 /** | 145 /** |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 154 public final boolean captureToTexture; | 159 public final boolean captureToTexture; |
| 155 public final int audioStartBitrate; | 160 public final int audioStartBitrate; |
| 156 public final String audioCodec; | 161 public final String audioCodec; |
| 157 public final boolean noAudioProcessing; | 162 public final boolean noAudioProcessing; |
| 158 public final boolean aecDump; | 163 public final boolean aecDump; |
| 159 public final boolean useOpenSLES; | 164 public final boolean useOpenSLES; |
| 160 public final boolean disableBuiltInAEC; | 165 public final boolean disableBuiltInAEC; |
| 161 public final boolean disableBuiltInAGC; | 166 public final boolean disableBuiltInAGC; |
| 162 public final boolean disableBuiltInNS; | 167 public final boolean disableBuiltInNS; |
| 163 public final boolean enableLevelControl; | 168 public final boolean enableLevelControl; |
| 169 public final String videoFileAsCamera; | |
|
magjed_webrtc
2016/09/26 11:40:02
This doesn't really scale. We now have useCamera2,
kjellander_webrtc
2016/09/27 11:30:21
I think this can wait. This CL is adding new funct
| |
| 164 | 170 |
| 165 public PeerConnectionParameters( | 171 public PeerConnectionParameters( |
| 166 boolean videoCallEnabled, boolean loopback, boolean tracing, boolean use Camera2, | 172 boolean videoCallEnabled, boolean loopback, boolean tracing, boolean use Camera2, |
| 167 int videoWidth, int videoHeight, int videoFps, | 173 int videoWidth, int videoHeight, int videoFps, |
| 168 int videoMaxBitrate, String videoCodec, boolean videoCodecHwAcceleration , | 174 int videoMaxBitrate, String videoCodec, boolean videoCodecHwAcceleration , |
| 169 boolean captureToTexture, int audioStartBitrate, String audioCodec, | 175 boolean captureToTexture, int audioStartBitrate, String audioCodec, |
| 170 boolean noAudioProcessing, boolean aecDump, boolean useOpenSLES, | 176 boolean noAudioProcessing, boolean aecDump, boolean useOpenSLES, |
| 171 boolean disableBuiltInAEC, boolean disableBuiltInAGC, boolean disableBui ltInNS, | 177 boolean disableBuiltInAEC, boolean disableBuiltInAGC, boolean disableBui ltInNS, |
| 172 boolean enableLevelControl) { | 178 boolean enableLevelControl, |
| 179 String videoFileAsCamera) { | |
| 180 | |
| 173 this.videoCallEnabled = videoCallEnabled; | 181 this.videoCallEnabled = videoCallEnabled; |
| 174 this.useCamera2 = useCamera2; | 182 this.useCamera2 = useCamera2; |
| 175 this.loopback = loopback; | 183 this.loopback = loopback; |
| 176 this.tracing = tracing; | 184 this.tracing = tracing; |
| 177 this.videoWidth = videoWidth; | 185 this.videoWidth = videoWidth; |
| 178 this.videoHeight = videoHeight; | 186 this.videoHeight = videoHeight; |
| 179 this.videoFps = videoFps; | 187 this.videoFps = videoFps; |
| 180 this.videoMaxBitrate = videoMaxBitrate; | 188 this.videoMaxBitrate = videoMaxBitrate; |
| 181 this.videoCodec = videoCodec; | 189 this.videoCodec = videoCodec; |
| 182 this.videoCodecHwAcceleration = videoCodecHwAcceleration; | 190 this.videoCodecHwAcceleration = videoCodecHwAcceleration; |
| 183 this.captureToTexture = captureToTexture; | 191 this.captureToTexture = captureToTexture; |
| 184 this.audioStartBitrate = audioStartBitrate; | 192 this.audioStartBitrate = audioStartBitrate; |
| 185 this.audioCodec = audioCodec; | 193 this.audioCodec = audioCodec; |
| 186 this.noAudioProcessing = noAudioProcessing; | 194 this.noAudioProcessing = noAudioProcessing; |
| 187 this.aecDump = aecDump; | 195 this.aecDump = aecDump; |
| 188 this.useOpenSLES = useOpenSLES; | 196 this.useOpenSLES = useOpenSLES; |
| 189 this.disableBuiltInAEC = disableBuiltInAEC; | 197 this.disableBuiltInAEC = disableBuiltInAEC; |
| 190 this.disableBuiltInAGC = disableBuiltInAGC; | 198 this.disableBuiltInAGC = disableBuiltInAGC; |
| 191 this.disableBuiltInNS = disableBuiltInNS; | 199 this.disableBuiltInNS = disableBuiltInNS; |
| 192 this.enableLevelControl = enableLevelControl; | 200 this.enableLevelControl = enableLevelControl; |
| 201 this.videoFileAsCamera = videoFileAsCamera; | |
| 193 } | 202 } |
| 194 } | 203 } |
| 195 | 204 |
| 196 /** | 205 /** |
| 197 * Peer connection events. | 206 * Peer connection events. |
| 198 */ | 207 */ |
| 199 public interface PeerConnectionEvents { | 208 public interface PeerConnectionEvents { |
| 200 /** | 209 /** |
| 201 * Callback fired once local SDP is created and set. | 210 * Callback fired once local SDP is created and set. |
| 202 */ | 211 */ |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 createPeerConnectionFactoryInternal(context); | 296 createPeerConnectionFactoryInternal(context); |
| 288 } | 297 } |
| 289 }); | 298 }); |
| 290 } | 299 } |
| 291 | 300 |
| 292 public void createPeerConnection( | 301 public void createPeerConnection( |
| 293 final EglBase.Context renderEGLContext, | 302 final EglBase.Context renderEGLContext, |
| 294 final VideoRenderer.Callbacks localRender, | 303 final VideoRenderer.Callbacks localRender, |
| 295 final VideoRenderer.Callbacks remoteRender, | 304 final VideoRenderer.Callbacks remoteRender, |
| 296 final SignalingParameters signalingParameters) { | 305 final SignalingParameters signalingParameters) { |
| 306 createPeerConnection( | |
| 307 renderEGLContext, | |
| 308 localRender, | |
| 309 Collections.singletonList(remoteRender), | |
| 310 signalingParameters); | |
| 311 } | |
| 312 public void createPeerConnection( | |
| 313 final EglBase.Context renderEGLContext, | |
| 314 final VideoRenderer.Callbacks localRender, | |
| 315 final List<VideoRenderer.Callbacks> remoteRenders, | |
| 316 final SignalingParameters signalingParameters) { | |
| 297 if (peerConnectionParameters == null) { | 317 if (peerConnectionParameters == null) { |
| 298 Log.e(TAG, "Creating peer connection without initializing factory."); | 318 Log.e(TAG, "Creating peer connection without initializing factory."); |
| 299 return; | 319 return; |
| 300 } | 320 } |
| 301 this.localRender = localRender; | 321 this.localRender = localRender; |
| 302 this.remoteRender = remoteRender; | 322 this.remoteRenders = remoteRenders; |
| 303 this.signalingParameters = signalingParameters; | 323 this.signalingParameters = signalingParameters; |
| 304 executor.execute(new Runnable() { | 324 executor.execute(new Runnable() { |
| 305 @Override | 325 @Override |
| 306 public void run() { | 326 public void run() { |
| 307 try { | 327 try { |
| 308 createMediaConstraintsInternal(); | 328 createMediaConstraintsInternal(); |
| 309 createPeerConnectionInternal(renderEGLContext); | 329 createPeerConnectionInternal(renderEGLContext); |
| 310 } catch (Exception e) { | 330 } catch (Exception e) { |
| 311 reportError("Failed to create peer connection: " + e.getMessage()); | 331 reportError("Failed to create peer connection: " + e.getMessage()); |
| 312 throw e; | 332 throw e; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 537 | 557 |
| 538 // Set default WebRTC tracing and INFO libjingle logging. | 558 // Set default WebRTC tracing and INFO libjingle logging. |
| 539 // NOTE: this _must_ happen while |factory| is alive! | 559 // NOTE: this _must_ happen while |factory| is alive! |
| 540 Logging.enableTracing( | 560 Logging.enableTracing( |
| 541 "logcat:", | 561 "logcat:", |
| 542 EnumSet.of(Logging.TraceLevel.TRACE_DEFAULT)); | 562 EnumSet.of(Logging.TraceLevel.TRACE_DEFAULT)); |
| 543 Logging.enableLogToDebugOutput(Logging.Severity.LS_INFO); | 563 Logging.enableLogToDebugOutput(Logging.Severity.LS_INFO); |
| 544 | 564 |
| 545 mediaStream = factory.createLocalMediaStream("ARDAMS"); | 565 mediaStream = factory.createLocalMediaStream("ARDAMS"); |
| 546 if (videoCallEnabled) { | 566 if (videoCallEnabled) { |
| 547 if (peerConnectionParameters.useCamera2) { | 567 if (peerConnectionParameters.videoFileAsCamera != null) { |
| 568 videoCapturer = FileVideoCapturer.create( | |
| 569 peerConnectionParameters.videoFileAsCamera); | |
| 570 | |
| 571 if (videoCapturer == null) { | |
| 572 reportError("Failed to open video file for emulated camera"); | |
| 573 return; | |
| 574 } | |
| 575 } | |
| 576 else if (peerConnectionParameters.useCamera2) { | |
| 548 if (!peerConnectionParameters.captureToTexture) { | 577 if (!peerConnectionParameters.captureToTexture) { |
| 549 reportError(context.getString(R.string.camera2_texture_only_error)); | 578 reportError(context.getString(R.string.camera2_texture_only_error)); |
| 550 return; | 579 return; |
| 551 } | 580 } |
| 552 | 581 |
| 553 Logging.d(TAG, "Creating capturer using camera2 API."); | 582 Logging.d(TAG, "Creating capturer using camera2 API."); |
| 554 createCapturer(new Camera2Enumerator(context)); | 583 createCapturer(new Camera2Enumerator(context)); |
| 555 } else { | 584 } else { |
| 556 Logging.d(TAG, "Creating capturer using camera1 API."); | 585 Logging.d(TAG, "Creating capturer using camera1 API."); |
| 557 createCapturer(new Camera1Enumerator(peerConnectionParameters.captureToT exture)); | 586 createCapturer(new Camera1Enumerator(peerConnectionParameters.captureToT exture)); |
| 558 } | 587 } |
| 559 | |
| 560 if (videoCapturer == null) { | 588 if (videoCapturer == null) { |
| 561 reportError("Failed to open camera"); | 589 reportError("Failed to open camera"); |
| 562 return; | 590 return; |
| 563 } | 591 } |
| 564 mediaStream.addTrack(createVideoTrack(videoCapturer)); | 592 mediaStream.addTrack(createVideoTrack(videoCapturer)); |
| 565 } | 593 } |
| 566 | 594 |
| 567 mediaStream.addTrack(createAudioTrack()); | 595 mediaStream.addTrack(createAudioTrack()); |
| 568 peerConnection.addStream(mediaStream); | 596 peerConnection.addStream(mediaStream); |
| 569 if (videoCallEnabled) { | 597 if (videoCallEnabled) { |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 } | 1051 } |
| 1024 } | 1052 } |
| 1025 | 1053 |
| 1026 private void switchCameraInternal() { | 1054 private void switchCameraInternal() { |
| 1027 if (!videoCallEnabled || numberOfCameras < 2 || isError || videoCapturer == null) { | 1055 if (!videoCallEnabled || numberOfCameras < 2 || isError || videoCapturer == null) { |
| 1028 Log.e(TAG, "Failed to switch camera. Video: " + videoCallEnabled + ". Erro r : " | 1056 Log.e(TAG, "Failed to switch camera. Video: " + videoCallEnabled + ". Erro r : " |
| 1029 + isError + ". Number of cameras: " + numberOfCameras); | 1057 + isError + ". Number of cameras: " + numberOfCameras); |
| 1030 return; // No video is sent or only one camera is available or error happ ened. | 1058 return; // No video is sent or only one camera is available or error happ ened. |
| 1031 } | 1059 } |
| 1032 Log.d(TAG, "Switch camera"); | 1060 Log.d(TAG, "Switch camera"); |
| 1033 videoCapturer.switchCamera(null); | 1061 if (videoCapturer instanceof CameraVideoCapturer) { |
|
magjed_webrtc
2016/09/26 11:40:02
Maybe you should log when this is not the case. Ma
| |
| 1062 CameraVideoCapturer cameraVideoCapturer = (CameraVideoCapturer)videoCaptur er; | |
| 1063 cameraVideoCapturer.switchCamera(null); | |
| 1064 } | |
| 1034 } | 1065 } |
| 1035 | 1066 |
| 1036 public void switchCamera() { | 1067 public void switchCamera() { |
| 1037 executor.execute(new Runnable() { | 1068 executor.execute(new Runnable() { |
| 1038 @Override | 1069 @Override |
| 1039 public void run() { | 1070 public void run() { |
| 1040 switchCameraInternal(); | 1071 switchCameraInternal(); |
| 1041 } | 1072 } |
| 1042 }); | 1073 }); |
| 1043 } | 1074 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1126 if (peerConnection == null || isError) { | 1157 if (peerConnection == null || isError) { |
| 1127 return; | 1158 return; |
| 1128 } | 1159 } |
| 1129 if (stream.audioTracks.size() > 1 || stream.videoTracks.size() > 1) { | 1160 if (stream.audioTracks.size() > 1 || stream.videoTracks.size() > 1) { |
| 1130 reportError("Weird-looking stream: " + stream); | 1161 reportError("Weird-looking stream: " + stream); |
| 1131 return; | 1162 return; |
| 1132 } | 1163 } |
| 1133 if (stream.videoTracks.size() == 1) { | 1164 if (stream.videoTracks.size() == 1) { |
| 1134 remoteVideoTrack = stream.videoTracks.get(0); | 1165 remoteVideoTrack = stream.videoTracks.get(0); |
| 1135 remoteVideoTrack.setEnabled(renderVideo); | 1166 remoteVideoTrack.setEnabled(renderVideo); |
| 1136 remoteVideoTrack.addRenderer(new VideoRenderer(remoteRender)); | 1167 for (VideoRenderer.Callbacks remoteRender : remoteRenders) { |
| 1168 remoteVideoTrack.addRenderer(new VideoRenderer(remoteRender)); | |
| 1169 } | |
| 1137 } | 1170 } |
| 1138 } | 1171 } |
| 1139 }); | 1172 }); |
| 1140 } | 1173 } |
| 1141 | 1174 |
| 1142 @Override | 1175 @Override |
| 1143 public void onRemoveStream(final MediaStream stream){ | 1176 public void onRemoveStream(final MediaStream stream){ |
| 1144 executor.execute(new Runnable() { | 1177 executor.execute(new Runnable() { |
| 1145 @Override | 1178 @Override |
| 1146 public void run() { | 1179 public void run() { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1236 public void onCreateFailure(final String error) { | 1269 public void onCreateFailure(final String error) { |
| 1237 reportError("createSDP error: " + error); | 1270 reportError("createSDP error: " + error); |
| 1238 } | 1271 } |
| 1239 | 1272 |
| 1240 @Override | 1273 @Override |
| 1241 public void onSetFailure(final String error) { | 1274 public void onSetFailure(final String error) { |
| 1242 reportError("setSDP error: " + error); | 1275 reportError("setSDP error: " + error); |
| 1243 } | 1276 } |
| 1244 } | 1277 } |
| 1245 } | 1278 } |
| OLD | NEW |