Java Code Examples for android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY

The following examples show how to use android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY . 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: CameraInfo.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
private static String getLevel(Integer level) {
    if (level == null) {
        return UNKNOWN;
    }
    switch (level) {
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY:
            return "LEGACY";
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_3:
            return "LEVEL_3";
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL:
            return "EXTERNAL";
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL:
            return "FULL";
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED:
            return "LIMITED";
        default:
            return UNKNOWN + "-" + level;
    }
}
 
Example 2
Source File: Camera2Enumerator.java    From VideoCRE with MIT License 6 votes vote down vote up
/**
 * Checks if API is supported and all cameras have better than legacy support.
 */
public static boolean isSupported(Context context) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    return false;
  }

  CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
  try {
    String[] cameraIds = cameraManager.getCameraIdList();
    for (String id : cameraIds) {
      CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(id);
      if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)
          == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        return false;
      }
    }
    // On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
    // catch statement with an Exception from a newer API, even if the code is never executed.
    // https://code.google.com/p/android/issues/detail?id=209129
  } catch (/* CameraAccessException */ AndroidException e) {
    Logging.e(TAG, "Camera access exception: " + e);
    return false;
  }
  return true;
}
 
Example 3
Source File: Camera2Source.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 6 votes vote down vote up
public boolean isCamera2Native() {
    try {
        if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
        manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
        mCameraId = manager.getCameraIdList()[mFacing];
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
        //CHECK CAMERA HARDWARE LEVEL. IF CAMERA2 IS NOT NATIVELY SUPPORTED, GO BACK TO CAMERA1
        Integer deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
        return deviceLevel != null && (deviceLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY);
    } catch (CameraAccessException ex) {
        return false;
    } catch (NullPointerException e) {
        return false;
    } catch (ArrayIndexOutOfBoundsException ez) {
        return false;
    }
}
 
Example 4
Source File: OneCameraCharacteristicsImpl.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
@Override
public SupportedHardwareLevel getSupportedHardwareLevel()
{
    Integer supportedHardwareLevel = mCameraCharacteristics
            .get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
    // If this fails, it is a framework bug, per API documentation.
    checkNotNull(supportedHardwareLevel, "INFO_SUPPORTED_HARDWARE_LEVEL not found");
    switch (supportedHardwareLevel)
    {
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL:
            return SupportedHardwareLevel.FULL;
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED:
            return SupportedHardwareLevel.LIMITED;
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY:
            return SupportedHardwareLevel.LEGACY;
        default:
            if (supportedHardwareLevel >
                    CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL)
            {
                Log.i(TAG, "Unknown higher hardware level mapped to FULL: "
                        + supportedHardwareLevel);
                return SupportedHardwareLevel.FULL;
            }
            throw new IllegalStateException("Invalid value for INFO_SUPPORTED_HARDWARE_LEVEL");
    }
}
 
Example 5
Source File: AndroidCamera2AgentImpl.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
@Override
public void onOpened(CameraDevice camera) {
    mCamera = camera;
    if (mOpenCallback != null) {
        try {
            CameraCharacteristics props =
                    mCameraManager.getCameraCharacteristics(mCameraId);
            CameraDeviceInfo.Characteristics characteristics =
                    getCameraDeviceInfo().getCharacteristics(mCameraIndex);
            mCameraProxy = new AndroidCamera2ProxyImpl(AndroidCamera2AgentImpl.this,
                    mCameraIndex, mCamera, characteristics, props);
            mPersistentSettings = new Camera2RequestSettingsSet();
            mActiveArray =
                    props.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
            mLegacyDevice =
                    props.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) ==
                            CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY;
            changeState(AndroidCamera2StateHolder.CAMERA_UNCONFIGURED);
            mOpenCallback.onCameraOpened(mCameraProxy);
        } catch (CameraAccessException ex) {
            mOpenCallback.onDeviceOpenFailure(mCameraIndex,
                    generateHistoryString(mCameraIndex));
        }
    }
}
 
Example 6
Source File: CameraActivity.java    From tensorflow-classifier-android with Apache License 2.0 5 votes vote down vote up
private boolean isHardwareLevelSupported(
    CameraCharacteristics characteristics, int requiredLevel) {
  int deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
  if (deviceLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
    return requiredLevel == deviceLevel;
  }
  // deviceLevel is not LEGACY, can use numerical sort
  return requiredLevel <= deviceLevel;
}
 
Example 7
Source File: BaseCameraActivity.java    From fritz-examples with MIT License 5 votes vote down vote up
private boolean isHardwareLevelSupported(
        CameraCharacteristics characteristics, int requiredLevel) {
    int deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
    if (deviceLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        return requiredLevel == deviceLevel;
    }
    // deviceLevel is not LEGACY, can use numerical sort
    return requiredLevel <= deviceLevel;
}
 
