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

Commit 03585acc authored by Sohail Nagaraj's avatar Sohail Nagaraj
Browse files

Add a conditional wait for file switching in MPEG4Writer.

If MPEG4Writer has notified approaching max file size limit to the app,
wait on a condition before throwing
MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED error.  The condition will wait
if the notification was sent and no new file is available yet. This is
to ensure that max filesize error is not thrown incorrectly when the app
has sent a new file but the handling of setNextFd is delayed.

Bug: 302064703
Test: atest CtsMediaRecorderTestCases

Change-Id: I9b7f024de2cac0f2cfd434c2382397a996c783ba
parent 206543e3
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -72,6 +72,9 @@ static const int64_t kInitialDelayTimeUs = 700000LL;
static const int64_t kMaxMetadataSize = 0x4000000LL;   // 64MB max per-frame metadata size
static const int64_t kMaxCttsOffsetTimeUs = 30 * 60 * 1000000LL;  // 30 minutes
static const size_t kESDSScratchBufferSize = 10;  // kMaxAtomSize in Mpeg4Extractor 64MB
// Allow up to 100 milli second, which is safely above the maximum delay observed in manual testing
// between posting from setNextFd and handling it
static const int64_t kFdCondWaitTimeoutNs = 100000000;

static const char kMetaKey_Version[]    = "com.android.version";
static const char kMetaKey_Manufacturer[]      = "com.android.manufacturer";
@@ -1262,10 +1265,14 @@ status_t MPEG4Writer::switchFd() {
        return OK;
    }

    // Wait for the signal only if the new file is not available.
    if (mNextFd == -1) {
        status_t res = mFdCond.waitRelative(mLock, kFdCondWaitTimeoutNs);
        if (res != OK) {
            ALOGW("No FileDescriptor for next recording");
            return INVALID_OPERATION;
        }
    }

    mSwitchPending = true;
    sp<AMessage> msg = new AMessage(kWhatSwitch, mReflector);
@@ -2433,6 +2440,7 @@ status_t MPEG4Writer::setNextFd(int fd) {
        return INVALID_OPERATION;
    }
    mNextFd = dup(fd);
    mFdCond.signal();
    return OK;
}

+1 −0
Original line number Diff line number Diff line
@@ -144,6 +144,7 @@ private:
    std::mutex mFallocMutex;
    bool mPreAllocFirstTime; // Pre-allocate space for file and track headers only once per file.
    uint64_t mPrevAllTracksTotalMetaDataSizeEstimate;
    Condition mFdCond;

    List<Track *> mTracks;