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

Commit b69caa46 authored by Hassan Shojania's avatar Hassan Shojania Committed by android-build-merger
Browse files

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

am: a666b698

Change-Id: I9a7d62c2e199bc33dd0677d54647d4d9be02893a
parents 41e635dc a666b698
Loading
Loading
Loading
Loading
+57 −0
Original line number Original line Diff line number Diff line
@@ -98,6 +98,7 @@ void NuPlayer::GenericSource::resetDataSource() {
    mBufferingMonitor->stop();
    mBufferingMonitor->stop();


    mIsDrmProtected = false;
    mIsDrmProtected = false;
    mIsDrmReleased = false;
    mIsSecure = false;
    mIsSecure = false;
    mMimes.clear();
    mMimes.clear();
}
}
@@ -690,6 +691,17 @@ void NuPlayer::GenericSource::onMessageReceived(const sp<AMessage> &msg) {
          break;
          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:
      default:
          Source::onMessageReceived(msg);
          Source::onMessageReceived(msg);
          break;
          break;
@@ -839,6 +851,13 @@ status_t NuPlayer::GenericSource::dequeueAccessUnit(
        return -EWOULDBLOCK;
        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;
    Track *track = audio ? &mAudioTrack : &mVideoTrack;


    if (track->mSource == NULL) {
    if (track->mSource == NULL) {
@@ -1897,11 +1916,31 @@ status_t NuPlayer::GenericSource::prepareDrm(
    return status;
    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)
status_t NuPlayer::GenericSource::onPrepareDrm(const sp<AMessage> &msg)
{
{
    ALOGV("onPrepareDrm ");
    ALOGV("onPrepareDrm ");


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


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


    virtual status_t releaseDrm();



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


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


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


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


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


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

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