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