Fix stream source selection
This commit is contained in:
parent
754271c466
commit
b44a1c2422
|
@ -1,5 +1,6 @@
|
||||||
package ctbrec.ui;
|
package ctbrec.ui;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
@ -15,7 +16,9 @@ public class StreamSourceSelectionDialog {
|
||||||
Task<List<StreamSource>> selectStreamSource = new Task<List<StreamSource>>() {
|
Task<List<StreamSource>> selectStreamSource = new Task<List<StreamSource>>() {
|
||||||
@Override
|
@Override
|
||||||
protected List<StreamSource> call() throws Exception {
|
protected List<StreamSource> call() throws Exception {
|
||||||
return model.getStreamSources();
|
List<StreamSource> sources = model.getStreamSources();
|
||||||
|
Collections.sort(sources);
|
||||||
|
return sources;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
selectStreamSource.setOnSucceeded((e) -> {
|
selectStreamSource.setOnSucceeded((e) -> {
|
||||||
|
|
|
@ -710,13 +710,20 @@ public class LocalRecorder implements Recorder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void switchStreamSource(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException {
|
public void switchStreamSource(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException {
|
||||||
|
if (models.contains(model)) {
|
||||||
|
int index = models.indexOf(model);
|
||||||
|
models.get(index).setStreamUrlIndex(model.getStreamUrlIndex());
|
||||||
|
config.save();
|
||||||
LOG.debug("Switching stream source to index {} for model {}", model.getStreamUrlIndex(), model.getName());
|
LOG.debug("Switching stream source to index {} for model {}", model.getStreamUrlIndex(), model.getName());
|
||||||
Download download = recordingProcesses.get(model);
|
Download download = recordingProcesses.get(model);
|
||||||
if(download != null) {
|
if(download != null) {
|
||||||
stopRecordingProcess(model);
|
stopRecordingProcess(model);
|
||||||
}
|
}
|
||||||
tryRestartRecording(model);
|
tryRestartRecording(model);
|
||||||
config.save();
|
} else {
|
||||||
|
LOG.warn("Couldn't switch stream source for model {}. Not found in list", model.getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -83,12 +83,18 @@ public abstract class AbstractHlsDownload implements Download {
|
||||||
|
|
||||||
|
|
||||||
String getSegmentPlaylistUrl(Model model) throws IOException, ExecutionException, ParseException, PlaylistException {
|
String getSegmentPlaylistUrl(Model model) throws IOException, ExecutionException, ParseException, PlaylistException {
|
||||||
|
LOG.debug("{} stream idx: {}", model.getName(), model.getStreamUrlIndex());
|
||||||
List<StreamSource> streamSources = model.getStreamSources();
|
List<StreamSource> streamSources = model.getStreamSources();
|
||||||
|
Collections.sort(streamSources);
|
||||||
|
for (StreamSource streamSource : streamSources) {
|
||||||
|
LOG.debug("{} src {}", model.getName(), streamSource);
|
||||||
|
}
|
||||||
String url = null;
|
String url = null;
|
||||||
if(model.getStreamUrlIndex() >= 0 && model.getStreamUrlIndex() < streamSources.size()) {
|
if(model.getStreamUrlIndex() >= 0 && model.getStreamUrlIndex() < streamSources.size()) {
|
||||||
|
// TODO don't use the index, but the bandwidth. if the bandwidth does not match, take the closest one
|
||||||
|
LOG.debug("{} selected {}", model.getName(), streamSources.get(model.getStreamUrlIndex()));
|
||||||
url = streamSources.get(model.getStreamUrlIndex()).getMediaPlaylistUrl();
|
url = streamSources.get(model.getStreamUrlIndex()).getMediaPlaylistUrl();
|
||||||
} else {
|
} else {
|
||||||
Collections.sort(streamSources);
|
|
||||||
// filter out stream resolutions, which are too high
|
// filter out stream resolutions, which are too high
|
||||||
int maxRes = Config.getInstance().getSettings().maximumResolution;
|
int maxRes = Config.getInstance().getSettings().maximumResolution;
|
||||||
if(maxRes > 0) {
|
if(maxRes > 0) {
|
||||||
|
@ -103,9 +109,11 @@ public abstract class AbstractHlsDownload implements Download {
|
||||||
if(streamSources.isEmpty()) {
|
if(streamSources.isEmpty()) {
|
||||||
throw new ExecutionException(new RuntimeException("No stream left in playlist"));
|
throw new ExecutionException(new RuntimeException("No stream left in playlist"));
|
||||||
} else {
|
} else {
|
||||||
|
LOG.debug("{} selected {}", model.getName(), streamSources.get(streamSources.size()-1));
|
||||||
url = streamSources.get(streamSources.size()-1).getMediaPlaylistUrl();
|
url = streamSources.get(streamSources.size()-1).getMediaPlaylistUrl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LOG.debug("Segment playlist url {}", url);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue