com.google.android.exoplayer2.ExoPlaybackException Java Examples

The following examples show how to use com.google.android.exoplayer2.ExoPlaybackException. 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: LocalPlayback.java    From YouTube-In-Background with MIT License 9 votes vote down vote up
@Override
public void onPlayerError(ExoPlaybackException error)
{
    final String what;
    switch (error.type) {
        case ExoPlaybackException.TYPE_SOURCE:
            what = error.getSourceException().getMessage();
            break;
        case ExoPlaybackException.TYPE_RENDERER:
            what = error.getRendererException().getMessage();
            break;
        case ExoPlaybackException.TYPE_UNEXPECTED:
            what = error.getUnexpectedException().getMessage();
            break;
        default:
            what = "Unknown: " + error;
    }

    LogHelper.e(TAG, "ExoPlayer error: what=" + what);
    if (callback != null) {
        callback.onError("ExoPlayer error " + what);
    }
}
 
Example #2
Source File: MediaCodecRenderer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Processes an end of stream signal.
 *
 * @throws ExoPlaybackException If an error occurs processing the signal.
 */
private void processEndOfStream() throws ExoPlaybackException {
  switch (codecDrainAction) {
    case DRAIN_ACTION_REINITIALIZE:
      reinitializeCodec();
      break;
    case DRAIN_ACTION_UPDATE_DRM_SESSION:
      updateDrmSessionOrReinitializeCodecV23();
      break;
    case DRAIN_ACTION_FLUSH:
      flushOrReinitializeCodec();
      break;
    case DRAIN_ACTION_NONE:
    default:
      outputStreamEnded = true;
      renderToEndOfStream();
      break;
  }
}
 
Example #3
Source File: MediaCodecAudioRenderer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void handleMessage(int messageType, @Nullable Object message) throws ExoPlaybackException {
  switch (messageType) {
    case C.MSG_SET_VOLUME:
      audioSink.setVolume((Float) message);
      break;
    case C.MSG_SET_AUDIO_ATTRIBUTES:
      AudioAttributes audioAttributes = (AudioAttributes) message;
      audioSink.setAudioAttributes(audioAttributes);
      break;
    case C.MSG_SET_AUX_EFFECT_INFO:
      AuxEffectInfo auxEffectInfo = (AuxEffectInfo) message;
      audioSink.setAuxEffectInfo(auxEffectInfo);
      break;
    default:
      super.handleMessage(messageType, message);
      break;
  }
}
 
Example #4
Source File: MediaCodecVideoRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void handleMessage(int messageType, @Nullable Object message) throws ExoPlaybackException {
  if (messageType == C.MSG_SET_SURFACE) {
    setSurface((Surface) message);
  } else if (messageType == C.MSG_SET_SCALING_MODE) {
    scalingMode = (Integer) message;
    MediaCodec codec = getCodec();
    if (codec != null) {
      codec.setVideoScalingMode(scalingMode);
    }
  } else if (messageType == C.MSG_SET_VIDEO_FRAME_METADATA_LISTENER) {
    frameMetadataListener = (VideoFrameMetadataListener) message;
  } else {
    super.handleMessage(messageType, message);
  }
}
 
Example #5
Source File: MediaCodecRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates the codec operating rate.
 *
 * @throws ExoPlaybackException If an error occurs releasing or initializing a codec.
 */
private void updateCodecOperatingRate() throws ExoPlaybackException {
  if (Util.SDK_INT < 23) {
    return;
  }

  float newCodecOperatingRate =
      getCodecOperatingRateV23(rendererOperatingRate, codecFormat, getStreamFormats());
  if (codecOperatingRate == newCodecOperatingRate) {
    // No change.
  } else if (newCodecOperatingRate == CODEC_OPERATING_RATE_UNSET) {
    // The only way to clear the operating rate is to instantiate a new codec instance. See
    // [Internal ref: b/71987865].
    drainAndReinitializeCodec();
  } else if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET
      || newCodecOperatingRate > assumedMinimumCodecOperatingRate) {
    // We need to set the operating rate, either because we've set it previously or because it's
    // above the assumed minimum rate.
    Bundle codecParameters = new Bundle();
    codecParameters.putFloat(MediaFormat.KEY_OPERATING_RATE, newCodecOperatingRate);
    codec.setParameters(codecParameters);
    codecOperatingRate = newCodecOperatingRate;
  }
}
 
