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

Commit 2ea8d6fe authored by ELIYAZ MOMIN's avatar ELIYAZ MOMIN Committed by Gerrit Code Review
Browse files

Revert "InputSurface: update InputSurfaceSource"

Revert submission 3368808-c2inputsurface-2

Reason for revert: <Potential culprit for b/396536754   - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted>

Reverted changes: /q/submissionid:3368808-c2inputsurface-2

Change-Id: I7c4d218b8b77179167ae0c5df0fb00ed1456252f
parent 83f4b07e
Loading
Loading
Loading
Loading
+0 −3
Original line number Original line Diff line number Diff line
@@ -161,10 +161,8 @@ cc_library {
        "Configurable.cpp",
        "Configurable.cpp",
        "InputBufferManager.cpp",
        "InputBufferManager.cpp",
        "ParamTypes.cpp",
        "ParamTypes.cpp",
        "inputsurface/FrameDropper.cpp",
        "inputsurface/InputSurface.cpp",
        "inputsurface/InputSurface.cpp",
        "inputsurface/InputSurfaceConnection.cpp",
        "inputsurface/InputSurfaceConnection.cpp",
        "inputsurface/InputSurfaceSource.cpp",
    ],
    ],


    header_libs: [
    header_libs: [
@@ -188,7 +186,6 @@ cc_library {
        "libmediandk",
        "libmediandk",
        "libstagefright_aidl_bufferpool2",
        "libstagefright_aidl_bufferpool2",
        "libstagefright_bufferpool@2.0.1",
        "libstagefright_bufferpool@2.0.1",
        "libstagefright_foundation",
        "libui",
        "libui",
        "libutils",
        "libutils",
    ],
    ],
+20 −22
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2024 The Android Open Source Project
 * Copyright (C) 2015 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
@@ -14,39 +14,35 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#pragma once
#ifndef FRAME_DROPPER_H_

#define FRAME_DROPPER_H_


#include <utils/Errors.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>


#include <media/stagefright/foundation/ABase.h>
#include <media/stagefright/foundation/ABase.h>


#include <C2.h>
namespace android {

namespace aidl::android::hardware::media::c2::implementation {


/**
struct FrameDropper : public RefBase {
 * The class decides whether to drop a frame or not for InputSurface and
    // No frames will be dropped until a valid max frame rate is set.
 * InputSurfaceConnection.
 */
struct FrameDropper {
    FrameDropper();
    FrameDropper();


    ~FrameDropper();
    // maxFrameRate required to be positive.

    // maxFrameRate negative causes shouldDrop() to always return false
    /**
    // maxFrameRate == 0 is illegal
     * Sets max frame rate, which is based on for deciding frame drop.
    status_t setMaxFrameRate(float maxFrameRate);
     *
     * @param[in] maxFrameRate  negative value means there is no drop
     *                          zero value is ignored
     */
    void setMaxFrameRate(float maxFrameRate);


    /** Returns false if max frame rate has not been set via setMaxFrameRate. */
    // Returns false if max frame rate has not been set via setMaxFrameRate.
    bool shouldDrop(int64_t timeUs);
    bool shouldDrop(int64_t timeUs);


    /** Returns true if all frame drop logic should be disabled. */
    // Returns true if all frame drop logic should be disabled.
    bool disabled() { return (mMinIntervalUs == -1ll); }
    bool disabled() { return (mMinIntervalUs == -1ll); }


protected:
    virtual ~FrameDropper();

private:
private:
    int64_t mDesiredMinTimeUs;
    int64_t mDesiredMinTimeUs;
    int64_t mMinIntervalUs;
    int64_t mMinIntervalUs;
@@ -54,4 +50,6 @@ private:
    DISALLOW_EVIL_CONSTRUCTORS(FrameDropper);
    DISALLOW_EVIL_CONSTRUCTORS(FrameDropper);
};
};


}  // namespace aidl::android::hardware::media::c2::implementation
}  // namespace android

#endif  // FRAME_DROPPER_H_
+126 −119
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2024 The Android Open Source Project
 * Copyright (C) 2013 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
@@ -14,33 +14,35 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#pragma once
#ifndef GRAPHIC_BUFFER_SOURCE_H_


#include <list>
#define GRAPHIC_BUFFER_SOURCE_H_
#include <map>
#include <mutex>


#include <binder/Status.h>
#include <utils/RefBase.h>
#include <utils/RefBase.h>


#include <media-vndk/VndkImageReader.h>
#include <media/hardware/VideoAPI.h>
#include <media/hardware/VideoAPI.h>
#include <media/stagefright/foundation/ABase.h>
#include <media/stagefright/foundation/ABase.h>
#include <media/stagefright/foundation/AHandlerReflector.h>
#include <media/stagefright/foundation/AHandlerReflector.h>
#include <media/stagefright/foundation/ALooper.h>
#include <media/stagefright/foundation/ALooper.h>
#include <media/stagefright/bqhelper/ComponentWrapper.h>
#include <android/hardware/graphics/bufferqueue/1.0/IGraphicBufferProducer.h>
#include <android/hardware/graphics/bufferqueue/2.0/IGraphicBufferProducer.h>


#include <codec2/aidl/inputsurface/InputSurfaceConnection.h>
namespace android {

namespace aidl::android::hardware::media::c2::implementation {


struct FrameDropper;
struct FrameDropper;
/**
class BufferItem;
 * This class is used to feed codecs from ANativeWindow via AImageReader
class IGraphicBufferProducer;
 * for InputSurface and InputSurfaceConnection.
class IGraphicBufferConsumer;
/*
 * This class is used to feed codecs from a Surface via BufferQueue or
 * HW producer.
 *
 *
 * Instances of the class don't run on a dedicated thread.  Instead,
 * Instances of the class don't run on a dedicated thread.  Instead,
 * various events trigger data movement:
 * various events trigger data movement:
 *
 *
 *  - Availability of a new frame of data from the AImageReader (notified
 *  - Availability of a new frame of data from the BufferQueue (notified
 *    via the onFrameAvailable callback).
 *    via the onFrameAvailable callback).
 *  - The return of a codec buffer.
 *  - The return of a codec buffer.
 *  - Application signaling end-of-stream.
 *  - Application signaling end-of-stream.
@@ -50,7 +52,7 @@ struct FrameDropper;
 * before the codec is in the "executing" state, so we need to queue
 * before the codec is in the "executing" state, so we need to queue
 * things up until we're ready to go.
 * things up until we're ready to go.
 *
 *
 * The InputSurfaceSource can be configure dynamically to discard frames
 * The GraphicBufferSource can be configure dynamically to discard frames
 * from the source:
 * from the source:
 *
 *
 * - if their timestamp is less than a start time
 * - if their timestamp is less than a start time
@@ -66,62 +68,75 @@ struct FrameDropper;
 * (even if it was dropped) to reencode it after an interval if no further
 * (even if it was dropped) to reencode it after an interval if no further
 * frames are sent by the producer.
 * frames are sent by the producer.
 */
 */
class InputSurfaceSource : public ::android::RefBase {
class GraphicBufferSource : public RefBase {
// TODO: remove RefBase dependency and AHanderReflector.
public:
public:
    // creates an InputSurfaceSource.
    GraphicBufferSource();
    // init() have to be called prior to use the class.
    InputSurfaceSource();

    virtual ~InputSurfaceSource();


    // Initialize with the default parameter. (persistent surface or init params
    virtual ~GraphicBufferSource();
    // are not decided yet.)
    void init();

    // Initialize with the specified parameters. (non-persistent surface)
    void initWithParams(int32_t width, int32_t height, int32_t format,
                       int32_t maxImages, uint64_t usage);


    // We can't throw an exception if the constructor fails, so we just set
    // We can't throw an exception if the constructor fails, so we just set
    // this and require that the caller test the value.
    // this and require that the caller test the value.
    c2_status_t initCheck() const {
    status_t initCheck() const {
        return mInitCheck;
        return mInitCheck;
    }
    }


    /**
    // Returns the handle to the producer side of the BufferQueue.  Buffers
     * Returns the handle of ANativeWindow of the AImageReader.
    // queued on this will be received by GraphicBufferSource.
     */
    sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
    ANativeWindow *getNativeWindow();

    // Returns the handle to the bufferqueue HAL (V1_0) producer side of the BufferQueue.
    // Buffers queued on this will be received by GraphicBufferSource.
    sp<::android::hardware::graphics::bufferqueue::V1_0::IGraphicBufferProducer>
        getHGraphicBufferProducer_V1_0() const;

    // Returns the handle to the bufferqueue HAL producer side of the BufferQueue.
    // Buffers queued on this will be received by GraphicBufferSource.
    sp<::android::hardware::graphics::bufferqueue::V2_0::IGraphicBufferProducer>
        getHGraphicBufferProducer() const;


    // This is called when component transitions to running state, which means
    // This is called when component transitions to running state, which means
    // we can start handing it buffers.  If we already have buffers of data
    // we can start handing it buffers.  If we already have buffers of data
    // sitting in the AImageReader, this will send them to the codec.
    // sitting in the BufferQueue, this will send them to the codec.
    c2_status_t start();
    status_t start();


    // This is called when component transitions to stopped, indicating that
    // This is called when component transitions to stopped, indicating that
    // the codec is meant to return all buffers back to the client for them
    // 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.
    // to be freed. Do NOT submit any more buffers to the component.
    c2_status_t stop();
    status_t stop();


    // This is called when component transitions to released, indicating that
    // This is called when component transitions to released, indicating that
    // we are shutting down.
    // we are shutting down.
    c2_status_t release();
    status_t release();


    // A "codec buffer", i.e. a buffer that can be used to pass data into
    // 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
    // the encoder, has been allocated.  (This call does not call back into
    // component.)
    // component.)
    c2_status_t onInputBufferAdded(int32_t bufferId);
    status_t onInputBufferAdded(int32_t bufferId);

    // Called when encoder is no longer using the buffer.  If we have a BQ
    // buffer available, fill it with a new frame of data; otherwise, just mark
    // it as available.
    status_t onInputBufferEmptied(int32_t bufferId, int fenceFd);

    // IGraphicBufferSource interface
    // ------------------------------


    // Called when encoder is no longer using the buffer.  If we have an
    // Configure the buffer source to be used with a component with the default
    // AImageReader buffer available, fill it with a new frame of data;
    // data space. (32-bit consumerUsage flag, for vendor partition
    // otherwise, just mark it as available.
    // compatibility)
    c2_status_t onInputBufferEmptied(int32_t bufferId, int fenceFd);
    [[deprecated("use configure() with a 64-bit consumerUsage flag instead")]]
    status_t configure(
        const sp<ComponentWrapper> &component,
        int32_t dataSpace,
        int32_t bufferCount,
        uint32_t frameWidth,
        uint32_t frameHeight,
        uint32_t consumerUsage);


