1 /* 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 package org.webrtc; 12 13 import android.content.Context; 14 import android.support.annotation.Nullable; 15 16 public class UnityUtility { 17 private static final String VIDEO_CAPTURER_THREAD_NAME = "VideoCapturerThread"; 18 LoadSurfaceTextureHelper()19 public static SurfaceTextureHelper LoadSurfaceTextureHelper() { 20 final SurfaceTextureHelper surfaceTextureHelper = 21 SurfaceTextureHelper.create(VIDEO_CAPTURER_THREAD_NAME, null); 22 return surfaceTextureHelper; 23 } 24 useCamera2()25 private static boolean useCamera2() { 26 return Camera2Enumerator.isSupported(ContextUtils.getApplicationContext()); 27 } 28 createCameraCapturer(CameraEnumerator enumerator)29 private static @Nullable VideoCapturer createCameraCapturer(CameraEnumerator enumerator) { 30 final String[] deviceNames = enumerator.getDeviceNames(); 31 32 for (String deviceName : deviceNames) { 33 if (enumerator.isFrontFacing(deviceName)) { 34 VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null); 35 36 if (videoCapturer != null) { 37 return videoCapturer; 38 } 39 } 40 } 41 42 return null; 43 } 44 LinkCamera( long nativeTrackSource, SurfaceTextureHelper surfaceTextureHelper)45 public static VideoCapturer LinkCamera( 46 long nativeTrackSource, SurfaceTextureHelper surfaceTextureHelper) { 47 VideoCapturer capturer = 48 createCameraCapturer(new Camera2Enumerator(ContextUtils.getApplicationContext())); 49 50 VideoSource videoSource = new VideoSource(nativeTrackSource); 51 52 capturer.initialize(surfaceTextureHelper, ContextUtils.getApplicationContext(), 53 videoSource.getCapturerObserver()); 54 55 capturer.startCapture(720, 480, 30); 56 return capturer; 57 } 58 StopCamera(VideoCapturer camera)59 public static void StopCamera(VideoCapturer camera) throws InterruptedException { 60 camera.stopCapture(); 61 camera.dispose(); 62 } 63 InitializePeerConncectionFactory(Context context)64 public static void InitializePeerConncectionFactory(Context context) throws InterruptedException { 65 PeerConnectionFactory.initialize( 66 PeerConnectionFactory.InitializationOptions.builder(context).createInitializationOptions()); 67 } 68 } 69