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

Commit c8ce1d8b authored by Chong Zhang's avatar Chong Zhang
Browse files

Remove ligbui dep from libcodec2_vndk and libcodec2_hidl@1.0

bug: 128894663
test: builds;  atest CtsMediaTestCases -- --module-arg CtsMediaTestCases:size:small
Change-Id: I3bb8792bd6eec46a9131bc6bd0c773648f430538
parent 019b2fc5
Loading
Loading
Loading
Loading
+56 −3
Original line number Diff line number Diff line
// DO NOT DEPEND ON THIS DIRECTLY
// use libcodec2-hidl-client-defaults instead
cc_library {
    name: "libcodec2_hidl_client@1.0",

    defaults: ["hidl_defaults"],

    srcs: [
        "ClientBlockHelper.cpp",
        "types.cpp",
    ],

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

    shared_libs: [
        "android.hardware.media.bufferpool@2.0",
        "android.hardware.media.c2@1.0",
        "libbase",
        "libcodec2",
        "libcodec2_vndk",
        "libcutils",
        "libgui",
        "libhidlbase",
        "liblog",
        "libstagefright_bufferpool@2.0",
        "libui",
        "libutils",
    ],

    export_include_dirs: [
        "include",
    ],

    export_shared_lib_headers: [
        "android.hardware.media.c2@1.0",
        "libcodec2",
        "libgui",
        "libstagefright_bufferpool@2.0",
        "libui",
    ],
}


// DO NOT DEPEND ON THIS DIRECTLY
// use libcodec2-hidl-defaults instead
cc_library {
@@ -33,12 +78,10 @@ cc_library {
        "android.hardware.media.bufferpool@2.0",
        "android.hardware.media.c2@1.0",
        "android.hardware.media.omx@1.0",
        "android.hidl.safe_union@1.0",
        "libbase",
        "libcodec2",
        "libcodec2_vndk",
        "libcutils",
        "libgui",
        "libhidlbase",
        "libhidltransport",
        "libhwbinder",
@@ -58,7 +101,6 @@ cc_library {
        "libcodec2",
        "libhidlbase",
        "libstagefright_bufferpool@2.0",
        "libstagefright_bufferqueue_helper",
        "libui",
    ],
}
@@ -73,3 +115,14 @@ cc_defaults {
        "libcodec2_hidl@1.0",
    ],
}

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

    shared_libs: [
        "android.hardware.media.c2@1.0",
        "libcodec2_hidl_client@1.0",
    ],
}
+232 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 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 "Codec2-block_helper"
#include <android-base/logging.h>

#include <android/hardware/graphics/bufferqueue/2.0/IGraphicBufferProducer.h>
#include <codec2/hidl/1.0/ClientBlockHelper.h>
#include <gui/bufferqueue/2.0/B2HGraphicBufferProducer.h>

#include <C2AllocatorGralloc.h>
#include <C2BlockInternal.h>
#include <C2Buffer.h>
#include <C2PlatformSupport.h>

#include <iomanip>

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

using HGraphicBufferProducer = ::android::hardware::graphics::bufferqueue::
        V2_0::IGraphicBufferProducer;
using B2HGraphicBufferProducer = ::android::hardware::graphics::bufferqueue::
        V2_0::utils::B2HGraphicBufferProducer;

