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

The following examples show how to use com.google.android.exoplayer2.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: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param trackType The track type that the renderer handles. One of the {@code C.TRACK_TYPE_*}
 *     constants defined in {@link C}.
 * @param mediaCodecSelector A decoder selector.
 * @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 acquisition. 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 assumedMinimumCodecOperatingRate A codec operating rate that all codecs instantiated by
 *     this renderer are assumed to meet implicitly (i.e. without the operating rate being set
 *     explicitly using {@link MediaFormat#KEY_OPERATING_RATE}).
 */
public MediaCodecRenderer(
    int trackType,
    MediaCodecSelector mediaCodecSelector,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    float assumedMinimumCodecOperatingRate) {
  super(trackType);
  Assertions.checkState(Util.SDK_INT >= 16);
  this.mediaCodecSelector = Assertions.checkNotNull(mediaCodecSelector);
  this.drmSessionManager = drmSessionManager;
  this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
  this.assumedMinimumCodecOperatingRate = assumedMinimumCodecOperatingRate;
  buffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
  flagsOnlyBuffer = DecoderInputBuffer.newFlagsOnlyInstance();
  formatHolder = new FormatHolder();
  decodeOnlyPresentationTimestamps = new ArrayList<>();
  outputBufferInfo = new MediaCodec.BufferInfo();
  codecReconfigurationState = RECONFIGURATION_STATE_NONE;
  codecReinitializationState = REINITIALIZATION_STATE_NONE;
  codecOperatingRate = CODEC_OPERATING_RATE_UNSET;
  rendererOperatingRate = 1f;
}
 
Example #2
Source File: DefaultRenderersFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Renderer[] createRenderers(
    Handler eventHandler,
    VideoRendererEventListener videoRendererEventListener,
    AudioRendererEventListener audioRendererEventListener,
    TextOutput textRendererOutput,
    MetadataOutput metadataRendererOutput,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  if (drmSessionManager == null) {
    drmSessionManager = this.drmSessionManager;
  }
  ArrayList<Renderer> renderersList = new ArrayList<>();
  buildVideoRenderers(context, drmSessionManager, allowedVideoJoiningTimeMs,
      eventHandler, videoRendererEventListener, extensionRendererMode, renderersList);
  buildAudioRenderers(context, drmSessionManager, buildAudioProcessors(),
      eventHandler, audioRendererEventListener, extensionRendererMode, renderersList);
  buildTextRenderers(context, textRendererOutput, eventHandler.getLooper(),
      extensionRendererMode, renderersList);
  buildMetadataRenderers(context, metadataRendererOutput, eventHandler.getLooper(),
      extensionRendererMode, renderersList);
  buildMiscellaneousRenderers(context, eventHandler, extensionRendererMode, renderersList);
  return renderersList.toArray(new Renderer[renderersList.size()]);
}
 
Example #3
Source File: ExoPlayerFactory.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
 *     be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
 *     MediaSource} factories.
 */
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter) {
  return newSimpleInstance(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      new AnalyticsCollector(Clock.DEFAULT),
      Util.getLooper());
}
 
Example #4
Source File: DownloadHelper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link DownloadHelper} for SmoothStreaming streams.
 *
 * @param uri A manifest {@link Uri}.
 * @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest.
 * @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
 *     selected.
 * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers created by
 *     {@code renderersFactory}.
 * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for
 *     downloading.
 * @return A {@link DownloadHelper} for SmoothStreaming streams.
 * @throws IllegalStateException If the SmoothStreaming module is missing.
 */
public static DownloadHelper forSmoothStreaming(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    RenderersFactory renderersFactory,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    DefaultTrackSelector.Parameters trackSelectorParameters) {
  return new DownloadHelper(
      DownloadRequest.TYPE_SS,
      uri,
      /* cacheKey= */ null,
      createMediaSourceInternal(
          SS_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null),
      trackSelectorParameters,
      Util.getRendererCapabilities(renderersFactory, drmSessionManager));
}
 
Example #5
Source File: DownloadHelper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link DownloadHelper} for HLS streams.
 *
 * @param uri A playlist {@link Uri}.
 * @param dataSourceFactory A {@link DataSource.Factory} used to load the playlist.
 * @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
 *     selected.
 * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers created by
 *     {@code renderersFactory}.
 * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for
 *     downloading.
 * @return A {@link DownloadHelper} for HLS streams.
 * @throws IllegalStateException If the HLS module is missing.
 */
public static DownloadHelper forHls(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    RenderersFactory renderersFactory,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    DefaultTrackSelector.Parameters trackSelectorParameters) {
  return new DownloadHelper(
      DownloadRequest.TYPE_HLS,
      uri,
      /* cacheKey= */ null,
      createMediaSourceInternal(
          HLS_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null),
      trackSelectorParameters,
      Util.getRendererCapabilities(renderersFactory, drmSessionManager));
}
 
Example #6
Source File: SimpleExoPlayer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Looper looper) {
  this(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      analyticsCollectorFactory,
      Clock.DEFAULT,
      looper);
}
 
Example #7
Source File: SimpleExoPlayer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollector A factory for creating the {@link AnalyticsCollector} that will
 *     collect and forward all player events.
 * @param clock The {@link Clock} that will be used by the instance. Should always be {@link
 *     Clock#DEFAULT}, unless the player is being used from a test.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
@SuppressWarnings("deprecation")
protected SimpleExoPlayer(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector analyticsCollector,
    Clock clock,
    Looper looper) {
  this(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      DrmSessionManager.getDummyDrmSessionManager(),
      bandwidthMeter,
      analyticsCollector,
      clock,
      looper);
}
 
Example #8
Source File: MediaCodecAudioRenderer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context A context.
 * @param mediaCodecSelector A decoder selector.
 * @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 acquisition. 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 MediaCodecAudioRenderer(
    Context context,
    MediaCodecSelector mediaCodecSelector,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener) {
  this(
      context,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      eventHandler,
      eventListener,
      (AudioCapabilities) null);
}
 
Example #9
Source File: MediaCodecVideoRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context A context.
 * @param mediaCodecSelector A decoder selector.
 * @param allowedJoiningTimeMs The maximum duration in milliseconds for which this video renderer
 *     can attempt to seamlessly join an ongoing playback.
 * @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 acquisition. 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.
 * @param maxDroppedFramesToNotify The maximum number of frames that can be dropped between
 *     invocations of {@link VideoRendererEventListener#onDroppedFrames(int, long)}.
 */
public MediaCodecVideoRenderer(
    Context context,
    MediaCodecSelector mediaCodecSelector,
    long allowedJoiningTimeMs,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    @Nullable Handler eventHandler,
    @Nullable VideoRendererEventListener eventListener,
    int maxDroppedFramesToNotify) {
  this(
      context,
      mediaCodecSelector,
      allowedJoiningTimeMs,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      /* enableDecoderFallback= */ false,
      eventHandler,
      eventListener,
      maxDroppedFramesToNotify);
}
 
Example #10
Source File: DefaultRenderersFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Renderer[] createRenderers(
    Handler eventHandler,
    VideoRendererEventListener videoRendererEventListener,
    AudioRendererEventListener audioRendererEventListener,
    TextOutput textRendererOutput,
    MetadataOutput metadataRendererOutput,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  if (drmSessionManager == null) {
    drmSessionManager = this.drmSessionManager;
  }
  ArrayList<Renderer> renderersList = new ArrayList<>();
  buildVideoRenderers(context, drmSessionManager, allowedVideoJoiningTimeMs,
      eventHandler, videoRendererEventListener, extensionRendererMode, renderersList);
  buildAudioRenderers(context, drmSessionManager, buildAudioProcessors(),
      eventHandler, audioRendererEventListener, extensionRendererMode, renderersList);
  buildTextRenderers(context, textRendererOutput, eventHandler.getLooper(),
      extensionRendererMode, renderersList);
  buildMetadataRenderers(context, metadataRendererOutput, eventHandler.getLooper(),
      extensionRendererMode, renderersList);
  buildMiscellaneousRenderers(context, eventHandler, extensionRendererMode, renderersList);
  return renderersList.toArray(new Renderer[renderersList.size()]);
}
 
Example #11
Source File: MediaCodecAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context A context.
 * @param mediaCodecSelector A decoder selector.
 * @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 acquisition. 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 MediaCodecAudioRenderer(
    Context context,
    MediaCodecSelector mediaCodecSelector,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener) {
  this(
      context,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      eventHandler,
      eventListener,
      (AudioCapabilities) null);
}
 
Example #12
Source File: ExoPlayerFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@link SimpleExoPlayer} instance.
 *
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
public static SimpleExoPlayer newSimpleInstance(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Looper looper) {
  return newSimpleInstance(
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      getDefaultBandwidthMeter(),
      analyticsCollectorFactory,
      looper);
}
 
Example #13
Source File: MediaCodecAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context A context.
 * @param mediaCodecSelector A decoder selector.
 * @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 acquisition. 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 MediaCodecAudioRenderer(
    Context context,
    MediaCodecSelector mediaCodecSelector,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener) {
  this(
      context,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      eventHandler,
      eventListener,
      (AudioCapabilities) null);
}
 
Example #14
Source File: ExoPlayerFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@link SimpleExoPlayer} instance.
 *
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 */
public static SimpleExoPlayer newSimpleInstance(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter) {
  return newSimpleInstance(
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      new AnalyticsCollector.Factory(),
      Util.getLooper());
}
 