    // Configure the buffer source to be used with a component with the default
    // Configure the buffer source to be used with a component with the default
    // data space.
    // data space. (64-bit consumerUsage flag)
    c2_status_t configure(
    status_t configure(
        const std::shared_ptr<c2::utils::InputSurfaceConnection> &component,
        const sp<ComponentWrapper> &component,
        int32_t dataSpace,
        int32_t dataSpace,
        int32_t bufferCount,
        int32_t bufferCount,
        uint32_t frameWidth,
        uint32_t frameWidth,
@@ -132,14 +147,14 @@ public:
    // timestamp is greater or equal than stopTimeUs. We need to submit an empty
    // timestamp is greater or equal than stopTimeUs. We need to submit an empty
    // buffer with the EOS flag set.  If we don't have a codec buffer ready,
    // buffer with the EOS flag set.  If we don't have a codec buffer ready,
    // we just set the mEndOfStream flag.
    // we just set the mEndOfStream flag.
    c2_status_t signalEndOfInputStream();
    status_t signalEndOfInputStream();


    // If suspend is true, all incoming buffers (including those currently
    // If suspend is true, all incoming buffers (including those currently
    // in the BufferQueue) with timestamp larger than timeUs will be discarded
    // in the BufferQueue) with timestamp larger than timeUs will be discarded
    // until the suspension is lifted. If suspend is false, all incoming buffers
    // until the suspension is lifted. If suspend is false, all incoming buffers
    // including those currently in the BufferQueue) with timestamp larger than
    // including those currently in the BufferQueue) with timestamp larger than
    // timeUs will be processed. timeUs uses SYSTEM_TIME_MONOTONIC time base.
    // timeUs will be processed. timeUs uses SYSTEM_TIME_MONOTONIC time base.
    c2_status_t setSuspend(bool suspend, int64_t timeUs);
    status_t setSuspend(bool suspend, int64_t timeUs);


    // Specifies the interval after which we requeue the buffer previously
    // Specifies the interval after which we requeue the buffer previously
    // queued to the encoder. This is useful in the case of surface flinger
    // queued to the encoder. This is useful in the case of surface flinger
@@ -148,11 +163,11 @@ public:
    // the decoder on the remote end would be unable to decode the latest frame.
    // the decoder on the remote end would be unable to decode the latest frame.
    // This API must be called before transitioning the encoder to "executing"
    // This API must be called before transitioning the encoder to "executing"
    // state and once this behaviour is specified it cannot be reset.
    // state and once this behaviour is specified it cannot be reset.
    c2_status_t setRepeatPreviousFrameDelayUs(int64_t repeatAfterUs);
    status_t setRepeatPreviousFrameDelayUs(int64_t repeatAfterUs);


    // Sets the input buffer timestamp offset.
    // Sets the input buffer timestamp offset.
    // When set, the sample's timestamp will be adjusted with the timeOffsetUs.
    // When set, the sample's timestamp will be adjusted with the timeOffsetUs.
    c2_status_t setTimeOffsetUs(int64_t timeOffsetUs);
    status_t setTimeOffsetUs(int64_t timeOffsetUs);


    /*
    /*
     * Set the maximum frame rate on the source.
     * Set the maximum frame rate on the source.
@@ -169,63 +184,68 @@ public:
     *
     *
     * When maxFps is 0, this call will fail with BAD_VALUE.
     * When maxFps is 0, this call will fail with BAD_VALUE.
     */
     */
    c2_status_t setMaxFps(float maxFps);
    status_t setMaxFps(float maxFps);


    // Sets the time lapse (or slow motion) parameters.
    // Sets the time lapse (or slow motion) parameters.
    // When set, the sample's timestamp will be modified to playback framerate,
    // When set, the sample's timestamp will be modified to playback framerate,
    // and capture timestamp will be modified to capture rate.
    // and capture timestamp will be modified to capture rate.
    c2_status_t setTimeLapseConfig(double fps, double captureFps);
    status_t setTimeLapseConfig(double fps, double captureFps);


    // Sets the start time us (in system time), samples before which should
    // Sets the start time us (in system time), samples before which should
    // be dropped and not submitted to encoder
    // be dropped and not submitted to encoder
    c2_status_t setStartTimeUs(int64_t startTimeUs);
    status_t setStartTimeUs(int64_t startTimeUs);


    // Sets the stop time us (in system time), samples after which should be dropped
    // Sets the stop time us (in system time), samples after which should be dropped
    // and not submitted to encoder. timeUs uses SYSTEM_TIME_MONOTONIC time base.
    // and not submitted to encoder. timeUs uses SYSTEM_TIME_MONOTONIC time base.
    c2_status_t setStopTimeUs(int64_t stopTimeUs);
    status_t setStopTimeUs(int64_t stopTimeUs);


    // Gets the stop time offset in us. This is the time offset between latest buffer
    // Gets the stop time offset in us. This is the time offset between latest buffer
    // time and the stopTimeUs. If stop time is not set, INVALID_OPERATION will be returned.
    // time and the stopTimeUs. If stop time is not set, INVALID_OPERATION will be returned.
    // If return is OK, *stopTimeOffsetUs will contain the valid offset. Otherwise,
    // If return is OK, *stopTimeOffsetUs will contain the valid offset. Otherwise,
    // *stopTimeOffsetUs will not be modified. Positive stopTimeOffsetUs means buffer time
    // *stopTimeOffsetUs will not be modified. Positive stopTimeOffsetUs means buffer time
    // larger than stopTimeUs.
    // larger than stopTimeUs.
    c2_status_t getStopTimeOffsetUs(int64_t *stopTimeOffsetUs);
    status_t getStopTimeOffsetUs(int64_t *stopTimeOffsetUs);


    // Sets the desired color aspects, e.g. to be used when producer does not specify a dataspace.
    // Sets the desired color aspects, e.g. to be used when producer does not specify a dataspace.
    c2_status_t setColorAspects(int32_t aspectsPacked);
    status_t setColorAspects(int32_t aspectsPacked);


protected:
protected:


    // Called from AImageReader_ImageListener::onImageAvailable when a new frame
    // BufferQueue::ConsumerListener interface, called when a new frame of
    // of  data is available. If we're executing and a codec buffer is
    // data is available.  If we're executing and a codec buffer is
    // available, we acquire the buffer as an AImage, copy the AImage into the codec
    // available, we acquire the buffer, copy the GraphicBuffer reference
    // buffer, and call Empty[This]Buffer.  If we're not yet executing or
    // into the codec buffer, and call Empty[This]Buffer.  If we're not yet
    // there's no codec buffer available, we just increment mNumFramesAvailable
    // executing or there's no codec buffer available, we just increment
    // and return.
    // mNumFramesAvailable and return.
    void onFrameAvailable() ;
    void onFrameAvailable(const BufferItem& item) ;


    // Called from AImageReader_BufferRemovedListener::onBufferRemoved when a
    // BufferQueue::ConsumerListener interface, called when the client has
    // buffer is removed. We clear an appropriate cached buffer.
    // released one or more GraphicBuffers.  We clear out the appropriate
    void onBufferReleased(uint64_t bid) ;
    // set of mBufferSlot entries.
    void onBuffersReleased() ;


private:
    // BufferQueue::ConsumerListener interface, called when the client has
    // changed the sideband stream. GraphicBufferSource doesn't handle sideband
    // streams so this is a no-op (and should never be called).
    void onSidebandStreamChanged() ;


    // AImageReader listener interface
private:
    struct ImageReaderListener;
    // BQ::ConsumerListener interface
    AImageReader_ImageListener mImageListener;
    // ------------------------------
    AImageReader_BufferRemovedListener mBufferRemovedListener;
    struct ConsumerProxy;
    sp<ConsumerProxy> mConsumerProxy;


    // Lock, covers all member variables.
    // Lock, covers all member variables.
    mutable std::mutex mMutex;
    mutable Mutex mMutex;


    // Used to report constructor failure regarding AImageReader creation.
    // Used to report constructor failure.
    c2_status_t mInitCheck;
    status_t mInitCheck;


    // Graphic buffer reference objects
    // Graphic buffer reference objects
    // --------------------------------
    // --------------------------------


    // These are used to keep a reference to AImage and gralloc handles owned by the
    // These are used to keep a shared reference to GraphicBuffers and gralloc handles owned by the
    // InputSurfaceSource as well as to manage the cache slots. Separate references are owned by
    // GraphicBufferSource as well as to manage the cache slots. Separate references are owned by
    // the buffer cache (controlled by the buffer queue/buffer producer) and the codec.
    // the buffer cache (controlled by the buffer queue/buffer producer) and the codec.


    // When we get a buffer from the producer (BQ) it designates them to be cached into specific
    // When we get a buffer from the producer (BQ) it designates them to be cached into specific
@@ -247,42 +267,39 @@ private:
        android_dataspace_t mDataspace;
        android_dataspace_t mDataspace;
    };
    };


