Camera2: Fix StreamConfigurationMap#isOutputSupportedFor for depth

Need to check the right configuration list if the format is a
depth format.

Also refactor code slightly to use SurfaceUtils when possible.

Bug: 21902551
Change-Id: Icca2e81d8144bede46ad9f117d5e010ed409887c
This commit is contained in:
Eino-Ville Talvala
2015-06-19 17:29:14 -07:00
parent 0819c75680
commit e365120aae
4 changed files with 66 additions and 13 deletions

View File

@@ -605,6 +605,14 @@ public class LegacyCameraDevice implements AutoCloseable {
return LegacyExceptionUtils.throwOnError(nativeDetectSurfaceType(surface));
}
/**
* Query the surface for its currently configured dataspace
*/
public static int detectSurfaceDataspace(Surface surface) throws BufferQueueAbandonedException {
checkNotNull(surface);
return LegacyExceptionUtils.throwOnError(nativeDetectSurfaceDataspace(surface));
}
static void configureSurface(Surface surface, int width, int height,
int pixelFormat) throws BufferQueueAbandonedException {
checkNotNull(surface);
@@ -702,6 +710,8 @@ public class LegacyCameraDevice implements AutoCloseable {
private static native int nativeDetectSurfaceType(Surface surface);
private static native int nativeDetectSurfaceDataspace(Surface surface);
private static native int nativeDetectSurfaceDimens(Surface surface,
/*out*/int[/*2*/] dimens);

View File

@@ -22,9 +22,9 @@ import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.utils.HashCodeHelpers;
import android.hardware.camera2.utils.SurfaceUtils;
import android.hardware.camera2.legacy.LegacyCameraDevice;
import android.hardware.camera2.legacy.LegacyMetadataMapper;
import android.hardware.camera2.legacy.LegacyExceptionUtils.BufferQueueAbandonedException;
import android.view.Surface;
import android.util.Range;
import android.util.Size;
@@ -389,27 +389,24 @@ public final class StreamConfigurationMap {
public boolean isOutputSupportedFor(Surface surface) {
checkNotNull(surface, "surface must not be null");
Size surfaceSize;
int surfaceFormat = -1;
try {
surfaceSize = LegacyCameraDevice.getSurfaceSize(surface);
surfaceFormat = LegacyCameraDevice.detectSurfaceType(surface);
} catch(BufferQueueAbandonedException e) {
throw new IllegalArgumentException("Abandoned surface", e);
}
Size surfaceSize = SurfaceUtils.getSurfaceSize(surface);
int surfaceFormat = SurfaceUtils.getSurfaceFormat(surface);
int surfaceDataspace = SurfaceUtils.getSurfaceDataspace(surface);
// See if consumer is flexible.
boolean isFlexible = LegacyCameraDevice.isFlexibleConsumer(surface);
boolean isFlexible = SurfaceUtils.isFlexibleConsumer(surface);
// Override RGB formats to IMPLEMENTATION_DEFINED, b/9487482
if ((surfaceFormat >= LegacyMetadataMapper.HAL_PIXEL_FORMAT_RGBA_8888 &&
surfaceFormat <= LegacyMetadataMapper.HAL_PIXEL_FORMAT_BGRA_8888)) {
surfaceFormat = LegacyMetadataMapper.HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
surfaceFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
}
for (StreamConfiguration config : mConfigurations) {
StreamConfiguration[] configs =
surfaceDataspace != HAL_DATASPACE_DEPTH ? mConfigurations : mDepthConfigurations;
for (StreamConfiguration config : configs) {
if (config.getFormat() == surfaceFormat && config.isOutput()) {
// Mathing format, either need exact size match, or a flexible consumer
// Matching format, either need exact size match, or a flexible consumer
// and a size no bigger than MAX_DIMEN_FOR_ROUNDING
if (config.getSize().equals(surfaceSize)) {
return true;

View File

@@ -79,4 +79,30 @@ public class SurfaceUtils {
throw new IllegalArgumentException("Surface was abandoned", e);
}
}
/**
* Get the Surface dataspace.
*
* @param surface The surface to be queried for dataspace.
* @return dataspace of the surface.
*
* @throws IllegalArgumentException if the surface is already abandoned.
*/
public static int getSurfaceDataspace(Surface surface) {
try {
return LegacyCameraDevice.detectSurfaceDataspace(surface);
} catch (BufferQueueAbandonedException e) {
throw new IllegalArgumentException("Surface was abandoned", e);
}
}
/**
* Return true is the consumer is one of the consumers that can accept
* producer overrides of the default dimensions and format.
*
*/
public static boolean isFlexibleConsumer(Surface output) {
return LegacyCameraDevice.isFlexibleConsumer(output);
}
}

View File

@@ -436,6 +436,23 @@ static jint LegacyCameraDevice_nativeDetectSurfaceType(JNIEnv* env, jobject thiz
return fmt;
}
static jint LegacyCameraDevice_nativeDetectSurfaceDataspace(JNIEnv* env, jobject thiz, jobject surface) {
ALOGV("nativeDetectSurfaceDataspace");
sp<ANativeWindow> anw;
if ((anw = getNativeWindow(env, surface)) == NULL) {
ALOGE("%s: Could not retrieve native window from surface.", __FUNCTION__);
return BAD_VALUE;
}
int32_t fmt = 0;
status_t err = anw->query(anw.get(), NATIVE_WINDOW_DEFAULT_DATASPACE, &fmt);
if(err != NO_ERROR) {
ALOGE("%s: Error while querying surface dataspace %s (%d).", __FUNCTION__, strerror(-err),
err);
return err;
}
return fmt;
}
static jint LegacyCameraDevice_nativeDetectSurfaceDimens(JNIEnv* env, jobject thiz,
jobject surface, jintArray dimens) {
ALOGV("nativeGetSurfaceDimens");
@@ -717,6 +734,9 @@ static JNINativeMethod gCameraDeviceMethods[] = {
{ "nativeDetectSurfaceType",
"(Landroid/view/Surface;)I",
(void *)LegacyCameraDevice_nativeDetectSurfaceType },
{ "nativeDetectSurfaceDataspace",
"(Landroid/view/Surface;)I",
(void *)LegacyCameraDevice_nativeDetectSurfaceDataspace },
{ "nativeDetectSurfaceDimens",
"(Landroid/view/Surface;[I)I",
(void *)LegacyCameraDevice_nativeDetectSurfaceDimens },