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

Commit a438123b authored by Andreas Huber's avatar Andreas Huber Committed by Android (Google) Code Review
Browse files

Various improvements to cleanly shutdown a wfd session.

Change-Id: I86f0a27d7e8eb96200153bab847a862f21a19d13
parent 6701a449
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -49,6 +49,10 @@ Converter::~Converter() {
        mEncoder->release();
        mEncoder.clear();
    }

    AString mime;
    CHECK(mInputFormat->findString("mime", &mime));
    ALOGI("encoder (%s) shut down.", mime.c_str());
}

status_t Converter::initCheck() const {
+23 −2
Original line number Diff line number Diff line
@@ -33,7 +33,13 @@ MediaPuller::MediaPuller(
        const sp<MediaSource> &source, const sp<AMessage> &notify)
    : mSource(source),
      mNotify(notify),
      mPullGeneration(0) {
      mPullGeneration(0),
      mIsAudio(false) {
    sp<MetaData> meta = source->getFormat();
    const char *mime;
    CHECK(meta->findCString(kKeyMIMEType, &mime));

    mIsAudio = !strncasecmp(mime, "audio/", 6);
}

MediaPuller::~MediaPuller() {
@@ -77,7 +83,14 @@ void MediaPuller::onMessageReceived(const sp<AMessage> &msg) {
                    schedulePull();
                }
            } else {
                sp<MetaData> meta = mSource->getFormat();
                const char *tmp;
                CHECK(meta->findCString(kKeyMIMEType, &tmp));
                AString mime = tmp;

                ALOGI("MediaPuller(%s) stopping.", mime.c_str());
                err = mSource->stop();
                ALOGI("MediaPuller(%s) stopped.", mime.c_str());
                ++mPullGeneration;
            }

@@ -124,7 +137,15 @@ void MediaPuller::onMessageReceived(const sp<AMessage> &msg) {
                       mbuf->range_length());

                accessUnit->meta()->setInt64("timeUs", timeUs);

                if (mIsAudio) {
                    mbuf->release();
                    mbuf = NULL;
                } else {
                    // video encoder will release MediaBuffer when done
                    // with underlying data.
                    accessUnit->meta()->setPointer("mediaBuffer", mbuf);
                }

                sp<AMessage> notify = mNotify->dup();

+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ private:
    sp<MediaSource> mSource;
    sp<AMessage> mNotify;
    int32_t mPullGeneration;
    bool mIsAudio;

    status_t postSynchronouslyAndReturnError(const sp<AMessage> &msg);
    void schedulePull();
+41 −35
Original line number Diff line number Diff line
@@ -159,6 +159,8 @@ status_t WifiDisplaySource::PlaybackSession::Track::stop() {
        err = mMediaPuller->stop();
    }

    mConverter.clear();

    mStarted = false;

    return err;
@@ -288,41 +290,6 @@ WifiDisplaySource::PlaybackSession::~PlaybackSession() {
        mLogFile = NULL;
    }
#endif

    mTracks.clear();

    mPacketizer.clear();

    if (mSerializer != NULL) {
        mSerializer->stop();

        looper()->unregisterHandler(mSerializer->id());
        mSerializer.clear();
    }

    mTracks.clear();

    if (mSerializerLooper != NULL) {
        mSerializerLooper->stop();
        mSerializerLooper.clear();
    }

    if (mLegacyMode) {
        sp<IServiceManager> sm = defaultServiceManager();
        sp<IBinder> binder = sm->getService(String16("SurfaceFlinger"));
        sp<ISurfaceComposer> service = interface_cast<ISurfaceComposer>(binder);
        CHECK(service != NULL);

        service->connectDisplay(NULL);
    }

    if (mRTCPSessionID != 0) {
        mNetSession->destroySession(mRTCPSessionID);
    }

    if (mRTPSessionID != 0) {
        mNetSession->destroySession(mRTPSessionID);
    }
}

int32_t WifiDisplaySource::PlaybackSession::getRTPPort() const {
@@ -369,6 +336,45 @@ status_t WifiDisplaySource::PlaybackSession::pause() {
    return OK;
}

status_t WifiDisplaySource::PlaybackSession::destroy() {
    mTracks.clear();

    mPacketizer.clear();

    if (mSerializer != NULL) {
        mSerializer->stop();

        looper()->unregisterHandler(mSerializer->id());
        mSerializer.clear();
    }

    mTracks.clear();

    if (mSerializerLooper != NULL) {
        mSerializerLooper->stop();
        mSerializerLooper.clear();
    }

    if (mLegacyMode) {
        sp<IServiceManager> sm = defaultServiceManager();
        sp<IBinder> binder = sm->getService(String16("SurfaceFlinger"));
        sp<ISurfaceComposer> service = interface_cast<ISurfaceComposer>(binder);
        CHECK(service != NULL);

        service->connectDisplay(NULL);
    }

    if (mRTCPSessionID != 0) {
        mNetSession->destroySession(mRTCPSessionID);
    }

    if (mRTPSessionID != 0) {
        mNetSession->destroySession(mRTPSessionID);
    }

    return OK;
}

void WifiDisplaySource::PlaybackSession::onMessageReceived(
        const sp<AMessage> &msg) {
    switch (msg->what()) {
+2 −0
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ struct WifiDisplaySource::PlaybackSession : public AHandler {
            const char *clientIP, int32_t clientRtp, int32_t clientRtcp,
            bool useInterleavedTCP);

    status_t destroy();

    int32_t getRTPPort() const;

    int64_t getLastLifesignUs() const;
Loading