Remove throws clause from Renderer.stop

We don't need the renderer immediately after stopping, so the
renderer should not throw a checked exception until it's used again.
This is inline with the not throwing from disable().

Also, none of the known implementation throw an exception at the moment
and all reasonable base classes omit the throws clause already.

PiperOrigin-RevId: 319503643
This commit is contained in:
tonihei 2020-07-03 13:00:28 +01:00 committed by Ian Baker
parent 113a2df775
commit 08478d1163
6 changed files with 11 additions and 79 deletions

View file

@ -91,6 +91,7 @@
* Add `TrackSelection.shouldCancelMediaChunkLoad` to check whether an
ongoing load should be canceled. Only supported by HLS streams so far.
([#2848](https://github.com/google/ExoPlayer/issues/2848)).
* Remove throws clause from Renderer.stop.
* Video: Pass frame rate hint to `Surface.setFrameRate` on Android R devices.
* Track selection:
* Add `Player.getTrackSelector`.

View file

@ -151,7 +151,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
}
@Override
public final void stop() throws ExoPlaybackException {
public final void stop() {
Assertions.checkState(state == STATE_STARTED);
state = STATE_ENABLED;
onStopped();
@ -255,12 +255,10 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
/**
* Called when the renderer is stopped.
* <p>
* The default implementation is a no-op.
*
* @throws ExoPlaybackException If an error occurs.
* <p>The default implementation is a no-op.
*/
protected void onStopped() throws ExoPlaybackException {
protected void onStopped() {
// Do nothing.
}

View file

@ -130,7 +130,7 @@ public abstract class NoSampleRenderer implements Renderer, RendererCapabilities
}
@Override
public final void stop() throws ExoPlaybackException {
public final void stop() {
Assertions.checkState(state == STATE_STARTED);
state = STATE_ENABLED;
onStopped();
@ -237,12 +237,10 @@ public abstract class NoSampleRenderer implements Renderer, RendererCapabilities
/**
* Called when the renderer is stopped.
* <p>
* The default implementation is a no-op.
*
* @throws ExoPlaybackException If an error occurs.
* <p>The default implementation is a no-op.
*/
protected void onStopped() throws ExoPlaybackException {
protected void onStopped() {
// Do nothing.
}

View file

@ -466,13 +466,11 @@ public interface Renderer extends PlayerMessage.Target {
/**
* Stops the renderer, transitioning it to the {@link #STATE_ENABLED} state.
* <p>
* This method may be called when the renderer is in the following states:
* {@link #STATE_STARTED}.
*
* @throws ExoPlaybackException If an error occurs.
* <p>This method may be called when the renderer is in the following states: {@link
* #STATE_STARTED}.
*/
void stop() throws ExoPlaybackException;
void stop();
/**
* Disable the renderer, transitioning it to the {@link #STATE_DISABLED} state.

View file

@ -6089,69 +6089,6 @@ public final class ExoPlayerTest {
assertThat(trackSelectionsAfterError.get().get(1)).isNotNull(); // Audio renderer.
}
@Test
public void errorThrownDuringRendererDisableAtPeriodTransition_isReportedForCurrentPeriod() {
FakeMediaSource source1 =
new FakeMediaSource(
new FakeTimeline(/* windowCount= */ 1), ExoPlayerTestRunner.VIDEO_FORMAT);
FakeMediaSource source2 =
new FakeMediaSource(
new FakeTimeline(/* windowCount= */ 1), ExoPlayerTestRunner.AUDIO_FORMAT);
FakeRenderer videoRenderer =
new FakeRenderer(C.TRACK_TYPE_VIDEO) {
@Override
protected void onStopped() throws ExoPlaybackException {
// Fail when stopping the renderer. This will happen during the period transition.
throw createRendererException(
new IllegalStateException(), ExoPlayerTestRunner.VIDEO_FORMAT);
}
};
FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
AtomicReference<TrackGroupArray> trackGroupsAfterError = new AtomicReference<>();
AtomicReference<TrackSelectionArray> trackSelectionsAfterError = new AtomicReference<>();
AtomicInteger windowIndexAfterError = new AtomicInteger();
ActionSchedule actionSchedule =
new ActionSchedule.Builder(TAG)
.executeRunnable(
new PlayerRunnable() {
@Override
public void run(SimpleExoPlayer player) {
player.addAnalyticsListener(
new AnalyticsListener() {
@Override
public void onPlayerError(
EventTime eventTime, ExoPlaybackException error) {
trackGroupsAfterError.set(player.getCurrentTrackGroups());
trackSelectionsAfterError.set(player.getCurrentTrackSelections());
windowIndexAfterError.set(player.getCurrentWindowIndex());
}
});
}
})
.build();
ExoPlayerTestRunner testRunner =
new ExoPlayerTestRunner.Builder(context)
.setMediaSources(source1, source2)
.setActionSchedule(actionSchedule)
.setRenderers(videoRenderer, audioRenderer)
.build();
assertThrows(
ExoPlaybackException.class,
() ->
testRunner
.start(/* doPrepare= */ true)
.blockUntilActionScheduleFinished(TIMEOUT_MS)
.blockUntilEnded(TIMEOUT_MS));
assertThat(windowIndexAfterError.get()).isEqualTo(0);
assertThat(trackGroupsAfterError.get().length).isEqualTo(1);
assertThat(trackGroupsAfterError.get().get(0).getFormat(0))
.isEqualTo(ExoPlayerTestRunner.VIDEO_FORMAT);
assertThat(trackSelectionsAfterError.get().get(0)).isNotNull(); // Video renderer.
assertThat(trackSelectionsAfterError.get().get(1)).isNull(); // Audio renderer.
}
// TODO(b/150584930): Fix reporting of renderer errors.
@Ignore
@Test

View file

@ -63,7 +63,7 @@ public class FakeVideoRenderer extends FakeRenderer {
}
@Override
protected void onStopped() throws ExoPlaybackException {
protected void onStopped() {
super.onStopped();
eventDispatcher.droppedFrames(/* droppedFrameCount= */ 0, /* elapsedMs= */ 0);
eventDispatcher.reportVideoFrameProcessingOffset(