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

项目:Exoplayer2Radio    文件:OfflineLicenseHelper.java   
/**
 * Returns the remaining license and playback durations in seconds, for an offline license.
 *
 * @param offlineLicenseKeySetId The key set id of the license.
 * @return The remaining license and playback durations, in seconds.
 * @throws DrmSessionException Thrown when a DRM session error occurs.
 */
public synchronized Pair<Long, Long> getLicenseDurationRemainingSec(byte[] offlineLicenseKeySetId)
    throws DrmSessionException {
  Assertions.checkNotNull(offlineLicenseKeySetId);
  DrmSession<T> drmSession = openBlockingKeyRequest(DefaultDrmSessionManager.MODE_QUERY,
      offlineLicenseKeySetId, null);
  DrmSessionException error = drmSession.getError();
  Pair<Long, Long> licenseDurationRemainingSec =
      WidevineUtil.getLicenseDurationRemainingSec(drmSession);
  drmSessionManager.releaseSession(drmSession);
  if (error != null) {
    if (error.getCause() instanceof KeysExpiredException) {
      return Pair.create(0L, 0L);
    }
    throw error;
  }
  return licenseDurationRemainingSec;
}
项目:transistor    文件:OfflineLicenseHelper.java   
/**
 * Returns the remaining license and playback durations in seconds, for an offline license.
 *
 * @param offlineLicenseKeySetId The key set id of the license.
 * @return The remaining license and playback durations, in seconds.
 * @throws DrmSessionException Thrown when a DRM session error occurs.
 */
public synchronized Pair<Long, Long> getLicenseDurationRemainingSec(byte[] offlineLicenseKeySetId)
    throws DrmSessionException {
  Assertions.checkNotNull(offlineLicenseKeySetId);
  DrmSession<T> drmSession = openBlockingKeyRequest(DefaultDrmSessionManager.MODE_QUERY,
      offlineLicenseKeySetId, null);
  DrmSessionException error = drmSession.getError();
  Pair<Long, Long> licenseDurationRemainingSec =
      WidevineUtil.getLicenseDurationRemainingSec(drmSession);
  drmSessionManager.releaseSession(drmSession);
  if (error != null) {
    if (error.getCause() instanceof KeysExpiredException) {
      return Pair.create(0L, 0L);
    }
    throw error;
  }
  return licenseDurationRemainingSec;
}
项目:ExoPlayer-Offline    文件:DashTest.java   
public byte[] downloadLicense() throws InterruptedException, DrmSessionException, IOException {
  assertNull(offlineLicenseKeySetId);
  offlineLicenseKeySetId = offlineLicenseHelper
      .download(httpDataSourceFactory.createDataSource(), parameters.manifestUrl);
  assertNotNull(offlineLicenseKeySetId);
  assertTrue(offlineLicenseKeySetId.length > 0);
  return offlineLicenseKeySetId;
}
项目:ExoPlayer-Offline    文件:DashTest.java   
public void releaseResources() throws DrmSessionException {
  if (offlineLicenseKeySetId != null) {
    releaseLicense();
  }
  if (offlineLicenseHelper != null) {
    offlineLicenseHelper.releaseResources();
  }
}
项目:Exoplayer2Radio    文件:OfflineLicenseHelper.java   
private byte[] blockingKeyRequest(@Mode int licenseMode, byte[] offlineLicenseKeySetId,
    DrmInitData drmInitData) throws DrmSessionException {
  DrmSession<T> drmSession = openBlockingKeyRequest(licenseMode, offlineLicenseKeySetId,
      drmInitData);
  DrmSessionException error = drmSession.getError();
  byte[] keySetId = drmSession.getOfflineLicenseKeySetId();
  drmSessionManager.releaseSession(drmSession);
  if (error != null) {
    throw error;
  }
  return keySetId;
}
项目:K-Sonic    文件:OfflineLicenseHelper.java   
/**
 * Downloads an offline license.
 *
 * @param dataSource The {@link HttpDataSource} to be used for download.
 * @param dashManifest The {@link DashManifest} of the DASH content.
 * @return The downloaded offline license key set id.
 * @throws IOException If an error occurs reading data from the stream.
 * @throws InterruptedException If the thread has been interrupted.
 * @throws DrmSessionException Thrown when there is an error during DRM session.
 */
public byte[] download(HttpDataSource dataSource, DashManifest dashManifest)
    throws IOException, InterruptedException, DrmSessionException {
  // Get DrmInitData
  // Prefer drmInitData obtained from the manifest over drmInitData obtained from the stream,
  // as per DASH IF Interoperability Recommendations V3.0, 7.5.3.
  if (dashManifest.getPeriodCount() < 1) {
    return null;
  }
  Period period = dashManifest.getPeriod(0);
  int adaptationSetIndex = period.getAdaptationSetIndex(C.TRACK_TYPE_VIDEO);
  if (adaptationSetIndex == C.INDEX_UNSET) {
    adaptationSetIndex = period.getAdaptationSetIndex(C.TRACK_TYPE_AUDIO);
    if (adaptationSetIndex == C.INDEX_UNSET) {
      return null;
    }
  }
  AdaptationSet adaptationSet = period.adaptationSets.get(adaptationSetIndex);
  if (adaptationSet.representations.isEmpty()) {
    return null;
  }
  Representation representation = adaptationSet.representations.get(0);
  DrmInitData drmInitData = representation.format.drmInitData;
  if (drmInitData == null) {
    Format sampleFormat = DashUtil.loadSampleFormat(dataSource, representation);
    if (sampleFormat != null) {
      drmInitData = sampleFormat.drmInitData;
    }
    if (drmInitData == null) {
      return null;
    }
  }
  blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, null, drmInitData);
  return drmSessionManager.getOfflineLicenseKeySetId();
}
项目:K-Sonic    文件:OfflineLicenseHelper.java   
/**
 * Returns license and playback durations remaining in seconds of the given offline license.
 *
 * @param offlineLicenseKeySetId The key set id of the license.
 */
