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

Commit d5f7ccfa authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 13219462 from 83b7c2eb to 25Q2-release

Change-Id: Ia33494d57e6a1d82581202a2682d2dc396e02864
parents e42095c8 83b7c2eb
Loading
Loading
Loading
Loading
+26 −8
Original line number Original line Diff line number Diff line
@@ -69,8 +69,8 @@ std::optional<Range<int32_t>> VideoCapabilities::getSupportedWidthsFor(int32_t h
        ALOGE("unsupported height");
        ALOGE("unsupported height");
        return std::nullopt;
        return std::nullopt;
    }
    }
    const int32_t heightInBlocks = divUp(height, mBlockHeight);


    const int32_t heightInBlocks = divUp(height, mBlockHeight);
    // constrain by block count and by block aspect ratio
    // constrain by block count and by block aspect ratio
    const int32_t minWidthInBlocks = std::max(
    const int32_t minWidthInBlocks = std::max(
            divUp(mBlockCountRange.lower(), heightInBlocks),
            divUp(mBlockCountRange.lower(), heightInBlocks),
@@ -94,6 +94,10 @@ std::optional<Range<int32_t>> VideoCapabilities::getSupportedWidthsFor(int32_t h
            (int32_t)std::ceil(mAspectRatioRange.lower().asDouble()
            (int32_t)std::ceil(mAspectRatioRange.lower().asDouble()
                    * height),
                    * height),
            (int32_t)(mAspectRatioRange.upper().asDouble() * height));
            (int32_t)(mAspectRatioRange.upper().asDouble() * height));
    if (range.empty()) {
        return std::nullopt;
    }

    return range;
    return range;
}
}


@@ -104,8 +108,8 @@ std::optional<Range<int32_t>> VideoCapabilities::getSupportedHeightsFor(int32_t
        ALOGE("unsupported width");
        ALOGE("unsupported width");
        return std::nullopt;
        return std::nullopt;
    }
    }
    const int32_t widthInBlocks = divUp(width, mBlockWidth);


    const int32_t widthInBlocks = divUp(width, mBlockWidth);
    // constrain by block count and by block aspect ratio
    // constrain by block count and by block aspect ratio
    const int32_t minHeightInBlocks = std::max(
    const int32_t minHeightInBlocks = std::max(
            divUp(mBlockCountRange.lower(), widthInBlocks),
            divUp(mBlockCountRange.lower(), widthInBlocks),
@@ -129,6 +133,10 @@ std::optional<Range<int32_t>> VideoCapabilities::getSupportedHeightsFor(int32_t
            (int32_t)std::ceil(width /
            (int32_t)std::ceil(width /
                    mAspectRatioRange.upper().asDouble()),
                    mAspectRatioRange.upper().asDouble()),
            (int32_t)(width / mAspectRatioRange.lower().asDouble()));
            (int32_t)(width / mAspectRatioRange.lower().asDouble()));
    if (range.empty()) {
        return std::nullopt;
    }

    return range;
    return range;
}
}


@@ -142,12 +150,15 @@ std::optional<Range<double>> VideoCapabilities::getSupportedFrameRatesFor(


    const int32_t blockCount =
    const int32_t blockCount =
            divUp(width, mBlockWidth) * divUp(height, mBlockHeight);
            divUp(width, mBlockWidth) * divUp(height, mBlockHeight);

    Range<double> result = Range(
    return std::make_optional(Range(
            std::max(mBlocksPerSecondRange.lower() / (double) blockCount,
            std::max(mBlocksPerSecondRange.lower() / (double) blockCount,
                (double) mFrameRateRange.lower()),
                (double) mFrameRateRange.lower()),
            std::min(mBlocksPerSecondRange.upper() / (double) blockCount,
            std::min(mBlocksPerSecondRange.upper() / (double) blockCount,
                (double) mFrameRateRange.upper())));
                (double) mFrameRateRange.upper()));
    if (result.empty()) {
        return std::nullopt;
    }
    return result;
}
}


int32_t VideoCapabilities::getBlockCount(int32_t width, int32_t height) const {
int32_t VideoCapabilities::getBlockCount(int32_t width, int32_t height) const {
@@ -613,9 +624,16 @@ std::optional<std::pair<Range<int32_t>, Range<int32_t>>> VideoCapabilities
        return std::nullopt;
        return std::nullopt;
    }
    }


    return std::make_optional(std::pair(
    Range<int32_t> widthRange
            Range(range.value().first.getWidth(), range.value().second.getWidth()),
            = Range(range.value().first.getWidth(), range.value().second.getWidth());
            Range(range.value().first.getHeight(), range.value().second.getHeight())));
    Range<int32_t> heightRange
            = Range(range.value().first.getHeight(), range.value().second.getHeight());
    if (widthRange.empty() || heightRange.empty()) {
        ALOGW("could not parse size range: %s", str.c_str());
        return std::nullopt;
    }

    return std::make_optional(std::pair(widthRange, heightRange));
}
}


// static
// static
+3 −5
Original line number Original line Diff line number Diff line
@@ -109,7 +109,7 @@ struct Range {
            Range<T> result = Range<T>(std::max(lower_, range.lower_),
            Range<T> result = Range<T>(std::max(lower_, range.lower_),
                    std::min(upper_, range.upper_));
                    std::min(upper_, range.upper_));
            if (result.empty()) {
            if (result.empty()) {
                ALOGE("Failed to intersect 2 ranges as they are disjoint");
                ALOGV("Failed to intersect 2 ranges as they are disjoint");
            }
            }
            return result;
            return result;
        }
        }
@@ -124,12 +124,10 @@ struct Range {
     * @param lower a non-{@code null} {@code T} reference
     * @param lower a non-{@code null} {@code T} reference
     * @param upper a non-{@code null} {@code T} reference
     * @param upper a non-{@code null} {@code T} reference
     * @return the intersection of this range and the other range
     * @return the intersection of this range and the other range
     *
     * @throws NullPointerException if {@code lower} or {@code upper} was {@code null}
     * @throws IllegalArgumentException if the ranges are disjoint.
     */
     */
    Range<T> intersect(T lower, T upper) {
    Range<T> intersect(T lower, T upper) {
        return Range(std::max(lower_, lower), std::min(upper_, upper));
        Range<T> range = Range<T>(lower, upper);
        return this->intersect(range);
    }
    }


    /**
    /**
+40 −0
Original line number Original line Diff line number Diff line
@@ -48,7 +48,10 @@
#include <binder/IMemory.h>
#include <binder/IMemory.h>
#include <binder/IServiceManager.h>
#include <binder/IServiceManager.h>
#include <binder/MemoryDealer.h>
#include <binder/MemoryDealer.h>
#include <com_android_graphics_libgui_flags.h>
#include <cutils/properties.h>
#include <cutils/properties.h>
#include <gui/BufferItem.h>
#include <gui/BufferItemConsumer.h>
#include <gui/BufferQueue.h>
#include <gui/BufferQueue.h>
#include <gui/Surface.h>
#include <gui/Surface.h>
#include <hidlmemory/FrameworkUtils.h>
#include <hidlmemory/FrameworkUtils.h>
@@ -770,6 +773,42 @@ MediaCodec::BufferInfo::BufferInfo() : mOwnedByClient(false) {}


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////


#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
class MediaCodec::ReleaseSurface {
    public:
        explicit ReleaseSurface(uint64_t usage) {
            std::tie(mConsumer, mSurface) = BufferItemConsumer::create(usage);

            struct FrameAvailableListener : public BufferItemConsumer::FrameAvailableListener {
                FrameAvailableListener(const sp<BufferItemConsumer> &consumer) {
                    mConsumer = consumer;
                }
                void onFrameAvailable(const BufferItem&) override {
                    BufferItem buffer;
                    // consume buffer
                    sp<BufferItemConsumer> consumer = mConsumer.promote();
                    if (consumer != nullptr && consumer->acquireBuffer(&buffer, 0) == NO_ERROR) {
                        consumer->releaseBuffer(buffer.mGraphicBuffer, buffer.mFence);
                    }
                }

                wp<BufferItemConsumer> mConsumer;
            };
            mFrameAvailableListener = sp<FrameAvailableListener>::make(mConsumer);
            mConsumer->setFrameAvailableListener(mFrameAvailableListener);
            mConsumer->setName(String8{"MediaCodec.release"});
        }

        const sp<Surface> &getSurface() {
            return mSurface;
        }

    private:
        sp<BufferItemConsumer> mConsumer;
        sp<Surface> mSurface;
        sp<BufferItemConsumer::FrameAvailableListener> mFrameAvailableListener;
    };
#else
class MediaCodec::ReleaseSurface {
class MediaCodec::ReleaseSurface {
public:
public:
    explicit ReleaseSurface(uint64_t usage) {
    explicit ReleaseSurface(uint64_t usage) {
@@ -807,6 +846,7 @@ private:
    sp<IGraphicBufferConsumer> mConsumer;
    sp<IGraphicBufferConsumer> mConsumer;
    sp<Surface> mSurface;
    sp<Surface> mSurface;
};
};
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////


+80 −1
Original line number Original line Diff line number Diff line
@@ -18,8 +18,15 @@
#define LOG_TAG "MediaSync"
#define LOG_TAG "MediaSync"
#include <inttypes.h>
#include <inttypes.h>


#include <gui/BufferQueue.h>
#include <com_android_graphics_libgui_flags.h>

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
#include <gui/BufferItemConsumer.h>
#include <gui/Surface.h>
#else
#include <gui/IGraphicBufferConsumer.h>
#include <gui/IGraphicBufferConsumer.h>
#endif
#include <gui/BufferQueue.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/IGraphicBufferProducer.h>


#include <media/AudioTrack.h>
#include <media/AudioTrack.h>
@@ -74,7 +81,11 @@ MediaSync::MediaSync()


MediaSync::~MediaSync() {
MediaSync::~MediaSync() {
    if (mInput != NULL) {
    if (mInput != NULL) {
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
        mInput->abandon();
#else
        mInput->consumerDisconnect();
        mInput->consumerDisconnect();
#endif
    }
    }
    if (mOutput != NULL) {
    if (mOutput != NULL) {
        mOutput->disconnect(NATIVE_WINDOW_API_MEDIA);
        mOutput->disconnect(NATIVE_WINDOW_API_MEDIA);
@@ -204,6 +215,39 @@ status_t MediaSync::createInputSurface(
        return INVALID_OPERATION;
        return INVALID_OPERATION;
    }
    }


#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    int usageFlags = 0;
    mOutput->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &usageFlags);

    auto [newInput, surface] = BufferItemConsumer::create(usageFlags);

    sp<InputListener> listener(new InputListener(this));
    newInput->setFrameAvailableListener(listener);
    newInput->setName(String8("MediaSync"));
    // propagate usage bits from output surface
    status_t status = newInput->setConsumerUsageBits(usageFlags);
    if (status != OK) {
        ALOGE("%s: Unable to set usage bits to %d", __FUNCTION__, usageFlags);
        return status;
    }

    // set undequeued buffer count
    int minUndequeuedBuffers;
    mOutput->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &minUndequeuedBuffers);
    status = newInput->setMaxAcquiredBufferCount(minUndequeuedBuffers);
    if (status != OK) {
        ALOGE("%s: Unable to set setMaxAcquiredBufferCount to %d", __FUNCTION__,
              minUndequeuedBuffers);
        return status;
    }

    mMaxAcquiredBufferCount = minUndequeuedBuffers;
    mUsageFlagsFromOutput = usageFlags;
    mInput = newInput;
    mListener = listener;
    *outBufferProducer = surface->getIGraphicBufferProducer();
    return OK;
#else
    sp<IGraphicBufferProducer> bufferProducer;
    sp<IGraphicBufferProducer> bufferProducer;
    sp<IGraphicBufferConsumer> bufferConsumer;
    sp<IGraphicBufferConsumer> bufferConsumer;
    BufferQueue::createBufferQueue(&bufferProducer, &bufferConsumer);
    BufferQueue::createBufferQueue(&bufferProducer, &bufferConsumer);
@@ -227,6 +271,7 @@ status_t MediaSync::createInputSurface(
        bufferConsumer->setMaxAcquiredBufferCount(mMaxAcquiredBufferCount);
        bufferConsumer->setMaxAcquiredBufferCount(mMaxAcquiredBufferCount);
    }
    }
    return status;
    return status;
#endif
}
}


void MediaSync::resync_l() {
void MediaSync::resync_l() {
@@ -339,7 +384,15 @@ status_t MediaSync::updateQueuedAudioData(


void MediaSync::setName(const AString &name) {
void MediaSync::setName(const AString &name) {
    Mutex::Autolock lock(mMutex);
    Mutex::Autolock lock(mMutex);
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    if (mInput) {
        mInput->setName(String8(name.c_str()));
    } else {
        ALOGE("%s with name %s called without an mInput set", __FUNCTION__, name.c_str());
    }
#else
    mInput->setConsumerName(String8(name.c_str()));
    mInput->setConsumerName(String8(name.c_str()));
#endif
}
}


void MediaSync::flush() {
void MediaSync::flush() {
@@ -621,7 +674,11 @@ void MediaSync::onFrameAvailableFromInput() {


    ALOGV("acquired buffer %#llx from input", (long long)bufferItem.mGraphicBuffer->getId());
    ALOGV("acquired buffer %#llx from input", (long long)bufferItem.mGraphicBuffer->getId());


#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    status = mInput->detachBuffer(bufferItem.mGraphicBuffer);
#else
    status = mInput->detachBuffer(bufferItem.mSlot);
    status = mInput->detachBuffer(bufferItem.mSlot);
#endif
    if (status != NO_ERROR) {
    if (status != NO_ERROR) {
        ALOGE("detaching buffer from input failed (%d)", status);
        ALOGE("detaching buffer from input failed (%d)", status);
        if (status == NO_INIT) {
        if (status == NO_INIT) {
@@ -634,7 +691,11 @@ void MediaSync::onFrameAvailableFromInput() {
    if (mBuffersFromInput.indexOfKey(bufferItem.mGraphicBuffer->getId()) >= 0) {
    if (mBuffersFromInput.indexOfKey(bufferItem.mGraphicBuffer->getId()) >= 0) {
        // Something is wrong since this buffer should be at our hands, bail.
        // Something is wrong since this buffer should be at our hands, bail.
        ALOGE("received buffer multiple times from input");
        ALOGE("received buffer multiple times from input");
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
        mInput->abandon();
#else
        mInput->consumerDisconnect();
        mInput->consumerDisconnect();
#endif
        onAbandoned_l(true /* isInput */);
        onAbandoned_l(true /* isInput */);
        return;
        return;
    }
    }
@@ -687,7 +748,11 @@ void MediaSync::renderOneBufferItem_l(const BufferItem &bufferItem) {


    if (mBuffersSentToOutput.indexOfKey(bufferItem.mGraphicBuffer->getId()) >= 0) {
    if (mBuffersSentToOutput.indexOfKey(bufferItem.mGraphicBuffer->getId()) >= 0) {
        // Something is wrong since this buffer should be held by output now, bail.
        // Something is wrong since this buffer should be held by output now, bail.
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
        mInput->abandon();
#else
        mInput->consumerDisconnect();
        mInput->consumerDisconnect();
#endif
        onAbandoned_l(true /* isInput */);
        onAbandoned_l(true /* isInput */);
        return;
        return;
    }
    }
@@ -748,10 +813,18 @@ void MediaSync::returnBufferToInput_l(


    // Attach and release the buffer back to the input.
    // Attach and release the buffer back to the input.
    int consumerSlot;
    int consumerSlot;
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    status_t status = mInput->attachBuffer(oldBuffer);
#else
    status_t status = mInput->attachBuffer(&consumerSlot, oldBuffer);
    status_t status = mInput->attachBuffer(&consumerSlot, oldBuffer);
#endif
    ALOGE_IF(status != NO_ERROR, "attaching buffer to input failed (%d)", status);
    ALOGE_IF(status != NO_ERROR, "attaching buffer to input failed (%d)", status);
    if (status == NO_ERROR) {
    if (status == NO_ERROR) {
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
        mInput->releaseBuffer(oldBuffer, fence);
#else
        status = mInput->releaseBuffer(consumerSlot, 0 /* frameNumber */, fence);
        status = mInput->releaseBuffer(consumerSlot, 0 /* frameNumber */, fence);
#endif
        ALOGE_IF(status != NO_ERROR, "releasing buffer to input failed (%d)", status);
        ALOGE_IF(status != NO_ERROR, "releasing buffer to input failed (%d)", status);
    }
    }


@@ -770,7 +843,11 @@ void MediaSync::onAbandoned_l(bool isInput) {
        if (isInput) {
        if (isInput) {
            mOutput->disconnect(NATIVE_WINDOW_API_MEDIA);
            mOutput->disconnect(NATIVE_WINDOW_API_MEDIA);
        } else {
        } else {
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
            mInput->abandon();
#else
            mInput->consumerDisconnect();
            mInput->consumerDisconnect();
#endif
        }
        }
        mIsAbandoned = true;
        mIsAbandoned = true;
    }
    }
@@ -815,6 +892,7 @@ void MediaSync::InputListener::onFrameAvailable(const BufferItem &/* item */) {
    mSync->onFrameAvailableFromInput();
    mSync->onFrameAvailableFromInput();
}
}


#if !COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
// We don't care about sideband streams, since we won't relay them.
// We don't care about sideband streams, since we won't relay them.
void MediaSync::InputListener::onSidebandStreamChanged() {
void MediaSync::InputListener::onSidebandStreamChanged() {
    ALOGE("onSidebandStreamChanged: got sideband stream unexpectedly.");
    ALOGE("onSidebandStreamChanged: got sideband stream unexpectedly.");
@@ -825,6 +903,7 @@ void MediaSync::InputListener::binderDied(const wp<IBinder> &/* who */) {
    Mutex::Autolock lock(mSync->mMutex);
    Mutex::Autolock lock(mSync->mMutex);
    mSync->onAbandoned_l(true /* isInput */);
    mSync->onAbandoned_l(true /* isInput */);
}
}
#endif


MediaSync::OutputListener::OutputListener(const sp<MediaSync> &sync,
MediaSync::OutputListener::OutputListener(const sp<MediaSync> &sync,
        const sp<IGraphicBufferProducer> &output)
        const sp<IGraphicBufferProducer> &output)
+23 −3
Original line number Original line Diff line number Diff line
@@ -17,7 +17,13 @@
#ifndef MEDIA_SYNC_H
#ifndef MEDIA_SYNC_H
#define MEDIA_SYNC_H
#define MEDIA_SYNC_H


#include <com_android_graphics_libgui_flags.h>

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
#include <gui/BufferItemConsumer.h>
#else
#include <gui/IConsumerListener.h>
#include <gui/IConsumerListener.h>
#endif
#include <gui/IProducerListener.h>
#include <gui/IProducerListener.h>


#include <media/AudioResamplerPublic.h>
#include <media/AudioResamplerPublic.h>
@@ -34,7 +40,9 @@ class AudioTrack;
class BufferItem;
class BufferItem;
class Fence;
class Fence;
class GraphicBuffer;
class GraphicBuffer;
#if !COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
class IGraphicBufferConsumer;
class IGraphicBufferConsumer;
#endif
class IGraphicBufferProducer;
class IGraphicBufferProducer;
struct MediaClock;
struct MediaClock;
struct VideoFrameScheduler;
struct VideoFrameScheduler;
@@ -140,13 +148,19 @@ private:


    // This is a thin wrapper class that lets us listen to
    // This is a thin wrapper class that lets us listen to
    // IConsumerListener::onFrameAvailable from mInput.
    // IConsumerListener::onFrameAvailable from mInput.
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    class InputListener : public BufferItemConsumer::FrameAvailableListener {
#else
    class InputListener : public IConsumerListener, public IBinder::DeathRecipient {
    class InputListener : public IConsumerListener, public IBinder::DeathRecipient {
#endif
      public:
      public:
        InputListener(const sp<MediaSync> &sync);
        InputListener(const sp<MediaSync> &sync);
        virtual ~InputListener();
        virtual ~InputListener();


        // From IConsumerListener
        // From FrameAvailableListener
        virtual void onFrameAvailable(const BufferItem &item);
        virtual void onFrameAvailable(const BufferItem&) override;

#if !COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)


        // From IConsumerListener
        // From IConsumerListener
        // We don't care about released buffers because we detach each buffer as
        // We don't care about released buffers because we detach each buffer as
@@ -160,6 +174,7 @@ private:


        // From IBinder::DeathRecipient
        // From IBinder::DeathRecipient
        virtual void binderDied(const wp<IBinder> &who);
        virtual void binderDied(const wp<IBinder> &who);
#endif


      private:
      private:
        sp<MediaSync> mSync;
        sp<MediaSync> mSync;
@@ -192,7 +207,12 @@ private:
    mutable Mutex mMutex;
    mutable Mutex mMutex;
    Condition mReleaseCondition;
    Condition mReleaseCondition;
    size_t mNumOutstandingBuffers;
    size_t mNumOutstandingBuffers;
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    sp<BufferItemConsumer> mInput;
    sp<InputListener> mListener;  // listener for mInput, so the reference isn't dropped.
#else
    sp<IGraphicBufferConsumer> mInput;
    sp<IGraphicBufferConsumer> mInput;
#endif
    sp<IGraphicBufferProducer> mOutput;
    sp<IGraphicBufferProducer> mOutput;
    int mUsageFlagsFromOutput;
    int mUsageFlagsFromOutput;
    uint32_t mMaxAcquiredBufferCount; // max acquired buffer count
    uint32_t mMaxAcquiredBufferCount; // max acquired buffer count