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 android.content.Context; | 13 import android.content.Context; |
14 import android.os.ParcelFileDescriptor; | 14 import android.os.ParcelFileDescriptor; |
15 import android.os.Environment; | 15 import android.os.Environment; |
16 import android.util.Log; | 16 import android.util.Log; |
17 | 17 |
18 import org.appspot.apprtc.AppRTCClient.SignalingParameters; | 18 import org.appspot.apprtc.AppRTCClient.SignalingParameters; |
19 import org.appspot.apprtc.util.LooperExecutor; | |
20 import org.webrtc.AudioTrack; | 19 import org.webrtc.AudioTrack; |
21 import org.webrtc.CameraEnumerationAndroid; | 20 import org.webrtc.CameraEnumerationAndroid; |
22 import org.webrtc.DataChannel; | 21 import org.webrtc.DataChannel; |
23 import org.webrtc.EglBase; | 22 import org.webrtc.EglBase; |
24 import org.webrtc.IceCandidate; | 23 import org.webrtc.IceCandidate; |
25 import org.webrtc.Logging; | 24 import org.webrtc.Logging; |
26 import org.webrtc.MediaCodecVideoEncoder; | 25 import org.webrtc.MediaCodecVideoEncoder; |
27 import org.webrtc.MediaConstraints; | 26 import org.webrtc.MediaConstraints; |
28 import org.webrtc.MediaConstraints.KeyValuePair; | 27 import org.webrtc.MediaConstraints.KeyValuePair; |
29 import org.webrtc.MediaStream; | 28 import org.webrtc.MediaStream; |
30 import org.webrtc.PeerConnection; | 29 import org.webrtc.PeerConnection; |
31 import org.webrtc.PeerConnection.IceConnectionState; | 30 import org.webrtc.PeerConnection.IceConnectionState; |
32 import org.webrtc.PeerConnectionFactory; | 31 import org.webrtc.PeerConnectionFactory; |
33 import org.webrtc.SdpObserver; | 32 import org.webrtc.SdpObserver; |
34 import org.webrtc.SessionDescription; | 33 import org.webrtc.SessionDescription; |
35 import org.webrtc.StatsObserver; | 34 import org.webrtc.StatsObserver; |
36 import org.webrtc.StatsReport; | 35 import org.webrtc.StatsReport; |
37 import org.webrtc.VideoCapturerAndroid; | 36 import org.webrtc.VideoCapturerAndroid; |
38 import org.webrtc.VideoRenderer; | 37 import org.webrtc.VideoRenderer; |
39 import org.webrtc.VideoSource; | 38 import org.webrtc.VideoSource; |
40 import org.webrtc.VideoTrack; | 39 import org.webrtc.VideoTrack; |
41 import org.webrtc.voiceengine.WebRtcAudioManager; | 40 import org.webrtc.voiceengine.WebRtcAudioManager; |
42 | 41 |
43 import java.io.File; | 42 import java.io.File; |
44 import java.io.IOException; | 43 import java.io.IOException; |
45 import java.util.EnumSet; | 44 import java.util.EnumSet; |
46 import java.util.LinkedList; | 45 import java.util.LinkedList; |
47 import java.util.Timer; | 46 import java.util.Timer; |
48 import java.util.TimerTask; | 47 import java.util.TimerTask; |
| 48 import java.util.concurrent.ExecutorService; |
| 49 import java.util.concurrent.Executors; |
| 50 import java.util.concurrent.ScheduledExecutorService; |
49 import java.util.regex.Matcher; | 51 import java.util.regex.Matcher; |
50 import java.util.regex.Pattern; | 52 import java.util.regex.Pattern; |
51 | 53 |
52 /** | 54 /** |
53 * Peer connection client implementation. | 55 * Peer connection client implementation. |
54 * | 56 * |
55 * <p>All public methods are routed to local looper thread. | 57 * <p>All public methods are routed to local looper thread. |
56 * All PeerConnectionEvents callbacks are invoked from the same looper thread. | 58 * All PeerConnectionEvents callbacks are invoked from the same looper thread. |
57 * This class is a singleton. | 59 * This class is a singleton. |
58 */ | 60 */ |
(...skipping 22 matching lines...) Expand all Loading... |
81 private static final String DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT = "DtlsSrtpKeyA
greement"; | 83 private static final String DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT = "DtlsSrtpKeyA
greement"; |
82 private static final int HD_VIDEO_WIDTH = 1280; | 84 private static final int HD_VIDEO_WIDTH = 1280; |
83 private static final int HD_VIDEO_HEIGHT = 720; | 85 private static final int HD_VIDEO_HEIGHT = 720; |
84 private static final int MAX_VIDEO_WIDTH = 1280; | 86 private static final int MAX_VIDEO_WIDTH = 1280; |
85 private static final int MAX_VIDEO_HEIGHT = 1280; | 87 private static final int MAX_VIDEO_HEIGHT = 1280; |
86 private static final int MAX_VIDEO_FPS = 30; | 88 private static final int MAX_VIDEO_FPS = 30; |
87 | 89 |
88 private static final PeerConnectionClient instance = new PeerConnectionClient(
); | 90 private static final PeerConnectionClient instance = new PeerConnectionClient(
); |
89 private final PCObserver pcObserver = new PCObserver(); | 91 private final PCObserver pcObserver = new PCObserver(); |
90 private final SDPObserver sdpObserver = new SDPObserver(); | 92 private final SDPObserver sdpObserver = new SDPObserver(); |
91 private final LooperExecutor executor; | 93 private final ScheduledExecutorService executor; |
92 | 94 |
93 private PeerConnectionFactory factory; | 95 private PeerConnectionFactory factory; |
94 private PeerConnection peerConnection; | 96 private PeerConnection peerConnection; |
95 PeerConnectionFactory.Options options = null; | 97 PeerConnectionFactory.Options options = null; |
96 private VideoSource videoSource; | 98 private VideoSource videoSource; |
97 private boolean videoCallEnabled; | 99 private boolean videoCallEnabled; |
98 private boolean preferIsac; | 100 private boolean preferIsac; |
99 private String preferredVideoCodec; | 101 private String preferredVideoCodec; |
100 private boolean videoSourceStopped; | 102 private boolean videoSourceStopped; |
101 private boolean isError; | 103 private boolean isError; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 */ | 214 */ |
213 public void onPeerConnectionStatsReady(final StatsReport[] reports); | 215 public void onPeerConnectionStatsReady(final StatsReport[] reports); |
214 | 216 |
215 /** | 217 /** |
216 * Callback fired once peer connection error happened. | 218 * Callback fired once peer connection error happened. |
217 */ | 219 */ |
218 public void onPeerConnectionError(final String description); | 220 public void onPeerConnectionError(final String description); |
219 } | 221 } |
220 | 222 |
221 private PeerConnectionClient() { | 223 private PeerConnectionClient() { |
222 executor = new LooperExecutor(); | 224 // Executor thread is started once in private ctor and is used for all |
223 // Looper thread is started once in private ctor and is used for all | |
224 // peer connection API calls to ensure new peer connection factory is | 225 // peer connection API calls to ensure new peer connection factory is |
225 // created on the same thread as previously destroyed factory. | 226 // created on the same thread as previously destroyed factory. |
226 executor.requestStart(); | 227 executor = Executors.newSingleThreadScheduledExecutor(); |
227 } | 228 } |
228 | 229 |
229 public static PeerConnectionClient getInstance() { | 230 public static PeerConnectionClient getInstance() { |
230 return instance; | 231 return instance; |
231 } | 232 } |
232 | 233 |
233 public void setPeerConnectionFactoryOptions(PeerConnectionFactory.Options opti
ons) { | 234 public void setPeerConnectionFactoryOptions(PeerConnectionFactory.Options opti
ons) { |
234 this.options = options; | 235 this.options = options; |
235 } | 236 } |
236 | 237 |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 public void onCreateFailure(final String error) { | 1131 public void onCreateFailure(final String error) { |
1131 reportError("createSDP error: " + error); | 1132 reportError("createSDP error: " + error); |
1132 } | 1133 } |
1133 | 1134 |
1134 @Override | 1135 @Override |
1135 public void onSetFailure(final String error) { | 1136 public void onSetFailure(final String error) { |
1136 reportError("setSDP error: " + error); | 1137 reportError("setSDP error: " + error); |
1137 } | 1138 } |
1138 } | 1139 } |
1139 } | 1140 } |
OLD | NEW |