namespace /* unnamed */ {

// Create a GraphicBuffer object from a graphic block.
sp<GraphicBuffer> createGraphicBuffer(const C2ConstGraphicBlock& block) {
    uint32_t width;
    uint32_t height;
    uint32_t format;
    uint64_t usage;
    uint32_t stride;
    uint32_t generation;
    uint64_t bqId;
    int32_t bqSlot;
    _UnwrapNativeCodec2GrallocMetadata(
            block.handle(), &width, &height, &format, &usage,
            &stride, &generation, &bqId, reinterpret_cast<uint32_t*>(&bqSlot));
    native_handle_t *grallocHandle =
            UnwrapNativeCodec2GrallocHandle(block.handle());
    sp<GraphicBuffer> graphicBuffer =
            new GraphicBuffer(grallocHandle,
                              GraphicBuffer::CLONE_HANDLE,
                              width, height, format,
                              1, usage, stride);
    native_handle_delete(grallocHandle);
    return graphicBuffer;
}

template <typename BlockProcessor>
void forEachBlock(C2FrameData& frameData,
                  BlockProcessor process) {
    for (const std::shared_ptr<C2Buffer>& buffer : frameData.buffers) {
        if (buffer) {
            for (const C2ConstGraphicBlock& block :
                    buffer->data().graphicBlocks()) {
                process(block);
            }
        }
    }
}

template <typename BlockProcessor>
void forEachBlock(const std::list<std::unique_ptr<C2Work>>& workList,
                  BlockProcessor process,
                  bool processInput, bool processOutput) {
    for (const std::unique_ptr<C2Work>& work : workList) {
        if (!work) {
            continue;
        }
        if (processInput) {
            forEachBlock(work->input, process);
        }
        if (processOutput) {
            for (const std::unique_ptr<C2Worklet>& worklet : work->worklets) {
                if (worklet) {
                    forEachBlock(worklet->output,
                                 process);
                }
            }
        }
    }
}

sp<HGraphicBufferProducer> getHgbp(const sp<IGraphicBufferProducer>& igbp) {
    sp<HGraphicBufferProducer> hgbp =
            igbp->getHalInterface<HGraphicBufferProducer>();
    return hgbp ? hgbp :
            new B2HGraphicBufferProducer(igbp);
}

} // unnamed namespace

status_t attachToBufferQueue(const C2ConstGraphicBlock& block,
                             const sp<IGraphicBufferProducer>& igbp,
                             uint32_t generation,
                             int32_t* bqSlot) {
    if (!igbp) {
        LOG(WARNING) << "attachToBufferQueue -- null producer.";
        return NO_INIT;
    }

    sp<GraphicBuffer> graphicBuffer = createGraphicBuffer(block);
    graphicBuffer->setGenerationNumber(generation);

    LOG(VERBOSE) << "attachToBufferQueue -- attaching buffer:"
            << " block dimension " << block.width() << "x"
                                   << block.height()
            << ", graphicBuffer dimension " << graphicBuffer->getWidth() << "x"
                                           << graphicBuffer->getHeight()
            << std::hex << std::setfill('0')
            << ", format 0x" << std::setw(8) << graphicBuffer->getPixelFormat()
            << ", usage 0x" << std::setw(16) << graphicBuffer->getUsage()
            << std::dec << std::setfill(' ')
            << ", stride " << graphicBuffer->getStride()
            << ", generation " << graphicBuffer->getGenerationNumber();

    status_t result = igbp->attachBuffer(bqSlot, graphicBuffer);
    if (result != OK) {
        LOG(WARNING) << "attachToBufferQueue -- attachBuffer failed: "
                        "status = " << result << ".";
        return result;
    }
    LOG(VERBOSE) << "attachToBufferQueue -- attachBuffer returned slot #"
                 << *bqSlot << ".";
    return OK;
}

bool getBufferQueueAssignment(const C2ConstGraphicBlock& block,
                              uint32_t* generation,
                              uint64_t* bqId,
                              int32_t* bqSlot) {
    return _C2BlockFactory::GetBufferQueueData(
            _C2BlockFactory::GetGraphicBlockPoolData(block),
            generation, bqId, bqSlot);
}

