-
Notifications
You must be signed in to change notification settings - Fork 0
fix(cache): ne pas garder le début d'un transcodage quitté en route #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
app/src/main/java/app/waveflow/playback/IncompleteTranscodeEviction.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package app.waveflow.playback | ||
|
|
||
| import android.net.Uri | ||
| import androidx.media3.common.C | ||
| import androidx.media3.datasource.DataSource | ||
| import androidx.media3.datasource.DataSpec | ||
| import androidx.media3.datasource.TransferListener | ||
| import androidx.media3.datasource.cache.Cache | ||
| import androidx.media3.datasource.cache.CacheKeyFactory | ||
| import androidx.media3.datasource.cache.ContentMetadata | ||
|
|
||
| /** | ||
| * Retire du cache le début qu'un transcodage quitté en route y a laissé. | ||
| * | ||
| * Un transcodage en direct arrive sans longueur et refuse toute plage qui ne | ||
| * part pas du premier octet. Son début gardé en cache ne sert donc à rien : à la | ||
| * réécoute, `CacheDataSource` le relirait puis demanderait la suite par une | ||
| * plage, que le serveur refuse en 416 — une erreur que Media3 ne retente jamais. | ||
| * La piste tomberait en erreur là où le cache s'arrêtait. | ||
| * | ||
| * C'est la longueur consignée qui départage, et `CacheDataSource` la consigne | ||
| * lui-même : dès l'ouverture quand le serveur l'annonce — l'original, qui se sert | ||
| * par plages et dont le début reste utile —, à la fin du flux sinon. Une entrée | ||
| * refermée sans longueur est un transcodage abandonné avant sa fin. | ||
| * | ||
| * Ne couvre pas la **coupure réseau** en cours de transcodage : Media3 reprend | ||
| * alors à l'octet atteint, et le serveur refuse cette plage-là aussi, cache ou | ||
| * pas. C'est la relance par décalage temporel qui la couvrira. | ||
| */ | ||
| internal class IncompleteTranscodeEviction( | ||
| private val cached: DataSource, | ||
| private val cache: Cache, | ||
| private val cacheKeyFactory: CacheKeyFactory, | ||
| ) : DataSource { | ||
|
|
||
| private var key: String? = null | ||
|
|
||
| override fun addTransferListener(transferListener: TransferListener) { | ||
| cached.addTransferListener(transferListener) | ||
| } | ||
|
|
||
| override fun open(dataSpec: DataSpec): Long { | ||
| key = cacheKeyFactory.buildCacheKey(dataSpec) | ||
| return cached.open(dataSpec) | ||
| } | ||
|
|
||
| override fun read(buffer: ByteArray, offset: Int, length: Int): Int = cached.read(buffer, offset, length) | ||
|
|
||
| override fun getUri(): Uri? = cached.uri | ||
|
|
||
| override fun getResponseHeaders(): Map<String, List<String>> = cached.responseHeaders | ||
|
|
||
| override fun close() { | ||
| try { | ||
| cached.close() | ||
| } finally { | ||
| key?.let { entree -> | ||
| if (ContentMetadata.getContentLength(cache.getContentMetadata(entree)) == C.LENGTH_UNSET.toLong()) { | ||
| cache.removeResource(entree) | ||
| } | ||
| } | ||
| key = null | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.