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

Commit b48b5aff authored by Sungtak Lee's avatar Sungtak Lee
Browse files

media c2.aidl: PersistentSurface related aidl defs & impls

Bug: 322870482
Test: m libstagefright_graphicbuffersource_aidl
Merged-In: I61aa0bcb82344430ca7e828624f3cfbf7d888af8
Change-Id: I61aa0bcb82344430ca7e828624f3cfbf7d888af8
parent 255708d3
Loading
Loading
Loading
Loading
+97 −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 <inttypes.h>

#define LOG_TAG "AidlGraphicBufferSource"
//#define LOG_NDEBUG 0
#include <utils/Log.h>

#include <media/stagefright/bqhelper/ComponentWrapper.h>
#include <media/stagefright/bqhelper/GraphicBufferSource.h>
#include <media/stagefright/aidlpersistentsurface/AidlGraphicBufferSource.h>
#include <media/stagefright/aidlpersistentsurface/C2NodeDef.h>

namespace android::media {

namespace {

class AidlComponentWrapper : public ComponentWrapper {
public:
    explicit AidlComponentWrapper(const sp<IAidlNodeWrapper> &node)
        : mAidlNode(node) {}
    virtual ~AidlComponentWrapper() = default;

    status_t submitBuffer(
            int32_t bufferId, const sp<GraphicBuffer> &buffer,
            int64_t timestamp, int fenceFd) override {
        return mAidlNode->submitBuffer(
                bufferId, BUFFERFLAG_ENDOFFRAME, buffer, timestamp, fenceFd);
    }

    status_t submitEos(int32_t bufferId) override {
        return mAidlNode->submitBuffer(
            bufferId, BUFFERFLAG_ENDOFFRAME | BUFFERFLAG_EOS);
    }

    void dispatchDataSpaceChanged(
            int32_t dataSpace, int32_t aspects, int32_t pixelFormat) override {
        mAidlNode->dispatchDataSpaceChanged(dataSpace, aspects, pixelFormat);
    }

private:
    sp<IAidlNodeWrapper> mAidlNode;

    DISALLOW_EVIL_CONSTRUCTORS(AidlComponentWrapper);
};

}  // namespace

::ndk::ScopedAStatus AidlGraphicBufferSource::onStart() {
    status_t err = start();
    return (OK == err) ? ::ndk::ScopedAStatus::ok() :
            ::ndk::ScopedAStatus::fromServiceSpecificError(err);
}

::ndk::ScopedAStatus AidlGraphicBufferSource::onStop() {
    status_t err = stop();
    return (OK == err) ? ::ndk::ScopedAStatus::ok() :
            ::ndk::ScopedAStatus::fromServiceSpecificError(err);
}

::ndk::ScopedAStatus AidlGraphicBufferSource::onRelease(){
    status_t err = release();
    return (OK == err) ? ::ndk::ScopedAStatus::ok() :
            ::ndk::ScopedAStatus::fromServiceSpecificError(err);
}

status_t AidlGraphicBufferSource::configure(
        const sp<IAidlNodeWrapper>& aidlNode,
        int32_t dataSpace,
        int32_t bufferCount,
        uint32_t frameWidth,
        uint32_t frameHeight,
        uint64_t consumerUsage) {
    if (aidlNode == NULL) {
        return BAD_VALUE;
    }

    return GraphicBufferSource::configure(
            new AidlComponentWrapper(aidlNode), dataSpace, bufferCount,
            frameWidth, frameHeight, consumerUsage);
}

}  // namespace android::media
+69 −0
Original line number Diff line number Diff line
aidl_interface {
    name: "graphicbuffersource-aidl",
    unstable: true,
    local_include_dir: "aidl",
    min_sdk_version: "29",
    srcs: [
        "aidl/android/media/AidlColorAspects.aidl",
        "aidl/android/media/IAidlGraphicBufferSource.aidl",
        "aidl/android/media/IAidlBufferSource.aidl",
        "aidl/android/media/IAidlNode.aidl",
    ],
    headers: [
        "HardwareBuffer_aidl",
    ],
    imports: [
        "android.hardware.graphics.common-V5",
    ],
    include_dirs: [
        "frameworks/native/aidl/gui",
    ],
    backend: {
        cpp: {
            enabled: false,
        },
        java: {
            enabled: false,
        },
        ndk: {
            enabled: true,
            additional_shared_libraries: [
                "libnativewindow",
            ],
        },
        rust: {
            // No users, and no rust implementation of android.os.Surface yet
            enabled: false,
        },
    },
}

cc_library_shared {
    name: "libstagefright_graphicbuffersource_aidl",
    min_sdk_version: "29",
    srcs: [
        "AidlGraphicBufferSource.cpp",
        "wrapper/WAidlGraphicBufferSource.cpp",
    ],
    export_include_dirs: [
        "include",
    ],
    header_libs: [
        "media_plugin_headers",
    ],

    export_header_lib_headers: [
        "media_plugin_headers",
    ],
    shared_libs: [
        "android.hardware.graphics.common-V5-ndk",
        "graphicbuffersource-aidl-ndk",
        "libbinder_ndk",
        "libcutils",
        "libgui",
        "liblog",
        "libnativewindow",
        "libstagefright_bufferqueue_helper",
        "libutils",
    ],
}
+89 −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.
 */

package android.media;

