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

Commit 0ffef2c3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Camera: Filter out extension keys if needed" into main

parents a8b7ec8e 3a4fa466
Loading
Loading
Loading
Loading
+45 −1
Original line number Diff line number Diff line
@@ -17,12 +17,13 @@
#define LOG_TAG "AidlUtils"

#include <aidl/AidlUtils.h>
#include <aidl/ExtensionMetadataTags.h>
#include <aidl/VndkVersionMetadataTags.h>
#include <aidlcommonsupport/NativeHandle.h>
#include <camera/StringUtils.h>
#include <device3/Camera3StreamInterface.h>
#include <gui/bufferqueue/1.0/H2BGraphicBufferProducer.h>
#include <mediautils/AImageReaderUtils.h>
#include <camera/StringUtils.h>

namespace android::hardware::cameraservice::utils::conversion::aidl {

@@ -333,4 +334,47 @@ status_t filterVndkKeys(int vndkVersion, CameraMetadata &metadata, bool isStatic
    return OK;
}

bool areExtensionKeysSupported(const CameraMetadata& metadata) {
    auto requestKeys = metadata.find(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS);
    if (requestKeys.count == 0) {
        ALOGE("%s: No ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS entries!", __FUNCTION__);
        return false;
    }

    auto resultKeys = metadata.find(ANDROID_REQUEST_AVAILABLE_RESULT_KEYS);
    if (resultKeys.count == 0) {
        ALOGE("%s: No ANDROID_REQUEST_AVAILABLE_RESULT_KEYS entries!", __FUNCTION__);
        return false;
    }

    for (const auto& extensionKey : extension_metadata_keys) {
        if (std::find(requestKeys.data.i32, requestKeys.data.i32 + requestKeys.count, extensionKey)
                != requestKeys.data.i32 + requestKeys.count) {
            return true;
        }

        if (std::find(resultKeys.data.i32, resultKeys.data.i32 + resultKeys.count, extensionKey)
                != resultKeys.data.i32 + resultKeys.count) {
            return true;
        }
    }

    return false;
}

status_t filterExtensionKeys(CameraMetadata* metadata /*out*/) {
    if (metadata == nullptr) {
        return BAD_VALUE;
    }

    for (const auto& key : extension_metadata_keys) {
        status_t res = metadata->erase(key);
        if (res != OK) {
            ALOGE("%s metadata key %d could not be erased", __FUNCTION__, key);
            return res;
        }
    }
    return OK;
}

} // namespace android::hardware::cameraservice::utils::conversion::aidl
+3 −0
Original line number Diff line number Diff line
@@ -122,6 +122,9 @@ bool areBindersEqual(const ndk::SpAIBinder& b1, const ndk::SpAIBinder& b2);

status_t filterVndkKeys(int vndkVersion, CameraMetadata &metadata, bool isStatic = true);

bool areExtensionKeysSupported(const CameraMetadata& metadata);

status_t filterExtensionKeys(CameraMetadata* metadata /*out*/);
} // namespace android::hardware::cameraservice::utils::conversion::aidl

#endif  // FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLUTILS_H_
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <vector>
#pragma once
/**
 * ! Do not edit this file directly !
 *
 * Generated automatically from extensions_camera_metadata_tags.mako. To be included in libcameraservice
 * only by aidl/AidlUtils.cpp.
 */

/**
 * API level to dynamic keys mapping. To be used for filtering out keys depending on vndk version
 * used by vendor clients.
 */
std::vector<camera_metadata_tag> extension_metadata_keys{
            ANDROID_EXTENSION_STRENGTH,
            ANDROID_EXTENSION_CURRENT_TYPE,
            ANDROID_EFV_PADDING_ZOOM_FACTOR,
            ANDROID_EFV_AUTO_ZOOM,
            ANDROID_EFV_MAX_PADDING_ZOOM_FACTOR,
            ANDROID_EFV_STABILIZATION_MODE,
            ANDROID_EFV_TRANSLATE_VIEWPORT,
            ANDROID_EFV_ROTATE_VIEWPORT,
            ANDROID_EFV_PADDING_REGION,
            ANDROID_EFV_AUTO_ZOOM_PADDING_REGION,
            ANDROID_EFV_TARGET_COORDINATES,
};
+14 −2
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@
using namespace android::camera3;
using namespace android::camera3::SessionConfigurationUtils;
using namespace android::hardware::camera;
using namespace android::hardware::cameraservice::utils::conversion::aidl;

namespace flags = com::android::internal::camera::flags;
namespace android {
@@ -254,6 +255,8 @@ status_t Camera3Device::initializeCommonLocked() {
        return res;
    }

    mSupportsExtensionKeys = areExtensionKeysSupported(mDeviceInfo);

    return OK;
}

@@ -3887,13 +3890,22 @@ status_t Camera3Device::RequestThread::prepareHalRequests() {

                    for (it = captureRequest->mSettingsList.begin();
                            it != captureRequest->mSettingsList.end(); it++) {
                        res = hardware::cameraservice::utils::conversion::aidl::filterVndkKeys(
                                mVndkVersion, it->metadata, false /*isStatic*/);
                        res = filterVndkKeys(mVndkVersion, it->metadata, false /*isStatic*/);
                        if (res != OK) {
                            SET_ERR("RequestThread: Failed during VNDK filter of capture requests "
                                    "%d: %s (%d)", halRequest->frame_number, strerror(-res), res);
                            return INVALID_OPERATION;
                        }

                        if (!parent->mSupportsExtensionKeys) {
                            res = filterExtensionKeys(&it->metadata);
                            if (res != OK) {
                                SET_ERR("RequestThread: Failed during extension filter of capture "
                                        "requests %d: %s (%d)", halRequest->frame_number,
                                        strerror(-res), res);
                                return INVALID_OPERATION;
                            }
                        }
                    }
                }
            }
+3 −0
Original line number Diff line number Diff line
@@ -1523,6 +1523,9 @@ class Camera3Device :
    // AE_TARGET_FPS_RANGE
    bool mIsFixedFps = false;

    // Flag to indicate that we shouldn't forward extension related metadata
    bool mSupportsExtensionKeys = false;

    // Injection camera related methods.
    class Camera3DeviceInjectionMethods : public virtual RefBase {
      public: