com.google.android.exoplayer2.mediacodec.MediaCodecSelector Java Examples

The following examples show how to use com.google.android.exoplayer2.mediacodec.MediaCodecSelector. 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: 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.
 * @param audioCapabilities The audio capabilities for playback on this device. May be null if the
 *     default capabilities (no encoded audio passthrough support) should be assumed.
 * @param audioProcessors Optional {@link AudioProcessor}s that will process PCM audio before
 *     output.
 */
public MediaCodecAudioRenderer(
    Context context,
    MediaCodecSelector mediaCodecSelector,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    @Nullable AudioCapabilities audioCapabilities,
    AudioProcessor... audioProcessors) {
  this(
      context,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      eventHandler,
      eventListener,
      new DefaultAudioSink(audioCapabilities, audioProcessors));
}
 
Example #2
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.
 * @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) {
  super(
      C.TRACK_TYPE_AUDIO,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      /* assumedMinimumCodecOperatingRate= */ 44100);
  this.context = context.getApplicationContext();
  this.audioSink = audioSink;
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  audioSink.setListener(new AudioSinkListener());
}
 
Example #3
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 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 Handler eventHandler,
    @Nullable VideoRendererEventListener eventListener,
    int maxDroppedFramesToNotify) {
  this(
      context,
      mediaCodecSelector,
      allowedJoiningTimeMs,
      /* drmSessionManager= */ null,
      /* playClearSamplesWithoutKeys= */ false,
      eventHandler,
      eventListener,
      maxDroppedFramesToNotify);
}
 
Example #4
Source File: ExoplayerAudioRenderer.java    From lbry-android with MIT License 6 votes vote down vote up
@Override
protected void buildAudioRenderers(
        Context context,
        int extensionRendererMode,
        MediaCodecSelector mediaCodecSelector,
        @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
        boolean playClearSamplesWithoutKeys,
        boolean enableDecoderFallback,
        AudioProcessor[] audioProcessors,
        Handler eventHandler,
        AudioRendererEventListener eventListener,
        ArrayList<Renderer> out) {
    AudioProcessor[] audioProcessorList = { new TeeAudioProcessor(audioBufferSink) };
    super.buildAudioRenderers(
            context,
            extensionRendererMode,
            mediaCodecSelector,
            drmSessionManager,
            playClearSamplesWithoutKeys,
            enableDecoderFallback,
            audioProcessorList,
            eventHandler,
            eventListener,
            out);
}
 
Example #5
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 #6
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.
 * @param audioCapabilities The audio capabilities for playback on this device. May be null if the
 *     default capabilities (no encoded audio passthrough support) should be assumed.
 * @param audioProcessors Optional {@link AudioProcessor}s that will process PCM audio before
 *     output.
 */
public MediaCodecAudioRenderer(
    Context context,
    MediaCodecSelector mediaCodecSelector,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    @Nullable AudioCapabilities audioCapabilities,
    AudioProcessor... audioProcessors) {
  this(
      context,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      eventHandler,
      eventListener,
      new DefaultAudioSink(audioCapabilities, audioProcessors));
}
 
Example #7
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 #8
Source File: MediaCodecAudioRenderer.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
protected int supportsFormat(MediaCodecSelector mediaCodecSelector, Format format)
    throws DecoderQueryException {
  String mimeType = format.sampleMimeType;
  if (!MimeTypes.isAudio(mimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  }
  int tunnelingSupport = Util.SDK_INT >= 21 ? TUNNELING_SUPPORTED : TUNNELING_NOT_SUPPORTED;
  if (allowPassthrough(mimeType) && mediaCodecSelector.getPassthroughDecoderInfo() != null) {
    return ADAPTIVE_NOT_SEAMLESS | tunnelingSupport | FORMAT_HANDLED;
  }
  MediaCodecInfo decoderInfo = mediaCodecSelector.getDecoderInfo(mimeType, false);
  if (decoderInfo == null) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  }
  // Note: We assume support for unknown sampleRate and channelCount.
  boolean decoderCapable = Util.SDK_INT < 21
      || ((format.sampleRate == Format.NO_VALUE
      || decoderInfo.isAudioSampleRateSupportedV21(format.sampleRate))
      && (format.channelCount == Format.NO_VALUE
      ||  decoderInfo.isAudioChannelCountSupportedV21(format.channelCount)));
  int formatSupport = decoderCapable ? FORMAT_HANDLED : FORMAT_EXCEEDS_CAPABILITIES;
  return ADAPTIVE_NOT_SEAMLESS | tunnelingSupport | formatSupport;
}
 
