org.webrtc.CameraEnumerator Java Examples

The following examples show how to use org.webrtc.CameraEnumerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Camera.java    From mollyim-android with GNU General Public License v3.0 7 votes vote down vote up
public Camera(@NonNull Context             context,
              @NonNull CameraEventListener cameraEventListener,
              @NonNull EglBase             eglBase)
{
  this.context                = context;
  this.cameraEventListener    = cameraEventListener;
  this.eglBase                = eglBase;
  CameraEnumerator enumerator = getCameraEnumerator(context);
  cameraCount                 = enumerator.getDeviceNames().length;

  CameraVideoCapturer capturerCandidate = createVideoCapturer(enumerator, FRONT);
  if (capturerCandidate != null) {
    activeDirection = FRONT;
  } else {
    capturerCandidate = createVideoCapturer(enumerator, BACK);
    if (capturerCandidate != null) {
      activeDirection = BACK;
    } else {
      activeDirection = NONE;
    }
  }
  capturer = capturerCandidate;
}
 
Example #2
Source File: PeerConnectionWrapper.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
Camera(@NonNull Context context, @NonNull CameraEventListener cameraEventListener) {
    this.cameraEventListener = cameraEventListener;
    CameraEnumerator enumerator = getCameraEnumerator(context);
    cameraCount = enumerator.getDeviceNames().length;

    CameraVideoCapturer cameraVideoCapturer = createVideoCapturer(enumerator, FRONT);
    if (cameraVideoCapturer != null) {
        activeDirection = FRONT;
    } else  {
        cameraVideoCapturer = createVideoCapturer(enumerator, BACK);
        if (cameraVideoCapturer != null) {
            activeDirection = BACK;
        } else {
            activeDirection = NONE;
        }
    }

    capturer = cameraVideoCapturer;
}
 
Example #3
Source File: OwtVideoCapturer.java    From owt-client-android with Apache License 2.0 6 votes vote down vote up
private static String getDeviceName(boolean captureToTexture, boolean isCameraFront) {
    CameraEnumerator enumerator = new Camera1Enumerator(captureToTexture);

    String deviceName = null;
    for (String device : enumerator.getDeviceNames()) {
        if (enumerator.isFrontFacing(device) && isCameraFront) {
            deviceName = device;
            break;
        }
        if (enumerator.isBackFacing(device) && !isCameraFront) {
            deviceName = device;
            break;
        }
    }

    return deviceName == null ? enumerator.getDeviceNames()[0] : deviceName;
}
 
Example #4
Source File: WebRTCWrapper.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
private Optional<CapturerChoice> getVideoCapturer() {
    final CameraEnumerator enumerator = getCameraEnumerator();
    final Set<String> deviceNames = ImmutableSet.copyOf(enumerator.getDeviceNames());
    for (final String deviceName : deviceNames) {
        if (enumerator.isFrontFacing(deviceName)) {
            final CapturerChoice capturerChoice = of(enumerator, deviceName, deviceNames);
            if (capturerChoice == null) {
                return Optional.absent();
            }
            capturerChoice.isFrontCamera = true;
            return Optional.of(capturerChoice);
        }
    }
    if (deviceNames.size() == 0) {
        return Optional.absent();
    } else {
        return Optional.fromNullable(of(enumerator, Iterables.get(deviceNames, 0), deviceNames));
    }
}
 
Example #5
Source File: WebRTCWrapper.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
private Optional<CapturerChoice> getVideoCapturer() {
    final CameraEnumerator enumerator = getCameraEnumerator();
    final Set<String> deviceNames = ImmutableSet.copyOf(enumerator.getDeviceNames());
    for (final String deviceName : deviceNames) {
        if (enumerator.isFrontFacing(deviceName)) {
            final CapturerChoice capturerChoice = of(enumerator, deviceName, deviceNames);
            if (capturerChoice == null) {
                return Optional.absent();
            }
            capturerChoice.isFrontCamera = true;
            return Optional.of(capturerChoice);
        }
    }
    if (deviceNames.size() == 0) {
        return Optional.absent();
    } else {
        return Optional.fromNullable(of(enumerator, Iterables.get(deviceNames, 0), deviceNames));
    }
}
 
Example #6
Source File: Camera.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private @Nullable CameraVideoCapturer createVideoCapturer(@NonNull CameraEnumerator enumerator,
                                                          @NonNull CameraState.Direction direction)
{
  String[] deviceNames = enumerator.getDeviceNames();
  for (String deviceName : deviceNames) {
    if ((direction == FRONT && enumerator.isFrontFacing(deviceName)) ||
        (direction == BACK  && enumerator.isBackFacing(deviceName)))
      {
        return enumerator.createCapturer(deviceName, null);
      }
  }

  return null;
}
 
