forked from j62/ctbrec
1
0
Fork 0

Fix stream source selection

This commit is contained in:
0xboobface 2018-12-01 02:12:27 +01:00
parent 754271c466
commit b44a1c2422
3 changed files with 26 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package ctbrec.ui;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
@ -15,7 +16,9 @@ public class StreamSourceSelectionDialog {
Task<List<StreamSource>> selectStreamSource = new Task<List<StreamSource>>() {
@Override
protected List<StreamSource> call() throws Exception {
return model.getStreamSources();
List<StreamSource> sources = model.getStreamSources();
Collections.sort(sources);
return sources;
}
};
selectStreamSource.setOnSucceeded((e) -> {

View File

@ -710,13 +710,20 @@ public class LocalRecorder implements Recorder {
@Override
public void switchStreamSource(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException {
LOG.debug("Switching stream source to index {} for model {}", model.getStreamUrlIndex(), model.getName());
Download download = recordingProcesses.get(model);
if(download != null) {
stopRecordingProcess(model);
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());
Download download = recordingProcesses.get(model);
if(download != null) {
stopRecordingProcess(model);
}
tryRestartRecording(model);
} else {
LOG.warn("Couldn't switch stream source for model {}. Not found in list", model.getName());
return;
}
tryRestartRecording(model);
config.save();
}
@Override

View File

@ -83,12 +83,18 @@ public abstract class AbstractHlsDownload implements Download {
String getSegmentPlaylistUrl(Model model) throws IOException, ExecutionException, ParseException, PlaylistException {
LOG.debug("{} stream idx: {}", model.getName(), model.getStreamUrlIndex());
List<StreamSource> streamSources = model.getStreamSources();
Collections.sort(streamSources);
for (StreamSource streamSource : streamSources) {
LOG.debug("{} src {}", model.getName(), streamSource);
}
String url = null;
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();
} else {
Collections.sort(streamSources);
// filter out stream resolutions, which are too high
int maxRes = Config.getInstance().getSettings().maximumResolution;
if(maxRes > 0) {
@ -103,9 +109,11 @@ public abstract class AbstractHlsDownload implements Download {
if(streamSources.isEmpty()) {
throw new ExecutionException(new RuntimeException("No stream left in playlist"));
} else {
LOG.debug("{} selected {}", model.getName(), streamSources.get(streamSources.size()-1));
url = streamSources.get(streamSources.size()-1).getMediaPlaylistUrl();
}
}
LOG.debug("Segment playlist url {}", url);
return url;
}