Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
getSupportedCameraIds api method introduced on android, fixes #145
Browse files Browse the repository at this point in the history
  • Loading branch information
tanersener committed May 28, 2019
1 parent f16edb5 commit 0733ca2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
42 changes: 41 additions & 1 deletion android/app/src/main/java/com/arthenica/mobileffmpeg/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@
package com.arthenica.mobileffmpeg;

import android.content.Context;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata;
import android.os.Build;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import static android.content.Context.CAMERA_SERVICE;
import static com.arthenica.mobileffmpeg.FFmpeg.getBuildDate;
import static com.arthenica.mobileffmpeg.FFmpeg.getVersion;

Expand Down Expand Up @@ -438,7 +444,7 @@ public static List<String> getExternalLibraries() {
*
* <p>Please note that creator is responsible of closing created pipes.
*
* @param context application context to access application data
* @param context application context
* @return the full path of named pipe
*/
public static String registerNewFFmpegPipe(final Context context) {
Expand Down Expand Up @@ -535,6 +541,40 @@ static String getSystemCommandOutput() {
return systemCommandOutputReference.get().toString();
}

/**
* Returns the list of camera ids supported.
*
* @param context application context
* @return the list of camera ids supported or an empty list if no supported camera is found
*/
public static List<String> getSupportedCameraIds(final Context context) {
final List<String> detectedCameraIdList = new ArrayList<>();

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
try {
final CameraManager manager = (CameraManager) context.getSystemService(CAMERA_SERVICE);
if (manager != null) {
final String[] cameraIdList = manager.getCameraIdList();

for (String cameraId : cameraIdList) {
final CameraCharacteristics chars = manager.getCameraCharacteristics(cameraId);
final Integer cameraSupport = chars.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);

if (cameraSupport != null && cameraSupport == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
Log.d(TAG, "Detected camera with id " + cameraId + " has not supported LEGACY hardware level.");
} else if (cameraSupport != null) {
detectedCameraIdList.add(cameraId);
}
}
}
} catch (final CameraAccessException e) {
Log.w(TAG, "Detecting camera ids failed.", e);
}
}

return detectedCameraIdList;
}

/**
* <p>Enables native redirection. Necessary for log and statistics callback functions.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand Down Expand Up @@ -139,6 +140,9 @@ protected void onCreate(final Bundle savedInstanceState) {
} catch (final IOException e) {
Log.e(TAG, "Font registration failed.", e);
}

Log.d(TAG, "Listing supported camera ids.");
listSupportedCameraIds();
}

@Override
Expand All @@ -152,7 +156,7 @@ protected void onDestroy() {
* <p>Starts a new asynchronous FFmpeg operation with arguments provided.
*
* @param executeCallback callback function to receive result of this execution
* @param arguments FFmpeg command options/arguments
* @param arguments FFmpeg command options/arguments
*/
public static void executeAsync(final ExecuteCallback executeCallback, final String arguments) {
final AsyncExecuteTask asyncCommandTask = new AsyncExecuteTask(executeCallback);
Expand Down Expand Up @@ -252,4 +256,15 @@ protected void registerAppFont() throws IOException {
// Config.setFontDirectory(this, cacheDirectory.getAbsolutePath(), null);
}

protected void listSupportedCameraIds() {
final List<String> supportedCameraIds = Config.getSupportedCameraIds(this);
if (supportedCameraIds.size() == 0) {
android.util.Log.d(MainActivity.TAG, "No supported cameras found.");
} else {
for (String supportedCameraId : supportedCameraIds) {
android.util.Log.d(MainActivity.TAG, "Supported camera detected: " + supportedCameraId);
}
}
}

}

0 comments on commit 0733ca2

Please sign in to comment.