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

Commit 7b0acc5b authored by Sungtak Lee's avatar Sungtak Lee Committed by Gerrit Code Review
Browse files

Merge changes from topic "c2aidl-hidl-token" into main

* changes:
  media.c2 aidl: use aidl based PersistentSurface for c2 aidl
  media.c2 aidl: PersistentSurface: add an option to use AIDL interface
  media.c2 aidl: add C2AidlNode
  sfplugin: rename C2OMXNode to C2NodeImpl
  media c2.aidl: PersistentSurface related aidl defs & impls
parents 255708d3 92bca445
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1868,6 +1868,10 @@ std::shared_ptr<Codec2Client::InputSurface> Codec2Client::CreateInputSurface(
    return nullptr;
}

bool Codec2Client::IsAidlSelected() {
    return c2_aidl::utils::IsSelected();
}

// Codec2Client::Interface
Codec2Client::Interface::Interface(const sp<HidlBase>& base)
      : Configurable{
+3 −0
Original line number Diff line number Diff line
@@ -270,6 +270,9 @@ struct Codec2Client : public Codec2ConfigurableClient {
    static std::shared_ptr<InputSurface> CreateInputSurface(
            char const* serviceName = nullptr);

    // Whether AIDL is selected.
    static bool IsAidlSelected();

    // base and/or configurable cannot be null.
    Codec2Client(
            sp<HidlBase> const& base,
+7 −0
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ cc_library_shared {
    export_include_dirs: ["include"],

    srcs: [
        "C2AidlNode.cpp",
        "C2OMXNode.cpp",
        "C2NodeImpl.cpp",
        "CCodec.cpp",
        "CCodecBufferChannel.cpp",
        "CCodecBuffers.cpp",
@@ -54,8 +56,11 @@ cc_library_shared {
        "android.hardware.drm@1.0",
        "android.hardware.media.c2@1.0",
        "android.hardware.media.omx@1.0",
        "android.hardware.graphics.common-V5-ndk",
        "graphicbuffersource-aidl-ndk",
        "libbase",
        "libbinder",
        "libbinder_ndk",
        "libcodec2",
        "libcodec2_client",
        "libcodec2_vndk",
@@ -67,9 +72,11 @@ cc_library_shared {
        "liblog",
        "libmedia_codeclist",
        "libmedia_omx",
        "libnativewindow",
        "libsfplugin_ccodec_utils",
        "libstagefright_bufferqueue_helper",
        "libstagefright_codecbase",
        "libstagefright_graphicbuffersource_aidl",
        "libstagefright_foundation",
        "libstagefright_omx",
        "libstagefright_surface_utils",
+130 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.
 */
//#define LOG_NDEBUG 0
#define LOG_TAG "C2AidlNode"
#include <log/log.h>
#include <private/android/AHardwareBufferHelpers.h>

#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/aidlpersistentsurface/wrapper/Conversion.h>

#include "C2NodeImpl.h"
#include "C2AidlNode.h"

namespace android {

using ::aidl::android::media::IAidlBufferSource;
using ::aidl::android::media::IAidlNode;

using ::android::media::CommandStateSet;
using ::android::media::NodeStatusLoaded;

// Conversion
using ::android::media::aidl_conversion::toAidlStatus;

C2AidlNode::C2AidlNode(const std::shared_ptr<Codec2Client::Component> &comp)
    : mImpl(new C2NodeImpl(comp, true)) {}

// aidl ndk interfaces
::ndk::ScopedAStatus C2AidlNode::freeNode() {
    return toAidlStatus(mImpl->freeNode());
}

::ndk::ScopedAStatus C2AidlNode::sendCommand(int32_t cmd, int32_t param) {
    if (cmd == CommandStateSet && param == NodeStatusLoaded) {
        mImpl->onFirstInputFrame();
    }
    return toAidlStatus(ERROR_UNSUPPORTED);
}

::ndk::ScopedAStatus C2AidlNode::getConsumerUsage(int64_t* _aidl_return) {
    uint64_t usage;
    mImpl->getConsumerUsageBits(&usage);
    *_aidl_return = usage;
    return ::ndk::ScopedAStatus::ok();
}

::ndk::ScopedAStatus C2AidlNode::getInputBufferParams(IAidlNode::InputBufferParams* _aidl_return) {
    mImpl->getInputBufferParams(_aidl_return);
    return ::ndk::ScopedAStatus::ok();
}

::ndk::ScopedAStatus C2AidlNode::setConsumerUsage(int64_t usage) {
    mImpl->setConsumerUsageBits(static_cast<uint64_t>(usage));
    return ::ndk::ScopedAStatus::ok();
}

::ndk::ScopedAStatus C2AidlNode::setAdjustTimestampGapUs(int32_t gapUs) {
    mImpl->setAdjustTimestampGapUs(gapUs);
    return ::ndk::ScopedAStatus::ok();
}

::ndk::ScopedAStatus C2AidlNode::setInputSurface(
        const std::shared_ptr<IAidlBufferSource>& bufferSource) {
    return toAidlStatus(mImpl->setAidlInputSurface(bufferSource));
}

::ndk::ScopedAStatus C2AidlNode::submitBuffer(
        int32_t buffer, const ::aidl::android::hardware::HardwareBuffer& hBuffer,
        int32_t flags, int64_t timestamp, const ::ndk::ScopedFileDescriptor& fence) {
    sp<GraphicBuffer> gBuf;
    AHardwareBuffer *ahwb = hBuffer.get();
    if (ahwb) {
        gBuf = AHardwareBuffer_to_GraphicBuffer(ahwb);
    }
    return toAidlStatus(mImpl->submitBuffer(
            buffer, gBuf, flags, timestamp, ::dup(fence.get())));
}

::ndk::ScopedAStatus C2AidlNode::onDataSpaceChanged(
        int32_t dataSpace,
        int32_t aspects,
        int32_t pixelFormat) {
    // NOTE: legacy codes passed aspects, but they didn't used.
    (void)aspects;

    return toAidlStatus(mImpl->onDataspaceChanged(
            static_cast<uint32_t>(dataSpace),
            static_cast<uint32_t>(pixelFormat)));
}

// cpp interface

std::shared_ptr<IAidlBufferSource> C2AidlNode::getSource() {
    return mImpl->getAidlSource();
}

void C2AidlNode::setFrameSize(uint32_t width, uint32_t height) {
    return mImpl->setFrameSize(width, height);
}

void C2AidlNode::onInputBufferDone(c2_cntr64_t index) {
    return mImpl->onInputBufferDone(index);
}

android_dataspace C2AidlNode::getDataspace() {
    return mImpl->getDataspace();
}

uint32_t C2AidlNode::getPixelFormat() {
    return mImpl->getPixelFormat();
}

void C2AidlNode::setPriority(int priority) {
    return mImpl->setPriority(priority);
}

}  // namespace android
+99 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.
 */

#pragma once

#include <aidl/android/media/BnAidlNode.h>
#include <codec2/hidl/client.h>

namespace android {

struct C2NodeImpl;

/**
 * Thin Codec2 AIdL encoder HAL wrapper for InputSurface
 */
class C2AidlNode : public ::aidl::android::media::BnAidlNode {
public:
    explicit C2AidlNode(const std::shared_ptr<Codec2Client::Component> &comp);
    ~C2AidlNode() override = default;

    // IAidlNode
    ::ndk::ScopedAStatus freeNode() override;

    ::ndk::ScopedAStatus sendCommand(int32_t cmd, int32_t param) override;

    ::ndk::ScopedAStatus getConsumerUsage(int64_t *_aidl_return) override;

    ::ndk::ScopedAStatus getInputBufferParams(
            ::aidl::android::media::IAidlNode::InputBufferParams *_aidl_return) override;

    ::ndk::ScopedAStatus setConsumerUsage(int64_t usage) override;

    ::ndk::ScopedAStatus setAdjustTimestampGapUs(int32_t gapUs) override;

    ::ndk::ScopedAStatus setInputSurface(
            const std::shared_ptr<::aidl::android::media::IAidlBufferSource>&
                    bufferSource) override;

    ::ndk::ScopedAStatus submitBuffer(
            int32_t buffer,
            const ::aidl::android::hardware::HardwareBuffer& hBuffer,
            int32_t flags,
            int64_t timestampUs,
            const ::ndk::ScopedFileDescriptor& fence) override;

    ::ndk::ScopedAStatus onDataSpaceChanged(
            int dataSpace, int aspects, int pixelFormat) override;

    /**
     * Returns underlying IAidlBufferSource object.
     */
    std::shared_ptr<::aidl::android::media::IAidlBufferSource> getSource();

    /**
     * Configure the frame size.
     */
    void setFrameSize(uint32_t width, uint32_t height);

    /**
     * Clean up work item reference.
     *
     * \param index input work index
     */
    void onInputBufferDone(c2_cntr64_t index);

    /**
     * Returns dataspace information from GraphicBufferSource.
     */
    android_dataspace getDataspace();

    /**
     * Returns dataspace information from GraphicBufferSource.
     */
    uint32_t getPixelFormat();

    /**
     * Sets priority of the queue thread.
     */
    void setPriority(int priority);

private:
    std::shared_ptr<C2NodeImpl> mImpl;
};

}  // namespace android
Loading