optimisations for exo

This commit is contained in:
chrisk325 2026-01-04 16:17:16 +05:30 committed by GitHub
parent 4fdda9a184
commit 59f77ac831
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -270,6 +270,7 @@ public class ReactExoplayerView extends FrameLayout implements
private final String instanceId = String.valueOf(UUID.randomUUID());
private CmcdConfiguration.Factory cmcdConfigurationFactory;
private static final ExecutorService SHARED_EXECUTOR = Executors.newSingleThreadExecutor();
public void setCmcdConfigurationFactory(CmcdConfiguration.Factory factory) {
this.cmcdConfigurationFactory = factory;
@ -683,8 +684,7 @@ public class ReactExoplayerView extends FrameLayout implements
exoPlayerView.invalidateAspectRatio();
// DRM session manager creation must be done on a different thread to prevent
// crashes so we start a new thread
ExecutorService es = Executors.newSingleThreadExecutor();
es.execute(() -> {
SHARED_EXECUTOR.execute(() -> {
// DRM initialization must run on a different thread
if (viewHasDropped && runningSource == source) {
return;
@ -1518,8 +1518,7 @@ public class ReactExoplayerView extends FrameLayout implements
ArrayList<Track> textTracks = getTextTrackInfo();
if (source.getContentStartTime() != -1) {
ExecutorService es = Executors.newSingleThreadExecutor();
es.execute(() -> {
SHARED_EXECUTOR.execute(() -> {
// To prevent ANRs caused by getVideoTrackInfo we run this on a different thread
// and notify the player only when we're done
ArrayList<VideoTrack> videoTracks = getVideoTrackInfoFromManifest();
@ -1632,12 +1631,11 @@ public class ReactExoplayerView extends FrameLayout implements
// conditions
@WorkerThread
private ArrayList<VideoTrack> getVideoTrackInfoFromManifest(int retryCount) {
ExecutorService es = Executors.newSingleThreadExecutor();
final DataSource dataSource = this.mediaDataSourceFactory.createDataSource();
final Uri sourceUri = source.getUri();
final long startTime = source.getContentStartTime() * 1000 - 100; // s -> ms with 100ms offset
Future<ArrayList<VideoTrack>> result = es.submit(new Callable() {
Future<ArrayList<VideoTrack>> result = SHARED_EXECUTOR.submit(new Callable<ArrayList<VideoTrack>>() {
final DataSource ds = dataSource;
final Uri uri = sourceUri;
final long startTimeUs = startTime * 1000; // ms -> us
@ -1687,7 +1685,6 @@ public class ReactExoplayerView extends FrameLayout implements
if (results == null && retryCount < 1) {
return this.getVideoTrackInfoFromManifest(++retryCount);
}
es.shutdown();
return results;
} catch (Exception e) {
DebugLog.w(TAG, "error in getVideoTrackInfoFromManifest handling request:" + e.getMessage());