    // Cached and acquired buffers
    // Cached and aquired buffers
    // --------------------------------
    // --------------------------------


    typedef uint64_t ahwb_id;
    typedef int slot_id;
    typedef std::map<ahwb_id, std::shared_ptr<CachedBuffer>> BufferIdMap;


    // TODO: refactor(or remove) this not to have the buffer,
    // Maps a slot to the cached buffer in that slot
    // since it is no longer slot based
    KeyedVector<slot_id, std::shared_ptr<CachedBuffer>> mBufferSlots;
    // Maps a AHardwareBuffer id to the cached buffer
    BufferIdMap mBufferIds;


    // Queue of buffers acquired in chronological order that are not yet submitted to the codec
    // Queue of buffers acquired in chronological order that are not yet submitted to the codec
    ::std::list<VideoBuffer> mAvailableBuffers;
    List<VideoBuffer> mAvailableBuffers;


    // Number of buffers that have been signaled by the producer that they are available, but
    // Number of buffers that have been signaled by the producer that they are available, but
    // we've been unable to acquire them due to our max acquire count
    // we've been unable to acquire them due to our max acquire count
    int32_t mNumAvailableUnacquiredBuffers;
    int32_t mNumAvailableUnacquiredBuffers;


    // Number of frames acquired from consumer (debug only)
    // Number of frames acquired from consumer (debug only)
    // (as in acquireBuffer called, and release needs to be called)
    // (as in aquireBuffer called, and release needs to be called)
    int32_t mNumOutstandingAcquires;
    int32_t mNumOutstandingAcquires;


