mirror of
https://github.com/androidx/media.git
synced 2025-05-08 08:00:49 +08:00
Fix misreporting cached bytes when caching is paused
When caching is resumed, it starts from the initial position. This makes more data to be reported as cached. Issue:#5573 PiperOrigin-RevId: 250678841
This commit is contained in:
parent
811cdf06ac
commit
c231e1120e
@ -10,20 +10,16 @@
|
|||||||
`PlayerControlView`.
|
`PlayerControlView`.
|
||||||
* Change playback controls toggle from touch down to touch up events
|
* Change playback controls toggle from touch down to touch up events
|
||||||
([#5784](https://github.com/google/ExoPlayer/issues/5784)).
|
([#5784](https://github.com/google/ExoPlayer/issues/5784)).
|
||||||
<<<<<<< HEAD
|
|
||||||
* Fix issue where playback controls were not kept visible on key presses
|
* Fix issue where playback controls were not kept visible on key presses
|
||||||
([#5963](https://github.com/google/ExoPlayer/issues/5963)).
|
([#5963](https://github.com/google/ExoPlayer/issues/5963)).
|
||||||
=======
|
|
||||||
* Add a workaround for broken raw audio decoding on Oppo R9
|
|
||||||
([#5782](https://github.com/google/ExoPlayer/issues/5782)).
|
|
||||||
* Offline:
|
* Offline:
|
||||||
* Add Scheduler implementation which uses WorkManager.
|
|
||||||
* Prevent unexpected `DownloadHelper.Callback.onPrepared` callbacks after the
|
* Prevent unexpected `DownloadHelper.Callback.onPrepared` callbacks after the
|
||||||
preparation of the `DownloadHelper` failed
|
preparation of the `DownloadHelper` failed
|
||||||
([#5915](https://github.com/google/ExoPlayer/issues/5915)).
|
([#5915](https://github.com/google/ExoPlayer/issues/5915)).
|
||||||
* Fix CacheUtil.cache() use too much data
|
* Fix CacheUtil.cache() use too much data
|
||||||
([#5927](https://github.com/google/ExoPlayer/issues/5927)).
|
([#5927](https://github.com/google/ExoPlayer/issues/5927)).
|
||||||
>>>>>>> 42ba6abf5... Fix CacheUtil.cache() use too much data
|
* Fix misreporting cached bytes when caching is paused
|
||||||
|
([#5573](https://github.com/google/ExoPlayer/issues/5573)).
|
||||||
* Add a playWhenReady flag to MediaSessionConnector.PlaybackPreparer methods
|
* Add a playWhenReady flag to MediaSessionConnector.PlaybackPreparer methods
|
||||||
to indicate whether a controller sent a play or only a prepare command. This
|
to indicate whether a controller sent a play or only a prepare command. This
|
||||||
allows to take advantage of decoder reuse with the MediaSessionConnector
|
allows to take advantage of decoder reuse with the MediaSessionConnector
|
||||||
|
@ -268,6 +268,8 @@ public final class CacheUtil {
|
|||||||
AtomicBoolean isCanceled)
|
AtomicBoolean isCanceled)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
long positionOffset = absoluteStreamPosition - dataSpec.absoluteStreamPosition;
|
long positionOffset = absoluteStreamPosition - dataSpec.absoluteStreamPosition;
|
||||||
|
long initialPositionOffset = positionOffset;
|
||||||
|
long endOffset = length != C.LENGTH_UNSET ? positionOffset + length : C.POSITION_UNSET;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (priorityTaskManager != null) {
|
if (priorityTaskManager != null) {
|
||||||
// Wait for any other thread with higher priority to finish its job.
|
// Wait for any other thread with higher priority to finish its job.
|
||||||
@ -275,45 +277,51 @@ public final class CacheUtil {
|
|||||||
}
|
}
|
||||||
throwExceptionIfInterruptedOrCancelled(isCanceled);
|
throwExceptionIfInterruptedOrCancelled(isCanceled);
|
||||||
try {
|
try {
|
||||||
long resolvedLength;
|
long resolvedLength = C.LENGTH_UNSET;
|
||||||
try {
|
boolean isDataSourceOpen = false;
|
||||||
resolvedLength = dataSource.open(dataSpec.subrange(positionOffset, length));
|
if (endOffset != C.POSITION_UNSET) {
|
||||||
} catch (IOException exception) {
|
// If a specific length is given, first try to open the data source for that length to
|
||||||
if (length == C.LENGTH_UNSET
|
// avoid more data then required to be requested. If the given length exceeds the end of
|
||||||
|| !isLastBlock
|
// input we will get a "position out of range" error. In that case try to open the source
|
||||||
|| !isCausedByPositionOutOfRange(exception)) {
|
// again with unset length.
|
||||||
throw exception;
|
try {
|
||||||
|
resolvedLength =
|
||||||
|
dataSource.open(dataSpec.subrange(positionOffset, endOffset - positionOffset));
|
||||||
|
isDataSourceOpen = true;
|
||||||
|
} catch (IOException exception) {
|
||||||
|
if (!isLastBlock || !isCausedByPositionOutOfRange(exception)) {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
Util.closeQuietly(dataSource);
|
||||||
}
|
}
|
||||||
Util.closeQuietly(dataSource);
|
}
|
||||||
// Retry to open the data source again, setting length to C.LENGTH_UNSET to prevent
|
if (!isDataSourceOpen) {
|
||||||
// getting an error in case the given length exceeds the end of input.
|
|
||||||
resolvedLength = dataSource.open(dataSpec.subrange(positionOffset, C.LENGTH_UNSET));
|
resolvedLength = dataSource.open(dataSpec.subrange(positionOffset, C.LENGTH_UNSET));
|
||||||
}
|
}
|
||||||
if (isLastBlock && progressNotifier != null && resolvedLength != C.LENGTH_UNSET) {
|
if (isLastBlock && progressNotifier != null && resolvedLength != C.LENGTH_UNSET) {
|
||||||
progressNotifier.onRequestLengthResolved(positionOffset + resolvedLength);
|
progressNotifier.onRequestLengthResolved(positionOffset + resolvedLength);
|
||||||
}
|
}
|
||||||
long totalBytesRead = 0;
|
while (positionOffset != endOffset) {
|
||||||
while (totalBytesRead != length) {
|
|
||||||
throwExceptionIfInterruptedOrCancelled(isCanceled);
|
throwExceptionIfInterruptedOrCancelled(isCanceled);
|
||||||
int bytesRead =
|
int bytesRead =
|
||||||
dataSource.read(
|
dataSource.read(
|
||||||
buffer,
|
buffer,
|
||||||
0,
|
0,
|
||||||
length != C.LENGTH_UNSET
|
endOffset != C.POSITION_UNSET
|
||||||
? (int) Math.min(buffer.length, length - totalBytesRead)
|
? (int) Math.min(buffer.length, endOffset - positionOffset)
|
||||||
: buffer.length);
|
: buffer.length);
|
||||||
if (bytesRead == C.RESULT_END_OF_INPUT) {
|
if (bytesRead == C.RESULT_END_OF_INPUT) {
|
||||||
if (progressNotifier != null) {
|
if (progressNotifier != null) {
|
||||||
progressNotifier.onRequestLengthResolved(positionOffset + totalBytesRead);
|
progressNotifier.onRequestLengthResolved(positionOffset);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
totalBytesRead += bytesRead;
|
positionOffset += bytesRead;
|
||||||
if (progressNotifier != null) {
|
if (progressNotifier != null) {
|
||||||
progressNotifier.onBytesCached(bytesRead);
|
progressNotifier.onBytesCached(bytesRead);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return totalBytesRead;
|
return positionOffset - initialPositionOffset;
|
||||||
} catch (PriorityTaskManager.PriorityTooLowException exception) {
|
} catch (PriorityTaskManager.PriorityTooLowException exception) {
|
||||||
// catch and try again
|
// catch and try again
|
||||||
} finally {
|
} finally {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user