Commit 18031e25 by kimvde Committed by Tianyi Feng

Make AssetLoader progress not Transformer specific

To do that, rename PROGRESS_STATE_NO_TRANSFORMATION to
PROGRESS_STATE_NOT_STARTED and update Javadoc of ProgressState to not be
Transformer specific.

PiperOrigin-RevId: 496653460
parent 14517e46
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.transformerdemo; package com.google.android.exoplayer2.transformerdemo;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE; import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NOT_STARTED;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Assertions.checkState; import static com.google.android.exoplayer2.util.Assertions.checkState;
...@@ -211,8 +212,7 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -211,8 +212,7 @@ public final class TransformerActivity extends AppCompatActivity {
@Override @Override
public void run() { public void run() {
if (transformer != null if (transformer != null
&& transformer.getProgress(progressHolder) && transformer.getProgress(progressHolder) != PROGRESS_STATE_NOT_STARTED) {
!= Transformer.PROGRESS_STATE_NO_TRANSFORMATION) {
progressIndicator.setProgress(progressHolder.progress); progressIndicator.setProgress(progressHolder.progress);
informationTextView.setText( informationTextView.setText(
getString( getString(
......
...@@ -96,7 +96,7 @@ mainHandler.post( ...@@ -96,7 +96,7 @@ mainHandler.post(
public void run() { public void run() {
@ProgressState int progressState = transformer.getProgress(progressHolder); @ProgressState int progressState = transformer.getProgress(progressHolder);
updateProgressInUi(progressState, progressHolder); updateProgressInUi(progressState, progressHolder);
if (progressState != PROGRESS_STATE_NO_TRANSFORMATION) { if (progressState != PROGRESS_STATE_NOT_STARTED) {
mainHandler.postDelayed(/* r= */ this, /* delayMillis= */ 500); mainHandler.postDelayed(/* r= */ this, /* delayMillis= */ 500);
} }
} }
......
...@@ -21,7 +21,7 @@ import static com.google.android.exoplayer2.DefaultLoadControl.DEFAULT_BUFFER_FO ...@@ -21,7 +21,7 @@ import static com.google.android.exoplayer2.DefaultLoadControl.DEFAULT_BUFFER_FO
import static com.google.android.exoplayer2.DefaultLoadControl.DEFAULT_MAX_BUFFER_MS; import static com.google.android.exoplayer2.DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
import static com.google.android.exoplayer2.DefaultLoadControl.DEFAULT_MIN_BUFFER_MS; import static com.google.android.exoplayer2.DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_AVAILABLE; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_AVAILABLE;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NO_TRANSFORMATION; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NOT_STARTED;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_UNAVAILABLE; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_UNAVAILABLE;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_WAITING_FOR_AVAILABILITY; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_WAITING_FOR_AVAILABILITY;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
...@@ -227,7 +227,7 @@ public final class ExoPlayerAssetLoader implements AssetLoader { ...@@ -227,7 +227,7 @@ public final class ExoPlayerAssetLoader implements AssetLoader {
player = playerBuilder.build(); player = playerBuilder.build();
player.addListener(new PlayerListener(listener)); player.addListener(new PlayerListener(listener));
progressState = PROGRESS_STATE_NO_TRANSFORMATION; progressState = PROGRESS_STATE_NOT_STARTED;
} }
@Override @Override
...@@ -251,7 +251,7 @@ public final class ExoPlayerAssetLoader implements AssetLoader { ...@@ -251,7 +251,7 @@ public final class ExoPlayerAssetLoader implements AssetLoader {
@Override @Override
public void release() { public void release() {
player.release(); player.release();
progressState = PROGRESS_STATE_NO_TRANSFORMATION; progressState = PROGRESS_STATE_NOT_STARTED;
} }
private static final class RenderersFactoryImpl implements RenderersFactory { private static final class RenderersFactoryImpl implements RenderersFactory {
......
...@@ -551,32 +551,32 @@ public final class Transformer { ...@@ -551,32 +551,32 @@ public final class Transformer {
} }
/** /**
* Progress state. One of {@link #PROGRESS_STATE_WAITING_FOR_AVAILABILITY}, {@link * Progress state. One of {@link #PROGRESS_STATE_NOT_STARTED}, {@link
* #PROGRESS_STATE_AVAILABLE}, {@link #PROGRESS_STATE_UNAVAILABLE}, {@link * #PROGRESS_STATE_WAITING_FOR_AVAILABILITY}, {@link #PROGRESS_STATE_AVAILABLE} or {@link
* #PROGRESS_STATE_NO_TRANSFORMATION} * #PROGRESS_STATE_UNAVAILABLE}.
*/ */
@Documented @Documented
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@Target(TYPE_USE) @Target(TYPE_USE)
@IntDef({ @IntDef({
PROGRESS_STATE_NOT_STARTED,
PROGRESS_STATE_WAITING_FOR_AVAILABILITY, PROGRESS_STATE_WAITING_FOR_AVAILABILITY,
PROGRESS_STATE_AVAILABLE, PROGRESS_STATE_AVAILABLE,
PROGRESS_STATE_UNAVAILABLE, PROGRESS_STATE_UNAVAILABLE
PROGRESS_STATE_NO_TRANSFORMATION
}) })
public @interface ProgressState {} public @interface ProgressState {}
/** Indicates that the corresponding operation hasn't been started. */
public static final int PROGRESS_STATE_NOT_STARTED = 0;
/** /**
* Indicates that the progress is unavailable for the current transformation, but might become * @deprecated Use {@link #PROGRESS_STATE_NOT_STARTED} instead.
* available.
*/ */
public static final int PROGRESS_STATE_WAITING_FOR_AVAILABILITY = 0; @Deprecated public static final int PROGRESS_STATE_NO_TRANSFORMATION = PROGRESS_STATE_NOT_STARTED;
/** Indicates that the progress is currently unavailable, but might become available. */
public static final int PROGRESS_STATE_WAITING_FOR_AVAILABILITY = 1;
/** Indicates that the progress is available. */ /** Indicates that the progress is available. */
public static final int PROGRESS_STATE_AVAILABLE = 1; public static final int PROGRESS_STATE_AVAILABLE = 2;
/** Indicates that the progress is permanently unavailable for the current transformation. */ /** Indicates that the progress is permanently unavailable. */
public static final int PROGRESS_STATE_UNAVAILABLE = 2; public static final int PROGRESS_STATE_UNAVAILABLE = 3;
/** Indicates that there is no current transformation. */
public static final int PROGRESS_STATE_NO_TRANSFORMATION = 4;
@VisibleForTesting /* package */ final Codec.DecoderFactory decoderFactory; @VisibleForTesting /* package */ final Codec.DecoderFactory decoderFactory;
@VisibleForTesting /* package */ final Codec.EncoderFactory encoderFactory; @VisibleForTesting /* package */ final Codec.EncoderFactory encoderFactory;
...@@ -795,8 +795,7 @@ public final class Transformer { ...@@ -795,8 +795,7 @@ public final class Transformer {
* progress if it is {@link #PROGRESS_STATE_AVAILABLE available}. * progress if it is {@link #PROGRESS_STATE_AVAILABLE available}.
* *
* <p>After a transformation {@linkplain Listener#onTransformationCompleted(MediaItem, * <p>After a transformation {@linkplain Listener#onTransformationCompleted(MediaItem,
* TransformationResult) completes}, this method returns {@link * TransformationResult) completes}, this method returns {@link #PROGRESS_STATE_NOT_STARTED}.
* #PROGRESS_STATE_NO_TRANSFORMATION}.
* *
* @param progressHolder A {@link ProgressHolder}, updated to hold the percentage progress if * @param progressHolder A {@link ProgressHolder}, updated to hold the percentage progress if
* {@link #PROGRESS_STATE_AVAILABLE available}. * {@link #PROGRESS_STATE_AVAILABLE available}.
...@@ -806,7 +805,7 @@ public final class Transformer { ...@@ -806,7 +805,7 @@ public final class Transformer {
public @ProgressState int getProgress(ProgressHolder progressHolder) { public @ProgressState int getProgress(ProgressHolder progressHolder) {
verifyApplicationThread(); verifyApplicationThread();
return transformerInternal == null return transformerInternal == null
? PROGRESS_STATE_NO_TRANSFORMATION ? PROGRESS_STATE_NOT_STARTED
: transformerInternal.getProgress(progressHolder); : transformerInternal.getProgress(progressHolder);
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
package com.google.android.exoplayer2.transformer; package com.google.android.exoplayer2.transformer;
import static com.google.android.exoplayer2.transformer.TransformationException.ERROR_CODE_MUXING_FAILED; import static com.google.android.exoplayer2.transformer.TransformationException.ERROR_CODE_MUXING_FAILED;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NO_TRANSFORMATION; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NOT_STARTED;
import static java.lang.annotation.ElementType.TYPE_USE; import static java.lang.annotation.ElementType.TYPE_USE;
import android.content.Context; import android.content.Context;
...@@ -184,7 +184,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -184,7 +184,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public @Transformer.ProgressState int getProgress(ProgressHolder progressHolder) { public @Transformer.ProgressState int getProgress(ProgressHolder progressHolder) {
if (released) { if (released) {
return PROGRESS_STATE_NO_TRANSFORMATION; return PROGRESS_STATE_NOT_STARTED;
} }
internalHandler.obtainMessage(MSG_UPDATE_PROGRESS, progressHolder).sendToTarget(); internalHandler.obtainMessage(MSG_UPDATE_PROGRESS, progressHolder).sendToTarget();
// TODO: figure out why calling clock.onThreadBlocked() here makes the tests fail. // TODO: figure out why calling clock.onThreadBlocked() here makes the tests fail.
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
package com.google.android.exoplayer2.transformer; package com.google.android.exoplayer2.transformer;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_AVAILABLE; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_AVAILABLE;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NO_TRANSFORMATION; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NOT_STARTED;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_UNAVAILABLE; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_UNAVAILABLE;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_WAITING_FOR_AVAILABILITY; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_WAITING_FOR_AVAILABILITY;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
...@@ -658,8 +658,8 @@ public final class TransformerEndToEndTest { ...@@ -658,8 +658,8 @@ public final class TransformerEndToEndTest {
return; return;
} }
break; break;
case PROGRESS_STATE_NO_TRANSFORMATION: case PROGRESS_STATE_NOT_STARTED:
if (progressState != PROGRESS_STATE_NO_TRANSFORMATION) { if (progressState != PROGRESS_STATE_NOT_STARTED) {
foundInconsistentState.set(true); foundInconsistentState.set(true);
return; return;
} }
...@@ -689,7 +689,7 @@ public final class TransformerEndToEndTest { ...@@ -689,7 +689,7 @@ public final class TransformerEndToEndTest {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
@Transformer.ProgressState int progressState = transformer.getProgress(progressHolder); @Transformer.ProgressState int progressState = transformer.getProgress(progressHolder);
if (progressState == PROGRESS_STATE_NO_TRANSFORMATION) { if (progressState == PROGRESS_STATE_NOT_STARTED) {
return; return;
} }
if (progressState != PROGRESS_STATE_WAITING_FOR_AVAILABILITY if (progressState != PROGRESS_STATE_WAITING_FOR_AVAILABILITY
...@@ -724,8 +724,8 @@ public final class TransformerEndToEndTest { ...@@ -724,8 +724,8 @@ public final class TransformerEndToEndTest {
TransformerTestRunner.runUntilCompleted(transformer); TransformerTestRunner.runUntilCompleted(transformer);
@Transformer.ProgressState int stateAfterTransform = transformer.getProgress(progressHolder); @Transformer.ProgressState int stateAfterTransform = transformer.getProgress(progressHolder);
assertThat(stateBeforeTransform).isEqualTo(Transformer.PROGRESS_STATE_NO_TRANSFORMATION); assertThat(stateBeforeTransform).isEqualTo(PROGRESS_STATE_NOT_STARTED);
assertThat(stateAfterTransform).isEqualTo(Transformer.PROGRESS_STATE_NO_TRANSFORMATION); assertThat(stateAfterTransform).isEqualTo(PROGRESS_STATE_NOT_STARTED);
} }
@Test @Test
...@@ -750,8 +750,8 @@ public final class TransformerEndToEndTest { ...@@ -750,8 +750,8 @@ public final class TransformerEndToEndTest {
return; return;
} }
break; break;
case PROGRESS_STATE_NO_TRANSFORMATION: case PROGRESS_STATE_NOT_STARTED:
if (progressState != PROGRESS_STATE_NO_TRANSFORMATION) { if (progressState != PROGRESS_STATE_NOT_STARTED) {
foundInconsistentState.set(true); foundInconsistentState.set(true);
return; return;
} }
......
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