    // Acquire a buffer from the BQ and store it in |item| if successful
    // Acquire a buffer from the BQ and store it in |item| if successful
    // \return OK on success, or error on failure.
    // \return OK on success, or error on failure.
    c2_status_t acquireBuffer_l(VideoBuffer *item);
    status_t acquireBuffer_l(VideoBuffer *item);


    // Called when a buffer was acquired from the producer
    // Called when a buffer was acquired from the producer
    void onBufferAcquired_l(const VideoBuffer &buffer);
    void onBufferAcquired_l(const VideoBuffer &buffer);


    // marks the buffer of the id no longer cached, and accounts for the outstanding
    // marks the buffer at the slot no longer cached, and accounts for the outstanding
    // acquire count. Returns true if the slot was populated; otherwise, false.
    // acquire count. Returns true if the slot was populated; otherwise, false.
    bool discardBufferInId_l(ahwb_id id);
    bool discardBufferInSlot_l(slot_id i);


    // marks the buffer at the id index no longer cached, and accounts for the outstanding
    // marks the buffer at the slot index no longer cached, and accounts for the outstanding
    // acquire count
    // acquire count
    void discardBufferAtIter_l(BufferIdMap::iterator &bit);
    void discardBufferAtSlotIndex_l(ssize_t bsi);


    // release all acquired and unacquired available buffers
    // release all acquired and unacquired available buffers
    // This method will return if it fails to acquire an unacquired available buffer, which will
    // This method will return if it fails to acquire an unacquired available buffer, which will
@@ -303,11 +320,11 @@ private:
    typedef int32_t codec_buffer_id;
    typedef int32_t codec_buffer_id;


    // set of codec buffer ID-s of buffers available to fill
    // set of codec buffer ID-s of buffers available to fill
    std::list<codec_buffer_id> mFreeCodecBuffers;
    List<codec_buffer_id> mFreeCodecBuffers;