bool holdBufferQueueBlock(const C2ConstGraphicBlock& block,
                            const sp<IGraphicBufferProducer>& igbp,
                            uint64_t bqId,
                            uint32_t generation) {
    std::shared_ptr<_C2BlockPoolData> data =
            _C2BlockFactory::GetGraphicBlockPoolData(block);
    if (!data) {
        return false;
    }

    uint32_t oldGeneration;
    uint64_t oldId;
    int32_t oldSlot;
    // If the block is not bufferqueue-based, do nothing.
    if (!_C2BlockFactory::GetBufferQueueData(
            data, &oldGeneration, &oldId, &oldSlot) ||
            (oldId == 0)) {
        return false;
    }

    // If the block's bqId is the same as the desired bqId, just hold.
    if ((oldId == bqId) && (oldGeneration == generation)) {
        LOG(VERBOSE) << "holdBufferQueueBlock -- import without attaching:"
                     << " bqId " << oldId
                     << ", bqSlot " << oldSlot
                     << ", generation " << generation
                     << ".";
        _C2BlockFactory::HoldBlockFromBufferQueue(data, getHgbp(igbp));
        return true;
    }

    // Otherwise, attach to the given igbp, which must not be null.
    if (!igbp) {
        return false;
    }

    int32_t bqSlot;
    status_t result = attachToBufferQueue(block, igbp, generation, &bqSlot);

    if (result != OK) {
        LOG(ERROR) << "holdBufferQueueBlock -- fail to attach:"
                   << " target bqId " << bqId
                   << ", generation " << generation
                   << ".";
        return false;
    }

    LOG(VERBOSE) << "holdBufferQueueBlock -- attached:"
                 << " bqId " << bqId
                 << ", bqSlot " << bqSlot
                 << ", generation " << generation
                 << ".";
    _C2BlockFactory::AssignBlockToBufferQueue(
            data, getHgbp(igbp), generation, bqId, bqSlot, true);
    return true;
}

void holdBufferQueueBlocks(const std::list<std::unique_ptr<C2Work>>& workList,
                           const sp<IGraphicBufferProducer>& igbp,
                           uint64_t bqId,
                           uint32_t generation,
                           bool forInput) {
    forEachBlock(workList,
                 std::bind(holdBufferQueueBlock,
                           std::placeholders::_1, igbp, bqId, generation),
                 forInput, !forInput);
}

}  // namespace utils
}  // namespace V1_0
}  // namespace c2
}  // namespace media
}  // namespace hardware
}  // namespace android
+1 −2
Original line number Diff line number Diff line
@@ -222,8 +222,7 @@ Return<void> ComponentStore::createInputSurface(createInputSurface_cb _hidl_cb)
    sp<InputSurface> inputSurface = new InputSurface(
            this,
            std::make_shared<C2ReflectorHelper>(),
            new ::android::hardware::graphics::bufferqueue::V2_0::utils::
                B2HGraphicBufferProducer(source->getIGraphicBufferProducer()),
            source->getHGraphicBufferProducer(),
            source);
    _hidl_cb(inputSurface ? Status::OK : Status::NO_MEMORY,
             inputSurface);
+95 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 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 CLIENT_BLOCK_HELPER_H
#define CLIENT_BLOCK_HELPER_H

#include <gui/IGraphicBufferProducer.h>
#include <codec2/hidl/1.0/types.h>
#include <C2Work.h>

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


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

// Create a GraphicBuffer object from a graphic block and attach it to an
// IGraphicBufferProducer.
status_t attachToBufferQueue(const C2ConstGraphicBlock& block,
                             const sp<IGraphicBufferProducer>& igbp,
                             uint32_t generation,
                             int32_t* bqSlot);

// Return false if block does not come from a bufferqueue-based blockpool.
// Otherwise, extract generation, bqId and bqSlot and return true.
bool getBufferQueueAssignment(const C2ConstGraphicBlock& block,
                              uint32_t* generation,
                              uint64_t* bqId,
                              int32_t* bqSlot);

// Assign the given block to a bufferqueue so that when the block is destroyed,
// cancelBuffer() will be called.
//
// If the block does not come from a bufferqueue-based blockpool, this function
// returns false.
//
// If the block already has a bufferqueue assignment that matches the given one,
// the function returns true.
//
// If the block already has a bufferqueue assignment that does not match the
// given one, the block will be reassigned to the given bufferqueue. This
// will call attachBuffer() on the given igbp. The function then returns true on
// success or false on any failure during the operation.
//
// Note: This function should be called after detachBuffer() or dequeueBuffer()
// is called manually.
bool holdBufferQueueBlock(const C2ConstGraphicBlock& block,
                          const sp<IGraphicBufferProducer>& igbp,
                          uint64_t bqId,
                          uint32_t generation);

