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

Commit 1f9600b6 authored by Jyoti Bhayana's avatar Jyoti Bhayana
Browse files

Add multi-client support in camera2

Add support for multiple clients to access the same camera using
camera2 api. This is initial set of changes and includes all the new
API changes as well as implementation of opening the camera in shared
mode, new open callbacks, newly added characteristics and creating
shared sesion.

After the merge of these initial changes, it will be followed by
another set of changes which will include implementation of
startStreaming and stopStreaming APIs and the capability for multiple
clients to stream the camera images.

Flag: com.android.internal.camera.flags.camera_multi_client
Bug:265196098
API-Coverage-Bug: 377371012
Test: Tested that a java and native client are able to open the camera
at the same time and get the required callbacks and they are able to get
the shared session configuration using newly added characteristics.
Tested the clientaccessprioritieschanged callback occur appropriately
when new client connects/disconnects.

Change-Id: I4cd3babf538b065d635c99c695718d8f52883afc
parent c81b2f9d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ interface ICameraService
     *                     policy for default device context). Only virtual cameras would be exposed
     *                     only for custom policy and only real cameras would be exposed for default
     *                     policy.
     * @param sharedMode Parameter specifying if the camera should be opened in shared mode.
     */
    ICameraDeviceUser connectDevice(ICameraDeviceCallbacks callbacks,
            @utf8InCpp String cameraId,
@@ -164,7 +165,8 @@ interface ICameraService
            int targetSdkVersion,
            int rotationOverride,
            in AttributionSourceState clientAttribution,
            int devicePolicy);
            int devicePolicy,
            boolean sharedMode);

    /**
     * Add listener for changes to camera device and flashlight state.
+1 −0
Original line number Diff line number Diff line
@@ -105,5 +105,6 @@ interface ICameraServiceListener
     * will receive such callbacks.
     */
    oneway void onCameraOpened(@utf8InCpp String cameraId, @utf8InCpp String clientPackageId, int deviceId);
    oneway void onCameraOpenedInSharedMode(@utf8InCpp String cameraId, @utf8InCpp String clientPackageId, int deviceId, boolean primaryClient);
    oneway void onCameraClosed(@utf8InCpp String cameraId, int deviceId);
}
+11 −0
Original line number Diff line number Diff line
@@ -50,4 +50,15 @@ interface ICameraDeviceCallbacks
    oneway void onRepeatingRequestError(in long lastFrameNumber,
                                        in int repeatingRequestId);
    oneway void onRequestQueueEmpty();

    /**
     * Notify registered clients about client shared access priority changes when the camera device
     * has been opened in shared mode.
     *
     * If the client priority changes from secondary to primary, then it can now
     * create capture request and change the capture request parameters. If client priority
     * changes from primary to secondary, that implies that another higher priority client is also
     * accessing the camera in shared mode and is now the primary client.
     */
    oneway void onClientSharedAccessPriorityChanged(boolean primaryClient);
}
+19 −0
Original line number Diff line number Diff line
@@ -67,6 +67,17 @@ interface ICameraDeviceUser
     */
    const int CONSTRAINED_HIGH_SPEED_MODE = 1;

    /**
     * The shared operating mode for a camera device.
     *
     * <p>
     * When in shared mode, the camera device can be opened and accessed by multiple applications
     * simultaneously.
     * </p>
     *
     */
    const int SHARED_MODE = 2;

    /**
     * Start of custom vendor modes
     */
@@ -194,4 +205,12 @@ interface ICameraDeviceUser
     */
    ICameraOfflineSession switchToOffline(in ICameraDeviceCallbacks callbacks,
            in int[] offlineOutputIds);

    /**
     * Get the client status as primary or secondary when camera is opened in shared mode.
     *
     * @return true if this is primary client when camera is opened in shared mode.
     *         false if another higher priority client with primary access is also using the camera.
     */
    boolean isPrimaryClient();
}
+28 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ namespace flags = com::android::internal::camera::flags;
namespace android {

const int OutputConfiguration::INVALID_ROTATION = -1;
const int OutputConfiguration::ROTATION_0 = 0;
const int OutputConfiguration::INVALID_SET_ID = -1;

const std::vector<sp<IGraphicBufferProducer>>&
@@ -97,6 +98,10 @@ int OutputConfiguration::getTimestampBase() const {
    return mTimestampBase;
}

int OutputConfiguration::getMirrorMode() const {
    return mMirrorMode;
}

int OutputConfiguration::getMirrorMode(sp<IGraphicBufferProducer> surface) const {
    if (!flags::mirror_mode_shared_surfaces()) {
        return mMirrorMode;
@@ -164,6 +169,29 @@ OutputConfiguration::OutputConfiguration() :
        mUsage(0) {
}

OutputConfiguration::OutputConfiguration(int surfaceType, int width, int height, int format,
        int32_t colorSpace, int mirrorMode, bool useReadoutTimestamp, int timestampBase,
        int dataspace, int64_t usage, int64_t streamusecase, std::string physicalCamId):
        mRotation(ROTATION_0),
        mSurfaceSetID(INVALID_SET_ID),
        mSurfaceType(surfaceType),
        mWidth(width),
        mHeight(height),
        mIsDeferred(false),
        mIsShared(false),
        mPhysicalCameraId(physicalCamId),
        mIsMultiResolution(false),
        mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
        mColorSpace(colorSpace),
        mStreamUseCase(streamusecase),
        mTimestampBase(timestampBase),
        mMirrorMode(mirrorMode),
        mUseReadoutTimestamp(useReadoutTimestamp),
        mFormat(format),
        mDataspace(dataspace),
        mUsage(usage){
}

OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
        mRotation(INVALID_ROTATION),
        mSurfaceSetID(INVALID_SET_ID) {
Loading