com.google.android.exoplayer2.util.TraceUtil Java Examples

The following examples show how to use com.google.android.exoplayer2.util.TraceUtil. 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: MediaCodecVideoRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
@TargetApi(21)
private void renderOutputBufferV21(MediaCodec codec, int bufferIndex, long releaseTimeNs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(bufferIndex, releaseTimeNs);
  TraceUtil.endSection();
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #2
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Renders the output buffer with the specified index. This method is only called if the platform
 * API version of the device is less than 21.
 *
 * @param codec The codec that owns the output buffer.
 * @param index The index of the output buffer to drop.
 * @param presentationTimeUs The presentation time of the output buffer, in microseconds.
 */
protected void renderOutputBuffer(MediaCodec codec, int index, long presentationTimeUs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(index, true);
  TraceUtil.endSection();
  lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000;
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #3
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Renders the output buffer with the specified index. This method is only called if the platform
 * API version of the device is 21 or later.
 *
 * @param codec The codec that owns the output buffer.
 * @param index The index of the output buffer to drop.
 * @param presentationTimeUs The presentation time of the output buffer, in microseconds.
 * @param releaseTimeNs The wallclock time at which the frame should be displayed, in nanoseconds.
 */
@TargetApi(21)
protected void renderOutputBufferV21(
    MediaCodec codec, int index, long presentationTimeUs, long releaseTimeNs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(index, releaseTimeNs);
  TraceUtil.endSection();
  lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000;
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #4
Source File: SoftVideoRenderer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
  if (outputStreamEnded) {
    return;
  }

  if (format == null) {
    // We don't have a format yet, so try and read one.
    flagsOnlyBuffer.clear();
    int result = readSource(formatHolder, flagsOnlyBuffer, true);
    if (result == C.RESULT_FORMAT_READ) {
      onInputFormatChanged(formatHolder.format);
    } else if (result == C.RESULT_BUFFER_READ) {
      // End of stream read having not read a format.
      Assertions.checkState(flagsOnlyBuffer.isEndOfStream());
      inputStreamEnded = true;
      outputStreamEnded = true;
      return;
    } else {
      // We still don't have a format and can't make progress without one.
      return;
    }
  }

  // If we don't have a videoDecoder yet, we need to instantiate one.
  maybeInitDecoder();

  if (videoDecoder != null) {
    try {
      // Rendering loop.
      TraceUtil.beginSection("drainAndFeed");
      while (drainOutputBuffer(positionUs)) {}
      while (feedInputBuffer()) {}
      TraceUtil.endSection();
    } catch (VideoSoftDecoderException e) {
      throw ExoPlaybackException.createForRenderer(e, getIndex());
    }
    decoderCounters.ensureUpdated();
  }
}
 
Example #5
Source File: MediaCodecRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
  if (pendingOutputEndOfStream) {
    pendingOutputEndOfStream = false;
    processEndOfStream();
  }
  try {
    if (outputStreamEnded) {
      renderToEndOfStream();
      return;
    }
    if (inputFormat == null && !readToFlagsOnlyBuffer(/* requireFormat= */ true)) {
      // We still don't have a format and can't make progress without one.
      return;
    }
    // We have a format.
    maybeInitCodec();
    if (codec != null) {
      long drainStartTimeMs = SystemClock.elapsedRealtime();
      TraceUtil.beginSection("drainAndFeed");
      while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
      while (feedInputBuffer() && shouldContinueFeeding(drainStartTimeMs)) {}
      TraceUtil.endSection();
    } else {
      decoderCounters.skippedInputBufferCount += skipSource(positionUs);
      // We need to read any format changes despite not having a codec so that drmSession can be
      // updated, and so that we have the most recent format should the codec be initialized. We
      // may also reach the end of the stream. Note that readSource will not read a sample into a
      // flags-only buffer.
      readToFlagsOnlyBuffer(/* requireFormat= */ false);
    }
    decoderCounters.ensureUpdated();
  } catch (IllegalStateException e) {
    if (isMediaCodecException(e)) {
      throw createRendererException(e, inputFormat);
    }
    throw e;
  }
}
 
Example #6
Source File: MediaCodecRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
  if (outputStreamEnded) {
    renderToEndOfStream();
    return;
  }
  if (format == null) {
    // We don't have a format yet, so try and read one.
    buffer.clear();
    int result = readSource(formatHolder, buffer, true);
    if (result == C.RESULT_FORMAT_READ) {
      onInputFormatChanged(formatHolder.format);
    } else if (result == C.RESULT_BUFFER_READ) {
      // End of stream read having not read a format.
      Assertions.checkState(buffer.isEndOfStream());
      inputStreamEnded = true;
      processEndOfStream();
      return;
    } else {
      // We still don't have a format and can't make progress without one.
      return;
    }
  }
  maybeInitCodec();
  if (codec != null) {
    TraceUtil.beginSection("drainAndFeed");
    while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
    while (feedInputBuffer()) {}
    TraceUtil.endSection();
  } else if (format != null) {
    skipToKeyframeBefore(positionUs);
  }
  decoderCounters.ensureUpdated();
}
 
Example #7
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 #8
Source File: MediaCodecVideoRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
private void dropOutputBuffer(MediaCodec codec, int bufferIndex) {
  TraceUtil.beginSection("dropVideoBuffer");
  codec.releaseOutputBuffer(bufferIndex, false);
  TraceUtil.endSection();
  decoderCounters.droppedOutputBufferCount++;
  droppedFrames++;
  consecutiveDroppedFrameCount++;
  decoderCounters.maxConsecutiveDroppedOutputBufferCount = Math.max(consecutiveDroppedFrameCount,
      decoderCounters.maxConsecutiveDroppedOutputBufferCount);
  if (droppedFrames == maxDroppedFramesToNotify) {
    maybeNotifyDroppedFrames();
  }
}
 
Example #9
Source File: MediaCodecVideoRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
private void renderOutputBuffer(MediaCodec codec, int bufferIndex) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(bufferIndex, true);
  TraceUtil.endSection();
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #10
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());
  }
}
 
Example #11
Source File: MediaCodecRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
  if (outputStreamEnded) {
    renderToEndOfStream();
    return;
  }
  if (inputFormat == null && !readToFlagsOnlyBuffer(/* requireFormat= */ true)) {
      // We still don't have a format and can't make progress without one.
      return;
  }
  // We have a format.
  maybeInitCodec();
  if (codec != null) {
    long drainStartTimeMs = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("drainAndFeed");
    while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
    while (feedInputBuffer() && shouldContinueFeeding(drainStartTimeMs)) {}
    TraceUtil.endSection();
  } else {
    decoderCounters.skippedInputBufferCount += skipSource(positionUs);
    // We need to read any format changes despite not having a codec so that drmSession can be
    // updated, and so that we have the most recent format should the codec be initialized. We may
    // also reach the end of the stream. Note that readSource will not read a sample into a
    // flags-only buffer.
    readToFlagsOnlyBuffer(/* requireFormat= */ false);
  }
  decoderCounters.ensureUpdated();
}
 
Example #12
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 #13
Source File: MediaCodecVideoRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Renders the output buffer with the specified index. This method is only called if the platform
 * API version of the device is less than 21.
 *
 * @param codec The codec that owns the output buffer.
 * @param index The index of the output buffer to drop.
 * @param presentationTimeUs The presentation time of the output buffer, in microseconds.
 */
protected void renderOutputBuffer(MediaCodec codec, int index, long presentationTimeUs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(index, true);
  TraceUtil.endSection();
  lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000;
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #14
Source File: MediaCodecVideoRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Renders the output buffer with the specified index. This method is only called if the platform
 * API version of the device is 21 or later.
 *
 * @param codec The codec that owns the output buffer.
 * @param index The index of the output buffer to drop.
 * @param presentationTimeUs The presentation time of the output buffer, in microseconds.
 * @param releaseTimeNs The wallclock time at which the frame should be displayed, in nanoseconds.
 */
@TargetApi(21)
protected void renderOutputBufferV21(
    MediaCodec codec, int index, long presentationTimeUs, long releaseTimeNs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(index, releaseTimeNs);
  TraceUtil.endSection();
  lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000;
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #15
Source File: MediaCodecRenderer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
  if (outputStreamEnded) {
    renderToEndOfStream();
    return;
  }
  if (inputFormat == null && !readToFlagsOnlyBuffer(/* requireFormat= */ true)) {
      // We still don't have a format and can't make progress without one.
      return;
  }
  // We have a format.
  maybeInitCodec();
  if (codec != null) {
    long drainStartTimeMs = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("drainAndFeed");
    while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
    while (feedInputBuffer() && shouldContinueFeeding(drainStartTimeMs)) {}
    TraceUtil.endSection();
  } else {
    decoderCounters.skippedInputBufferCount += skipSource(positionUs);
    // We need to read any format changes despite not having a codec so that drmSession can be
    // updated, and so that we have the most recent format should the codec be initialized. We may
    // also reach the end of the stream. Note that readSource will not read a sample into a
    // flags-only buffer.
    readToFlagsOnlyBuffer(/* requireFormat= */ false);
  }
  decoderCounters.ensureUpdated();
}
 
Example #16
Source File: SimpleDecoderAudioRenderer.java    From Telegram 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 #17
Source File: MediaCodecVideoRenderer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Renders the output buffer with the specified index. This method is only called if the platform
 * API version of the device is less than 21.
 *
 * @param codec The codec that owns the output buffer.
 * @param index The index of the output buffer to drop.
 * @param presentationTimeUs The presentation time of the output buffer, in microseconds.
 */
protected void renderOutputBuffer(MediaCodec codec, int index, long presentationTimeUs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(index, true);
  TraceUtil.endSection();
  lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000;
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #18
Source File: MediaCodecVideoRenderer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Renders the output buffer with the specified index. This method is only called if the platform
 * API version of the device is 21 or later.
 *
 * @param codec The codec that owns the output buffer.
 * @param index The index of the output buffer to drop.
 * @param presentationTimeUs The presentation time of the output buffer, in microseconds.
 * @param releaseTimeNs The wallclock time at which the frame should be displayed, in nanoseconds.
 */
@TargetApi(21)
protected void renderOutputBufferV21(
    MediaCodec codec, int index, long presentationTimeUs, long releaseTimeNs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(index, releaseTimeNs);
  TraceUtil.endSection();
  lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000;
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #19
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 #20
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void initCodec(MediaCodecInfo codecInfo, MediaCrypto crypto) throws Exception {
  long codecInitializingTimestamp;
  long codecInitializedTimestamp;
  MediaCodec codec = null;
  String name = codecInfo.name;
  updateCodecOperatingRate();
  boolean configureWithOperatingRate = codecOperatingRate > assumedMinimumCodecOperatingRate;
  try {
    codecInitializingTimestamp = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("createCodec:" + name);
    codec = MediaCodec.createByCodecName(name);
    TraceUtil.endSection();
    TraceUtil.beginSection("configureCodec");
    configureCodec(
        codecInfo,
        codec,
        format,
        crypto,
        configureWithOperatingRate ? codecOperatingRate : CODEC_OPERATING_RATE_UNSET);
    codecConfiguredWithOperatingRate = configureWithOperatingRate;
    TraceUtil.endSection();
    TraceUtil.beginSection("startCodec");
    codec.start();
    TraceUtil.endSection();
    codecInitializedTimestamp = SystemClock.elapsedRealtime();
    getCodecBuffers(codec);
  } catch (Exception e) {
    if (codec != null) {
      resetCodecBuffers();
      codec.release();
    }
    throw e;
  }
  this.codec = codec;
  this.codecInfo = codecInfo;
  long elapsed = codecInitializedTimestamp - codecInitializingTimestamp;
  onCodecInitialized(name, codecInitializedTimestamp, elapsed);
}
 
Example #21
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Renders the output buffer with the specified index. This method is only called if the platform
 * API version of the device is 21 or later.
 *
 * @param codec The codec that owns the output buffer.
 * @param index The index of the output buffer to drop.
 * @param presentationTimeUs The presentation time of the output buffer, in microseconds.
 * @param releaseTimeNs The wallclock time at which the frame should be displayed, in nanoseconds.
 */
@TargetApi(21)
protected void renderOutputBufferV21(
    MediaCodec codec, int index, long presentationTimeUs, long releaseTimeNs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(index, releaseTimeNs);
  TraceUtil.endSection();
  lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000;
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #22
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Renders the output buffer with the specified index. This method is only called if the platform
 * API version of the device is less than 21.
 *
 * @param codec The codec that owns the output buffer.
 * @param index The index of the output buffer to drop.
 * @param presentationTimeUs The presentation time of the output buffer, in microseconds.
 */
protected void renderOutputBuffer(MediaCodec codec, int index, long presentationTimeUs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(index, true);
  TraceUtil.endSection();
  lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000;
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #23
Source File: SimpleDecoderAudioRenderer.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 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 createRendererException(e, inputFormat);
  }
}
 
Example #24
Source File: MediaCodecVideoRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Renders the output buffer with the specified index. This method is only called if the platform
 * API version of the device is less than 21.
 *
 * @param codec The codec that owns the output buffer.
 * @param index The index of the output buffer to drop.
 * @param presentationTimeUs The presentation time of the output buffer, in microseconds.
 */
protected void renderOutputBuffer(MediaCodec codec, int index, long presentationTimeUs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(index, true);
  TraceUtil.endSection();
  lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000;
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #25
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 #26
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void initCodec(MediaCodecInfo codecInfo, MediaCrypto crypto) throws Exception {
  long codecInitializingTimestamp;
  long codecInitializedTimestamp;
  MediaCodec codec = null;
  String name = codecInfo.name;
  updateCodecOperatingRate();
  boolean configureWithOperatingRate = codecOperatingRate > assumedMinimumCodecOperatingRate;
  try {
    codecInitializingTimestamp = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("createCodec:" + name);
    codec = MediaCodec.createByCodecName(name);
    TraceUtil.endSection();
    TraceUtil.beginSection("configureCodec");
    configureCodec(
        codecInfo,
        codec,
        format,
        crypto,
        configureWithOperatingRate ? codecOperatingRate : CODEC_OPERATING_RATE_UNSET);
    codecConfiguredWithOperatingRate = configureWithOperatingRate;
    TraceUtil.endSection();
    TraceUtil.beginSection("startCodec");
    codec.start();
    TraceUtil.endSection();
    codecInitializedTimestamp = SystemClock.elapsedRealtime();
    getCodecBuffers(codec);
  } catch (Exception e) {
    if (codec != null) {
      resetCodecBuffers();
      codec.release();
    }
    throw e;
  }
  this.codec = codec;
  this.codecInfo = codecInfo;
  long elapsed = codecInitializedTimestamp - codecInitializingTimestamp;
  onCodecInitialized(name, codecInitializedTimestamp, elapsed);
}
 
Example #27
Source File: MediaCodecVideoRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Renders the output buffer with the specified index. This method is only called if the platform
 * API version of the device is 21 or later.
 *
 * @param codec The codec that owns the output buffer.
 * @param index The index of the output buffer to drop.
 * @param presentationTimeUs The presentation time of the output buffer, in microseconds.
 * @param releaseTimeNs The wallclock time at which the frame should be displayed, in nanoseconds.
 */
@TargetApi(21)
protected void renderOutputBufferV21(
    MediaCodec codec, int index, long presentationTimeUs, long releaseTimeNs) {
  maybeNotifyVideoSizeChanged();
  TraceUtil.beginSection("releaseOutputBuffer");
  codec.releaseOutputBuffer(index, releaseTimeNs);
  TraceUtil.endSection();
  lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000;
  decoderCounters.renderedOutputBufferCount++;
  consecutiveDroppedFrameCount = 0;
  maybeNotifyRenderedFirstFrame();
}
 
Example #28
Source File: SimpleDecoderVideoRenderer.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
  if (outputStreamEnded) {
    return;
  }

  if (inputFormat == null) {
    // We don't have a format yet, so try and read one.
    FormatHolder formatHolder = getFormatHolder();
    flagsOnlyBuffer.clear();
    int result = readSource(formatHolder, flagsOnlyBuffer, true);
    if (result == C.RESULT_FORMAT_READ) {
      onInputFormatChanged(formatHolder);
    } else if (result == C.RESULT_BUFFER_READ) {
      // End of stream read having not read a format.
      Assertions.checkState(flagsOnlyBuffer.isEndOfStream());
      inputStreamEnded = true;
      outputStreamEnded = true;
      return;
    } else {
      // We still don't have a format and can't make progress without one.
      return;
    }
  }

  // If we don't have a decoder yet, we need to instantiate one.
  maybeInitDecoder();

  if (decoder != null) {
    try {
      // Rendering loop.
      TraceUtil.beginSection("drainAndFeed");
      while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
      while (feedInputBuffer()) {}
      TraceUtil.endSection();
    } catch (VideoDecoderException e) {
      throw createRendererException(e, inputFormat);
    }
    decoderCounters.ensureUpdated();
  }
}
 
Example #29
Source File: MediaCodecRenderer.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private void initCodec(MediaCodecInfo codecInfo, MediaCrypto crypto) throws Exception {
  long codecInitializingTimestamp;
  long codecInitializedTimestamp;
  MediaCodec codec = null;
  String codecName = codecInfo.name;

  float codecOperatingRate =
      Util.SDK_INT < 23
          ? CODEC_OPERATING_RATE_UNSET
          : getCodecOperatingRateV23(rendererOperatingRate, inputFormat, getStreamFormats());
  if (codecOperatingRate <= assumedMinimumCodecOperatingRate) {
    codecOperatingRate = CODEC_OPERATING_RATE_UNSET;
  }
  try {
    codecInitializingTimestamp = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("createCodec:" + codecName);
    codec = MediaCodec.createByCodecName(codecName);
    TraceUtil.endSection();
    TraceUtil.beginSection("configureCodec");
    configureCodec(codecInfo, codec, inputFormat, crypto, codecOperatingRate);
    TraceUtil.endSection();
    TraceUtil.beginSection("startCodec");
    codec.start();
    TraceUtil.endSection();
    codecInitializedTimestamp = SystemClock.elapsedRealtime();
    getCodecBuffers(codec);
  } catch (Exception e) {
    if (codec != null) {
      resetCodecBuffers();
      codec.release();
    }
    throw e;
  }

  this.codec = codec;
  this.codecInfo = codecInfo;
  this.codecOperatingRate = codecOperatingRate;
  codecFormat = inputFormat;
  codecAdaptationWorkaroundMode = codecAdaptationWorkaroundMode(codecName);
  codecNeedsReconfigureWorkaround = codecNeedsReconfigureWorkaround(codecName);
  codecNeedsDiscardToSpsWorkaround = codecNeedsDiscardToSpsWorkaround(codecName, codecFormat);
  codecNeedsFlushWorkaround = codecNeedsFlushWorkaround(codecName);
  codecNeedsEosFlushWorkaround = codecNeedsEosFlushWorkaround(codecName);
  codecNeedsEosOutputExceptionWorkaround = codecNeedsEosOutputExceptionWorkaround(codecName);
  codecNeedsMonoChannelCountWorkaround =
      codecNeedsMonoChannelCountWorkaround(codecName, codecFormat);
  codecNeedsEosPropagation =
      codecNeedsEosPropagationWorkaround(codecInfo) || getCodecNeedsEosPropagation();

  resetInputBuffer();
  resetOutputBuffer();
  codecHotswapDeadlineMs =
      getState() == STATE_STARTED
          ? (SystemClock.elapsedRealtime() + MAX_CODEC_HOTSWAP_TIME_MS)
          : C.TIME_UNSET;
  codecReconfigured = false;
  codecReconfigurationState = RECONFIGURATION_STATE_NONE;
  codecReceivedEos = false;
  codecReceivedBuffers = false;
  largestQueuedPresentationTimeUs = C.TIME_UNSET;
  lastBufferInStreamPresentationTimeUs = C.TIME_UNSET;
  codecDrainState = DRAIN_STATE_NONE;
  codecDrainAction = DRAIN_ACTION_NONE;
  codecNeedsAdaptationWorkaroundBuffer = false;
  shouldSkipAdaptationWorkaroundOutputBuffer = false;
  isDecodeOnlyOutputBuffer = false;
  isLastOutputBuffer = false;
  waitingForFirstSyncSample = true;

  decoderCounters.decoderInitCount++;
  long elapsed = codecInitializedTimestamp - codecInitializingTimestamp;
  onCodecInitialized(codecName, codecInitializedTimestamp, elapsed);
}
 
Example #30
Source File: MediaCodecRenderer.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void initCodec(MediaCodecInfo codecInfo, MediaCrypto crypto) throws Exception {
  long codecInitializingTimestamp;
  long codecInitializedTimestamp;
  MediaCodec codec = null;
  String codecName = codecInfo.name;

  float codecOperatingRate =
      Util.SDK_INT < 23
          ? CODEC_OPERATING_RATE_UNSET
          : getCodecOperatingRateV23(rendererOperatingRate, inputFormat, getStreamFormats());
  if (codecOperatingRate <= assumedMinimumCodecOperatingRate) {
    codecOperatingRate = CODEC_OPERATING_RATE_UNSET;
  }
  try {
    codecInitializingTimestamp = SystemClock.elapsedRealtime();
    TraceUtil.beginSection("createCodec:" + codecName);
    codec = MediaCodec.createByCodecName(codecName);
    TraceUtil.endSection();
    TraceUtil.beginSection("configureCodec");
    configureCodec(codecInfo, codec, inputFormat, crypto, codecOperatingRate);
    TraceUtil.endSection();
    TraceUtil.beginSection("startCodec");
    codec.start();
    TraceUtil.endSection();
    codecInitializedTimestamp = SystemClock.elapsedRealtime();
    getCodecBuffers(codec);
  } catch (Exception e) {
    if (codec != null) {
      resetCodecBuffers();
      codec.release();
    }
    throw e;
  }

  this.codec = codec;
  this.codecInfo = codecInfo;
  this.codecOperatingRate = codecOperatingRate;
  codecFormat = inputFormat;
  codecAdaptationWorkaroundMode = codecAdaptationWorkaroundMode(codecName);
  codecNeedsReconfigureWorkaround = codecNeedsReconfigureWorkaround(codecName);
  codecNeedsDiscardToSpsWorkaround = codecNeedsDiscardToSpsWorkaround(codecName, codecFormat);
  codecNeedsFlushWorkaround = codecNeedsFlushWorkaround(codecName);
  codecNeedsEosFlushWorkaround = codecNeedsEosFlushWorkaround(codecName);
  codecNeedsEosOutputExceptionWorkaround = codecNeedsEosOutputExceptionWorkaround(codecName);
  codecNeedsMonoChannelCountWorkaround =
      codecNeedsMonoChannelCountWorkaround(codecName, codecFormat);
  codecNeedsEosPropagation =
      codecNeedsEosPropagationWorkaround(codecInfo) || getCodecNeedsEosPropagation();

  resetInputBuffer();
  resetOutputBuffer();
  codecHotswapDeadlineMs =
      getState() == STATE_STARTED
          ? (SystemClock.elapsedRealtime() + MAX_CODEC_HOTSWAP_TIME_MS)
          : C.TIME_UNSET;
  codecReconfigured = false;
  codecReconfigurationState = RECONFIGURATION_STATE_NONE;
  codecReceivedEos = false;
  codecReceivedBuffers = false;
  codecDrainState = DRAIN_STATE_NONE;
  codecDrainAction = DRAIN_ACTION_NONE;
  codecNeedsAdaptationWorkaroundBuffer = false;
  shouldSkipAdaptationWorkaroundOutputBuffer = false;
  isDecodeOnlyOutputBuffer = false;
  isLastOutputBuffer = false;
  waitingForFirstSyncSample = true;

  decoderCounters.decoderInitCount++;
  long elapsed = codecInitializedTimestamp - codecInitializingTimestamp;
  onCodecInitialized(codecName, codecInitializedTimestamp, elapsed);
}