Fix TCP retry bug when some RTSP tracks are not selected.

The size of rtspLoaderWrappers must match the number of tracks exposed by the
RTSP session (a track is exposed if its media description entry appears in
DESCRIBE's SDP response).

When retrying with TCP, the old code will start loading all exposed RTSP
tracks, regardless of whether they are selected.
The fixed code will only start loading selected tracks.

#minor-release

PiperOrigin-RevId: 377931030
This commit is contained in:
claincly 2021-06-07 17:09:34 +01:00 committed by bachinger
parent 4b30cca914
commit d0dc72fb6a

View File

@ -306,11 +306,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Nullable
private RtpDataLoadable getLoadableByTrackUri(Uri trackUri) {
for (int i = 0; i < rtspLoaderWrappers.size(); i++) {
if (!rtspLoaderWrappers.get(i).canceled) {
RtpLoadInfo loadInfo = rtspLoaderWrappers.get(i).loadInfo;
if (loadInfo.getTrackUri().equals(trackUri)) {
return loadInfo.loadable;
}
}
}
return null;
}
@ -543,18 +545,22 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
ArrayList<RtspLoaderWrapper> newLoaderWrappers = new ArrayList<>(rtspLoaderWrappers.size());
ArrayList<RtpLoadInfo> newSelectedLoadInfos = new ArrayList<>(selectedLoadInfos.size());
// newLoaderWrappers' elements and orders must match those of rtspLoaderWrappers'.
for (int i = 0; i < rtspLoaderWrappers.size(); i++) {
RtspLoaderWrapper loaderWrapper = rtspLoaderWrappers.get(i);
if (!loaderWrapper.canceled) {
RtspLoaderWrapper newLoaderWrapper =
new RtspLoaderWrapper(
loaderWrapper.loadInfo.mediaTrack, /* trackId= */ i, rtpDataChannelFactory);
newLoaderWrappers.add(newLoaderWrapper);
newLoaderWrapper.startLoading();
if (selectedLoadInfos.contains(loaderWrapper.loadInfo)) {
newSelectedLoadInfos.add(newLoaderWrapper.loadInfo);
}
} else {
newLoaderWrappers.add(loaderWrapper);
}
}
// Switch to new LoaderWrappers.
@ -644,22 +650,23 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** Cancels loading. */
public void cancelLoad() {
if (canceled) {
return;
}
if (!canceled) {
loadInfo.loadable.cancelLoad();
canceled = true;
// Update loadingFinished every time loading is canceled.
updateLoadingFinished();
}
}
/** Resets the {@link Loadable} and {@link SampleQueue} to prepare for an RTSP seek. */
public void seekTo(long positionUs) {
if (!canceled) {
loadInfo.loadable.resetForSeek();
sampleQueue.reset();
sampleQueue.setStartTimeUs(positionUs);
}
}
/** Releases the instance. */
public void release() {