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

Commit 0d0a9e2f authored by Lajos Molnar's avatar Lajos Molnar Committed by Android (Google) Code Review
Browse files

Merge "stagefright: MediaCodecSource: wait till upstream source stops on stop" into nyc-dev

parents c085a757 72e9ab92
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ const int kStopTimeoutUs = 300000; // allow 1 sec for shutting down encoder
struct MediaCodecSource::Puller : public AHandler {
    Puller(const sp<MediaSource> &source);

    void interruptSource();
    status_t start(const sp<MetaData> &meta, const sp<AMessage> &notify);
    void stop();
    void stopSource();
@@ -186,14 +187,19 @@ void MediaCodecSource::Puller::stop() {
    }

    if (interrupt) {
        interruptSource();
    }
}

void MediaCodecSource::Puller::interruptSource() {
    // call source->stop if read has been pending for over a second
        // TODO: we should really call this if kWhatStop has not returned for more than a second.
    // We have to call this outside the looper as looper is pending on the read.
    mSource->stop();
}
}

void MediaCodecSource::Puller::stopSource() {
    (new AMessage(kWhatStop, this))->post();
    sp<AMessage> msg = new AMessage(kWhatStop, this);
    (void)postSynchronouslyAndReturnError(msg);
}

void MediaCodecSource::Puller::pause() {
@@ -247,6 +253,13 @@ void MediaCodecSource::Puller::onMessageReceived(const sp<AMessage> &msg) {
        case kWhatStop:
        {
            mSource->stop();

            sp<AMessage> response = new AMessage;
            response->setInt32("err", OK);

            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));
            response->postReply(replyID);
            break;
        }

@@ -915,7 +928,7 @@ void MediaCodecSource::onMessageReceived(const sp<AMessage> &msg) {

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