VEX-5545: Some Android codecs don't support specific resolutions (#8)

Add support for detecting if format is supported and exclude unsupported resolutions from auto quality selection and video track info in RN.
This commit is contained in:
Armands Malejev 2021-09-26 16:38:10 +03:00 committed by GitHub
parent 93604b2c25
commit a0b679cc07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,7 @@ import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
import com.google.android.exoplayer2.drm.FrameworkMediaDrm; import com.google.android.exoplayer2.drm.FrameworkMediaDrm;
import com.google.android.exoplayer2.drm.HttpMediaDrmCallback; import com.google.android.exoplayer2.drm.HttpMediaDrmCallback;
import com.google.android.exoplayer2.drm.UnsupportedDrmException; import com.google.android.exoplayer2.drm.UnsupportedDrmException;
import com.google.android.exoplayer2.mediacodec.MediaCodecInfo;
import com.google.android.exoplayer2.mediacodec.MediaCodecRenderer; import com.google.android.exoplayer2.mediacodec.MediaCodecRenderer;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil; import com.google.android.exoplayer2.mediacodec.MediaCodecUtil;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
@ -921,7 +922,9 @@ class ReactExoplayerView extends FrameLayout implements
videoTrack.putString("codecs", format.codecs != null ? format.codecs : ""); videoTrack.putString("codecs", format.codecs != null ? format.codecs : "");
videoTrack.putString("trackId", videoTrack.putString("trackId",
format.id == null ? String.valueOf(trackIndex) : format.id); format.id == null ? String.valueOf(trackIndex) : format.id);
videoTracks.pushMap(videoTrack); if (isFormatSupported(format)) {
videoTracks.pushMap(videoTrack);
}
} }
} }
return videoTracks; return videoTracks;
@ -1241,10 +1244,31 @@ class ReactExoplayerView extends FrameLayout implements
if (groupIndex == C.INDEX_UNSET && trackType == C.TRACK_TYPE_VIDEO && groups.length != 0) { // Video auto if (groupIndex == C.INDEX_UNSET && trackType == C.TRACK_TYPE_VIDEO && groups.length != 0) { // Video auto
// Add all tracks as valid options for ABR to choose from // Add all tracks as valid options for ABR to choose from
TrackGroup group = groups.get(0); TrackGroup group = groups.get(0);
tracks = new int[group.length]; int[] allTracks = new int[group.length];
groupIndex = 0; groupIndex = 0;
for (int j = 0; j < group.length; j++) { for (int j = 0; j < group.length; j++) {
tracks[j] = j; allTracks[j] = j;
}
// Valiate list of all tracks and add only supported formats
int supportedFormatLength = 0;
ArrayList<Integer> supportedTrackList = new ArrayList<Integer>();
for (int g = 0; g < allTracks.length; g++) {
Format format = group.getFormat(g);
if (isFormatSupported(format)) {
supportedFormatLength++;
}
}
tracks = new int[supportedFormatLength + 1];
int o = 0;
for (int k = 0; k < allTracks.length; k++) {
Format format = group.getFormat(k);
if (isFormatSupported(format)) {
tracks[o] = allTracks[k];
supportedTrackList.add(allTracks[k]);
o++;
}
} }
} }
@ -1262,6 +1286,25 @@ class ReactExoplayerView extends FrameLayout implements
trackSelector.setParameters(selectionParameters); trackSelector.setParameters(selectionParameters);
} }
private boolean isFormatSupported(Format format) {
int width = format.width == Format.NO_VALUE ? 0 : format.width;
int height = format.height == Format.NO_VALUE ? 0 : format.height;
float frameRate = format.frameRate == Format.NO_VALUE ? 0 : format.frameRate;
String mimeType = format.sampleMimeType;
if (mimeType == null) {
return true;
}
boolean isSupported = false;
try {
MediaCodecInfo codecInfo = MediaCodecUtil.getDecoderInfo(mimeType, false, false);
isSupported = codecInfo.isVideoSizeAndRateSupportedV21(width, height, frameRate);
} catch (Exception e) {
// Failed to get decoder info - assume it is supported
isSupported = true;
}
return isSupported;
}
private int getGroupIndexForDefaultLocale(TrackGroupArray groups) { private int getGroupIndexForDefaultLocale(TrackGroupArray groups) {
if (groups.length == 0){ if (groups.length == 0){
return C.INDEX_UNSET; return C.INDEX_UNSET;