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

Commit a666b698 authored by Hassan Shojania's avatar Hassan Shojania Committed by Android (Google) Code Review
Browse files

Merge "Modular DRM for MediaPlayer/Race at stop/releaseDrm" into oc-dev

parents 65098155 355e8473
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ void NuPlayer::GenericSource::resetDataSource() {
    mBufferingMonitor->stop();

    mIsDrmProtected = false;
    mIsDrmReleased = false;
    mIsSecure = false;
    mMimes.clear();
}
@@ -690,6 +691,17 @@ void NuPlayer::GenericSource::onMessageReceived(const sp<AMessage> &msg) {
          break;
      }

      case kWhatReleaseDrm:
      {
          status_t status = onReleaseDrm();
          sp<AMessage> response = new AMessage;
          response->setInt32("status", status);
          sp<AReplyToken> replyID;
          CHECK(msg->senderAwaitsResponse(&replyID));
          response->postReply(replyID);
          break;
      }

      default:
          Source::onMessageReceived(msg);
          break;
@@ -839,6 +851,13 @@ status_t NuPlayer::GenericSource::dequeueAccessUnit(
        return -EWOULDBLOCK;
    }

    // If has gone through stop/releaseDrm sequence, we no longer send down any buffer b/c
    // the codec's crypto object has gone away (b/37960096).
    // Note: This will be unnecessary when stop() changes behavior and releases codec (b/35248283).
    if (!mStarted && mIsDrmReleased) {
        return -EWOULDBLOCK;
    }

    Track *track = audio ? &mAudioTrack : &mVideoTrack;

    if (track->mSource == NULL) {
@@ -1897,11 +1916,31 @@ status_t NuPlayer::GenericSource::prepareDrm(
    return status;
}

status_t NuPlayer::GenericSource::releaseDrm()
{
    ALOGV("releaseDrm");

    sp<AMessage> msg = new AMessage(kWhatReleaseDrm, this);

    // synchronous call to update the source states before the player proceedes with crypto cleanup
    sp<AMessage> response;
    status_t status = msg->postAndAwaitResponse(&response);

    if (status == OK && response != NULL) {
        ALOGD("releaseDrm ret: OK ");
    } else {
        ALOGE("releaseDrm err: %d", status);
    }

    return status;
}

status_t NuPlayer::GenericSource::onPrepareDrm(const sp<AMessage> &msg)
{
    ALOGV("onPrepareDrm ");

    mIsDrmProtected = false;
    mIsDrmReleased = false;
    mIsSecure = false;

    uint8_t *uuid;
@@ -1949,8 +1988,26 @@ status_t NuPlayer::GenericSource::onPrepareDrm(const sp<AMessage> &msg)
    return status;
}

status_t NuPlayer::GenericSource::onReleaseDrm()
{
    if (mIsDrmProtected) {
        mIsDrmProtected = false;
        // to prevent returning any more buffer after stop/releaseDrm (b/37960096)
        mIsDrmReleased = true;
        ALOGV("onReleaseDrm: mIsDrmProtected is reset.");
    } else {
        ALOGE("onReleaseDrm: mIsDrmProtected is already false.");
    }

    return OK;
}

status_t NuPlayer::GenericSource::checkDrmInfo()
{
    // clearing the flag at prepare in case the player is reused after stop/releaseDrm with the
    // same source without being reset (called by prepareAsync/initFromDataSource)
    mIsDrmReleased = false;

    if (mFileMeta == NULL) {
        ALOGI("checkDrmInfo: No metadata");
        return OK; // letting the caller responds accordingly
+5 −0
Original line number Diff line number Diff line
@@ -91,6 +91,8 @@ struct NuPlayer::GenericSource : public NuPlayer::Source,
    virtual status_t prepareDrm(
            const uint8_t uuid[16], const Vector<uint8_t> &drmSessionId, sp<ICrypto> *crypto);

    virtual status_t releaseDrm();


protected:
    virtual ~GenericSource();
@@ -119,6 +121,7 @@ private:
        kWhatSecureDecodersInstantiated,
        // Modular DRM
        kWhatPrepareDrm,
        kWhatReleaseDrm,
    };

    struct Track {
@@ -308,10 +311,12 @@ private:

    // Modular DRM
    bool mIsDrmProtected;
    bool mIsDrmReleased;
    Vector<String8> mMimes;

    status_t checkDrmInfo();
    status_t onPrepareDrm(const sp<AMessage> &msg);
    status_t onReleaseDrm();

    DISALLOW_EVIL_CONSTRUCTORS(GenericSource);
};
+5 −0
Original line number Diff line number Diff line
@@ -2787,6 +2787,11 @@ status_t NuPlayer::onReleaseDrm()

    status_t status;
    if (mCrypto != NULL) {
        // notifying the source first before removing crypto from codec
        if (mSource != NULL) {
            mSource->releaseDrm();
        }

        status=OK;
        // first making sure the codecs have released their crypto reference
        const sp<DecoderBase> &videoDecoder = getDecoder(false/*audio*/);