mirror of
https://github.com/samsonjs/media.git
synced 2026-04-15 12:55:46 +00:00
Move PriorityTaskManager from DefaultLoadControl to SimpleExoPlayer.
The priority task manager only needs to listen to loading state changes and is independent of the rest of DefaultLoadControl. This also fixes problems where the player stops loading without consultin the LoadControl. PiperOrigin-RevId: 242098374
This commit is contained in:
parent
d6244773ec
commit
346c72c00e
5 changed files with 57 additions and 76 deletions
|
|
@ -99,6 +99,7 @@
|
|||
* Handle meta atom as a full box when parsing mp4
|
||||
([#5698](https://github.com/google/ExoPlayer/issues/5698),
|
||||
[#5694](https://github.com/google/ExoPlayer/issues/5694)).
|
||||
* Move `PriorityTaskManager` from `DefaultLoadControl` to `SimpleExoPlayer`.
|
||||
|
||||
### 2.9.6 ###
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
|||
import com.google.android.exoplayer2.upstream.Allocator;
|
||||
import com.google.android.exoplayer2.upstream.DefaultAllocator;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.PriorityTaskManager;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
||||
/**
|
||||
|
|
@ -76,21 +75,18 @@ public class DefaultLoadControl implements LoadControl {
|
|||
private int bufferForPlaybackAfterRebufferMs;
|
||||
private int targetBufferBytes;
|
||||
private boolean prioritizeTimeOverSizeThresholds;
|
||||
private PriorityTaskManager priorityTaskManager;
|
||||
private int backBufferDurationMs;
|
||||
private boolean retainBackBufferFromKeyframe;
|
||||
private boolean createDefaultLoadControlCalled;
|
||||
|
||||
/** Constructs a new instance. */
|
||||
public Builder() {
|
||||
allocator = null;
|
||||
minBufferMs = DEFAULT_MIN_BUFFER_MS;
|
||||
maxBufferMs = DEFAULT_MAX_BUFFER_MS;
|
||||
bufferForPlaybackMs = DEFAULT_BUFFER_FOR_PLAYBACK_MS;
|
||||
bufferForPlaybackAfterRebufferMs = DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;
|
||||
targetBufferBytes = DEFAULT_TARGET_BUFFER_BYTES;
|
||||
prioritizeTimeOverSizeThresholds = DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS;
|
||||
priorityTaskManager = null;
|
||||
backBufferDurationMs = DEFAULT_BACK_BUFFER_DURATION_MS;
|
||||
retainBackBufferFromKeyframe = DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME;
|
||||
}
|
||||
|
|
@ -165,19 +161,6 @@ public class DefaultLoadControl implements LoadControl {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link PriorityTaskManager} to use.
|
||||
*
|
||||
* @param priorityTaskManager The {@link PriorityTaskManager} to use.
|
||||
* @return This builder, for convenience.
|
||||
* @throws IllegalStateException If {@link #createDefaultLoadControl()} has already been called.
|
||||
*/
|
||||
public Builder setPriorityTaskManager(PriorityTaskManager priorityTaskManager) {
|
||||
Assertions.checkState(!createDefaultLoadControlCalled);
|
||||
this.priorityTaskManager = priorityTaskManager;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the back buffer duration, and whether the back buffer is retained from the previous
|
||||
* keyframe.
|
||||
|
|
@ -210,7 +193,6 @@ public class DefaultLoadControl implements LoadControl {
|
|||
bufferForPlaybackAfterRebufferMs,
|
||||
targetBufferBytes,
|
||||
prioritizeTimeOverSizeThresholds,
|
||||
priorityTaskManager,
|
||||
backBufferDurationMs,
|
||||
retainBackBufferFromKeyframe);
|
||||
}
|
||||
|
|
@ -224,7 +206,6 @@ public class DefaultLoadControl implements LoadControl {
|
|||
private final long bufferForPlaybackAfterRebufferUs;
|
||||
private final int targetBufferBytesOverwrite;
|
||||
private final boolean prioritizeTimeOverSizeThresholds;
|
||||
private final PriorityTaskManager priorityTaskManager;
|
||||
private final long backBufferDurationUs;
|
||||
private final boolean retainBackBufferFromKeyframe;
|
||||
|
||||
|
|
@ -253,7 +234,6 @@ public class DefaultLoadControl implements LoadControl {
|
|||
|
||||
/** @deprecated Use {@link Builder} instead. */
|
||||
@Deprecated
|
||||
@SuppressWarnings("deprecation")
|
||||
public DefaultLoadControl(
|
||||
DefaultAllocator allocator,
|
||||
int minBufferMs,
|
||||
|
|
@ -270,29 +250,6 @@ public class DefaultLoadControl implements LoadControl {
|
|||
bufferForPlaybackAfterRebufferMs,
|
||||
targetBufferBytes,
|
||||
prioritizeTimeOverSizeThresholds,
|
||||
/* priorityTaskManager= */ null);
|
||||
}
|
||||
|
||||
/** @deprecated Use {@link Builder} instead. */
|
||||
@Deprecated
|
||||
public DefaultLoadControl(
|
||||
DefaultAllocator allocator,
|
||||
int minBufferMs,
|
||||
int maxBufferMs,
|
||||
int bufferForPlaybackMs,
|
||||
int bufferForPlaybackAfterRebufferMs,
|
||||
int targetBufferBytes,
|
||||
boolean prioritizeTimeOverSizeThresholds,
|
||||
PriorityTaskManager priorityTaskManager) {
|
||||
this(
|
||||
allocator,
|
||||
minBufferMs,
|
||||
maxBufferMs,
|
||||
bufferForPlaybackMs,
|
||||
bufferForPlaybackAfterRebufferMs,
|
||||
targetBufferBytes,
|
||||
prioritizeTimeOverSizeThresholds,
|
||||
priorityTaskManager,
|
||||
DEFAULT_BACK_BUFFER_DURATION_MS,
|
||||
DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME);
|
||||
}
|
||||
|
|
@ -305,7 +262,6 @@ public class DefaultLoadControl implements LoadControl {
|
|||
int bufferForPlaybackAfterRebufferMs,
|
||||
int targetBufferBytes,
|
||||
boolean prioritizeTimeOverSizeThresholds,
|
||||
PriorityTaskManager priorityTaskManager,
|
||||
int backBufferDurationMs,
|
||||
boolean retainBackBufferFromKeyframe) {
|
||||
assertGreaterOrEqual(bufferForPlaybackMs, 0, "bufferForPlaybackMs", "0");
|
||||
|
|
@ -327,7 +283,6 @@ public class DefaultLoadControl implements LoadControl {
|
|||
this.bufferForPlaybackAfterRebufferUs = C.msToUs(bufferForPlaybackAfterRebufferMs);
|
||||
this.targetBufferBytesOverwrite = targetBufferBytes;
|
||||
this.prioritizeTimeOverSizeThresholds = prioritizeTimeOverSizeThresholds;
|
||||
this.priorityTaskManager = priorityTaskManager;
|
||||
this.backBufferDurationUs = C.msToUs(backBufferDurationMs);
|
||||
this.retainBackBufferFromKeyframe = retainBackBufferFromKeyframe;
|
||||
}
|
||||
|
|
@ -375,7 +330,6 @@ public class DefaultLoadControl implements LoadControl {
|
|||
@Override
|
||||
public boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed) {
|
||||
boolean targetBufferSizeReached = allocator.getTotalBytesAllocated() >= targetBufferSize;
|
||||
boolean wasBuffering = isBuffering;
|
||||
long minBufferUs = this.minBufferUs;
|
||||
if (playbackSpeed > 1) {
|
||||
// The playback speed is faster than real time, so scale up the minimum required media
|
||||
|
|
@ -389,13 +343,6 @@ public class DefaultLoadControl implements LoadControl {
|
|||
} else if (bufferedDurationUs >= maxBufferUs || targetBufferSizeReached) {
|
||||
isBuffering = false;
|
||||
} // Else don't change the buffering state
|
||||
if (priorityTaskManager != null && isBuffering != wasBuffering) {
|
||||
if (isBuffering) {
|
||||
priorityTaskManager.add(C.PRIORITY_PLAYBACK);
|
||||
} else {
|
||||
priorityTaskManager.remove(C.PRIORITY_PLAYBACK);
|
||||
}
|
||||
}
|
||||
return isBuffering;
|
||||
}
|
||||
|
||||
|
|
@ -431,9 +378,6 @@ public class DefaultLoadControl implements LoadControl {
|
|||
|
||||
private void reset(boolean resetAllocator) {
|
||||
targetBufferSize = 0;
|
||||
if (priorityTaskManager != null && isBuffering) {
|
||||
priorityTaskManager.remove(C.PRIORITY_PLAYBACK);
|
||||
}
|
||||
isBuffering = false;
|
||||
if (resetAllocator) {
|
||||
allocator.reset();
|
||||
|
|
|
|||
|
|
@ -401,6 +401,11 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
mediaSource = null;
|
||||
internalPlayer.release();
|
||||
eventHandler.removeCallbacksAndMessages(null);
|
||||
playbackInfo =
|
||||
getResetPlaybackInfo(
|
||||
/* resetPosition= */ true,
|
||||
/* resetState= */ true,
|
||||
/* playbackState= */ Player.STATE_IDLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -48,8 +48,10 @@ import com.google.android.exoplayer2.text.TextOutput;
|
|||
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelector;
|
||||
import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Clock;
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
import com.google.android.exoplayer2.util.PriorityTaskManager;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
|
||||
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
||||
|
|
@ -113,6 +115,8 @@ public class SimpleExoPlayer extends BasePlayer
|
|||
@Nullable private VideoFrameMetadataListener videoFrameMetadataListener;
|
||||
@Nullable private CameraMotionListener cameraMotionListener;
|
||||
private boolean hasNotifiedFullWrongThreadWarning;
|
||||
@Nullable private PriorityTaskManager priorityTaskManager;
|
||||
private boolean isPriorityTaskManagerRegistered;
|
||||
|
||||
/**
|
||||
* @param context A {@link Context}.
|
||||
|
|
@ -233,6 +237,7 @@ public class SimpleExoPlayer extends BasePlayer
|
|||
new ExoPlayerImpl(renderers, trackSelector, loadControl, bandwidthMeter, clock, looper);
|
||||
analyticsCollector = analyticsCollectorFactory.createAnalyticsCollector(player, clock);
|
||||
addListener(analyticsCollector);
|
||||
addListener(componentListener);
|
||||
videoDebugListeners.add(analyticsCollector);
|
||||
videoListeners.add(analyticsCollector);
|
||||
audioDebugListeners.add(analyticsCollector);
|
||||
|
|
@ -538,6 +543,31 @@ public class SimpleExoPlayer extends BasePlayer
|
|||
analyticsCollector.removeListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link PriorityTaskManager}, or null to clear a previously set priority task manager.
|
||||
*
|
||||
* <p>The priority {@link C#PRIORITY_PLAYBACK} will be set while the player is loading.
|
||||
*
|
||||
* @param priorityTaskManager The {@link PriorityTaskManager}, or null to clear a previously set
|
||||
* priority task manager.
|
||||
*/
|
||||
public void setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager) {
|
||||
verifyApplicationThread();
|
||||
if (Util.areEqual(this.priorityTaskManager, priorityTaskManager)) {
|
||||
return;
|
||||
}
|
||||
if (isPriorityTaskManagerRegistered) {
|
||||
Assertions.checkNotNull(this.priorityTaskManager).remove(C.PRIORITY_PLAYBACK);
|
||||
}
|
||||
if (priorityTaskManager != null && isLoading()) {
|
||||
priorityTaskManager.add(C.PRIORITY_PLAYBACK);
|
||||
isPriorityTaskManagerRegistered = true;
|
||||
} else {
|
||||
isPriorityTaskManagerRegistered = false;
|
||||
}
|
||||
this.priorityTaskManager = priorityTaskManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link PlaybackParams} governing audio playback.
|
||||
*
|
||||
|
|
@ -994,6 +1024,10 @@ public class SimpleExoPlayer extends BasePlayer
|
|||
mediaSource.removeEventListener(analyticsCollector);
|
||||
mediaSource = null;
|
||||
}
|
||||
if (isPriorityTaskManagerRegistered) {
|
||||
Assertions.checkNotNull(priorityTaskManager).remove(C.PRIORITY_PLAYBACK);
|
||||
isPriorityTaskManagerRegistered = false;
|
||||
}
|
||||
bandwidthMeter.removeEventListener(analyticsCollector);
|
||||
currentCues = Collections.emptyList();
|
||||
}
|
||||
|
|
@ -1211,7 +1245,8 @@ public class SimpleExoPlayer extends BasePlayer
|
|||
MetadataOutput,
|
||||
SurfaceHolder.Callback,
|
||||
TextureView.SurfaceTextureListener,
|
||||
AudioFocusManager.PlayerControl {
|
||||
AudioFocusManager.PlayerControl,
|
||||
Player.EventListener {
|
||||
|
||||
// VideoRendererEventListener implementation
|
||||
|
||||
|
|
@ -1421,5 +1456,20 @@ public class SimpleExoPlayer extends BasePlayer
|
|||
public void executePlayerCommand(@AudioFocusManager.PlayerCommand int playerCommand) {
|
||||
updatePlayWhenReady(getPlayWhenReady(), playerCommand);
|
||||
}
|
||||
|
||||
// Player.EventListener implementation.
|
||||
|
||||
@Override
|
||||
public void onLoadingChanged(boolean isLoading) {
|
||||
if (priorityTaskManager != null) {
|
||||
if (isLoading && !isPriorityTaskManagerRegistered) {
|
||||
priorityTaskManager.add(C.PRIORITY_PLAYBACK);
|
||||
isPriorityTaskManagerRegistered = true;
|
||||
} else if (!isLoading && isPriorityTaskManagerRegistered) {
|
||||
priorityTaskManager.remove(C.PRIORITY_PLAYBACK);
|
||||
isPriorityTaskManagerRegistered = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
|||
import com.google.android.exoplayer2.upstream.DefaultAllocator;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Clock;
|
||||
import com.google.android.exoplayer2.util.PriorityTaskManager;
|
||||
import java.util.List;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
|
||||
|
|
@ -112,7 +111,6 @@ public final class BufferSizeAdaptationBuilder {
|
|||
private int hysteresisBufferMs;
|
||||
private float startUpBandwidthFraction;
|
||||
private int startUpMinBufferForQualityIncreaseMs;
|
||||
@Nullable private PriorityTaskManager priorityTaskManager;
|
||||
private DynamicFormatFilter dynamicFormatFilter;
|
||||
private boolean buildCalled;
|
||||
|
||||
|
|
@ -219,20 +217,6 @@ public final class BufferSizeAdaptationBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link PriorityTaskManager} to use.
|
||||
*
|
||||
* @param priorityTaskManager The {@link PriorityTaskManager}.
|
||||
* @return This builder, for convenience.
|
||||
* @throws IllegalStateException If {@link #buildPlayerComponents()} has already been called.
|
||||
*/
|
||||
public BufferSizeAdaptationBuilder setPriorityTaskManager(
|
||||
PriorityTaskManager priorityTaskManager) {
|
||||
Assertions.checkState(!buildCalled);
|
||||
this.priorityTaskManager = priorityTaskManager;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link DynamicFormatFilter} to use when updating the selected track.
|
||||
*
|
||||
|
|
@ -266,9 +250,6 @@ public final class BufferSizeAdaptationBuilder {
|
|||
maxBufferMs,
|
||||
bufferForPlaybackMs,
|
||||
bufferForPlaybackAfterRebufferMs);
|
||||
if (priorityTaskManager != null) {
|
||||
loadControlBuilder.setPriorityTaskManager(priorityTaskManager);
|
||||
}
|
||||
if (allocator != null) {
|
||||
loadControlBuilder.setAllocator(allocator);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue