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

Commit ef7d3793 authored by Andreas Huber's avatar Andreas Huber
Browse files

Cleaner Wifi Display shutdown process, avoid crashing HDCP on exit.

Change-Id: Ie54ee3edd672ec629360b4ecc5df2f85ecbaa45f
related-to-bug: 7247584
parent e399acc9
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ HDCP::HDCP()
}

HDCP::~HDCP() {
    Mutex::Autolock autoLock(mLock);

    if (mHDCPModule != NULL) {
        delete mHDCPModule;
        mHDCPModule = NULL;
@@ -63,6 +65,8 @@ HDCP::~HDCP() {
}

status_t HDCP::setObserver(const sp<IHDCPObserver> &observer) {
    Mutex::Autolock autoLock(mLock);

    if (mHDCPModule == NULL) {
        return NO_INIT;
    }
@@ -73,6 +77,8 @@ status_t HDCP::setObserver(const sp<IHDCPObserver> &observer) {
}

status_t HDCP::initAsync(const char *host, unsigned port) {
    Mutex::Autolock autoLock(mLock);

    if (mHDCPModule == NULL) {
        return NO_INIT;
    }
@@ -81,6 +87,8 @@ status_t HDCP::initAsync(const char *host, unsigned port) {
}

status_t HDCP::shutdownAsync() {
    Mutex::Autolock autoLock(mLock);

    if (mHDCPModule == NULL) {
        return NO_INIT;
    }
@@ -91,6 +99,8 @@ status_t HDCP::shutdownAsync() {
status_t HDCP::encrypt(
        const void *inData, size_t size, uint32_t streamCTR,
        uint64_t *outInputCTR, void *outData) {
    Mutex::Autolock autoLock(mLock);

    if (mHDCPModule == NULL) {
        *outInputCTR = 0;

@@ -106,6 +116,8 @@ void HDCP::ObserveWrapper(void *me, int msg, int ext1, int ext2) {
}

void HDCP::observe(int msg, int ext1, int ext2) {
    Mutex::Autolock autoLock(mLock);

    if (mObserver != NULL) {
        mObserver->notify(msg, ext1, ext2, NULL /* obj */);
    }
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#define HDCP_H_

#include <media/IHDCP.h>
#include <utils/Mutex.h>

namespace android {

@@ -35,6 +36,8 @@ struct HDCP : public BnHDCP {
            uint64_t *outInputCTR, void *outData);

private:
    Mutex mLock;

    void *mLibHandle;
    HDCPModule *mHDCPModule;
    sp<IHDCPObserver> mObserver;
+1 −0
Original line number Diff line number Diff line
@@ -193,6 +193,7 @@ status_t SurfaceMediaSource::stop()

    mStopped = true;
    mFrameAvailableCondition.signal();
    mMediaBuffersAvailableCondition.signal();

    return mBufferQueue->consumerDisconnect();
}
+22 −19
Original line number Diff line number Diff line
@@ -153,6 +153,8 @@ void WifiDisplaySource::PlaybackSession::Track::setPacketizerTrackIndex(size_t i
}

status_t WifiDisplaySource::PlaybackSession::Track::start() {
    ALOGV("Track::start isAudio=%d", mIsAudio);

    if (mStarted) {
        return INVALID_OPERATION;
    }
@@ -171,6 +173,8 @@ status_t WifiDisplaySource::PlaybackSession::Track::start() {
}

status_t WifiDisplaySource::PlaybackSession::Track::stop() {
    ALOGV("Track::stop isAudio=%d", mIsAudio);

    if (!mStarted) {
        return INVALID_OPERATION;
    }
@@ -217,6 +221,7 @@ WifiDisplaySource::PlaybackSession::PlaybackSession(
      mNotify(notify),
      mInterfaceAddr(interfaceAddr),
      mHDCP(hdcp),
      mWeAreDead(false),
      mLastLifesignUs(),
      mVideoTrackIndex(-1),
      mTSQueue(new ABuffer(12 + kMaxNumTSPacketsPerRTPPacket * 188)),
@@ -531,6 +536,10 @@ status_t WifiDisplaySource::PlaybackSession::destroy() {

void WifiDisplaySource::PlaybackSession::onMessageReceived(
        const sp<AMessage> &msg) {
    if (mWeAreDead) {
        return;
    }

    switch (msg->what()) {
        case kWhatRTPNotify:
        case kWhatRTCPNotify:
@@ -590,10 +599,7 @@ void WifiDisplaySource::PlaybackSession::onMessageReceived(
                    }
#endif

                    // Inform WifiDisplaySource of our premature death (wish).
                    sp<AMessage> notify = mNotify->dup();
                    notify->setInt32("what", kWhatSessionDead);
                    notify->post();
                    notifySessionDead();
                    break;
                }

@@ -714,12 +720,7 @@ void WifiDisplaySource::PlaybackSession::onMessageReceived(
                        status_t err = packetizeQueuedAccessUnits();

                        if (err != OK) {
                            // Inform WifiDisplaySource of our premature death
                            // (wish).
                            sp<AMessage> notify = mNotify->dup();
                            notify->setInt32("what", kWhatSessionDead);
                            notify->post();

                            notifySessionDead();
                            break;
                        }
                    }
@@ -736,11 +737,7 @@ void WifiDisplaySource::PlaybackSession::onMessageReceived(
                status_t err = packetizeAccessUnit(trackIndex, accessUnit);

                if (err != OK) {
                    // Inform WifiDisplaySource of our premature death
                    // (wish).
                    sp<AMessage> notify = mNotify->dup();
                    notify->setInt32("what", kWhatSessionDead);
                    notify->post();
                    notifySessionDead();
                }
                break;
            } else if (what == Converter::kWhatEOS) {
@@ -768,10 +765,7 @@ void WifiDisplaySource::PlaybackSession::onMessageReceived(

                ALOGE("converter signaled error %d", err);

                // Inform WifiDisplaySource of our premature death (wish).
                sp<AMessage> notify = mNotify->dup();
                notify->setInt32("what", kWhatSessionDead);
                notify->post();
                notifySessionDead();
            }
            break;
        }
@@ -1482,5 +1476,14 @@ status_t WifiDisplaySource::PlaybackSession::packetizeQueuedAccessUnits() {
    return OK;
}

void WifiDisplaySource::PlaybackSession::notifySessionDead() {
    // Inform WifiDisplaySource of our premature death (wish).
    sp<AMessage> notify = mNotify->dup();
    notify->setInt32("what", kWhatSessionDead);
    notify->post();

    mWeAreDead = true;
}

}  // namespace android
+3 −0
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ private:
    sp<AMessage> mNotify;
    in_addr mInterfaceAddr;
    sp<IHDCP> mHDCP;
    bool mWeAreDead;

    int64_t mLastLifesignUs;

@@ -205,6 +206,8 @@ private:

    status_t packetizeQueuedAccessUnits();

    void notifySessionDead();

    DISALLOW_EVIL_CONSTRUCTORS(PlaybackSession);
};

Loading