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

Commit abf5f70f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "CCodec: remove dependency to # of slots for allocating local buffers"...

Merge "CCodec: remove dependency to # of slots for allocating local buffers" into rvc-dev am: 55bfd11f

Change-Id: I010502c5d7a1f464a89453ee8e78fcb5a84f6b4c
parents d661908c 55bfd11f
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -44,6 +44,7 @@
#include <media/stagefright/MediaCodecConstants.h>
#include <media/stagefright/MediaCodecConstants.h>
#include <media/stagefright/SkipCutBuffer.h>
#include <media/stagefright/SkipCutBuffer.h>
#include <media/MediaCodecBuffer.h>
#include <media/MediaCodecBuffer.h>
#include <mediadrm/ICrypto.h>
#include <system/window.h>
#include <system/window.h>


#include "CCodecBufferChannel.h"
#include "CCodecBufferChannel.h"
@@ -1084,7 +1085,7 @@ status_t CCodecBufferChannel::start(
                // TODO: handle this without going into array mode
                // TODO: handle this without going into array mode
                forceArrayMode = true;
                forceArrayMode = true;
            } else {
            } else {
                input->buffers.reset(new GraphicInputBuffers(numInputSlots, mName));
                input->buffers.reset(new GraphicInputBuffers(mName));
            }
            }
        } else {
        } else {
            if (hasCryptoOrDescrambler()) {
            if (hasCryptoOrDescrambler()) {
@@ -1252,7 +1253,7 @@ status_t CCodecBufferChannel::start(
            if (outputSurface || !buffersBoundToCodec) {
            if (outputSurface || !buffersBoundToCodec) {
                output->buffers.reset(new GraphicOutputBuffers(mName));
                output->buffers.reset(new GraphicOutputBuffers(mName));
            } else {
            } else {
                output->buffers.reset(new RawGraphicOutputBuffers(numOutputSlots, mName));
                output->buffers.reset(new RawGraphicOutputBuffers(mName));
            }
            }
        } else {
        } else {
            output->buffers.reset(new LinearOutputBuffers(mName));
            output->buffers.reset(new LinearOutputBuffers(mName));
+21 −9
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/MediaCodecConstants.h>
#include <media/stagefright/MediaCodecConstants.h>
#include <media/stagefright/SkipCutBuffer.h>
#include <media/stagefright/SkipCutBuffer.h>
#include <mediadrm/ICrypto.h>


#include "CCodecBuffers.h"
#include "CCodecBuffers.h"


@@ -121,6 +122,11 @@ sp<Codec2Buffer> InputBuffers::cloneAndReleaseBuffer(const sp<MediaCodecBuffer>


// OutputBuffers
// OutputBuffers


OutputBuffers::OutputBuffers(const char *componentName, const char *name)
    : CCodecBuffers(componentName, name) { }

OutputBuffers::~OutputBuffers() = default;

void OutputBuffers::initSkipCutBuffer(
void OutputBuffers::initSkipCutBuffer(
        int32_t delay, int32_t padding, int32_t sampleRate, int32_t channelCount) {
        int32_t delay, int32_t padding, int32_t sampleRate, int32_t channelCount) {
    CHECK(mSkipCutBuffer == nullptr);
    CHECK(mSkipCutBuffer == nullptr);
@@ -171,8 +177,11 @@ void OutputBuffers::setSkipCutBuffer(int32_t skip, int32_t cut) {


// LocalBufferPool
// LocalBufferPool


std::shared_ptr<LocalBufferPool> LocalBufferPool::Create(size_t poolCapacity) {
constexpr size_t kInitialPoolCapacity = kMaxLinearBufferSize;
    return std::shared_ptr<LocalBufferPool>(new LocalBufferPool(poolCapacity));
constexpr size_t kMaxPoolCapacity = kMaxLinearBufferSize * 32;

std::shared_ptr<LocalBufferPool> LocalBufferPool::Create() {
    return std::shared_ptr<LocalBufferPool>(new LocalBufferPool(kInitialPoolCapacity));
}
}


sp<ABuffer> LocalBufferPool::newBuffer(size_t capacity) {
sp<ABuffer> LocalBufferPool::newBuffer(size_t capacity) {
@@ -192,6 +201,11 @@ sp<ABuffer> LocalBufferPool::newBuffer(size_t capacity) {
            mUsedSize -= mPool.back().capacity();
            mUsedSize -= mPool.back().capacity();
            mPool.pop_back();
            mPool.pop_back();
        }
        }
        while (mUsedSize + capacity > mPoolCapacity && mPoolCapacity * 2 <= kMaxPoolCapacity) {
            ALOGD("Increasing local buffer pool capacity from %zu to %zu",
                  mPoolCapacity, mPoolCapacity * 2);
            mPoolCapacity *= 2;
        }
        if (mUsedSize + capacity > mPoolCapacity) {
        if (mUsedSize + capacity > mPoolCapacity) {
            ALOGD("mUsedSize = %zu, capacity = %zu, mPoolCapacity = %zu",
            ALOGD("mUsedSize = %zu, capacity = %zu, mPoolCapacity = %zu",
                    mUsedSize, capacity, mPoolCapacity);
                    mUsedSize, capacity, mPoolCapacity);
@@ -777,11 +791,10 @@ sp<Codec2Buffer> GraphicMetadataInputBuffers::createNewBuffer() {
// GraphicInputBuffers
// GraphicInputBuffers


GraphicInputBuffers::GraphicInputBuffers(
GraphicInputBuffers::GraphicInputBuffers(
        size_t numInputSlots, const char *componentName, const char *name)
        const char *componentName, const char *name)
    : InputBuffers(componentName, name),
    : InputBuffers(componentName, name),
      mImpl(mName),
      mImpl(mName),
      mLocalBufferPool(LocalBufferPool::Create(
      mLocalBufferPool(LocalBufferPool::Create()) { }
              kMaxLinearBufferSize * numInputSlots)) { }


bool GraphicInputBuffers::requestNewBuffer(size_t *index, sp<MediaCodecBuffer> *buffer) {
bool GraphicInputBuffers::requestNewBuffer(size_t *index, sp<MediaCodecBuffer> *buffer) {
    sp<Codec2Buffer> newBuffer = createNewBuffer();
    sp<Codec2Buffer> newBuffer = createNewBuffer();
@@ -942,7 +955,7 @@ void OutputBuffersArray::realloc(const std::shared_ptr<C2Buffer> &c2buffer) {
        case C2BufferData::GRAPHIC: {
        case C2BufferData::GRAPHIC: {
            // This is only called for RawGraphicOutputBuffers.
            // This is only called for RawGraphicOutputBuffers.
            mAlloc = [format = mFormat,
            mAlloc = [format = mFormat,
                      lbp = LocalBufferPool::Create(kMaxLinearBufferSize * mImpl.arraySize())] {
                      lbp = LocalBufferPool::Create()] {
                return ConstGraphicBlockBuffer::AllocateEmpty(
                return ConstGraphicBlockBuffer::AllocateEmpty(
                        format,
                        format,
                        [lbp](size_t capacity) {
                        [lbp](size_t capacity) {
@@ -1079,10 +1092,9 @@ std::function<sp<Codec2Buffer>()> GraphicOutputBuffers::getAlloc() {
// RawGraphicOutputBuffers
// RawGraphicOutputBuffers


RawGraphicOutputBuffers::RawGraphicOutputBuffers(
RawGraphicOutputBuffers::RawGraphicOutputBuffers(
        size_t numOutputSlots, const char *componentName, const char *name)
        const char *componentName, const char *name)
    : FlexOutputBuffers(componentName, name),
    : FlexOutputBuffers(componentName, name),
      mLocalBufferPool(LocalBufferPool::Create(
      mLocalBufferPool(LocalBufferPool::Create()) { }
              kMaxLinearBufferSize * numOutputSlots)) { }


sp<Codec2Buffer> RawGraphicOutputBuffers::wrap(const std::shared_ptr<C2Buffer> &buffer) {
sp<Codec2Buffer> RawGraphicOutputBuffers::wrap(const std::shared_ptr<C2Buffer> &buffer) {
    if (buffer == nullptr) {
    if (buffer == nullptr) {
+7 −10
Original line number Original line Diff line number Diff line
@@ -28,6 +28,8 @@


namespace android {
namespace android {


struct ICrypto;
class MemoryDealer;
class SkipCutBuffer;
class SkipCutBuffer;


constexpr size_t kLinearBufferSize = 1048576;
constexpr size_t kLinearBufferSize = 1048576;
@@ -156,9 +158,8 @@ private:


class OutputBuffers : public CCodecBuffers {
class OutputBuffers : public CCodecBuffers {
public:
public:
    OutputBuffers(const char *componentName, const char *name = "Output")
    OutputBuffers(const char *componentName, const char *name = "Output");
        : CCodecBuffers(componentName, name) { }
    virtual ~OutputBuffers();
    virtual ~OutputBuffers() = default;


    /**
    /**
     * Register output C2Buffer from the component and obtain corresponding
     * Register output C2Buffer from the component and obtain corresponding
@@ -243,11 +244,9 @@ public:
    /**
    /**
     * Create a new LocalBufferPool object.
     * Create a new LocalBufferPool object.
     *
     *
     * \param poolCapacity  max total size of buffers managed by this pool.
     *
     * \return  a newly created pool object.
     * \return  a newly created pool object.
     */
     */
    static std::shared_ptr<LocalBufferPool> Create(size_t poolCapacity);
    static std::shared_ptr<LocalBufferPool> Create();


    /**
    /**
     * Return an ABuffer object whose size is at least |capacity|.
     * Return an ABuffer object whose size is at least |capacity|.
@@ -679,8 +678,7 @@ private:


class GraphicInputBuffers : public InputBuffers {
class GraphicInputBuffers : public InputBuffers {
public:
public:
    GraphicInputBuffers(
    GraphicInputBuffers(const char *componentName, const char *name = "2D-BB-Input");
            size_t numInputSlots, const char *componentName, const char *name = "2D-BB-Input");
    ~GraphicInputBuffers() override = default;
    ~GraphicInputBuffers() override = default;


    bool requestNewBuffer(size_t *index, sp<MediaCodecBuffer> *buffer) override;
    bool requestNewBuffer(size_t *index, sp<MediaCodecBuffer> *buffer) override;
@@ -892,8 +890,7 @@ public:


class RawGraphicOutputBuffers : public FlexOutputBuffers {
class RawGraphicOutputBuffers : public FlexOutputBuffers {
public:
public:
    RawGraphicOutputBuffers(
    RawGraphicOutputBuffers(const char *componentName, const char *name = "2D-BB-Output");
            size_t numOutputSlots, const char *componentName, const char *name = "2D-BB-Output");
    ~RawGraphicOutputBuffers() override = default;
    ~RawGraphicOutputBuffers() override = default;


    sp<Codec2Buffer> wrap(const std::shared_ptr<C2Buffer> &buffer) override;
    sp<Codec2Buffer> wrap(const std::shared_ptr<C2Buffer> &buffer) override;
+3 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,8 @@
#define LOG_TAG "Codec2Buffer"
#define LOG_TAG "Codec2Buffer"
#include <utils/Log.h>
#include <utils/Log.h>


#include <android/hardware/cas/native/1.0/types.h>
#include <android/hardware/drm/1.0/types.h>
#include <hidlmemory/FrameworkUtils.h>
#include <hidlmemory/FrameworkUtils.h>
#include <media/hardware/HardwareAPI.h>
#include <media/hardware/HardwareAPI.h>
#include <media/stagefright/CodecBase.h>
#include <media/stagefright/CodecBase.h>
@@ -25,6 +27,7 @@
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/AUtils.h>
#include <media/stagefright/foundation/AUtils.h>
#include <mediadrm/ICrypto.h>
#include <nativebase/nativebase.h>
#include <nativebase/nativebase.h>
#include <ui/Fence.h>
#include <ui/Fence.h>


+16 −3
Original line number Original line Diff line number Diff line
@@ -20,16 +20,29 @@


#include <C2Buffer.h>
#include <C2Buffer.h>


#include <android/hardware/cas/native/1.0/types.h>
#include <android/hardware/drm/1.0/types.h>
#include <binder/IMemory.h>
#include <binder/IMemory.h>
#include <media/hardware/VideoAPI.h>
#include <media/hardware/VideoAPI.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/MediaCodecBuffer.h>
#include <media/MediaCodecBuffer.h>
#include <mediadrm/ICrypto.h>


namespace android {
namespace android {


namespace hardware {
class HidlMemory;
namespace cas {
namespace native {
namespace V1_0 {
struct SharedBuffer;
}  // namespace V1_0
}  // namespace native
}  // namespace cas
namespace drm {
namespace V1_0 {
struct SharedBuffer;
}  // namespace V1_0
}  // namespace drm
}  // namespace hardware

/**
/**
 * Copies a graphic view into a media image.
 * Copies a graphic view into a media image.
 *
 *
Loading