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

Commit aaec7976 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "codec2 hal: AIDL type conversion, step 2" into main

parents ca545707 7055d7f4
Loading
Loading
Loading
Loading
+149 −0
Original line number Diff line number Diff line
package {
    default_applicable_licenses: ["frameworks_av_license"],
}

// DO NOT DEPEND ON THIS DIRECTLY
// use libcodec2-aidl-client-defaults instead
cc_library {
    name: "libcodec2_aidl_client",

    srcs: [
        "ParamTypes.cpp",
    ],

    header_libs: [
        "libcodec2_hal_common",
        "libcodec2_internal", // private
        "libgui_headers",
    ],

    shared_libs: [
        "android.hardware.media.bufferpool@2.0",
        "android.hardware.media.c2-V1-ndk",
        "libbinder_ndk",
        "libbase",
        "libcodec2",
        "libcodec2_vndk",
        "libcutils",
        "liblog",
        "libnativewindow",
        "libutils",
    ],

    export_include_dirs: [
        "include",
    ],

    export_shared_lib_headers: [
        "android.hardware.media.c2-V1-ndk",
        "libcodec2",
    ],
}

// DO NOT DEPEND ON THIS DIRECTLY
// use libcodec2-hidl-defaults instead
//cc_library {
//    name: "libcodec2_hidl@1.0",
//    vendor_available: true,
//    min_sdk_version: "29",
//    apex_available: [
//        "//apex_available:platform",
//        "com.android.media.swcodec",
//    ],
//
//    defaults: ["hidl_defaults"],
//
//    srcs: [
//        "Component.cpp",
//        "ComponentInterface.cpp",
//        "ComponentStore.cpp",
//        "Configurable.cpp",
//        "InputBufferManager.cpp",
//        "InputSurface.cpp",
//        "InputSurfaceConnection.cpp",
//        "types.cpp",
//    ],
//
//    header_libs: [
//        "libbinder_headers",
//        "libcodec2_hal_common",
//        "libcodec2_internal", // private
//        "libsystem_headers",
//    ],
//
//    shared_libs: [
//        "android.hardware.graphics.bufferqueue@1.0",
//        "android.hardware.graphics.bufferqueue@2.0",
//        "android.hardware.graphics.common@1.0",
//        "android.hardware.media@1.0",
//        "android.hardware.media.bufferpool@2.0",
//        "android.hardware.media.c2@1.0",
//        "android.hardware.media.omx@1.0",
//        "libbase",
//        "libcodec2",
//        "libcodec2_vndk",
//        "libcodec2_hidl_plugin_stub",
//        "libcutils",
//        "libhidlbase",
//        "liblog",
//        "libstagefright_bufferpool@2.0.1",
//        "libstagefright_bufferqueue_helper_novndk",
//        "libui",
//        "libutils",
//    ],
//
//    target: {
//        vendor: {
//            exclude_shared_libs: [
//                "libstagefright_bufferqueue_helper_novndk",
//                "libcodec2_hidl_plugin_stub",
//            ],
//            shared_libs: [
//                "libstagefright_bufferqueue_helper",
//                "libcodec2_hidl_plugin",
//            ],
//        },
//        apex: {
//            exclude_shared_libs: [
//                "libcodec2_hidl_plugin",
//                "libcodec2_hidl_plugin_stub",
//            ],
//        },
//    },
//
//    export_include_dirs: [
//        "include",
//    ],
//
//    export_shared_lib_headers: [
//        "android.hardware.media.c2@1.0",
//        "libcodec2",
//        "libcodec2_vndk",
//        "libhidlbase",
//        "libstagefright_bufferpool@2.0.1",
//        "libui",
//    ],
//}
//
//// public dependency for Codec 2.0 HAL service implementations
//cc_defaults {
//    name: "libcodec2-hidl-defaults@1.0",
//    defaults: ["libcodec2-impl-defaults"],
//
//    shared_libs: [
//        "android.hardware.media.c2@1.0",
//        "libcodec2_hidl@1.0",
//    ],
//}