Example 8
Source File: BaseCameraActivity.java    From fritz-examples with MIT License 5 votes vote down vote up
private boolean isHardwareLevelSupported(
        CameraCharacteristics characteristics, int requiredLevel) {
    int deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
    if (deviceLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        return requiredLevel == deviceLevel;
    }
    // deviceLevel is not LEGACY, can use numerical sort
    return requiredLevel <= deviceLevel;
}
 
Example 9
Source File: BaseCameraActivity.java    From fritz-examples with MIT License 5 votes vote down vote up
private boolean isHardwareLevelSupported(
        CameraCharacteristics characteristics, int requiredLevel) {
    int deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
    if (deviceLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        return requiredLevel == deviceLevel;
    }
    // deviceLevel is not LEGACY, can use numerical sort
    return requiredLevel <= deviceLevel;
}
 
Example 10
Source File: BaseCameraActivity.java    From fritz-examples with MIT License 5 votes vote down vote up
private boolean isHardwareLevelSupported(
        CameraCharacteristics characteristics, int requiredLevel) {
    int deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
    if (deviceLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        return requiredLevel == deviceLevel;
    }
    // deviceLevel is not LEGACY, can use numerical sort
    return requiredLevel <= deviceLevel;
}
 
Example 11
Source File: BaseCameraActivity.java    From fritz-examples with MIT License 5 votes vote down vote up
private boolean isHardwareLevelSupported(
        CameraCharacteristics characteristics, int requiredLevel) {
    int deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
    if (deviceLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        return requiredLevel == deviceLevel;
    }
    // deviceLevel is not LEGACY, can use numerical sort
    return requiredLevel <= deviceLevel;
}
 
Example 12
Source File: BaseCameraActivity.java    From fritz-examples with MIT License 5 votes vote down vote up
private boolean isHardwareLevelSupported(
        CameraCharacteristics characteristics, int requiredLevel) {
    int deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
    if (deviceLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        return requiredLevel == deviceLevel;
    }
    // deviceLevel is not LEGACY, can use numerical sort
    return requiredLevel <= deviceLevel;
}
 
Example 13
Source File: Camera2Source.java    From Camera2Vision with Apache License 2.0 5 votes vote down vote up
public boolean isCamera2Native() {
    try {
        if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {return false;}
        manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
        mCameraId = manager.getCameraIdList()[mFacing];
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
        //CHECK CAMERA HARDWARE LEVEL. IF CAMERA2 IS NOT NATIVELY SUPPORTED, GO BACK TO CAMERA1
        Integer deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
        return deviceLevel != null && (deviceLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY);
    }
    catch (CameraAccessException ex) {return false;}
    catch (NullPointerException e) {return false;}
    catch (ArrayIndexOutOfBoundsException ez) {return false;}
}
 
Example 14
Source File: Camera2Enumerator.java    From VideoCRE with MIT License 5 votes vote down vote up
static List<Size> getSupportedSizes(CameraCharacteristics cameraCharacteristics) {
  final StreamConfigurationMap streamMap =
      cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
  final int supportLevel =
      cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);

  final android.util.Size[] nativeSizes = streamMap.getOutputSizes(SurfaceTexture.class);
  final List<Size> sizes = convertSizes(nativeSizes);

  // Video may be stretched pre LMR1 on legacy implementations.
  // Filter out formats that have different aspect ratio than the sensor array.
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1
      && supportLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
    final Rect activeArraySize =
        cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
    final ArrayList<Size> filteredSizes = new ArrayList<Size>();

    for (Size size : sizes) {
      if (activeArraySize.width() * size.height == activeArraySize.height() * size.width) {
        filteredSizes.add(size);
      }
    }

    return filteredSizes;
  } else {
    return sizes;
  }
}
 
Example 15
Source File: CameraActivity.java    From dbclf with Apache License 2.0 5 votes vote down vote up
private boolean isHardwareLevelSupported(
        CameraCharacteristics characteristics, int requiredLevel) {
    int deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
    if (deviceLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        return requiredLevel == deviceLevel;
    }
    // deviceLevel is not LEGACY, can use numerical sort
    return requiredLevel <= deviceLevel;
}
 
