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

Commit cf6b1f99 authored by Sungtak Lee's avatar Sungtak Lee Committed by Android (Google) Code Review
Browse files

Merge changes from topic "inputsurface-client-glue" into main

* changes:
  InputSurface: fix bugs and add logs
  CCodec: enable InputSurface
  Codec2Client: add c2 aidl HAL inputsurface
parents 38845013 1612cbb8
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -78,7 +78,7 @@ private:
    c2_status_t mInit;
    c2_status_t mInit;
    std::atomic<bool> mReleased;
    std::atomic<bool> mReleased;


    std::weak_ptr<IInputSink> mSink;
    std::shared_ptr<IInputSink> mSink;
    ::android::wp<c2::implementation::InputSurfaceSource> mSource;
    ::android::wp<c2::implementation::InputSurfaceSource> mSource;
    std::shared_ptr<c2::implementation::FrameQueueThread> mQueueThread;
    std::shared_ptr<c2::implementation::FrameQueueThread> mQueueThread;


+6 −2
Original line number Original line Diff line number Diff line
@@ -16,7 +16,7 @@
 */
 */


//#define LOG_NDEBUG 0
//#define LOG_NDEBUG 0
#define LOG_TAG "Codec2-InputSurface"
#define LOG_TAG "Codec2-InputSurfaceQueue"


#include <sys/types.h>
#include <sys/types.h>


@@ -90,7 +90,11 @@ void FrameQueueThread::run() {
        nsecs_t nowNs = systemTime();
        nsecs_t nowNs = systemTime();
        nsecs_t diffNs = nowNs - mLastQueuedTimestampNs;
        nsecs_t diffNs = nowNs - mLastQueuedTimestampNs;
        if (mItems.empty() || (mLastQueuedTimestampNs != 0 && diffNs < kIntervalNs)) {
        if (mItems.empty() || (mLastQueuedTimestampNs != 0 && diffNs < kIntervalNs)) {
            mCv.wait_for(lock, std::chrono::nanoseconds(kIntervalNs - diffNs));
            nsecs_t waitNs = kIntervalNs;
            if (mLastQueuedTimestampNs != 0) {
                waitNs = diffNs < kIntervalNs ? kIntervalNs - diffNs : 1;
            }
            mCv.wait_for(lock, std::chrono::nanoseconds(waitNs));
            continue;
            continue;
        }
        }
        std::deque<Item> items = std::move(mItems);
        std::deque<Item> items = std::move(mItems);
+5 −1
Original line number Original line Diff line number Diff line
@@ -429,6 +429,10 @@ void InputSurface::init() {
        ALOGE("InputSurface connect: configuring source failed(%d)", c2Res);
        ALOGE("InputSurface connect: configuring source failed(%d)", c2Res);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(c2Res);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(c2Res);
    }
    }
    int numSlots = mImageConfig.mNumBuffers;
    for (size_t i = 0; i < numSlots; ++i) {
        mSource->onInputBufferAdded(i);
    }
    c2Res = mSource->start();
    c2Res = mSource->start();
    if (c2Res != C2_OK) {
    if (c2Res != C2_OK) {
        ALOGE("InputSurface connect: starting source failed(%d)", c2Res);
        ALOGE("InputSurface connect: starting source failed(%d)", c2Res);
@@ -565,7 +569,7 @@ bool InputSurface::updateStreamConfig(
        mStreamConfig.mStopped = config.mStopped;
        mStreamConfig.mStopped = config.mStopped;
    }
    }
    if (status.str().empty()) {
    if (status.str().empty()) {
        ALOGD("StreamConfig not changed");
        ALOGV("StreamConfig not changed");
    } else {
    } else {
        ALOGD("StreamConfig%s", status.str().c_str());
        ALOGD("StreamConfig%s", status.str().c_str());
    }
    }
+4 −4
Original line number Original line Diff line number Diff line
@@ -15,7 +15,7 @@
 */
 */


//#define LOG_NDEBUG 0
//#define LOG_NDEBUG 0
#define LOG_TAG "Codec2-InputSurface"
#define LOG_TAG "Codec2-InputSurfaceConnection"


#include <android_media_codec.h>
#include <android_media_codec.h>
#include <android-base/logging.h>
#include <android-base/logging.h>
@@ -36,8 +36,7 @@ InputSurfaceConnection::InputSurfaceConnection(
    : mSink{sink}, mSource{source},
    : mSink{sink}, mSource{source},
      mQueueThread{std::make_shared<implementation::FrameQueueThread>(sink)}, mFrameIndex(0),
      mQueueThread{std::make_shared<implementation::FrameQueueThread>(sink)}, mFrameIndex(0),
      mAdjustTimestampGapUs(0), mFirstInputFrame(true) {
      mAdjustTimestampGapUs(0), mFirstInputFrame(true) {
    auto component = mSink.lock();
    if (!mSink) {
    if (!component) {
        mInit = C2_NO_INIT;
        mInit = C2_NO_INIT;
        return;
        return;
    }
    }
@@ -153,13 +152,14 @@ void InputSurfaceConnection::onInputBufferEmptied() {
        bufferId = mBuffersTracker.mAvailableIds.front();
        bufferId = mBuffersTracker.mAvailableIds.front();
        mBuffersTracker.mAvailableIds.pop_front();
        mBuffersTracker.mAvailableIds.pop_front();
    }
    }
    notifyInputBufferEmptied(bufferId);
}
}


c2_status_t InputSurfaceConnection::submitBufferInternal(
c2_status_t InputSurfaceConnection::submitBufferInternal(
        int32_t bufferId, const AImage *buffer, int64_t timestamp, int fenceFd, bool eos) {
        int32_t bufferId, const AImage *buffer, int64_t timestamp, int fenceFd, bool eos) {
    // close fenceFd on returning an error.
    // close fenceFd on returning an error.
    ::android::base::unique_fd ufd(fenceFd);
    ::android::base::unique_fd ufd(fenceFd);
    std::shared_ptr<IInputSink> sink = mSink.lock();
    std::shared_ptr<IInputSink> sink = mSink;
    if (!sink) {
    if (!sink) {
        ALOGE("inputsurface does not have valid sink");
        ALOGE("inputsurface does not have valid sink");
        return C2_BAD_STATE;
        return C2_BAD_STATE;
+2 −2
Original line number Original line Diff line number Diff line
@@ -424,8 +424,8 @@ void InputSurfaceSource::initLocked() {
            mImageReaderConfig.width,
            mImageReaderConfig.width,
            mImageReaderConfig.height,
            mImageReaderConfig.height,
            mImageReaderConfig.format,
            mImageReaderConfig.format,
            mImageReaderConfig.maxImages,
            mImageReaderConfig.usage,
            mImageReaderConfig.usage, &mImageReader);
            mImageReaderConfig.maxImages, &mImageReader);
    if (err != AMEDIA_OK) {
    if (err != AMEDIA_OK) {
        if (err == AMEDIA_ERROR_INVALID_PARAMETER) {
        if (err == AMEDIA_ERROR_INVALID_PARAMETER) {
            mInitCheck = C2_BAD_VALUE;
            mInitCheck = C2_BAD_VALUE;
Loading