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 11 matching lines...) Expand all Loading... | |
| 22 import org.webrtc.Camera1Enumerator; | 22 import org.webrtc.Camera1Enumerator; |
| 23 import org.webrtc.Camera2Enumerator; | 23 import org.webrtc.Camera2Enumerator; |
| 24 import org.webrtc.CameraEnumerationAndroid; | 24 import org.webrtc.CameraEnumerationAndroid; |
| 25 import org.webrtc.CameraEnumerator; | 25 import org.webrtc.CameraEnumerator; |
| 26 import org.webrtc.CameraVideoCapturer; | 26 import org.webrtc.CameraVideoCapturer; |
| 27 import org.webrtc.DataChannel; | 27 import org.webrtc.DataChannel; |
| 28 import org.webrtc.EglBase; | 28 import org.webrtc.EglBase; |
| 29 import org.webrtc.IceCandidate; | 29 import org.webrtc.IceCandidate; |
| 30 import org.webrtc.Logging; | 30 import org.webrtc.Logging; |
| 31 import org.webrtc.MediaConstraints; | 31 import org.webrtc.MediaConstraints; |
| 32 import org.webrtc.MediaConstraints.KeyValuePair; | |
| 33 import org.webrtc.MediaStream; | 32 import org.webrtc.MediaStream; |
| 34 import org.webrtc.PeerConnection; | 33 import org.webrtc.PeerConnection; |
| 35 import org.webrtc.PeerConnection.IceConnectionState; | 34 import org.webrtc.PeerConnection.IceConnectionState; |
| 36 import org.webrtc.PeerConnectionFactory; | 35 import org.webrtc.PeerConnectionFactory; |
| 36 import org.webrtc.RtpParameters; | |
| 37 import org.webrtc.RtpSender; | |
| 37 import org.webrtc.SdpObserver; | 38 import org.webrtc.SdpObserver; |
| 38 import org.webrtc.SessionDescription; | 39 import org.webrtc.SessionDescription; |
| 39 import org.webrtc.StatsObserver; | 40 import org.webrtc.StatsObserver; |
| 40 import org.webrtc.StatsReport; | 41 import org.webrtc.StatsReport; |
| 41 import org.webrtc.VideoCapturer; | 42 import org.webrtc.VideoCapturer; |
| 42 import org.webrtc.VideoRenderer; | 43 import org.webrtc.VideoRenderer; |
| 43 import org.webrtc.VideoSource; | 44 import org.webrtc.VideoSource; |
| 44 import org.webrtc.VideoTrack; | 45 import org.webrtc.VideoTrack; |
| 45 import org.webrtc.voiceengine.WebRtcAudioManager; | 46 import org.webrtc.voiceengine.WebRtcAudioManager; |
| 46 import org.webrtc.voiceengine.WebRtcAudioUtils; | 47 import org.webrtc.voiceengine.WebRtcAudioUtils; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 59 /** | 60 /** |
| 60 * Peer connection client implementation. | 61 * Peer connection client implementation. |
| 61 * | 62 * |
| 62 * <p>All public methods are routed to local looper thread. | 63 * <p>All public methods are routed to local looper thread. |
| 63 * All PeerConnectionEvents callbacks are invoked from the same looper thread. | 64 * All PeerConnectionEvents callbacks are invoked from the same looper thread. |
| 64 * This class is a singleton. | 65 * This class is a singleton. |
| 65 */ | 66 */ |
| 66 public class PeerConnectionClient { | 67 public class PeerConnectionClient { |
| 67 public static final String VIDEO_TRACK_ID = "ARDAMSv0"; | 68 public static final String VIDEO_TRACK_ID = "ARDAMSv0"; |
| 68 public static final String AUDIO_TRACK_ID = "ARDAMSa0"; | 69 public static final String AUDIO_TRACK_ID = "ARDAMSa0"; |
| 70 public static final String VIDEO_TRACK_TYPE = "video"; | |
| 69 private static final String TAG = "PCRTCClient"; | 71 private static final String TAG = "PCRTCClient"; |
| 70 private static final String VIDEO_CODEC_VP8 = "VP8"; | 72 private static final String VIDEO_CODEC_VP8 = "VP8"; |
| 71 private static final String VIDEO_CODEC_VP9 = "VP9"; | 73 private static final String VIDEO_CODEC_VP9 = "VP9"; |
| 72 private static final String VIDEO_CODEC_H264 = "H264"; | 74 private static final String VIDEO_CODEC_H264 = "H264"; |
| 73 private static final String AUDIO_CODEC_OPUS = "opus"; | 75 private static final String AUDIO_CODEC_OPUS = "opus"; |
| 74 private static final String AUDIO_CODEC_ISAC = "ISAC"; | 76 private static final String AUDIO_CODEC_ISAC = "ISAC"; |
| 75 private static final String VIDEO_CODEC_PARAM_START_BITRATE = | 77 private static final String VIDEO_CODEC_PARAM_START_BITRATE = |
| 76 "x-google-start-bitrate"; | 78 "x-google-start-bitrate"; |
| 77 private static final String AUDIO_CODEC_PARAM_BITRATE = "maxaveragebitrate"; | 79 private static final String AUDIO_CODEC_PARAM_BITRATE = "maxaveragebitrate"; |
| 78 private static final String AUDIO_ECHO_CANCELLATION_CONSTRAINT = "googEchoCanc ellation"; | 80 private static final String AUDIO_ECHO_CANCELLATION_CONSTRAINT = "googEchoCanc ellation"; |
| 79 private static final String AUDIO_AUTO_GAIN_CONTROL_CONSTRAINT= "googAutoGainC ontrol"; | 81 private static final String AUDIO_AUTO_GAIN_CONTROL_CONSTRAINT= "googAutoGainC ontrol"; |
| 80 private static final String AUDIO_HIGH_PASS_FILTER_CONSTRAINT = "googHighpass Filter"; | 82 private static final String AUDIO_HIGH_PASS_FILTER_CONSTRAINT = "googHighpass Filter"; |
| 81 private static final String AUDIO_NOISE_SUPPRESSION_CONSTRAINT = "googNoiseSup pression"; | 83 private static final String AUDIO_NOISE_SUPPRESSION_CONSTRAINT = "googNoiseSup pression"; |
| 82 private static final String AUDIO_LEVEL_CONTROL_CONSTRAINT = "levelControl"; | 84 private static final String AUDIO_LEVEL_CONTROL_CONSTRAINT = "levelControl"; |
| 83 private static final String MAX_VIDEO_WIDTH_CONSTRAINT = "maxWidth"; | |
| 84 private static final String MIN_VIDEO_WIDTH_CONSTRAINT = "minWidth"; | |
| 85 private static final String MAX_VIDEO_HEIGHT_CONSTRAINT = "maxHeight"; | |
| 86 private static final String MIN_VIDEO_HEIGHT_CONSTRAINT = "minHeight"; | |
| 87 private static final String MAX_VIDEO_FPS_CONSTRAINT = "maxFrameRate"; | |
| 88 private static final String MIN_VIDEO_FPS_CONSTRAINT = "minFrameRate"; | |
| 89 private static final String DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT = "DtlsSrtpKeyA greement"; | 85 private static final String DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT = "DtlsSrtpKeyA greement"; |
| 90 private static final int HD_VIDEO_WIDTH = 1280; | 86 private static final int HD_VIDEO_WIDTH = 1280; |
| 91 private static final int HD_VIDEO_HEIGHT = 720; | 87 private static final int HD_VIDEO_HEIGHT = 720; |
| 92 private static final int MAX_VIDEO_WIDTH = 1280; | 88 private static final int MAX_VIDEO_WIDTH = 1280; |
| 93 private static final int MAX_VIDEO_HEIGHT = 1280; | 89 private static final int MAX_VIDEO_HEIGHT = 1280; |
| 94 private static final int MAX_VIDEO_FPS = 30; | 90 private static final int MAX_VIDEO_FPS = 30; |
| 91 private static final int BPS_IN_KBPS = 1000; | |
| 95 | 92 |
| 96 private static final PeerConnectionClient instance = new PeerConnectionClient( ); | 93 private static final PeerConnectionClient instance = new PeerConnectionClient( ); |
| 97 private final PCObserver pcObserver = new PCObserver(); | 94 private final PCObserver pcObserver = new PCObserver(); |
| 98 private final SDPObserver sdpObserver = new SDPObserver(); | 95 private final SDPObserver sdpObserver = new SDPObserver(); |
| 99 private final ScheduledExecutorService executor; | 96 private final ScheduledExecutorService executor; |
| 100 | 97 |
| 101 private Context context; | 98 private Context context; |
| 102 private PeerConnectionFactory factory; | 99 private PeerConnectionFactory factory; |
| 103 private PeerConnection peerConnection; | 100 private PeerConnection peerConnection; |
| 104 PeerConnectionFactory.Options options = null; | 101 PeerConnectionFactory.Options options = null; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 128 private PeerConnectionEvents events; | 125 private PeerConnectionEvents events; |
| 129 private boolean isInitiator; | 126 private boolean isInitiator; |
| 130 private SessionDescription localSdp; // either offer or answer SDP | 127 private SessionDescription localSdp; // either offer or answer SDP |
| 131 private MediaStream mediaStream; | 128 private MediaStream mediaStream; |
| 132 private int numberOfCameras; | 129 private int numberOfCameras; |
| 133 private CameraVideoCapturer videoCapturer; | 130 private CameraVideoCapturer videoCapturer; |
| 134 // enableVideo is set to true if video should be rendered and sent. | 131 // enableVideo is set to true if video should be rendered and sent. |
| 135 private boolean renderVideo; | 132 private boolean renderVideo; |
| 136 private VideoTrack localVideoTrack; | 133 private VideoTrack localVideoTrack; |
| 137 private VideoTrack remoteVideoTrack; | 134 private VideoTrack remoteVideoTrack; |
| 135 private RtpSender localVideoSender; | |
| 138 // enableAudio is set to true if audio should be sent. | 136 // enableAudio is set to true if audio should be sent. |
| 139 private boolean enableAudio; | 137 private boolean enableAudio; |
| 140 private AudioTrack localAudioTrack; | 138 private AudioTrack localAudioTrack; |
| 141 | 139 |
| 142 /** | 140 /** |
| 143 * Peer connection parameters. | 141 * Peer connection parameters. |
| 144 */ | 142 */ |
| 145 public static class PeerConnectionParameters { | 143 public static class PeerConnectionParameters { |
| 146 public final boolean videoCallEnabled; | 144 public final boolean videoCallEnabled; |
| 147 public final boolean loopback; | 145 public final boolean loopback; |
| 148 public final boolean tracing; | 146 public final boolean tracing; |
| 149 public final boolean useCamera2; | 147 public final boolean useCamera2; |
| 150 public final int videoWidth; | 148 public final int videoWidth; |
| 151 public final int videoHeight; | 149 public final int videoHeight; |
| 152 public final int videoFps; | 150 public final int videoFps; |
| 153 public final int videoStartBitrate; | 151 public final int videoMaxBitrate; |
| 154 public final String videoCodec; | 152 public final String videoCodec; |
| 155 public final boolean videoCodecHwAcceleration; | 153 public final boolean videoCodecHwAcceleration; |
| 156 public final boolean captureToTexture; | 154 public final boolean captureToTexture; |
| 157 public final int audioStartBitrate; | 155 public final int audioStartBitrate; |
| 158 public final String audioCodec; | 156 public final String audioCodec; |
| 159 public final boolean noAudioProcessing; | 157 public final boolean noAudioProcessing; |
| 160 public final boolean aecDump; | 158 public final boolean aecDump; |
| 161 public final boolean useOpenSLES; | 159 public final boolean useOpenSLES; |
| 162 public final boolean disableBuiltInAEC; | 160 public final boolean disableBuiltInAEC; |
| 163 public final boolean disableBuiltInAGC; | 161 public final boolean disableBuiltInAGC; |
| 164 public final boolean disableBuiltInNS; | 162 public final boolean disableBuiltInNS; |
| 165 public final boolean enableLevelControl; | 163 public final boolean enableLevelControl; |
| 166 | 164 |
| 167 public PeerConnectionParameters( | 165 public PeerConnectionParameters( |
| 168 boolean videoCallEnabled, boolean loopback, boolean tracing, boolean use Camera2, | 166 boolean videoCallEnabled, boolean loopback, boolean tracing, boolean use Camera2, |
| 169 int videoWidth, int videoHeight, int videoFps, | 167 int videoWidth, int videoHeight, int videoFps, |
| 170 int videoStartBitrate, String videoCodec, boolean videoCodecHwAccelerati on, | 168 int videoMaxBitrate, String videoCodec, boolean videoCodecHwAcceleration , |
| 171 boolean captureToTexture, int audioStartBitrate, String audioCodec, | 169 boolean captureToTexture, int audioStartBitrate, String audioCodec, |
| 172 boolean noAudioProcessing, boolean aecDump, boolean useOpenSLES, | 170 boolean noAudioProcessing, boolean aecDump, boolean useOpenSLES, |
| 173 boolean disableBuiltInAEC, boolean disableBuiltInAGC, boolean disableBui ltInNS, | 171 boolean disableBuiltInAEC, boolean disableBuiltInAGC, boolean disableBui ltInNS, |
| 174 boolean enableLevelControl) { | 172 boolean enableLevelControl) { |
| 175 this.videoCallEnabled = videoCallEnabled; | 173 this.videoCallEnabled = videoCallEnabled; |
| 176 this.useCamera2 = useCamera2; | 174 this.useCamera2 = useCamera2; |
| 177 this.loopback = loopback; | 175 this.loopback = loopback; |
| 178 this.tracing = tracing; | 176 this.tracing = tracing; |
| 179 this.videoWidth = videoWidth; | 177 this.videoWidth = videoWidth; |
| 180 this.videoHeight = videoHeight; | 178 this.videoHeight = videoHeight; |
| 181 this.videoFps = videoFps; | 179 this.videoFps = videoFps; |
| 182 this.videoStartBitrate = videoStartBitrate; | 180 this.videoMaxBitrate = videoMaxBitrate; |
| 183 this.videoCodec = videoCodec; | 181 this.videoCodec = videoCodec; |
| 184 this.videoCodecHwAcceleration = videoCodecHwAcceleration; | 182 this.videoCodecHwAcceleration = videoCodecHwAcceleration; |
| 185 this.captureToTexture = captureToTexture; | 183 this.captureToTexture = captureToTexture; |
| 186 this.audioStartBitrate = audioStartBitrate; | 184 this.audioStartBitrate = audioStartBitrate; |
| 187 this.audioCodec = audioCodec; | 185 this.audioCodec = audioCodec; |
| 188 this.noAudioProcessing = noAudioProcessing; | 186 this.noAudioProcessing = noAudioProcessing; |
| 189 this.aecDump = aecDump; | 187 this.aecDump = aecDump; |
| 190 this.useOpenSLES = useOpenSLES; | 188 this.useOpenSLES = useOpenSLES; |
| 191 this.disableBuiltInAEC = disableBuiltInAEC; | 189 this.disableBuiltInAEC = disableBuiltInAEC; |
| 192 this.disableBuiltInAGC = disableBuiltInAGC; | 190 this.disableBuiltInAGC = disableBuiltInAGC; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 preferIsac = false; | 269 preferIsac = false; |
| 272 videoCapturerStopped = false; | 270 videoCapturerStopped = false; |
| 273 isError = false; | 271 isError = false; |
| 274 queuedRemoteCandidates = null; | 272 queuedRemoteCandidates = null; |
| 275 localSdp = null; // either offer or answer SDP | 273 localSdp = null; // either offer or answer SDP |
| 276 mediaStream = null; | 274 mediaStream = null; |
| 277 videoCapturer = null; | 275 videoCapturer = null; |
| 278 renderVideo = true; | 276 renderVideo = true; |
| 279 localVideoTrack = null; | 277 localVideoTrack = null; |
| 280 remoteVideoTrack = null; | 278 remoteVideoTrack = null; |
| 279 localVideoSender = null; | |
| 281 enableAudio = true; | 280 enableAudio = true; |
| 282 localAudioTrack = null; | 281 localAudioTrack = null; |
| 283 statsTimer = new Timer(); | 282 statsTimer = new Timer(); |
| 284 | 283 |
| 285 executor.execute(new Runnable() { | 284 executor.execute(new Runnable() { |
| 286 @Override | 285 @Override |
| 287 public void run() { | 286 public void run() { |
| 288 createPeerConnectionFactoryInternal(context); | 287 createPeerConnectionFactoryInternal(context); |
| 289 } | 288 } |
| 290 }); | 289 }); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 | 559 |
| 561 if (videoCapturer == null) { | 560 if (videoCapturer == null) { |
| 562 reportError("Failed to open camera"); | 561 reportError("Failed to open camera"); |
| 563 return; | 562 return; |
| 564 } | 563 } |
| 565 mediaStream.addTrack(createVideoTrack(videoCapturer)); | 564 mediaStream.addTrack(createVideoTrack(videoCapturer)); |
| 566 } | 565 } |
| 567 | 566 |
| 568 mediaStream.addTrack(createAudioTrack()); | 567 mediaStream.addTrack(createAudioTrack()); |
| 569 peerConnection.addStream(mediaStream); | 568 peerConnection.addStream(mediaStream); |
| 569 if (videoCallEnabled) { | |
| 570 findVideoSender(); | |
| 571 } | |
| 570 | 572 |
| 571 if (peerConnectionParameters.aecDump) { | 573 if (peerConnectionParameters.aecDump) { |
| 572 try { | 574 try { |
| 573 aecDumpFileDescriptor = ParcelFileDescriptor.open( | 575 aecDumpFileDescriptor = ParcelFileDescriptor.open( |
| 574 new File(Environment.getExternalStorageDirectory().getPath() | 576 new File(Environment.getExternalStorageDirectory().getPath() |
| 575 + File.separator | 577 + File.separator |
| 576 + "Download/audio.aecdump"), | 578 + "Download/audio.aecdump"), |
| 577 ParcelFileDescriptor.MODE_READ_WRITE | | 579 ParcelFileDescriptor.MODE_READ_WRITE | |
| 578 ParcelFileDescriptor.MODE_CREATE | | 580 ParcelFileDescriptor.MODE_CREATE | |
| 579 ParcelFileDescriptor.MODE_TRUNCATE); | 581 ParcelFileDescriptor.MODE_TRUNCATE); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 if (peerConnection == null || isError) { | 765 if (peerConnection == null || isError) { |
| 764 return; | 766 return; |
| 765 } | 767 } |
| 766 String sdpDescription = sdp.description; | 768 String sdpDescription = sdp.description; |
| 767 if (preferIsac) { | 769 if (preferIsac) { |
| 768 sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true); | 770 sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true); |
| 769 } | 771 } |
| 770 if (videoCallEnabled) { | 772 if (videoCallEnabled) { |
| 771 sdpDescription = preferCodec(sdpDescription, preferredVideoCodec, fals e); | 773 sdpDescription = preferCodec(sdpDescription, preferredVideoCodec, fals e); |
| 772 } | 774 } |
| 773 if (videoCallEnabled && peerConnectionParameters.videoStartBitrate > 0) { | |
| 774 sdpDescription = setStartBitrate(VIDEO_CODEC_VP8, true, | |
| 775 sdpDescription, peerConnectionParameters.videoStartBitrate); | |
| 776 sdpDescription = setStartBitrate(VIDEO_CODEC_VP9, true, | |
| 777 sdpDescription, peerConnectionParameters.videoStartBitrate); | |
| 778 sdpDescription = setStartBitrate(VIDEO_CODEC_H264, true, | |
| 779 sdpDescription, peerConnectionParameters.videoStartBitrate); | |
| 780 } | |
| 781 if (peerConnectionParameters.audioStartBitrate > 0) { | 775 if (peerConnectionParameters.audioStartBitrate > 0) { |
| 782 sdpDescription = setStartBitrate(AUDIO_CODEC_OPUS, false, | 776 sdpDescription = setStartBitrate(AUDIO_CODEC_OPUS, false, |
| 783 sdpDescription, peerConnectionParameters.audioStartBitrate); | 777 sdpDescription, peerConnectionParameters.audioStartBitrate); |
| 784 } | 778 } |
| 785 Log.d(TAG, "Set remote SDP."); | 779 Log.d(TAG, "Set remote SDP."); |
| 786 SessionDescription sdpRemote = new SessionDescription( | 780 SessionDescription sdpRemote = new SessionDescription( |
| 787 sdp.type, sdpDescription); | 781 sdp.type, sdpDescription); |
| 788 peerConnection.setRemoteDescription(sdpObserver, sdpRemote); | 782 peerConnection.setRemoteDescription(sdpObserver, sdpRemote); |
| 789 } | 783 } |
| 790 }); | 784 }); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 811 public void run() { | 805 public void run() { |
| 812 if (videoCapturer != null && videoCapturerStopped) { | 806 if (videoCapturer != null && videoCapturerStopped) { |
| 813 Log.d(TAG, "Restart video source."); | 807 Log.d(TAG, "Restart video source."); |
| 814 videoCapturer.startCapture(videoWidth, videoHeight, videoFps); | 808 videoCapturer.startCapture(videoWidth, videoHeight, videoFps); |
| 815 videoCapturerStopped = false; | 809 videoCapturerStopped = false; |
| 816 } | 810 } |
| 817 } | 811 } |
| 818 }); | 812 }); |
| 819 } | 813 } |
| 820 | 814 |
| 815 public void setVideoMaxBitrate(final Integer maxBitrateKbps) { | |
| 816 executor.execute(new Runnable() { | |
| 817 @Override | |
| 818 public void run() { | |
| 819 if (peerConnection == null || localVideoSender == null || isError) { | |
| 820 return; | |
| 821 } | |
| 822 Log.d(TAG, "Requested max video bitrate: " + maxBitrateKbps); | |
| 823 if (localVideoSender == null) { | |
| 824 Log.w(TAG, "Sender is not ready."); | |
| 825 return; | |
| 826 } | |
| 827 | |
| 828 RtpParameters parameters = localVideoSender.getParameters(); | |
| 829 if (parameters.encodings.size() == 0) { | |
| 830 Log.w(TAG, "RtpParameters are not ready."); | |
| 831 return; | |
| 832 } | |
| 833 | |
| 834 for (RtpParameters.Encoding encoding : parameters.encodings) { | |
| 835 // Null value means no limit. | |
| 836 encoding.maxBitrateBps = maxBitrateKbps == null | |
| 837 ? null | |
| 838 : maxBitrateKbps * BPS_IN_KBPS; | |
| 839 } | |
| 840 if (!localVideoSender.setParameters(parameters)) { | |
| 841 Log.e(TAG, "RtpSender.setParameters failed."); | |
| 842 } | |
| 843 Log.d(TAG, "Configured max video bitrate to: " + maxBitrateKbps); | |
| 844 } | |
| 845 }); | |
| 846 } | |
| 847 | |
| 821 private void reportError(final String errorMessage) { | 848 private void reportError(final String errorMessage) { |
| 822 Log.e(TAG, "Peerconnection error: " + errorMessage); | 849 Log.e(TAG, "Peerconnection error: " + errorMessage); |
| 823 executor.execute(new Runnable() { | 850 executor.execute(new Runnable() { |
| 824 @Override | 851 @Override |
| 825 public void run() { | 852 public void run() { |
| 826 if (!isError) { | 853 if (!isError) { |
| 827 events.onPeerConnectionError(errorMessage); | 854 events.onPeerConnectionError(errorMessage); |
| 828 isError = true; | 855 isError = true; |
| 829 } | 856 } |
| 830 } | 857 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 841 private VideoTrack createVideoTrack(VideoCapturer capturer) { | 868 private VideoTrack createVideoTrack(VideoCapturer capturer) { |
| 842 videoSource = factory.createVideoSource(capturer); | 869 videoSource = factory.createVideoSource(capturer); |
| 843 capturer.startCapture(videoWidth, videoHeight, videoFps); | 870 capturer.startCapture(videoWidth, videoHeight, videoFps); |
| 844 | 871 |
| 845 localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource); | 872 localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource); |
| 846 localVideoTrack.setEnabled(renderVideo); | 873 localVideoTrack.setEnabled(renderVideo); |
| 847 localVideoTrack.addRenderer(new VideoRenderer(localRender)); | 874 localVideoTrack.addRenderer(new VideoRenderer(localRender)); |
| 848 return localVideoTrack; | 875 return localVideoTrack; |
| 849 } | 876 } |
| 850 | 877 |
| 878 private void findVideoSender() { | |
| 879 for (RtpSender sender : peerConnection.getSenders()) { | |
| 880 if (sender.track() != null) { | |
| 881 String trackType = sender.track().kind(); | |
| 882 if (trackType.equals(VIDEO_TRACK_TYPE)) { | |
| 883 Log.d(TAG, "Found video sender."); | |
| 884 localVideoSender = sender; | |
| 885 } | |
|
wzh
2016/09/01 06:38:43
do you need an early return or a break here?
| |
| 886 } | |
| 887 } | |
| 888 } | |
| 889 | |
| 851 private static String setStartBitrate(String codec, boolean isVideoCodec, | 890 private static String setStartBitrate(String codec, boolean isVideoCodec, |
| 852 String sdpDescription, int bitrateKbps) { | 891 String sdpDescription, int bitrateKbps) { |
| 853 String[] lines = sdpDescription.split("\r\n"); | 892 String[] lines = sdpDescription.split("\r\n"); |
| 854 int rtpmapLineIndex = -1; | 893 int rtpmapLineIndex = -1; |
| 855 boolean sdpFormatUpdated = false; | 894 boolean sdpFormatUpdated = false; |
| 856 String codecRtpMap = null; | 895 String codecRtpMap = null; |
| 857 // Search for codec rtpmap in format | 896 // Search for codec rtpmap in format |
| 858 // a=rtpmap:<payload type> <encoding name>/<clock rate> [/<encoding paramete rs>] | 897 // a=rtpmap:<payload type> <encoding name>/<clock rate> [/<encoding paramete rs>] |
| 859 String regex = "^a=rtpmap:(\\d+) " + codec + "(/\\d+)+[\r]?$"; | 898 String regex = "^a=rtpmap:(\\d+) " + codec + "(/\\d+)+[\r]?$"; |
| 860 Pattern codecPattern = Pattern.compile(regex); | 899 Pattern codecPattern = Pattern.compile(regex); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1197 public void onCreateFailure(final String error) { | 1236 public void onCreateFailure(final String error) { |
| 1198 reportError("createSDP error: " + error); | 1237 reportError("createSDP error: " + error); |
| 1199 } | 1238 } |
| 1200 | 1239 |
| 1201 @Override | 1240 @Override |
| 1202 public void onSetFailure(final String error) { | 1241 public void onSetFailure(final String error) { |
| 1203 reportError("setSDP error: " + error); | 1242 reportError("setSDP error: " + error); |
| 1204 } | 1243 } |
| 1205 } | 1244 } |
| 1206 } | 1245 } |
| OLD | NEW |