diff options
| author | Emilian Peev <epeev@google.com> | 2021-07-29 00:20:06 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-07-29 00:20:06 +0000 |
| commit | e922ec31aa08acadcfadd1691c8a34c6e86edb68 (patch) | |
| tree | 2fc03fda9f796e6a50499c566eb754cdd9c7e523 /core/java | |
| parent | 782b4e9e080bd89badcdfabd37e53740f2f0f2dd (diff) | |
| parent | 83eb162a5d3e34fa3e3db83d982cf710f4254354 (diff) | |
Merge changes from topic "b194508189" into sc-dev
* changes:
Camera: Support common outputs between regular and extension sessions
Camera: Include the parceled image dimensions
Diffstat (limited to 'core/java')
5 files changed, 73 insertions, 45 deletions
diff --git a/core/java/android/hardware/camera2/impl/CameraAdvancedExtensionSessionImpl.java b/core/java/android/hardware/camera2/impl/CameraAdvancedExtensionSessionImpl.java index bfc1f2765c3b..d5a35bc31e68 100644 --- a/core/java/android/hardware/camera2/impl/CameraAdvancedExtensionSessionImpl.java +++ b/core/java/android/hardware/camera2/impl/CameraAdvancedExtensionSessionImpl.java @@ -446,10 +446,16 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes } } - public void release() { - synchronized (mInterfaceLock) { + @Override + protected void finalize() throws Throwable { + if (mHandlerThread != null) { mHandlerThread.quitSafely(); + } + super.finalize(); + } + public void release() { + synchronized (mInterfaceLock) { if (mSessionProcessor != null) { try { mSessionProcessor.deInitSession(); @@ -812,6 +818,8 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes Log.e(TAG,"Failed to parcel buffer fence!"); } } + parcelImage.width = img.getWidth(); + parcelImage.height = img.getHeight(); parcelImage.format = img.getFormat(); parcelImage.timestamp = img.getTimestamp(); parcelImage.transform = img.getTransform(); diff --git a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java index 11b137ca01f3..0bf812e03984 100644 --- a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java +++ b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java @@ -696,6 +696,16 @@ public class CameraDeviceImpl extends CameraDevice mCurrentSession.replaceSessionClose(); } + if (mCurrentExtensionSession != null) { + mCurrentExtensionSession.release(); + mCurrentExtensionSession = null; + } + + if (mCurrentAdvancedExtensionSession != null) { + mCurrentAdvancedExtensionSession.release(); + mCurrentAdvancedExtensionSession = null; + } + // TODO: dont block for this boolean configureSuccess = true; CameraAccessException pendingException = null; diff --git a/core/java/android/hardware/camera2/impl/CameraExtensionSessionImpl.java b/core/java/android/hardware/camera2/impl/CameraExtensionSessionImpl.java index 537b894d9a6a..7d29a7d275cf 100644 --- a/core/java/android/hardware/camera2/impl/CameraExtensionSessionImpl.java +++ b/core/java/android/hardware/camera2/impl/CameraExtensionSessionImpl.java @@ -49,8 +49,6 @@ import android.media.ImageWriter; import android.os.Binder; import android.os.Handler; import android.os.HandlerThread; -import android.os.IBinder; -import android.os.IInterface; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.annotation.NonNull; @@ -265,13 +263,6 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession { } catch (ClassCastException e) { throw new UnsupportedOperationException("Failed casting preview processor!"); } - if (mClientRepeatingRequestSurface != null) { - mPreviewRequestUpdateProcessor.onOutputSurface(mClientRepeatingRequestSurface, - nativeGetSurfaceFormat(mClientRepeatingRequestSurface)); - mRepeatingRequestImageWriter = ImageWriter.newInstance( - mClientRepeatingRequestSurface, PREVIEW_QUEUE_SIZE, - CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT); - } mRepeatingRequestImageReader = ImageReader.newInstance(repeatingSurfaceInfo.mWidth, repeatingSurfaceInfo.mHeight, CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT, @@ -285,11 +276,6 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession { mPreviewRequestUpdateProcessor.onImageFormatUpdate( CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT); } else { - if (mClientRepeatingRequestSurface != null) { - mRepeatingRequestImageWriter = ImageWriter.newInstance( - mClientRepeatingRequestSurface, PREVIEW_QUEUE_SIZE, - CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT); - } mRepeatingRequestImageReader = ImageReader.newInstance(repeatingSurfaceInfo.mWidth, repeatingSurfaceInfo.mHeight, CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT, @@ -320,7 +306,6 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession { mBurstCaptureImageReader = ImageReader.newInstance(surfaceInfo.mWidth, surfaceInfo.mHeight, CameraExtensionCharacteristics.PROCESSING_INPUT_FORMAT, mImageExtender.getMaxCaptureStage()); - mImageProcessor.onOutputSurface(mClientCaptureSurface, surfaceInfo.mFormat); } else { // The client doesn't intend to trigger multi-frame capture, however the // image extender still needs to get initialized and the camera still capture @@ -367,6 +352,29 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession { } } + private void finishPipelineInitialization() throws RemoteException { + if (mClientRepeatingRequestSurface != null) { + if (mPreviewProcessorType == IPreviewExtenderImpl.PROCESSOR_TYPE_REQUEST_UPDATE_ONLY) { + mPreviewRequestUpdateProcessor.onOutputSurface(mClientRepeatingRequestSurface, + nativeGetSurfaceFormat(mClientRepeatingRequestSurface)); + mRepeatingRequestImageWriter = ImageWriter.newInstance( + mClientRepeatingRequestSurface, + PREVIEW_QUEUE_SIZE, + CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT); + } else if (mPreviewProcessorType == IPreviewExtenderImpl.PROCESSOR_TYPE_NONE) { + mRepeatingRequestImageWriter = ImageWriter.newInstance( + mClientRepeatingRequestSurface, + PREVIEW_QUEUE_SIZE, + CameraExtensionCharacteristics.NON_PROCESSING_INPUT_FORMAT); + } + } + if ((mImageProcessor != null) && (mClientCaptureSurface != null)) { + CameraExtensionUtils.SurfaceInfo surfaceInfo = CameraExtensionUtils.querySurface( + mClientCaptureSurface); + mImageProcessor.onOutputSurface(mClientCaptureSurface, surfaceInfo.mFormat); + } + } + /** * @hide */ @@ -622,11 +630,18 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession { new CameraExtensionUtils.HandlerExecutor(mHandler), requestHandler); } + @Override + protected void finalize() throws Throwable { + if (mHandlerThread != null) { + mHandlerThread.quitSafely(); + } + super.finalize(); + } + /** @hide */ public void release() { synchronized (mInterfaceLock) { mInternalRepeatingRequestEnabled = false; - mHandlerThread.quitSafely(); try { mPreviewExtender.onDeInit(); @@ -750,6 +765,7 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession { synchronized (mInterfaceLock) { mCaptureSession = session; try { + finishPipelineInitialization(); CameraExtensionCharacteristics.initializeSession(mInitializeHandler); } catch (RemoteException e) { Log.e(TAG, "Failed to initialize session! Extension service does" @@ -1640,6 +1656,8 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession { Log.e(TAG,"Failed to parcel buffer fence!"); } } + parcelImage.width = img.getWidth(); + parcelImage.height = img.getHeight(); parcelImage.format = img.getFormat(); parcelImage.timestamp = img.getTimestamp(); parcelImage.transform = img.getTransform(); diff --git a/core/java/android/hardware/camera2/impl/CameraExtensionUtils.java b/core/java/android/hardware/camera2/impl/CameraExtensionUtils.java index 950d716b05e8..9acf9bf0c803 100644 --- a/core/java/android/hardware/camera2/impl/CameraExtensionUtils.java +++ b/core/java/android/hardware/camera2/impl/CameraExtensionUtils.java @@ -20,7 +20,6 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.graphics.ImageFormat; import android.graphics.PixelFormat; -import android.hardware.HardwareBuffer; import android.hardware.camera2.CameraExtensionCharacteristics; import android.hardware.camera2.params.OutputConfiguration; import android.hardware.camera2.params.StreamConfigurationMap; @@ -78,41 +77,20 @@ public final class CameraExtensionUtils { SurfaceInfo surfaceInfo = new SurfaceInfo(); int nativeFormat = SurfaceUtils.getSurfaceFormat(s); int dataspace = SurfaceUtils.getSurfaceDataspace(s); + Size surfaceSize = SurfaceUtils.getSurfaceSize(s); + surfaceInfo.mFormat = nativeFormat; + surfaceInfo.mWidth = surfaceSize.getWidth(); + surfaceInfo.mHeight = surfaceSize.getHeight(); + surfaceInfo.mUsage = SurfaceUtils.getSurfaceUsage(s); // Jpeg surfaces cannot be queried for their usage and other parameters // in the usual way below. A buffer can only be de-queued after the // producer overrides the surface dimensions to (width*height) x 1. if ((nativeFormat == StreamConfigurationMap.HAL_PIXEL_FORMAT_BLOB) && (dataspace == StreamConfigurationMap.HAL_DATASPACE_V0_JFIF)) { surfaceInfo.mFormat = ImageFormat.JPEG; - Size surfaceSize = SurfaceUtils.getSurfaceSize(s); - surfaceInfo.mWidth = surfaceSize.getWidth(); - surfaceInfo.mHeight = surfaceSize.getHeight(); return surfaceInfo; } - HardwareBuffer buffer = null; - try { - writer = ImageWriter.newInstance(s, 1); - img = writer.dequeueInputImage(); - buffer = img.getHardwareBuffer(); - surfaceInfo.mFormat = buffer.getFormat(); - surfaceInfo.mWidth = buffer.getWidth(); - surfaceInfo.mHeight = buffer.getHeight(); - surfaceInfo.mUsage = buffer.getUsage(); - } catch (Exception e) { - Log.e(TAG, "Failed to query surface, returning defaults!"); - } finally { - if (buffer != null) { - buffer.close(); - } - if (img != null) { - img.close(); - } - if (writer != null) { - writer.close(); - } - } - return surfaceInfo; } diff --git a/core/java/android/hardware/camera2/utils/SurfaceUtils.java b/core/java/android/hardware/camera2/utils/SurfaceUtils.java index 35b5c1599070..57d8ded79e8e 100644 --- a/core/java/android/hardware/camera2/utils/SurfaceUtils.java +++ b/core/java/android/hardware/camera2/utils/SurfaceUtils.java @@ -105,6 +105,20 @@ public class SurfaceUtils { } /** + * Get the surface usage bits. + * + * @param surface The surface to be queried for usage. + * @return the native object id of the surface, 0 if surface is not backed by a native object. + */ + public static long getSurfaceUsage(Surface surface) { + checkNotNull(surface); + try { + return nativeDetectSurfaceUsageFlags(surface); + } catch (IllegalArgumentException e) { + return 0; + } + } + /** * Get the Surface size. * * @param surface The surface to be queried for size. |