    // maps codec buffer ID-s to buffer info submitted to the codec. Used to keep a reference for
    // maps codec buffer ID-s to buffer info submitted to the codec. Used to keep a reference for
    // the graphics buffer.
    // the graphics buffer.
    std::map<codec_buffer_id, std::shared_ptr<AcquiredBuffer>> mSubmittedCodecBuffers;
    KeyedVector<codec_buffer_id, std::shared_ptr<AcquiredBuffer>> mSubmittedCodecBuffers;


    // Processes the next acquired frame. If there is no available codec buffer, it returns false
    // Processes the next acquired frame. If there is no available codec buffer, it returns false
    // without any further action.
    // without any further action.
@@ -326,7 +343,7 @@ private:
    // while also keeping a reference for it in mSubmittedCodecBuffers.
    // while also keeping a reference for it in mSubmittedCodecBuffers.
    // Returns UNKNOWN_ERROR if the buffer was not submitted due to buffer timestamp. Otherwise,
    // Returns UNKNOWN_ERROR if the buffer was not submitted due to buffer timestamp. Otherwise,
    // it returns any submit success or error value returned by the codec.
    // it returns any submit success or error value returned by the codec.
    c2_status_t submitBuffer_l(const VideoBuffer &item);
    status_t submitBuffer_l(const VideoBuffer &item);


    // Submits an empty buffer, with the EOS flag set if there is an available codec buffer and
    // Submits an empty buffer, with the EOS flag set if there is an available codec buffer and
    // sets mEndOfStreamSent flag. Does nothing if there is no codec buffer available.
    // sets mEndOfStreamSent flag. Does nothing if there is no codec buffer available.
@@ -349,7 +366,7 @@ private:
    void onDataspaceChanged_l(android_dataspace dataspace, android_pixel_format pixelFormat);
    void onDataspaceChanged_l(android_dataspace dataspace, android_pixel_format pixelFormat);


    // Pointer back to the component that created us.  We send buffers here.
    // Pointer back to the component that created us.  We send buffers here.
    std::shared_ptr<c2::utils::InputSurfaceConnection> mComponent;
    sp<ComponentWrapper> mComponent;


    // Set by start() / stop().
    // Set by start() / stop().
    bool mExecuting;
    bool mExecuting;
@@ -362,21 +379,11 @@ private:


    int64_t mLastFrameTimestampUs;
    int64_t mLastFrameTimestampUs;


    // AImageReader creates ANativeWindow. The created ANativeWindow is passed
    // Our BufferQueue interfaces. mProducer is passed to the producer through
    // to the producer, and mImageReader is used internally to retrieve the
    // getIGraphicBufferProducer, and mConsumer is used internally to retrieve
    // buffers queued by the producer.
    // the buffers queued by the producer.
    AImageReader *mImageReader;
    sp<IGraphicBufferProducer> mProducer;
    ANativeWindow *mImageWindow;
    sp<IGraphicBufferConsumer> mConsumer;

    // AImageReader creation parameters
    // maxImages cannot be changed after AImageReader is created.
    struct ImageReaderConfig {
        int32_t width;
        int32_t height;
        int32_t format;
        int32_t maxImages;
        uint64_t usage;
    } mImageReaderConfig;


    // The time to stop sending buffers.
    // The time to stop sending buffers.
    int64_t mStopTimeUs;
    int64_t mStopTimeUs;
@@ -395,13 +402,13 @@ private:
    // monotonically increasing.
    // monotonically increasing.
    int64_t mLastActionTimeUs;
    int64_t mLastActionTimeUs;


    // An action queue that queue up all the actions sent to InputSurfaceSource.
    // An action queue that queue up all the actions sent to GraphicBufferSource.
    // STOP action should only show up at the end of the list as all the actions
    // STOP action should only show up at the end of the list as all the actions
    // after a STOP action will be discarded. mActionQueue is protected by mMutex.
    // after a STOP action will be discarded. mActionQueue is protected by mMutex.
    std::list<ActionItem> mActionQueue;
    List<ActionItem> mActionQueue;


