mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-05-11 12:04:40 +02:00
Add some main thread checks, change incorrect cache size
This commit is contained in:
parent
1768d73c01
commit
7ebd8f13c2
@ -17,6 +17,7 @@ import androidx.core.content.ContextCompat
|
|||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import com.futo.platformplayer.api.http.ManagedHttpClient
|
import com.futo.platformplayer.api.http.ManagedHttpClient
|
||||||
import com.futo.platformplayer.api.media.models.video.IPlatformVideo
|
import com.futo.platformplayer.api.media.models.video.IPlatformVideo
|
||||||
|
import com.futo.platformplayer.engine.V8Plugin
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.models.PlatformVideoWithTime
|
import com.futo.platformplayer.models.PlatformVideoWithTime
|
||||||
import com.futo.platformplayer.others.PlatformLinkMovementMethod
|
import com.futo.platformplayer.others.PlatformLinkMovementMethod
|
||||||
@ -51,6 +52,11 @@ fun findNonRuntimeException(ex: Throwable?): Throwable? {
|
|||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun warnIfMainThread(context: String) {
|
||||||
|
if(BuildConfig.DEBUG && Looper.myLooper() == Looper.getMainLooper())
|
||||||
|
Logger.w(V8Plugin.TAG, "JAVASCRIPT ON MAIN THREAD\nAt: ${context}\n" + Thread.currentThread().stackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
fun ensureNotMainThread() {
|
fun ensureNotMainThread() {
|
||||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||||
Logger.e("Utility", "Throwing exception because a function that should not be called on main thread, is called on main thread")
|
Logger.e("Utility", "Throwing exception because a function that should not be called on main thread, is called on main thread")
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package com.futo.platformplayer.api.media.platforms.js.models
|
package com.futo.platformplayer.api.media.platforms.js.models
|
||||||
|
|
||||||
|
import android.os.Looper
|
||||||
import com.caoccao.javet.values.reference.V8ValueArray
|
import com.caoccao.javet.values.reference.V8ValueArray
|
||||||
import com.caoccao.javet.values.reference.V8ValueObject
|
import com.caoccao.javet.values.reference.V8ValueObject
|
||||||
|
import com.futo.platformplayer.BuildConfig
|
||||||
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
||||||
import com.futo.platformplayer.api.media.structures.IPager
|
import com.futo.platformplayer.api.media.structures.IPager
|
||||||
import com.futo.platformplayer.engine.V8Plugin
|
import com.futo.platformplayer.engine.V8Plugin
|
||||||
import com.futo.platformplayer.getOrThrow
|
import com.futo.platformplayer.getOrThrow
|
||||||
|
import com.futo.platformplayer.warnIfMainThread
|
||||||
|
|
||||||
abstract class JSPager<T> : IPager<T> {
|
abstract class JSPager<T> : IPager<T> {
|
||||||
protected val plugin: V8Plugin;
|
protected val plugin: V8Plugin;
|
||||||
@ -37,6 +40,8 @@ abstract class JSPager<T> : IPager<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun nextPage() {
|
override fun nextPage() {
|
||||||
|
warnIfMainThread("JSPager.nextPage");
|
||||||
|
|
||||||
pager = plugin.catchScriptErrors("[${plugin.config.name}] JSPager", "pager.nextPage()") {
|
pager = plugin.catchScriptErrors("[${plugin.config.name}] JSPager", "pager.nextPage()") {
|
||||||
pager.invoke("nextPage", arrayOf<Any>());
|
pager.invoke("nextPage", arrayOf<Any>());
|
||||||
};
|
};
|
||||||
@ -53,6 +58,8 @@ abstract class JSPager<T> : IPager<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getResults(): List<T> {
|
override fun getResults(): List<T> {
|
||||||
|
warnIfMainThread("JSPager.getResults");
|
||||||
|
|
||||||
val previousResults = _lastResults?.let {
|
val previousResults = _lastResults?.let {
|
||||||
if(!_resultChanged)
|
if(!_resultChanged)
|
||||||
return@let it;
|
return@let it;
|
||||||
|
@ -6,6 +6,7 @@ import com.futo.platformplayer.engine.IV8PluginConfig
|
|||||||
import com.futo.platformplayer.engine.exceptions.ScriptImplementationException
|
import com.futo.platformplayer.engine.exceptions.ScriptImplementationException
|
||||||
import com.futo.platformplayer.getOrThrow
|
import com.futo.platformplayer.getOrThrow
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
import com.futo.platformplayer.warnIfMainThread
|
||||||
|
|
||||||
class JSPlaybackTracker: IPlaybackTracker {
|
class JSPlaybackTracker: IPlaybackTracker {
|
||||||
private val _config: IV8PluginConfig;
|
private val _config: IV8PluginConfig;
|
||||||
@ -20,6 +21,7 @@ class JSPlaybackTracker: IPlaybackTracker {
|
|||||||
private set;
|
private set;
|
||||||
|
|
||||||
constructor(config: IV8PluginConfig, obj: V8ValueObject) {
|
constructor(config: IV8PluginConfig, obj: V8ValueObject) {
|
||||||
|
warnIfMainThread("JSPlaybackTracker.constructor");
|
||||||
if(!obj.has("onProgress"))
|
if(!obj.has("onProgress"))
|
||||||
throw ScriptImplementationException(config, "Missing onProgress on PlaybackTracker");
|
throw ScriptImplementationException(config, "Missing onProgress on PlaybackTracker");
|
||||||
if(!obj.has("nextRequest"))
|
if(!obj.has("nextRequest"))
|
||||||
@ -31,6 +33,7 @@ class JSPlaybackTracker: IPlaybackTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onInit(seconds: Double) {
|
override fun onInit(seconds: Double) {
|
||||||
|
warnIfMainThread("JSPlaybackTracker.onInit");
|
||||||
synchronized(_obj) {
|
synchronized(_obj) {
|
||||||
if(_hasCalledInit)
|
if(_hasCalledInit)
|
||||||
return;
|
return;
|
||||||
@ -44,6 +47,7 @@ class JSPlaybackTracker: IPlaybackTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onProgress(seconds: Double, isPlaying: Boolean) {
|
override fun onProgress(seconds: Double, isPlaying: Boolean) {
|
||||||
|
warnIfMainThread("JSPlaybackTracker.onProgress");
|
||||||
synchronized(_obj) {
|
synchronized(_obj) {
|
||||||
if(!_hasCalledInit && _hasInit)
|
if(!_hasCalledInit && _hasInit)
|
||||||
onInit(seconds);
|
onInit(seconds);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.futo.platformplayer.constructs
|
package com.futo.platformplayer.constructs
|
||||||
|
|
||||||
|
import android.provider.Settings.Global
|
||||||
import com.futo.platformplayer.states.StateApp
|
import com.futo.platformplayer.states.StateApp
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
@ -39,8 +40,7 @@ class BatchedTaskHandler<TParameter, TResult> {
|
|||||||
|
|
||||||
//Cached
|
//Cached
|
||||||
if(result != null)
|
if(result != null)
|
||||||
//TODO: Replace with some kind of constant Deferred<IPlatformStreamVideo>
|
return CompletableDeferred(result as TResult);
|
||||||
return _scope.async { result as TResult }
|
|
||||||
//Already requesting
|
//Already requesting
|
||||||
if(taskResult != null)
|
if(taskResult != null)
|
||||||
return taskResult as Deferred<TResult>;
|
return taskResult as Deferred<TResult>;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.futo.platformplayer.engine
|
package com.futo.platformplayer.engine
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.Looper
|
||||||
import com.caoccao.javet.exceptions.JavetCompilationException
|
import com.caoccao.javet.exceptions.JavetCompilationException
|
||||||
import com.caoccao.javet.exceptions.JavetExecutionException
|
import com.caoccao.javet.exceptions.JavetExecutionException
|
||||||
import com.caoccao.javet.interop.V8Host
|
import com.caoccao.javet.interop.V8Host
|
||||||
@ -17,6 +18,7 @@ import com.futo.platformplayer.engine.exceptions.*
|
|||||||
import com.futo.platformplayer.engine.internal.V8Converter
|
import com.futo.platformplayer.engine.internal.V8Converter
|
||||||
import com.futo.platformplayer.engine.packages.*
|
import com.futo.platformplayer.engine.packages.*
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.states.StateAssets
|
import com.futo.platformplayer.states.StateAssets
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
@ -25,6 +27,7 @@ class V8Plugin {
|
|||||||
private val _client: ManagedHttpClient;
|
private val _client: ManagedHttpClient;
|
||||||
private val _clientAuth: ManagedHttpClient;
|
private val _clientAuth: ManagedHttpClient;
|
||||||
|
|
||||||
|
|
||||||
val httpClient: ManagedHttpClient get() = _client;
|
val httpClient: ManagedHttpClient get() = _client;
|
||||||
val httpClientAuth: ManagedHttpClient get() = _clientAuth;
|
val httpClientAuth: ManagedHttpClient get() = _clientAuth;
|
||||||
|
|
||||||
@ -137,6 +140,8 @@ class V8Plugin {
|
|||||||
return executeTyped<V8Value>(js);
|
return executeTyped<V8Value>(js);
|
||||||
}
|
}
|
||||||
fun <T : V8Value> executeTyped(js: String) : T {
|
fun <T : V8Value> executeTyped(js: String) : T {
|
||||||
|
warnIfMainThread("V8Plugin.executeTyped");
|
||||||
|
|
||||||
val runtime = _runtime ?: throw IllegalStateException("JSPlugin not started yet");
|
val runtime = _runtime ?: throw IllegalStateException("JSPlugin not started yet");
|
||||||
return catchScriptErrors("Plugin[${config.name}]", js) { runtime.getExecutor(js).execute() };
|
return catchScriptErrors("Plugin[${config.name}]", js) { runtime.getExecutor(js).execute() };
|
||||||
}
|
}
|
||||||
|
@ -927,6 +927,7 @@ class VideoDetailView : ConstraintLayout {
|
|||||||
StateDownloads.instance.getCachedVideo(videoDetail.id) ?: videoDetail;
|
StateDownloads.instance.getCachedVideo(videoDetail.id) ?: videoDetail;
|
||||||
this.video = video;
|
this.video = video;
|
||||||
this._playbackTracker = null;
|
this._playbackTracker = null;
|
||||||
|
|
||||||
if(video is JSVideoDetails) {
|
if(video is JSVideoDetails) {
|
||||||
val me = this;
|
val me = this;
|
||||||
fragment.lifecycleScope.launch(Dispatchers.IO) {
|
fragment.lifecycleScope.launch(Dispatchers.IO) {
|
||||||
@ -1001,6 +1002,7 @@ class VideoDetailView : ConstraintLayout {
|
|||||||
_subTitle.text = subTitleSegments.joinToString(" • ");
|
_subTitle.text = subTitleSegments.joinToString(" • ");
|
||||||
|
|
||||||
_rating.onLikeDislikeUpdated.remove(this);
|
_rating.onLikeDislikeUpdated.remove(this);
|
||||||
|
|
||||||
if (ref != null) {
|
if (ref != null) {
|
||||||
_rating.visibility = View.GONE;
|
_rating.visibility = View.GONE;
|
||||||
|
|
||||||
@ -1085,12 +1087,14 @@ class VideoDetailView : ConstraintLayout {
|
|||||||
_layoutRating.visibility = View.GONE;
|
_layoutRating.visibility = View.GONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Overlay
|
//Overlay
|
||||||
updateQualitySourcesOverlay(video);
|
updateQualitySourcesOverlay(video);
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
||||||
//Set Mediasource
|
//Set Mediasource
|
||||||
|
|
||||||
val toResume = _videoResumePositionMilliseconds;
|
val toResume = _videoResumePositionMilliseconds;
|
||||||
_videoResumePositionMilliseconds = 0;
|
_videoResumePositionMilliseconds = 0;
|
||||||
loadCurrentVideo(toResume);
|
loadCurrentVideo(toResume);
|
||||||
@ -1118,6 +1122,7 @@ class VideoDetailView : ConstraintLayout {
|
|||||||
_textResume.text = "";
|
_textResume.text = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
StatePlayer.instance.startOrUpdateMediaSession(context, video);
|
StatePlayer.instance.startOrUpdateMediaSession(context, video);
|
||||||
StatePlayer.instance.setCurrentlyPlaying(video);
|
StatePlayer.instance.setCurrentlyPlaying(video);
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ import kotlin.streams.toList
|
|||||||
*/
|
*/
|
||||||
class StatePlatform {
|
class StatePlatform {
|
||||||
private val TAG = "StatePlatform";
|
private val TAG = "StatePlatform";
|
||||||
private val VIDEO_CACHE = 1024 * 1024 * 10;
|
private val VIDEO_CACHE = 100;
|
||||||
|
|
||||||
private val _scope = CoroutineScope(Dispatchers.IO);
|
private val _scope = CoroutineScope(Dispatchers.IO);
|
||||||
|
|
||||||
@ -92,6 +92,7 @@ class StatePlatform {
|
|||||||
return@BatchedTaskHandler null;
|
return@BatchedTaskHandler null;
|
||||||
else {
|
else {
|
||||||
val cached = synchronized(_cache) { _cache.get(it); } ?: return@BatchedTaskHandler null;
|
val cached = synchronized(_cache) { _cache.get(it); } ?: return@BatchedTaskHandler null;
|
||||||
|
Logger.i(TAG, "Video Cache Hit [${cached.video.name}]");
|
||||||
if (cached.creationTime.getNowDiffSeconds() > _cacheExpirationSeconds) {
|
if (cached.creationTime.getNowDiffSeconds() > _cacheExpirationSeconds) {
|
||||||
Logger.i(TAG, "Invalidated cache for [${it}]");
|
Logger.i(TAG, "Invalidated cache for [${it}]");
|
||||||
synchronized(_cache) {
|
synchronized(_cache) {
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 123960682a286232963b5ed456598b1922dbe559
|
Subproject commit 2061a75ec1a9428b83f8cef5b84738c6f9cac290
|
Loading…
x
Reference in New Issue
Block a user