Java 类com.google.android.exoplayer2.drm.DrmSession 实例源码

项目:no-player    文件:LocalDrmSessionManager.java   
@SuppressWarnings("PMD.AvoidCatchingGenericException") // We are forced to catch Exception as ResourceBusyException is minSdk 19
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public DrmSession<FrameworkMediaCrypto> acquireSession(Looper playbackLooper, DrmInitData drmInitData) {
    DrmSession<FrameworkMediaCrypto> drmSession;

    try {
        SessionId sessionId = SessionId.of(mediaDrm.openSession());
        FrameworkMediaCrypto mediaCrypto = mediaDrm.createMediaCrypto(sessionId.asBytes());

        mediaDrm.restoreKeys(sessionId.asBytes(), keySetIdToRestore.asBytes());

        drmSession = new LocalDrmSession(mediaCrypto, keySetIdToRestore, sessionId);
    } catch (Exception exception) {
        drmSession = new InvalidDrmSession(new DrmSession.DrmSessionException(exception));
        notifyErrorListener(drmSession);
    }
    return drmSession;
}
项目:Exoplayer2Radio    文件:MediaCodecRenderer.java   
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (drmSession == null) {
    return false;
  }
  @DrmSession.State int drmSessionState = drmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS
      && (bufferEncrypted || !playClearSamplesWithoutKeys);
}
项目:Exoplayer2Radio    文件:SimpleDecoderAudioRenderer.java   
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (drmSession == null) {
    return false;
  }
  @DrmSession.State int drmSessionState = drmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS
      && (bufferEncrypted || !playClearSamplesWithoutKeys);
}
项目:Exoplayer2Radio    文件:SimpleDecoderAudioRenderer.java   
private void maybeInitDecoder() throws ExoPlaybackException {
  if (decoder != null) {
    return;
  }

  drmSession = pendingDrmSession;
  ExoMediaCrypto mediaCrypto = null;
  if (drmSession != null) {
    @DrmSession.State int drmSessionState = drmSession.getState();
    if (drmSessionState == DrmSession.STATE_ERROR) {
      throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
    } else if (drmSessionState == DrmSession.STATE_OPENED
        || drmSessionState == DrmSession.STATE_OPENED_WITH_KEYS) {
      mediaCrypto = drmSession.getMediaCrypto();
    } else {
      // The drm session isn't open yet.
      return;
    }
  }

  try {
    long codecInitializingTimestamp = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("createAudioDecoder");
    decoder = createDecoder(inputFormat, mediaCrypto);
    TraceUtil.endSection();
    long codecInitializedTimestamp = SystemClock.elapsedRealtime();
    eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp,
        codecInitializedTimestamp - codecInitializingTimestamp);
    decoderCounters.decoderInitCount++;
  } catch (AudioDecoderException e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }
}
项目:no-player    文件:LocalDrmSessionManager.java   
private void notifyErrorListener(DrmSession<FrameworkMediaCrypto> drmSession) {
    final DrmSession.DrmSessionException error = drmSession.getError();
    handler.post(new Runnable() {
        @Override
        public void run() {
            eventListener.onDrmSessionManagerError(error);
        }
    });
}
项目:no-player    文件:LocalDrmSessionManagerTest.java   
@Test
public void givenValidMediaDrm_whenAcquiringSession_thenReturnsLocalDrmSession() throws MediaCryptoException {
    given(mediaDrm.createMediaCrypto(SESSION_ID.asBytes())).willReturn(frameworkMediaCrypto);

    DrmSession<FrameworkMediaCrypto> drmSession = localDrmSessionManager.acquireSession(IGNORED_LOOPER, IGNORED_DRM_DATA);

    LocalDrmSession localDrmSession = new LocalDrmSession(frameworkMediaCrypto, KEY_SET_ID_TO_RESTORE, SESSION_ID);
    assertThat(drmSession).isEqualTo(localDrmSession);
}
项目:no-player    文件:LocalDrmSessionManagerTest.java   
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Test
public void givenOpeningSessionError_whenAcquiringSession_thenNotifiesErrorEventListenerOnHandler() throws MediaDrmException {
    given(mediaDrm.openSession()).willThrow(new ResourceBusyException("resource is busy"));

    localDrmSessionManager.acquireSession(IGNORED_LOOPER, IGNORED_DRM_DATA);

    ArgumentCaptor<Runnable> argumentCaptor = ArgumentCaptor.forClass(Runnable.class);
    verify(handler).post(argumentCaptor.capture());
    argumentCaptor.getValue().run();
    verify(eventListener).onDrmSessionManagerError(any(DrmSession.DrmSessionException.class));
}
项目:no-player    文件:LocalDrmSessionManagerTest.java   
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Test
public void givenOpeningSessionError_whenAcquiringSession_thenReturnsInvalidDrmSession() throws MediaDrmException {
    ResourceBusyException resourceBusyException = new ResourceBusyException("resource is busy");
    given(mediaDrm.openSession()).willThrow(resourceBusyException);

    DrmSession<FrameworkMediaCrypto> drmSession = localDrmSessionManager.acquireSession(IGNORED_LOOPER, IGNORED_DRM_DATA);

    assertThat(drmSession).isInstanceOf(InvalidDrmSession.class);
    assertThat(drmSession.getError().getCause()).isEqualTo(resourceBusyException);
}
项目:no-player    文件:LocalDrmSessionManagerTest.java   
@Test
public void givenAcquiredSession_whenReleasingSession_thenClosesCurrentSession() {
    DrmSession<FrameworkMediaCrypto> drmSession = new LocalDrmSession(frameworkMediaCrypto, KEY_SET_ID_TO_RESTORE, SESSION_ID);

    localDrmSessionManager.releaseSession(drmSession);

    verify(mediaDrm).closeSession(SESSION_ID.asBytes());
}
项目:K-Sonic    文件:MediaCodecRenderer.java   
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (drmSession == null) {
    return false;
  }
  @DrmSession.State int drmSessionState = drmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS
      && (bufferEncrypted || !playClearSamplesWithoutKeys);
}
项目:K-Sonic    文件:SimpleDecoderAudioRenderer.java   
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (drmSession == null) {
    return false;
  }
  @DrmSession.State int drmSessionState = drmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS
      && (bufferEncrypted || !playClearSamplesWithoutKeys);
}
项目:K-Sonic    文件:SimpleDecoderAudioRenderer.java   
private void maybeInitDecoder() throws ExoPlaybackException {
  if (decoder != null) {
    return;
  }

  drmSession = pendingDrmSession;
  ExoMediaCrypto mediaCrypto = null;
  if (drmSession != null) {
    @DrmSession.State int drmSessionState = drmSession.getState();
    if (drmSessionState == DrmSession.STATE_ERROR) {
      throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
    } else if (drmSessionState == DrmSession.STATE_OPENED
        || drmSessionState == DrmSession.STATE_OPENED_WITH_KEYS) {
      mediaCrypto = drmSession.getMediaCrypto();
    } else {
      // The drm session isn't open yet.
      return;
    }
  }

  try {
    long codecInitializingTimestamp = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("createAudioDecoder");
    decoder = createDecoder(inputFormat, mediaCrypto);
    TraceUtil.endSection();
    long codecInitializedTimestamp = SystemClock.elapsedRealtime();
    eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp,
        codecInitializedTimestamp - codecInitializingTimestamp);
    decoderCounters.decoderInitCount++;
  } catch (AudioDecoderException e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }
}
项目:videoPickPlayer    文件:MediaCodecRenderer.java   
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (drmSession == null) {
    return false;
  }
  @DrmSession.State int drmSessionState = drmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS
      && (bufferEncrypted || !playClearSamplesWithoutKeys);
}
项目:Komica    文件:LibvpxVideoRenderer.java   
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (drmSession == null) {
    return false;
  }
  int drmSessionState = drmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS
      && (bufferEncrypted || !playClearSamplesWithoutKeys);
}
项目:transistor    文件:LibvpxVideoRenderer.java   
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (drmSession == null || (!bufferEncrypted && playClearSamplesWithoutKeys)) {
    return false;
  }
  @DrmSession.State int drmSessionState = drmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS;
}
项目:transistor    文件:MediaCodecRenderer.java   
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (drmSession == null || (!bufferEncrypted && playClearSamplesWithoutKeys)) {
    return false;
  }
  @DrmSession.State int drmSessionState = drmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS;
}
项目:transistor    文件:SimpleDecoderAudioRenderer.java   
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (drmSession == null || (!bufferEncrypted && playClearSamplesWithoutKeys)) {
    return false;
  }
  @DrmSession.State int drmSessionState = drmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS;
}
项目:ExoPlayer-Offline    文件:PlayerActivity.java   
private DrmSessionManager<FrameworkMediaCrypto> buildOfflineDrmSessionManager(UUID uuid,
                                                                              String licenseUrl, Map<String, String> keyRequestProperties) throws UnsupportedDrmException, IOException, DrmSession.DrmSessionException, InterruptedException {
    if (Util.SDK_INT < 18) {
        return null;
    }

    customDrmCallback = new CustomDrmCallback(
            DemoApplication.getAppInstance().buildHttpDataSourceFactory(new DefaultBandwidthMeter()),
            licenseUrl
    );

    DefaultDrmSessionManager<FrameworkMediaCrypto> drmSessionManager = new DefaultDrmSessionManager<>(uuid,
            FrameworkMediaDrm.newInstance(uuid), customDrmCallback, null, mainHandler, eventLogger);

    String offlineAssetKeyIdStr = DemoApplication.getAppInstance().
            getSharedPreferences().getString(DemoApplication.KEY_OFFLINE_OFFSET_ID,DemoApplication.EMPTY);
    byte[] offlineAssetKeyId = Base64.decode(offlineAssetKeyIdStr, Base64.DEFAULT);
    this.offlineLicenseHelper = OfflineLicenseHelper.newWidevineInstance(customDrmCallback, null);
    Pair<Long, Long> remainingSecPair = offlineLicenseHelper.getLicenseDurationRemainingSec(offlineAssetKeyId);
    Log.e(TAG," License remaining Play time : "+remainingSecPair.first+", Purchase time : "+remainingSecPair.second);
    if(DemoApplication.EMPTY.equals(offlineAssetKeyIdStr) || ( remainingSecPair.first == 0 || remainingSecPair.second == 0)) {
        String path = getIntent().getStringExtra(EXTRA_OFFLINE_URI);
        File file = getUriForManifest(path);
        Uri uri = Uri.fromFile(file);
        InputStream is = new FileInputStream(file);
        Log.e(TAG, "will start download now");
        offlineAssetKeyId = offlineLicenseHelper.download(
                DemoApplication.getAppInstance().buildHttpDataSourceFactory(new DefaultBandwidthMeter()).createDataSource(),
                new DashManifestParser().parse(uri, is));
        Pair<Long, Long> p = offlineLicenseHelper.getLicenseDurationRemainingSec(offlineAssetKeyId);
        Log.e(TAG, "download done : " + p.toString());

        SharedPreferences sharedPreferences = DemoApplication.getAppInstance().getSharedPreferences();
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(DemoApplication.KEY_OFFLINE_OFFSET_ID,
                Base64.encodeToString(offlineAssetKeyId, Base64.DEFAULT));
        editor.commit();
    }


    drmSessionManager.setMode(DefaultDrmSessionManager.MODE_QUERY,offlineAssetKeyId);
    return drmSessionManager;
}
项目:no-player    文件:LocalDrmSessionManager.java   
@Override
public void releaseSession(DrmSession<FrameworkMediaCrypto> drmSession) {
    FrameworkDrmSession frameworkDrmSession = (FrameworkDrmSession) drmSession;
    SessionId sessionId = frameworkDrmSession.getSessionId();
    mediaDrm.closeSession(sessionId.asBytes());
}
项目:no-player    文件:InvalidDrmSession.java   
@Override
public int getState() {
    return DrmSession.STATE_ERROR;
}
项目:Komica    文件:LibvpxVideoRenderer.java   
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
  if (outputStreamEnded) {
    return;
  }

  // Try and read a format if we don't have one already.
  if (format == null && !readFormat()) {
    // We can't make progress without one.
    return;
  }

  if (isRendererAvailable()) {
    drmSession = pendingDrmSession;
    ExoMediaCrypto mediaCrypto = null;
    if (drmSession != null) {
      int drmSessionState = drmSession.getState();
      if (drmSessionState == DrmSession.STATE_ERROR) {
        throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
      } else if (drmSessionState == DrmSession.STATE_OPENED
          || drmSessionState == DrmSession.STATE_OPENED_WITH_KEYS) {
        mediaCrypto = drmSession.getMediaCrypto();
      } else {
        // The drm session isn't open yet.
        return;
      }
    }
    try {
      if (decoder == null) {
        // If we don't have a decoder yet, we need to instantiate one.
        long codecInitializingTimestamp = SystemClock.elapsedRealtime();
        TraceUtil.beginSection("createVpxDecoder");
        decoder = new VpxDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE,
            mediaCrypto);
        decoder.setOutputMode(outputMode);
        TraceUtil.endSection();
        long codecInitializedTimestamp = SystemClock.elapsedRealtime();
        eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp,
            codecInitializedTimestamp - codecInitializingTimestamp);
        decoderCounters.decoderInitCount++;
      }
      TraceUtil.beginSection("drainAndFeed");
      while (drainOutputBuffer(positionUs)) {}
      while (feedInputBuffer()) {}
      TraceUtil.endSection();
    } catch (VpxDecoderException e) {
      throw ExoPlaybackException.createForRenderer(e, getIndex());
    }
  } else {
    skipToKeyframeBefore(positionUs);
  }
  decoderCounters.ensureUpdated();
}