public Pair<Long, Long> getLicenseDurationRemainingSec(byte[] offlineLicenseKeySetId)
    throws DrmSessionException {
  Assertions.checkNotNull(offlineLicenseKeySetId);
  DrmSession<T> session = openBlockingKeyRequest(DefaultDrmSessionManager.MODE_QUERY,
      offlineLicenseKeySetId, null);
  Pair<Long, Long> licenseDurationRemainingSec =
      WidevineUtil.getLicenseDurationRemainingSec(drmSessionManager);
  drmSessionManager.releaseSession(session);
  return licenseDurationRemainingSec;
}
项目:K-Sonic    文件:OfflineLicenseHelper.java   
private void blockingKeyRequest(@Mode int licenseMode, byte[] offlineLicenseKeySetId,
    DrmInitData drmInitData) throws DrmSessionException {
  DrmSession<T> session = openBlockingKeyRequest(licenseMode, offlineLicenseKeySetId,
      drmInitData);
  DrmSessionException error = session.getError();
  if (error != null) {
    throw error;
  }
  drmSessionManager.releaseSession(session);
}
项目:transistor    文件:DashWidevineOfflineTest.java   
private void downloadLicense() throws InterruptedException, DrmSessionException, IOException {
  DataSource dataSource = httpDataSourceFactory.createDataSource();
  DashManifest dashManifest = DashUtil.loadManifest(dataSource,
      Uri.parse(DashTestData.WIDEVINE_H264_MANIFEST));
  DrmInitData drmInitData = DashUtil.loadDrmInitData(dataSource, dashManifest.getPeriod(0));
  offlineLicenseKeySetId = offlineLicenseHelper.downloadLicense(drmInitData);
  Assert.assertNotNull(offlineLicenseKeySetId);
  Assert.assertTrue(offlineLicenseKeySetId.length > 0);
  testRunner.setOfflineLicenseKeySetId(offlineLicenseKeySetId);
}
项目:transistor    文件:LibvpxVideoRenderer.java   
private void maybeInitDecoder() throws ExoPlaybackException {
  if (decoder != null) {
    return;
  }

  drmSession = pendingDrmSession;
  ExoMediaCrypto mediaCrypto = null;
  if (drmSession != null) {
    mediaCrypto = drmSession.getMediaCrypto();
    if (mediaCrypto == null) {
      DrmSessionException drmError = drmSession.getError();
      if (drmError != null) {
        throw ExoPlaybackException.createForRenderer(drmError, getIndex());
      }
      // The drm session isn't open yet.
      return;
    }
  }

  try {
    long codecInitializingTimestamp = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("createVpxDecoder");
    decoder = new VpxDecoder(NUM_INPUT_BUFFERS, NUM_OUTPUT_BUFFERS, INITIAL_INPUT_BUFFER_SIZE,
        mediaCrypto);
    decoder.setOutputMode(outputMode);
    TraceUtil.endSection();
    long codecInitializedTimestamp = SystemClock.elapsedRealtime();
    eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp,
        codecInitializedTimestamp - codecInitializingTimestamp);
    decoderCounters.decoderInitCount++;
  } catch (VpxDecoderException e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }
}
项目:transistor    文件:OfflineLicenseHelper.java   
private byte[] blockingKeyRequest(@Mode int licenseMode, byte[] offlineLicenseKeySetId,
    DrmInitData drmInitData) throws DrmSessionException {
  DrmSession<T> drmSession = openBlockingKeyRequest(licenseMode, offlineLicenseKeySetId,
      drmInitData);
  DrmSessionException error = drmSession.getError();
  byte[] keySetId = drmSession.getOfflineLicenseKeySetId();
  drmSessionManager.releaseSession(drmSession);
  if (error != null) {
    throw error;
  }
  return keySetId;
}
项目:transistor    文件:SimpleDecoderAudioRenderer.java   
private void maybeInitDecoder() throws ExoPlaybackException {
  if (decoder != null) {
    return;
  }

  drmSession = pendingDrmSession;
  ExoMediaCrypto mediaCrypto = null;
  if (drmSession != null) {
    mediaCrypto = drmSession.getMediaCrypto();
    if (mediaCrypto == null) {
      DrmSessionException drmError = drmSession.getError();
      if (drmError != null) {
        throw ExoPlaybackException.createForRenderer(drmError, getIndex());
      }
      // 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());
  }
}
项目:ExoPlayer-Offline    文件:DashTest.java   
public void renewLicense() throws DrmSessionException {
  assertNotNull(offlineLicenseKeySetId);
  offlineLicenseKeySetId = offlineLicenseHelper.renew(offlineLicenseKeySetId);
  assertNotNull(offlineLicenseKeySetId);
}
项目:ExoPlayer-Offline    文件:DashTest.java   
public void releaseLicense() throws DrmSessionException {
  assertNotNull(offlineLicenseKeySetId);
  offlineLicenseHelper.release(offlineLicenseKeySetId);
  offlineLicenseKeySetId = null;
}
项目:ExoPlayer-Offline    文件:DashTest.java   
public Pair<Long, Long> getLicenseDurationRemainingSec() throws DrmSessionException {
  return offlineLicenseHelper.getLicenseDurationRemainingSec(offlineLicenseKeySetId);
}
项目:transistor    文件:DashWidevineOfflineTest.java   
private void releaseLicense() throws DrmSessionException {
  offlineLicenseHelper.releaseLicense(offlineLicenseKeySetId);
  offlineLicenseKeySetId = null;
}
项目:transistor    文件:DefaultDrmSessionManager.java   
@Override
public DrmSession<T> acquireSession(Looper playbackLooper, DrmInitData drmInitData) {
  Assertions.checkState(this.playbackLooper == null || this.playbackLooper == playbackLooper);
  if (sessions.isEmpty()) {
    this.playbackLooper = playbackLooper;
    if (mediaDrmHandler == null) {
      mediaDrmHandler = new MediaDrmHandler(playbackLooper);
    }
  }

  byte[] initData = null;
  String mimeType = null;
  if (offlineLicenseKeySetId == null) {
    SchemeData data = getSchemeData(drmInitData, uuid, false);
    if (data == null) {
      final IllegalStateException error = new IllegalStateException(
          "Media does not support uuid: " + uuid);
      if (eventHandler != null && eventListener != null) {
        eventHandler.post(new Runnable() {
          @Override
          public void run() {
            eventListener.onDrmSessionManagerError(error);
          }
        });
      }
      return new ErrorStateDrmSession<>(new DrmSessionException(error));
    }
    initData = getSchemeInitData(data, uuid);
    mimeType = getSchemeMimeType(data, uuid);
  }

  DefaultDrmSession<T> session;
  if (!multiSession) {
    session = sessions.isEmpty() ? null : sessions.get(0);
  } else {
    // Only use an existing session if it has matching init data.
    session = null;
    for (DefaultDrmSession<T> existingSession : sessions) {
      if (existingSession.hasInitData(initData)) {
        session = existingSession;
        break;
      }
    }
  }

  if (session == null) {
    // Create a new session.
    session = new DefaultDrmSession<>(uuid, mediaDrm, this, initData, mimeType, mode,
        offlineLicenseKeySetId, optionalKeyRequestParameters, callback, playbackLooper,
        eventHandler, eventListener, initialDrmRequestRetryCount);
    sessions.add(session);
  }
  session.acquire();
  return session;
}
项目:Exoplayer2Radio    文件:OfflineLicenseHelper.java   
/**
 * Downloads an offline license.
 *
 * @param drmInitData The {@link DrmInitData} for the content whose license is to be downloaded.
 * @return The key set id for the downloaded license.
 * @throws IOException If an error occurs reading data from the stream.
 * @throws InterruptedException If the thread has been interrupted.
 * @throws DrmSessionException Thrown when a DRM session error occurs.
 */
public synchronized byte[] downloadLicense(DrmInitData drmInitData) throws IOException,
    InterruptedException, DrmSessionException {
  Assertions.checkArgument(drmInitData != null);
  return blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, null, drmInitData);
}
项目:Exoplayer2Radio    文件:OfflineLicenseHelper.java   
/**
 * Renews an offline license.
 *
 * @param offlineLicenseKeySetId The key set id of the license to be renewed.
 * @return The renewed offline license key set id.
 * @throws DrmSessionException Thrown when a DRM session error occurs.
 */
