1package eu.siacs.conversations.xmpp.jingle;
2
3import android.content.Context;
4import android.os.Build;
5import android.os.Handler;
6import android.os.Looper;
7import android.util.Log;
8
9import com.google.common.base.Optional;
10import com.google.common.base.Preconditions;
11import com.google.common.collect.ImmutableSet;
12import com.google.common.collect.Iterables;
13import com.google.common.util.concurrent.Futures;
14import com.google.common.util.concurrent.ListenableFuture;
15import com.google.common.util.concurrent.MoreExecutors;
16import com.google.common.util.concurrent.SettableFuture;
17
18import org.webrtc.AudioSource;
19import org.webrtc.AudioTrack;
20import org.webrtc.Camera1Enumerator;
21import org.webrtc.Camera2Enumerator;
22import org.webrtc.CameraEnumerationAndroid;
23import org.webrtc.CameraEnumerator;
24import org.webrtc.CameraVideoCapturer;
25import org.webrtc.CandidatePairChangeEvent;
26import org.webrtc.DataChannel;
27import org.webrtc.DefaultVideoDecoderFactory;
28import org.webrtc.DefaultVideoEncoderFactory;
29import org.webrtc.EglBase;
30import org.webrtc.IceCandidate;
31import org.webrtc.MediaConstraints;
32import org.webrtc.MediaStream;
33import org.webrtc.MediaStreamTrack;
34import org.webrtc.PeerConnection;
35import org.webrtc.PeerConnectionFactory;
36import org.webrtc.RtpReceiver;
37import org.webrtc.RtpTransceiver;
38import org.webrtc.SdpObserver;
39import org.webrtc.SessionDescription;
40import org.webrtc.SurfaceTextureHelper;
41import org.webrtc.VideoSource;
42import org.webrtc.VideoTrack;
43import org.webrtc.audio.JavaAudioDeviceModule;
44import org.webrtc.voiceengine.WebRtcAudioEffects;
45
46import java.util.ArrayList;
47import java.util.Collections;
48import java.util.List;
49import java.util.Set;
50
51import javax.annotation.Nonnull;
52import javax.annotation.Nullable;
53
54import eu.siacs.conversations.Config;
55import eu.siacs.conversations.services.AppRTCAudioManager;
56import eu.siacs.conversations.services.XmppConnectionService;
57
58public class WebRTCWrapper {
59
60 private static final String EXTENDED_LOGGING_TAG = WebRTCWrapper.class.getSimpleName();
61
62 //we should probably keep this in sync with: https://github.com/signalapp/Signal-Android/blob/master/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java#L296
63 private static final Set<String> HARDWARE_AEC_BLACKLIST = new ImmutableSet.Builder<String>()
64 .add("Pixel")
65 .add("Pixel XL")
66 .add("Moto G5")
67 .add("Moto G (5S) Plus")
68 .add("Moto G4")
69 .add("TA-1053")
70 .add("Mi A1")
71 .add("Mi A2")
72 .add("E5823") // Sony z5 compact
73 .add("Redmi Note 5")
74 .add("FP2") // Fairphone FP2
75 .add("MI 5")
76 .build();
77
78 private static final int CAPTURING_RESOLUTION = 1920;
79 private static final int CAPTURING_MAX_FRAME_RATE = 30;
80
81 private final EventCallback eventCallback;
82 private final AppRTCAudioManager.AudioManagerEvents audioManagerEvents = new AppRTCAudioManager.AudioManagerEvents() {
83 @Override
84 public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) {
85 eventCallback.onAudioDeviceChanged(selectedAudioDevice, availableAudioDevices);
86 }
87 };
88 private final Handler mainHandler = new Handler(Looper.getMainLooper());
89 private VideoTrack localVideoTrack = null;
90 private VideoTrack remoteVideoTrack = null;
91 private final PeerConnection.Observer peerConnectionObserver = new PeerConnection.Observer() {
92 @Override
93 public void onSignalingChange(PeerConnection.SignalingState signalingState) {
94 Log.d(EXTENDED_LOGGING_TAG, "onSignalingChange(" + signalingState + ")");
95 //this is called after removeTrack or addTrack
96 //and should then trigger a content-add or content-remove or something
97 //https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/removeTrack
98 }
99
100 @Override
101 public void onConnectionChange(PeerConnection.PeerConnectionState newState) {
102 eventCallback.onConnectionChange(newState);
103 }
104
105 @Override
106 public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) {
107
108 }
109
110 @Override
111 public void onSelectedCandidatePairChanged(CandidatePairChangeEvent event) {
112 Log.d(Config.LOGTAG, "remote candidate selected: " + event.remote);
113 Log.d(Config.LOGTAG, "local candidate selected: " + event.local);
114 }
115
116 @Override
117 public void onIceConnectionReceivingChange(boolean b) {
118
119 }
120
121 @Override
122 public void onIceGatheringChange(PeerConnection.IceGatheringState iceGatheringState) {
123 Log.d(EXTENDED_LOGGING_TAG, "onIceGatheringChange(" + iceGatheringState + ")");
124 }
125
126 @Override
127 public void onIceCandidate(IceCandidate iceCandidate) {
128 eventCallback.onIceCandidate(iceCandidate);
129 }
130
131 @Override
132 public void onIceCandidatesRemoved(IceCandidate[] iceCandidates) {
133
134 }
135
136 @Override
137 public void onAddStream(MediaStream mediaStream) {
138 Log.d(EXTENDED_LOGGING_TAG, "onAddStream(numAudioTracks=" + mediaStream.audioTracks.size() + ",numVideoTracks=" + mediaStream.videoTracks.size() + ")");
139 final List<VideoTrack> videoTracks = mediaStream.videoTracks;
140 if (videoTracks.size() > 0) {
141 remoteVideoTrack = videoTracks.get(0);
142 Log.d(Config.LOGTAG, "remote video track enabled?=" + remoteVideoTrack.enabled());
143 } else {
144 Log.d(Config.LOGTAG, "no remote video tracks found");
145 }
146 }
147
148 @Override
149 public void onRemoveStream(MediaStream mediaStream) {
150
151 }
152
153 @Override
154 public void onDataChannel(DataChannel dataChannel) {
155
156 }
157
158 @Override
159 public void onRenegotiationNeeded() {
160
161 }
162
163 @Override
164 public void onAddTrack(RtpReceiver rtpReceiver, MediaStream[] mediaStreams) {
165 final MediaStreamTrack track = rtpReceiver.track();
166 Log.d(EXTENDED_LOGGING_TAG, "onAddTrack(kind=" + (track == null ? "null" : track.kind()) + ",numMediaStreams=" + mediaStreams.length + ")");
167 }
168
169 @Override
170 public void onTrack(RtpTransceiver transceiver) {
171 Log.d(EXTENDED_LOGGING_TAG, "onTrack(mid=" + transceiver.getMid() + ",media=" + transceiver.getMediaType() + ")");
172 }
173 };
174 @Nullable
175 private PeerConnection peerConnection = null;
176 private AudioTrack localAudioTrack = null;
177 private AppRTCAudioManager appRTCAudioManager = null;
178 private ToneManager toneManager = null;
179 private Context context = null;
180 private EglBase eglBase = null;
181 private CapturerChoice capturerChoice;
182
183 WebRTCWrapper(final EventCallback eventCallback) {
184 this.eventCallback = eventCallback;
185 }
186
187 private static void dispose(final PeerConnection peerConnection) {
188 try {
189 peerConnection.dispose();
190 } catch (final IllegalStateException e) {
191 Log.e(Config.LOGTAG, "unable to dispose of peer connection", e);
192 }
193 }
194
195 @Nullable
196 private static CapturerChoice of(CameraEnumerator enumerator, final String deviceName, Set<String> availableCameras) {
197 final CameraVideoCapturer capturer = enumerator.createCapturer(deviceName, null);
198 if (capturer == null) {
199 return null;
200 }
201 final ArrayList<CameraEnumerationAndroid.CaptureFormat> choices = new ArrayList<>(enumerator.getSupportedFormats(deviceName));
202 Collections.sort(choices, (a, b) -> b.width - a.width);
203 for (final CameraEnumerationAndroid.CaptureFormat captureFormat : choices) {
204 if (captureFormat.width <= CAPTURING_RESOLUTION) {
205 return new CapturerChoice(capturer, captureFormat, availableCameras);
206 }
207 }
208 return null;
209 }
210
211 public void setup(final XmppConnectionService service, final AppRTCAudioManager.SpeakerPhonePreference speakerPhonePreference) throws InitializationException {
212 try {
213 PeerConnectionFactory.initialize(
214 PeerConnectionFactory.InitializationOptions.builder(service).createInitializationOptions()
215 );
216 } catch (final UnsatisfiedLinkError e) {
217 throw new InitializationException(e);
218 }
219 this.eglBase = EglBase.create();
220 this.context = service;
221 this.toneManager = service.getJingleConnectionManager().toneManager;
222 mainHandler.post(() -> {
223 appRTCAudioManager = AppRTCAudioManager.create(service, speakerPhonePreference);
224 toneManager.setAppRtcAudioManagerHasControl(true);
225 appRTCAudioManager.start(audioManagerEvents);
226 eventCallback.onAudioDeviceChanged(appRTCAudioManager.getSelectedAudioDevice(), appRTCAudioManager.getAudioDevices());
227 });
228 }
229
230 synchronized void initializePeerConnection(final Set<Media> media, final List<PeerConnection.IceServer> iceServers) throws InitializationException {
231 Preconditions.checkState(this.eglBase != null);
232 Preconditions.checkNotNull(media);
233 Preconditions.checkArgument(media.size() > 0, "media can not be empty when initializing peer connection");
234 final boolean setUseHardwareAcousticEchoCanceler = WebRtcAudioEffects.canUseAcousticEchoCanceler() && !HARDWARE_AEC_BLACKLIST.contains(Build.MODEL);
235 Log.d(Config.LOGTAG, String.format("setUseHardwareAcousticEchoCanceler(%s) model=%s", setUseHardwareAcousticEchoCanceler, Build.MODEL));
236 PeerConnectionFactory peerConnectionFactory = PeerConnectionFactory.builder()
237 .setVideoDecoderFactory(new DefaultVideoDecoderFactory(eglBase.getEglBaseContext()))
238 .setVideoEncoderFactory(new DefaultVideoEncoderFactory(eglBase.getEglBaseContext(), true, true))
239 .setAudioDeviceModule(JavaAudioDeviceModule.builder(context)
240 .setUseHardwareAcousticEchoCanceler(setUseHardwareAcousticEchoCanceler)
241 .createAudioDeviceModule()
242 )
243 .createPeerConnectionFactory();
244
245
246 final MediaStream stream = peerConnectionFactory.createLocalMediaStream("my-media-stream");
247
248 final Optional<CapturerChoice> optionalCapturerChoice = media.contains(Media.VIDEO) ? getVideoCapturer() : Optional.absent();
249
250 if (optionalCapturerChoice.isPresent()) {
251 this.capturerChoice = optionalCapturerChoice.get();
252 final CameraVideoCapturer capturer = this.capturerChoice.cameraVideoCapturer;
253 final VideoSource videoSource = peerConnectionFactory.createVideoSource(false);
254 SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("webrtc", eglBase.getEglBaseContext());
255 capturer.initialize(surfaceTextureHelper, requireContext(), videoSource.getCapturerObserver());
256 Log.d(Config.LOGTAG, String.format("start capturing at %dx%d@%d", capturerChoice.captureFormat.width, capturerChoice.captureFormat.height, capturerChoice.getFrameRate()));
257 capturer.startCapture(capturerChoice.captureFormat.width, capturerChoice.captureFormat.height, capturerChoice.getFrameRate());
258
259 this.localVideoTrack = peerConnectionFactory.createVideoTrack("my-video-track", videoSource);
260
261 stream.addTrack(this.localVideoTrack);
262 }
263
264
265 if (media.contains(Media.AUDIO)) {
266 //set up audio track
267 final AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints());
268 this.localAudioTrack = peerConnectionFactory.createAudioTrack("my-audio-track", audioSource);
269 stream.addTrack(this.localAudioTrack);
270 }
271
272
273 final PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
274 rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED; //XEP-0176 doesn't support tcp
275 rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
276 final PeerConnection peerConnection = peerConnectionFactory.createPeerConnection(rtcConfig, peerConnectionObserver);
277 if (peerConnection == null) {
278 throw new InitializationException("Unable to create PeerConnection");
279 }
280 peerConnection.addStream(stream);
281 peerConnection.setAudioPlayout(true);
282 peerConnection.setAudioRecording(true);
283 this.peerConnection = peerConnection;
284 }
285
286 synchronized void close() {
287 final PeerConnection peerConnection = this.peerConnection;
288 final CapturerChoice capturerChoice = this.capturerChoice;
289 final AppRTCAudioManager audioManager = this.appRTCAudioManager;
290 final EglBase eglBase = this.eglBase;
291 if (peerConnection != null) {
292 dispose(peerConnection);
293 this.peerConnection = null;
294 }
295 if (audioManager != null) {
296 toneManager.setAppRtcAudioManagerHasControl(false);
297 mainHandler.post(audioManager::stop);
298 }
299 this.localVideoTrack = null;
300 this.remoteVideoTrack = null;
301 if (capturerChoice != null) {
302 try {
303 capturerChoice.cameraVideoCapturer.stopCapture();
304 } catch (InterruptedException e) {
305 Log.e(Config.LOGTAG, "unable to stop capturing");
306 }
307 }
308 if (eglBase != null) {
309 eglBase.release();
310 this.eglBase = null;
311 }
312 }
313
314 synchronized void verifyClosed() {
315 if (this.peerConnection != null
316 || this.eglBase != null
317 || this.localVideoTrack != null
318 || this.remoteVideoTrack != null) {
319 final IllegalStateException e = new IllegalStateException("WebRTCWrapper hasn't been closed properly");
320 Log.e(Config.LOGTAG, "verifyClosed() failed. Going to throw", e);
321 throw e;
322 }
323 }
324
325 boolean isCameraSwitchable() {
326 final CapturerChoice capturerChoice = this.capturerChoice;
327 return capturerChoice != null && capturerChoice.availableCameras.size() > 1;
328 }
329
330 boolean isFrontCamera() {
331 final CapturerChoice capturerChoice = this.capturerChoice;
332 return capturerChoice == null || capturerChoice.isFrontCamera;
333 }
334
335 ListenableFuture<Boolean> switchCamera() {
336 final CapturerChoice capturerChoice = this.capturerChoice;
337 if (capturerChoice == null) {
338 return Futures.immediateFailedFuture(new IllegalStateException("CameraCapturer has not been initialized"));
339 }
340 final SettableFuture<Boolean> future = SettableFuture.create();
341 capturerChoice.cameraVideoCapturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() {
342 @Override
343 public void onCameraSwitchDone(boolean isFrontCamera) {
344 capturerChoice.isFrontCamera = isFrontCamera;
345 future.set(isFrontCamera);
346 }
347
348 @Override
349 public void onCameraSwitchError(final String message) {
350 future.setException(new IllegalStateException(String.format("Unable to switch camera %s", message)));
351 }
352 });
353 return future;
354 }
355
356 boolean isMicrophoneEnabled() {
357 final AudioTrack audioTrack = this.localAudioTrack;
358 if (audioTrack == null) {
359 throw new IllegalStateException("Local audio track does not exist (yet)");
360 }
361 try {
362 return audioTrack.enabled();
363 } catch (final IllegalStateException e) {
364 //sometimes UI might still be rendering the buttons when a background thread has already ended the call
365 return false;
366 }
367 }
368
369 void setMicrophoneEnabled(final boolean enabled) {
370 final AudioTrack audioTrack = this.localAudioTrack;
371 if (audioTrack == null) {
372 throw new IllegalStateException("Local audio track does not exist (yet)");
373 }
374 audioTrack.setEnabled(enabled);
375 }
376
377 boolean isVideoEnabled() {
378 final VideoTrack videoTrack = this.localVideoTrack;
379 if (videoTrack == null) {
380 throw new IllegalStateException("Local video track does not exist");
381 }
382 return videoTrack.enabled();
383 }
384
385 void setVideoEnabled(final boolean enabled) {
386 final VideoTrack videoTrack = this.localVideoTrack;
387 if (videoTrack == null) {
388 throw new IllegalStateException("Local video track does not exist");
389 }
390 videoTrack.setEnabled(enabled);
391 }
392
393 ListenableFuture<SessionDescription> createOffer() {
394 return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
395 final SettableFuture<SessionDescription> future = SettableFuture.create();
396 peerConnection.createOffer(new CreateSdpObserver() {
397 @Override
398 public void onCreateSuccess(SessionDescription sessionDescription) {
399 future.set(sessionDescription);
400 }
401
402 @Override
403 public void onCreateFailure(String s) {
404 future.setException(new IllegalStateException("Unable to create offer: " + s));
405 }
406 }, new MediaConstraints());
407 return future;
408 }, MoreExecutors.directExecutor());
409 }
410
411 ListenableFuture<SessionDescription> createAnswer() {
412 return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
413 final SettableFuture<SessionDescription> future = SettableFuture.create();
414 peerConnection.createAnswer(new CreateSdpObserver() {
415 @Override
416 public void onCreateSuccess(SessionDescription sessionDescription) {
417 future.set(sessionDescription);
418 }
419
420 @Override
421 public void onCreateFailure(String s) {
422 future.setException(new IllegalStateException("Unable to create answer: " + s));
423 }
424 }, new MediaConstraints());
425 return future;
426 }, MoreExecutors.directExecutor());
427 }
428
429 ListenableFuture<Void> setLocalDescription(final SessionDescription sessionDescription) {
430 Log.d(EXTENDED_LOGGING_TAG, "setting local description:");
431 for (final String line : sessionDescription.description.split(eu.siacs.conversations.xmpp.jingle.SessionDescription.LINE_DIVIDER)) {
432 Log.d(EXTENDED_LOGGING_TAG, line);
433 }
434 return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
435 final SettableFuture<Void> future = SettableFuture.create();
436 peerConnection.setLocalDescription(new SetSdpObserver() {
437 @Override
438 public void onSetSuccess() {
439 future.set(null);
440 }
441
442 @Override
443 public void onSetFailure(final String s) {
444 future.setException(new IllegalArgumentException("unable to set local session description: " + s));
445
446 }
447 }, sessionDescription);
448 return future;
449 }, MoreExecutors.directExecutor());
450 }
451
452 ListenableFuture<Void> setRemoteDescription(final SessionDescription sessionDescription) {
453 Log.d(EXTENDED_LOGGING_TAG, "setting remote description:");
454 for (final String line : sessionDescription.description.split(eu.siacs.conversations.xmpp.jingle.SessionDescription.LINE_DIVIDER)) {
455 Log.d(EXTENDED_LOGGING_TAG, line);
456 }
457 return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
458 final SettableFuture<Void> future = SettableFuture.create();
459 peerConnection.setRemoteDescription(new SetSdpObserver() {
460 @Override
461 public void onSetSuccess() {
462 future.set(null);
463 }
464
465 @Override
466 public void onSetFailure(String s) {
467 future.setException(new IllegalArgumentException("unable to set remote session description: " + s));
468
469 }
470 }, sessionDescription);
471 return future;
472 }, MoreExecutors.directExecutor());
473 }
474
475 @Nonnull
476 private ListenableFuture<PeerConnection> getPeerConnectionFuture() {
477 final PeerConnection peerConnection = this.peerConnection;
478 if (peerConnection == null) {
479 return Futures.immediateFailedFuture(new IllegalStateException("initialize PeerConnection first"));
480 } else {
481 return Futures.immediateFuture(peerConnection);
482 }
483 }
484
485 void addIceCandidate(IceCandidate iceCandidate) {
486 requirePeerConnection().addIceCandidate(iceCandidate);
487 }
488
489 private CameraEnumerator getCameraEnumerator() {
490 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
491 return new Camera2Enumerator(requireContext());
492 } else {
493 return new Camera1Enumerator();
494 }
495 }
496
497 private Optional<CapturerChoice> getVideoCapturer() {
498 final CameraEnumerator enumerator = getCameraEnumerator();
499 final Set<String> deviceNames = ImmutableSet.copyOf(enumerator.getDeviceNames());
500 for (final String deviceName : deviceNames) {
501 if (enumerator.isFrontFacing(deviceName)) {
502 final CapturerChoice capturerChoice = of(enumerator, deviceName, deviceNames);
503 if (capturerChoice == null) {
504 return Optional.absent();
505 }
506 capturerChoice.isFrontCamera = true;
507 return Optional.of(capturerChoice);
508 }
509 }
510 if (deviceNames.size() == 0) {
511 return Optional.absent();
512 } else {
513 return Optional.fromNullable(of(enumerator, Iterables.get(deviceNames, 0), deviceNames));
514 }
515 }
516
517 public PeerConnection.PeerConnectionState getState() {
518 return requirePeerConnection().connectionState();
519 }
520
521 EglBase.Context getEglBaseContext() {
522 return this.eglBase.getEglBaseContext();
523 }
524
525 Optional<VideoTrack> getLocalVideoTrack() {
526 return Optional.fromNullable(this.localVideoTrack);
527 }
528
529 Optional<VideoTrack> getRemoteVideoTrack() {
530 return Optional.fromNullable(this.remoteVideoTrack);
531 }
532
533 private PeerConnection requirePeerConnection() {
534 final PeerConnection peerConnection = this.peerConnection;
535 if (peerConnection == null) {
536 throw new IllegalStateException("initialize PeerConnection first");
537 }
538 return peerConnection;
539 }
540
541 private Context requireContext() {
542 final Context context = this.context;
543 if (context == null) {
544 throw new IllegalStateException("call setup first");
545 }
546 return context;
547 }
548
549 AppRTCAudioManager getAudioManager() {
550 return appRTCAudioManager;
551 }
552
553 public interface EventCallback {
554 void onIceCandidate(IceCandidate iceCandidate);
555
556 void onConnectionChange(PeerConnection.PeerConnectionState newState);
557
558 void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices);
559 }
560
561 private static abstract class SetSdpObserver implements SdpObserver {
562
563 @Override
564 public void onCreateSuccess(org.webrtc.SessionDescription sessionDescription) {
565 throw new IllegalStateException("Not able to use SetSdpObserver");
566 }
567
568 @Override
569 public void onCreateFailure(String s) {
570 throw new IllegalStateException("Not able to use SetSdpObserver");
571 }
572
573 }
574
575 private static abstract class CreateSdpObserver implements SdpObserver {
576
577
578 @Override
579 public void onSetSuccess() {
580 throw new IllegalStateException("Not able to use CreateSdpObserver");
581 }
582
583
584 @Override
585 public void onSetFailure(String s) {
586 throw new IllegalStateException("Not able to use CreateSdpObserver");
587 }
588 }
589
590 static class InitializationException extends Exception {
591
592 private InitializationException(final Throwable throwable) {
593 super(throwable);
594 }
595
596 private InitializationException(final String message) {
597 super(message);
598 }
599 }
600
601 private static class CapturerChoice {
602 private final CameraVideoCapturer cameraVideoCapturer;
603 private final CameraEnumerationAndroid.CaptureFormat captureFormat;
604 private final Set<String> availableCameras;
605 private boolean isFrontCamera = false;
606
607 CapturerChoice(CameraVideoCapturer cameraVideoCapturer, CameraEnumerationAndroid.CaptureFormat captureFormat, Set<String> cameras) {
608 this.cameraVideoCapturer = cameraVideoCapturer;
609 this.captureFormat = captureFormat;
610 this.availableCameras = cameras;
611 }
612
613 int getFrameRate() {
614 return Math.max(captureFormat.framerate.min, Math.min(CAPTURING_MAX_FRAME_RATE, captureFormat.framerate.max));
615 }
616 }
617}