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

Commit 4da7c6c9 authored by Yin-Chia Yeh's avatar Yin-Chia Yeh
Browse files

Camera: add webcam HAL@3.6 support

First CL to setup webcam HAL to support HIDL camera device 3.6.
Follow up CL will add actual offline processing capability.

Test: TestingCamera.apk
Bug: 135142453
Change-Id: Ifcd1b22f42d08b0fa5dc6039125c1d979b8104c2
parent 585950d8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ protected:
    // Calls into virtual member function. Do not use it in constructor
    status_t initCameraCharacteristics();
    // Init available capabilities keys
    status_t initAvailableCapabilities(
    virtual status_t initAvailableCapabilities(
            ::android::hardware::camera::common::V1_0::helper::CameraMetadata*);
    // Init non-device dependent keys
    virtual status_t initDefaultCharsKeys(
+66 −0
Original line number Diff line number Diff line
//
// Copyright (C) 2020 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.
//

cc_library_headers {
    name: "camera.device@3.6-external-impl_headers",
    vendor: true,
    export_include_dirs: ["include/ext_device_v3_6_impl"]
}

cc_library_shared {
    name: "camera.device@3.6-external-impl",
    defaults: ["hidl_defaults"],
    proprietary: true,
    vendor: true,
    srcs: [
        "ExternalCameraDevice.cpp",
        "ExternalCameraDeviceSession.cpp",
    ],
    shared_libs: [
        "libhidlbase",
        "libutils",
        "libcutils",
        "camera.device@3.2-impl",
        "camera.device@3.3-impl",
        "camera.device@3.4-external-impl",
        "camera.device@3.5-external-impl",
        "android.hardware.camera.device@3.2",
        "android.hardware.camera.device@3.3",
        "android.hardware.camera.device@3.4",
        "android.hardware.camera.device@3.5",
        "android.hardware.camera.device@3.6",
        "android.hardware.camera.provider@2.4",
        "android.hardware.graphics.mapper@2.0",
        "android.hardware.graphics.mapper@3.0",
        "android.hardware.graphics.mapper@4.0",
        "liblog",
        "libhardware",
        "libcamera_metadata",
        "libfmq",
        "libsync",
        "libyuv",
        "libjpeg",
        "libexif",
        "libtinyxml2"
    ],
    static_libs: [
        "android.hardware.camera.common@1.0-helper",
    ],
    local_include_dirs: ["include/ext_device_v3_6_impl"],
    export_shared_lib_headers: [
        "libfmq",
    ],
}
+91 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */

#define LOG_TAG "ExtCamDev@3.6"
//#define LOG_NDEBUG 0
#include <log/log.h>

#include "ExternalCameraDevice_3_6.h"

namespace android {
namespace hardware {
namespace camera {
namespace device {
namespace V3_6 {
namespace implementation {

ExternalCameraDevice::ExternalCameraDevice(
        const std::string& cameraId, const ExternalCameraConfig& cfg) :
        V3_5::implementation::ExternalCameraDevice(cameraId, cfg) {}

ExternalCameraDevice::~ExternalCameraDevice() {}

sp<V3_4::implementation::ExternalCameraDeviceSession> ExternalCameraDevice::createSession(
        const sp<V3_2::ICameraDeviceCallback>& cb,
        const ExternalCameraConfig& cfg,
        const std::vector<SupportedV4L2Format>& sortedFormats,
        const CroppingType& croppingType,
        const common::V1_0::helper::CameraMetadata& chars,
        const std::string& cameraId,
        unique_fd v4l2Fd) {
    return new ExternalCameraDeviceSession(
            cb, cfg, sortedFormats, croppingType, chars, cameraId, std::move(v4l2Fd));
}

#define UPDATE(tag, data, size)                    \
do {                                               \
  if (metadata->update((tag), (data), (size))) {   \
    ALOGE("Update " #tag " failed!");              \
    return -EINVAL;                                \
  }                                                \
} while (0)

status_t ExternalCameraDevice::initAvailableCapabilities(
        ::android::hardware::camera::common::V1_0::helper::CameraMetadata* metadata) {
    status_t res =
            V3_4::implementation::ExternalCameraDevice::initAvailableCapabilities(metadata);

    if (res != OK) {
        return res;
    }

    camera_metadata_entry caps = metadata->find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
    std::vector<uint8_t> availableCapabilities;

    for (size_t i = 0; i < caps.count; i++) {
        uint8_t capability = caps.data.u8[i];
        availableCapabilities.push_back(capability);
    }

    // Add OFFLINE_PROCESSING capability to device 3.6
    availableCapabilities.push_back(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_OFFLINE_PROCESSING);

    UPDATE(ANDROID_REQUEST_AVAILABLE_CAPABILITIES,
           availableCapabilities.data(),
           availableCapabilities.size());

    return OK;
}

#undef UPDATE

}  // namespace implementation
}  // namespace V3_6
}  // namespace device
}  // namespace camera
}  // namespace hardware
}  // namespace android
+100 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */

#define LOG_TAG "ExtCamDevSsn@3.6"
#include <android/log.h>

#include <utils/Trace.h>
#include "ExternalCameraDeviceSession.h"

namespace android {
namespace hardware {
namespace camera {
namespace device {
namespace V3_6 {
namespace implementation {

ExternalCameraDeviceSession::ExternalCameraDeviceSession(
        const sp<V3_2::ICameraDeviceCallback>& callback,
        const ExternalCameraConfig& cfg,
        const std::vector<SupportedV4L2Format>& sortedFormats,
        const CroppingType& croppingType,
        const common::V1_0::helper::CameraMetadata& chars,
        const std::string& cameraId,
        unique_fd v4l2Fd) :
        V3_5::implementation::ExternalCameraDeviceSession(
                callback, cfg, sortedFormats, croppingType, chars, cameraId, std::move(v4l2Fd)) {
}

ExternalCameraDeviceSession::~ExternalCameraDeviceSession() {}


Return<void> ExternalCameraDeviceSession::configureStreams_3_6(
        const StreamConfiguration& requestedConfiguration,
        ICameraDeviceSession::configureStreams_3_6_cb _hidl_cb)  {
    V3_2::StreamConfiguration config_v32;
    V3_3::HalStreamConfiguration outStreams_v33;
    V3_6::HalStreamConfiguration outStreams;
    const V3_4::StreamConfiguration& requestedConfiguration_3_4 = requestedConfiguration.v3_4;
    Mutex::Autolock _il(mInterfaceLock);

    config_v32.operationMode = requestedConfiguration_3_4.operationMode;
    config_v32.streams.resize(requestedConfiguration_3_4.streams.size());
    uint32_t blobBufferSize = 0;
    int numStallStream = 0;
    for (size_t i = 0; i < config_v32.streams.size(); i++) {
        config_v32.streams[i] = requestedConfiguration_3_4.streams[i].v3_2;
        if (config_v32.streams[i].format == PixelFormat::BLOB) {
            blobBufferSize = requestedConfiguration_3_4.streams[i].bufferSize;
            numStallStream++;
        }
    }

    // Fail early if there are multiple BLOB streams
    if (numStallStream > kMaxStallStream) {
        ALOGE("%s: too many stall streams (expect <= %d, got %d)", __FUNCTION__,
                kMaxStallStream, numStallStream);
        _hidl_cb(Status::ILLEGAL_ARGUMENT, outStreams);
        return Void();
    }

    Status status = configureStreams(config_v32, &outStreams_v33, blobBufferSize);

    outStreams.streams.resize(outStreams_v33.streams.size());
    for (size_t i = 0; i < outStreams.streams.size(); i++) {
        outStreams.streams[i].v3_4.v3_3 = outStreams_v33.streams[i];
        // TODO: implement it later
        outStreams.streams[i].supportOffline = false;
    }
    _hidl_cb(status, outStreams);
    return Void();
}

Return<void> ExternalCameraDeviceSession::switchToOffline(
        const hidl_vec<int32_t>& streamsToKeep,
        ICameraDeviceSession::switchToOffline_cb _hidl_cb) {
    // TODO: implement this
    (void) streamsToKeep;
    (void) _hidl_cb;
    return Void();
}

} // namespace implementation
}  // namespace V3_6
}  // namespace device
}  // namespace camera
}  // namespace hardware
}  // namespace android
+1 −0
Original line number Diff line number Diff line
include platform/frameworks/av:/camera/OWNERS
Loading