Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class DefaultThumbnailsEngine(
}

override fun isDrained(): Boolean {
if(source.isDrained) {
if (source.isDrained) {
source.seekTo(stubs.firstOrNull()?.positionUs ?: -1)
}
return source.isDrained
Expand Down Expand Up @@ -121,18 +121,16 @@ class DefaultThumbnailsEngine(
val nextKeyFrameUs =
if (nextKeyFrameIndex == -1) Long.MAX_VALUE else source.keyFrameTimestampsUs[nextKeyFrameIndex]
val previousKeyFrameUs =
if (nextKeyFrameIndex > 0) {
source.keyFrameTimestampsUs[nextKeyFrameIndex - 1]
}
else {
source.keyFrameTimestampsUs[source.keyFrameTimestampsUs.size - 1]
}
source.keyFrameTimestampsUs[
if (nextKeyFrameIndex > 0)
nextKeyFrameIndex - 1 else (source.keyFrameTimestampsUs.size - 1)
]

log.i(
"seek: current ${source.positionUs}," +
" requested $requested, threshold $threshold, nextKeyFrameUs $nextKeyFrameUs"
)

val rightGap = nextKeyFrameUs - requested
val nextKeyFrameInThreshold = rightGap <= threshold
seek = nextKeyFrameInThreshold || previousKeyFrameUs > current || (current - requested > threshold)
Expand Down Expand Up @@ -172,7 +170,7 @@ class DefaultThumbnailsEngine(

private lateinit var progress: (Thumbnail) -> Unit

private fun DataSource.search(timestampUs: Long) : Int {
private fun DataSource.search(timestampUs: Long): Int {
if (keyFrameTimestampsUs.isEmpty())
requestKeyFrameTimestamps()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.otaliastudios.transcoder.thumbnail

@Suppress("MagicNumber")
open class SingleThumbnailRequest(private val positionUs: Long) : ThumbnailRequest {
override fun locate(durationUs: Long): List<Long> {
// val positionUs = positionUs.coerceIn(0L..durationUs)
val positionUs = positionUs.coerceIn(0L..durationUs - 135005 - (positionUs / 1000) % 10000)
val randomizer = (positionUs / 1000) % 10000
val positionUs = positionUs.coerceIn(0L..durationUs - 135005 - randomizer)
return listOf(positionUs)
}
}