Skip to content

Commit 04b0850

Browse files
committed
Make ASS glyph and cache sizes configurable
Introduce AssRenderConfig to allow configuring glyph size and cache size when creating AssHandler, replacing hardcoded libass cache limits. Defaults preserve existing behavior
1 parent 5491fd2 commit 04b0850

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

lib_ass_media/src/main/java/io/github/peerless2012/ass/media/AssHandler.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ import io.github.peerless2012.ass.media.type.AssRenderType
2828
* @param renderType The subtitle render type.
2929
*/
3030
@OptIn(UnstableApi::class)
31-
class AssHandler(val renderType: AssRenderType) : Listener {
31+
class AssHandler(
32+
val renderType: AssRenderType,
33+
val config: AssHandlerConfig = AssHandlerConfig()
34+
) : Listener {
3235

3336
/** The ASS instance used for creating tracks and renderers. This is lazy to avoid loading
3437
* libass if the played media does not have ASS tracks. */
@@ -259,13 +262,9 @@ class AssHandler(val renderType: AssRenderType) : Listener {
259262
render.setFrameSize(videoSize.width, videoSize.height)
260263
}
261264
}
262-
val totalMemoryBytes = Runtime.getRuntime().maxMemory()
263-
val glyphSize = 10000
264-
val cacheSize = 128 //((totalMemoryBytes / (1024 * 1024)) / 4).toInt()
265-
Log.i("AssHandler", "Ass cacheSize: ${cacheSize}MB")
266-
Log.i("AssHandler", "Ass glyphSize: ${glyphSize}")
267-
// https://github.com/peerless2012/libass-android/issues/48#issuecomment-3086561167
268-
render.setCacheLimit(glyphSize, cacheSize)
265+
Log.i("AssHandler", "Ass cacheSize: ${config.cacheSize}MB")
266+
Log.i("AssHandler", "Ass glyphSize: ${config.glyphSize}")
267+
render.setCacheLimit(config.glyphSize, config.cacheSize)
269268
}
270269
renderCallback?.invoke(render)
271270
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.github.peerless2012.ass.media
2+
3+
data class AssHandlerConfig(
4+
val glyphSize: Int = 1024,
5+
val cacheSize: Int = 128){
6+
}

0 commit comments

Comments
 (0)