Example #9
Source File: MediaCodecVideoRenderer.java    From MediaSDK with Apache License 2.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)}.
 * @deprecated Use {@link #MediaCodecVideoRenderer(Context, MediaCodecSelector, long, boolean,
 *     Handler, VideoRendererEventListener, int)} instead, and pass DRM-related parameters to the
 *     {@link MediaSource} factories.
 */
@Deprecated
@SuppressWarnings("deprecation")
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: 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.
 * @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 #11
Source File: MediaCodecVideoRenderer.java    From K-Sonic with MIT License 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, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys, Handler eventHandler,
    VideoRendererEventListener eventListener, int maxDroppedFramesToNotify) {
  super(C.TRACK_TYPE_VIDEO, mediaCodecSelector, drmSessionManager, playClearSamplesWithoutKeys);
  this.allowedJoiningTimeMs = allowedJoiningTimeMs;
  this.maxDroppedFramesToNotify = maxDroppedFramesToNotify;
  frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(context);
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  deviceNeedsAutoFrcWorkaround = deviceNeedsAutoFrcWorkaround();
  joiningDeadlineMs = C.TIME_UNSET;
  currentWidth = Format.NO_VALUE;
  currentHeight = Format.NO_VALUE;
  currentPixelWidthHeightRatio = Format.NO_VALUE;
  pendingPixelWidthHeightRatio = Format.NO_VALUE;
  scalingMode = C.VIDEO_SCALING_MODE_DEFAULT;
  clearLastReportedVideoSize();
}
 
Example #12
Source File: RendererProvider.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
@NonNull
protected List<Renderer> buildAudioRenderers() {
    List<Renderer> renderers = new ArrayList<>();
    renderers.add(new MediaCodecAudioRenderer(context, MediaCodecSelector.DEFAULT, drmSessionManager, true, handler, audioRendererEventListener, AudioCapabilities.getCapabilities(context)));

    // Adds any registered classes
    List<String> classNames = ExoMedia.Data.registeredRendererClasses.get(ExoMedia.RendererType.AUDIO);
    if (classNames != null) {
        for (String className: classNames) {
            try {
                Class<?> clazz = Class.forName(className);
                Constructor<?> constructor = clazz.getConstructor(Handler.class, AudioRendererEventListener.class);
                Renderer renderer = (Renderer) constructor.newInstance(handler, audioRendererEventListener);
                renderers.add(renderer);
            } catch (Exception e) {
                // Purposefully left blank
            }
        }
    }

    return renderers;
}
 
Example #13
Source File: MediaCodecVideoRenderer.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 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 #14
Source File: MediaCodecAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected List<MediaCodecInfo> getDecoderInfos(
    MediaCodecSelector mediaCodecSelector, Format format, boolean requiresSecureDecoder)
    throws DecoderQueryException {
  if (allowPassthrough(format.channelCount, format.sampleMimeType)) {
    MediaCodecInfo passthroughDecoderInfo = mediaCodecSelector.getPassthroughDecoderInfo();
    if (passthroughDecoderInfo != null) {
      return Collections.singletonList(passthroughDecoderInfo);
    }
  }
  List<MediaCodecInfo> decoderInfos =
      mediaCodecSelector.getDecoderInfos(
          format.sampleMimeType, requiresSecureDecoder, /* requiresTunnelingDecoder= */ false);
  if (MimeTypes.AUDIO_E_AC3_JOC.equals(format.sampleMimeType)) {
    // E-AC3 decoders can decode JOC streams, but in 2-D rather than 3-D.
    List<MediaCodecInfo> decoderInfosWithEac3 = new ArrayList<>(decoderInfos);
    decoderInfosWithEac3.addAll(
        mediaCodecSelector.getDecoderInfos(
            MimeTypes.AUDIO_E_AC3, requiresSecureDecoder, /* requiresTunnelingDecoder= */ false));
    decoderInfos = decoderInfosWithEac3;
  }
  return Collections.unmodifiableList(decoderInfos);
}
 
Example #15
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 #16
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 audioCapabilities The audio capabilities for playback on this device. May be null if the
 *     default capabilities (no encoded audio passthrough support) should be assumed.
 * @param audioProcessors Optional {@link AudioProcessor}s that will process PCM audio before
 *     output.
 */
public MediaCodecAudioRenderer(
    Context context,
    MediaCodecSelector mediaCodecSelector,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    @Nullable AudioCapabilities audioCapabilities,
    AudioProcessor... audioProcessors) {
  this(
      context,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      eventHandler,
      eventListener,
      new DefaultAudioSink(audioCapabilities, audioProcessors));
}
 
Example #17
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.
 * @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) {
  this(
      context,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      eventHandler,
      eventListener,
      (AudioCapabilities) null);
}
 
