package org.webrtc; import android.hardware.Camera; import android.os.SystemClock; import java.util.ArrayList; import java.util.List; import org.webrtc.CameraEnumerationAndroid; import org.webrtc.CameraVideoCapturer; /* loaded from: classes3.dex */ public class Camera1Enumerator implements CameraEnumerator { private static final String TAG = "Camera1Enumerator"; private static List> cachedSupportedFormats; private final boolean captureToTexture; public Camera1Enumerator() { this(true); } public Camera1Enumerator(boolean z) { this.captureToTexture = z; } @Override // org.webrtc.CameraEnumerator public String[] getDeviceNames() { ArrayList arrayList = new ArrayList(); for (int i = 0; i < Camera.getNumberOfCameras(); i++) { String deviceName = getDeviceName(i); if (deviceName != null) { arrayList.add(deviceName); Logging.d(TAG, "Index: " + i + ". " + deviceName); } else { Logging.e(TAG, "Index: " + i + ". Failed to query camera name."); } } return (String[]) arrayList.toArray(new String[arrayList.size()]); } @Override // org.webrtc.CameraEnumerator public boolean isFrontFacing(String str) { Camera.CameraInfo cameraInfo = getCameraInfo(getCameraIndex(str)); return cameraInfo != null && cameraInfo.facing == 1; } @Override // org.webrtc.CameraEnumerator public boolean isBackFacing(String str) { Camera.CameraInfo cameraInfo = getCameraInfo(getCameraIndex(str)); return cameraInfo != null && cameraInfo.facing == 0; } @Override // org.webrtc.CameraEnumerator public List getSupportedFormats(String str) { return getSupportedFormats(getCameraIndex(str)); } @Override // org.webrtc.CameraEnumerator public CameraVideoCapturer createCapturer(String str, CameraVideoCapturer.CameraEventsHandler cameraEventsHandler) { return new Camera1Capturer(str, cameraEventsHandler, this.captureToTexture); } private static Camera.CameraInfo getCameraInfo(int i) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); try { Camera.getCameraInfo(i, cameraInfo); return cameraInfo; } catch (Exception e) { Logging.e(TAG, "getCameraInfo failed on index " + i, e); return null; } } static synchronized List getSupportedFormats(int i) { List list; synchronized (Camera1Enumerator.class) { if (cachedSupportedFormats == null) { cachedSupportedFormats = new ArrayList(); for (int i2 = 0; i2 < Camera.getNumberOfCameras(); i2++) { cachedSupportedFormats.add(enumerateFormats(i2)); } } list = cachedSupportedFormats.get(i); } return list; } private static List enumerateFormats(int i) { int i2; Logging.d(TAG, "Get supported formats for camera index " + i + "."); long elapsedRealtime = SystemClock.elapsedRealtime(); Camera camera = null; try { try { Logging.d(TAG, "Opening camera with index " + i); camera = Camera.open(i); Camera.Parameters parameters = camera.getParameters(); if (camera != null) { camera.release(); } ArrayList arrayList = new ArrayList(); try { List supportedPreviewFpsRange = parameters.getSupportedPreviewFpsRange(); int i3 = 0; if (supportedPreviewFpsRange != null) { int[] iArr = supportedPreviewFpsRange.get(supportedPreviewFpsRange.size() - 1); i3 = iArr[0]; i2 = iArr[1]; } else { i2 = 0; } for (Camera.Size size : parameters.getSupportedPreviewSizes()) { arrayList.add(new CameraEnumerationAndroid.CaptureFormat(size.width, size.height, i3, i2)); } } catch (Exception e) { Logging.e(TAG, "getSupportedFormats() failed on camera index " + i, e); } Logging.d(TAG, "Get supported formats for camera index " + i + " done. Time spent: " + (SystemClock.elapsedRealtime() - elapsedRealtime) + " ms."); return arrayList; } catch (RuntimeException e2) { Logging.e(TAG, "Open camera failed on camera index " + i, e2); ArrayList arrayList2 = new ArrayList(); if (camera != null) { camera.release(); } return arrayList2; } } catch (Throwable th) { if (camera != null) { camera.release(); } throw th; } } /* JADX INFO: Access modifiers changed from: package-private */ public static List convertSizes(List list) { ArrayList arrayList = new ArrayList(); for (Camera.Size size : list) { arrayList.add(new Size(size.width, size.height)); } return arrayList; } /* JADX INFO: Access modifiers changed from: package-private */ public static List convertFramerates(List list) { ArrayList arrayList = new ArrayList(); for (int[] iArr : list) { arrayList.add(new CameraEnumerationAndroid.CaptureFormat.FramerateRange(iArr[0], iArr[1])); } return arrayList; } /* JADX INFO: Access modifiers changed from: package-private */ public static int getCameraIndex(String str) { Logging.d(TAG, "getCameraIndex: " + str); for (int i = 0; i < Camera.getNumberOfCameras(); i++) { if (str.equals(getDeviceName(i))) { return i; } } throw new IllegalArgumentException("No such camera: " + str); } static String getDeviceName(int i) { Camera.CameraInfo cameraInfo = getCameraInfo(i); if (cameraInfo == null) { return null; } return "Camera " + i + ", Facing " + (cameraInfo.facing == 1 ? "front" : "back") + ", Orientation " + cameraInfo.orientation; } }