com.google.android.exoplayer.drm.DrmSessionManager Java Examples

The following examples show how to use com.google.android.exoplayer.drm.DrmSessionManager. 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: MediaCodecTrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted media. May be null if support for encrypted
 *     media is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 */
public MediaCodecTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys, Handler eventHandler, EventListener eventListener) {
  Assertions.checkState(Util.SDK_INT >= 16);
  this.source = source;
  this.drmSessionManager = drmSessionManager;
  this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
  this.eventHandler = eventHandler;
  this.eventListener = eventListener;
  codecCounters = new CodecCounters();
  sampleHolder = new SampleHolder(SampleHolder.BUFFER_REPLACEMENT_MODE_DISABLED);
  formatHolder = new MediaFormatHolder();
  decodeOnlyPresentationTimestamps = new ArrayList<Long>();
  outputBufferInfo = new MediaCodec.BufferInfo();

}
 
Example #2
Source File: MediaCodecTrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
private boolean shouldWaitForKeys(boolean sampleEncrypted) throws ExoPlaybackException {
  if (!openedDrmSession) {
    return false;
  }
  int drmManagerState = drmSessionManager.getState();
  if (drmManagerState == DrmSessionManager.STATE_ERROR) {
    throw new ExoPlaybackException(drmSessionManager.getError());
  }
  if (drmManagerState != DrmSessionManager.STATE_OPENED_WITH_KEYS &&
      (sampleEncrypted || !playClearSamplesWithoutKeys)) {
    return true;
  }
  return false;
}
 
Example #3
Source File: DashVodRendererBuilder.java    From Mobilyzer with Apache License 2.0 5 votes vote down vote up
public static Pair<DrmSessionManager, Boolean> getDrmSessionManagerData(DemoPlayer player,
    MediaDrmCallback drmCallback) throws UnsupportedSchemeException {
  StreamingDrmSessionManager streamingDrmSessionManager = new StreamingDrmSessionManager(
      DemoUtil.WIDEVINE_UUID, player.getPlaybackLooper(), drmCallback, player.getMainHandler(),
      player);
  return Pair.create((DrmSessionManager) streamingDrmSessionManager,
      getWidevineSecurityLevel(streamingDrmSessionManager) == SECURITY_LEVEL_1);
}
 
Example #4
Source File: SmoothStreamingRendererBuilder.java    From ShareBox with Apache License 2.0 4 votes vote down vote up
@Override
public void onSingleManifest(SmoothStreamingManifest manifest) {
  if (canceled) {
    return;
  }

  Handler mainHandler = player.getMainHandler();
  LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
  DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player);

  // Check drm support if necessary.
  DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
  if (manifest.protectionElement != null) {
    if (Util.SDK_INT < 18) {
      player.onRenderersError(
          new UnsupportedDrmException(UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME));
      return;
    }
    try {
      drmSessionManager = StreamingDrmSessionManager.newFrameworkInstance(
          manifest.protectionElement.uuid, player.getPlaybackLooper(), drmCallback, null,
          player.getMainHandler(), player);
    } catch (UnsupportedDrmException e) {
      player.onRenderersError(e);
      return;
    }
  }

  // Build the video renderer.
  DataSource videoDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource videoChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
      DefaultSmoothStreamingTrackSelector.newVideoInstance(context, true, false),
      videoDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS);
  ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
      VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_VIDEO);
  TrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context, videoSampleSource,
      MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
      drmSessionManager, true, mainHandler, player, 50);

  // Build the audio renderer.
  DataSource audioDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource audioChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
      DefaultSmoothStreamingTrackSelector.newAudioInstance(),
      audioDataSource, null, LIVE_EDGE_LATENCY_MS);
  ChunkSampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
      AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_AUDIO);
  TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource,
      MediaCodecSelector.DEFAULT, drmSessionManager, true, mainHandler, player,
      AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);

  // Build the text renderer.
  DataSource textDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource textChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
      DefaultSmoothStreamingTrackSelector.newTextInstance(),
      textDataSource, null, LIVE_EDGE_LATENCY_MS);
  ChunkSampleSource textSampleSource = new ChunkSampleSource(textChunkSource, loadControl,
      TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_TEXT);
  TrackRenderer textRenderer = new TextTrackRenderer(textSampleSource, player,
      mainHandler.getLooper());

  // Invoke the callback.
  TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
  player.onRenderers(renderers, bandwidthMeter);
}
 