Example #18
Source File: RendererProvider.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
@NonNull
protected List<Renderer> buildVideoRenderers() {
    List<Renderer> renderers = new ArrayList<>();

    renderers.add(new MediaCodecVideoRenderer(context, MediaCodecSelector.DEFAULT, videoJoiningTimeMs, drmSessionManager, false, handler, videoRendererEventListener, droppedFrameNotificationAmount));

    // Adds any registered classes
    List<String> classNames = ExoMedia.Data.registeredRendererClasses.get(ExoMedia.RendererType.VIDEO);
    if (classNames != null) {
        for (String className: classNames) {
            try {
                Class<?> clazz = Class.forName(className);
                Constructor<?> constructor = clazz.getConstructor(boolean.class, long.class, Handler.class, VideoRendererEventListener.class, int.class);
                Renderer renderer = (Renderer) constructor.newInstance(true, videoJoiningTimeMs, handler, videoRendererEventListener, droppedFrameNotificationAmount);
                renderers.add(renderer);
            } catch (Exception e) {
                // Purposefully left blank
            }
        }
    }

    return renderers;
}
 
Example #19
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 #20
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.
 * @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) {
  this(
      context,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      /* eventHandler= */ null,
      /* eventListener= */ null);
}
 
Example #21
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.
 * @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) {
  super(
      C.TRACK_TYPE_AUDIO,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      /* assumedMinimumCodecOperatingRate= */ 44100);
  this.context = context.getApplicationContext();
  this.audioSink = audioSink;
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  audioSink.setListener(new AudioSinkListener());
}
 
Example #22
Source File: MediaCodecAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected List<MediaCodecInfo> getDecoderInfos(
    MediaCodecSelector mediaCodecSelector, Format format, boolean requiresSecureDecoder)
    throws DecoderQueryException {
  if (allowPassthrough(format.sampleMimeType)) {
    MediaCodecInfo passthroughDecoderInfo = mediaCodecSelector.getPassthroughDecoderInfo();
    if (passthroughDecoderInfo != null) {
      return Collections.singletonList(passthroughDecoderInfo);
    }
  }
  return super.getDecoderInfos(mediaCodecSelector, format, requiresSecureDecoder);
}
 
Example #23
Source File: MediaCodecVideoRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
protected int supportsFormat(MediaCodecSelector mediaCodecSelector, Format format)
    throws DecoderQueryException {
  String mimeType = format.sampleMimeType;
  if (!MimeTypes.isVideo(mimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  }
  boolean requiresSecureDecryption = false;
  DrmInitData drmInitData = format.drmInitData;
  if (drmInitData != null) {
    for (int i = 0; i < drmInitData.schemeDataCount; i++) {
      requiresSecureDecryption |= drmInitData.get(i).requiresSecureDecryption;
    }
  }
  MediaCodecInfo decoderInfo = mediaCodecSelector.getDecoderInfo(mimeType,
      requiresSecureDecryption);
  if (decoderInfo == null) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  }

  boolean decoderCapable = decoderInfo.isCodecSupported(format.codecs);
  if (decoderCapable && format.width > 0 && format.height > 0) {
    if (Util.SDK_INT >= 21) {
      decoderCapable = decoderInfo.isVideoSizeAndRateSupportedV21(format.width, format.height,
          format.frameRate);
    } else {
      decoderCapable = format.width * format.height <= MediaCodecUtil.maxH264DecodableFrameSize();
      if (!decoderCapable) {
        Log.d(TAG, "FalseCheck [legacyFrameSize, " + format.width + "x" + format.height + "] ["
            + Util.DEVICE_DEBUG_INFO + "]");
      }
    }
  }

  int adaptiveSupport = decoderInfo.adaptive ? ADAPTIVE_SEAMLESS : ADAPTIVE_NOT_SEAMLESS;
  int tunnelingSupport = decoderInfo.tunneling ? TUNNELING_SUPPORTED : TUNNELING_NOT_SUPPORTED;
  int formatSupport = decoderCapable ? FORMAT_HANDLED : FORMAT_EXCEEDS_CAPABILITIES;
  return adaptiveSupport | tunnelingSupport | formatSupport;
}
 
Example #24
Source File: DefaultRenderersFactory.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link #DefaultRenderersFactory(Context)}, {@link
 *     #setExtensionRendererMode(int)} and {@link #setAllowedVideoJoiningTimeMs(long)}, and pass
 *     {@link DrmSessionManager} directly to {@link SimpleExoPlayer} or {@link ExoPlayerFactory}.
 */
@Deprecated
public DefaultRenderersFactory(
    Context context,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    @ExtensionRendererMode int extensionRendererMode,
    long allowedVideoJoiningTimeMs) {
  this.context = context;
  this.extensionRendererMode = extensionRendererMode;
  this.allowedVideoJoiningTimeMs = allowedVideoJoiningTimeMs;
  this.drmSessionManager = drmSessionManager;
  mediaCodecSelector = MediaCodecSelector.DEFAULT;
}
 
