Implement ExoPlayerPool for better reuse and performance.

This commit is contained in:
Alex Hart
2021-09-24 13:10:48 -03:00
committed by GitHub
parent a5c51ff801
commit 5c1b57e4ba
12 changed files with 478 additions and 154 deletions

View File

@@ -39,6 +39,7 @@ import org.thoughtcrime.securesms.util.EarlyMessageCache;
import org.thoughtcrime.securesms.util.FrameRateTracker;
import org.thoughtcrime.securesms.util.Hex;
import org.thoughtcrime.securesms.util.IasKeyStore;
import org.thoughtcrime.securesms.video.exo.SimpleExoPlayerPool;
import org.thoughtcrime.securesms.video.exo.GiphyMp4Cache;
import org.whispersystems.signalservice.api.KeyBackupService;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
@@ -99,7 +100,8 @@ public class ApplicationDependencies {
private static volatile TextSecureSessionStore sessionStore;
private static volatile TextSecurePreKeyStore preKeyStore;
private static volatile SignalSenderKeyStore senderKeyStore;
private static volatile GiphyMp4Cache giphyMp4Cache;
private static volatile GiphyMp4Cache giphyMp4Cache;
private static volatile SimpleExoPlayerPool exoPlayerPool;
@MainThread
public static void init(@NonNull Application application, @NonNull Provider provider) {
@@ -564,6 +566,17 @@ public class ApplicationDependencies {
return giphyMp4Cache;
}
public static @NonNull SimpleExoPlayerPool getExoPlayerPool() {
if (exoPlayerPool == null) {
synchronized (LOCK) {
if (exoPlayerPool == null) {
exoPlayerPool = provider.provideExoPlayerPool();
}
}
}
return exoPlayerPool;
}
public interface Provider {
@NonNull GroupsV2Operations provideGroupsV2Operations();
@NonNull SignalServiceAccountManager provideSignalServiceAccountManager();
@@ -597,5 +610,6 @@ public class ApplicationDependencies {
@NonNull TextSecurePreKeyStore providePreKeyStore();
@NonNull SignalSenderKeyStore provideSenderKeyStore();
@NonNull GiphyMp4Cache provideGiphyMp4Cache();
@NonNull SimpleExoPlayerPool provideExoPlayerPool();
}
}

View File

@@ -58,6 +58,7 @@ import org.thoughtcrime.securesms.util.EarlyMessageCache;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.FrameRateTracker;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.video.exo.SimpleExoPlayerPool;
import org.thoughtcrime.securesms.video.exo.GiphyMp4Cache;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
@@ -289,6 +290,11 @@ public class ApplicationDependencyProvider implements ApplicationDependencies.Pr
return new GiphyMp4Cache(ByteUnit.MEGABYTES.toBytes(16));
}
@Override
public @NonNull SimpleExoPlayerPool provideExoPlayerPool() {
return new SimpleExoPlayerPool(context);
}
private @NonNull WebSocketFactory provideWebSocketFactory(@NonNull SignalWebSocketHealthMonitor healthMonitor) {
return new WebSocketFactory() {
@Override