Skip to content

Commit

Permalink
VEX-5545: Some Android codecs don't support specific resolutions (24i#8)
Browse files Browse the repository at this point in the history
Add support for detecting if format is supported and exclude unsupported resolutions from auto quality selection and video track info in RN.
  • Loading branch information
armands-malejevs authored Sep 26, 2021
1 parent 93604b2 commit a0b679c
Showing 1 changed file with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.google.android.exoplayer2.drm.FrameworkMediaDrm;
import com.google.android.exoplayer2.drm.HttpMediaDrmCallback;
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.MediaCodecUtil;
import com.google.android.exoplayer2.metadata.Metadata;
Expand Down Expand Up @@ -921,7 +922,9 @@ private WritableArray getVideoTrackInfo() {
videoTrack.putString("codecs", format.codecs != null ? format.codecs : "");
videoTrack.putString("trackId",
format.id == null ? String.valueOf(trackIndex) : format.id);
videoTracks.pushMap(videoTrack);
if (isFormatSupported(format)) {
videoTracks.pushMap(videoTrack);
}
}
}
return videoTracks;
Expand Down Expand Up @@ -1241,10 +1244,31 @@ public void setSelectedTrack(int trackType, String type, Dynamic value) {
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
TrackGroup group = groups.get(0);
tracks = new int[group.length];
int[] allTracks = new int[group.length];
groupIndex = 0;

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++;
}
}
}

Expand All @@ -1262,6 +1286,25 @@ public void setSelectedTrack(int trackType, String type, Dynamic value) {
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) {
if (groups.length == 0){
return C.INDEX_UNSET;
Expand Down

0 comments on commit a0b679c

Please sign in to comment.