Java Code Examples for com.google.android.exoplayer2.drm.DrmSession#STATE_OPENED_WITH_KEYS

The following examples show how to use com.google.android.exoplayer2.drm.DrmSession#STATE_OPENED_WITH_KEYS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleDecoderAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: SimpleDecoderAudioRenderer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (decoderDrmSession == null || (!bufferEncrypted && playClearSamplesWithoutKeys)) {
    return false;
  }
  @DrmSession.State int drmSessionState = decoderDrmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(decoderDrmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS;
}
 
Example 3
Source File: MediaCodecRenderer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (codecDrmSession == null || (!bufferEncrypted && playClearSamplesWithoutKeys)) {
    return false;
  }
  @DrmSession.State int drmSessionState = codecDrmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(codecDrmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS;
}
 
Example 4
Source File: SimpleDecoderAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (decoderDrmSession == null || (!bufferEncrypted && playClearSamplesWithoutKeys)) {
    return false;
  }
  @DrmSession.State int drmSessionState = decoderDrmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(decoderDrmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS;
}
 
Example 5
Source File: MediaCodecRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (codecDrmSession == null || (!bufferEncrypted && playClearSamplesWithoutKeys)) {
    return false;
  }
  @DrmSession.State int drmSessionState = codecDrmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(codecDrmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS;
}
 
Example 6
Source File: SimpleDecoderAudioRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
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());
  }
}
 
Example 7
Source File: SimpleDecoderAudioRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
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);
}
 
Example 8
Source File: MediaCodecRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
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);
}
 
Example 9
Source File: SoftVideoRenderer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
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;
}
 
Example 10
Source File: SampleMetadataQueue.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether it's possible to read the next sample.
 *
 * @param relativeReadIndex The relative read index of the next sample.
 * @return Whether it's possible to read the next sample.
 */
private boolean mayReadSample(int relativeReadIndex) {
  if (drmSessionManager == DrmSessionManager.DUMMY) {
    // TODO: Remove once renderers are migrated [Internal ref: b/122519809].
    // For protected content it's likely that the DrmSessionManager is still being injected into
    // the renderers. We assume that the renderers will be able to acquire a DrmSession if needed.
    return true;
  }
  return currentDrmSession == null
      || currentDrmSession.getState() == DrmSession.STATE_OPENED_WITH_KEYS
      || ((flags[relativeReadIndex] & C.BUFFER_FLAG_ENCRYPTED) == 0
          && currentDrmSession.playClearSamplesWithoutKeys());
}
 
Example 11
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: SimpleDecoderAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 13
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: SimpleDecoderVideoRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (decoderDrmSession == null
      || (!bufferEncrypted
          && (playClearSamplesWithoutKeys || decoderDrmSession.playClearSamplesWithoutKeys()))) {
    return false;
  }
  @DrmSession.State int drmSessionState = decoderDrmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw createRendererException(decoderDrmSession.getError(), inputFormat);
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS;
}
 
Example 15
Source File: SimpleDecoderAudioRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (decoderDrmSession == null
      || (!bufferEncrypted
          && (playClearSamplesWithoutKeys || decoderDrmSession.playClearSamplesWithoutKeys()))) {
    return false;
  }
  @DrmSession.State int drmSessionState = decoderDrmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw createRendererException(decoderDrmSession.getError(), inputFormat);
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS;
}
 
Example 16
Source File: MediaCodecRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (codecDrmSession == null
      || (!bufferEncrypted
          && (playClearSamplesWithoutKeys || codecDrmSession.playClearSamplesWithoutKeys()))) {
    return false;
  }
  @DrmSession.State int drmSessionState = codecDrmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw createRendererException(codecDrmSession.getError(), inputFormat);
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS;
}
 