// public dependency for Codec 2.0 HAL client
cc_defaults {
    name: "libcodec2-aidl-client-defaults",
    min_sdk_version: "34",
    defaults: ["libcodec2-impl-defaults"],

    shared_libs: [
        "android.hardware.media.c2-V1-ndk",
        "libcodec2_aidl_client",
    ],
}
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 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.
 */

#ifndef CODEC2_AIDL_UTILS_PARAM_TYPES_SPECIALIZATIONS_H
#define CODEC2_AIDL_UTILS_PARAM_TYPES_SPECIALIZATIONS_H

#include <aidl/android/hardware/media/c2/FieldId.h>
#include <aidl/android/hardware/media/c2/FieldSupportedValues.h>
#include <aidl/android/hardware/media/c2/Params.h>
#include <aidl/android/hardware/media/c2/Status.h>
#include <codec2/common/ParamTypes.h>

namespace android {

using ::aidl::android::hardware::media::c2::FieldId;
using ::aidl::android::hardware::media::c2::FieldSupportedValues;
using ::aidl::android::hardware::media::c2::Params;
using ::aidl::android::hardware::media::c2::Status;

// {offset, size} -> FieldId
template<>
void SetFieldId(FieldId *d, uint32_t offset, uint32_t size);

// FieldId -> offset
template<>
uint32_t GetOffsetFromFieldId(const FieldId &s);

// FieldId -> size
template<>
uint32_t GetSizeFromFieldId(const FieldId &s);

template<>
void SetStatus(Status *dst, c2_status_t src);

template<>
c2_status_t GetStatus(const Status &status);

// C2FieldSupportedValues -> FieldSupportedValues
template<>
bool objcpy(FieldSupportedValues *d, const C2FieldSupportedValues &s);

// FieldSupportedValues -> C2FieldSupportedValues
template<>
bool objcpy(C2FieldSupportedValues *d, const FieldSupportedValues &s);

template<>
struct _ParamsBlobHelper<Params> { typedef std::vector<uint8_t> BlobType; };

template<>
const std::vector<uint8_t> &GetBlob<Params>(const Params &params);

template<>
std::vector<uint8_t> *GetBlob<Params>(Params *params);

} // namespace android



#endif  // CODEC2_AIDL_UTILS_PARAM_TYPES_SPECIALIZATIONS_H
+124 −1744

File changed.

Preview size limit exceeded, changes collapsed.

+39 −222
Original line number Diff line number Diff line
@@ -14,57 +14,29 @@
 * limitations under the License.
 */

#ifndef CODEC2_HIDL_V1_0_UTILS_TYPES_H
#define CODEC2_HIDL_V1_0_UTILS_TYPES_H
#ifndef CODEC2_AIDL_UTILS_PARAM_TYPES_H
#define CODEC2_AIDL_UTILS_PARAM_TYPES_H

#include <bufferpool/ClientManager.h>
#include <android/hardware/media/bufferpool/2.0/IClientManager.h>
#include <android/hardware/media/bufferpool/2.0/types.h>
#include <android/hardware/media/c2/1.0/IComponentStore.h>
#include <android/hardware/media/c2/1.0/types.h>
#include <android/hidl/safe_union/1.0/types.h>
#include <aidl/android/hardware/media/c2/FieldSupportedValuesQuery.h>
#include <aidl/android/hardware/media/c2/FieldSupportedValuesQueryResult.h>
#include <aidl/android/hardware/media/c2/IComponentStore.h>
#include <aidl/android/hardware/media/c2/ParamDescriptor.h>
#include <aidl/android/hardware/media/c2/SettingResult.h>
#include <aidl/android/hardware/media/c2/Status.h>
#include <aidl/android/hardware/media/c2/StructDescriptor.h>

#include <C2Component.h>
#include <C2Param.h>
#include <C2ParamDef.h>
#include <C2Work.h>
#include <util/C2Debug-base.h>

#include <chrono>

using namespace std::chrono_literals;

