| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.camera2.impl; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.RequiresPermission; |
| 22 |
import android.content.Context; |
| 23 |
import android.graphics.ImageFormat; |
| 24 |
import android.graphics.SurfaceTexture; |
| 25 |
import android.hardware.SyncFence; |
| 26 |
import android.hardware.camera2.CameraAccessException; |
| 27 |
import android.hardware.camera2.CameraCaptureSession; |
| 28 |
import android.hardware.camera2.CameraCharacteristics; |
| 29 |
import android.hardware.camera2.CameraDevice; |
| 30 |
import android.hardware.camera2.CameraExtensionCharacteristics; |
| 31 |
import android.hardware.camera2.CameraExtensionSession; |
| 32 |
import android.hardware.camera2.CameraManager; |
| 33 |
import android.hardware.camera2.CaptureFailure; |
| 34 |
import android.hardware.camera2.CaptureRequest; |
| 35 |
import android.hardware.camera2.CaptureResult; |
| 36 |
import android.hardware.camera2.TotalCaptureResult; |
| 37 |
import android.hardware.camera2.extension.CameraOutputConfig; |
| 38 |
import android.hardware.camera2.extension.CameraSessionConfig; |
| 39 |
import android.hardware.camera2.extension.IAdvancedExtenderImpl; |
| 40 |
import android.hardware.camera2.extension.ICaptureCallback; |
| 41 |
import android.hardware.camera2.extension.IImageProcessorImpl; |
| 42 |
import android.hardware.camera2.extension.IInitializeSessionCallback; |
| 43 |
import android.hardware.camera2.extension.IRequestCallback; |
| 44 |
import android.hardware.camera2.extension.IRequestProcessorImpl; |
| 45 |
import android.hardware.camera2.extension.ISessionProcessorImpl; |
| 46 |
import android.hardware.camera2.extension.OutputConfigId; |
| 47 |
import android.hardware.camera2.extension.OutputSurface; |
| 48 |
import android.hardware.camera2.extension.ParcelCaptureResult; |
| 49 |
import android.hardware.camera2.extension.ParcelImage; |
| 50 |
import android.hardware.camera2.extension.ParcelTotalCaptureResult; |
| 51 |
import android.hardware.camera2.extension.Request; |
| 52 |
import android.hardware.camera2.params.DynamicRangeProfiles; |
| 53 |
import android.hardware.camera2.params.ExtensionSessionConfiguration; |
| 54 |
import android.hardware.camera2.params.OutputConfiguration; |
| 55 |
import android.hardware.camera2.params.SessionConfiguration; |
| 56 |
import android.hardware.camera2.utils.SurfaceUtils; |
| 57 |
import android.media.Image; |
| 58 |
import android.media.ImageReader; |
| 59 |
import android.os.Binder; |
| 60 |
import android.os.Handler; |
| 61 |
import android.os.HandlerThread; |
| 62 |
import android.os.RemoteException; |
| 63 |
import android.util.Log; |
| 64 |
import android.util.Size; |
| 65 |
import android.view.Surface; |
| 66 |
|
| 67 |
import java.io.IOException; |
| 68 |
import java.util.ArrayList; |
| 69 |
import java.util.HashMap; |
| 70 |
import java.util.List; |
| 71 |
import java.util.Map; |
| 72 |
import java.util.concurrent.Executor; |
| 73 |
|
| 74 |
public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSession { |
| 75 |
private static final String TAG = "CameraAdvancedExtensionSessionImpl"; |
| 76 |
|
| 77 |
private final Executor mExecutor; |
| 78 |
private final CameraDevice mCameraDevice; |
| 79 |
private final long mExtensionClientId; |
| 80 |
private final Handler mHandler; |
| 81 |
private final HandlerThread mHandlerThread; |
| 82 |
private final CameraExtensionSession.StateCallback mCallbacks; |
| 83 |
private final IAdvancedExtenderImpl mAdvancedExtender; |
| 84 |
|
| 85 |
private final HashMap<Surface, CameraOutputConfig> mCameraConfigMap = new HashMap<>(); |
| 86 |
|
| 87 |
private final HashMap<Integer, ImageReader> mReaderMap = new HashMap<>(); |
| 88 |
private final RequestProcessor mRequestProcessor = new RequestProcessor(); |
| 89 |
private final int mSessionId; |
| 90 |
|
| 91 |
private Surface mClientRepeatingRequestSurface; |
| 92 |
private Surface mClientCaptureSurface; |
| 93 |
private CameraCaptureSession mCaptureSession = null; |
| 94 |
private ISessionProcessorImpl mSessionProcessor = null; |
| 95 |
private final InitializeSessionHandler mInitializeHandler; |
| 96 |
|
| 97 |
private boolean mInitialized; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
final Object mInterfaceLock; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
@RequiresPermission(android.Manifest.permission.CAMERA) |
| 107 |
public static CameraAdvancedExtensionSessionImpl createCameraAdvancedExtensionSession( |
| 108 |
@NonNull android.hardware.camera2.impl.CameraDeviceImpl cameraDevice, |
| 109 |
@NonNull Context ctx, @NonNull ExtensionSessionConfiguration config, int sessionId) |
| 110 |
throws CameraAccessException, RemoteException { |
| 111 |
long clientId = CameraExtensionCharacteristics.registerClient(ctx); |
| 112 |
if (clientId < 0) { |
| 113 |
throw new UnsupportedOperationException("Unsupported extension!"); |
| 114 |
} |
| 115 |
|
| 116 |
String cameraId = cameraDevice.getId(); |
| 117 |
CameraManager manager = ctx.getSystemService(CameraManager.class); |
| 118 |
CameraCharacteristics chars = manager.getCameraCharacteristics(cameraId); |
| 119 |
CameraExtensionCharacteristics extensionChars = new CameraExtensionCharacteristics(ctx, |
| 120 |
cameraId, chars); |
| 121 |
|
| 122 |
if (!CameraExtensionCharacteristics.isExtensionSupported(cameraDevice.getId(), |
| 123 |
config.getExtension(), chars)) { |
| 124 |
throw new UnsupportedOperationException("Unsupported extension type: " + |
| 125 |
config.getExtension()); |
| 126 |
} |
| 127 |
|
| 128 |
if (config.getOutputConfigurations().isEmpty() || |
| 129 |
config.getOutputConfigurations().size() > 2) { |
| 130 |
throw new IllegalArgumentException("Unexpected amount of output surfaces, received: " + |
| 131 |
config.getOutputConfigurations().size() + " expected <= 2"); |
| 132 |
} |
| 133 |
|
| 134 |
for (OutputConfiguration c : config.getOutputConfigurations()) { |
| 135 |
if (c.getDynamicRangeProfile() != DynamicRangeProfiles.STANDARD) { |
| 136 |
throw new IllegalArgumentException("Unsupported dynamic range profile: " + |
| 137 |
c.getDynamicRangeProfile()); |
| 138 |
} |
| 139 |
if (c.getStreamUseCase() != |
| 140 |
CameraCharacteristics.SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT) { |
| 141 |
throw new IllegalArgumentException("Unsupported stream use case: " + |
| 142 |
c.getStreamUseCase()); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
int suitableSurfaceCount = 0; |
| 147 |
List<Size> supportedPreviewSizes = extensionChars.getExtensionSupportedSizes( |
| 148 |
config.getExtension(), SurfaceTexture.class); |
| 149 |
Surface repeatingRequestSurface = CameraExtensionUtils.getRepeatingRequestSurface( |
| 150 |
config.getOutputConfigurations(), supportedPreviewSizes); |
| 151 |
if (repeatingRequestSurface != null) { |
| 152 |
suitableSurfaceCount++; |
| 153 |
} |
| 154 |
|
| 155 |
HashMap<Integer, List<Size>> supportedCaptureSizes = new HashMap<>(); |
| 156 |
for (int format : CameraExtensionUtils.SUPPORTED_CAPTURE_OUTPUT_FORMATS) { |
| 157 |
List<Size> supportedSizes = extensionChars.getExtensionSupportedSizes( |
| 158 |
config.getExtension(), format); |
| 159 |
if (supportedSizes != null) { |
| 160 |
supportedCaptureSizes.put(format, supportedSizes); |
| 161 |
} |
| 162 |
} |
| 163 |
Surface burstCaptureSurface = CameraExtensionUtils.getBurstCaptureSurface( |
| 164 |
config.getOutputConfigurations(), supportedCaptureSizes); |
| 165 |
if (burstCaptureSurface != null) { |
| 166 |
suitableSurfaceCount++; |
| 167 |
} |
| 168 |
|
| 169 |
if (suitableSurfaceCount != config.getOutputConfigurations().size()) { |
| 170 |
throw new IllegalArgumentException("One or more unsupported output surfaces found!"); |
| 171 |
} |
| 172 |
|
| 173 |
IAdvancedExtenderImpl extender = CameraExtensionCharacteristics.initializeAdvancedExtension( |
| 174 |
config.getExtension()); |
| 175 |
extender.init(cameraId); |
| 176 |
|
| 177 |
CameraAdvancedExtensionSessionImpl ret = new CameraAdvancedExtensionSessionImpl(clientId, |
| 178 |
extender, cameraDevice, repeatingRequestSurface, burstCaptureSurface, |
| 179 |
config.getStateCallback(), config.getExecutor(), sessionId); |
| 180 |
ret.initialize(); |
| 181 |
|
| 182 |
return ret; |
| 183 |
} |
| 184 |
|
| 185 |
private CameraAdvancedExtensionSessionImpl(long extensionClientId, |
| 186 |
@NonNull IAdvancedExtenderImpl extender, |
| 187 |
@NonNull android.hardware.camera2.impl.CameraDeviceImpl cameraDevice, |
| 188 |
@Nullable Surface repeatingRequestSurface, @Nullable Surface burstCaptureSurface, |
| 189 |
@NonNull CameraExtensionSession.StateCallback callback, @NonNull Executor executor, |
| 190 |
int sessionId) { |
| 191 |
mExtensionClientId = extensionClientId; |
| 192 |
mAdvancedExtender = extender; |
| 193 |
mCameraDevice = cameraDevice; |
| 194 |
mCallbacks = callback; |
| 195 |
mExecutor = executor; |
| 196 |
mClientRepeatingRequestSurface = repeatingRequestSurface; |
| 197 |
mClientCaptureSurface = burstCaptureSurface; |
| 198 |
mHandlerThread = new HandlerThread(TAG); |
| 199 |
mHandlerThread.start(); |
| 200 |
mHandler = new Handler(mHandlerThread.getLooper()); |
| 201 |
mInitialized = false; |
| 202 |
mInitializeHandler = new InitializeSessionHandler(); |
| 203 |
mSessionId = sessionId; |
| 204 |
mInterfaceLock = cameraDevice.mInterfaceLock; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
public synchronized void initialize() throws CameraAccessException, RemoteException { |
| 211 |
if (mInitialized) { |
| 212 |
Log.d(TAG, "Session already initialized"); |
| 213 |
return; |
| 214 |
} |
| 215 |
|
| 216 |
OutputSurface previewSurface = initializeParcelable(mClientRepeatingRequestSurface); |
| 217 |
OutputSurface captureSurface = initializeParcelable(mClientCaptureSurface); |
| 218 |
mSessionProcessor = mAdvancedExtender.getSessionProcessor(); |
| 219 |
CameraSessionConfig sessionConfig = mSessionProcessor.initSession(mCameraDevice.getId(), |
| 220 |
previewSurface, captureSurface); |
| 221 |
List<CameraOutputConfig> outputConfigs = sessionConfig.outputConfigs; |
| 222 |
ArrayList<OutputConfiguration> outputList = new ArrayList<>(); |
| 223 |
for (CameraOutputConfig output : outputConfigs) { |
| 224 |
Surface outputSurface = initializeSurfrace(output); |
| 225 |
if (outputSurface == null) { |
| 226 |
continue; |
| 227 |
} |
| 228 |
OutputConfiguration cameraOutput = new OutputConfiguration(output.surfaceGroupId, |
| 229 |
outputSurface); |
| 230 |
|
| 231 |
if ((output.sharedSurfaceConfigs != null) && !output.sharedSurfaceConfigs.isEmpty()) { |
| 232 |
cameraOutput.enableSurfaceSharing(); |
| 233 |
for (CameraOutputConfig sharedOutputConfig : output.sharedSurfaceConfigs) { |
| 234 |
Surface sharedSurface = initializeSurfrace(sharedOutputConfig); |
| 235 |
if (sharedSurface == null) { |
| 236 |
continue; |
| 237 |
} |
| 238 |
cameraOutput.addSurface(sharedSurface); |
| 239 |
mCameraConfigMap.put(sharedSurface, sharedOutputConfig); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
cameraOutput.setPhysicalCameraId(output.physicalCameraId); |
| 244 |
outputList.add(cameraOutput); |
| 245 |
mCameraConfigMap.put(cameraOutput.getSurface(), output); |
| 246 |
} |
| 247 |
|
| 248 |
SessionConfiguration sessionConfiguration = new SessionConfiguration( |
| 249 |
SessionConfiguration.SESSION_REGULAR, outputList, |
| 250 |
new CameraExtensionUtils.HandlerExecutor(mHandler), new SessionStateHandler()); |
| 251 |
|
| 252 |
if ((sessionConfig.sessionParameter != null) && |
| 253 |
(!sessionConfig.sessionParameter.isEmpty())) { |
| 254 |
CaptureRequest.Builder requestBuilder = mCameraDevice.createCaptureRequest( |
| 255 |
sessionConfig.sessionTemplateId); |
| 256 |
CaptureRequest sessionRequest = requestBuilder.build(); |
| 257 |
CameraMetadataNative.update(sessionRequest.getNativeMetadata(), |
| 258 |
sessionConfig.sessionParameter); |
| 259 |
sessionConfiguration.setSessionParameters(sessionRequest); |
| 260 |
} |
| 261 |
|
| 262 |
mCameraDevice.createCaptureSession(sessionConfiguration); |
| 263 |
} |
| 264 |
|
| 265 |
private static ParcelCaptureResult initializeParcelable(CaptureResult result) { |
| 266 |
ParcelCaptureResult ret = new ParcelCaptureResult(); |
| 267 |
ret.cameraId = result.getCameraId(); |
| 268 |
ret.results = result.getNativeMetadata(); |
| 269 |
ret.parent = result.getRequest(); |
| 270 |
ret.sequenceId = result.getSequenceId(); |
| 271 |
ret.frameNumber = result.getFrameNumber(); |
| 272 |
|
| 273 |
return ret; |
| 274 |
} |
| 275 |
|
| 276 |
private static ParcelTotalCaptureResult initializeParcelable(TotalCaptureResult totalResult) { |
| 277 |
ParcelTotalCaptureResult ret = new ParcelTotalCaptureResult(); |
| 278 |
ret.logicalCameraId = totalResult.getCameraId(); |
| 279 |
ret.results = totalResult.getNativeMetadata(); |
| 280 |
ret.parent = totalResult.getRequest(); |
| 281 |
ret.sequenceId = totalResult.getSequenceId(); |
| 282 |
ret.frameNumber = totalResult.getFrameNumber(); |
| 283 |
ret.sessionId = totalResult.getSessionId(); |
| 284 |
ret.partials = new ArrayList<>(totalResult.getPartialResults().size()); |
| 285 |
for (CaptureResult partial : totalResult.getPartialResults()) { |
| 286 |
ret.partials.add(initializeParcelable(partial)); |
| 287 |
} |
| 288 |
Map<String, TotalCaptureResult> physicalResults = |
| 289 |
totalResult.getPhysicalCameraTotalResults(); |
| 290 |
ret.physicalResult = new ArrayList<>(physicalResults.size()); |
| 291 |
for (TotalCaptureResult physicalResult : physicalResults.values()) { |
| 292 |
ret.physicalResult.add(new PhysicalCaptureResultInfo(physicalResult.getCameraId(), |
| 293 |
physicalResult.getNativeMetadata())); |
| 294 |
} |
| 295 |
|
| 296 |
return ret; |
| 297 |
} |
| 298 |
|
| 299 |
private static OutputSurface initializeParcelable(Surface s) { |
| 300 |
OutputSurface ret = new OutputSurface(); |
| 301 |
if (s != null) { |
| 302 |
ret.surface = s; |
| 303 |
ret.size = new android.hardware.camera2.extension.Size(); |
| 304 |
Size surfaceSize = SurfaceUtils.getSurfaceSize(s); |
| 305 |
ret.size.width = surfaceSize.getWidth(); |
| 306 |
ret.size.height = surfaceSize.getHeight(); |
| 307 |
ret.imageFormat = SurfaceUtils.getSurfaceFormat(s); |
| 308 |
} else { |
| 309 |
ret.surface = null; |
| 310 |
ret.size = new android.hardware.camera2.extension.Size(); |
| 311 |
ret.size.width = -1; |
| 312 |
ret.size.height = -1; |
| 313 |
ret.imageFormat = ImageFormat.UNKNOWN; |
| 314 |
} |
| 315 |
|
| 316 |
return ret; |
| 317 |
} |
| 318 |
|
| 319 |
@Override |
| 320 |
public @NonNull CameraDevice getDevice() { |
| 321 |
synchronized (mInterfaceLock) { |
| 322 |
return mCameraDevice; |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
@Override |
| 327 |
public int setRepeatingRequest(@NonNull CaptureRequest request, @NonNull Executor executor, |
| 328 |
@NonNull ExtensionCaptureCallback listener) throws CameraAccessException { |
| 329 |
int seqId = -1; |
| 330 |
synchronized (mInterfaceLock) { |
| 331 |
if (!mInitialized) { |
| 332 |
throw new IllegalStateException("Uninitialized component"); |
| 333 |
} |
| 334 |
|
| 335 |
if (mClientRepeatingRequestSurface == null) { |
| 336 |
throw new IllegalArgumentException("No registered preview surface"); |
| 337 |
} |
| 338 |
|
| 339 |
if (!request.containsTarget(mClientRepeatingRequestSurface) || |
| 340 |
(request.getTargets().size() != 1)) { |
| 341 |
throw new IllegalArgumentException("Invalid repeating request output target!"); |
| 342 |
} |
| 343 |
|
| 344 |
try { |
| 345 |
mSessionProcessor.setParameters(request); |
| 346 |
|
| 347 |
seqId = mSessionProcessor.startRepeating(new RequestCallbackHandler(request, |
| 348 |
executor, listener)); |
| 349 |
} catch (RemoteException e) { |
| 350 |
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR, |
| 351 |
"Failed to enable repeating request, extension service failed to respond!"); |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
return seqId; |
| 356 |
} |
| 357 |
|
| 358 |
@Override |
| 359 |
public int capture(@NonNull CaptureRequest request, |
| 360 |
@NonNull Executor executor, |
| 361 |
@NonNull ExtensionCaptureCallback listener) throws CameraAccessException { |
| 362 |
int seqId = -1; |
| 363 |
synchronized (mInterfaceLock) { |
| 364 |
if (!mInitialized) { |
| 365 |
throw new IllegalStateException("Uninitialized component"); |
| 366 |
} |
| 367 |
|
| 368 |
if (request.getTargets().size() != 1) { |
| 369 |
throw new IllegalArgumentException("Single capture to both preview & still" + |
| 370 |
" capture outputs target is not supported!"); |
| 371 |
} |
| 372 |
|
| 373 |
if ((mClientCaptureSurface != null) && request.containsTarget(mClientCaptureSurface)) { |
| 374 |
try { |
| 375 |
mSessionProcessor.setParameters(request); |
| 376 |
|
| 377 |
seqId = mSessionProcessor.startCapture(new RequestCallbackHandler(request, |
| 378 |
executor, listener)); |
| 379 |
} catch (RemoteException e) { |
| 380 |
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR, "Failed " + |
| 381 |
" to submit capture request, extension service failed to respond!"); |
| 382 |
} |
| 383 |
} else if ((mClientRepeatingRequestSurface != null) && |
| 384 |
request.containsTarget(mClientRepeatingRequestSurface)) { |
| 385 |
try { |
| 386 |
seqId = mSessionProcessor.startTrigger(request, |
| 387 |
new RequestCallbackHandler(request, executor, listener)); |
| 388 |
} catch (RemoteException e) { |
| 389 |
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR, "Failed " + |
| 390 |
" to submit trigger request, extension service failed to respond!"); |
| 391 |
} |
| 392 |
} else { |
| 393 |
throw new IllegalArgumentException("Invalid single capture output target!"); |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
return seqId; |
| 398 |
} |
| 399 |
|
| 400 |
@Override |
| 401 |
public void stopRepeating() throws CameraAccessException { |
| 402 |
synchronized (mInterfaceLock) { |
| 403 |
if (!mInitialized) { |
| 404 |
throw new IllegalStateException("Uninitialized component"); |
| 405 |
} |
| 406 |
|
| 407 |
mCaptureSession.stopRepeating(); |
| 408 |
|
| 409 |
try { |
| 410 |
mSessionProcessor.stopRepeating(); |
| 411 |
} catch (RemoteException e) { |
| 412 |
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR, |
| 413 |
"Failed to notify about the end of repeating request, extension service" |
| 414 |
+ " failed to respond!"); |
| 415 |
} |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
@Override |
| 420 |
public void close() throws CameraAccessException { |
| 421 |
synchronized (mInterfaceLock) { |
| 422 |
if (mInitialized) { |
| 423 |
try { |
| 424 |
mCaptureSession.stopRepeating(); |
| 425 |
mSessionProcessor.stopRepeating(); |
| 426 |
mSessionProcessor.onCaptureSessionEnd(); |
| 427 |
} catch (RemoteException e) { |
| 428 |
Log.e(TAG, "Failed to stop the repeating request or end the session," |
| 429 |
+ " , extension service does not respond!") ; |
| 430 |
} |
| 431 |
mCaptureSession.close(); |
| 432 |
} |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
public void release(boolean skipCloseNotification) { |
| 437 |
boolean notifyClose = false; |
| 438 |
|
| 439 |
synchronized (mInterfaceLock) { |
| 440 |
mHandlerThread.quitSafely(); |
| 441 |
|
| 442 |
if (mSessionProcessor != null) { |
| 443 |
try { |
| 444 |
mSessionProcessor.deInitSession(); |
| 445 |
} catch (RemoteException e) { |
| 446 |
Log.e(TAG, "Failed to de-initialize session processor, extension service" |
| 447 |
+ " does not respond!") ; |
| 448 |
} |
| 449 |
mSessionProcessor = null; |
| 450 |
} |
| 451 |
|
| 452 |
if (mExtensionClientId >= 0) { |
| 453 |
CameraExtensionCharacteristics.unregisterClient(mExtensionClientId); |
| 454 |
if (mInitialized) { |
| 455 |
notifyClose = true; |
| 456 |
CameraExtensionCharacteristics.releaseSession(); |
| 457 |
} |
| 458 |
} |
| 459 |
mInitialized = false; |
| 460 |
|
| 461 |
for (ImageReader reader : mReaderMap.values()) { |
| 462 |
reader.close(); |
| 463 |
} |
| 464 |
mReaderMap.clear(); |
| 465 |
|
| 466 |
mClientRepeatingRequestSurface = null; |
| 467 |
mClientCaptureSurface = null; |
| 468 |
} |
| 469 |
|
| 470 |
if (notifyClose && !skipCloseNotification) { |
| 471 |
final long ident = Binder.clearCallingIdentity(); |
| 472 |
try { |
| 473 |
mExecutor.execute(() -> mCallbacks.onClosed( |
| 474 |
CameraAdvancedExtensionSessionImpl.this)); |
| 475 |
} finally { |
| 476 |
Binder.restoreCallingIdentity(ident); |
| 477 |
} |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
private void notifyConfigurationFailure() { |
| 482 |
synchronized (mInterfaceLock) { |
| 483 |
if (mInitialized) { |
| 484 |
return; |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
release(true ); |
| 489 |
|
| 490 |
final long ident = Binder.clearCallingIdentity(); |
| 491 |
try { |
| 492 |
mExecutor.execute( |
| 493 |
() -> mCallbacks.onConfigureFailed( |
| 494 |
CameraAdvancedExtensionSessionImpl.this)); |
| 495 |
} finally { |
| 496 |
Binder.restoreCallingIdentity(ident); |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
private class SessionStateHandler extends |
| 501 |
android.hardware.camera2.CameraCaptureSession.StateCallback { |
| 502 |
@Override |
| 503 |
public void onClosed(@NonNull CameraCaptureSession session) { |
| 504 |
release(false ); |
| 505 |
} |
| 506 |
|
| 507 |
@Override |
| 508 |
public void onConfigureFailed(@NonNull CameraCaptureSession session) { |
| 509 |
notifyConfigurationFailure(); |
| 510 |
} |
| 511 |
|
| 512 |
@Override |
| 513 |
public void onConfigured(@NonNull CameraCaptureSession session) { |
| 514 |
synchronized (mInterfaceLock) { |
| 515 |
mCaptureSession = session; |
| 516 |
} |
| 517 |
|
| 518 |
try { |
| 519 |
CameraExtensionCharacteristics.initializeSession(mInitializeHandler); |
| 520 |
} catch (RemoteException e) { |
| 521 |
Log.e(TAG, "Failed to initialize session! Extension service does" |
| 522 |
+ " not respond!"); |
| 523 |
notifyConfigurationFailure(); |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
private class InitializeSessionHandler extends IInitializeSessionCallback.Stub { |
| 529 |
@Override |
| 530 |
public void onSuccess() { |
| 531 |
mHandler.post(new Runnable() { |
| 532 |
@Override |
| 533 |
public void run() { |
| 534 |
boolean status = true; |
| 535 |
synchronized (mInterfaceLock) { |
| 536 |
try { |
| 537 |
if (mSessionProcessor != null) { |
| 538 |
mSessionProcessor.onCaptureSessionStart(mRequestProcessor); |
| 539 |
mInitialized = true; |
| 540 |
} else { |
| 541 |
Log.v(TAG, "Failed to start capture session, session " + |
| 542 |
" released before extension start!"); |
| 543 |
status = false; |
| 544 |
} |
| 545 |
} catch (RemoteException e) { |
| 546 |
Log.e(TAG, "Failed to start capture session," |
| 547 |
+ " extension service does not respond!"); |
| 548 |
status = false; |
| 549 |
mInitialized = false; |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
if (status) { |
| 554 |
final long ident = Binder.clearCallingIdentity(); |
| 555 |
try { |
| 556 |
mExecutor.execute(() -> mCallbacks.onConfigured( |
| 557 |
CameraAdvancedExtensionSessionImpl.this)); |
| 558 |
} finally { |
| 559 |
Binder.restoreCallingIdentity(ident); |
| 560 |
} |
| 561 |
} else { |
| 562 |
onFailure(); |
| 563 |
} |
| 564 |
} |
| 565 |
}); |
| 566 |
} |
| 567 |
|
| 568 |
@Override |
| 569 |
public void onFailure() { |
| 570 |
mHandler.post(new Runnable() { |
| 571 |
@Override |
| 572 |
public void run() { |
| 573 |
mCaptureSession.close(); |
| 574 |
|
| 575 |
Log.e(TAG, "Failed to initialize proxy service session!" |
| 576 |
+ " This can happen when trying to configure multiple " |
| 577 |
+ "concurrent extension sessions!"); |
| 578 |
notifyConfigurationFailure(); |
| 579 |
} |
| 580 |
}); |
| 581 |
} |
| 582 |
} |
| 583 |
|
| 584 |
private final class RequestCallbackHandler extends ICaptureCallback.Stub { |
| 585 |
private final CaptureRequest mClientRequest; |
| 586 |
private final Executor mClientExecutor; |
| 587 |
private final ExtensionCaptureCallback mClientCallbacks; |
| 588 |
|
| 589 |
private RequestCallbackHandler(@NonNull CaptureRequest clientRequest, |
| 590 |
@NonNull Executor clientExecutor, |
| 591 |
@NonNull ExtensionCaptureCallback clientCallbacks) { |
| 592 |
mClientRequest = clientRequest; |
| 593 |
mClientExecutor = clientExecutor; |
| 594 |
mClientCallbacks = clientCallbacks; |
| 595 |
} |
| 596 |
|
| 597 |
@Override |
| 598 |
public void onCaptureStarted(int captureSequenceId, long timestamp) { |
| 599 |
final long ident = Binder.clearCallingIdentity(); |
| 600 |
try { |
| 601 |
mClientExecutor.execute( |
| 602 |
() -> mClientCallbacks.onCaptureStarted( |
| 603 |
CameraAdvancedExtensionSessionImpl.this, mClientRequest, |
| 604 |
timestamp)); |
| 605 |
} finally { |
| 606 |
Binder.restoreCallingIdentity(ident); |
| 607 |
} |
| 608 |
} |
| 609 |
|
| 610 |
@Override |
| 611 |
public void onCaptureProcessStarted(int captureSequenceId) { |
| 612 |
final long ident = Binder.clearCallingIdentity(); |
| 613 |
try { |
| 614 |
mClientExecutor.execute( |
| 615 |
() -> mClientCallbacks.onCaptureProcessStarted( |
| 616 |
CameraAdvancedExtensionSessionImpl.this, mClientRequest)); |
| 617 |
} finally { |
| 618 |
Binder.restoreCallingIdentity(ident); |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
@Override |
| 623 |
public void onCaptureFailed(int captureSequenceId) { |
| 624 |
final long ident = Binder.clearCallingIdentity(); |
| 625 |
try { |
| 626 |
mClientExecutor.execute( |
| 627 |
() -> mClientCallbacks.onCaptureFailed( |
| 628 |
CameraAdvancedExtensionSessionImpl.this, mClientRequest)); |
| 629 |
} finally { |
| 630 |
Binder.restoreCallingIdentity(ident); |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
@Override |
| 635 |
public void onCaptureSequenceCompleted(int captureSequenceId) { |
| 636 |
final long ident = Binder.clearCallingIdentity(); |
| 637 |
try { |
| 638 |
mClientExecutor.execute( |
| 639 |
() -> mClientCallbacks.onCaptureSequenceCompleted( |
| 640 |
CameraAdvancedExtensionSessionImpl.this, captureSequenceId)); |
| 641 |
} finally { |
| 642 |
Binder.restoreCallingIdentity(ident); |
| 643 |
} |
| 644 |
} |
| 645 |
|
| 646 |
@Override |
| 647 |
public void onCaptureSequenceAborted(int captureSequenceId) { |
| 648 |
final long ident = Binder.clearCallingIdentity(); |
| 649 |
try { |
| 650 |
mClientExecutor.execute( |
| 651 |
() -> mClientCallbacks.onCaptureSequenceAborted( |
| 652 |
CameraAdvancedExtensionSessionImpl.this, captureSequenceId)); |
| 653 |
} finally { |
| 654 |
Binder.restoreCallingIdentity(ident); |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
@Override |
| 659 |
public void onCaptureCompleted(long timestamp, int requestId, CameraMetadataNative result) { |
| 660 |
if (result == null) { |
| 661 |
Log.e(TAG,"Invalid capture result!"); |
| 662 |
return; |
| 663 |
} |
| 664 |
|
| 665 |
result.set(CaptureResult.SENSOR_TIMESTAMP, timestamp); |
| 666 |
TotalCaptureResult totalResult = new TotalCaptureResult(mCameraDevice.getId(), result, |
| 667 |
mClientRequest, requestId, timestamp, new ArrayList<>(), mSessionId, |
| 668 |
new PhysicalCaptureResultInfo[0]); |
| 669 |
final long ident = Binder.clearCallingIdentity(); |
| 670 |
try { |
| 671 |
mExecutor.execute( |
| 672 |
() -> mClientCallbacks.onCaptureResultAvailable( |
| 673 |
CameraAdvancedExtensionSessionImpl.this, mClientRequest, |
| 674 |
totalResult)); |
| 675 |
} finally { |
| 676 |
Binder.restoreCallingIdentity(ident); |
| 677 |
} |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
private final class CaptureCallbackHandler extends CameraCaptureSession.CaptureCallback { |
| 682 |
private final IRequestCallback mCallback; |
| 683 |
|
| 684 |
public CaptureCallbackHandler(IRequestCallback callback) { |
| 685 |
mCallback = callback; |
| 686 |
} |
| 687 |
|
| 688 |
@Override |
| 689 |
public void onCaptureBufferLost(CameraCaptureSession session, CaptureRequest request, |
| 690 |
Surface target, long frameNumber) { |
| 691 |
try { |
| 692 |
if (request.getTag() instanceof Integer) { |
| 693 |
Integer requestId = (Integer) request.getTag(); |
| 694 |
mCallback.onCaptureBufferLost(requestId, frameNumber, |
| 695 |
mCameraConfigMap.get(target).outputId.id); |
| 696 |
} else { |
| 697 |
Log.e(TAG, "Invalid capture request tag!"); |
| 698 |
} |
| 699 |
} catch (RemoteException e) { |
| 700 |
Log.e(TAG, "Failed to notify lost capture buffer, extension service doesn't" |
| 701 |
+ " respond!"); |
| 702 |
} |
| 703 |
} |
| 704 |
|
| 705 |
@Override |
| 706 |
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, |
| 707 |
TotalCaptureResult result) { |
| 708 |
try { |
| 709 |
if (request.getTag() instanceof Integer) { |
| 710 |
Integer requestId = (Integer) request.getTag(); |
| 711 |
mCallback.onCaptureCompleted(requestId, initializeParcelable(result)); |
| 712 |
} else { |
| 713 |
Log.e(TAG, "Invalid capture request tag!"); |
| 714 |
} |
| 715 |
} catch (RemoteException e) { |
| 716 |
Log.e(TAG, "Failed to notify capture result, extension service doesn't" |
| 717 |
+ " respond!"); |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
@Override |
| 722 |
public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, |
| 723 |
CaptureFailure failure) { |
| 724 |
try { |
| 725 |
if (request.getTag() instanceof Integer) { |
| 726 |
Integer requestId = (Integer) request.getTag(); |
| 727 |
android.hardware.camera2.extension.CaptureFailure captureFailure = |
| 728 |
new android.hardware.camera2.extension.CaptureFailure(); |
| 729 |
captureFailure.request = request; |
| 730 |
captureFailure.reason = failure.getReason(); |
| 731 |
captureFailure.errorPhysicalCameraId = failure.getPhysicalCameraId(); |
| 732 |
captureFailure.frameNumber = failure.getFrameNumber(); |
| 733 |
captureFailure.sequenceId = failure.getSequenceId(); |
| 734 |
captureFailure.dropped = !failure.wasImageCaptured(); |
| 735 |
mCallback.onCaptureFailed(requestId, captureFailure); |
| 736 |
} else { |
| 737 |
Log.e(TAG, "Invalid capture request tag!"); |
| 738 |
} |
| 739 |
} catch (RemoteException e) { |
| 740 |
Log.e(TAG, "Failed to notify capture failure, extension service doesn't" |
| 741 |
+ " respond!"); |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
@Override |
| 746 |
public void onCaptureProgressed(CameraCaptureSession session, CaptureRequest request, |
| 747 |
CaptureResult partialResult) { |
| 748 |
try { |
| 749 |
if (request.getTag() instanceof Integer) { |
| 750 |
Integer requestId = (Integer) request.getTag(); |
| 751 |
mCallback.onCaptureProgressed(requestId, initializeParcelable(partialResult)); |
| 752 |
} else { |
| 753 |
Log.e(TAG, "Invalid capture request tag!"); |
| 754 |
} |
| 755 |
} catch (RemoteException e) { |
| 756 |
Log.e(TAG, "Failed to notify capture partial result, extension service doesn't" |
| 757 |
+ " respond!"); |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
@Override |
| 762 |
public void onCaptureSequenceAborted(CameraCaptureSession session, int sequenceId) { |
| 763 |
try { |
| 764 |
mCallback.onCaptureSequenceAborted(sequenceId); |
| 765 |
} catch (RemoteException e) { |
| 766 |
Log.e(TAG, "Failed to notify aborted sequence, extension service doesn't" |
| 767 |
+ " respond!"); |
| 768 |
} |
| 769 |
} |
| 770 |
|
| 771 |
@Override |
| 772 |
public void onCaptureSequenceCompleted(CameraCaptureSession session, int sequenceId, |
| 773 |
long frameNumber) { |
| 774 |
try { |
| 775 |
mCallback.onCaptureSequenceCompleted(sequenceId, frameNumber); |
| 776 |
} catch (RemoteException e) { |
| 777 |
Log.e(TAG, "Failed to notify sequence complete, extension service doesn't" |
| 778 |
+ " respond!"); |
| 779 |
} |
| 780 |
} |
| 781 |
|
| 782 |
@Override |
| 783 |
public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, |
| 784 |
long timestamp, long frameNumber) { |
| 785 |
try { |
| 786 |
if (request.getTag() instanceof Integer) { |
| 787 |
Integer requestId = (Integer) request.getTag(); |
| 788 |
mCallback.onCaptureStarted(requestId, frameNumber, timestamp); |
| 789 |
} else { |
| 790 |
Log.e(TAG, "Invalid capture request tag!"); |
| 791 |
} |
| 792 |
} catch (RemoteException e) { |
| 793 |
Log.e(TAG, "Failed to notify capture started, extension service doesn't" |
| 794 |
+ " respond!"); |
| 795 |
} |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
private static final class ImageReaderHandler implements ImageReader.OnImageAvailableListener { |
| 800 |
private final OutputConfigId mOutputConfigId; |
| 801 |
private final IImageProcessorImpl mIImageProcessor; |
| 802 |
private final String mPhysicalCameraId; |
| 803 |
|
| 804 |
private ImageReaderHandler(int outputConfigId, |
| 805 |
IImageProcessorImpl iImageProcessor, String physicalCameraId) { |
| 806 |
mOutputConfigId = new OutputConfigId(); |
| 807 |
mOutputConfigId.id = outputConfigId; |
| 808 |
mIImageProcessor = iImageProcessor; |
| 809 |
mPhysicalCameraId = physicalCameraId; |
| 810 |
} |
| 811 |
|
| 812 |
@Override |
| 813 |
public void onImageAvailable(ImageReader reader) { |
| 814 |
if (mIImageProcessor == null) { |
| 815 |
return; |
| 816 |
} |
| 817 |
|
| 818 |
Image img; |
| 819 |
try { |
| 820 |
img = reader.acquireNextImage(); |
| 821 |
} catch (IllegalStateException e) { |
| 822 |
Log.e(TAG, "Failed to acquire image, too many images pending!"); |
| 823 |
return; |
| 824 |
} |
| 825 |
if (img == null) { |
| 826 |
Log.e(TAG, "Invalid image!"); |
| 827 |
return; |
| 828 |
} |
| 829 |
|
| 830 |
try { |
| 831 |
reader.detachImage(img); |
| 832 |
} catch(Exception e) { |
| 833 |
Log.e(TAG, "Failed to detach image"); |
| 834 |
img.close(); |
| 835 |
return; |
| 836 |
} |
| 837 |
|
| 838 |
ParcelImage parcelImage = new ParcelImage(); |
| 839 |
parcelImage.buffer = img.getHardwareBuffer(); |
| 840 |
try { |
| 841 |
SyncFence fd = img.getFence(); |
| 842 |
if (fd.isValid()) { |
| 843 |
parcelImage.fence = fd.getFdDup(); |
| 844 |
} |
| 845 |
} catch (IOException e) { |
| 846 |
Log.e(TAG, "Failed to parcel buffer fence!"); |
| 847 |
} |
| 848 |
parcelImage.width = img.getWidth(); |
| 849 |
parcelImage.height = img.getHeight(); |
| 850 |
parcelImage.format = img.getFormat(); |
| 851 |
parcelImage.timestamp = img.getTimestamp(); |
| 852 |
parcelImage.transform = img.getTransform(); |
| 853 |
parcelImage.scalingMode = img.getScalingMode(); |
| 854 |
parcelImage.planeCount = img.getPlaneCount(); |
| 855 |
parcelImage.crop = img.getCropRect(); |
| 856 |
|
| 857 |
try { |
| 858 |
mIImageProcessor.onNextImageAvailable(mOutputConfigId, parcelImage, |
| 859 |
mPhysicalCameraId); |
| 860 |
} catch (RemoteException e) { |
| 861 |
Log.e(TAG, "Failed to propagate image buffer on output surface id: " + |
| 862 |
mOutputConfigId + " extension service does not respond!"); |
| 863 |
} finally { |
| 864 |
parcelImage.buffer.close(); |
| 865 |
img.close(); |
| 866 |
} |
| 867 |
} |
| 868 |
} |
| 869 |
|
| 870 |
private final class RequestProcessor extends IRequestProcessorImpl.Stub { |
| 871 |
@Override |
| 872 |
public void setImageProcessor(OutputConfigId outputConfigId, |
| 873 |
IImageProcessorImpl imageProcessor) { |
| 874 |
synchronized (mInterfaceLock) { |
| 875 |
if (mReaderMap.containsKey(outputConfigId.id)) { |
| 876 |
ImageReader reader = mReaderMap.get(outputConfigId.id); |
| 877 |
String physicalCameraId = null; |
| 878 |
if (mCameraConfigMap.containsKey(reader.getSurface())) { |
| 879 |
physicalCameraId = |
| 880 |
mCameraConfigMap.get(reader.getSurface()).physicalCameraId; |
| 881 |
reader.setOnImageAvailableListener(new ImageReaderHandler(outputConfigId.id, |
| 882 |
imageProcessor, physicalCameraId), mHandler); |
| 883 |
} else { |
| 884 |
Log.e(TAG, "Camera output configuration for ImageReader with " + |
| 885 |
" config Id " + outputConfigId.id + " not found!"); |
| 886 |
} |
| 887 |
} else { |
| 888 |
Log.e(TAG, "ImageReader with output config id: " + outputConfigId.id + |
| 889 |
" not found!"); |
| 890 |
} |
| 891 |
} |
| 892 |
} |
| 893 |
|
| 894 |
@Override |
| 895 |
public int submit(Request request, IRequestCallback callback) { |
| 896 |
ArrayList<Request> captureList = new ArrayList<>(); |
| 897 |
captureList.add(request); |
| 898 |
return submitBurst(captureList, callback); |
| 899 |
} |
| 900 |
|
| 901 |
@Override |
| 902 |
public int submitBurst(List<Request> requests, IRequestCallback callback) { |
| 903 |
int seqId = -1; |
| 904 |
try { |
| 905 |
CaptureCallbackHandler captureCallback = new CaptureCallbackHandler(callback); |
| 906 |
ArrayList<CaptureRequest> captureRequests = new ArrayList<>(); |
| 907 |
for (Request request : requests) { |
| 908 |
captureRequests.add(initializeCaptureRequest(mCameraDevice, request, |
| 909 |
mCameraConfigMap)); |
| 910 |
} |
| 911 |
seqId = mCaptureSession.captureBurstRequests(captureRequests, |
| 912 |
new CameraExtensionUtils.HandlerExecutor(mHandler), captureCallback); |
| 913 |
} catch (CameraAccessException e) { |
| 914 |
Log.e(TAG, "Failed to submit capture requests!"); |
| 915 |
} catch (IllegalStateException e) { |
| 916 |
Log.e(TAG, "Capture session closed!"); |
| 917 |
} |
| 918 |
|
| 919 |
return seqId; |
| 920 |
} |
| 921 |
|
| 922 |
@Override |
| 923 |
public int setRepeating(Request request, IRequestCallback callback) { |
| 924 |
int seqId = -1; |
| 925 |
try { |
| 926 |
CaptureRequest repeatingRequest = initializeCaptureRequest(mCameraDevice, |
| 927 |
request, mCameraConfigMap); |
| 928 |
CaptureCallbackHandler captureCallback = new CaptureCallbackHandler(callback); |
| 929 |
seqId = mCaptureSession.setSingleRepeatingRequest(repeatingRequest, |
| 930 |
new CameraExtensionUtils.HandlerExecutor(mHandler), captureCallback); |
| 931 |
} catch (CameraAccessException e) { |
| 932 |
Log.e(TAG, "Failed to enable repeating request!"); |
| 933 |
} catch (IllegalStateException e) { |
| 934 |
Log.e(TAG, "Capture session closed!"); |
| 935 |
} |
| 936 |
|
| 937 |
return seqId; |
| 938 |
} |
| 939 |
|
| 940 |
@Override |
| 941 |
public void abortCaptures() { |
| 942 |
try { |
| 943 |
mCaptureSession.abortCaptures(); |
| 944 |
} catch (CameraAccessException e) { |
| 945 |
Log.e(TAG, "Failed during capture abort!"); |
| 946 |
} catch (IllegalStateException e) { |
| 947 |
Log.e(TAG, "Capture session closed!"); |
| 948 |
} |
| 949 |
} |
| 950 |
|
| 951 |
@Override |
| 952 |
public void stopRepeating() { |
| 953 |
try { |
| 954 |
mCaptureSession.stopRepeating(); |
| 955 |
} catch (CameraAccessException e) { |
| 956 |
Log.e(TAG, "Failed during repeating capture stop!"); |
| 957 |
} catch (IllegalStateException e) { |
| 958 |
Log.e(TAG, "Capture session closed!"); |
| 959 |
} |
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
private static CaptureRequest initializeCaptureRequest(CameraDevice cameraDevice, |
| 964 |
Request request, HashMap<Surface, CameraOutputConfig> surfaceIdMap) |
| 965 |
throws CameraAccessException { |
| 966 |
CaptureRequest.Builder builder = cameraDevice.createCaptureRequest(request.templateId); |
| 967 |
for (OutputConfigId configId : request.targetOutputConfigIds) { |
| 968 |
boolean found = false; |
| 969 |
for (Map.Entry<Surface, CameraOutputConfig> entry : surfaceIdMap.entrySet()) { |
| 970 |
if (entry.getValue().outputId.id == configId.id) { |
| 971 |
builder.addTarget(entry.getKey()); |
| 972 |
found = true; |
| 973 |
break; |
| 974 |
} |
| 975 |
} |
| 976 |
|
| 977 |
if (!found) { |
| 978 |
Log.e(TAG, "Surface with output id: " + configId.id + |
| 979 |
" not found among registered camera outputs!"); |
| 980 |
} |
| 981 |
} |
| 982 |
|
| 983 |
builder.setTag(request.requestId); |
| 984 |
CaptureRequest ret = builder.build(); |
| 985 |
CameraMetadataNative.update(ret.getNativeMetadata(), request.parameters); |
| 986 |
return ret; |
| 987 |
} |
| 988 |
|
| 989 |
private Surface initializeSurfrace(CameraOutputConfig output) { |
| 990 |
switch(output.type) { |
| 991 |
case CameraOutputConfig.TYPE_SURFACE: |
| 992 |
if (output.surface == null) { |
| 993 |
Log.w(TAG, "Unsupported client output id: " + output.outputId.id + |
| 994 |
", skipping!"); |
| 995 |
return null; |
| 996 |
} |
| 997 |
return output.surface; |
| 998 |
case CameraOutputConfig.TYPE_IMAGEREADER: |
| 999 |
if ((output.imageFormat == ImageFormat.UNKNOWN) || (output.size.width <= 0) || |
| 1000 |
(output.size.height <= 0)) { |
| 1001 |
Log.w(TAG, "Unsupported client output id: " + output.outputId.id + |
| 1002 |
", skipping!"); |
| 1003 |
return null; |
| 1004 |
} |
| 1005 |
ImageReader reader = ImageReader.newInstance(output.size.width, |
| 1006 |
output.size.height, output.imageFormat, output.capacity); |
| 1007 |
mReaderMap.put(output.outputId.id, reader); |
| 1008 |
return reader.getSurface(); |
| 1009 |
case CameraOutputConfig.TYPE_MULTIRES_IMAGEREADER: |
| 1010 |
|
| 1011 |
default: |
| 1012 |
throw new IllegalArgumentException("Unsupported output config type: " + |
| 1013 |
output.type); |
| 1014 |
} |
| 1015 |
} |
| 1016 |
} |