    ////
    ////
    friend struct ::android::AHandlerReflector<InputSurfaceSource>;
    friend struct AHandlerReflector<GraphicBufferSource>;


    enum {
    enum {
        kWhatRepeatLastFrame,   ///< queue last frame for reencoding
        kWhatRepeatLastFrame,   ///< queue last frame for reencoding
@@ -412,10 +419,10 @@ private:


    int64_t mSkipFramesBeforeNs;
    int64_t mSkipFramesBeforeNs;


    std::shared_ptr<FrameDropper> mFrameDropper;
    sp<FrameDropper> mFrameDropper;


    ::android::sp<::android::ALooper> mLooper;
    sp<ALooper> mLooper;
    ::android::sp<::android::AHandlerReflector<InputSurfaceSource> > mReflector;
    sp<AHandlerReflector<GraphicBufferSource> > mReflector;


    // Repeat last frame feature
    // Repeat last frame feature
    // -------------------------
    // -------------------------
@@ -519,11 +526,11 @@ private:
    // adjustment requests.
    // adjustment requests.
    bool calculateCodecTimestamp_l(nsecs_t bufferTimeNs, int64_t *codecTimeUs);
    bool calculateCodecTimestamp_l(nsecs_t bufferTimeNs, int64_t *codecTimeUs);


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


    void createImageListeners();
    DISALLOW_EVIL_CONSTRUCTORS(GraphicBufferSource);

    DISALLOW_EVIL_CONSTRUCTORS(InputSurfaceSource);
};
};


}  // namespace aidl::android::hardware::media::c2::implementation
}  // namespace android

#endif  // GRAPHIC_BUFFER_SOURCE_H_
+10 −10
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2024 The Android Open Source Project
 * Copyright (C) 2015 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
@@ -15,14 +15,13 @@
 */
 */


//#define LOG_NDEBUG 0
//#define LOG_NDEBUG 0
#define LOG_TAG "C2AIDL-FrameDropper"
#define LOG_TAG "FrameDropper"
#include <utils/Log.h>
#include <utils/Log.h>


#include <codec2/aidl/inputsurface/FrameDropper.h>
#include <media/stagefright/bqhelper/FrameDropper.h>

#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/ADebug.h>


namespace aidl::android::hardware::media::c2::implementation {
namespace android {


static const int64_t kMaxJitterUs = 2000;
static const int64_t kMaxJitterUs = 2000;


@@ -34,17 +33,18 @@ FrameDropper::FrameDropper()
FrameDropper::~FrameDropper() {
FrameDropper::~FrameDropper() {
}
}


void FrameDropper::setMaxFrameRate(float maxFrameRate) {
status_t FrameDropper::setMaxFrameRate(float maxFrameRate) {
    if (maxFrameRate < 0) {
    if (maxFrameRate < 0) {
        mMinIntervalUs = -1LL;
        mMinIntervalUs = -1LL;
        return;
        return OK;
    }
    }


    if (maxFrameRate == 0) {
    if (maxFrameRate == 0) {
        ALOGW("framerate should be positive but got %f.", maxFrameRate);
        ALOGE("framerate should be positive but got %f.", maxFrameRate);
        return;
        return BAD_VALUE;
    }
    }
    mMinIntervalUs = (int64_t) (1000000.0f / maxFrameRate);
    mMinIntervalUs = (int64_t) (1000000.0f / maxFrameRate);
    return OK;
}
}


bool FrameDropper::shouldDrop(int64_t timeUs) {
bool FrameDropper::shouldDrop(int64_t timeUs) {
@@ -74,4 +74,4 @@ bool FrameDropper::shouldDrop(int64_t timeUs) {
    return false;
    return false;
}
}


}  // namespace aidl::android::hardware::media::c2::implementation
}  // namespace android
+359 −453

File changed.

Preview size limit exceeded, changes collapsed.