namespace aidl {
namespace android {
namespace hardware {
namespace media {
namespace c2 {
namespace V1_0 {
namespace utils {

using ::android::hardware::hidl_bitfield;
using ::android::hardware::hidl_handle;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::status_t;
using ::android::sp;
using ::android::hardware::media::bufferpool::V2_0::implementation::
        ConnectionId;

// Types of metadata for Blocks.
struct C2Hidl_Range {
    uint32_t offset;
    uint32_t length; // Do not use "size" because the name collides with C2Info::size().
};
typedef C2GlobalParam<C2Info, C2Hidl_Range, 0> C2Hidl_RangeInfo;

struct C2Hidl_Rect {
    uint32_t left;
    uint32_t top;
    uint32_t width;
    uint32_t height;
};
typedef C2GlobalParam<C2Info, C2Hidl_Rect, 1> C2Hidl_RectInfo;

// Make asString() and operator<< work with Status as well as c2_status_t.
C2_DECLARE_AS_STRING_AND_DEFINE_STREAM_OUT(Status);

@@ -74,169 +46,66 @@ C2_DECLARE_AS_STRING_AND_DEFINE_STREAM_OUT(Status);
 */

// C2SettingResult -> SettingResult
bool objcpy(
bool ToAidl(
        SettingResult* d,
        const C2SettingResult& s);

// SettingResult -> std::unique_ptr<C2SettingResult>
bool objcpy(
bool FromAidl(
        std::unique_ptr<C2SettingResult>* d,
        const SettingResult& s);

// C2ParamDescriptor -> ParamDescriptor
bool objcpy(
bool ToAidl(
        ParamDescriptor* d,
        const C2ParamDescriptor& s);

// ParamDescriptor -> std::shared_ptr<C2ParamDescriptor>
bool objcpy(
bool FromAidl(
        std::shared_ptr<C2ParamDescriptor>* d,
        const ParamDescriptor& s);

// C2FieldSupportedValuesQuery -> FieldSupportedValuesQuery
bool objcpy(
bool ToAidl(
        FieldSupportedValuesQuery* d,
        const C2FieldSupportedValuesQuery& s);

// FieldSupportedValuesQuery -> C2FieldSupportedValuesQuery
bool objcpy(
bool FromAidl(
        C2FieldSupportedValuesQuery* d,
        const FieldSupportedValuesQuery& s);

// C2FieldSupportedValuesQuery -> FieldSupportedValuesQueryResult
bool objcpy(
bool ToAidl(
        FieldSupportedValuesQueryResult* d,
        const C2FieldSupportedValuesQuery& s);

// FieldSupportedValuesQuery, FieldSupportedValuesQueryResult -> C2FieldSupportedValuesQuery
bool objcpy(
bool FromAidl(
        C2FieldSupportedValuesQuery* d,
        const FieldSupportedValuesQuery& sq,
        const FieldSupportedValuesQueryResult& sr);

// C2Component::Traits -> ComponentTraits
bool objcpy(
bool ToAidl(
        IComponentStore::ComponentTraits* d,
        const C2Component::Traits& s);

// ComponentTraits -> C2Component::Traits
bool objcpy(
bool FromAidl(
        C2Component::Traits* d,
        const IComponentStore::ComponentTraits& s);

// C2StructDescriptor -> StructDescriptor
bool objcpy(
bool ToAidl(
        StructDescriptor* d,
        const C2StructDescriptor& s);

// StructDescriptor -> C2StructDescriptor
bool objcpy(
bool FromAidl(
        std::unique_ptr<C2StructDescriptor>* d,
        const StructDescriptor& s);

// Abstract class to be used in
// objcpy(std::list<std::unique_ptr<C2Work>> -> WorkBundle).
struct BufferPoolSender {
    typedef ::android::hardware::media::bufferpool::V2_0::
            ResultStatus ResultStatus;
    typedef ::android::hardware::media::bufferpool::V2_0::
            BufferStatusMessage BufferStatusMessage;
    typedef ::android::hardware::media::bufferpool::
            BufferPoolData BufferPoolData;

    /**
     * Send bpData and return BufferStatusMessage that can be supplied to
     * IClientManager::receive() in the receiving process.
     *
     * This function will be called from within the function
     * objcpy(std::list<std::unique_ptr<C2Work>> -> WorkBundle).
     *
     * \param[in] bpData BufferPoolData identifying the buffer to send.
     * \param[out] bpMessage BufferStatusMessage of the transaction. Information
     *    inside \p bpMessage should be passed to the receiving process by some
     *    other means so it can call receive() properly.
     * \return ResultStatus value that determines the success of the operation.
     *    (See the possible values of ResultStatus in
     *    hardware/interfaces/media/bufferpool/2.0/types.hal.)
     */
    virtual ResultStatus send(
            const std::shared_ptr<BufferPoolData>& bpData,
            BufferStatusMessage* bpMessage) = 0;

    virtual ~BufferPoolSender() = default;
};

// Default implementation of BufferPoolSender.
//
// To use DefaultBufferPoolSender, the IClientManager instance of the receiving
// process must be set before send() can operate. DefaultBufferPoolSender will
// hold a strong reference to the IClientManager instance and use it to call
// IClientManager::registerSender() to establish the bufferpool connection when
// send() is called.
struct DefaultBufferPoolSender : BufferPoolSender {
    typedef ::android::hardware::media::bufferpool::V2_0::implementation::
            ClientManager ClientManager;
    typedef ::android::hardware::media::bufferpool::V2_0::
            IClientManager IClientManager;

    // Set the IClientManager instance of the receiving process and the refresh
    // interval for the connection. The default interval is 4.5 seconds, which
    // is slightly shorter than the amount of time the bufferpool will keep an
    // inactive connection for.
    DefaultBufferPoolSender(
            const sp<IClientManager>& receiverManager = nullptr,
            std::chrono::steady_clock::duration refreshInterval = 4500ms);

    // Set the IClientManager instance of the receiving process and the refresh
    // interval for the connection. The default interval is 4.5 seconds, which
    // is slightly shorter than the amount of time the bufferpool will keep an
    // inactive connection for.
    void setReceiver(
            const sp<IClientManager>& receiverManager,
            std::chrono::steady_clock::duration refreshInterval = 4500ms);

    // Implementation of BufferPoolSender::send(). send() will establish a
    // bufferpool connection if needed, then send the bufferpool data over to
    // the receiving process.
    virtual ResultStatus send(
            const std::shared_ptr<BufferPoolData>& bpData,
            BufferStatusMessage* bpMessage) override;

private:
    std::mutex mMutex;
    sp<ClientManager> mSenderManager;
    sp<IClientManager> mReceiverManager;
    std::chrono::steady_clock::duration mRefreshInterval;

    struct Connection {
        int64_t receiverConnectionId;
        std::chrono::steady_clock::time_point lastSent;
        Connection(int64_t receiverConnectionId,
                   std::chrono::steady_clock::time_point lastSent)
              : receiverConnectionId(receiverConnectionId),
                lastSent(lastSent) {
        }
    };

    // Map of connections.
    //
    // The key is the connection id. One sender-receiver pair may have multiple
    // connections.
    std::map<int64_t, Connection> mConnections;
};

// std::list<std::unique_ptr<C2Work>> -> WorkBundle
// Note: If bufferpool will be used, bpSender must not be null.
bool objcpy(
        WorkBundle* d,
        const std::list<std::unique_ptr<C2Work>>& s,
        BufferPoolSender* bpSender = nullptr);

// WorkBundle -> std::list<std::unique_ptr<C2Work>>
bool objcpy(
        std::list<std::unique_ptr<C2Work>>* d,
        const WorkBundle& s);

/**
 * Parses a params blob and returns C2Param pointers to its params. The pointers
 * point to locations inside the underlying buffer of \p blob. If \p blob is
@@ -247,9 +116,9 @@ bool objcpy(
 * \retval true if the full blob was parsed
 * \retval false otherwise
 */
bool parseParamsBlob(
bool ParseParamsBlob(
        std::vector<C2Param*> *params,
        const hidl_vec<uint8_t> &blob);
        const Params &blob);

/**
 * Concatenates a list of C2Params into a params blob.
@@ -260,17 +129,17 @@ bool parseParamsBlob(
 * \retval false if the blob was not successful (this only happens if the
 *         parameters were not const)
 */
bool createParamsBlob(
        hidl_vec<uint8_t> *blob,
bool CreateParamsBlob(
        Params *blob,
        const std::vector<C2Param*> &params);
bool createParamsBlob(
        hidl_vec<uint8_t> *blob,
bool CreateParamsBlob(
        Params *blob,
        const std::vector<std::unique_ptr<C2Param>> &params);
bool createParamsBlob(
        hidl_vec<uint8_t> *blob,
bool CreateParamsBlob(
        Params *blob,
        const std::vector<std::shared_ptr<const C2Info>> &params);
bool createParamsBlob(
        hidl_vec<uint8_t> *blob,
bool CreateParamsBlob(
        Params *blob,
        const std::vector<std::unique_ptr<C2Tuning>> &params);

/**
@@ -282,12 +151,12 @@ bool createParamsBlob(
 * \retval true if the full blob was parsed and params was constructed
 * \retval false otherwise
 */
bool copyParamsFromBlob(
bool CopyParamsFromBlob(
        std::vector<std::unique_ptr<C2Param>>* params,
        Params blob);
bool copyParamsFromBlob(
        const Params &blob);
bool CopyParamsFromBlob(
        std::vector<std::unique_ptr<C2Tuning>>* params,
        Params blob);
        const Params &blob);

/**
 * Parses a params blob and applies updates to params.
@@ -297,67 +166,15 @@ bool copyParamsFromBlob(
 * \retval true if the full blob was parsed and params was updated
 * \retval false otherwise
 */
bool updateParamsFromBlob(
bool UpdateParamsFromBlob(
        const std::vector<C2Param*>& params,
        const Params& blob);

/**
 * Converts a BufferPool status value to c2_status_t.
 * \param BufferPool status
 * \return Corresponding c2_status_t
 */
c2_status_t toC2Status(::android::hardware::media::bufferpool::V2_0::
        ResultStatus rs);

// BufferQueue-Based Block Operations
// ==================================

// Call before transferring block to other processes.
//
// The given block is ready to transfer to other processes. This will guarantee
// the given block data is not mutated by bufferqueue migration.
bool beginTransferBufferQueueBlock(const C2ConstGraphicBlock& block);

// Call beginTransferBufferQueueBlock() on blocks in the given workList.
// processInput determines whether input blocks are yielded. processOutput
// works similarly on output blocks. (The default value of processInput is
// false while the default value of processOutput is true. This implies that in
// most cases, only output buffers contain bufferqueue-based blocks.)
void beginTransferBufferQueueBlocks(
        const std::list<std::unique_ptr<C2Work>>& workList,
        bool processInput = false,
        bool processOutput = true);

// Call after transferring block is finished and make sure that
// beginTransferBufferQueueBlock() is called before.
//
// The transfer of given block is finished. If transfer is successful the given
// block is not owned by process anymore. Since transfer is finished the given
// block data is OK to mutate by bufferqueue migration after this call.
bool endTransferBufferQueueBlock(const C2ConstGraphicBlock& block,
                                 bool transfer);

// Call endTransferBufferQueueBlock() on blocks in the given workList.
// processInput determines whether input blocks are yielded. processOutput
// works similarly on output blocks. (The default value of processInput is
// false while the default value of processOutput is true. This implies that in
// most cases, only output buffers contain bufferqueue-based blocks.)
void endTransferBufferQueueBlocks(
        const std::list<std::unique_ptr<C2Work>>& workList,
        bool transfer,
        bool processInput = false,
        bool processOutput = true);

// The given block is ready to be rendered. the given block is not owned by
// process anymore. If migration is in progress, this returns false in order
// not to render.
bool displayBufferQueueBlock(const C2ConstGraphicBlock& block);

}  // namespace utils
}  // namespace V1_0
}  // namespace c2
}  // namespace media
}  // namespace hardware
}  // namespace android
}  // namespace aidl

#endif  // CODEC2_HIDL_V1_0_UTILS_TYPES_H
#endif  // CODEC2_AIDL_UTILS_PARAM_TYPES_H