Example #15
Source File: DownloadHelper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link DownloadHelper} for DASH streams.
 *
 * @param uri A manifest {@link Uri}.
 * @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest.
 * @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
 *     selected.
 * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers created by
 *     {@code renderersFactory}.
 * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for
 *     downloading.
 * @return A {@link DownloadHelper} for DASH streams.
 * @throws IllegalStateException If the DASH module is missing.
 */
public static DownloadHelper forDash(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    RenderersFactory renderersFactory,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    DefaultTrackSelector.Parameters trackSelectorParameters) {
  return new DownloadHelper(
      DownloadRequest.TYPE_DASH,
      uri,
      /* cacheKey= */ null,
      createMediaSourceInternal(
          DASH_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null),
      trackSelectorParameters,
      Util.getRendererCapabilities(renderersFactory, drmSessionManager));
}
 
Example #16
Source File: SsMediaPeriod.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private static TrackGroupArray buildTrackGroups(
    SsManifest manifest, DrmSessionManager<?> drmSessionManager) {
  TrackGroup[] trackGroups = new TrackGroup[manifest.streamElements.length];
  for (int i = 0; i < manifest.streamElements.length; i++) {
    Format[] manifestFormats = manifest.streamElements[i].formats;
    Format[] exposedFormats = new Format[manifestFormats.length];
    for (int j = 0; j < manifestFormats.length; j++) {
      Format manifestFormat = manifestFormats[j];
      exposedFormats[j] =
          manifestFormat.drmInitData != null
              ? manifestFormat.copyWithExoMediaCryptoType(
                  drmSessionManager.getExoMediaCryptoType(manifestFormat.drmInitData))
              : manifestFormat;
    }
    trackGroups[i] = new TrackGroup(exposedFormats);
  }
  return new TrackGroupArray(trackGroups);
}
 
