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

The following examples show how to use com.google.android.exoplayer2.drm.ExoMediaCrypto. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleDecoderAudioRenderer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @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 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 audioSink The sink to which audio will be output.
 */
public SimpleDecoderAudioRenderer(
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    @Nullable DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    AudioSink audioSink) {
  super(C.TRACK_TYPE_AUDIO);
  this.drmSessionManager = drmSessionManager;
  this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  this.audioSink = audioSink;
  audioSink.setListener(new AudioSinkListener());
  formatHolder = new FormatHolder();
  flagsOnlyBuffer = DecoderInputBuffer.newFlagsOnlyInstance();
  decoderReinitializationState = REINITIALIZATION_STATE_NONE;
  audioTrackNeedsConfigure = true;
}
 
Example #2
Source File: SimpleDecoderAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @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 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 audioSink The sink to which audio will be output.
 */
public SimpleDecoderAudioRenderer(
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    @Nullable DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    AudioSink audioSink) {
  super(C.TRACK_TYPE_AUDIO);
  this.drmSessionManager = drmSessionManager;
  this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  this.audioSink = audioSink;
  audioSink.setListener(new AudioSinkListener());
  formatHolder = new FormatHolder();
  flagsOnlyBuffer = DecoderInputBuffer.newFlagsOnlyInstance();
  decoderReinitializationState = REINITIALIZATION_STATE_NONE;
  audioTrackNeedsConfigure = true;
}
 
Example #3
Source File: SimpleDecoderAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @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 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 audioSink The sink to which audio will be output.
 */
public SimpleDecoderAudioRenderer(
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    @Nullable DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    AudioSink audioSink) {
  super(C.TRACK_TYPE_AUDIO);
  this.drmSessionManager = drmSessionManager;
  this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  this.audioSink = audioSink;
  audioSink.setListener(new AudioSinkListener());
  formatHolder = new FormatHolder();
  flagsOnlyBuffer = DecoderInputBuffer.newFlagsOnlyInstance();
  decoderReinitializationState = REINITIALIZATION_STATE_NONE;
  audioTrackNeedsConfigure = true;
}
 
Example #4
Source File: SimpleDecoderAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @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 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 audioSink The sink to which audio will be output.
 */
public SimpleDecoderAudioRenderer(
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    @Nullable DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    AudioSink audioSink) {
  super(C.TRACK_TYPE_AUDIO);
  this.drmSessionManager = drmSessionManager;
  this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  this.audioSink = audioSink;
  audioSink.setListener(new AudioSinkListener());
  formatHolder = new FormatHolder();
  flagsOnlyBuffer = DecoderInputBuffer.newFlagsOnlyInstance();
  decoderReinitializationState = REINITIALIZATION_STATE_NONE;
  audioTrackNeedsConfigure = true;
}
 
Example #5
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 #6
Source File: SimpleDecoderAudioRenderer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @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 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 audioSink The sink to which audio will be output.
 */
public SimpleDecoderAudioRenderer(
    @Nullable Handler eventHandler,
    @Nullable AudioRendererEventListener eventListener,
    @Nullable DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys,
    AudioSink audioSink) {
  super(C.TRACK_TYPE_AUDIO);
  this.drmSessionManager = drmSessionManager;
  this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  this.audioSink = audioSink;
  audioSink.setListener(new AudioSinkListener());
  flagsOnlyBuffer = DecoderInputBuffer.newFlagsOnlyInstance();
  decoderReinitializationState = REINITIALIZATION_STATE_NONE;
  audioTrackNeedsConfigure = true;
}
 
Example #7
Source File: FfmpegAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected FfmpegDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
    throws FfmpegDecoderException {
  int initialInputBufferSize =
      format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
  decoder =
      new FfmpegDecoder(
          NUM_BUFFERS, NUM_BUFFERS, initialInputBufferSize, format, shouldUseFloatOutput(format));
  return decoder;
}
 
