Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FEC-12958): fix multicast change media not performing stop api on TrackSelectionHelper #798

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ public void onTimelineChanged(@NonNull Timeline timeline, int reason) {
log.d("onTimelineChanged reason = " + reason + " duration = " + getDuration());
if (reason == Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED) {
isLoadedMetaDataFired = false;
if (getDuration() != TIME_UNSET) {
if (getDuration() != TIME_UNSET || PKMediaFormat.udp.equals(sourceConfig.mediaSource.getMediaFormat())) {
sendDistinctEvent(PlayerEvent.Type.DURATION_CHANGE);
profiler.onDurationChanged(getDuration());
}
Expand Down Expand Up @@ -1156,7 +1156,6 @@ public void pause() {
if (currentEvent == PlayerEvent.Type.ENDED) {
return;
}

sendDistinctEvent(PlayerEvent.Type.PAUSE);
profiler.onPauseRequested();
player.setPlayWhenReady(false);
Expand Down Expand Up @@ -1346,6 +1345,10 @@ public void changeTrack(String uniqueId) {
try {
trackSelectionHelper.changeTrack(uniqueId);
} catch (IllegalArgumentException ex) {
int trackTypeId = trackSelectionHelper.getTrackTypeId(uniqueId);
if (trackTypeId >= 0) {
lastSelectedTrackIds[trackTypeId] = TrackSelectionHelper.NONE;
}
sendTrackSelectionError(uniqueId, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ private PlayerEngine.EventListener initEventListener() {
break;
case DURATION_CHANGE:
event = new PlayerEvent.DurationChanged(getDuration());
if (getDuration() != Consts.TIME_UNSET && isNewEntry) {
if ((getDuration() != Consts.TIME_UNSET || getMediaFormat() == PKMediaFormat.udp) && isNewEntry) {
if (mediaConfig.getStartPosition() != null) {
if (mediaConfig.getStartPosition() * MILLISECONDS_MULTIPLIER > getDuration()) {
mediaConfig.setStartPosition(getDuration() / MILLISECONDS_MULTIPLIER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public PKTracks buildTracks(String externalThumbnailWebVttUrl, List<CustomFormat
// in future handle that in hls case for thumbnailInfo
continue;
}

if (!videoTracksAvailable) {
videoTracksAvailable = true;
}
Expand Down Expand Up @@ -1149,11 +1149,16 @@ private int restoreLastSelectedTrack(List<? extends BaseTrack> trackList, String
//If track was previously selected and selection is differed from the default selection apply it.
String defaultUniqueId = trackList.get(defaultTrackIndex).getUniqueId();
if (!NONE.equals(lastSelectedTrackId) && !lastSelectedTrackId.equals(defaultUniqueId)) {
changeTrack(lastSelectedTrackId);
for (int i = 0; i < trackList.size(); i++) {
if (lastSelectedTrackId.equals(trackList.get(i).getUniqueId())) {
return i;
try {
changeTrack(lastSelectedTrackId);
for (int i = 0; i < trackList.size(); i++) {
if (lastSelectedTrackId.equals(trackList.get(i).getUniqueId())) {
return i;
}
}
} catch (IllegalArgumentException ex) {
PKError currentError = new PKError(PKPlayerErrorType.UNEXPECTED, PKError.Severity.Fatal, ex.getMessage(), ex);
tracksErrorListener.onUnsupportedTracksAvailableError(currentError);
}
}

Expand Down Expand Up @@ -1238,7 +1243,7 @@ private String getUniqueIdPostfix(int rendererIndex, int trackIndex) {
* @param uniqueId - unique identifier of the track to apply.
*/

protected void changeTrack(String uniqueId) {
protected void changeTrack(String uniqueId) throws IllegalArgumentException {
if (assertTrackSelectorIsNull("changeTrack")) {
return;
}
Expand Down Expand Up @@ -1831,24 +1836,43 @@ private int[] validateUniqueId(String uniqueId) throws IllegalArgumentException
|| uniqueId.contains(TEXT_PREFIX)
|| uniqueId.contains(IMAGE_PREFIX)
&& uniqueId.contains(",")) {

int trackTypeId = getTrackTypeId(uniqueId);
int[] parsedUniqueId = parseUniqueId(uniqueId);
if (!isRendererTypeValid(parsedUniqueId[RENDERER_INDEX])) {
lastSelectedTrackIds[trackTypeId] = NONE;
throw new IllegalArgumentException("Track selection with uniqueId = " + uniqueId + " failed. Due to invalid renderer index. " + parsedUniqueId[RENDERER_INDEX]);
}

if (!isGroupIndexValid(parsedUniqueId)) {
lastSelectedTrackIds[trackTypeId] = NONE;
throw new IllegalArgumentException("Track selection with uniqueId = " + uniqueId + " failed. Due to invalid group index. " + parsedUniqueId[GROUP_INDEX]);
}

if (!isTrackIndexValid(parsedUniqueId)) {
lastSelectedTrackIds[trackTypeId] = NONE;
throw new IllegalArgumentException("Track selection with uniqueId = " + uniqueId + " failed. Due to invalid track index. " + parsedUniqueId[TRACK_INDEX]);
}
return parsedUniqueId;
}
throw new IllegalArgumentException("Invalid structure of uniqueId " + uniqueId);
}

public int getTrackTypeId(String uniqueId) {
if (uniqueId.contains(VIDEO_PREFIX)) {
return TRACK_TYPE_VIDEO;
}
if (uniqueId.contains(AUDIO_PREFIX)) {
return TRACK_TYPE_AUDIO;
}
if (uniqueId.contains(TEXT_PREFIX)) {
return TRACK_TYPE_TEXT;
}
if (uniqueId.contains(IMAGE_PREFIX)) {
return TRACK_TYPE_IMAGE;
}
return -1;
}

private boolean isTrackIndexValid(int[] parsedUniqueId) {
int rendererIndex = parsedUniqueId[RENDERER_INDEX];
int groupIndex = parsedUniqueId[GROUP_INDEX];
Expand Down