Example 16
Source File: CameraHelper.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean hasCamera2(Context context) {
    if (context == null) return false;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return false;
    try {
        CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
        String[] idList = manager.getCameraIdList();
        boolean notNull = true;
        if (idList.length == 0) {
            notNull = false;
        } else {
            for (final String str : idList) {
                if (str == null || str.trim().isEmpty()) {
                    notNull = false;
                    break;
                }
                final CameraCharacteristics characteristics = manager.getCameraCharacteristics(str);

                final int supportLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
                if (supportLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
                    notNull = false;
                    break;
                }
            }
        }
        return notNull;
    } catch (Throwable ignore) {
        return false;
    }
}
 
Example 17
Source File: LollipopCamera.java    From LiveMultimedia with Apache License 2.0 5 votes vote down vote up
private String determineCameraApiSupport(int level) {
    String support;
    if (level == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        support = LEGACY;
    }  else if (level == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED) {
        support = LIMITED;
    }  else if (level == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL) {
        support = FULL;
    } else {
        support = LEGACY;
    }
    return support;
}
 
Example 18
Source File: OneCameraFeatureConfigCreator.java    From Camera2 with Apache License 2.0 4 votes vote down vote up
private static Function<CameraCharacteristics, CaptureSupportLevel> buildCaptureModuleDetector(
        final ContentResolver contentResolver)
{
    return new Function<CameraCharacteristics, CaptureSupportLevel>()
    {
        @Override
        public CaptureSupportLevel apply(CameraCharacteristics characteristics)
        {
            // If a capture support level override exists, use it. Otherwise
            // dynamically check the capabilities of the current device.
            Optional<CaptureSupportLevel> override =
                    getCaptureSupportLevelOverride(characteristics, contentResolver);
            if (override.isPresent())
            {
                Log.i(TAG, "Camera support level override: " + override.get().name());
                return override.get();
            }

            Integer supportedLevel = characteristics
                    .get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);

            // A hardware level should always be supported, so we should
            // never have to return here. If no hardware level is supported
            // on a LEGACY device, the LIMITED_JPEG fallback will not work.
            if (supportedLevel == null)
            {
                Log.e(TAG, "Device does not report supported hardware level.");
                return CaptureSupportLevel.LIMITED_JPEG;
            }

            // LEGACY_JPEG is the ONLY mode that is supported on LEGACY
            // devices.
            if (supportedLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY)
            {
                return CaptureSupportLevel.LEGACY_JPEG;
            }

            // No matter if L or L MR1, the N5 does not currently support
            // ZSL due to HAL bugs. The latest one causes random preview
            // freezes even on MR1, see b/19565931.
            if (ApiHelper.IS_NEXUS_5)
            {
                return CaptureSupportLevel.LIMITED_JPEG;
            }

            if (ApiHelper.IS_NEXUS_6)
            {
                if (ApiHelper.isLMr1OrHigher())
                {
                    // Although front-facing cameras on the N6 (and N5) are not advertised as
                    // FULL, they can do ZSL. We might want to change the check for ZSL
                    // according to b/19625916.
                    return CaptureSupportLevel.ZSL;
                } else
                {
                    // On a non-LEGACY N6 (or N5) prior to Lollipop MR1 we fall back to
                    // LIMITED_JPEG due to HAL bugs.
                    return CaptureSupportLevel.LIMITED_JPEG;
                }
            }

            // On FULL devices starting with L-MR1 we can run ZSL if private reprocessing
            // or YUV reprocessing is supported.
            if (supportedLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL ||
                    supportedLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_3)
            {
                if (supportsReprocessing(characteristics))
                {
                    return CaptureSupportLevel.ZSL;
                } else
                {
                    return CaptureSupportLevel.LIMITED_YUV;
                }
            }

            // On LIMITED devices starting with L-MR1 we run a simple YUV
            // capture mode.
            if (supportedLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED)
            {
                return CaptureSupportLevel.LIMITED_YUV;
            }

            // We should never get here. If we do, let's fall back to a mode
            // that should work on all non-LEGACY devices.
            Log.e(TAG, "Unknown support level: " + supportedLevel);
            return CaptureSupportLevel.LIMITED_JPEG;
        }
    };
}
 
Example 19
Source File: Camera2Fragment.java    From 361Camera with Apache License 2.0 2 votes vote down vote up
/**
 * Check if we are using a device that only supports the LEGACY hardware level.
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 *
 * @return true if this is a legacy device.
 */
private boolean isLegacyLocked() {
    return mCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) ==
            CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY;
}
 
Example 20
Source File: Camera2RawFragment.java    From android-Camera2Raw with Apache License 2.0 2 votes vote down vote up
/**
 * Check if we are using a device that only supports the LEGACY hardware level.
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 *
 * @return true if this is a legacy device.
 */
private boolean isLegacyLocked() {
    return mCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) ==
            CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY;
}