Example #8
Source File: LibopusAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected OpusDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
    throws OpusDecoderException {
  int initialInputBufferSize =
      format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
  decoder =
      new OpusDecoder(
          NUM_BUFFERS,
          NUM_BUFFERS,
          initialInputBufferSize,
          format.initializationData,
          mediaCrypto);
  return decoder;
}
 
Example #9
Source File: LibflacAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected int supportsFormatInternal(DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    Format format) {
  if (!MimeTypes.AUDIO_FLAC.equalsIgnoreCase(format.sampleMimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  } else if (!supportsOutputEncoding(C.ENCODING_PCM_16BIT)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else if (!supportsFormatDrm(drmSessionManager, format.drmInitData)) {
    return FORMAT_UNSUPPORTED_DRM;
  } else {
    return FORMAT_HANDLED;
  }
}
 
Example #10
Source File: LibflacAudioRenderer.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Override
protected int supportsFormatInternal(DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    Format format) {
  if (!FlacLibrary.isAvailable()
      || !MimeTypes.AUDIO_FLAC.equalsIgnoreCase(format.sampleMimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  } else if (!supportsOutputEncoding(C.ENCODING_PCM_16BIT)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else if (!supportsFormatDrm(drmSessionManager, format.drmInitData)) {
    return FORMAT_UNSUPPORTED_DRM;
  } else {
    return FORMAT_HANDLED;
  }
}
 
Example #11
Source File: FfmpegAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected int supportsFormatInternal(DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    Format format) {
  Assertions.checkNotNull(format.sampleMimeType);
  if (!MimeTypes.isAudio(format.sampleMimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  } else if (!FfmpegLibrary.supportsFormat(format.sampleMimeType, format.pcmEncoding)
      || !isOutputSupported(format)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else if (!supportsFormatDrm(drmSessionManager, format.drmInitData)) {
    return FORMAT_UNSUPPORTED_DRM;
  } else {
    return FORMAT_HANDLED;
  }
}
 
Example #12
Source File: FfmpegAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected FfmpegDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
    throws FfmpegDecoderException {
  int initialInputBufferSize =
      format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
  decoder =
      new FfmpegDecoder(
          NUM_BUFFERS, NUM_BUFFERS, initialInputBufferSize, format, shouldUseFloatOutput(format));
  return decoder;
}
 
Example #13
Source File: FfmpegAudioRenderer.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected FfmpegDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
    throws FfmpegDecoderException {
  decoder = new FfmpegDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE,
      format.sampleMimeType, format.initializationData);
  return decoder;
}
 
Example #14
Source File: SimpleDecoderAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void maybeInitDecoder() throws ExoPlaybackException {
  if (decoder != null) {
    return;
  }

  setDecoderDrmSession(sourceDrmSession);

  ExoMediaCrypto mediaCrypto = null;
  if (decoderDrmSession != null) {
    mediaCrypto = decoderDrmSession.getMediaCrypto();
    if (mediaCrypto == null) {
      DrmSessionException drmError = decoderDrmSession.getError();
      if (drmError != null) {
        // Continue for now. We may be able to avoid failure if the session recovers, or if a new
        // input format causes the session to be replaced before it's used.
      } else {
        // The drm session isn't open yet.
        return;
      }
    }
  }

  try {
    long codecInitializingTimestamp = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("createAudioDecoder");
    decoder = createDecoder(inputFormat, mediaCrypto);
    TraceUtil.endSection();
    long codecInitializedTimestamp = SystemClock.elapsedRealtime();
    eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp,
        codecInitializedTimestamp - codecInitializingTimestamp);
    decoderCounters.decoderInitCount++;
  } catch (AudioDecoderException e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }
}
 
Example #15
Source File: LibopusAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected OpusDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
    throws OpusDecoderException {
  int initialInputBufferSize =
      format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
  decoder =
      new OpusDecoder(
          NUM_BUFFERS,
          NUM_BUFFERS,
          initialInputBufferSize,
          format.initializationData,
          mediaCrypto);
  return decoder;
}
 
Example #16
Source File: LibflacAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected int supportsFormatInternal(DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    Format format) {
  if (!MimeTypes.AUDIO_FLAC.equalsIgnoreCase(format.sampleMimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  } else if (!supportsOutput(format.channelCount, C.ENCODING_PCM_16BIT)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else if (!supportsFormatDrm(drmSessionManager, format.drmInitData)) {
    return FORMAT_UNSUPPORTED_DRM;
  } else {
    return FORMAT_HANDLED;
  }
}
 
Example #17
Source File: SimpleDecoderVideoRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private void maybeInitDecoder() throws ExoPlaybackException {
  if (decoder != null) {
    return;
  }

  setDecoderDrmSession(sourceDrmSession);

  ExoMediaCrypto mediaCrypto = null;
  if (decoderDrmSession != null) {
    mediaCrypto = decoderDrmSession.getMediaCrypto();
    if (mediaCrypto == null) {
      DrmSessionException drmError = decoderDrmSession.getError();
      if (drmError != null) {
        // Continue for now. We may be able to avoid failure if the session recovers, or if a new
        // input format causes the session to be replaced before it's used.
      } else {
        // The drm session isn't open yet.
        return;
      }
    }
  }

  try {
    long decoderInitializingTimestamp = SystemClock.elapsedRealtime();
    decoder = createDecoder(inputFormat, mediaCrypto);
    setDecoderOutputMode(outputMode);
    long decoderInitializedTimestamp = SystemClock.elapsedRealtime();
    onDecoderInitialized(
        decoder.getName(),
        decoderInitializedTimestamp,
        decoderInitializedTimestamp - decoderInitializingTimestamp);
    decoderCounters.decoderInitCount++;
  } catch (VideoDecoderException e) {
    throw createRendererException(e, inputFormat);
  }
}
 
Example #18
Source File: SimpleDecoderAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void maybeInitDecoder() throws ExoPlaybackException {
  if (decoder != null) {
    return;
  }

  drmSession = pendingDrmSession;
  ExoMediaCrypto mediaCrypto = null;
  if (drmSession != null) {
    mediaCrypto = drmSession.getMediaCrypto();
    if (mediaCrypto == null) {
      DrmSessionException drmError = drmSession.getError();
      if (drmError != null) {
        // Continue for now. We may be able to avoid failure if the session recovers, or if a new
        // input format causes the session to be replaced before it's used.
      } else {
        // The drm session isn't open yet.
        return;
      }
    }
  }

  try {
    long codecInitializingTimestamp = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("createAudioDecoder");
    decoder = createDecoder(inputFormat, mediaCrypto);
    TraceUtil.endSection();
    long codecInitializedTimestamp = SystemClock.elapsedRealtime();
    eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp,
        codecInitializedTimestamp - codecInitializingTimestamp);
    decoderCounters.decoderInitCount++;
  } catch (AudioDecoderException e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }
}
 
Example #19
Source File: Format.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public Format copyWithExoMediaCryptoType(
    @Nullable Class<? extends ExoMediaCrypto> exoMediaCryptoType) {
  return new Format(
      id,
      label,
      selectionFlags,
      roleFlags,
      bitrate,
      codecs,
      metadata,
      containerMimeType,
      sampleMimeType,
      maxInputSize,
      initializationData,
      drmInitData,
      subsampleOffsetUs,
      width,
      height,
      frameRate,
      rotationDegrees,
      pixelWidthHeightRatio,
      projectionData,
      stereoMode,
      colorInfo,
      channelCount,
      sampleRate,
      pcmEncoding,
      encoderDelay,
      encoderPadding,
      language,
      accessibilityChannel,
      exoMediaCryptoType);
}
 
Example #20
Source File: SimpleDecoderAudioRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
private void maybeInitDecoder() throws ExoPlaybackException {
  if (decoder != null) {
    return;
  }

  drmSession = pendingDrmSession;
  ExoMediaCrypto mediaCrypto = null;
  if (drmSession != null) {
    @DrmSession.State int drmSessionState = drmSession.getState();
    if (drmSessionState == DrmSession.STATE_ERROR) {
      throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
    } else if (drmSessionState == DrmSession.STATE_OPENED
        || drmSessionState == DrmSession.STATE_OPENED_WITH_KEYS) {
      mediaCrypto = drmSession.getMediaCrypto();
    } else {
      // The drm session isn't open yet.
      return;
    }
  }

  try {
    long codecInitializingTimestamp = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("createAudioDecoder");
    decoder = createDecoder(inputFormat, mediaCrypto);
    TraceUtil.endSection();
    long codecInitializedTimestamp = SystemClock.elapsedRealtime();
    eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp,
        codecInitializedTimestamp - codecInitializingTimestamp);
    decoderCounters.decoderInitCount++;
  } catch (AudioDecoderException e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }
}
 
Example #21
Source File: VideoDecoder.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
private native int ffmpegSecureDecode(long context,
ByteBuffer encoded,
int length,
ExoMediaCrypto mediaCrypto,
int inputMode,
byte[] key,
byte[] iv,
int numSubSamples,
int[] numBytesOfClearData,
int[] numBytesOfEncryptedData,
long timeUs,
boolean isDecodeOnly,
boolean isEndOfStream);
 
Example #22
Source File: LibopusAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected int supportsFormatInternal(DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    Format format) {
  if (!MimeTypes.AUDIO_OPUS.equalsIgnoreCase(format.sampleMimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  } else if (!supportsOutputEncoding(C.ENCODING_PCM_16BIT)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else if (!supportsFormatDrm(drmSessionManager, format.drmInitData)) {
    return FORMAT_UNSUPPORTED_DRM;
  } else {
    return FORMAT_HANDLED;
  }
}
 
Example #23
Source File: LibopusAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected OpusDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
    throws OpusDecoderException {
  int initialInputBufferSize =
      format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
  decoder =
      new OpusDecoder(
          NUM_BUFFERS,
          NUM_BUFFERS,
          initialInputBufferSize,
          format.initializationData,
          mediaCrypto);
  return decoder;
}
 
Example #24
Source File: LibflacAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected int supportsFormatInternal(DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    Format format) {
  if (!MimeTypes.AUDIO_FLAC.equalsIgnoreCase(format.sampleMimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  } else if (!supportsOutputEncoding(C.ENCODING_PCM_16BIT)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else if (!supportsFormatDrm(drmSessionManager, format.drmInitData)) {
    return FORMAT_UNSUPPORTED_DRM;
  } else {
    return FORMAT_HANDLED;
  }
}
 
Example #25
Source File: VideoDecoder.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
/**
 * Creates a ffmpeg decoder.
 *
 * @param numInputBuffers        The number of input buffers.
 * @param numOutputBuffers       The number of output buffers.
 * @param initialInputBufferSize The initial size of each input buffer.
 * @param exoMediaCrypto         The {@link ExoMediaCrypto} object required for decoding encrypted
 *                               content. Maybe null and can be ignored if decoder does not handle encrypted content.
 * @throws VideoSoftDecoderException Thrown if an exception occurs when initializing the decoder.
 */
public VideoDecoder(Format format, int numInputBuffers, int numOutputBuffers, int initialInputBufferSize,
                    ExoMediaCrypto exoMediaCrypto) throws VideoSoftDecoderException {
    super(new PacketBuffer[numInputBuffers], new FrameBuffer[numOutputBuffers]);
    if (!DecoderSoLibrary.isAvailable()) {
        throw new VideoSoftDecoderException("Failed to load decoder native libraries.");
    }
    this.exoMediaCrypto = exoMediaCrypto;
    if (exoMediaCrypto != null && !DecoderSoLibrary.ffmpegIsSecureDecodeSupported()) {
        throw new VideoSoftDecoderException("FFmpeg decoder does not support secure decode.");
    }
    String mimeType = format.sampleMimeType;
    String codecName;
    if (mimeType.equals(MimeTypes.VIDEO_H264)) {
        codecName = "h264";
    } else if (mimeType.equals(MimeTypes.VIDEO_H265)) {
        codecName = "hevc";
    } else {
        throw new VideoSoftDecoderException("Unsupported mimetype:" + mimeType);
    }

    int width = format.width;
    int height = format.height;

    ffmpegDecContext = ffmpegInit(codecName,
            width,
            height,
            getExtraData(mimeType, format.initializationData),
            getCpuNumCores() + 1);
    if (ffmpegDecContext == 0) {
        throw new VideoSoftDecoderException("Failed to initialize decoder");
    }
    setInitialInputBufferSize(initialInputBufferSize);
}
 
Example #26
Source File: FfmpegAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected int supportsFormatInternal(DrmSessionManager<ExoMediaCrypto> drmSessionManager,
    Format format) {
  Assertions.checkNotNull(format.sampleMimeType);
  if (!MimeTypes.isAudio(format.sampleMimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  } else if (!FfmpegLibrary.supportsFormat(format.sampleMimeType, format.pcmEncoding)
      || !isOutputSupported(format)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else if (!supportsFormatDrm(drmSessionManager, format.drmInitData)) {
    return FORMAT_UNSUPPORTED_DRM;
  } else {
    return FORMAT_HANDLED;
  }
}
 
Example #27
Source File: FfmpegAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected FfmpegDecoder createDecoder(Format format, ExoMediaCrypto mediaCrypto)
    throws FfmpegDecoderException {
  int initialInputBufferSize =
      format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
  decoder =
      new FfmpegDecoder(
          NUM_BUFFERS, NUM_BUFFERS, initialInputBufferSize, format, shouldUseFloatOutput(format));
  return decoder;
}
 
Example #28
Source File: SoftAudioRenderer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
protected int supportsFormatInternal(DrmSessionManager<ExoMediaCrypto> drmSessionManager,
                                     Format format) {
  Assertions.checkNotNull(format.sampleMimeType);
  if (!DecoderSoLibrary.isAvailable()) {
    return FORMAT_UNSUPPORTED_TYPE;
  } else if (!AudioDecoder.supportsFormat(format.sampleMimeType, format.pcmEncoding)
      || !isOutputSupported(format)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else if (!supportsFormatDrm(drmSessionManager, format.drmInitData)) {
    return FORMAT_UNSUPPORTED_DRM;
  } else {
    return FORMAT_HANDLED;
  }
}
 
Example #29
Source File: SoftAudioRenderer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
protected SimpleDecoder<DecoderInputBuffer, ? extends SimpleOutputBuffer, ? extends AudioSoftDecoderException> createDecoder(Format format, ExoMediaCrypto mediaCrypto) throws AudioSoftDecoderException {
  int initialInputBufferSize =
          format.maxInputSize != Format.NO_VALUE ? format.maxInputSize : DEFAULT_INPUT_BUFFER_SIZE;
  decoder = new AudioDecoder(
                  NUM_BUFFERS, NUM_BUFFERS, initialInputBufferSize, format, shouldUseFloatOutput(format));
  return decoder;
}
 
Example #30
Source File: SoftVideoRenderer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
private void maybeInitDecoder() throws ExoPlaybackException {
  if (videoDecoder != null) {
    return;
  }

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

  try {
    long codecInitializingTimestamp = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("createFFmpegDecoder");
    videoDecoder = new VideoDecoder(format, NUM_INPUT_BUFFERS, NUM_OUTPUT_BUFFERS, INITIAL_INPUT_BUFFER_SIZE,
        mediaCrypto);
    TraceUtil.endSection();
    long codecInitializedTimestamp = SystemClock.elapsedRealtime();
    eventDispatcher.decoderInitialized(videoDecoder.getName(), codecInitializedTimestamp,
        codecInitializedTimestamp - codecInitializingTimestamp);
    decoderCounters.decoderInitCount++;
  } catch (Exception e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }
}