-Added loader eviction to avoid spawning too many threads in MediaSourceManager.

-Added nonnull and final constraints to variables in MediaSourceManager.
-Added nonnull and final constraints on context related objects in BasePlayer.
-Fixed Hls livestreams crashing player when behind live window for too long.
-Fixed cache miss when InfoCache key mismatch between StreamInfo and StreamInfoItem.
This commit is contained in:
John Zhen Mo 2018-03-03 11:42:23 -08:00
parent 9ea08c8a4b
commit 0c17f0825b
10 changed files with 395 additions and 277 deletions

View file

@ -172,7 +172,7 @@ public final class ExtractorHelper {
String url,
Single<I> loadFromNetwork) {
checkServiceId(serviceId);
loadFromNetwork = loadFromNetwork.doOnSuccess((@NonNull I i) -> cache.putInfo(i));
loadFromNetwork = loadFromNetwork.doOnSuccess(info -> cache.putInfo(serviceId, url, info));
Single<I> load;
if (forceLoad) {

View file

@ -20,6 +20,7 @@
package org.schabi.newpipe.util;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.LruCache;
import android.util.Log;
@ -29,6 +30,8 @@ import org.schabi.newpipe.extractor.Info;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
public final class InfoCache {
private static final boolean DEBUG = MainActivity.DEBUG;
@ -52,6 +55,7 @@ public final class InfoCache {
return instance;
}
@Nullable
public Info getFromKey(int serviceId, @NonNull String url) {
if (DEBUG) Log.d(TAG, "getFromKey() called with: serviceId = [" + serviceId + "], url = [" + url + "]");
synchronized (lruCache) {
@ -59,18 +63,19 @@ public final class InfoCache {
}
}
public void putInfo(@NonNull Info info) {
public void putInfo(int serviceId, @NonNull String url, @NonNull Info info) {
if (DEBUG) Log.d(TAG, "putInfo() called with: info = [" + info + "]");
synchronized (lruCache) {
final CacheData data = new CacheData(info, DEFAULT_TIMEOUT_HOURS, TimeUnit.HOURS);
lruCache.put(keyOf(info), data);
}
}
public void removeInfo(@NonNull Info info) {
if (DEBUG) Log.d(TAG, "removeInfo() called with: info = [" + info + "]");
final long expirationMillis;
if (info.getServiceId() == SoundCloud.getServiceId()) {
expirationMillis = TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES);
} else {
expirationMillis = TimeUnit.MILLISECONDS.convert(DEFAULT_TIMEOUT_HOURS, TimeUnit.HOURS);
}
synchronized (lruCache) {
lruCache.remove(keyOf(info));
final CacheData data = new CacheData(info, expirationMillis);
lruCache.put(keyOf(serviceId, url), data);
}
}
@ -102,10 +107,7 @@ public final class InfoCache {
}
}
private static String keyOf(@NonNull final Info info) {
return keyOf(info.getServiceId(), info.getUrl());
}
@NonNull
private static String keyOf(final int serviceId, @NonNull final String url) {
return serviceId + url;
}
@ -119,6 +121,7 @@ public final class InfoCache {
}
}
@Nullable
private static Info getInfo(@NonNull final LruCache<String, CacheData> cache,
@NonNull final String key) {
final CacheData data = cache.get(key);
@ -136,12 +139,8 @@ public final class InfoCache {
final private long expireTimestamp;
final private Info info;
private CacheData(@NonNull final Info info,
final long timeout,
@NonNull final TimeUnit timeUnit) {
this.expireTimestamp = System.currentTimeMillis() +
TimeUnit.MILLISECONDS.convert(timeout, timeUnit);
private CacheData(@NonNull final Info info, final long timeoutMillis) {
this.expireTimestamp = System.currentTimeMillis() + timeoutMillis;
this.info = info;
}