Example 17
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
protected final void maybeInitCodec() throws ExoPlaybackException {
  if (codec != null || format == null) {
    // We have a codec already, or we don't have a format with which to instantiate one.
    return;
  }

  drmSession = pendingDrmSession;
  String mimeType = format.sampleMimeType;
  MediaCrypto wrappedMediaCrypto = null;
  boolean drmSessionRequiresSecureDecoder = false;
  if (drmSession != null) {
    FrameworkMediaCrypto mediaCrypto = drmSession.getMediaCrypto();
    if (mediaCrypto == null) {
      DrmSessionException drmError = drmSession.getError();
      if (drmError != null) {
        // Continue for now. We may be able to avoid failure if the session recovers, or if a new
        // input format causes the session to be replaced before it's used.
      } else {
        // The drm session isn't open yet.
        return;
      }
    } else {
      wrappedMediaCrypto = mediaCrypto.getWrappedMediaCrypto();
      drmSessionRequiresSecureDecoder = mediaCrypto.requiresSecureDecoderComponent(mimeType);
    }
    if (deviceNeedsDrmKeysToConfigureCodecWorkaround()) {
      @DrmSession.State int drmSessionState = drmSession.getState();
      if (drmSessionState == DrmSession.STATE_ERROR) {
        throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
      } else if (drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS) {
        // Wait for keys.
        return;
      }
    }
  }

  try {
    if (!initCodecWithFallback(wrappedMediaCrypto, drmSessionRequiresSecureDecoder)) {
      // We can't initialize a codec yet.
      return;
    }
  } catch (DecoderInitializationException e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }

  String codecName = codecInfo.name;
  codecAdaptationWorkaroundMode = codecAdaptationWorkaroundMode(codecName);
  codecNeedsDiscardToSpsWorkaround = codecNeedsDiscardToSpsWorkaround(codecName, format);
  codecNeedsFlushWorkaround = codecNeedsFlushWorkaround(codecName);
  codecNeedsEosPropagationWorkaround = codecNeedsEosPropagationWorkaround(codecInfo);
  codecNeedsEosFlushWorkaround = codecNeedsEosFlushWorkaround(codecName);
  codecNeedsEosOutputExceptionWorkaround = codecNeedsEosOutputExceptionWorkaround(codecName);
  codecNeedsMonoChannelCountWorkaround = codecNeedsMonoChannelCountWorkaround(codecName, format);
  codecHotswapDeadlineMs =
      getState() == STATE_STARTED
          ? (SystemClock.elapsedRealtime() + MAX_CODEC_HOTSWAP_TIME_MS)
          : C.TIME_UNSET;
  resetInputBuffer();
  resetOutputBuffer();
  waitingForFirstSyncFrame = true;
  decoderCounters.decoderInitCount++;
}
 
Example 18
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
protected final void maybeInitCodec() throws ExoPlaybackException {
  if (codec != null || format == null) {
    // We have a codec already, or we don't have a format with which to instantiate one.
    return;
  }

  drmSession = pendingDrmSession;
  String mimeType = format.sampleMimeType;
  MediaCrypto wrappedMediaCrypto = null;
  boolean drmSessionRequiresSecureDecoder = false;
  if (drmSession != null) {
    FrameworkMediaCrypto mediaCrypto = drmSession.getMediaCrypto();
    if (mediaCrypto == null) {
      DrmSessionException drmError = drmSession.getError();
      if (drmError != null) {
        // Continue for now. We may be able to avoid failure if the session recovers, or if a new
        // input format causes the session to be replaced before it's used.
      } else {
        // The drm session isn't open yet.
        return;
      }
    } else {
      wrappedMediaCrypto = mediaCrypto.getWrappedMediaCrypto();
      drmSessionRequiresSecureDecoder = mediaCrypto.requiresSecureDecoderComponent(mimeType);
    }
    if (deviceNeedsDrmKeysToConfigureCodecWorkaround()) {
      @DrmSession.State int drmSessionState = drmSession.getState();
      if (drmSessionState == DrmSession.STATE_ERROR) {
        throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
      } else if (drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS) {
        // Wait for keys.
        return;
      }
    }
  }

  try {
    if (!initCodecWithFallback(wrappedMediaCrypto, drmSessionRequiresSecureDecoder)) {
      // We can't initialize a codec yet.
      return;
    }
  } catch (DecoderInitializationException e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }

  String codecName = codecInfo.name;
  codecAdaptationWorkaroundMode = codecAdaptationWorkaroundMode(codecName);
  codecNeedsDiscardToSpsWorkaround = codecNeedsDiscardToSpsWorkaround(codecName, format);
  codecNeedsFlushWorkaround = codecNeedsFlushWorkaround(codecName);
  codecNeedsEosPropagationWorkaround = codecNeedsEosPropagationWorkaround(codecInfo);
  codecNeedsEosFlushWorkaround = codecNeedsEosFlushWorkaround(codecName);
  codecNeedsEosOutputExceptionWorkaround = codecNeedsEosOutputExceptionWorkaround(codecName);
  codecNeedsMonoChannelCountWorkaround = codecNeedsMonoChannelCountWorkaround(codecName, format);
  codecHotswapDeadlineMs =
      getState() == STATE_STARTED
          ? (SystemClock.elapsedRealtime() + MAX_CODEC_HOTSWAP_TIME_MS)
          : C.TIME_UNSET;
  resetInputBuffer();
  resetOutputBuffer();
  waitingForFirstSyncFrame = true;
  decoderCounters.decoderInitCount++;
}