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

Commit 55bfd11f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 6e6f5dfd 41d83436
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@
#include <media/stagefright/MediaCodecConstants.h>
#include <media/stagefright/SkipCutBuffer.h>
#include <media/MediaCodecBuffer.h>
#include <mediadrm/ICrypto.h>
#include <system/window.h>

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

#include "CCodecBuffers.h"

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

// OutputBuffers

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

OutputBuffers::~OutputBuffers() = default;

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

// LocalBufferPool

std::shared_ptr<LocalBufferPool> LocalBufferPool::Create(size_t poolCapacity) {
    return std::shared_ptr<LocalBufferPool>(new LocalBufferPool(poolCapacity));
constexpr size_t kInitialPoolCapacity = kMaxLinearBufferSize;
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) {
@@ -192,6 +201,11 @@ sp<ABuffer> LocalBufferPool::newBuffer(size_t capacity) {
            mUsedSize -= mPool.back().capacity();
            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) {
            ALOGD("mUsedSize = %zu, capacity = %zu, mPoolCapacity = %zu",
                    mUsedSize, capacity, mPoolCapacity);
@@ -777,11 +791,10 @@ sp<Codec2Buffer> GraphicMetadataInputBuffers::createNewBuffer() {
// GraphicInputBuffers

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

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

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

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

namespace android {

struct ICrypto;
class MemoryDealer;
class SkipCutBuffer;

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

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

    /**
     * Register output C2Buffer from the component and obtain corresponding
@@ -243,11 +244,9 @@ public:
    /**
     * Create a new LocalBufferPool object.
     *
     * \param poolCapacity  max total size of buffers managed by this pool.
     *
     * \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|.
@@ -679,8 +678,7 @@ private:

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

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

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

    sp<Codec2Buffer> wrap(const std::shared_ptr<C2Buffer> &buffer) override;
+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
#define LOG_TAG "Codec2Buffer"
#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 <media/hardware/HardwareAPI.h>
#include <media/stagefright/CodecBase.h>
@@ -25,6 +27,7 @@
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/AUtils.h>
#include <mediadrm/ICrypto.h>
#include <nativebase/nativebase.h>
#include <ui/Fence.h>

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

#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 <media/hardware/VideoAPI.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/MediaCodecBuffer.h>
#include <mediadrm/ICrypto.h>

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.
 *
Loading