/**
 * Ref: frameworks/native/include/media/hardware/VideoAPI.h
 *
 * Framework defined color aspects. These are based mainly on ISO 23001-8 spec. As this standard
 * continues to evolve, new values may be defined in the future. Use OTHER for these future values
 * as well as for values not listed here, as those are not supported by the framework.
 */
parcelable AidlColorAspects {
    @Backing(type="int")
    enum Range {
        UNSPECIFIED,  // Unspecified
        FULL,         // Full range
        LIMITED,      // Limited range (if defined), or not full range

        OTHER = 0xff, // Not one of the above values
    }

    // Color primaries
    @Backing(type="int")
    enum Primaries {
        UNSPECIFIED,  // Unspecified
        BT709_5,      // Rec.ITU-R BT.709-5 or equivalent
        BT470_6M,     // Rec.ITU-R BT.470-6 System M or equivalent
        BT601_6_625,  // Rec.ITU-R BT.601-6 625 or equivalent
        BT601_6_525,  // Rec.ITU-R BT.601-6 525 or equivalent
        GENERIC_FILM, // Generic Film
        BT2020,       // Rec.ITU-R BT.2020 or equivalent

        OTHER = 0xff, // Not one of the above values
    }

    // Transfer characteristics
    @Backing(type="int")
    enum Transfer {
        UNSPECIFIED,  // Unspecified
        LINEAR,       // Linear transfer characteristics
        SRGB,         // sRGB or equivalent
        SMPTE170M,    // SMPTE 170M or equivalent (e.g. BT.601/709/2020)
        GAMMA22,      // Assumed display gamma 2.2
        GAMMA28,      // Assumed display gamma 2.8
        ST2084,       // SMPTE ST 2084 for 10/12/14/16 bit systems
        HLG,          // ARIB STD-B67 hybrid-log-gamma

        // values unlikely to be required by Android follow here
        SMPTE240M = 0x40, // SMPTE 240M
        XVYCC,        // IEC 61966-2-4
        BT1361,       // Rec.ITU-R BT.1361 extended gamut
        ST428,        // SMPTE ST 428-1

        OTHER = 0xff, // Not one of the above values
    }

    // YUV <-> RGB conversion
    @Backing(type="int")
    enum MatrixCoeffs {
        UNSPECIFIED,    // Unspecified
        BT709_5,        // Rec.ITU-R BT.709-5 or equivalent
        BT470_6M,       // KR=0.30, KB=0.11 or equivalent
        BT601_6,        // Rec.ITU-R BT.601-6 625 or equivalent
        SMPTE240M,      // SMPTE 240M or equivalent
        BT2020,         // Rec.ITU-R BT.2020 non-constant luminance
        BT2020CONSTANT, // Rec.ITU-R BT.2020 constant luminance

        OTHER = 0xff,   // Not one of the above values
    }

    Range range;
    Primaries primaries;
    Transfer transfer;
    MatrixCoeffs matrixCoeffs;
}
+64 −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.
 */

package android.media;

import android.os.ParcelFileDescriptor;

/**
 * Binder interface for controlling and handling IAidlGraphicBufferSource
 * from the process which owns IAidlNode.
 *
 * In order to support Persistent InputSurface and/or MediaRecorder
 */
interface IAidlBufferSource {
    /**
     * This is called when IAidlGraphicBufferSource can start handing buffers.
     * If we already have buffers of data sitting in the BufferQueue,
     * this will send them to the codec.
     */
    void onStart();

    /**
     * This is called when IAidlGraphicBufferSource indicaters that
     * the codec is meant to return all buffers back to the client for them
     * to be freed. Do NOT submit any more buffers to the component.
     */
    void onStop();

    /**
     * This is called when IAidlGraphicBufferSource indicates that
     * we are shutting down.
     */
    void onRelease();

    /**
     * A "codec buffer", i.e. a buffer that can be used to pass data into
     * the encoder, has been allocated.
     */
    void onInputBufferAdded(int bufferID);

    /**
     * Called from OnEmptyBufferDone. If we have a BQ buffer available,
     * fill it with a new frame of data; otherwise, just mark it as available.
     *
     * fence contains the fence's fd that the callee should wait on before
     * using the buffer (or pass on to the user of the buffer, if the user supports
     * fences). Callee takes ownership of the fence fd even if it fails.
     */
    void onInputBufferEmptied(int bufferID, in @nullable ParcelFileDescriptor fence);
}
+41 −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.
 */

package android.media;

import android.hardware.graphics.common.Dataspace;
import android.media.AidlColorAspects;
import android.media.IAidlNode;

/**
 * Binder interface for configuring/controlling a Codec2 AIDL encoder instance
 * on behalf of a Surface which will produce input buffers.
 *
 * In order to support Persistent InputSurface and/or MediaRecorder.
 */
interface IAidlGraphicBufferSource {
    void configure(IAidlNode node, Dataspace dataSpace);
    void setSuspend(boolean suspend, long suspendTimeUs);
    void setRepeatPreviousFrameDelayUs(long repeatAfterUs);
    void setMaxFps(float maxFps);
    void setTimeLapseConfig(double fps, double captureFps);
    void setStartTimeUs(long startTimeUs);
    void setStopTimeUs(long stopTimeUs);
    long getStopTimeOffsetUs();
    void setColorAspects(in AidlColorAspects aspects);
    void setTimeOffsetUs(long timeOffsetsUs);
    void signalEndOfInputStream();
}
Loading