Commit 08478d11 by tonihei Committed by Ian Baker

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
parent 113a2df7
...@@ -91,6 +91,7 @@ ...@@ -91,6 +91,7 @@
* Add `TrackSelection.shouldCancelMediaChunkLoad` to check whether an * Add `TrackSelection.shouldCancelMediaChunkLoad` to check whether an
ongoing load should be canceled. Only supported by HLS streams so far. ongoing load should be canceled. Only supported by HLS streams so far.
([#2848](https://github.com/google/ExoPlayer/issues/2848)). ([#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. * Video: Pass frame rate hint to `Surface.setFrameRate` on Android R devices.
* Track selection: * Track selection:
* Add `Player.getTrackSelector`. * Add `Player.getTrackSelector`.
......
...@@ -151,7 +151,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities { ...@@ -151,7 +151,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
} }
@Override @Override
public final void stop() throws ExoPlaybackException { public final void stop() {
Assertions.checkState(state == STATE_STARTED); Assertions.checkState(state == STATE_STARTED);
state = STATE_ENABLED; state = STATE_ENABLED;
onStopped(); onStopped();
...@@ -255,12 +255,10 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities { ...@@ -255,12 +255,10 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
/** /**
* Called when the renderer is stopped. * 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. // Do nothing.
} }
......
...@@ -130,7 +130,7 @@ public abstract class NoSampleRenderer implements Renderer, RendererCapabilities ...@@ -130,7 +130,7 @@ public abstract class NoSampleRenderer implements Renderer, RendererCapabilities
} }
@Override @Override
public final void stop() throws ExoPlaybackException { public final void stop() {
Assertions.checkState(state == STATE_STARTED); Assertions.checkState(state == STATE_STARTED);
state = STATE_ENABLED; state = STATE_ENABLED;
onStopped(); onStopped();
...@@ -237,12 +237,10 @@ public abstract class NoSampleRenderer implements Renderer, RendererCapabilities ...@@ -237,12 +237,10 @@ public abstract class NoSampleRenderer implements Renderer, RendererCapabilities
/** /**
* Called when the renderer is stopped. * 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. // Do nothing.
} }
......
...@@ -466,13 +466,11 @@ public interface Renderer extends PlayerMessage.Target { ...@@ -466,13 +466,11 @@ public interface Renderer extends PlayerMessage.Target {
/** /**
* Stops the renderer, transitioning it to the {@link #STATE_ENABLED} state. * 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. * Disable the renderer, transitioning it to the {@link #STATE_DISABLED} state.
......
...@@ -6089,69 +6089,6 @@ public final class ExoPlayerTest { ...@@ -6089,69 +6089,6 @@ public final class ExoPlayerTest {
assertThat(trackSelectionsAfterError.get().get(1)).isNotNull(); // Audio renderer. 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. // TODO(b/150584930): Fix reporting of renderer errors.
@Ignore @Ignore
@Test @Test
......
...@@ -63,7 +63,7 @@ public class FakeVideoRenderer extends FakeRenderer { ...@@ -63,7 +63,7 @@ public class FakeVideoRenderer extends FakeRenderer {
} }
@Override @Override
protected void onStopped() throws ExoPlaybackException { protected void onStopped() {
super.onStopped(); super.onStopped();
eventDispatcher.droppedFrames(/* droppedFrameCount= */ 0, /* elapsedMs= */ 0); eventDispatcher.droppedFrames(/* droppedFrameCount= */ 0, /* elapsedMs= */ 0);
eventDispatcher.reportVideoFrameProcessingOffset( eventDispatcher.reportVideoFrameProcessingOffset(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment