Search in sources :

Example 6 with ExoPlaybackException

use of com.google.android.exoplayer2.ExoPlaybackException in project ExoPlayer by google.

the class ExoPlayerImplInternal method sendMessagesInternal.

private void sendMessagesInternal(ExoPlayerMessage[] messages) throws ExoPlaybackException {
    try {
        for (ExoPlayerMessage message : messages) {
            message.target.handleMessage(message.messageType, message.message);
        }
        if (mediaSource != null) {
            // The message may have caused something to change that now requires us to do work.
            handler.sendEmptyMessage(MSG_DO_SOME_WORK);
        }
    } finally {
        synchronized (this) {
            customMessagesProcessed++;
            notifyAll();
        }
    }
}
Also used : ExoPlayerMessage(com.google.android.exoplayer2.ExoPlayer.ExoPlayerMessage)

Example 7 with ExoPlaybackException

use of com.google.android.exoplayer2.ExoPlaybackException in project ExoPlayer by google.

the class LibvpxVideoRenderer method onEnabled.

@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
    decoderCounters = new DecoderCounters();
    eventDispatcher.enabled(decoderCounters);
}
Also used : DecoderCounters(com.google.android.exoplayer2.decoder.DecoderCounters)

Example 8 with ExoPlaybackException

use of com.google.android.exoplayer2.ExoPlaybackException in project ExoPlayer by google.

the class MediaCodecRenderer method maybeInitCodec.

@SuppressWarnings("deprecation")
protected final void maybeInitCodec() throws ExoPlaybackException {
    if (!shouldInitCodec()) {
        return;
    }
    drmSession = pendingDrmSession;
    String mimeType = format.sampleMimeType;
    MediaCrypto mediaCrypto = null;
    boolean drmSessionRequiresSecureDecoder = false;
    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().getWrappedMediaCrypto();
            drmSessionRequiresSecureDecoder = drmSession.requiresSecureDecoderComponent(mimeType);
        } else {
            // The drm session isn't open yet.
            return;
        }
    }
    MediaCodecInfo decoderInfo = null;
    try {
        decoderInfo = getDecoderInfo(mediaCodecSelector, format, drmSessionRequiresSecureDecoder);
        if (decoderInfo == null && drmSessionRequiresSecureDecoder) {
            // The drm session indicates that a secure decoder is required, but the device does not have
            // one. Assuming that supportsFormat indicated support for the media being played, we know
            // that it does not require a secure output path. Most CDM implementations allow playback to
            // proceed with a non-secure decoder in this case, so we try our luck.
            decoderInfo = getDecoderInfo(mediaCodecSelector, format, false);
            if (decoderInfo != null) {
                Log.w(TAG, "Drm session requires secure decoder for " + mimeType + ", but " + "no secure decoder available. Trying to proceed with " + decoderInfo.name + ".");
            }
        }
    } catch (DecoderQueryException e) {
        throwDecoderInitError(new DecoderInitializationException(format, e, drmSessionRequiresSecureDecoder, DecoderInitializationException.DECODER_QUERY_ERROR));
    }
    if (decoderInfo == null) {
        throwDecoderInitError(new DecoderInitializationException(format, null, drmSessionRequiresSecureDecoder, DecoderInitializationException.NO_SUITABLE_DECODER_ERROR));
    }
    String codecName = decoderInfo.name;
    codecIsAdaptive = decoderInfo.adaptive;
    codecNeedsDiscardToSpsWorkaround = codecNeedsDiscardToSpsWorkaround(codecName, format);
    codecNeedsFlushWorkaround = codecNeedsFlushWorkaround(codecName);
    codecNeedsAdaptationWorkaround = codecNeedsAdaptationWorkaround(codecName);
    codecNeedsEosPropagationWorkaround = codecNeedsEosPropagationWorkaround(codecName);
    codecNeedsEosFlushWorkaround = codecNeedsEosFlushWorkaround(codecName);
    codecNeedsEosOutputExceptionWorkaround = codecNeedsEosOutputExceptionWorkaround(codecName);
    codecNeedsMonoChannelCountWorkaround = codecNeedsMonoChannelCountWorkaround(codecName, format);
    try {
        long codecInitializingTimestamp = SystemClock.elapsedRealtime();
        TraceUtil.beginSection("createCodec:" + codecName);
        codec = MediaCodec.createByCodecName(codecName);
        TraceUtil.endSection();
        TraceUtil.beginSection("configureCodec");
        configureCodec(decoderInfo, codec, format, mediaCrypto);
        TraceUtil.endSection();
        TraceUtil.beginSection("startCodec");
        codec.start();
        TraceUtil.endSection();
        long codecInitializedTimestamp = SystemClock.elapsedRealtime();
        onCodecInitialized(codecName, codecInitializedTimestamp, codecInitializedTimestamp - codecInitializingTimestamp);
        inputBuffers = codec.getInputBuffers();
        outputBuffers = codec.getOutputBuffers();
    } catch (Exception e) {
        throwDecoderInitError(new DecoderInitializationException(format, e, drmSessionRequiresSecureDecoder, codecName));
    }
    codecHotswapDeadlineMs = getState() == STATE_STARTED ? (SystemClock.elapsedRealtime() + MAX_CODEC_HOTSWAP_TIME_MS) : C.TIME_UNSET;
    inputIndex = C.INDEX_UNSET;
    outputIndex = C.INDEX_UNSET;
    waitingForFirstSyncFrame = true;
    decoderCounters.decoderInitCount++;
}
Also used : DecoderQueryException(com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException) ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) CodecException(android.media.MediaCodec.CodecException) CryptoException(android.media.MediaCodec.CryptoException) DecoderQueryException(com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException) FrameworkMediaCrypto(com.google.android.exoplayer2.drm.FrameworkMediaCrypto) MediaCrypto(android.media.MediaCrypto)

Example 9 with ExoPlaybackException

use of com.google.android.exoplayer2.ExoPlaybackException in project ExoPlayer by google.

the class MediaCodecRenderer method onInputFormatChanged.

/**
   * Called when a new format is read from the upstream {@link MediaPeriod}.
   *
   * @param newFormat The new format.
   * @throws ExoPlaybackException If an error occurs reinitializing the {@link MediaCodec}.
   */
protected void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
    Format oldFormat = format;
    format = newFormat;
    boolean drmInitDataChanged = !Util.areEqual(format.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
    if (drmInitDataChanged) {
        if (format.drmInitData != null) {
            if (drmSessionManager == null) {
                throw ExoPlaybackException.createForRenderer(new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
            }
            pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(), format.drmInitData);
            if (pendingDrmSession == drmSession) {
                drmSessionManager.releaseSession(pendingDrmSession);
            }
        } else {
            pendingDrmSession = null;
        }
    }
    if (pendingDrmSession == drmSession && codec != null && canReconfigureCodec(codec, codecIsAdaptive, oldFormat, format)) {
        codecReconfigured = true;
        codecReconfigurationState = RECONFIGURATION_STATE_WRITE_PENDING;
        codecNeedsAdaptationWorkaroundBuffer = codecNeedsAdaptationWorkaround && format.width == oldFormat.width && format.height == oldFormat.height;
    } else {
        if (codecReceivedBuffers) {
            // Signal end of stream and wait for any final output buffers before re-initialization.
            codecReinitializationState = REINITIALIZATION_STATE_SIGNAL_END_OF_STREAM;
        } else {
            // There aren't any final output buffers, so perform re-initialization immediately.
            releaseCodec();
            maybeInitCodec();
        }
    }
}
Also used : MediaFormat(android.media.MediaFormat) Format(com.google.android.exoplayer2.Format)

Example 10 with ExoPlaybackException

use of com.google.android.exoplayer2.ExoPlaybackException in project ExoPlayer by google.

the class LibvpxVideoRenderer method onInputFormatChanged.

private void onInputFormatChanged(Format newFormat) throws ExoPlaybackException {
    Format oldFormat = format;
    format = newFormat;
    boolean drmInitDataChanged = !Util.areEqual(format.drmInitData, oldFormat == null ? null : oldFormat.drmInitData);
    if (drmInitDataChanged) {
        if (format.drmInitData != null) {
            if (drmSessionManager == null) {
                throw ExoPlaybackException.createForRenderer(new IllegalStateException("Media requires a DrmSessionManager"), getIndex());
            }
            pendingDrmSession = drmSessionManager.acquireSession(Looper.myLooper(), format.drmInitData);
            if (pendingDrmSession == drmSession) {
                drmSessionManager.releaseSession(pendingDrmSession);
            }
        } else {
            pendingDrmSession = null;
        }
    }
    eventDispatcher.inputFormatChanged(format);
}
Also used : Format(com.google.android.exoplayer2.Format)

Aggregations

Format (com.google.android.exoplayer2.Format)4 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)3 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)3 DecoderCounters (com.google.android.exoplayer2.decoder.DecoderCounters)2 ExoMediaCrypto (com.google.android.exoplayer2.drm.ExoMediaCrypto)2 DecoderQueryException (com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException)2 SampleStream (com.google.android.exoplayer2.source.SampleStream)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 Point (android.graphics.Point)1 CodecException (android.media.MediaCodec.CodecException)1 CryptoException (android.media.MediaCodec.CryptoException)1 MediaCrypto (android.media.MediaCrypto)1 MediaFormat (android.media.MediaFormat)1 ExoPlayerMessage (com.google.android.exoplayer2.ExoPlayer.ExoPlayerMessage)1 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)1 RendererConfiguration (com.google.android.exoplayer2.RendererConfiguration)1 FrameworkMediaCrypto (com.google.android.exoplayer2.drm.FrameworkMediaCrypto)1 UnsupportedDrmException (com.google.android.exoplayer2.drm.UnsupportedDrmException)1 MediaCodecRenderer (com.google.android.exoplayer2.mediacodec.MediaCodecRenderer)1 DecoderInitializationException (com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.DecoderInitializationException)1