Example #17
Source File: SoftVideoRenderer.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
/**
 * @param scaleToFit Whether video frames should be scaled to fit when rendering.
 * @param allowedJoiningTimeMs The maximum duration in milliseconds for which this video renderer
 *     can attempt to seamlessly join an ongoing playback.
 * @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 maxDroppedFramesToNotify The maximum number of frames that can be dropped between
 *     invocations of {@link VideoRendererEventListener#onDroppedFrames(int, long)}.
 * @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 acquisition. 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 SoftVideoRenderer(boolean scaleToFit, long allowedJoiningTimeMs,
                         Handler eventHandler, VideoRendererEventListener eventListener,
                         int maxDroppedFramesToNotify, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
                         boolean playClearSamplesWithoutKeys) {
  super(C.TRACK_TYPE_VIDEO);
  this.scaleToFit = scaleToFit;
  this.allowedJoiningTimeMs = allowedJoiningTimeMs;
  this.maxDroppedFramesToNotify = maxDroppedFramesToNotify;
  this.drmSessionManager = drmSessionManager;
  this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
  this.outputBufferRenderer = new FrameRenderer();
  joiningDeadlineMs = C.TIME_UNSET;
  clearReportedVideoSize();
  formatHolder = new FormatHolder();
  flagsOnlyBuffer = DecoderInputBuffer.newFlagsOnlyInstance();
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  decoderReinitializationState = REINITIALIZATION_STATE_NONE;
}
 
Example #18
Source File: SimpleDecoderVideoRenderer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @param allowedJoiningTimeMs The maximum duration in milliseconds for which this video renderer
 *     can attempt to seamlessly join an ongoing playback.
 * @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 maxDroppedFramesToNotify The maximum number of frames that can be dropped between
 *     invocations of {@link VideoRendererEventListener#onDroppedFrames(int, long)}.
 * @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 acquisition. 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.
 */
protected SimpleDecoderVideoRenderer(
    long allowedJoiningTimeMs,
    @Nullable Handler eventHandler,
    @Nullable VideoRendererEventListener eventListener,
    int maxDroppedFramesToNotify,
    @Nullable DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys) {
  super(C.TRACK_TYPE_VIDEO);
  this.allowedJoiningTimeMs = allowedJoiningTimeMs;
  this.maxDroppedFramesToNotify = maxDroppedFramesToNotify;
  this.drmSessionManager = drmSessionManager;
  this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
  joiningDeadlineMs = C.TIME_UNSET;
  clearReportedVideoSize();
  formatQueue = new TimedValueQueue<>();
  flagsOnlyBuffer = DecoderInputBuffer.newFlagsOnlyInstance();
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  decoderReinitializationState = REINITIALIZATION_STATE_NONE;
  outputMode = C.VIDEO_OUTPUT_MODE_NONE;
}
 
Example #19
Source File: MediaCodecAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context A context.
 * @param mediaCodecSelector A decoder selector.
 * @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 acquisition. 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 enableDecoderFallback Whether to enable fallback to lower-priority decoders if decoder
 *     initialization fails. This may result in using a decoder that is slower/less efficient than
 *     the primary decoder.
 * @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 audioSink The sink to which audio will be output.
 */
public MediaCodecAudioRenderer(
    Context context,
    MediaCodecSelector mediaCodecSelector,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    boolean enableDecoderFallback,
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    AudioSink audioSink) {
  super(
      C.TRACK_TYPE_AUDIO,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      enableDecoderFallback,
      /* assumedMinimumCodecOperatingRate= */ 44100);
  this.context = context.getApplicationContext();
  this.audioSink = audioSink;
  lastInputTimeUs = C.TIME_UNSET;
  pendingStreamChangeTimesUs = new long[MAX_PENDING_STREAM_CHANGE_COUNT];
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  audioSink.setListener(new AudioSinkListener());
}
 
Example #20
Source File: SsMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private SsMediaSource(
    @Nullable SsManifest manifest,
    @Nullable Uri manifestUri,
    @Nullable DataSource.Factory manifestDataSourceFactory,
    @Nullable ParsingLoadable.Parser<? extends SsManifest> manifestParser,
    SsChunkSource.Factory chunkSourceFactory,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    DrmSessionManager<?> drmSessionManager,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy,
    long livePresentationDelayMs,
    @Nullable Object tag) {
  Assertions.checkState(manifest == null || !manifest.isLive);
  this.manifest = manifest;
  this.manifestUri = manifestUri == null ? null : SsUtil.fixManifestUri(manifestUri);
  this.manifestDataSourceFactory = manifestDataSourceFactory;
  this.manifestParser = manifestParser;
  this.chunkSourceFactory = chunkSourceFactory;
  this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
  this.drmSessionManager = drmSessionManager;
  this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
  this.livePresentationDelayMs = livePresentationDelayMs;
  this.manifestEventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null);
  this.tag = tag;
  sideloadedManifest = manifest != null;
  mediaPeriods = new ArrayList<>();
}
 