Example #6
Source File: DefaultTrackSelector.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Called by {@link #selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)} to create a
 * {@link TrackSelection} for a video renderer.
 *
 * @param groups The {@link TrackGroupArray} mapped to the renderer.
 * @param formatSupports The {@link Capabilities} for each mapped track, indexed by renderer,
 *     track group and track (in that order).
 * @param mixedMimeTypeAdaptationSupports The {@link AdaptiveSupport} for mixed MIME type
 *     adaptation for the renderer.
 * @param params The selector's current constraint parameters.
 * @param enableAdaptiveTrackSelection Whether adaptive track selection is allowed.
 * @return The {@link TrackSelection.Definition} for the renderer, or null if no selection was
 *     made.
 * @throws ExoPlaybackException If an error occurs while selecting the tracks.
 */
@Nullable
protected TrackSelection.Definition selectVideoTrack(
    TrackGroupArray groups,
    @Capabilities int[][] formatSupports,
    @AdaptiveSupport int mixedMimeTypeAdaptationSupports,
    Parameters params,
    boolean enableAdaptiveTrackSelection)
    throws ExoPlaybackException {
  TrackSelection.Definition definition = null;
  if (!params.forceHighestSupportedBitrate
      && !params.forceLowestBitrate
      && enableAdaptiveTrackSelection) {
    definition =
        selectAdaptiveVideoTrack(groups, formatSupports, mixedMimeTypeAdaptationSupports, params);
  }
  if (definition == null) {
    definition = selectFixedVideoTrack(groups, formatSupports, params);
  }
  return definition;
}
 
Example #7
Source File: Alarmio.java    From Alarmio with Apache License 2.0 6 votes vote down vote up
@Override
public void onPlayerError(ExoPlaybackException error) {
    String lastStream = currentStream;
    currentStream = null;
    Exception exception;
    switch (error.type) {
        case ExoPlaybackException.TYPE_RENDERER:
            exception = error.getRendererException();
            break;
        case ExoPlaybackException.TYPE_SOURCE:
            if (lastStream != null && error.getSourceException().getMessage().contains("does not start with the #EXTM3U header")) {
                playStream(lastStream, SoundData.TYPE_RADIO, progressiveMediaSourceFactory);
                return;
            }
            exception = error.getSourceException();
            break;
        case ExoPlaybackException.TYPE_UNEXPECTED:
            exception = error.getUnexpectedException();
            break;
        default:
            return;
    }

    exception.printStackTrace();
    Toast.makeText(this, exception.getClass().getName() + ": " + exception.getMessage(), Toast.LENGTH_SHORT).show();
}
 
Example #8
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onStreamChanged(Format[] formats, long offsetUs) throws ExoPlaybackException {
  if (outputStreamOffsetUs == C.TIME_UNSET) {
    outputStreamOffsetUs = offsetUs;
  } else {
    if (pendingOutputStreamOffsetCount == pendingOutputStreamOffsetsUs.length) {
      Log.w(TAG, "Too many stream changes, so dropping offset: "
          + pendingOutputStreamOffsetsUs[pendingOutputStreamOffsetCount - 1]);
    } else {
      pendingOutputStreamOffsetCount++;
    }
    pendingOutputStreamOffsetsUs[pendingOutputStreamOffsetCount - 1] = offsetUs;
    pendingOutputStreamSwitchTimesUs[pendingOutputStreamOffsetCount - 1] = lastInputTimeUs;
  }
  super.onStreamChanged(formats, offsetUs);
}
 
Example #9
Source File: MediaCodecVideoRenderer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
protected void onStreamChanged(Format[] formats, long offsetUs) throws ExoPlaybackException {
  if (outputStreamOffsetUs == C.TIME_UNSET) {
    outputStreamOffsetUs = offsetUs;
  } else {
    if (pendingOutputStreamOffsetCount == pendingOutputStreamOffsetsUs.length) {
      Log.w(TAG, "Too many stream changes, so dropping offset: "
          + pendingOutputStreamOffsetsUs[pendingOutputStreamOffsetCount - 1]);
    } else {
      pendingOutputStreamOffsetCount++;
    }
    pendingOutputStreamOffsetsUs[pendingOutputStreamOffsetCount - 1] = offsetUs;
    pendingOutputStreamSwitchTimesUs[pendingOutputStreamOffsetCount - 1] = lastInputTimeUs;
  }
  super.onStreamChanged(formats, offsetUs);
}
 
Example #10
Source File: SimpleDecoderAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleMessage(int messageType, Object message) throws ExoPlaybackException {
  switch (messageType) {
    case C.MSG_SET_VOLUME:
      audioSink.setVolume((Float) message);
      break;
    case C.MSG_SET_AUDIO_ATTRIBUTES:
      AudioAttributes audioAttributes = (AudioAttributes) message;
      audioSink.setAudioAttributes(audioAttributes);
      break;
    default:
      super.handleMessage(messageType, message);
      break;
  }
}
 
Example #11
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected void flushCodec() throws ExoPlaybackException {
  codecHotswapDeadlineMs = C.TIME_UNSET;
  resetInputBuffer();
  resetOutputBuffer();
  waitingForFirstSyncFrame = true;
  waitingForKeys = false;
  shouldSkipOutputBuffer = false;
  decodeOnlyPresentationTimestamps.clear();
  codecNeedsAdaptationWorkaroundBuffer = false;
  shouldSkipAdaptationWorkaroundOutputBuffer = false;
  if (codecNeedsFlushWorkaround || (codecNeedsEosFlushWorkaround && codecReceivedEos)) {
    releaseCodec();
    maybeInitCodec();
  } else if (codecReinitializationState != REINITIALIZATION_STATE_NONE) {
    // We're already waiting to release and re-initialize the codec. Since we're now flushing,
    // there's no need to wait any longer.
    releaseCodec();
    maybeInitCodec();
  } else {
    // We can flush and re-use the existing decoder.
    codec.flush();
    codecReceivedBuffers = false;
  }
  if (codecReconfigured && format != null) {
    // Any reconfiguration data that we send shortly before the flush may be discarded. We
    // avoid this issue by sending reconfiguration data following every flush.
    codecReconfigurationState = RECONFIGURATION_STATE_WRITE_PENDING;
  }
}
 
Example #12
Source File: MediaCodecRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Processes an end of stream signal.
 *
 * @throws ExoPlaybackException If an error occurs processing the signal.
 */
private void processEndOfStream() throws ExoPlaybackException {
  if (codecReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM) {
    // We're waiting to re-initialize the codec, and have now processed all final buffers.
    releaseCodec();
    maybeInitCodec();
  } else {
    outputStreamEnded = true;
    renderToEndOfStream();
  }
}
 
Example #13
Source File: SimpleDecoderVideoRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a new format is read from the upstream source.
 *
 * @param formatHolder A {@link FormatHolder} that holds the new {@link Format}.
 * @throws ExoPlaybackException If an error occurs (re-)initializing the decoder.
 */
@CallSuper
@SuppressWarnings("unchecked")
protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
  waitingForFirstSampleInFormat = true;
  Format newFormat = Assertions.checkNotNull(formatHolder.format);
  if (formatHolder.includesDrmSession) {
    setSourceDrmSession((DrmSession<ExoMediaCrypto>) formatHolder.drmSession);
  } else {
    sourceDrmSession =
        getUpdatedSourceDrmSession(inputFormat, newFormat, drmSessionManager, sourceDrmSession);
  }
  inputFormat = newFormat;

  if (sourceDrmSession != decoderDrmSession) {
    if (decoderReceivedBuffers) {
      // Signal end of stream and wait for any final output buffers before re-initialization.
      decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM;
    } else {
      // There aren't any final output buffers, so release the decoder immediately.
      releaseDecoder();
      maybeInitDecoder();
    }
  }

  eventDispatcher.inputFormatChanged(inputFormat);
}
 
