forked from j62/ctbrec
1
0
Fork 0

Add possibility to switch the stream resolution for a recording

Add the possibility to switch the stream resolution for a model, which
already is recorded by the recorder. This makes it more convenient to
switch the resolution, if you already have a bunch of models in the
recorder list.
This commit is contained in:
0xboobface 2018-09-04 16:50:38 +02:00
parent c80f81d937
commit 22d32bcc64
5 changed files with 62 additions and 1 deletions

View File

@ -9,6 +9,8 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.ArrayList;
@ -614,4 +616,11 @@ public class LocalRecorder implements Recorder {
}
return mergedFile;
}
@Override
public void switchStreamSource(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException {
LOG.debug("Switching stream source to index {} for model {}", model.getStreamUrlIndex(), model.getName());
stopRecordingProcess(model);
tryRestartRecording(model);
}
}

View File

@ -14,6 +14,8 @@ public interface Recorder {
public void stopRecording(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException;
public void switchStreamSource(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException;
/**
* Returns, if a model is in the list of models to record. This does not reflect, if there currently is a recording running. The model might be offline
* aswell.

View File

@ -264,4 +264,9 @@ public class RemoteRecorder implements Recorder {
this.model = model;
}
}
@Override
public void switchStreamSource(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException {
sendRequest("switch", model);
}
}

View File

@ -104,6 +104,11 @@ public class RecorderServlet extends AbstractCtbrecServlet {
resp.getWriter().write(recAdapter.toJson(rec));
resp.getWriter().write("]}");
break;
case "switch":
recorder.switchStreamSource(request.model);
response = "{\"status\": \"success\", \"msg\": \"Resolution switched\"}";
resp.getWriter().write(response);
break;
default:
resp.setStatus(SC_BAD_REQUEST);
response = "{\"status\": \"error\", \"msg\": \"Unknown action\"}";

View File

@ -9,10 +9,12 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.HttpClient;
import ctbrec.Model;
import ctbrec.recorder.Recorder;
import javafx.application.Platform;
@ -217,8 +219,46 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
openInBrowser.setOnAction((e) -> Launcher.open(table.getSelectionModel().getSelectedItem().getUrl()));
MenuItem openInPlayer = new MenuItem("Open in Player");
openInPlayer.setOnAction((e) -> Player.play(table.getSelectionModel().getSelectedItem().getUrl()));
MenuItem switchStreamSource = new MenuItem("Switch resolution");
switchStreamSource.setOnAction((e) -> switchStreamSource(table.getSelectionModel().getSelectedItem()));
return new ContextMenu(stop, copyUrl, openInBrowser, openInPlayer);
return new ContextMenu(stop, copyUrl, openInBrowser, switchStreamSource);
}
private void switchStreamSource(JavaFxModel fxModel) {
if(!fxModel.isOnline()) {
Alert alert = new AutosizeAlert(Alert.AlertType.INFORMATION);
alert.setTitle("Switch resolution");
alert.setHeaderText("Couldn't switch stream resolution");
alert.setContentText("The resolution can only be changed, when the model is online");
alert.showAndWait();
return;
}
HttpClient client = HttpClient.getInstance();
Function<Model, Void> onSuccess = (m) -> {
try {
recorder.switchStreamSource(m);
} catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | IOException e) {
LOG.error("Error while switching stream resolution", e);
showStreamSwitchErrorDialog(e);
}
return null;
};
Function<Throwable, Void> onFail = (t) -> {
LOG.error("Error while switching stream resolution", t);
showStreamSwitchErrorDialog(t);
return null;
};
StreamSourceSelectionDialog.show(fxModel.getDelegate(), client, onSuccess, onFail);
}
private void showStreamSwitchErrorDialog(Throwable throwable) {
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Couldn't switch stream resolution");
alert.setContentText("Error while switching stream resolution: " + throwable.getLocalizedMessage());
alert.showAndWait();
}
private void stopAction() {