music: use unlimited buffering in loader
This commit is contained in:
parent
d52e301751
commit
1b295934e0
3 changed files with 14 additions and 7 deletions
|
@ -21,6 +21,7 @@ package org.oxycblt.auxio.music.stack
|
|||
import android.net.Uri
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.buffer
|
||||
|
@ -65,8 +66,8 @@ constructor(private val explorer: Explorer, private val interpreter: Interpreter
|
|||
start = { onProgress(IndexingProgress.Songs(0, 0)) },
|
||||
end = { onProgress(IndexingProgress.Indeterminate) })
|
||||
.flowOn(Dispatchers.IO)
|
||||
.buffer()
|
||||
val playlistFiles = files.playlists.flowOn(Dispatchers.IO).buffer()
|
||||
.buffer(Channel.UNLIMITED)
|
||||
val playlistFiles = files.playlists.flowOn(Dispatchers.IO).buffer(Channel.UNLIMITED)
|
||||
interpreter.interpret(audioFiles, playlistFiles, interpretation)
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ constructor(
|
|||
onProgress(IndexingProgress.Songs(loaded, explored))
|
||||
}
|
||||
.flowOn(Dispatchers.IO)
|
||||
.buffer()
|
||||
.buffer(Channel.UNLIMITED)
|
||||
// val cacheResults = tagCache.read(deviceFiles).flowOn(Dispatchers.IO).buffer()
|
||||
|
||||
// val (handle, uncachedDeviceFiles, cachedAudioFiles) = tagRead.results()
|
||||
|
@ -89,7 +89,7 @@ constructor(
|
|||
|
||||
/** Temporarily split a flow into 8 parallel threads and then */
|
||||
private fun <T, R> Flow<T>.stretch(n: Int, creator: (Flow<T>) -> Flow<R>): Flow<R> {
|
||||
val posChannels = Array(n) { Channel<T>(Channel.BUFFERED) }
|
||||
val posChannels = Array(n) { Channel<T>(Channel.UNLIMITED) }
|
||||
val divert: Flow<R> = flow {
|
||||
withIndex().collect {
|
||||
val index = it.index % n
|
||||
|
@ -99,7 +99,8 @@ constructor(
|
|||
channel.close()
|
||||
}
|
||||
}
|
||||
val handle = posChannels.map { creator(it.receiveAsFlow()).buffer() }.asFlow()
|
||||
val handle =
|
||||
posChannels.map { creator(it.receiveAsFlow()).buffer(Channel.UNLIMITED) }.asFlow()
|
||||
return merge(divert, handle.flattenMerge())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.oxycblt.auxio.music.stack.interpret
|
|||
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.flow.buffer
|
||||
|
@ -59,10 +60,14 @@ class InterpreterImpl @Inject constructor(private val preparer: Preparer) : Inte
|
|||
interpretation: Interpretation
|
||||
): MutableLibrary {
|
||||
val preSongs =
|
||||
preparer.prepare(audioFiles, interpretation).flowOn(Dispatchers.Main).buffer()
|
||||
preparer
|
||||
.prepare(audioFiles, interpretation)
|
||||
.flowOn(Dispatchers.Main)
|
||||
.buffer(Channel.UNLIMITED)
|
||||
|
||||
val genreLinker = GenreLinker()
|
||||
val genreLinkedSongs = genreLinker.register(preSongs).flowOn(Dispatchers.Main).buffer()
|
||||
val genreLinkedSongs =
|
||||
genreLinker.register(preSongs).flowOn(Dispatchers.Main).buffer(Channel.UNLIMITED)
|
||||
|
||||
val artistLinker = ArtistLinker()
|
||||
val artistLinkedSongs =
|
||||
|
|
Loading…
Reference in a new issue