Commit 62e590c5 authored by Christian Fremerey's avatar Christian Fremerey Committed by Commit Bot

[Video Capture Android] Support facing mode and list user-facing first

On Android, the facing mode of capture devices is currently reported only in
form of a string appended to the device name. This was probably a legacy
solution before facing mode has become an official field that can be queried.

This CL fills the facing mode field so that it gets reported correctly.
It then sorts device infos reported during device enumeration such that
user-facing devices get listed first. This has the effect of making them
preferred over back-facing cameras in case no facing-related constraints are
given.

Bug: 814298
Change-Id: I366475903693401c64ed7ff3f65d39536d6c13ba
Reviewed-on: https://chromium-review.googlesource.com/1025213Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarWeiyong Yao <braveyao@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Commit-Queue: Christian Fremerey <chfremer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553665}
parent cd8d48e7
......@@ -8,6 +8,8 @@
namespace media {
// Facing mode for video capture.
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.media
enum VideoFacingMode {
MEDIA_VIDEO_FACING_NONE = 0,
MEDIA_VIDEO_FACING_USER,
......
......@@ -41,6 +41,7 @@ generate_jni("capture_jni_headers") {
java_cpp_enum("media_java_enums_srcjar") {
sources = [
"../../../base/video_facing.h",
"../video_capture_device_descriptor.h",
"photo_capabilities.h",
"video_capture_device_android.h",
......
......@@ -188,6 +188,22 @@ public class VideoCaptureCamera
return VideoCaptureApi.ANDROID_API1;
}
static int getFacingMode(int id) {
android.hardware.Camera.CameraInfo cameraInfo = VideoCaptureCamera.getCameraInfo(id);
if (cameraInfo == null) {
return VideoFacingMode.MEDIA_VIDEO_FACING_NONE;
}
switch (cameraInfo.facing) {
case android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT:
return VideoFacingMode.MEDIA_VIDEO_FACING_USER;
case android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK:
return VideoFacingMode.MEDIA_VIDEO_FACING_ENVIRONMENT;
default:
return VideoFacingMode.MEDIA_VIDEO_FACING_NONE;
}
}
static String getName(int id) {
android.hardware.Camera.CameraInfo cameraInfo = VideoCaptureCamera.getCameraInfo(id);
if (cameraInfo == null) return null;
......
......@@ -615,6 +615,23 @@ public class VideoCaptureCamera2 extends VideoCapture {
}
}
static int getFacingMode(int id) {
final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(id);
if (cameraCharacteristics == null) {
return VideoFacingMode.MEDIA_VIDEO_FACING_NONE;
}
final int facing = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
switch (facing) {
case CameraCharacteristics.LENS_FACING_FRONT:
return VideoFacingMode.MEDIA_VIDEO_FACING_USER;
case CameraCharacteristics.LENS_FACING_BACK:
return VideoFacingMode.MEDIA_VIDEO_FACING_ENVIRONMENT;
default:
return VideoFacingMode.MEDIA_VIDEO_FACING_NONE;
}
}
static String getName(int id) {
final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(id);
if (cameraCharacteristics == null) return null;
......
......@@ -88,6 +88,14 @@ class VideoCaptureFactory {
return VideoCaptureCamera.getCaptureApiType(id);
}
@CalledByNative
static int getFacingMode(int id) {
if (isLReleaseOrLater() && !VideoCaptureCamera2.isLegacyDevice(id)) {
return VideoCaptureCamera2.getFacingMode(id);
}
return VideoCaptureCamera.getFacingMode(id);
}
@CalledByNative
static String getDeviceName(int id) {
if (isLReleaseOrLater() && !VideoCaptureCamera2.isLegacyDevice(id)) {
......
......@@ -70,6 +70,8 @@ void VideoCaptureDeviceFactoryAndroid::GetDeviceDescriptors(
const int capture_api_type =
Java_VideoCaptureFactory_getCaptureApiType(env, camera_id);
const int facing_mode =
Java_VideoCaptureFactory_getFacingMode(env, camera_id);
const std::string display_name =
base::android::ConvertJavaStringToUTF8(device_name);
const std::string device_id = base::IntToString(camera_id);
......@@ -77,9 +79,20 @@ void VideoCaptureDeviceFactoryAndroid::GetDeviceDescriptors(
// Android cameras are not typically USB devices, and the model_id is
// currently only used for USB model identifiers, so this implementation
// just indicates an unknown device model (by not providing one).
device_descriptors->emplace_back(
display_name, device_id,
static_cast<VideoCaptureApi>(capture_api_type));
VideoCaptureDeviceDescriptor descriptor(
display_name, device_id, "" /*model_id*/,
static_cast<VideoCaptureApi>(capture_api_type),
VideoCaptureTransportType::OTHER_TRANSPORT,
static_cast<VideoFacingMode>(facing_mode));
// We put user-facing devices to the front of the list in order to make
// them by-default preferred over environment-facing ones when no other
// constraints for device selection are given.
if (facing_mode == MEDIA_VIDEO_FACING_USER)
device_descriptors->insert(device_descriptors->begin(),
std::move(descriptor));
else
device_descriptors->emplace_back(std::move(descriptor));
DVLOG(1) << __func__ << ": camera "
<< "device_name=" << display_name << ", unique_id=" << device_id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment