Commit 33cc8448 by kimvde Committed by Marc Baechinger

Change FallbackListener registerTrack to setTrackCount

AssetLoader declares the tracks with a setTrackCount() method. Setting
the track count on the FallbackListener is easier than calling
registerTrack() as many times as the number of tracks.

PiperOrigin-RevId: 496919969
parent f6434c67
...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.transformer; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.transformer;
import static com.google.android.exoplayer2.util.Assertions.checkState; import static com.google.android.exoplayer2.util.Assertions.checkState;
import androidx.annotation.IntRange;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.util.HandlerWrapper; import com.google.android.exoplayer2.util.HandlerWrapper;
...@@ -61,13 +62,13 @@ import com.google.android.exoplayer2.util.Util; ...@@ -61,13 +62,13 @@ import com.google.android.exoplayer2.util.Util;
} }
/** /**
* Registers an output track. * Sets the number of output tracks.
* *
* <p>All tracks must be registered before a transformation request is {@linkplain * <p>The track count must be set before a transformation request is {@linkplain
* #onTransformationRequestFinalized(TransformationRequest) finalized}. * #onTransformationRequestFinalized(TransformationRequest) finalized}.
*/ */
public void registerTrack() { public void setTrackCount(@IntRange(from = 1) int trackCount) {
trackCount++; this.trackCount = trackCount;
} }
/** /**
...@@ -82,8 +83,8 @@ import com.google.android.exoplayer2.util.Util; ...@@ -82,8 +83,8 @@ import com.google.android.exoplayer2.util.Util;
* TransformationRequest)} once this method has been called for each track. * TransformationRequest)} once this method has been called for each track.
* *
* @param transformationRequest The final {@link TransformationRequest} for a track. * @param transformationRequest The final {@link TransformationRequest} for a track.
* @throws IllegalStateException If called for more tracks than registered using {@link * @throws IllegalStateException If called for more tracks than declared in {@link
* #registerTrack()}. * #setTrackCount(int)}.
*/ */
public void onTransformationRequestFinalized(TransformationRequest transformationRequest) { public void onTransformationRequestFinalized(TransformationRequest transformationRequest) {
checkState(trackCount-- > 0); checkState(trackCount-- > 0);
......
...@@ -417,8 +417,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -417,8 +417,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
for (int i = 0; i < trackCount.get(); i++) { for (int i = 0; i < trackCount.get(); i++) {
muxerWrapper.registerTrack(); muxerWrapper.registerTrack();
fallbackListener.registerTrack();
} }
fallbackListener.setTrackCount(trackCount.get());
} }
SamplePipeline samplePipeline = SamplePipeline samplePipeline =
......
...@@ -40,7 +40,7 @@ public class FallbackListenerTest { ...@@ -40,7 +40,7 @@ public class FallbackListenerTest {
private static final MediaItem PLACEHOLDER_MEDIA_ITEM = MediaItem.fromUri(Uri.EMPTY); private static final MediaItem PLACEHOLDER_MEDIA_ITEM = MediaItem.fromUri(Uri.EMPTY);
@Test @Test
public void onTransformationRequestFinalized_withoutTrackRegistration_throwsException() { public void onTransformationRequestFinalized_withoutTrackCountSet_throwsException() {
TransformationRequest transformationRequest = new TransformationRequest.Builder().build(); TransformationRequest transformationRequest = new TransformationRequest.Builder().build();
FallbackListener fallbackListener = FallbackListener fallbackListener =
new FallbackListener( new FallbackListener(
...@@ -52,13 +52,13 @@ public class FallbackListenerTest { ...@@ -52,13 +52,13 @@ public class FallbackListenerTest {
} }
@Test @Test
public void onTransformationRequestFinalized_afterTrackRegistration_completesSuccessfully() { public void onTransformationRequestFinalized_afterTrackCountSet_completesSuccessfully() {
TransformationRequest transformationRequest = new TransformationRequest.Builder().build(); TransformationRequest transformationRequest = new TransformationRequest.Builder().build();
FallbackListener fallbackListener = FallbackListener fallbackListener =
new FallbackListener( new FallbackListener(
PLACEHOLDER_MEDIA_ITEM, createListenerSet(), createHandler(), transformationRequest); PLACEHOLDER_MEDIA_ITEM, createListenerSet(), createHandler(), transformationRequest);
fallbackListener.registerTrack(); fallbackListener.setTrackCount(1);
fallbackListener.onTransformationRequestFinalized(transformationRequest); fallbackListener.onTransformationRequestFinalized(transformationRequest);
ShadowLooper.idleMainLooper(); ShadowLooper.idleMainLooper();
} }
...@@ -76,7 +76,7 @@ public class FallbackListenerTest { ...@@ -76,7 +76,7 @@ public class FallbackListenerTest {
createHandler(), createHandler(),
originalRequest); originalRequest);
fallbackListener.registerTrack(); fallbackListener.setTrackCount(1);
fallbackListener.onTransformationRequestFinalized(unchangedRequest); fallbackListener.onTransformationRequestFinalized(unchangedRequest);
ShadowLooper.idleMainLooper(); ShadowLooper.idleMainLooper();
...@@ -97,7 +97,7 @@ public class FallbackListenerTest { ...@@ -97,7 +97,7 @@ public class FallbackListenerTest {
createHandler(), createHandler(),
originalRequest); originalRequest);
fallbackListener.registerTrack(); fallbackListener.setTrackCount(1);
fallbackListener.onTransformationRequestFinalized(audioFallbackRequest); fallbackListener.onTransformationRequestFinalized(audioFallbackRequest);
ShadowLooper.idleMainLooper(); ShadowLooper.idleMainLooper();
...@@ -127,8 +127,7 @@ public class FallbackListenerTest { ...@@ -127,8 +127,7 @@ public class FallbackListenerTest {
createHandler(), createHandler(),
originalRequest); originalRequest);
fallbackListener.registerTrack(); fallbackListener.setTrackCount(2);
fallbackListener.registerTrack();
fallbackListener.onTransformationRequestFinalized(audioFallbackRequest); fallbackListener.onTransformationRequestFinalized(audioFallbackRequest);
fallbackListener.onTransformationRequestFinalized(videoFallbackRequest); fallbackListener.onTransformationRequestFinalized(videoFallbackRequest);
ShadowLooper.idleMainLooper(); ShadowLooper.idleMainLooper();
......
...@@ -61,8 +61,8 @@ public final class VideoEncoderWrapperTest { ...@@ -61,8 +61,8 @@ public final class VideoEncoderWrapperTest {
fallbackListener); fallbackListener);
@Before @Before
public void registerTrack() { public void setUp() {
fallbackListener.registerTrack(); fallbackListener.setTrackCount(1);
createShadowH264Encoder(); createShadowH264Encoder();
} }
......
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