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

Commit 0fd46582 authored by Gopalakrishnan Nallasamy's avatar Gopalakrishnan Nallasamy Committed by Android (Google) Code Review
Browse files

Merge "Modify MediaRecorder stopping process to avoid blocking" into rvc-qpr-dev

parents d3b1df43 f2d549f3
Loading
Loading
Loading
Loading
+10 −25
Original line number Original line Diff line number Diff line
@@ -168,9 +168,7 @@ status_t MediaCodecSource::Puller::postSynchronouslyAndReturnError(
}
}


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


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


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


    if (interrupt) {
        interruptSource();
    }
}

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

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