use of android.hardware.camera2.TotalCaptureResult in project android_frameworks_base by DirtyUnicorns.
the class Camera2ReprocessCaptureTest method doMixedReprocessBurstCapture.
/**
* Do a burst of captures that are mixed with regular and reprocess captures.
*
* @param isReprocessCaptures An array whose elements indicate whether it's a reprocess capture
* request. If the element is true, it represents a reprocess capture
* request. If the element is false, it represents a regular capture
* request. The size of the array is the number of capture requests
* in the burst.
*/
private ImageResultHolder[] doMixedReprocessBurstCapture(boolean[] isReprocessCaptures) throws Exception {
if (isReprocessCaptures == null || isReprocessCaptures.length <= 0) {
throw new IllegalArgumentException("isReprocessCaptures must have at least 1 capture.");
}
boolean hasReprocessRequest = false;
boolean hasRegularRequest = false;
TotalCaptureResult[] results = new TotalCaptureResult[isReprocessCaptures.length];
for (int i = 0; i < isReprocessCaptures.length; i++) {
// submit a capture and get the result if this entry is a reprocess capture.
if (isReprocessCaptures[i]) {
results[i] = submitCaptureRequest(mFirstImageReader.getSurface(), /*inputResult*/
null);
mImageWriter.queueInputImage(mFirstImageReaderListener.getImage(CAPTURE_TIMEOUT_MS));
hasReprocessRequest = true;
} else {
hasRegularRequest = true;
}
}
Surface[] outputSurfaces = new Surface[isReprocessCaptures.length];
for (int i = 0; i < isReprocessCaptures.length; i++) {
outputSurfaces[i] = getReprocessOutputImageReader().getSurface();
}
TotalCaptureResult[] finalResults = submitMixedCaptureBurstRequest(outputSurfaces, results);
ImageResultHolder[] holders = new ImageResultHolder[isReprocessCaptures.length];
for (int i = 0; i < isReprocessCaptures.length; i++) {
Image image = getReprocessOutputImageReaderListener().getImage(CAPTURE_TIMEOUT_MS);
if (hasReprocessRequest && hasRegularRequest) {
// If there are mixed requests, images and results may not be in the same order.
for (int j = 0; j < finalResults.length; j++) {
if (finalResults[j] != null && finalResults[j].get(CaptureResult.SENSOR_TIMESTAMP) == image.getTimestamp()) {
holders[i] = new ImageResultHolder(image, finalResults[j]);
finalResults[j] = null;
break;
}
}
assertNotNull("Cannot find a result matching output image's timestamp: " + image.getTimestamp(), holders[i]);
} else {
// If no mixed requests, images and results should be in the same order.
holders[i] = new ImageResultHolder(image, finalResults[i]);
}
}
return holders;
}
use of android.hardware.camera2.TotalCaptureResult in project android_frameworks_base by DirtyUnicorns.
the class Camera2ReprocessCaptureTest method testReprocessRequestKeys.
/**
* Test the following keys in reprocess results match the keys in reprocess requests:
* 1. EDGE_MODE
* 2. NOISE_REDUCTION_MODE
* 3. REPROCESS_EFFECTIVE_EXPOSURE_FACTOR (only for YUV reprocess)
*/
private void testReprocessRequestKeys(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat) throws Exception {
if (VERBOSE) {
Log.v(TAG, "testReprocessRequestKeys: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat);
}
final Integer[] EDGE_MODES = { CaptureRequest.EDGE_MODE_FAST, CaptureRequest.EDGE_MODE_HIGH_QUALITY, CaptureRequest.EDGE_MODE_OFF, CaptureRequest.EDGE_MODE_ZERO_SHUTTER_LAG };
final Integer[] NR_MODES = { CaptureRequest.NOISE_REDUCTION_MODE_HIGH_QUALITY, CaptureRequest.NOISE_REDUCTION_MODE_OFF, CaptureRequest.NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG, CaptureRequest.NOISE_REDUCTION_MODE_FAST };
final Float[] EFFECTIVE_EXP_FACTORS = { null, 1.0f, 2.5f, 4.0f };
int numFrames = EDGE_MODES.length;
try {
setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat, numFrames);
setupReprocessableSession(/*previewSurface*/
null, numFrames);
// Prepare reprocess capture requests.
ArrayList<CaptureRequest> reprocessRequests = new ArrayList<>(numFrames);
for (int i = 0; i < numFrames; i++) {
TotalCaptureResult result = submitCaptureRequest(mFirstImageReader.getSurface(), /*inputResult*/
null);
mImageWriter.queueInputImage(mFirstImageReaderListener.getImage(CAPTURE_TIMEOUT_MS));
CaptureRequest.Builder builder = mCamera.createReprocessCaptureRequest(result);
builder.addTarget(getReprocessOutputImageReader().getSurface());
// Set reprocess request keys
builder.set(CaptureRequest.EDGE_MODE, EDGE_MODES[i]);
builder.set(CaptureRequest.NOISE_REDUCTION_MODE, NR_MODES[i]);
if (inputFormat == ImageFormat.YUV_420_888) {
builder.set(CaptureRequest.REPROCESS_EFFECTIVE_EXPOSURE_FACTOR, EFFECTIVE_EXP_FACTORS[i]);
}
reprocessRequests.add(builder.build());
}
// Submit reprocess requests.
SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
mSession.captureBurst(reprocessRequests, captureCallback, mHandler);
TotalCaptureResult[] reprocessResults = captureCallback.getTotalCaptureResultsForRequests(reprocessRequests, CAPTURE_TIMEOUT_FRAMES);
for (int i = 0; i < numFrames; i++) {
// Verify result's keys
Integer resultEdgeMode = reprocessResults[i].get(CaptureResult.EDGE_MODE);
Integer resultNoiseReductionMode = reprocessResults[i].get(CaptureResult.NOISE_REDUCTION_MODE);
assertEquals("Reprocess result edge mode (" + resultEdgeMode + ") doesn't match requested edge mode (" + EDGE_MODES[i] + ")", resultEdgeMode, EDGE_MODES[i]);
assertEquals("Reprocess result noise reduction mode (" + resultNoiseReductionMode + ") doesn't match requested noise reduction mode (" + NR_MODES[i] + ")", resultNoiseReductionMode, NR_MODES[i]);
if (inputFormat == ImageFormat.YUV_420_888) {
Float resultEffectiveExposureFactor = reprocessResults[i].get(CaptureResult.REPROCESS_EFFECTIVE_EXPOSURE_FACTOR);
assertEquals("Reprocess effective exposure factor (" + resultEffectiveExposureFactor + ") doesn't match requested " + "effective exposure factor (" + EFFECTIVE_EXP_FACTORS[i] + ")", resultEffectiveExposureFactor, EFFECTIVE_EXP_FACTORS[i]);
}
}
} finally {
closeReprossibleSession();
closeImageReaders();
}
}
use of android.hardware.camera2.TotalCaptureResult in project android_frameworks_base by DirtyUnicorns.
the class Camera2ReprocessCaptureTest method testReprocessJpegExif.
/**
* Test JPEG tags for reprocess requests. Reprocess result's JPEG tags and JPEG image's tags
* match reprocess request's JPEG tags.
*/
private void testReprocessJpegExif(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize) throws Exception {
if (VERBOSE) {
Log.v(TAG, "testReprocessJpegExif: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize);
}
Size[] thumbnailSizes = mStaticInfo.getAvailableThumbnailSizesChecked();
Size[] testThumbnailSizes = new Size[EXIF_TEST_DATA.length];
Arrays.fill(testThumbnailSizes, thumbnailSizes[thumbnailSizes.length - 1]);
// Make sure thumbnail size (0, 0) is covered.
testThumbnailSizes[0] = new Size(0, 0);
try {
setupImageReaders(inputSize, inputFormat, reprocessOutputSize, ImageFormat.JPEG, EXIF_TEST_DATA.length);
setupReprocessableSession(/*previewSurface*/
null, EXIF_TEST_DATA.length);
// Prepare reprocess capture requests.
ArrayList<CaptureRequest> reprocessRequests = new ArrayList<>(EXIF_TEST_DATA.length);
for (int i = 0; i < EXIF_TEST_DATA.length; i++) {
TotalCaptureResult result = submitCaptureRequest(mFirstImageReader.getSurface(), /*inputResult*/
null);
mImageWriter.queueInputImage(mFirstImageReaderListener.getImage(CAPTURE_TIMEOUT_MS));
CaptureRequest.Builder builder = mCamera.createReprocessCaptureRequest(result);
builder.addTarget(getReprocessOutputImageReader().getSurface());
// set jpeg keys
setJpegKeys(builder, EXIF_TEST_DATA[i], testThumbnailSizes[i], mCollector);
reprocessRequests.add(builder.build());
}
// Submit reprocess requests.
SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
mSession.captureBurst(reprocessRequests, captureCallback, mHandler);
TotalCaptureResult[] reprocessResults = captureCallback.getTotalCaptureResultsForRequests(reprocessRequests, CAPTURE_TIMEOUT_FRAMES);
for (int i = 0; i < EXIF_TEST_DATA.length; i++) {
// Verify output image's and result's JPEG EXIF data.
Image image = getReprocessOutputImageReaderListener().getImage(CAPTURE_TIMEOUT_MS);
verifyJpegKeys(image, reprocessResults[i], reprocessOutputSize, testThumbnailSizes[i], EXIF_TEST_DATA[i], mStaticInfo, mCollector);
image.close();
}
} finally {
closeReprossibleSession();
closeImageReaders();
}
}
use of android.hardware.camera2.TotalCaptureResult in project android_frameworks_base by DirtyUnicorns.
the class CameraMetadata method getKeysStatic.
/**
* Return a list of all the Key<?> that are declared as a field inside of the class
* {@code type}.
*
* <p>
* Optionally, if {@code instance} is not null, then filter out any keys with null values.
* </p>
*
* <p>
* Optionally, if {@code filterTags} is not {@code null}, then filter out any keys
* whose native {@code tag} is not in {@code filterTags}. The {@code filterTags} array will be
* sorted as a side effect.
* </p>
*/
/*package*/
@SuppressWarnings("unchecked")
static <TKey> ArrayList<TKey> getKeysStatic(Class<?> type, Class<TKey> keyClass, CameraMetadata<TKey> instance, int[] filterTags) {
if (DEBUG)
Log.v(TAG, "getKeysStatic for " + type);
// TotalCaptureResult does not have any of the keys on it, use CaptureResult instead
if (type.equals(TotalCaptureResult.class)) {
type = CaptureResult.class;
}
if (filterTags != null) {
Arrays.sort(filterTags);
}
ArrayList<TKey> keyList = new ArrayList<TKey>();
Field[] fields = type.getDeclaredFields();
for (Field field : fields) {
// Filter for Keys that are public
if (field.getType().isAssignableFrom(keyClass) && (field.getModifiers() & Modifier.PUBLIC) != 0) {
TKey key;
try {
key = (TKey) field.get(instance);
} catch (IllegalAccessException e) {
throw new AssertionError("Can't get IllegalAccessException", e);
} catch (IllegalArgumentException e) {
throw new AssertionError("Can't get IllegalArgumentException", e);
}
if (instance == null || instance.getProtected(key) != null) {
if (shouldKeyBeAdded(key, field, filterTags)) {
keyList.add(key);
if (DEBUG) {
Log.v(TAG, "getKeysStatic - key was added - " + key);
}
} else if (DEBUG) {
Log.v(TAG, "getKeysStatic - key was filtered - " + key);
}
}
}
}
ArrayList<TKey> vendorKeys = CameraMetadataNative.getAllVendorKeys(keyClass);
if (vendorKeys != null) {
for (TKey k : vendorKeys) {
String keyName;
if (k instanceof CaptureRequest.Key<?>) {
keyName = ((CaptureRequest.Key<?>) k).getName();
} else if (k instanceof CaptureResult.Key<?>) {
keyName = ((CaptureResult.Key<?>) k).getName();
} else if (k instanceof CameraCharacteristics.Key<?>) {
keyName = ((CameraCharacteristics.Key<?>) k).getName();
} else {
continue;
}
if (filterTags == null || Arrays.binarySearch(filterTags, CameraMetadataNative.getTag(keyName)) >= 0) {
keyList.add(k);
}
}
}
return keyList;
}
use of android.hardware.camera2.TotalCaptureResult in project android_frameworks_base by AOSPA.
the class Camera2ReprocessCaptureTest method testReprocessAbort.
/**
* Test aborting a burst reprocess capture and multiple single reprocess captures.
*/
private void testReprocessAbort(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat) throws Exception {
if (VERBOSE) {
Log.v(TAG, "testReprocessAbort: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat);
}
try {
setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat, NUM_REPROCESS_CAPTURES);
setupReprocessableSession(/*previewSurface*/
null, NUM_REPROCESS_CAPTURES);
// Test two cases: submitting reprocess requests one by one and in a burst.
boolean[] submitInBursts = { false, true };
for (boolean submitInBurst : submitInBursts) {
// Prepare reprocess capture requests.
ArrayList<CaptureRequest> reprocessRequests = new ArrayList<>(NUM_REPROCESS_CAPTURES);
for (int i = 0; i < NUM_REPROCESS_CAPTURES; i++) {
TotalCaptureResult result = submitCaptureRequest(mFirstImageReader.getSurface(), /*inputResult*/
null);
mImageWriter.queueInputImage(mFirstImageReaderListener.getImage(CAPTURE_TIMEOUT_MS));
CaptureRequest.Builder builder = mCamera.createReprocessCaptureRequest(result);
builder.addTarget(getReprocessOutputImageReader().getSurface());
reprocessRequests.add(builder.build());
}
SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
// Submit reprocess capture requests.
if (submitInBurst) {
mSession.captureBurst(reprocessRequests, captureCallback, mHandler);
} else {
for (CaptureRequest request : reprocessRequests) {
mSession.capture(request, captureCallback, mHandler);
}
}
// Abort after getting the first result
TotalCaptureResult reprocessResult = captureCallback.getTotalCaptureResultForRequest(reprocessRequests.get(0), CAPTURE_TIMEOUT_FRAMES);
mSession.abortCaptures();
// Wait until the session is ready again.
mSessionListener.getStateWaiter().waitForState(BlockingSessionCallback.SESSION_READY, SESSION_CLOSE_TIMEOUT_MS);
// Gather all failed requests.
ArrayList<CaptureFailure> failures = captureCallback.getCaptureFailures(NUM_REPROCESS_CAPTURES - 1);
ArrayList<CaptureRequest> failedRequests = new ArrayList<>();
for (CaptureFailure failure : failures) {
failedRequests.add(failure.getRequest());
}
// For each request that didn't fail must have a valid result.
for (int i = 1; i < reprocessRequests.size(); i++) {
CaptureRequest request = reprocessRequests.get(i);
if (!failedRequests.contains(request)) {
captureCallback.getTotalCaptureResultForRequest(request, CAPTURE_TIMEOUT_FRAMES);
}
}
// Drain the image reader listeners.
mFirstImageReaderListener.drain();
if (!mShareOneImageReader) {
mSecondImageReaderListener.drain();
}
// Make sure all input surfaces are released.
for (int i = 0; i < NUM_REPROCESS_CAPTURES; i++) {
mImageWriterListener.waitForImageReleased(CAPTURE_TIMEOUT_MS);
}
}
} finally {
closeReprossibleSession();
closeImageReaders();
}
}
Aggregations