Skip to content

Commit

Permalink
fix(android)!: rework video tracks management (#3778)
Browse files Browse the repository at this point in the history
* fix: fix crash when invalid index type is provided and minor clean up
* fix: review video track management. Fix index support and rework string vs int in tracks management
* fix: ABR track selection check
* fix: split track selector in sample and lint code
* fix: ensure we don't report null fields
* chore: improve tracks displayed
* chore: start moving to selection by index only
  • Loading branch information
freeboub authored May 22, 2024
1 parent dbd7d7a commit cad5c46
Show file tree
Hide file tree
Showing 15 changed files with 530 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class VideoTrack {
var height = 0
var bitrate = 0
var codecs = ""
var id = -1
var index = -1
var trackId = ""
var isSelected = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,15 @@ WritableArray audioTracksToArray(ArrayList<Track> audioTracks) {
WritableMap audioTrack = Arguments.createMap();
audioTrack.putInt("index", i);
audioTrack.putString("title", format.getTitle());
audioTrack.putString("type", format.getMimeType());
audioTrack.putString("language", format.getLanguage());
audioTrack.putInt("bitrate", format.getBitrate());
if (format.getMimeType() != null) {
audioTrack.putString("type", format.getMimeType());
}
if (format.getLanguage() != null) {
audioTrack.putString("language", format.getLanguage());
}
if (format.getBitrate() > 0) {
audioTrack.putInt("bitrate", format.getBitrate());
}
audioTrack.putBoolean("selected", format.isSelected());
waAudioTracks.pushMap(audioTrack);
}
Expand All @@ -214,7 +220,8 @@ WritableArray videoTracksToArray(ArrayList<VideoTrack> videoTracks) {
videoTrack.putInt("height",vTrack.getHeight());
videoTrack.putInt("bitrate", vTrack.getBitrate());
videoTrack.putString("codecs", vTrack.getCodecs());
videoTrack.putInt("trackId",vTrack.getId());
videoTrack.putString("trackId", vTrack.getTrackId());
videoTrack.putInt("index", vTrack.getIndex());
videoTrack.putBoolean("selected", vTrack.isSelected());
waVideoTracks.pushMap(videoTrack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public final class ExoPlayerView extends FrameLayout implements AdViewProvider {
private final AspectRatioFrameLayout layout;
private final ComponentListener componentListener;
private ExoPlayer player;
private Context context;
private ViewGroup.LayoutParams layoutParams;
private final Context context;
private final ViewGroup.LayoutParams layoutParams;
private final FrameLayout adOverlayFrameLayout;

private boolean useTextureView = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1428,13 +1428,14 @@ private VideoTrack exoplayerVideoTrackToGenericVideoTrack(Format format, int tra
videoTrack.setBitrate(format.bitrate == Format.NO_VALUE ? 0 : format.bitrate);
if (format.codecs != null) videoTrack.setCodecs(format.codecs);
videoTrack.setTrackId(format.id == null ? String.valueOf(trackIndex) : format.id);
videoTrack.setIndex(trackIndex);
return videoTrack;
}

private ArrayList<VideoTrack> getVideoTrackInfo() {
ArrayList<VideoTrack> videoTracks = new ArrayList<>();
if (trackSelector == null) {
// Likely player is unmounting so no audio tracks are available anymore
// Likely player is unmounting so no video tracks are available anymore
return videoTracks;
}
MappingTrackSelector.MappedTrackInfo info = trackSelector.getCurrentMappedTrackInfo();
Expand Down Expand Up @@ -1869,14 +1870,15 @@ public void setSelectedTrack(int trackType, String type, String value) {
}
}
} else if ("index".equals(type)) {
try {
int iValue = Integer.parseInt(value);
if (iValue < groups.length) {
groupIndex = iValue;
}
} catch (Exception e) {
DebugLog.e(TAG, "cannot parse index:" + value);
int iValue = Integer.parseInt(value);

if (trackType == C.TRACK_TYPE_VIDEO && groups.length == 1) {
groupIndex = 0;
if (iValue < groups.get(groupIndex).length) {
tracks.set(0, iValue);
}
} else if (iValue < groups.length) {
groupIndex = iValue;
}
} else if ("resolution".equals(type)) {
int height = Integer.parseInt(value);
Expand Down
12 changes: 7 additions & 5 deletions docs/pages/component/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ Example:
{ title: '#3 English Director Commentary', language: 'en', index: 2, type: 'text/vtt' }
],
videoTracks: [
{ bitrate: 3987904, codecs: "avc1.640028", height: 720, trackId: "f1-v1-x3", width: 1280 },
{ bitrate: 7981888, codecs: "avc1.640028", height: 1080, trackId: "f2-v1-x3", width: 1920 },
{ bitrate: 1994979, codecs: "avc1.4d401f", height: 480, trackId: "f3-v1-x3", width: 848 }
{ index: 0, bitrate: 3987904, codecs: "avc1.640028", height: 720, trackId: "f1-v1-x3", width: 1280 },
{ index: 1, bitrate: 7981888, codecs: "avc1.640028", height: 1080, trackId: "f2-v1-x3", width: 1920 },
{ index: 2, bitrate: 1994979, codecs: "avc1.4d401f", height: 480, trackId: "f3-v1-x3", width: 848 }
]
}
```
Expand Down Expand Up @@ -550,7 +550,8 @@ Payload:

| Property | Type | Description |
| -------- | ------- | ------------------------------------- |
| trackId | number | Internal track ID |
| index | number | index of the track |
| trackId | string | Internal track ID |
| codecs | string | MimeType of codec used for this track |
| width | number | Track width |
| height | number | Track height |
Expand All @@ -563,7 +564,8 @@ Example:
{
videoTracks: [
{
trackId: 0,
index: O,
trackId: "0",
codecs: 'video/mp4',
width: 1920,
height: 1080,
Expand Down
Loading

0 comments on commit cad5c46

Please sign in to comment.