Example #7
Source File: Camera.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private @NonNull CameraEnumerator getCameraEnumerator(@NonNull Context context) {
  boolean camera2EnumeratorIsSupported = false;
  try {
    camera2EnumeratorIsSupported = Camera2Enumerator.isSupported(context);
  } catch (final Throwable throwable) {
    Log.w(TAG, "Camera2Enumator.isSupport() threw.", throwable);
  }

  Log.i(TAG, "Camera2 enumerator supported: " + camera2EnumeratorIsSupported);

  return camera2EnumeratorIsSupported ? new FilteredCamera2Enumerator(context)
                                      : new Camera1Enumerator(true);
}
 
Example #8
Source File: RTCCall.java    From meshenger-android with GNU General Public License v3.0 5 votes vote down vote up
private CameraVideoCapturer createCapturer() {
    CameraEnumerator enumerator = new Camera1Enumerator();
    for (String name : enumerator.getDeviceNames()) {
        if (enumerator.isFrontFacing(name)) {
            return enumerator.createCapturer(name, null);
        }
    }
    return null;
}
 
Example #9
Source File: PeerConnectionWrapper.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private @Nullable CameraVideoCapturer createVideoCapturer(@NonNull CameraEnumerator enumerator, @NonNull CameraState.Direction direction) {
    String[] deviceNames = enumerator.getDeviceNames();
    for (String deviceName : deviceNames) {
        if ((direction == FRONT && enumerator.isFrontFacing(deviceName)) || (direction == BACK  && enumerator.isBackFacing(deviceName))) {
            return enumerator.createCapturer(deviceName, null);
        }
    }

    return null;
}
 
Example #10
Source File: PeerConnectionWrapper.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private @NonNull CameraEnumerator getCameraEnumerator(@NonNull Context context) {
    boolean camera2EnumeratorIsSupported = false;
    try {
        camera2EnumeratorIsSupported = Camera2Enumerator.isSupported(context);
    } catch (final Throwable throwable) {
        ALog.w(TAG, "Camera2Enumator.isSupport() threw. " + throwable.getMessage());
    }

    ALog.i(TAG, "Camera2 enumerator supported: " + camera2EnumeratorIsSupported);

    return camera2EnumeratorIsSupported ? new Camera2Enumerator(context)
            : new Camera1Enumerator(true);
}
 
Example #11
Source File: VideoCapturerForTest.java    From owt-client-android with Apache License 2.0 5 votes vote down vote up
private static String getDeviceName(boolean captureToTexture) {
    CameraEnumerator enumerator = new Camera1Enumerator(captureToTexture);

    String deviceName = null;
    for (String device : enumerator.getDeviceNames()) {
        if (enumerator.isFrontFacing(device)) {
            deviceName = device;
            break;
        }
    }

    return deviceName == null ? enumerator.getDeviceNames()[0] : deviceName;
}
 
Example #12
Source File: RTCCall.java    From Meshenger with GNU General Public License v3.0 5 votes vote down vote up
private CameraVideoCapturer createCapturer() {
    CameraEnumerator enumerator = new Camera1Enumerator();
    for (String name : enumerator.getDeviceNames()) {
        if (enumerator.isFrontFacing(name)) {
            return enumerator.createCapturer(name, null);
        }
    }
    return null;
}
 
Example #13
Source File: WebRTCWrapper.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static CapturerChoice of(CameraEnumerator enumerator, final String deviceName, Set<String> availableCameras) {
    final CameraVideoCapturer capturer = enumerator.createCapturer(deviceName, null);
    if (capturer == null) {
        return null;
    }
    final ArrayList<CameraEnumerationAndroid.CaptureFormat> choices = new ArrayList<>(enumerator.getSupportedFormats(deviceName));
    Collections.sort(choices, (a, b) -> b.width - a.width);
    for (final CameraEnumerationAndroid.CaptureFormat captureFormat : choices) {
        if (captureFormat.width <= CAPTURING_RESOLUTION) {
            return new CapturerChoice(capturer, captureFormat, availableCameras);
        }
    }
    return null;
}
 
Example #14
Source File: WebRTCWrapper.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
private CameraEnumerator getCameraEnumerator() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return new Camera2Enumerator(requireContext());
    } else {
        return new Camera1Enumerator();
    }
}
 
Example #15
Source File: WebRTCWrapper.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static CapturerChoice of(CameraEnumerator enumerator, final String deviceName, Set<String> availableCameras) {
    final CameraVideoCapturer capturer = enumerator.createCapturer(deviceName, null);
    if (capturer == null) {
        return null;
    }
    final ArrayList<CameraEnumerationAndroid.CaptureFormat> choices = new ArrayList<>(enumerator.getSupportedFormats(deviceName));
    Collections.sort(choices, (a, b) -> b.width - a.width);
    for (final CameraEnumerationAndroid.CaptureFormat captureFormat : choices) {
        if (captureFormat.width <= CAPTURING_RESOLUTION) {
            return new CapturerChoice(capturer, captureFormat, availableCameras);
        }
    }
    return null;
}
 
Example #16
Source File: WebRTCWrapper.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private CameraEnumerator getCameraEnumerator() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return new Camera2Enumerator(requireContext());
    } else {
        return new Camera1Enumerator();
    }
}