Example #14
Source File: MediaCodecVideoRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
  super.onInputFormatChanged(newFormat);
  eventDispatcher.inputFormatChanged(newFormat);
  pendingPixelWidthHeightRatio = newFormat.pixelWidthHeightRatio;
  pendingRotationDegrees = newFormat.rotationDegrees;
}
 
Example #15
Source File: SimpleDecoderAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
  Format oldFormat = inputFormat;
  inputFormat = newFormat;

  boolean drmInitDataChanged = !Util.areEqual(inputFormat.drmInitData, oldFormat == null ? null
      : oldFormat.drmInitData);
  if (drmInitDataChanged) {
    if (inputFormat.drmInitData != null) {
      if (drmSessionManager == null) {
        throw ExoPlaybackException.createForRenderer(
            new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
      }
      pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(),
          inputFormat.drmInitData);
      if (pendingDrmSession == drmSession) {
        drmSessionManager.releaseSession(pendingDrmSession);
      }
    } else {
      pendingDrmSession = null;
    }
  }

  if (decoderReceivedBuffers) {
    // Signal end of stream and wait for any final output buffers before re-initialization.
    decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM;
  } else {
    // There aren't any final output buffers, so release the decoder immediately.
    releaseDecoder();
    maybeInitDecoder();
    audioTrackNeedsConfigure = true;
  }

  encoderDelay = newFormat.encoderDelay;
  encoderPadding = newFormat.encoderPadding;

  eventDispatcher.inputFormatChanged(newFormat);
}
 
Example #16
Source File: MediaCodecAudioRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
protected void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
  super.onInputFormatChanged(newFormat);
  eventDispatcher.inputFormatChanged(newFormat);
  // If the input format is anything other than PCM then we assume that the audio decoder will
  // output 16-bit PCM.
  pcmEncoding = MimeTypes.AUDIO_RAW.equals(newFormat.sampleMimeType) ? newFormat.pcmEncoding
      : C.ENCODING_PCM_16BIT;
  channelCount = newFormat.channelCount;
}
 
Example #17
Source File: SimpleDecoderVideoRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to dequeue an output buffer from the decoder and, if successful, passes it to {@link
 * #processOutputBuffer(long, long)}.
 *
 * @param positionUs The player's current position.
 * @param elapsedRealtimeUs {@link SystemClock#elapsedRealtime()} in microseconds,
 *     measured at the start of the current iteration of the rendering loop.
 * @return Whether it may be possible to drain more output data.
 * @throws ExoPlaybackException If an error occurs draining the output buffer.
 */
private boolean drainOutputBuffer(long positionUs, long elapsedRealtimeUs)
    throws ExoPlaybackException, VideoDecoderException {
  if (outputBuffer == null) {
    outputBuffer = decoder.dequeueOutputBuffer();
    if (outputBuffer == null) {
      return false;
    }
    decoderCounters.skippedOutputBufferCount += outputBuffer.skippedOutputBufferCount;
    buffersInCodecCount -= outputBuffer.skippedOutputBufferCount;
  }

  if (outputBuffer.isEndOfStream()) {
    if (decoderReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM) {
      // We're waiting to re-initialize the decoder, and have now processed all final buffers.
      releaseDecoder();
      maybeInitDecoder();
    } else {
      outputBuffer.release();
      outputBuffer = null;
      outputStreamEnded = true;
    }
    return false;
  }

  boolean processedOutputBuffer = processOutputBuffer(positionUs, elapsedRealtimeUs);
  if (processedOutputBuffer) {
    onProcessedOutputBuffer(outputBuffer.timeUs);
    outputBuffer = null;
  }
  return processedOutputBuffer;
}
 
Example #18
Source File: MediaCodecVideoRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
  super.onEnabled(joining);
  int oldTunnelingAudioSessionId = tunnelingAudioSessionId;
  tunnelingAudioSessionId = getConfiguration().tunnelingAudioSessionId;
  tunneling = tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET;
  if (tunnelingAudioSessionId != oldTunnelingAudioSessionId) {
    releaseCodec();
  }
  eventDispatcher.enabled(decoderCounters);
  frameReleaseTimeHelper.enable();
}
 
Example #19
Source File: MediaCodecRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
protected void flushCodec() throws ExoPlaybackException {
  codecHotswapDeadlineMs = C.TIME_UNSET;
  inputIndex = C.INDEX_UNSET;
  outputIndex = C.INDEX_UNSET;
  waitingForFirstSyncFrame = true;
  waitingForKeys = false;
  shouldSkipOutputBuffer = false;
  decodeOnlyPresentationTimestamps.clear();
  codecNeedsAdaptationWorkaroundBuffer = false;
  shouldSkipAdaptationWorkaroundOutputBuffer = false;
  if (codecNeedsFlushWorkaround || (codecNeedsEosFlushWorkaround && codecReceivedEos)) {
    releaseCodec();
    maybeInitCodec();
  } else if (codecReinitializationState != REINITIALIZATION_STATE_NONE) {
    // We're already waiting to release and re-initialize the codec. Since we're now flushing,
    // there's no need to wait any longer.
    releaseCodec();
    maybeInitCodec();
  } else {
    // We can flush and re-use the existing decoder.
    codec.flush();
    codecReceivedBuffers = false;
  }
  if (codecReconfigured && format != null) {
    // Any reconfiguration data that we send shortly before the flush may be discarded. We
    // avoid this issue by sending reconfiguration data following every flush.
    codecReconfigurationState = RECONFIGURATION_STATE_WRITE_PENDING;
  }
}
 
Example #20
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private boolean shouldWaitForKeys(boolean bufferEncrypted) throws ExoPlaybackException {
  if (drmSession == null || (!bufferEncrypted && playClearSamplesWithoutKeys)) {
    return false;
  }
  @DrmSession.State int drmSessionState = drmSession.getState();
  if (drmSessionState == DrmSession.STATE_ERROR) {
    throw ExoPlaybackException.createForRenderer(drmSession.getError(), getIndex());
  }
  return drmSessionState != DrmSession.STATE_OPENED_WITH_KEYS;
}
 
Example #21
Source File: DebugSimpleExoPlayer.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
@Override
protected void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
  super.onInputFormatChanged(newFormat);
  // Ensure timestamps of buffers queued after this format change are never inserted into the
  // queue of expected output timestamps before those of buffers that have already been queued.
  minimumInsertIndex = startIndex + queueSize;
}
 
Example #22
Source File: MediaCodecVideoRenderer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
  super.onInputFormatChanged(newFormat);
  eventDispatcher.inputFormatChanged(newFormat);
  pendingPixelWidthHeightRatio = newFormat.pixelWidthHeightRatio;
  pendingRotationDegrees = newFormat.rotationDegrees;
}
 
Example #23
Source File: MediaCodecRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final int supportsFormat(Format format) throws ExoPlaybackException {
  try {
    return supportsFormat(mediaCodecSelector, drmSessionManager, format);
  } catch (DecoderQueryException e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }
}
 
Example #24
Source File: SimpleDecoderAudioRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
  Format newFormat = Assertions.checkNotNull(formatHolder.format);
  if (formatHolder.includesDrmSession) {
    setSourceDrmSession((DrmSession<ExoMediaCrypto>) formatHolder.drmSession);
  } else {
    sourceDrmSession =
        getUpdatedSourceDrmSession(inputFormat, newFormat, drmSessionManager, sourceDrmSession);
  }
  Format oldFormat = inputFormat;
  inputFormat = newFormat;

  if (!canKeepCodec(oldFormat, inputFormat)) {
    if (decoderReceivedBuffers) {
      // Signal end of stream and wait for any final output buffers before re-initialization.
      decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM;
    } else {
      // There aren't any final output buffers, so release the decoder immediately.
      releaseDecoder();
      maybeInitDecoder();
      audioTrackNeedsConfigure = true;
    }
  }

  encoderDelay = inputFormat.encoderDelay;
  encoderPadding = inputFormat.encoderPadding;

  eventDispatcher.inputFormatChanged(inputFormat);
}
 
Example #25
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the codec operating rate, and the codec itself if necessary.
 *
 * @throws ExoPlaybackException If an error occurs releasing or initializing a codec.
 */
private void updateCodecOperatingRate() throws ExoPlaybackException {
  if (format == null || Util.SDK_INT < 23) {
    return;
  }

  float codecOperatingRate =
      getCodecOperatingRate(rendererOperatingRate, format, getStreamFormats());
  if (this.codecOperatingRate == codecOperatingRate) {
    return;
  }

  this.codecOperatingRate = codecOperatingRate;
  if (codec == null || codecReinitializationState != REINITIALIZATION_STATE_NONE) {
    // Either no codec, or it's about to be reinitialized anyway.
  } else if (codecOperatingRate == CODEC_OPERATING_RATE_UNSET
      && codecConfiguredWithOperatingRate) {
    // We need to clear the operating rate. The only way to do so is to instantiate a new codec
    // instance. See [Internal ref: b/71987865].
    reinitializeCodec();
  } else if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET
      && (codecConfiguredWithOperatingRate
          || codecOperatingRate > assumedMinimumCodecOperatingRate)) {
    // We need to set the operating rate, either because we've set it previously or because it's
    // above the assumed minimum rate.
    Bundle codecParameters = new Bundle();
    codecParameters.putFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    codec.setParameters(codecParameters);
    codecConfiguredWithOperatingRate = true;
  }
}
 
Example #26
Source File: DefaultTrackSelector.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called by {@link #selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)} to create a
 * {@link TrackSelection} for a renderer whose type is neither video, audio or text.
 *
 * @param trackType The type of the renderer.
 * @param groups The {@link TrackGroupArray} mapped to the renderer.
 * @param formatSupport The result of {@link RendererCapabilities#supportsFormat} for each mapped
 *     track, indexed by track group index and track index (in that order).
 * @param params The selector's current constraint parameters.
 * @return The {@link TrackSelection} for the renderer, or null if no selection was made.
 * @throws ExoPlaybackException If an error occurs while selecting the tracks.
 */
@Nullable
protected TrackSelection.Definition selectOtherTrack(
    int trackType, TrackGroupArray groups, int[][] formatSupport, Parameters params)
    throws ExoPlaybackException {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex],
          params.exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore = isDefault ? 2 : 1;
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null
      ? null
      : new TrackSelection.Definition(selectedGroup, selectedTrackIndex);
}
 
Example #27
Source File: MediaCodecAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
  super.onEnabled(joining);
  eventDispatcher.enabled(decoderCounters);
  int tunnelingAudioSessionId = getConfiguration().tunnelingAudioSessionId;
  if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) {
    audioSink.enableTunnelingV21(tunnelingAudioSessionId);
  } else {
    audioSink.disableTunneling();
  }
}
 
Example #28
Source File: SimpleDecoderAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException {
  audioSink.flush();
  currentPositionUs = positionUs;
  allowFirstBufferPositionDiscontinuity = true;
  allowPositionDiscontinuity = true;
  inputStreamEnded = false;
  outputStreamEnded = false;
  if (decoder != null) {
    flushDecoder();
  }
}
 
Example #29
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected void flushCodec() throws ExoPlaybackException {
  codecHotswapDeadlineMs = C.TIME_UNSET;
  resetInputBuffer();
  resetOutputBuffer();
  waitingForFirstSyncFrame = true;
  waitingForKeys = false;
  shouldSkipOutputBuffer = false;
  decodeOnlyPresentationTimestamps.clear();
  codecNeedsAdaptationWorkaroundBuffer = false;
  shouldSkipAdaptationWorkaroundOutputBuffer = false;
  if (codecNeedsFlushWorkaround || (codecNeedsEosFlushWorkaround && codecReceivedEos)) {
    releaseCodec();
    maybeInitCodec();
  } else if (codecReinitializationState != REINITIALIZATION_STATE_NONE) {
    // We're already waiting to release and re-initialize the codec. Since we're now flushing,
    // there's no need to wait any longer.
    releaseCodec();
    maybeInitCodec();
  } else {
    // We can flush and re-use the existing decoder.
    codec.flush();
    codecReceivedBuffers = false;
  }
  if (codecReconfigured && format != null) {
    // Any reconfiguration data that we send shortly before the flush may be discarded. We
    // avoid this issue by sending reconfiguration data following every flush.
    codecReconfigurationState = RECONFIGURATION_STATE_WRITE_PENDING;
  }
}
 
Example #30
Source File: SimpleDecoderAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
  Format oldFormat = inputFormat;
  inputFormat = newFormat;

  boolean drmInitDataChanged = !Util.areEqual(inputFormat.drmInitData, oldFormat == null ? null
      : oldFormat.drmInitData);
  if (drmInitDataChanged) {
    if (inputFormat.drmInitData != null) {
      if (drmSessionManager == null) {
        throw ExoPlaybackException.createForRenderer(
            new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
      }
      pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(),
          inputFormat.drmInitData);
      if (pendingDrmSession == drmSession) {
        drmSessionManager.releaseSession(pendingDrmSession);
      }
    } else {
      pendingDrmSession = null;
    }
  }

  if (decoderReceivedBuffers) {
    // Signal end of stream and wait for any final output buffers before re-initialization.
    decoderReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM;
  } else {
    // There aren't any final output buffers, so release the decoder immediately.
    releaseDecoder();
    maybeInitDecoder();
    audioTrackNeedsConfigure = true;
  }

  encoderDelay = newFormat.encoderDelay;
  encoderPadding = newFormat.encoderPadding;

  eventDispatcher.inputFormatChanged(newFormat);
}