Example #25
Source File: MediaCodecVideoRenderer.java    From Telegram with GNU General Public License v2.0 5 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 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 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,
    boolean enableDecoderFallback,
    @Nullable Handler eventHandler,
    @Nullable VideoRendererEventListener eventListener,
    int maxDroppedFramesToNotify) {
  super(
      C.TRACK_TYPE_VIDEO,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      enableDecoderFallback,
      /* assumedMinimumCodecOperatingRate= */ 30);
  this.allowedJoiningTimeMs = allowedJoiningTimeMs;
  this.maxDroppedFramesToNotify = maxDroppedFramesToNotify;
  this.context = context.getApplicationContext();
  frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(this.context);
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  deviceNeedsNoPostProcessWorkaround = deviceNeedsNoPostProcessWorkaround();
  pendingOutputStreamOffsetsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
  pendingOutputStreamSwitchTimesUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
  outputStreamOffsetUs = C.TIME_UNSET;
  lastInputTimeUs = C.TIME_UNSET;
  joiningDeadlineMs = C.TIME_UNSET;
  currentWidth = Format.NO_VALUE;
  currentHeight = Format.NO_VALUE;
  currentPixelWidthHeightRatio = Format.NO_VALUE;
  pendingPixelWidthHeightRatio = Format.NO_VALUE;
  scalingMode = C.VIDEO_SCALING_MODE_DEFAULT;
  clearReportedVideoSize();
}
 
Example #26
Source File: DebugSimpleExoPlayer.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public DebugMediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector,
    long allowedJoiningTimeMs, Handler eventHandler,
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    VideoRendererEventListener eventListener, int maxDroppedFrameCountToNotify) {
  super(context, mediaCodecSelector, allowedJoiningTimeMs, drmSessionManager, false,
      eventHandler, eventListener, maxDroppedFrameCountToNotify);
}
 
Example #27
Source File: DebugSimpleExoPlayer.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
@Override
protected void buildVideoRenderers(Context context, Handler mainHandler,
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    @ExtensionRendererMode int extensionRendererMode, VideoRendererEventListener eventListener,
    long allowedVideoJoiningTimeMs, ArrayList<Renderer> out) {
  out.add(new DebugMediaCodecVideoRenderer(context, MediaCodecSelector.DEFAULT,
      allowedVideoJoiningTimeMs, mainHandler, drmSessionManager, eventListener,
      MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY));
}
 
Example #28
Source File: SimpleRendersFactory.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
protected void buildVideoRenderers(Context context, int extensionRendererMode, MediaCodecSelector mediaCodecSelector, @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, boolean playClearSamplesWithoutKeys, Handler eventHandler, VideoRendererEventListener eventListener, long allowedVideoJoiningTimeMs, ArrayList<Renderer> out) {
    BaseRenderer ffmpegRenderer = new SoftVideoRenderer(true,
            allowedVideoJoiningTimeMs, eventHandler, eventListener,
            MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY,
            drmSessionManager, false);
    out.add(ffmpegRenderer);
    super.buildVideoRenderers(context, extensionRendererMode, mediaCodecSelector, drmSessionManager, playClearSamplesWithoutKeys, eventHandler, eventListener, allowedVideoJoiningTimeMs, out);
}
 
Example #29
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 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) {
  super(
      C.TRACK_TYPE_VIDEO,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      /* assumedMinimumCodecOperatingRate= */ 30);
  this.allowedJoiningTimeMs = allowedJoiningTimeMs;
  this.maxDroppedFramesToNotify = maxDroppedFramesToNotify;
  this.context = context.getApplicationContext();
  frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(this.context);
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  deviceNeedsAutoFrcWorkaround = deviceNeedsAutoFrcWorkaround();
  pendingOutputStreamOffsetsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
  pendingOutputStreamSwitchTimesUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
  outputStreamOffsetUs = C.TIME_UNSET;
  lastInputTimeUs = C.TIME_UNSET;
  joiningDeadlineMs = C.TIME_UNSET;
  currentWidth = Format.NO_VALUE;
  currentHeight = Format.NO_VALUE;
  currentPixelWidthHeightRatio = Format.NO_VALUE;
  pendingPixelWidthHeightRatio = Format.NO_VALUE;
  scalingMode = C.VIDEO_SCALING_MODE_DEFAULT;
  clearReportedVideoSize();
}
 
Example #30
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 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.
 */
public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector,
    long allowedJoiningTimeMs) {
  this(
      context,
      mediaCodecSelector,
      allowedJoiningTimeMs,
      /* eventHandler= */ null,
      /* eventListener= */ null,
      -1);
}