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

Commit c9cd6e12 authored by Shuzhen Wang's avatar Shuzhen Wang
Browse files

Camera: Reduce unnecessary expanding of characteristics metadata

Camera service adds and modifies certain camera characteristics keys.
That has the adverse side effect of doubling the memory footprint of
the camera characteristics objects.

Reduce the chance of such side effect by reserving extra entries and
data count during initialization.

Flag: com.android.internal.camera.flags.metadata_resize_fix
Test: Observe heap profile of cameraserver in idle
Bug: 379388099
Change-Id: I4a4dc236e2afc26f2b958dd8f78b8096faa4d632
parent 4ecdd87b
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -280,3 +280,13 @@ flag {
    description: "Applies system controlled effects targetting video conferencing"
    bug: "376797335"
}

flag {
    namespace: "camera_platform"
    name: "metadata_resize_fix"
    description: "metadata resize during update needs to consider existing entry"
    bug: "379388099"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+28 −2
Original line number Diff line number Diff line
@@ -499,7 +499,20 @@ AidlProviderInfo::AidlDeviceInfo3::AidlDeviceInfo3(
    int resV = validate_camera_metadata_structure(buffer, &expectedSize);
    if (resV == OK || resV == CAMERA_METADATA_VALIDATION_SHIFTED) {
        set_camera_metadata_vendor_id(buffer, mProviderTagid);
        if (flags::metadata_resize_fix()) {
            //b/379388099: Create a CameraCharacteristics object slightly larger
            //to accommodate framework addition/modification. This is to
            //optimize memory because the CameraMetadata::update() doubles the
            //memory footprint, which could be significant if original
            //CameraCharacteristics is already large.
            mCameraCharacteristics = {
                    get_camera_metadata_entry_count(buffer) + CHARACTERISTICS_EXTRA_ENTRIES,
                    get_camera_metadata_data_count(buffer) + CHARACTERISTICS_EXTRA_DATA_SIZE
            };
            mCameraCharacteristics.append(buffer);
        } else {
            mCameraCharacteristics = buffer;
        }
    } else {
        ALOGE("%s: Malformed camera metadata received from HAL", __FUNCTION__);
        return;
@@ -703,7 +716,20 @@ AidlProviderInfo::AidlDeviceInfo3::AidlDeviceInfo3(
            int res = validate_camera_metadata_structure(pBuffer, &expectedSize);
            if (res == OK || res == CAMERA_METADATA_VALIDATION_SHIFTED) {
                set_camera_metadata_vendor_id(pBuffer, mProviderTagid);
                if (flags::metadata_resize_fix()) {
                    //b/379388099: Create a CameraCharacteristics object slightly larger
                    //to accommodate framework addition/modification. This is to
                    //optimize memory because the CameraMetadata::update() doubles the
                    //memory footprint, which could be significant if original
                    //CameraCharacteristics is already large.
                    mPhysicalCameraCharacteristics[id] = {
                          get_camera_metadata_entry_count(pBuffer) + CHARACTERISTICS_EXTRA_ENTRIES,
                          get_camera_metadata_data_count(pBuffer) + CHARACTERISTICS_EXTRA_DATA_SIZE
                    };
                    mPhysicalCameraCharacteristics[id].append(pBuffer);
                } else {
                    mPhysicalCameraCharacteristics[id] = pBuffer;
                }
            } else {
                ALOGE("%s: Malformed camera metadata received from HAL", __FUNCTION__);
                return;
+18 −0
Original line number Diff line number Diff line
@@ -173,6 +173,24 @@ struct AidlProviderInfo : public CameraProviderManager::ProviderInfo {
    };
    ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;

    // Estimate based on the camera framework modification on camera
    // characteristics:
    // - Flash strength: 4 entries
    // - Dynamic depth: 6 entries
    // - Heic: 6 entries
    // - Rotation and crop: 1 entry
    // - Autoframing: 1 entry
    // - Pre-correction active array size: 1 entry
    // - Zoom ratio: 1 entry
    // - Readout timestamp: 1 entry
    // - color correction modes: 1 entry
    // - AE priority modes: 1 entry
    // - Torch strength level: 2 entries
    // - Session config query version: 1 entry
    //
    // Total: 26 entries. Round up to 64 entries.
    static constexpr size_t CHARACTERISTICS_EXTRA_ENTRIES = 64;
    static constexpr size_t CHARACTERISTICS_EXTRA_DATA_SIZE = 1024; // in bytes
};

} // namespace android