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

Commit 06ea138f authored by Gopalakrishnan Nallasamy's avatar Gopalakrishnan Nallasamy Committed by Automerger Merge Worker
Browse files

Merge "Modify MediaRecorder stopping process to avoid blocking" into rvc-qpr-dev am: 0fd46582

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/av/+/14066205

Change-Id: Ib824e3a93c8b61d8adfdffe464661f2ad3bd2c14
parents 339769f3 0fd46582
Loading
Loading
Loading
Loading
+10 −25
Original line number Diff line number Diff line
@@ -169,9 +169,7 @@ status_t MediaCodecSource::Puller::postSynchronouslyAndReturnError(
}

status_t MediaCodecSource::Puller::setStopTimeUs(int64_t stopTimeUs) {
    sp<AMessage> msg = new AMessage(kWhatSetStopTimeUs, this);
    msg->setInt64("stop-time-us", stopTimeUs);
    return postSynchronouslyAndReturnError(msg);
    return mSource->setStopTimeUs(stopTimeUs);
}

status_t MediaCodecSource::Puller::start(const sp<MetaData> &meta, const sp<AMessage> &notify) {
@@ -189,21 +187,13 @@ status_t MediaCodecSource::Puller::start(const sp<MetaData> &meta, const sp<AMes
}

void MediaCodecSource::Puller::stop() {
    bool interrupt = false;
    {
    // mark stopping before actually reaching kWhatStop on the looper, so the pulling will
    // stop.
    Mutexed<Queue>::Locked queue(mQueue);
    queue->mPulling = false;
        interrupt = queue->mReadPendingSince && (queue->mReadPendingSince < ALooper::GetNowUs() - 1000000);
    queue->flush(); // flush any unprocessed pulled buffers
}

    if (interrupt) {
        interruptSource();
    }
}

void MediaCodecSource::Puller::interruptSource() {
    // call source->stop if read has been pending for over a second
    // We have to call this outside the looper as looper is pending on the read.
@@ -685,9 +675,9 @@ void MediaCodecSource::signalEOS(status_t err) {
    if (mStopping && reachedEOS) {
        ALOGI("encoder (%s) stopped", mIsVideo ? "video" : "audio");
        if (mPuller != NULL) {
            mPuller->stopSource();
            mPuller->interruptSource();
        }
        ALOGV("source (%s) stopped", mIsVideo ? "video" : "audio");
        ALOGI("source (%s) stopped", mIsVideo ? "video" : "audio");
        // posting reply to everyone that's waiting
        List<sp<AReplyToken>>::iterator it;
        for (it = mStopReplyIDQueue.begin();
@@ -893,7 +883,7 @@ void MediaCodecSource::onMessageReceived(const sp<AMessage> &msg) {
    {
        int32_t eos = 0;
        if (msg->findInt32("eos", &eos) && eos) {
            ALOGV("puller (%s) reached EOS", mIsVideo ? "video" : "audio");
            ALOGI("puller (%s) reached EOS", mIsVideo ? "video" : "audio");
            signalEOS();
            break;
        }
@@ -1111,12 +1101,7 @@ void MediaCodecSource::onMessageReceived(const sp<AMessage> &msg) {
        if (generation != mGeneration) {
             break;
        }

        if (!(mFlags & FLAG_USE_SURFACE_INPUT)) {
            ALOGV("source (%s) stopping", mIsVideo ? "video" : "audio");
            mPuller->interruptSource();
            ALOGV("source (%s) stopped", mIsVideo ? "video" : "audio");
        }
        ALOGD("source (%s) stopping stalled", mIsVideo ? "video" : "audio");
        signalEOS();
        break;
    }