mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Rename MJPEG streams when camera name changes (#136)
* Rename MJPEG streams when camera name changes * Change camera name to HTTP request This allows us to wait for it to for sure be done * Fix reload logic * whee lnt * Reload on backend connect too * Update CameraAndPipelineSelect.vue
This commit is contained in:
@@ -160,6 +160,20 @@ public class RequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setCameraNickname(Context ctx) {
|
||||
try {
|
||||
var data = kObjectMapper.readValue(ctx.body(), HashMap.class);
|
||||
String name = String.valueOf(data.get("name"));
|
||||
int idx = Integer.parseInt(String.valueOf(data.get("cameraIndex")));
|
||||
VisionModuleManager.getInstance().getModule(idx).setCameraNickname(name);
|
||||
ctx.status(200);
|
||||
return;
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ctx.status(500);
|
||||
}
|
||||
|
||||
public static void uploadPnpModel(Context ctx) {
|
||||
UITargetData data;
|
||||
try {
|
||||
|
||||
@@ -81,6 +81,7 @@ public class Server {
|
||||
app.post("api/restartProgram", RequestHandler::restartProgram);
|
||||
app.post("api/vision/pnpModel", RequestHandler::uploadPnpModel);
|
||||
app.post("api/sendMetrics", RequestHandler::sendMetrics);
|
||||
app.post("api/setCameraNickname", RequestHandler::setCameraNickname);
|
||||
|
||||
app.start(port);
|
||||
}
|
||||
|
||||
@@ -34,12 +34,12 @@ import org.photonvision.vision.frame.FrameDivisor;
|
||||
|
||||
public class MJPGFrameConsumer {
|
||||
|
||||
private final CvSource cvSource;
|
||||
private final MjpegServer mjpegServer;
|
||||
private CvSource cvSource;
|
||||
private MjpegServer mjpegServer;
|
||||
private FrameDivisor divisor = FrameDivisor.NONE;
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private final VideoListener listener;
|
||||
private VideoListener listener;
|
||||
|
||||
private final NetworkTable table;
|
||||
|
||||
@@ -163,4 +163,14 @@ public class MJPGFrameConsumer {
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
table.getEntry("connected").setBoolean(false);
|
||||
mjpegServer.close();
|
||||
cvSource.close();
|
||||
listener.close();
|
||||
mjpegServer = null;
|
||||
cvSource = null;
|
||||
listener = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +135,11 @@ public class VisionModule {
|
||||
saveAndBroadcastAll();
|
||||
}
|
||||
|
||||
private void destroyStreams() {
|
||||
dashboardInputStreamer.close();
|
||||
dashboardOutputStreamer.close();
|
||||
}
|
||||
|
||||
private void createStreams() {
|
||||
var camStreamIdx = visionSource.getSettables().getConfiguration().streamIndex;
|
||||
// If idx = 0, we want (1181, 1182)
|
||||
@@ -143,11 +148,10 @@ public class VisionModule {
|
||||
|
||||
dashboardOutputStreamer =
|
||||
new MJPGFrameConsumer(
|
||||
visionSource.getSettables().getConfiguration().uniqueName + "-output",
|
||||
outputStreamPort);
|
||||
visionSource.getSettables().getConfiguration().nickname + "-output", outputStreamPort);
|
||||
dashboardInputStreamer =
|
||||
new MJPGFrameConsumer(
|
||||
visionSource.getSettables().getConfiguration().uniqueName + "-input", inputStreamPort);
|
||||
visionSource.getSettables().getConfiguration().nickname + "-input", inputStreamPort);
|
||||
}
|
||||
|
||||
void setDriverMode(boolean isDriverMode) {
|
||||
@@ -280,17 +284,22 @@ public class VisionModule {
|
||||
OutgoingUIEvent.wrappedOf("mutatePipeline", propertyName, value, originContext));
|
||||
}
|
||||
|
||||
void setCameraNickname(String newName) {
|
||||
public void setCameraNickname(String newName) {
|
||||
visionSource.getSettables().getConfiguration().nickname = newName;
|
||||
ntConsumer.updateCameraNickname(newName);
|
||||
|
||||
// rename streams
|
||||
fpsLimitedResultConsumers.clear();
|
||||
|
||||
// Teardown and recreate streams
|
||||
destroyStreams();
|
||||
createStreams();
|
||||
|
||||
fpsLimitedResultConsumers.add(result -> dashboardInputStreamer.accept(result.inputFrame));
|
||||
fpsLimitedResultConsumers.add(result -> dashboardOutputStreamer.accept(result.outputFrame));
|
||||
|
||||
// Push new data to the UI
|
||||
saveAndBroadcastAll();
|
||||
}
|
||||
|
||||
public PhotonConfiguration.UICameraConfiguration toUICameraConfig() {
|
||||
|
||||
@@ -62,12 +62,11 @@ public class VisionModuleChangeSubscriber extends DataChangeSubscriber {
|
||||
|
||||
// special case for non-PipelineSetting changes
|
||||
switch (propName) {
|
||||
case "cameraNickname": // rename camera
|
||||
var newNickname = (String) newPropValue;
|
||||
logger.info("Changing nickname to " + newNickname);
|
||||
parentModule.setCameraNickname(newNickname);
|
||||
parentModule.saveAndBroadcastAll();
|
||||
return;
|
||||
// case "cameraNickname": // rename camera
|
||||
// var newNickname = (String) newPropValue;
|
||||
// logger.info("Changing nickname to " + newNickname);
|
||||
// parentModule.setCameraNickname(newNickname);
|
||||
// return;
|
||||
case "pipelineName": // rename current pipeline
|
||||
logger.info("Changing nick to " + newPropValue);
|
||||
parentModule.pipelineManager.getCurrentPipelineSettings().pipelineNickname =
|
||||
|
||||
Reference in New Issue
Block a user