Skip to content

Commit 13a5d27

Browse files
authored
Merge pull request #61 from j3553a/master
Make libass glyph and cache sizes configurable
2 parents 570c973 + f3ec0f9 commit 13a5d27

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

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

Lines changed: 7 additions & 6 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,11 +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 cacheSize = ((totalMemoryBytes / (1024 * 1024)) / 4).toInt()
264-
Log.i("AssHandler", "Ass cacheSize: ${cacheSize}MB")
265-
// https://github.com/peerless2012/libass-android/issues/48#issuecomment-3086561167
266-
render.setCacheLimit(1024, 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)
267268
}
268269
renderCallback?.invoke(render)
269270
}
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)