Example #21
Source File: ExoPlayerFactory.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@link SimpleExoPlayer} instance.
 *
 * @param context A {@link Context}.
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
public static SimpleExoPlayer newSimpleInstance(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Looper looper) {
  return new SimpleExoPlayer(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      analyticsCollectorFactory,
      looper);
}
 
Example #22
Source File: SsMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance to play the manifest at a given {@link Uri}, which may be live or
 * on-demand.
 *
 * @param manifestUri The manifest {@link Uri}.
 * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used
 *     to load (and refresh) the manifest.
 * @param manifestParser A parser for loaded manifest data.
 * @param chunkSourceFactory A factory for {@link SsChunkSource} instances.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the
 *     default start position should precede the end of the live window.
 * @param eventHandler A handler for events. 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.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public SsMediaSource(
    Uri manifestUri,
    DataSource.Factory manifestDataSourceFactory,
    ParsingLoadable.Parser<? extends SsManifest> manifestParser,
    SsChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount,
    long livePresentationDelayMs,
    @Nullable Handler eventHandler,
    @Nullable MediaSourceEventListener eventListener) {
  this(
      /* manifest= */ null,
      manifestUri,
      manifestDataSourceFactory,
      manifestParser,
      chunkSourceFactory,
      new DefaultCompositeSequenceableLoaderFactory(),
      DrmSessionManager.getDummyDrmSessionManager(),
      new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount),
      livePresentationDelayMs,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #23
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 * @param analyticsCollectorFactory A factory for creating the {@link AnalyticsCollector} that
 *     will collect and forward all player events.
 * @param looper The {@link Looper} which must be used for all calls to the player and which is
 *     used to call listeners on.
 */
protected SimpleExoPlayer(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector.Factory analyticsCollectorFactory,
    Looper looper) {
  this(
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      analyticsCollectorFactory,
      Clock.DEFAULT,
      looper);
}
 
Example #24
Source File: ProgressiveMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
ProgressiveMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    DrmSessionManager<?> drmSessionManager,
    LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes,
    @Nullable Object tag) {
  this.uri = uri;
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  this.drmSessionManager = drmSessionManager;
  this.loadableLoadErrorHandlingPolicy = loadableLoadErrorHandlingPolicy;
  this.customCacheKey = customCacheKey;
  this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
  this.timelineDurationUs = C.TIME_UNSET;
  this.tag = tag;
}
 
Example #25
Source File: SimpleRenderersFactory.java    From no-player with Apache License 2.0 6 votes vote down vote up
@Override
public Renderer[] createRenderers(Handler eventHandler,
                                  VideoRendererEventListener videoRendererEventListener,
                                  AudioRendererEventListener audioRendererEventListener,
                                  TextOutput textRendererOutput,
                                  MetadataOutput metadataRendererOutput,
                                  @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
    ArrayList<Renderer> renderersList = new ArrayList<>();
    buildVideoRenderers(context, drmSessionManager, allowedVideoJoiningTimeMs,
            eventHandler, videoRendererEventListener, extensionRendererMode, renderersList);
    buildAudioRenderers(context, drmSessionManager, buildAudioProcessors(),
            eventHandler, audioRendererEventListener, extensionRendererMode, renderersList);
    buildTextRenderers(textRendererOutput, eventHandler.getLooper(), renderersList, subtitleDecoderFactory);
    buildMetadataRenderers(metadataRendererOutput, eventHandler.getLooper(),
            renderersList);
    buildMiscellaneousRenderers();
    return renderersList.toArray(new Renderer[renderersList.size()]);
}
 
Example #26
Source File: MediaCodecAudioRenderer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context A context.
 * @param mediaCodecSelector A decoder selector.
 * @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 acquisition. 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.
 * @param audioSink The sink to which audio will be output.
 */
public MediaCodecAudioRenderer(
    Context context,
    MediaCodecSelector mediaCodecSelector,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    AudioSink audioSink) {
  this(
      context,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      /* enableDecoderFallback= */ false,
      eventHandler,
      eventListener,
      audioSink);
}
 
