Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/api/rest_api_openapi_u64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3375,13 +3375,31 @@ paths:
schema:
type: string
example: '192.168.1.10:11000'
- name: palette
in: query
required: false
description: 'For video, request runtime VIC palette packets (0 or 1). The setting is device-wide: it applies to every receiver of the stream, and the most recent start sets it.'
schema:
type: integer
example: 0
responses:
'200':
description: The stream is running.
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
examples:
Palette must be 0 or 1 and is only valid for the video stream:
value:
errors:
- Palette must be 0 or 1 and is only valid for the video stream
'403':
$ref: '#/components/responses/Forbidden'
'404':
Expand Down
16 changes: 14 additions & 2 deletions software/api/route_streams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ API_DOC(PUT, streams, start,
PATH_PARAM("stream", "string", "Which stream to act on.", "video")
PATH_PARAM_ENUM("stream", "video,audio,debug")
PARAM("ip", "string", "Where to send the stream. An address, optionally followed by a port.", "", "192.168.1.10:11000")
PARAM("palette", "integer", "For video, request runtime VIC palette packets (0 or 1). The setting is device-wide: it applies to every receiver of the stream, and the most recent start sets it.", "", "0")
RESPONSE("200", "application/json", "ErrorResponse", "The stream is running.", "")
RESPONSE_ERROR("400", "Palette must be 0 or 1 and is only valid for the video stream", "")
RESPONSE_ERROR("404", "Unrecognized stream name 'screen'", "")
RESPONSE_ERROR("500", "No Operational Network Interface", "")
)
API_CALL(PUT, streams, start, NULL, ARRAY ( { { "ip", P_REQUIRED } }))
API_CALL(PUT, streams, start, NULL, ARRAY ( { { "ip", P_REQUIRED }, { "palette", P_OPTIONAL } }))
{
const char *streamName = args.get_path(0);
SubsysCommand *sys_command;
Expand All @@ -52,13 +54,23 @@ API_CALL(PUT, streams, start, NULL, ARRAY ( { { "ip", P_REQUIRED } }))
return;
}

// Checked before anything is stopped, so a rejected request changes nothing.
const char *paletteArg = args.get_or("palette", NULL);
const bool paletteRequested = paletteArg && strcmp(paletteArg, "1") == 0;
if (paletteArg && (streamIndex != 0 || (strcmp(paletteArg, "0") != 0 && !paletteRequested))) {
resp->error("Palette must be 0 or 1 and is only valid for the video stream");
resp->json_response(HTTP_BAD_REQUEST);
return;
}

if (streamIndex == 0) { // video streams require debug to be off
sys_command = new SubsysCommand(NULL, -1, (int)dataStreamer, 2, "", "");
sys_command->direct_call = DataStreamer :: S_stopStream;
sys_command->execute();
}

sys_command = new SubsysCommand(NULL, -1, (int)dataStreamer, streamIndex, args["ip"], "");
const int mode = streamIndex | (paletteRequested ? STREAM_MODE_PALETTE : 0);
sys_command = new SubsysCommand(NULL, -1, (int)dataStreamer, mode, args["ip"], "");
sys_command->direct_call = DataStreamer :: S_startStream;
SubsysResultCode_t retval = sys_command->execute();
resp->error(SubsysCommand::error_string(retval.status));
Expand Down
Loading