Class DecoderVideoRenderer

    • Field Detail

      • decoderCounters

        protected DecoderCounters decoderCounters
        Decoder event counters used for debugging purposes.
    • Constructor Detail

      • DecoderVideoRenderer

        protected DecoderVideoRenderer​(long allowedJoiningTimeMs,
                                       @Nullable
                                       Handler eventHandler,
                                       @Nullable
                                       VideoRendererEventListener eventListener,
                                       int maxDroppedFramesToNotify)
        Parameters:
        allowedJoiningTimeMs - The maximum duration in milliseconds for which this video renderer can attempt to seamlessly join an ongoing playback.
        eventHandler - A handler to use when delivering events to eventListener. May be null if delivery of events is not required.
        eventListener - A listener of events. May be null if delivery of events is not required.
        maxDroppedFramesToNotify - The maximum number of frames that can be dropped between invocations of VideoRendererEventListener.onDroppedFrames(int, long).
    • Method Detail

      • isEnded

        public boolean isEnded()
        Description copied from interface: Renderer
        Whether the renderer is ready for the ExoPlayer instance to transition to Player.STATE_ENDED. The player will make this transition as soon as true is returned by all of its renderers.

        This method may be called when the renderer is in the following states: Renderer.STATE_ENABLED, Renderer.STATE_STARTED.

        Returns:
        Whether the renderer is ready for the player to transition to the ended state.
      • isReady

        public boolean isReady()
        Description copied from interface: Renderer
        Whether the renderer is able to immediately render media from the current position.

        If the renderer is in the Renderer.STATE_STARTED state then returning true indicates that the renderer has everything that it needs to continue playback. Returning false indicates that the player should pause until the renderer is ready.

        If the renderer is in the Renderer.STATE_ENABLED state then returning true indicates that the renderer is ready for playback to be started. Returning false indicates that it is not.

        This method may be called when the renderer is in the following states: Renderer.STATE_ENABLED, Renderer.STATE_STARTED.

        Returns:
        Whether the renderer is ready to render media.
      • onEnabled

        protected void onEnabled​(boolean joining,
                                 boolean mayRenderStartOfStream)
                          throws ExoPlaybackException
        Description copied from class: BaseRenderer
        Called when the renderer is enabled.

        The default implementation is a no-op.

        Overrides:
        onEnabled in class BaseRenderer
        Parameters:
        joining - Whether this renderer is being enabled to join an ongoing playback.
        mayRenderStartOfStream - Whether this renderer is allowed to render the start of the stream even if the state is not Renderer.STATE_STARTED yet.
        Throws:
        ExoPlaybackException - If an error occurs.
      • onPositionReset

        protected void onPositionReset​(long positionUs,
                                       boolean joining)
                                throws ExoPlaybackException
        Description copied from class: BaseRenderer
        Called when the position is reset. This occurs when the renderer is enabled after BaseRenderer.onStreamChanged(Format[], long, long) has been called, and also when a position discontinuity is encountered.

        After a position reset, the renderer's SampleStream is guaranteed to provide samples starting from a key frame.

        The default implementation is a no-op.

        Overrides:
        onPositionReset in class BaseRenderer
        Parameters:
        positionUs - The new playback position in microseconds.
        joining - Whether this renderer is being enabled to join an ongoing playback.
        Throws:
        ExoPlaybackException - If an error occurs.
      • onStarted

        protected void onStarted()
        Description copied from class: BaseRenderer
        Called when the renderer is started.

        The default implementation is a no-op.

        Overrides:
        onStarted in class BaseRenderer
      • onStopped

        protected void onStopped()
        Description copied from class: BaseRenderer
        Called when the renderer is stopped.

        The default implementation is a no-op.

        Overrides:
        onStopped in class BaseRenderer
      • onDisabled

        protected void onDisabled()
        Description copied from class: BaseRenderer
        Called when the renderer is disabled.

        The default implementation is a no-op.

        Overrides:
        onDisabled in class BaseRenderer
      • releaseDecoder

        @CallSuper
        protected void releaseDecoder()
        Releases the decoder.
      • onQueueInputBuffer

        protected void onQueueInputBuffer​(VideoDecoderInputBuffer buffer)
        Called immediately before an input buffer is queued into the decoder.

        The default implementation is a no-op.

        Parameters:
        buffer - The buffer that will be queued.
      • onProcessedOutputBuffer

        @CallSuper
        protected void onProcessedOutputBuffer​(long presentationTimeUs)
        Called when an output buffer is successfully processed.
        Parameters:
        presentationTimeUs - The timestamp associated with the output buffer.
      • shouldDropOutputBuffer

        protected boolean shouldDropOutputBuffer​(long earlyUs,
                                                 long elapsedRealtimeUs)
        Returns whether the buffer being processed should be dropped.
        Parameters:
        earlyUs - The time until the buffer should be presented in microseconds. A negative value indicates that the buffer is late.
        elapsedRealtimeUs - SystemClock.elapsedRealtime() in microseconds, measured at the start of the current iteration of the rendering loop.
      • shouldDropBuffersToKeyframe

        protected boolean shouldDropBuffersToKeyframe​(long earlyUs,
                                                      long elapsedRealtimeUs)
        Returns whether to drop all buffers from the buffer being processed to the keyframe at or after the current playback position, if possible.
        Parameters:
        earlyUs - The time until the current buffer should be presented in microseconds. A negative value indicates that the buffer is late.
        elapsedRealtimeUs - SystemClock.elapsedRealtime() in microseconds, measured at the start of the current iteration of the rendering loop.
      • shouldForceRenderOutputBuffer

        protected boolean shouldForceRenderOutputBuffer​(long earlyUs,
                                                        long elapsedSinceLastRenderUs)
        Returns whether to force rendering an output buffer.
        Parameters:
        earlyUs - The time until the current buffer should be presented in microseconds. A negative value indicates that the buffer is late.
        elapsedSinceLastRenderUs - The elapsed time since the last output buffer was rendered, in microseconds.
        Returns:
        Returns whether to force rendering an output buffer.
      • skipOutputBuffer

        protected void skipOutputBuffer​(VideoDecoderOutputBuffer outputBuffer)
        Skips the specified output buffer and releases it.
        Parameters:
        outputBuffer - The output buffer to skip.
      • dropOutputBuffer

        protected void dropOutputBuffer​(VideoDecoderOutputBuffer outputBuffer)
        Drops the specified output buffer and releases it.
        Parameters:
        outputBuffer - The output buffer to drop.
      • maybeDropBuffersToKeyframe

        protected boolean maybeDropBuffersToKeyframe​(long positionUs)
                                              throws ExoPlaybackException
        Drops frames from the current output buffer to the next keyframe at or before the playback position. If no such keyframe exists, as the playback position is inside the same group of pictures as the buffer being processed, returns false. Returns true otherwise.
        Parameters:
        positionUs - The current playback position, in microseconds.
        Returns:
        Whether any buffers were dropped.
        Throws:
        ExoPlaybackException - If an error occurs flushing the decoder.
      • updateDroppedBufferCounters

        protected void updateDroppedBufferCounters​(int droppedBufferCount)
        Updates decoder counters to reflect that droppedBufferCount additional buffers were dropped.
        Parameters:
        droppedBufferCount - The number of additional dropped buffers.
      • setOutput

        protected final void setOutput​(@Nullable
                                       Object output)
        Sets the video output.
      • setDecoderOutputMode

        protected abstract void setDecoderOutputMode​(@VideoOutputMode
                                                     int outputMode)
        Sets output mode of the decoder.
        Parameters:
        outputMode - Output mode.
      • canReuseDecoder

        protected DecoderReuseEvaluation canReuseDecoder​(String decoderName,
                                                         Format oldFormat,
                                                         Format newFormat)
        Evaluates whether the existing decoder can be reused for a new Format.

        The default implementation does not allow decoder reuse.

        Parameters:
        oldFormat - The previous format.
        newFormat - The new format.
        Returns:
        The result of the evaluation.