Example #5
Source File: MediaCodecVideoTrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 4 votes vote down vote up
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted content. May be null if support for encrypted
 *     content is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 * @param videoScalingMode The scaling mode to pass to
 *     {@link MediaCodec#setVideoScalingMode(int)}.
 * @param allowedJoiningTimeMs The maximum duration in milliseconds for which this video renderer
 *     can attempt to seamlessly join an ongoing playback.
 * @param frameReleaseTimeHelper An optional helper to make fine-grained adjustments to frame
 *     release times. May be null.
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param maxDroppedFrameCountToNotify The maximum number of frames that can be dropped between
 *     invocations of {@link EventListener#onDroppedFrames(int, long)}.
 */
public MediaCodecVideoTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys, int videoScalingMode, long allowedJoiningTimeMs,
    FrameReleaseTimeHelper frameReleaseTimeHelper, Handler eventHandler,
    EventListener eventListener, int maxDroppedFrameCountToNotify) {
  super(source, drmSessionManager, playClearSamplesWithoutKeys, eventHandler, eventListener);
  this.videoScalingMode = videoScalingMode;
  this.allowedJoiningTimeUs = allowedJoiningTimeMs * 1000;
  this.frameReleaseTimeHelper = frameReleaseTimeHelper;
  this.eventListener = eventListener;
  this.maxDroppedFrameCountToNotify = maxDroppedFrameCountToNotify;
  joiningDeadlineUs = -1;
  currentWidth = -1;
  currentHeight = -1;
  currentPixelWidthHeightRatio = -1;
  lastReportedWidth = -1;
  lastReportedHeight = -1;
  lastReportedPixelWidthHeightRatio = -1;

}
 
Example #6
Source File: SmoothStreamingRendererBuilder.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
@Override
public void onSingleManifest(SmoothStreamingManifest manifest) {
    if (canceled) {
        return;
    }

    Handler mainHandler = player.getMainHandler();
    LoadControl loadControl =
            new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player);

    // Check drm support if necessary.
    DrmSessionManager drmSessionManager = null;
    if (manifest.protectionElement != null) {
        if (Util.SDK_INT < 18) {
            player.onRenderersError(new UnsupportedDrmException(
                    UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME));
            return;
        }
        try {
            drmSessionManager =  StreamingDrmSessionManager.newFrameworkInstance(
                    manifest.protectionElement.uuid, player.getPlaybackLooper(),
                    drmCallback, null, player.getMainHandler(), player);
        } catch (UnsupportedDrmException e) {
            player.onRenderersError(e);
            return;
        }
    }

    // Build the video renderer.
    DataSource videoDataSource =
            new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ChunkSource videoChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
            DefaultSmoothStreamingTrackSelector.newVideoInstance(context, true, false),
            videoDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS);
    ChunkSampleSource videoSampleSource =
            new ChunkSampleSource(videoChunkSource, loadControl,
                    VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
                    DemoPlayer.TYPE_VIDEO);
    TrackRenderer videoRenderer =
            new MediaCodecVideoTrackRenderer(context, videoSampleSource,
                    MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT,
                    5000, drmSessionManager, true, mainHandler, player, 50);

    // Build the audio renderer.
    DataSource audioDataSource =
            new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ChunkSource audioChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
            DefaultSmoothStreamingTrackSelector.newAudioInstance(),
            audioDataSource, null, LIVE_EDGE_LATENCY_MS);
    ChunkSampleSource audioSampleSource =
            new ChunkSampleSource(audioChunkSource, loadControl,
                    AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
                    DemoPlayer.TYPE_AUDIO);
    TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource,
            MediaCodecSelector.DEFAULT, drmSessionManager, true, mainHandler, player,
            AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);

    // Build the text renderer.
    DataSource textDataSource =
            new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ChunkSource textChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
            DefaultSmoothStreamingTrackSelector.newTextInstance(),
            textDataSource, null, LIVE_EDGE_LATENCY_MS);
    ChunkSampleSource textSampleSource = new ChunkSampleSource(textChunkSource, loadControl,
            TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
            DemoPlayer.TYPE_TEXT);
    TrackRenderer textRenderer = new TextTrackRenderer(textSampleSource, player,
            mainHandler.getLooper());

    // Invoke the callback.
    TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
    renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
    renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
    renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
    player.onRenderers(renderers, bandwidthMeter);
}
 
Example #7
Source File: MediaCodecAudioTrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 3 votes vote down vote up
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted content. May be null if support for encrypted
 *     content is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 */
public MediaCodecAudioTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys, Handler eventHandler, EventListener eventListener) {
  super(source, drmSessionManager, playClearSamplesWithoutKeys, eventHandler, eventListener);
  this.eventListener = eventListener;
  this.audioSessionId = AudioTrack.SESSION_ID_NOT_SET;
  this.audioTrack = new AudioTrack();
}
 
Example #8
Source File: MediaCodecVideoTrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 2 votes vote down vote up
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted content. May be null if support for encrypted
 *     content is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 * @param videoScalingMode The scaling mode to pass to
 *     {@link MediaCodec#setVideoScalingMode(int)}.
 */
public MediaCodecVideoTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys, int videoScalingMode) {
  this(source, drmSessionManager, playClearSamplesWithoutKeys, videoScalingMode, 0);
}
 
Example #9
Source File: MediaCodecVideoTrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 2 votes vote down vote up
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted content. May be null if support for encrypted
 *     content is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 * @param videoScalingMode The scaling mode to pass to
 *     {@link MediaCodec#setVideoScalingMode(int)}.
 * @param allowedJoiningTimeMs The maximum duration in milliseconds for which this video renderer
 *     can attempt to seamlessly join an ongoing playback.
 */
public MediaCodecVideoTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys, int videoScalingMode, long allowedJoiningTimeMs) {
  this(source, drmSessionManager, playClearSamplesWithoutKeys, videoScalingMode,
      allowedJoiningTimeMs, null, null, null, -1);
}
 
Example #10
Source File: MediaCodecAudioTrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 2 votes vote down vote up
/**
 * @param source The upstream source from which the renderer obtains samples.
 * @param drmSessionManager For use with encrypted content. May be null if support for encrypted
 *     content is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisision. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 */
public MediaCodecAudioTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
    boolean playClearSamplesWithoutKeys) {
  this(source, drmSessionManager, playClearSamplesWithoutKeys, null, null);
}