| 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; | 
|  | 47 import org.webrtc.FileVideoCapturerTimer; | 
| 44 import org.webrtc.VideoSource; | 48 import org.webrtc.VideoSource; | 
| 45 import org.webrtc.VideoTrack; | 49 import org.webrtc.VideoTrack; | 
| 46 import org.webrtc.voiceengine.WebRtcAudioManager; | 50 import org.webrtc.voiceengine.WebRtcAudioManager; | 
| 47 import org.webrtc.voiceengine.WebRtcAudioUtils; | 51 import org.webrtc.voiceengine.WebRtcAudioUtils; | 
| 48 | 52 | 
| 49 import java.io.File; | 53 import java.io.File; | 
| 50 import java.io.IOException; | 54 import java.io.IOException; | 
|  | 55 import java.util.Collections; | 
| 51 import java.util.EnumSet; | 56 import java.util.EnumSet; | 
| 52 import java.util.LinkedList; | 57 import java.util.LinkedList; | 
|  | 58 import java.util.List; | 
| 53 import java.util.Timer; | 59 import java.util.Timer; | 
| 54 import java.util.TimerTask; | 60 import java.util.TimerTask; | 
| 55 import java.util.concurrent.Executors; | 61 import java.util.concurrent.Executors; | 
| 56 import java.util.concurrent.ScheduledExecutorService; | 62 import java.util.concurrent.ScheduledExecutorService; | 
| 57 import java.util.regex.Matcher; | 63 import java.util.regex.Matcher; | 
| 58 import java.util.regex.Pattern; | 64 import java.util.regex.Pattern; | 
| 59 | 65 | 
| 60 /** | 66 /** | 
| 61  * Peer connection client implementation. | 67  * Peer connection client implementation. | 
| 62  * | 68  * | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 101   PeerConnectionFactory.Options options = null; | 107   PeerConnectionFactory.Options options = null; | 
| 102   private AudioSource audioSource; | 108   private AudioSource audioSource; | 
| 103   private VideoSource videoSource; | 109   private VideoSource videoSource; | 
| 104   private boolean videoCallEnabled; | 110   private boolean videoCallEnabled; | 
| 105   private boolean preferIsac; | 111   private boolean preferIsac; | 
| 106   private String preferredVideoCodec; | 112   private String preferredVideoCodec; | 
| 107   private boolean videoCapturerStopped; | 113   private boolean videoCapturerStopped; | 
| 108   private boolean isError; | 114   private boolean isError; | 
| 109   private Timer statsTimer; | 115   private Timer statsTimer; | 
| 110   private VideoRenderer.Callbacks localRender; | 116   private VideoRenderer.Callbacks localRender; | 
| 111   private VideoRenderer.Callbacks remoteRender; | 117   private List<VideoRenderer.Callbacks> remoteRenders; | 
| 112   private SignalingParameters signalingParameters; | 118   private SignalingParameters signalingParameters; | 
| 113   private MediaConstraints pcConstraints; | 119   private MediaConstraints pcConstraints; | 
| 114   private int videoWidth; | 120   private int videoWidth; | 
| 115   private int videoHeight; | 121   private int videoHeight; | 
| 116   private int videoFps; | 122   private int videoFps; | 
| 117   private MediaConstraints audioConstraints; | 123   private MediaConstraints audioConstraints; | 
| 118   private ParcelFileDescriptor aecDumpFileDescriptor; | 124   private ParcelFileDescriptor aecDumpFileDescriptor; | 
| 119   private MediaConstraints sdpMediaConstraints; | 125   private MediaConstraints sdpMediaConstraints; | 
| 120   private PeerConnectionParameters peerConnectionParameters; | 126   private PeerConnectionParameters peerConnectionParameters; | 
| 121   // Queued remote ICE candidates are consumed only after both local and | 127   // Queued remote ICE candidates are consumed only after both local and | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 154     public final boolean captureToTexture; | 160     public final boolean captureToTexture; | 
| 155     public final int audioStartBitrate; | 161     public final int audioStartBitrate; | 
| 156     public final String audioCodec; | 162     public final String audioCodec; | 
| 157     public final boolean noAudioProcessing; | 163     public final boolean noAudioProcessing; | 
| 158     public final boolean aecDump; | 164     public final boolean aecDump; | 
| 159     public final boolean useOpenSLES; | 165     public final boolean useOpenSLES; | 
| 160     public final boolean disableBuiltInAEC; | 166     public final boolean disableBuiltInAEC; | 
| 161     public final boolean disableBuiltInAGC; | 167     public final boolean disableBuiltInAGC; | 
| 162     public final boolean disableBuiltInNS; | 168     public final boolean disableBuiltInNS; | 
| 163     public final boolean enableLevelControl; | 169     public final boolean enableLevelControl; | 
|  | 170     public final String videoFileAsCamera; | 
|  | 171     public final int videoFileAsCameraWidth; | 
|  | 172     public final int videoFileAsCameraHeight; | 
| 164 | 173 | 
| 165     public PeerConnectionParameters( | 174     public PeerConnectionParameters( | 
| 166         boolean videoCallEnabled, boolean loopback, boolean tracing, boolean use
      Camera2, | 175         boolean videoCallEnabled, boolean loopback, boolean tracing, boolean use
      Camera2, | 
| 167         int videoWidth, int videoHeight, int videoFps, | 176         int videoWidth, int videoHeight, int videoFps, | 
| 168         int videoMaxBitrate, String videoCodec, boolean videoCodecHwAcceleration
      , | 177         int videoMaxBitrate, String videoCodec, boolean videoCodecHwAcceleration
      , | 
| 169         boolean captureToTexture, int audioStartBitrate, String audioCodec, | 178         boolean captureToTexture, int audioStartBitrate, String audioCodec, | 
| 170         boolean noAudioProcessing, boolean aecDump, boolean useOpenSLES, | 179         boolean noAudioProcessing, boolean aecDump, boolean useOpenSLES, | 
| 171         boolean disableBuiltInAEC, boolean disableBuiltInAGC, boolean disableBui
      ltInNS, | 180         boolean disableBuiltInAEC, boolean disableBuiltInAGC, boolean disableBui
      ltInNS, | 
| 172         boolean enableLevelControl) { | 181         boolean enableLevelControl, | 
|  | 182         String videoFileAsCamera, int videoFileAsCameraWidth, int videoFileAsCam
      eraHeight) { | 
|  | 183 | 
| 173       this.videoCallEnabled = videoCallEnabled; | 184       this.videoCallEnabled = videoCallEnabled; | 
| 174       this.useCamera2 = useCamera2; | 185       this.useCamera2 = useCamera2; | 
| 175       this.loopback = loopback; | 186       this.loopback = loopback; | 
| 176       this.tracing = tracing; | 187       this.tracing = tracing; | 
| 177       this.videoWidth = videoWidth; | 188       this.videoWidth = videoWidth; | 
| 178       this.videoHeight = videoHeight; | 189       this.videoHeight = videoHeight; | 
| 179       this.videoFps = videoFps; | 190       this.videoFps = videoFps; | 
| 180       this.videoMaxBitrate = videoMaxBitrate; | 191       this.videoMaxBitrate = videoMaxBitrate; | 
| 181       this.videoCodec = videoCodec; | 192       this.videoCodec = videoCodec; | 
| 182       this.videoCodecHwAcceleration = videoCodecHwAcceleration; | 193       this.videoCodecHwAcceleration = videoCodecHwAcceleration; | 
| 183       this.captureToTexture = captureToTexture; | 194       this.captureToTexture = captureToTexture; | 
| 184       this.audioStartBitrate = audioStartBitrate; | 195       this.audioStartBitrate = audioStartBitrate; | 
| 185       this.audioCodec = audioCodec; | 196       this.audioCodec = audioCodec; | 
| 186       this.noAudioProcessing = noAudioProcessing; | 197       this.noAudioProcessing = noAudioProcessing; | 
| 187       this.aecDump = aecDump; | 198       this.aecDump = aecDump; | 
| 188       this.useOpenSLES = useOpenSLES; | 199       this.useOpenSLES = useOpenSLES; | 
| 189       this.disableBuiltInAEC = disableBuiltInAEC; | 200       this.disableBuiltInAEC = disableBuiltInAEC; | 
| 190       this.disableBuiltInAGC = disableBuiltInAGC; | 201       this.disableBuiltInAGC = disableBuiltInAGC; | 
| 191       this.disableBuiltInNS = disableBuiltInNS; | 202       this.disableBuiltInNS = disableBuiltInNS; | 
| 192       this.enableLevelControl = enableLevelControl; | 203       this.enableLevelControl = enableLevelControl; | 
|  | 204       this.videoFileAsCamera = videoFileAsCamera; | 
|  | 205       this.videoFileAsCameraWidth = videoFileAsCameraWidth; | 
|  | 206       this.videoFileAsCameraHeight = videoFileAsCameraHeight; | 
| 193     } | 207     } | 
| 194   } | 208   } | 
| 195 | 209 | 
| 196   /** | 210   /** | 
| 197    * Peer connection events. | 211    * Peer connection events. | 
| 198    */ | 212    */ | 
| 199   public interface PeerConnectionEvents { | 213   public interface PeerConnectionEvents { | 
| 200     /** | 214     /** | 
| 201      * Callback fired once local SDP is created and set. | 215      * Callback fired once local SDP is created and set. | 
| 202      */ | 216      */ | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 287         createPeerConnectionFactoryInternal(context); | 301         createPeerConnectionFactoryInternal(context); | 
| 288       } | 302       } | 
| 289     }); | 303     }); | 
| 290   } | 304   } | 
| 291 | 305 | 
| 292   public void createPeerConnection( | 306   public void createPeerConnection( | 
| 293       final EglBase.Context renderEGLContext, | 307       final EglBase.Context renderEGLContext, | 
| 294       final VideoRenderer.Callbacks localRender, | 308       final VideoRenderer.Callbacks localRender, | 
| 295       final VideoRenderer.Callbacks remoteRender, | 309       final VideoRenderer.Callbacks remoteRender, | 
| 296       final SignalingParameters signalingParameters) { | 310       final SignalingParameters signalingParameters) { | 
|  | 311     createPeerConnection( | 
|  | 312         renderEGLContext, | 
|  | 313         localRender, | 
|  | 314         Collections.singletonList(remoteRender), | 
|  | 315         signalingParameters); | 
|  | 316   } | 
|  | 317   public void createPeerConnection( | 
|  | 318       final EglBase.Context renderEGLContext, | 
|  | 319       final VideoRenderer.Callbacks localRender, | 
|  | 320       final List<VideoRenderer.Callbacks> remoteRenders, | 
|  | 321       final SignalingParameters signalingParameters) { | 
| 297     if (peerConnectionParameters == null) { | 322     if (peerConnectionParameters == null) { | 
| 298       Log.e(TAG, "Creating peer connection without initializing factory."); | 323       Log.e(TAG, "Creating peer connection without initializing factory."); | 
| 299       return; | 324       return; | 
| 300     } | 325     } | 
| 301     this.localRender = localRender; | 326     this.localRender = localRender; | 
| 302     this.remoteRender = remoteRender; | 327     this.remoteRenders = remoteRenders; | 
| 303     this.signalingParameters = signalingParameters; | 328     this.signalingParameters = signalingParameters; | 
| 304     executor.execute(new Runnable() { | 329     executor.execute(new Runnable() { | 
| 305       @Override | 330       @Override | 
| 306       public void run() { | 331       public void run() { | 
| 307         try { | 332         try { | 
| 308           createMediaConstraintsInternal(); | 333           createMediaConstraintsInternal(); | 
| 309           createPeerConnectionInternal(renderEGLContext); | 334           createPeerConnectionInternal(renderEGLContext); | 
| 310         } catch (Exception e) { | 335         } catch (Exception e) { | 
| 311           reportError("Failed to create peer connection: " + e.getMessage()); | 336           reportError("Failed to create peer connection: " + e.getMessage()); | 
| 312           throw e; | 337           throw e; | 
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 537 | 562 | 
| 538     // Set default WebRTC tracing and INFO libjingle logging. | 563     // Set default WebRTC tracing and INFO libjingle logging. | 
| 539     // NOTE: this _must_ happen while |factory| is alive! | 564     // NOTE: this _must_ happen while |factory| is alive! | 
| 540     Logging.enableTracing( | 565     Logging.enableTracing( | 
| 541         "logcat:", | 566         "logcat:", | 
| 542         EnumSet.of(Logging.TraceLevel.TRACE_DEFAULT)); | 567         EnumSet.of(Logging.TraceLevel.TRACE_DEFAULT)); | 
| 543     Logging.enableLogToDebugOutput(Logging.Severity.LS_INFO); | 568     Logging.enableLogToDebugOutput(Logging.Severity.LS_INFO); | 
| 544 | 569 | 
| 545     mediaStream = factory.createLocalMediaStream("ARDAMS"); | 570     mediaStream = factory.createLocalMediaStream("ARDAMS"); | 
| 546     if (videoCallEnabled) { | 571     if (videoCallEnabled) { | 
| 547       if (peerConnectionParameters.useCamera2) { | 572       if (peerConnectionParameters.videoFileAsCamera != null) { | 
|  | 573         FileVideoCapturer fileVideoCapturer = FileVideoCapturer.create( | 
|  | 574             peerConnectionParameters.videoFileAsCamera, | 
|  | 575             peerConnectionParameters.videoFileAsCameraWidth, | 
|  | 576             peerConnectionParameters.videoFileAsCameraHeight); | 
|  | 577 | 
|  | 578         if (fileVideoCapturer == null) { | 
|  | 579           reportError("Failed to open video file for emulated camera"); | 
|  | 580           return; | 
|  | 581         } | 
|  | 582         videoCapturer = new FileVideoCapturerTimer(fileVideoCapturer); | 
|  | 583       } | 
|  | 584       else if (peerConnectionParameters.useCamera2) { | 
| 548         if (!peerConnectionParameters.captureToTexture) { | 585         if (!peerConnectionParameters.captureToTexture) { | 
| 549           reportError(context.getString(R.string.camera2_texture_only_error)); | 586           reportError(context.getString(R.string.camera2_texture_only_error)); | 
| 550           return; | 587           return; | 
| 551         } | 588         } | 
| 552 | 589 | 
| 553         Logging.d(TAG, "Creating capturer using camera2 API."); | 590         Logging.d(TAG, "Creating capturer using camera2 API."); | 
| 554         createCapturer(new Camera2Enumerator(context)); | 591         createCapturer(new Camera2Enumerator(context)); | 
| 555       } else { | 592       } else { | 
| 556         Logging.d(TAG, "Creating capturer using camera1 API."); | 593         Logging.d(TAG, "Creating capturer using camera1 API."); | 
| 557         createCapturer(new Camera1Enumerator(peerConnectionParameters.captureToT
      exture)); | 594         createCapturer(new Camera1Enumerator(peerConnectionParameters.captureToT
      exture)); | 
| 558       } | 595       } | 
| 559 |  | 
| 560       if (videoCapturer == null) { | 596       if (videoCapturer == null) { | 
| 561         reportError("Failed to open camera"); | 597         reportError("Failed to open camera"); | 
| 562         return; | 598         return; | 
| 563       } | 599       } | 
| 564       mediaStream.addTrack(createVideoTrack(videoCapturer)); | 600       mediaStream.addTrack(createVideoTrack(videoCapturer)); | 
| 565     } | 601     } | 
| 566 | 602 | 
| 567     mediaStream.addTrack(createAudioTrack()); | 603     mediaStream.addTrack(createAudioTrack()); | 
| 568     peerConnection.addStream(mediaStream); | 604     peerConnection.addStream(mediaStream); | 
| 569     if (videoCallEnabled) { | 605     if (videoCallEnabled) { | 
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1126           if (peerConnection == null || isError) { | 1162           if (peerConnection == null || isError) { | 
| 1127             return; | 1163             return; | 
| 1128           } | 1164           } | 
| 1129           if (stream.audioTracks.size() > 1 || stream.videoTracks.size() > 1) { | 1165           if (stream.audioTracks.size() > 1 || stream.videoTracks.size() > 1) { | 
| 1130             reportError("Weird-looking stream: " + stream); | 1166             reportError("Weird-looking stream: " + stream); | 
| 1131             return; | 1167             return; | 
| 1132           } | 1168           } | 
| 1133           if (stream.videoTracks.size() == 1) { | 1169           if (stream.videoTracks.size() == 1) { | 
| 1134             remoteVideoTrack = stream.videoTracks.get(0); | 1170             remoteVideoTrack = stream.videoTracks.get(0); | 
| 1135             remoteVideoTrack.setEnabled(renderVideo); | 1171             remoteVideoTrack.setEnabled(renderVideo); | 
| 1136             remoteVideoTrack.addRenderer(new VideoRenderer(remoteRender)); | 1172             for (VideoRenderer.Callbacks remoteRender : remoteRenders) { | 
|  | 1173               remoteVideoTrack.addRenderer(new VideoRenderer(remoteRender)); | 
|  | 1174             } | 
| 1137           } | 1175           } | 
| 1138         } | 1176         } | 
| 1139       }); | 1177       }); | 
| 1140     } | 1178     } | 
| 1141 | 1179 | 
| 1142     @Override | 1180     @Override | 
| 1143     public void onRemoveStream(final MediaStream stream){ | 1181     public void onRemoveStream(final MediaStream stream){ | 
| 1144       executor.execute(new Runnable() { | 1182       executor.execute(new Runnable() { | 
| 1145         @Override | 1183         @Override | 
| 1146         public void run() { | 1184         public void run() { | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1236     public void onCreateFailure(final String error) { | 1274     public void onCreateFailure(final String error) { | 
| 1237       reportError("createSDP error: " + error); | 1275       reportError("createSDP error: " + error); | 
| 1238     } | 1276     } | 
| 1239 | 1277 | 
| 1240     @Override | 1278     @Override | 
| 1241     public void onSetFailure(final String error) { | 1279     public void onSetFailure(final String error) { | 
| 1242       reportError("setSDP error: " + error); | 1280       reportError("setSDP error: " + error); | 
| 1243     } | 1281     } | 
| 1244   } | 1282   } | 
| 1245 } | 1283 } | 
| OLD | NEW | 
|---|