Example #27
Source File: MediaCodecAudioRenderer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @param context A context.
 * @param mediaCodecSelector A decoder selector.
 * @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 acquisition. 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 enableDecoderFallback Whether to enable fallback to lower-priority decoders if decoder
 *     initialization fails. This may result in using a decoder that is slower/less efficient than
 *     the primary decoder.
 * @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 audioSink The sink to which audio will be output.
 * @deprecated Use {@link #MediaCodecAudioRenderer(Context, MediaCodecSelector, boolean, Handler,
 *     AudioRendererEventListener, AudioSink)} instead, and pass DRM-related parameters to the
 *     {@link MediaSource} factories.
 */
@Deprecated
public MediaCodecAudioRenderer(
    Context context,
    MediaCodecSelector mediaCodecSelector,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    boolean enableDecoderFallback,
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    AudioSink audioSink) {
  super(
      C.TRACK_TYPE_AUDIO,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      enableDecoderFallback,
      /* assumedMinimumCodecOperatingRate= */ 44100);
  this.context = context.getApplicationContext();
  this.audioSink = audioSink;
  lastInputTimeUs = C.TIME_UNSET;
  pendingStreamChangeTimesUs = new long[MAX_PENDING_STREAM_CHANGE_COUNT];
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  audioSink.setListener(new AudioSinkListener());
}
 
Example #28
Source File: MediaCodecAudioRenderer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @param context A context.
 * @param mediaCodecSelector A decoder selector.
 * @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 acquisition. 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.
 * @param audioSink The sink to which audio will be output.
 * @deprecated Use {@link #MediaCodecAudioRenderer(Context, MediaCodecSelector, boolean, Handler,
 *     AudioRendererEventListener, AudioSink)} instead, and pass DRM-related parameters to the
 *     {@link MediaSource} factories.
 */
@Deprecated
@SuppressWarnings("deprecation")
public MediaCodecAudioRenderer(
    Context context,
    MediaCodecSelector mediaCodecSelector,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    AudioSink audioSink) {
  this(
      context,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      /* enableDecoderFallback= */ false,
      eventHandler,
      eventListener,
      audioSink);
}
 
Example #29
Source File: ExoPlayerFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@link SimpleExoPlayer} instance.
 *
 * @param renderersFactory A factory for creating {@link Renderer}s to be used by the instance.
 * @param trackSelector The {@link TrackSelector} that will be used by the instance.
 * @param loadControl The {@link LoadControl} that will be used by the instance.
 * @param drmSessionManager An optional {@link DrmSessionManager}. May be null if the instance
 *     will not be used for DRM protected playbacks.
 * @param bandwidthMeter The {@link BandwidthMeter} that will be used by the instance.
 */
public static SimpleExoPlayer newSimpleInstance(
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    BandwidthMeter bandwidthMeter) {
  return newSimpleInstance(
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      bandwidthMeter,
      new AnalyticsCollector.Factory(),
      Util.getLooper());
}
 
Example #30
Source File: DownloadHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link DownloadHelper} for HLS streams.
 *
 * @param uri A playlist {@link Uri}.
 * @param dataSourceFactory A {@link DataSource.Factory} used to load the playlist.
 * @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
 *     selected.
 * @param drmSessionManager An optional {@link DrmSessionManager} used by the renderers created by
 *     {@code renderersFactory}.
 * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for
 *     downloading.
 * @return A {@link DownloadHelper} for HLS streams.
 * @throws IllegalStateException If the HLS module is missing.
 */
public static DownloadHelper forHls(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    RenderersFactory renderersFactory,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    DefaultTrackSelector.Parameters trackSelectorParameters) {
  return new DownloadHelper(
      DownloadRequest.TYPE_HLS,
      uri,
      /* cacheKey= */ null,
      HLS_FACTORY.createMediaSource(uri, dataSourceFactory, /* streamKeys= */ null),
      trackSelectorParameters,
      Util.getRendererCapabilities(renderersFactory, drmSessionManager));
}