/* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.android.exoplayer2; import com.google.android.exoplayer2.ExoPlayer.ExoPlayerComponent; import com.google.android.exoplayer2.source.SampleStream; import com.google.android.exoplayer2.util.MediaClock; import java.io.IOException; /** * Renders media read from a {@link SampleStream}. *
* Internally, a renderer's lifecycle is managed by the owning {@link ExoPlayer}. The renderer is * transitioned through various states as the overall playback state changes. The valid state * transitions are shown below, annotated with the methods that are called during each transition. *
*
*
* This method may be called when the renderer is in the following states: * {@link #STATE_DISABLED}. * * @param formats The enabled formats. * @param stream The {@link SampleStream} from which the renderer should consume. * @param positionUs The player's current position. * @param joining Whether this renderer is being enabled to join an ongoing playback. * @param offsetUs The offset to be added to timestamps of buffers read from {@code stream} * before they are rendered. * @throws ExoPlaybackException If an error occurs. */ void enable(Format[] formats, SampleStream stream, long positionUs, boolean joining, long offsetUs) throws ExoPlaybackException; /** * Starts the renderer, meaning that calls to {@link #render(long, long)} will cause media to be * rendered. *
* This method may be called when the renderer is in the following states: * {@link #STATE_ENABLED}. * * @throws ExoPlaybackException If an error occurs. */ void start() throws ExoPlaybackException; /** * Replaces the {@link SampleStream} from which samples will be consumed. *
* This method may be called when the renderer is in the following states: * {@link #STATE_ENABLED}, {@link #STATE_STARTED}. * * @param formats The enabled formats. * @param stream The {@link SampleStream} from which the renderer should consume. * @param offsetUs The offset to be added to timestamps of buffers read from {@code stream} before * they are rendered. * @throws ExoPlaybackException If an error occurs. */ void replaceStream(Format[] formats, SampleStream stream, long offsetUs) throws ExoPlaybackException; /** * Returns the {@link SampleStream} being consumed, or null if the renderer is disabled. */ SampleStream getStream(); /** * Returns whether the renderer has read the current {@link SampleStream} to the end. *
* This method may be called when the renderer is in the following states: * {@link #STATE_ENABLED}, {@link #STATE_STARTED}. */ boolean hasReadStreamToEnd(); /** * Signals to the renderer that the current {@link SampleStream} will be the final one supplied * before it is next disabled or reset. *
* This method may be called when the renderer is in the following states: * {@link #STATE_ENABLED}, {@link #STATE_STARTED}. */ void setCurrentStreamIsFinal(); /** * Throws an error that's preventing the renderer from reading from its {@link SampleStream}. Does * nothing if no such error exists. *
* This method may be called when the renderer is in the following states: * {@link #STATE_ENABLED}, {@link #STATE_STARTED}. * * @throws IOException An error that's preventing the renderer from making progress or buffering * more data. */ void maybeThrowStreamError() throws IOException; /** * Signals to the renderer that a position discontinuity has occurred. *
* After a position discontinuity, the renderer's {@link SampleStream} is guaranteed to provide * samples starting from a key frame. *
* This method may be called when the renderer is in the following states: * {@link #STATE_ENABLED}, {@link #STATE_STARTED}. * * @param positionUs The new playback position in microseconds. * @throws ExoPlaybackException If an error occurs handling the reset. */ void resetPosition(long positionUs) throws ExoPlaybackException; /** * Incrementally renders the {@link SampleStream}. *
* If the renderer is in the {@link #STATE_ENABLED} state then each call to this method will do * work toward being ready to render the {@link SampleStream} when the renderer is started. It may * also render the very start of the media, for example the first frame of a video stream. If the * renderer is in the {@link #STATE_STARTED} state then calls to this method will render the * {@link SampleStream} in sync with the specified media positions. *
* This method should return quickly, and should not block if the renderer is unable to make * useful progress. *
* This method may be called when the renderer is in the following states: * {@link #STATE_ENABLED}, {@link #STATE_STARTED}. * * @param positionUs The current media time in microseconds, measured at the start of the * current iteration of the rendering loop. * @param elapsedRealtimeUs {@link android.os.SystemClock#elapsedRealtime()} in microseconds, * measured at the start of the current iteration of the rendering loop. * @throws ExoPlaybackException If an error occurs. */ void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException; /** * Whether the renderer is able to immediately render media from the current position. *
* If the renderer is in the {@link #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 {@link #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: * {@link #STATE_ENABLED}, {@link #STATE_STARTED}. * * @return Whether the renderer is ready to render media. */ boolean isReady(); /** * Whether the renderer is ready for the {@link ExoPlayer} instance to transition to * {@link ExoPlayer#STATE_ENDED}. The player will make this transition as soon as {@code true} is * returned by all of its {@link Renderer}s. *
* This method may be called when the renderer is in the following states: * {@link #STATE_ENABLED}, {@link #STATE_STARTED}. * * @return Whether the renderer is ready for the player to transition to the ended state. */ boolean isEnded(); /** * Stops the renderer, transitioning it to the {@link #STATE_ENABLED} state. *
* This method may be called when the renderer is in the following states: * {@link #STATE_STARTED}. * * @throws ExoPlaybackException If an error occurs. */ void stop() throws ExoPlaybackException; /** * Disable the renderer, transitioning it to the {@link #STATE_DISABLED} state. *
* This method may be called when the renderer is in the following states: * {@link #STATE_ENABLED}. */ void disable(); }