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
This commit is contained in:
parent
59166cce9c
commit
7c3cffdebe
@ -18,6 +18,7 @@ package androidx.media3.transformer;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkState;
|
||||
|
||||
import androidx.annotation.IntRange;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.util.HandlerWrapper;
|
||||
@ -61,13 +62,13 @@ import androidx.media3.common.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 androidx.media3.common.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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user