Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42b66ccf authored by Avichal Rakesh's avatar Avichal Rakesh Committed by Android (Google) Code Review
Browse files

Merge "cameraservice: Add metrics for extension sessions" into udc-dev

parents 65f443a6 51ef38a4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public class CameraSessionStats implements Parcelable {
    private String mUserTag;
    private int mVideoStabilizationMode;
    private int mSessionIndex;
    private CameraExtensionSessionStats mCameraExtensionSessionStats;

    public CameraSessionStats() {
        mFacing = -1;
@@ -82,6 +83,7 @@ public class CameraSessionStats implements Parcelable {
        mStreamStats = new ArrayList<CameraStreamStats>();
        mVideoStabilizationMode = -1;
        mSessionIndex = 0;
        mCameraExtensionSessionStats = new CameraExtensionSessionStats();
    }

    public CameraSessionStats(String cameraId, int facing, int newCameraState,
@@ -101,6 +103,7 @@ public class CameraSessionStats implements Parcelable {
        mInternalReconfigure = internalReconfigure;
        mStreamStats = new ArrayList<CameraStreamStats>();
        mSessionIndex = sessionIdx;
        mCameraExtensionSessionStats = new CameraExtensionSessionStats();
    }

    public static final @android.annotation.NonNull Parcelable.Creator<CameraSessionStats> CREATOR =
@@ -145,6 +148,7 @@ public class CameraSessionStats implements Parcelable {
        dest.writeString(mUserTag);
        dest.writeInt(mVideoStabilizationMode);
        dest.writeInt(mSessionIndex);
        mCameraExtensionSessionStats.writeToParcel(dest, 0);
    }

    public void readFromParcel(Parcel in) {
@@ -170,6 +174,7 @@ public class CameraSessionStats implements Parcelable {
        mUserTag = in.readString();
        mVideoStabilizationMode = in.readInt();
        mSessionIndex = in.readInt();
        mCameraExtensionSessionStats = CameraExtensionSessionStats.CREATOR.createFromParcel(in);
    }

    public String getCameraId() {
@@ -243,4 +248,8 @@ public class CameraSessionStats implements Parcelable {
    public int getSessionIndex() {
        return mSessionIndex;
    }

    public CameraExtensionSessionStats getExtensionSessionStats() {
        return mCameraExtensionSessionStats;
    }
}
+25 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.compat.annotation.Overridable;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.hardware.CameraExtensionSessionStats;
import android.hardware.CameraStatus;
import android.hardware.ICameraService;
import android.hardware.ICameraServiceListener;
@@ -1726,6 +1727,30 @@ public final class CameraManager {
        }
    }

    /**
     * Reports {@link CameraExtensionSessionStats} to the {@link ICameraService} to be logged for
     * currently active session. Validation is done downstream.
     *
     * @param extStats Extension Session stats to be logged by cameraservice
     *
     * @return the key to be used with the next call.
     *         See {@link ICameraService#reportExtensionSessionStats}.
     * @hide
     */
    public static String reportExtensionSessionStats(CameraExtensionSessionStats extStats) {
        ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
        if (cameraService == null) {
            Log.e(TAG, "CameraService not available. Not reporting extension stats.");
            return "";
        }
        try {
            return cameraService.reportExtensionSessionStats(extStats);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to report extension session stats to cameraservice.", e);
        }
        return "";
    }

    /**
     * A per-process global camera manager instance, to retain a connection to the camera service,
     * and to distribute camera availability notices to API-registered callbacks
+26 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.hardware.camera2.params.DynamicRangeProfiles;
import android.hardware.camera2.params.ExtensionSessionConfiguration;
import android.hardware.camera2.params.OutputConfiguration;
import android.hardware.camera2.params.SessionConfiguration;
import android.hardware.camera2.utils.ExtensionSessionStatsAggregator;
import android.hardware.camera2.utils.SurfaceUtils;
import android.media.Image;
import android.media.ImageReader;
@@ -96,6 +97,7 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
    private CameraCaptureSession mCaptureSession = null;
    private ISessionProcessorImpl mSessionProcessor = null;
    private final InitializeSessionHandler mInitializeHandler;
    private final ExtensionSessionStatsAggregator mStatsAggregator;

    private boolean mInitialized;

@@ -205,6 +207,10 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
                extender, cameraDevice, characteristicsMapNative, repeatingRequestSurface,
                burstCaptureSurface, postviewSurface, config.getStateCallback(),
                config.getExecutor(), sessionId);

        ret.mStatsAggregator.setClientName(ctx.getOpPackageName());
        ret.mStatsAggregator.setExtensionType(config.getExtension());

        ret.initialize();

        return ret;
@@ -234,6 +240,9 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
        mInitializeHandler = new InitializeSessionHandler();
        mSessionId = sessionId;
        mInterfaceLock = cameraDevice.mInterfaceLock;

        mStatsAggregator = new ExtensionSessionStatsAggregator(mCameraDevice.getId(),
                /*isAdvanced=*/true);
    }

    /**
@@ -523,11 +532,26 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
                    Log.e(TAG, "Failed to stop the repeating request or end the session,"
                            + " , extension service does not respond!") ;
                }
                // Commit stats before closing the capture session
                mStatsAggregator.commit(/*isFinal*/true);
                mCaptureSession.close();
            }
        }
    }

    /**
     * Called by {@link CameraDeviceImpl} right before the capture session is closed, and before it
     * calls {@link #release}
     */
    public void commitStats() {
        synchronized (mInterfaceLock) {
            if (mInitialized) {
                // Only commit stats if a capture session was initialized
                mStatsAggregator.commit(/*isFinal*/true);
            }
        }
    }

    public void release(boolean skipCloseNotification) {
        boolean notifyClose = false;

@@ -608,6 +632,8 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
        public void onConfigured(@NonNull CameraCaptureSession session) {
            synchronized (mInterfaceLock) {
                mCaptureSession = session;
                // Commit basic stats as soon as the capture session is created
                mStatsAggregator.commit(/*isFinal*/false);
            }

            try {
+17 −0
Original line number Diff line number Diff line
@@ -700,6 +700,14 @@ public class CameraDeviceImpl extends CameraDevice
                        + " input configuration yet.");
            }

            if (mCurrentExtensionSession != null) {
                mCurrentExtensionSession.commitStats();
            }

            if (mCurrentAdvancedExtensionSession != null) {
                mCurrentAdvancedExtensionSession.commitStats();
            }

            // Notify current session that it's going away, before starting camera operations
            // After this call completes, the session is not allowed to call into CameraDeviceImpl
            if (mCurrentSession != null) {
@@ -1414,6 +1422,15 @@ public class CameraDeviceImpl extends CameraDevice
                mOfflineSwitchService = null;
            }

            // Let extension sessions commit stats before disconnecting remoteDevice
            if (mCurrentExtensionSession != null) {
                mCurrentExtensionSession.commitStats();
            }

            if (mCurrentAdvancedExtensionSession != null) {
                mCurrentAdvancedExtensionSession.commitStats();
            }

            if (mRemoteDevice != null) {
                mRemoteDevice.disconnect();
                mRemoteDevice.unlinkToDeath(this, /*flags*/0);
+26 −1
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraExtensionCharacteristics;
import android.hardware.camera2.CameraExtensionSession;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CaptureFailure;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.CaptureResult;
@@ -49,6 +48,7 @@ import android.hardware.camera2.params.DynamicRangeProfiles;
import android.hardware.camera2.params.ExtensionSessionConfiguration;
import android.hardware.camera2.params.OutputConfiguration;
import android.hardware.camera2.params.SessionConfiguration;
import android.hardware.camera2.utils.ExtensionSessionStatsAggregator;
import android.hardware.camera2.utils.SurfaceUtils;
import android.media.Image;
import android.media.ImageReader;
@@ -90,6 +90,7 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
    private final int mSessionId;
    private final Set<CaptureRequest.Key> mSupportedRequestKeys;
    private final Set<CaptureResult.Key> mSupportedResultKeys;
    private final ExtensionSessionStatsAggregator mStatsAggregator;
    private boolean mCaptureResultsSupported;

    private CameraCaptureSession mCaptureSession = null;
@@ -242,6 +243,9 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
                extensionChars.getAvailableCaptureRequestKeys(config.getExtension()),
                extensionChars.getAvailableCaptureResultKeys(config.getExtension()));

        session.mStatsAggregator.setClientName(ctx.getOpPackageName());
        session.mStatsAggregator.setExtensionType(config.getExtension());

        session.initialize();

        return session;
@@ -280,6 +284,9 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
        mSupportedResultKeys = resultKeys;
        mCaptureResultsSupported = !resultKeys.isEmpty();
        mInterfaceLock = cameraDevice.mInterfaceLock;

        mStatsAggregator = new ExtensionSessionStatsAggregator(mCameraDevice.getId(),
                /*isAdvanced=*/false);
    }

    private void initializeRepeatingRequestPipeline() throws RemoteException {
@@ -793,11 +800,27 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
                            new CloseRequestHandler(mRepeatingRequestImageCallback), mHandler);
                }

                mStatsAggregator.commit(/*isFinal*/true); // Commit stats before closing session
                mCaptureSession.close();
            }
        }
    }

    /**
     * Called by {@link CameraDeviceImpl} right before the capture session is closed, and before it
     * calls {@link #release}
     *
     * @hide
     */
    public void commitStats() {
        synchronized (mInterfaceLock) {
            if (mInitialized) {
                // Only commit stats if a capture session was initialized
                mStatsAggregator.commit(/*isFinal*/true);
            }
        }
    }

    private void setInitialCaptureRequest(List<CaptureStageImpl> captureStageList,
                                          InitialRequestHandler requestHandler)
            throws CameraAccessException {
@@ -955,6 +978,8 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
        public void onConfigured(@NonNull CameraCaptureSession session) {
            synchronized (mInterfaceLock) {
                mCaptureSession = session;
                // Commit basic stats as soon as the capture session is created
                mStatsAggregator.commit(/*isFinal*/false);
                try {
                    finishPipelineInitialization();
                    CameraExtensionCharacteristics.initializeSession(mInitializeHandler);
Loading