public synchronized byte[] renewLicense(byte[] offlineLicenseKeySetId)
    throws DrmSessionException {
  Assertions.checkNotNull(offlineLicenseKeySetId);
  return blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, offlineLicenseKeySetId, null);
}
项目:Exoplayer2Radio    文件:OfflineLicenseHelper.java   
/**
 * Releases an offline license.
 *
 * @param offlineLicenseKeySetId The key set id of the license to be released.
 * @throws DrmSessionException Thrown when a DRM session error occurs.
 */
public synchronized void releaseLicense(byte[] offlineLicenseKeySetId)
    throws DrmSessionException {
  Assertions.checkNotNull(offlineLicenseKeySetId);
  blockingKeyRequest(DefaultDrmSessionManager.MODE_RELEASE, offlineLicenseKeySetId, null);
}
项目:K-Sonic    文件:OfflineLicenseHelper.java   
/**
 * Downloads an offline license.
 *
 * @param dataSource The {@link HttpDataSource} to be used for download.
 * @param manifestUriString The URI of the manifest to be read.
 * @return The downloaded offline license key set id.
 * @throws IOException If an error occurs reading data from the stream.
 * @throws InterruptedException If the thread has been interrupted.
 * @throws DrmSessionException Thrown when there is an error during DRM session.
 */
public byte[] download(HttpDataSource dataSource, String manifestUriString)
    throws IOException, InterruptedException, DrmSessionException {
  return download(dataSource, DashUtil.loadManifest(dataSource, manifestUriString));
}
项目:K-Sonic    文件:OfflineLicenseHelper.java   
/**
 * Renews an offline license.
 *
 * @param offlineLicenseKeySetId The key set id of the license to be renewed.
 * @return Renewed offline license key set id.
 * @throws DrmSessionException Thrown when there is an error during DRM session.
 */
public byte[] renew(byte[] offlineLicenseKeySetId) throws DrmSessionException {
  Assertions.checkNotNull(offlineLicenseKeySetId);
  blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, offlineLicenseKeySetId, null);
  return drmSessionManager.getOfflineLicenseKeySetId();
}
项目:K-Sonic    文件:OfflineLicenseHelper.java   
/**
 * Releases an offline license.
 *
 * @param offlineLicenseKeySetId The key set id of the license to be released.
 * @throws DrmSessionException Thrown when there is an error during DRM session.
 */
public void release(byte[] offlineLicenseKeySetId) throws DrmSessionException {
  Assertions.checkNotNull(offlineLicenseKeySetId);
  blockingKeyRequest(DefaultDrmSessionManager.MODE_RELEASE, offlineLicenseKeySetId, null);
}
项目:transistor    文件:OfflineLicenseHelper.java   
/**
 * Downloads an offline license.
 *
 * @param drmInitData The {@link DrmInitData} for the content whose license is to be downloaded.
 * @return The key set id for the downloaded license.
 * @throws DrmSessionException Thrown when a DRM session error occurs.
 */
public synchronized byte[] downloadLicense(DrmInitData drmInitData) throws DrmSessionException {
  Assertions.checkArgument(drmInitData != null);
  return blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, null, drmInitData);
}
项目:transistor    文件:OfflineLicenseHelper.java   
/**
 * Renews an offline license.
 *
 * @param offlineLicenseKeySetId The key set id of the license to be renewed.
 * @return The renewed offline license key set id.
 * @throws DrmSessionException Thrown when a DRM session error occurs.
 */
public synchronized byte[] renewLicense(byte[] offlineLicenseKeySetId)
    throws DrmSessionException {
  Assertions.checkNotNull(offlineLicenseKeySetId);
  return blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, offlineLicenseKeySetId, null);
}
项目:transistor    文件:OfflineLicenseHelper.java   
/**
 * Releases an offline license.
 *
 * @param offlineLicenseKeySetId The key set id of the license to be released.
 * @throws DrmSessionException Thrown when a DRM session error occurs.
 */
public synchronized void releaseLicense(byte[] offlineLicenseKeySetId)
    throws DrmSessionException {
  Assertions.checkNotNull(offlineLicenseKeySetId);
  blockingKeyRequest(DefaultDrmSessionManager.MODE_RELEASE, offlineLicenseKeySetId, null);
}