// Call holdBufferQueueBlock() on input or output blocks in the given workList.
// Since the bufferqueue assignment for input and output buffers can be
// different, this function takes forInput to determine whether the given
// bufferqueue is for input buffers or output buffers. (The default value of
// forInput is false.)
//
// In the (rare) case that both input and output buffers are bufferqueue-based,
// this function must be called twice, once for the input buffers and once for
// the output buffers.
//
// Note: This function should be called after WorkBundle has been received from
// another process.
void holdBufferQueueBlocks(const std::list<std::unique_ptr<C2Work>>& workList,
                           const sp<IGraphicBufferProducer>& igbp,
                           uint64_t bqId,
                           uint32_t generation,
                           bool forInput = false);

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

#endif  // CLIENT_BLOCK_HELPER_H
+0 −55
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@
#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 <gui/IGraphicBufferProducer.h>

#include <C2Component.h>
#include <C2Param.h>
@@ -50,7 +49,6 @@ using ::android::status_t;
using ::android::sp;
using ::android::hardware::media::bufferpool::V2_0::implementation::
        ConnectionId;
using ::android::IGraphicBufferProducer;

// Types of metadata for Blocks.
struct C2Hidl_Range {
@@ -301,20 +299,6 @@ c2_status_t toC2Status(::android::hardware::media::bufferpool::V2_0::
// BufferQueue-Based Block Operations
// ==================================

// Create a GraphicBuffer object from a graphic block and attach it to an
// IGraphicBufferProducer.
status_t attachToBufferQueue(const C2ConstGraphicBlock& block,
                             const sp<IGraphicBufferProducer>& igbp,
                             uint32_t generation,
                             int32_t* bqSlot);

// Return false if block does not come from a bufferqueue-based blockpool.
// Otherwise, extract generation, bqId and bqSlot and return true.
bool getBufferQueueAssignment(const C2ConstGraphicBlock& block,
                              uint32_t* generation,
                              uint64_t* bqId,
                              int32_t* bqSlot);

// Disassociate the given block with its designated bufferqueue so that
// cancelBuffer() will not be called when the block is destroyed. If the block
// does not have a designated bufferqueue, the function returns false.
@@ -336,45 +320,6 @@ void yieldBufferQueueBlocks(const std::list<std::unique_ptr<C2Work>>& workList,
                            bool processInput = false,
                            bool processOutput = true);

// Assign the given block to a bufferqueue so that when the block is destroyed,
// cancelBuffer() will be called.
//
// If the block does not come from a bufferqueue-based blockpool, this function
// returns false.
//
// If the block already has a bufferqueue assignment that matches the given one,
// the function returns true.
//
// If the block already has a bufferqueue assignment that does not match the
// given one, the block will be reassigned to the given bufferqueue. This
// will call attachBuffer() on the given igbp. The function then returns true on
// success or false on any failure during the operation.
//
// Note: This function should be called after detachBuffer() or dequeueBuffer()
// is called manually.
bool holdBufferQueueBlock(const C2ConstGraphicBlock& block,
                          const sp<IGraphicBufferProducer>& igbp,
                          uint64_t bqId,
                          uint32_t generation);

// Call holdBufferQueueBlock() on input or output blocks in the given workList.
// Since the bufferqueue assignment for input and output buffers can be
// different, this function takes forInput to determine whether the given
// bufferqueue is for input buffers or output buffers. (The default value of
// forInput is false.)
//
// In the (rare) case that both input and output buffers are bufferqueue-based,
// this function must be called twice, once for the input buffers and once for
// the output buffers.
//
// Note: This function should be called after WorkBundle has been received from
// another process.
void holdBufferQueueBlocks(const std::list<std::unique_ptr<C2Work>>& workList,
                           const sp<IGraphicBufferProducer>& igbp,
                           uint64_t bqId,
                           uint32_t generation,
                           bool forInput = false);

}  // namespace utils
}  // namespace V1_0
}  // namespace c2
Loading