track selection fix

This commit is contained in:
Yuriy Liskov
2020-10-03 23:42:48 +03:00
parent f64de8f585
commit 7361f68746
3 changed files with 51 additions and 4 deletions

View File

@@ -413,6 +413,10 @@ public class TrackSelectorManager implements TrackSelectorCallback {
result = mediaTrack;
}
}
if (result.format != null && TrackSelectorUtil.codecEquals(result.format.codecs, track.format.codecs)) {
break;
}
}
}

View File

@@ -119,4 +119,12 @@ public class TrackSelectorUtil {
playbackState == Player.STATE_IDLE ? "STATE_IDLE" :
"STATE_ENDED";
}
public static boolean codecEquals(String codecs1, String codecs2) {
if (codecs1 == null || codecs2 == null) {
return false;
}
return Helpers.equals(TrackSelectorUtil.codecNameShort(codecs1), TrackSelectorUtil.codecNameShort(codecs2));
}
}

View File

@@ -54,6 +54,39 @@ public class VideoTrack extends MediaTrack {
return track.format.frameRate == -1;
}
//@Override
//public int compare(MediaTrack track2) {
// if (track2.format == null) {
// return 1;
// }
//
// int result = -1;
//
// if (Helpers.equals(format.id, track2.format.id)) {
// result = 0;
// } else if (codecEquals(format.codecs, track2.format.codecs)) {
// if (fpsLessOrEquals(track2.format.frameRate, format.frameRate)) {
// if (heightEquals(format.height, track2.format.height)) {
// if (TrackSelectorUtil.isHdrCodec(format.codecs) == TrackSelectorUtil.isHdrCodec(track2.format.codecs)) {
// result = 0;
// } else {
// result = 1;
// }
// } else if (heightLessOrEquals(track2.format.height, format.height)) {
// result = 1;
// }
// }
// } else if (fpsLessOrEquals(track2.format.frameRate, format.frameRate)) {
// if (heightEquals(format.height, track2.format.height)) {
// result = 2;
// } else if (heightLessOrEquals(track2.format.height, format.height)) {
// result = 2;
// }
// }
//
// return result;
//}
@Override
public int compare(MediaTrack track2) {
if (track2.format == null) {
@@ -64,17 +97,19 @@ public class VideoTrack extends MediaTrack {
if (Helpers.equals(format.id, track2.format.id)) {
result = 0;
} else if (codecEquals(format.codecs, track2.format.codecs) || isLive(track2)) {
if (fpsLessOrEquals(track2.format.frameRate, format.frameRate)) {
if (heightEquals(format.height, track2.format.height)) {
} if (fpsLessOrEquals(track2.format.frameRate, format.frameRate)) {
if (heightEquals(format.height, track2.format.height)) {
if (codecEquals(format.codecs, track2.format.codecs)) {
if (TrackSelectorUtil.isHdrCodec(format.codecs) == TrackSelectorUtil.isHdrCodec(track2.format.codecs)) {
result = 0;
} else {
result = 1;
}
} else if (heightLessOrEquals(track2.format.height, format.height)) {
} else {
result = 1;
}
} else if (heightLessOrEquals(track2.format.height, format.height)) {
result = 1;
}
}