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

Commit 8ff40189 authored by Pawin Vongmasa's avatar Pawin Vongmasa
Browse files

Fix some bugs in the Treble connection.

Test: Do the following inside adb shell:
setenforce 0
setprop debug.treble_omx 1
pkill mediacodec
pkill mediaserver

Bug: 31399200
Change-Id: I8d0ebcca477738add8b41b58ae85539061cfad7b
parent 92b6b72d
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -90,6 +90,13 @@ status_t OMXBuffer::writeToParcel(Parcel *parcel) const {

        case kBufferTypeANWBuffer:
        {
            if (mGraphicBuffer == NULL) {
                return parcel->writeBool(false);
            }
            status_t err = parcel->writeBool(true);
            if (err != OK) {
                return err;
            }
            return parcel->write(*mGraphicBuffer);
        }

@@ -130,15 +137,21 @@ status_t OMXBuffer::readFromParcel(const Parcel *parcel) {

        case kBufferTypeANWBuffer:
        {
            bool notNull;
            status_t err = parcel->readBool(&notNull);
            if (err != OK) {
                return err;
            }
            if (notNull) {
                sp<GraphicBuffer> buffer = new GraphicBuffer();

                status_t err = parcel->read(*buffer);

                if (err != OK) {
                    return err;
                }

                mGraphicBuffer = buffer;
            } else {
                mGraphicBuffer = nullptr;
            }
            break;
        }

+32 −2
Original line number Diff line number Diff line
@@ -43,6 +43,35 @@ namespace android {

static const OMX_U32 kPortIndexInput = 0;

class GraphicBufferSource::OmxBufferSource : public BnOMXBufferSource {
public:
    GraphicBufferSource* mSource;

    OmxBufferSource(GraphicBufferSource* source): mSource(source) {
    }

    Status onOmxExecuting() override {
        return mSource->onOmxExecuting();
    }

    Status onOmxIdle() override {
        return mSource->onOmxIdle();
    }

    Status onOmxLoaded() override {
        return mSource->onOmxLoaded();
    }

    Status onInputBufferAdded(int bufferId) override {
        return mSource->onInputBufferAdded(bufferId);
    }

    Status onInputBufferEmptied(
            int bufferId, const OMXFenceParcelable& fenceParcel) override {
        return mSource->onInputBufferEmptied(bufferId, fenceParcel);
    }
};

GraphicBufferSource::GraphicBufferSource() :
    mInitCheck(UNKNOWN_ERROR),
    mExecuting(false),
@@ -66,7 +95,8 @@ GraphicBufferSource::GraphicBufferSource() :
    mTimePerFrameUs(-1ll),
    mPrevCaptureUs(-1ll),
    mPrevFrameUs(-1ll),
    mInputBufferTimeOffsetUs(0ll) {
    mInputBufferTimeOffsetUs(0ll),
    mOmxBufferSource(new OmxBufferSource(this)) {
    ALOGV("GraphicBufferSource");

    String8 name("GraphicBufferSource");
@@ -766,7 +796,7 @@ Status GraphicBufferSource::configure(
    // Do setInputSurface() first, the node will try to enable metadata
    // mode on input, and does necessary error checking. If this fails,
    // we can't use this input surface on the node.
    status_t err = omxNode->setInputSurface(this);
    status_t err = omxNode->setInputSurface(mOmxBufferSource);
    if (err != NO_ERROR) {
        ALOGE("Unable to set input surface: %d", err);
        return Status::fromServiceSpecificError(err);
+8 −6
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ struct FrameDropper;
 * things up until we're ready to go.
 */
class GraphicBufferSource : public BnGraphicBufferSource,
                            public BnOMXBufferSource,
                            public BufferQueue::ConsumerListener {
public:
    GraphicBufferSource();
@@ -77,26 +76,26 @@ public:
    // This is called when OMX transitions to OMX_StateExecuting, which means
    // we can start handing it buffers.  If we already have buffers of data
    // sitting in the BufferQueue, this will send them to the codec.
    Status onOmxExecuting() override;
    Status onOmxExecuting();

    // This is called when OMX transitions to OMX_StateIdle, indicating 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.
    Status onOmxIdle() override;
    Status onOmxIdle();

    // This is called when OMX transitions to OMX_StateLoaded, indicating that
    // we are shutting down.
    Status onOmxLoaded() override;
    Status onOmxLoaded();

    // A "codec buffer", i.e. a buffer that can be used to pass data into
    // the encoder, has been allocated.  (This call does not call back into
    // OMXNodeInstance.)
    Status onInputBufferAdded(int32_t bufferID) override;
    Status onInputBufferAdded(int32_t 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.
    Status onInputBufferEmptied(
            int32_t bufferID, const OMXFenceParcelable& fenceParcel) override;
            int32_t bufferID, const OMXFenceParcelable& fenceParcel);

    // Configure the buffer source to be used with an OMX node with the default
    // data space.
@@ -301,6 +300,9 @@ private:

    ColorAspects mColorAspects;

    class OmxBufferSource;
    sp<OmxBufferSource> mOmxBufferSource;

    void onMessageReceived(const sp<AMessage> &msg);

    DISALLOW_EVIL_CONSTRUCTORS(GraphicBufferSource);
+15 −1
Original line number Diff line number Diff line
@@ -294,7 +294,7 @@ inline bool wrapAs(Message* t, native_handle_t** nh, omx_message const& l) {
    if (!*nh) {
        return false;
    }
    t->fence = inHidlHandle(*nh);
    t->fence = *nh;
    switch (l.type) {
        case omx_message::EVENT:
            t->type = Message::Type::EVENT;
@@ -592,6 +592,16 @@ inline bool wrapAs(CodecBuffer* t, OMXBuffer const& l) {
        }
        case OMXBuffer::kBufferTypeANWBuffer: {
            t->type = CodecBuffer::Type::ANW_BUFFER;
            if (l.mGraphicBuffer == nullptr) {
                t->attr.anwBuffer.width = 0;
                t->attr.anwBuffer.height = 0;
                t->attr.anwBuffer.stride = 0;
                t->attr.anwBuffer.format = static_cast<PixelFormat>(1);
                t->attr.anwBuffer.layerCount = 0;
                t->attr.anwBuffer.usage = 0;
                t->nativeHandle = hidl_handle();
                return true;
            }
            t->attr.anwBuffer.width = l.mGraphicBuffer->getWidth();
            t->attr.anwBuffer.height = l.mGraphicBuffer->getHeight();
            t->attr.anwBuffer.stride = l.mGraphicBuffer->getStride();
@@ -636,6 +646,10 @@ inline bool convertTo(OMXBuffer* l, CodecBuffer const& t) {
            return true;
        }
        case CodecBuffer::Type::ANW_BUFFER: {
            if (t.nativeHandle.getNativeHandle() == nullptr) {
                *l = OMXBuffer(sp<GraphicBuffer>(nullptr));
                return true;
            }
            *l = OMXBuffer(sp<GraphicBuffer>(new GraphicBuffer(
                    t.attr.anwBuffer.width,
                    t.attr.anwBuffer.height,
+18 −18
Original line number Diff line number Diff line
@@ -78,10 +78,6 @@ LWGraphicBufferSource::LWGraphicBufferSource(
    return toBinderStatus(mBase->signalEndOfInputStream());
}

::android::IBinder* LWGraphicBufferSource::onAsBinder() {
    return nullptr;
}

// TWGraphicBufferSource
TWGraphicBufferSource::TWGraphicBufferSource(
        sp<LGraphicBufferSource> const& base) : mBase(base) {
@@ -89,47 +85,51 @@ TWGraphicBufferSource::TWGraphicBufferSource(

Return<void> TWGraphicBufferSource::configure(
        const sp<IOmxNode>& omxNode, Dataspace dataspace) {
    return toHardwareStatus(mBase->configure(
            new LWOmxNode(omxNode),
            toRawDataspace(dataspace)));
    mBase->configure(new LWOmxNode(omxNode), toRawDataspace(dataspace));
    return Void();
}

Return<void> TWGraphicBufferSource::setSuspend(bool suspend) {
    return toHardwareStatus(mBase->setSuspend(suspend));
    mBase->setSuspend(suspend);
    return Void();
}

Return<void> TWGraphicBufferSource::setRepeatPreviousFrameDelayUs(
        int64_t repeatAfterUs) {
    return toHardwareStatus(mBase->setRepeatPreviousFrameDelayUs(
            repeatAfterUs));
    mBase->setRepeatPreviousFrameDelayUs(repeatAfterUs);
    return Void();
}

Return<void> TWGraphicBufferSource::setMaxFps(float maxFps) {
    return toHardwareStatus(mBase->setMaxFps(maxFps));
    mBase->setMaxFps(maxFps);
    return Void();
}

Return<void> TWGraphicBufferSource::setTimeLapseConfig(
        int64_t timePerFrameUs, int64_t timePerCaptureUs) {
    return toHardwareStatus(mBase->setTimeLapseConfig(
            timePerFrameUs, timePerCaptureUs));
    mBase->setTimeLapseConfig(timePerFrameUs, timePerCaptureUs);
    return Void();
}

Return<void> TWGraphicBufferSource::setStartTimeUs(int64_t startTimeUs) {
    return toHardwareStatus(mBase->setStartTimeUs(startTimeUs));
    mBase->setStartTimeUs(startTimeUs);
    return Void();
}

Return<void> TWGraphicBufferSource::setColorAspects(
        const ColorAspects& aspects) {
    return toHardwareStatus(mBase->setColorAspects(toCompactColorAspects(
            aspects)));
    mBase->setColorAspects(toCompactColorAspects(aspects));
    return Void();
}

Return<void> TWGraphicBufferSource::setTimeOffsetUs(int64_t timeOffsetUs) {
    return toHardwareStatus(mBase->setTimeOffsetUs(timeOffsetUs));
    mBase->setTimeOffsetUs(timeOffsetUs);
    return Void();
}

Return<void> TWGraphicBufferSource::signalEndOfInputStream() {
    return toHardwareStatus(mBase->signalEndOfInputStream());
    mBase->signalEndOfInputStream();
    return Void();
}

}  // namespace implementation
Loading