mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: improved collection of RecordingProperties REST API params
parent
e3f66a75ec
commit
1d026e4a7d
|
@ -915,105 +915,190 @@ public class SessionRestController {
|
||||||
protected RecordingProperties.Builder getRecordingPropertiesFromParams(Map<?, ?> params, Session session)
|
protected RecordingProperties.Builder getRecordingPropertiesFromParams(Map<?, ?> params, Session session)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
RecordingProperties.Builder builder = new RecordingProperties.Builder();
|
// Final properties being used
|
||||||
|
String nameFinal = null;
|
||||||
|
Boolean hasAudioFinal = null;
|
||||||
|
Boolean hasVideoFinal = null;
|
||||||
|
OutputMode outputModeFinal = null;
|
||||||
|
RecordingLayout recordingLayoutFinal = null;
|
||||||
|
String resolutionFinal = null;
|
||||||
|
Integer frameRateFinal = null;
|
||||||
|
Long shmSizeFinal = null;
|
||||||
|
String customLayoutFinal = null;
|
||||||
|
|
||||||
|
RecordingProperties defaultProps = session.getSessionProperties().defaultRecordingProperties();
|
||||||
|
|
||||||
|
// Default properties configured in Session
|
||||||
|
String nameDefault = defaultProps.name();
|
||||||
|
Boolean hasAudioDefault = defaultProps.hasAudio();
|
||||||
|
Boolean hasVideoDefault = defaultProps.hasVideo();
|
||||||
|
OutputMode outputModeDefault = defaultProps.outputMode();
|
||||||
|
RecordingLayout recordingLayoutDefault = defaultProps.recordingLayout();
|
||||||
|
String resolutionDefault = defaultProps.resolution();
|
||||||
|
Integer frameRateDefault = defaultProps.frameRate();
|
||||||
|
Long shmSizeDefault = defaultProps.shmSize();
|
||||||
|
String customLayoutDefault = defaultProps.customLayout();
|
||||||
|
|
||||||
|
// Provided properties through params
|
||||||
|
String sessionIdParam;
|
||||||
|
String nameParam;
|
||||||
|
Boolean hasAudioParam;
|
||||||
|
Boolean hasVideoParam;
|
||||||
|
String outputModeStringParam;
|
||||||
|
String recordingLayoutStringParam;
|
||||||
|
String resolutionParam;
|
||||||
|
Integer frameRateParam;
|
||||||
|
Long shmSizeParam = null;
|
||||||
|
String customLayoutParam;
|
||||||
|
|
||||||
String sessionId;
|
|
||||||
String name;
|
|
||||||
String outputModeString;
|
|
||||||
String resolution;
|
|
||||||
Integer frameRate;
|
|
||||||
Boolean hasAudio;
|
|
||||||
Boolean hasVideo;
|
|
||||||
String recordingLayoutString;
|
|
||||||
String customLayout;
|
|
||||||
Long shmSize = null;
|
|
||||||
try {
|
try {
|
||||||
sessionId = (String) params.get("session");
|
sessionIdParam = (String) params.get("session");
|
||||||
name = (String) params.get("name");
|
nameParam = (String) params.get("name");
|
||||||
outputModeString = (String) params.get("outputMode");
|
hasAudioParam = (Boolean) params.get("hasAudio");
|
||||||
resolution = (String) params.get("resolution");
|
hasVideoParam = (Boolean) params.get("hasVideo");
|
||||||
frameRate = (Integer) params.get("frameRate");
|
outputModeStringParam = (String) params.get("outputMode");
|
||||||
hasAudio = (Boolean) params.get("hasAudio");
|
recordingLayoutStringParam = (String) params.get("recordingLayout");
|
||||||
hasVideo = (Boolean) params.get("hasVideo");
|
resolutionParam = (String) params.get("resolution");
|
||||||
recordingLayoutString = (String) params.get("recordingLayout");
|
frameRateParam = (Integer) params.get("frameRate");
|
||||||
customLayout = (String) params.get("customLayout");
|
|
||||||
if (params.get("shmSize") != null) {
|
if (params.get("shmSize") != null) {
|
||||||
shmSize = Long.parseLong(params.get("shmSize").toString());
|
shmSizeParam = Long.parseLong(params.get("shmSize").toString());
|
||||||
}
|
}
|
||||||
|
customLayoutParam = (String) params.get("customLayout");
|
||||||
} catch (ClassCastException | NumberFormatException e) {
|
} catch (ClassCastException | NumberFormatException e) {
|
||||||
throw new Exception("Type error in some parameter: " + e.getMessage());
|
throw new Exception("Type error in some parameter: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sessionId == null) {
|
if (sessionIdParam == null) {
|
||||||
// "session" parameter not found
|
// "session" parameter not found
|
||||||
throw new Exception("\"session\" parameter is mandatory");
|
throw new Exception("\"session\" parameter is mandatory");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name != null && !name.isEmpty()) {
|
if (nameParam != null) {
|
||||||
if (!sessionManager.formatChecker.isValidRecordingName(name)) {
|
if (!sessionManager.formatChecker.isValidRecordingName(nameParam)) {
|
||||||
throw new Exception("Parameter 'name' is wrong. Must be an alphanumeric string [a-zA-Z0-9_-]");
|
throw new Exception("Parameter 'name' is wrong. Must be an alphanumeric string [a-zA-Z0-9_-]+");
|
||||||
}
|
}
|
||||||
|
nameFinal = nameParam;
|
||||||
|
} else if (nameDefault != null) {
|
||||||
|
nameFinal = nameDefault;
|
||||||
|
} else {
|
||||||
|
nameFinal = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputMode finalOutputMode = OutputMode.COMPOSED;
|
if (hasAudioParam != null) {
|
||||||
RecordingLayout recordingLayout = null;
|
hasAudioFinal = hasAudioParam;
|
||||||
if (outputModeString != null && !outputModeString.isEmpty()) {
|
} else if (hasAudioDefault != null) {
|
||||||
try {
|
hasAudioFinal = hasAudioDefault;
|
||||||
finalOutputMode = OutputMode.valueOf(outputModeString);
|
} else {
|
||||||
} catch (Exception e) {
|
hasAudioFinal = RecordingProperties.DefaultValues.hasAudio;
|
||||||
throw new Exception("Type error in parameter 'outputMode'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasVideoParam != null) {
|
||||||
|
hasVideoFinal = hasVideoParam;
|
||||||
|
} else if (hasAudioDefault != null) {
|
||||||
|
hasVideoFinal = hasVideoDefault;
|
||||||
|
} else {
|
||||||
|
hasVideoFinal = RecordingProperties.DefaultValues.hasVideo;
|
||||||
}
|
}
|
||||||
if (RecordingUtils.IS_COMPOSED(finalOutputMode)) {
|
|
||||||
if (resolution != null && !sessionManager.formatChecker.isAcceptableRecordingResolution(resolution)) {
|
if (!hasAudioFinal && !hasVideoFinal) {
|
||||||
throw new RuntimeException(
|
|
||||||
"Wrong 'resolution' parameter. Acceptable values from 100 to 1999 for both width and height");
|
|
||||||
}
|
|
||||||
if (frameRate != null && !sessionManager.formatChecker.isAcceptableRecordingFrameRate(frameRate)) {
|
|
||||||
throw new RuntimeException("Wrong 'frameRate' parameter. Must be a number between 1 and 120");
|
|
||||||
}
|
|
||||||
if (recordingLayoutString != null && !recordingLayoutString.isEmpty()) {
|
|
||||||
try {
|
|
||||||
recordingLayout = RecordingLayout.valueOf(recordingLayoutString);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new Exception("Type error in parameter 'recordingLayout'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((hasAudio != null && hasVideo != null) && !hasAudio && !hasVideo) {
|
|
||||||
// Cannot start a recording with both "hasAudio" and "hasVideo" to false
|
// Cannot start a recording with both "hasAudio" and "hasVideo" to false
|
||||||
throw new RuntimeException("Cannot start a recording with both \"hasAudio\" and \"hasVideo\" set to false");
|
throw new RuntimeException("Cannot start a recording with both \"hasAudio\" and \"hasVideo\" set to false");
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordingProperties defaultRecordingProperties = session.getSessionProperties().defaultRecordingProperties();
|
if (outputModeStringParam != null) {
|
||||||
|
try {
|
||||||
|
outputModeFinal = OutputMode.valueOf(outputModeStringParam);
|
||||||
|
|
||||||
// If outputMode is COMPOSED when defaultOutputMode is COMPOSED_QUICK_START,
|
// If param outputMode is COMPOSED when default is COMPOSED_QUICK_START,
|
||||||
// change outputMode to COMPOSED_QUICK_START (and vice versa)
|
// change outputMode to COMPOSED_QUICK_START (and vice versa)
|
||||||
OutputMode defaultOutputMode = defaultRecordingProperties.outputMode();
|
if (OutputMode.COMPOSED_QUICK_START.equals(outputModeDefault)
|
||||||
if (OutputMode.COMPOSED_QUICK_START.equals(defaultOutputMode) && OutputMode.COMPOSED.equals(finalOutputMode)) {
|
&& OutputMode.COMPOSED.equals(outputModeFinal)) {
|
||||||
finalOutputMode = OutputMode.COMPOSED_QUICK_START;
|
outputModeFinal = OutputMode.COMPOSED_QUICK_START;
|
||||||
} else if (OutputMode.COMPOSED.equals(defaultOutputMode)
|
} else if (OutputMode.COMPOSED.equals(outputModeDefault)
|
||||||
&& OutputMode.COMPOSED_QUICK_START.equals(finalOutputMode)) {
|
&& OutputMode.COMPOSED_QUICK_START.equals(outputModeFinal)) {
|
||||||
finalOutputMode = OutputMode.COMPOSED;
|
outputModeFinal = OutputMode.COMPOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.outputMode(finalOutputMode == null ? defaultRecordingProperties.outputMode() : finalOutputMode);
|
} catch (Exception e) {
|
||||||
if (RecordingUtils.IS_COMPOSED(finalOutputMode)) {
|
throw new Exception("Type error in parameter 'outputMode'");
|
||||||
builder.resolution(resolution == null ? defaultRecordingProperties.resolution() : resolution);
|
|
||||||
builder.frameRate(frameRate == null ? defaultRecordingProperties.frameRate() : frameRate);
|
|
||||||
builder.recordingLayout(
|
|
||||||
recordingLayout == null ? defaultRecordingProperties.recordingLayout() : recordingLayout);
|
|
||||||
if (RecordingLayout.CUSTOM.equals(recordingLayout)) {
|
|
||||||
builder.customLayout(customLayout == null ? defaultRecordingProperties.customLayout() : customLayout);
|
|
||||||
}
|
}
|
||||||
if (shmSize != null) {
|
} else if (outputModeDefault != null) {
|
||||||
if (shmSize < 134217728L) {
|
outputModeFinal = outputModeDefault;
|
||||||
|
} else {
|
||||||
|
outputModeFinal = RecordingProperties.DefaultValues.outputMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RecordingUtils.IS_COMPOSED(outputModeFinal)) {
|
||||||
|
|
||||||
|
if (recordingLayoutStringParam != null) {
|
||||||
|
try {
|
||||||
|
recordingLayoutFinal = RecordingLayout.valueOf(recordingLayoutStringParam);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new Exception("Type error in parameter 'recordingLayout'");
|
||||||
|
}
|
||||||
|
} else if (recordingLayoutDefault != null) {
|
||||||
|
recordingLayoutFinal = recordingLayoutDefault;
|
||||||
|
} else {
|
||||||
|
recordingLayoutFinal = RecordingProperties.DefaultValues.recordingLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resolutionParam != null) {
|
||||||
|
if (!sessionManager.formatChecker.isAcceptableRecordingResolution(resolutionParam)) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Wrong 'resolution' parameter. Acceptable values from 100 to 1999 for both width and height");
|
||||||
|
}
|
||||||
|
resolutionFinal = resolutionParam;
|
||||||
|
} else if (resolutionDefault != null) {
|
||||||
|
resolutionFinal = resolutionDefault;
|
||||||
|
} else {
|
||||||
|
resolutionFinal = RecordingProperties.DefaultValues.resolution;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frameRateParam != null) {
|
||||||
|
if (!sessionManager.formatChecker.isAcceptableRecordingFrameRate(frameRateParam)) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Wrong 'resolution' parameter. Acceptable values from 100 to 1999 for both width and height");
|
||||||
|
}
|
||||||
|
frameRateFinal = frameRateParam;
|
||||||
|
} else if (frameRateDefault != null) {
|
||||||
|
frameRateFinal = frameRateDefault;
|
||||||
|
} else {
|
||||||
|
frameRateFinal = RecordingProperties.DefaultValues.frameRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shmSizeParam != null) {
|
||||||
|
if (!sessionManager.formatChecker.isAcceptableRecordingShmSize(shmSizeParam)) {
|
||||||
throw new RuntimeException("Wrong \"shmSize\" parameter. Must be 134217728 (128 MB) minimum");
|
throw new RuntimeException("Wrong \"shmSize\" parameter. Must be 134217728 (128 MB) minimum");
|
||||||
}
|
}
|
||||||
builder.shmSize(shmSize);
|
shmSizeFinal = shmSizeParam;
|
||||||
|
} else if (shmSizeDefault != null) {
|
||||||
|
shmSizeFinal = shmSizeDefault;
|
||||||
|
} else {
|
||||||
|
shmSizeFinal = RecordingProperties.DefaultValues.shmSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RecordingLayout.CUSTOM.equals(recordingLayoutFinal)) {
|
||||||
|
if (customLayoutParam != null) {
|
||||||
|
customLayoutFinal = customLayoutParam;
|
||||||
|
} else if (customLayoutDefault != null) {
|
||||||
|
customLayoutFinal = customLayoutDefault;
|
||||||
|
} else {
|
||||||
|
customLayoutFinal = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordingProperties.Builder builder = new RecordingProperties.Builder();
|
||||||
|
builder.name(nameFinal).hasAudio(hasAudioFinal).hasVideo(hasVideoFinal).outputMode(outputModeFinal);
|
||||||
|
if (RecordingUtils.IS_COMPOSED(outputModeFinal) && hasVideoFinal) {
|
||||||
|
builder.recordingLayout(recordingLayoutFinal);
|
||||||
|
builder.resolution(resolutionFinal);
|
||||||
|
builder.frameRate(frameRateFinal);
|
||||||
|
builder.shmSize(shmSizeFinal);
|
||||||
|
if (RecordingLayout.CUSTOM.equals(recordingLayoutFinal)) {
|
||||||
|
builder.customLayout(customLayoutFinal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
builder.name(name).hasAudio(hasAudio != null ? hasAudio : true).hasVideo(hasVideo != null ? hasVideo : true);
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,11 @@ public class FormatChecker {
|
||||||
return (frameRate > 0 && frameRate <= 120);
|
return (frameRate > 0 && frameRate <= 120);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAcceptableRecordingShmSize(Long shmSize) {
|
||||||
|
// Long grater than 134217728 (128 MB)
|
||||||
|
return (shmSize >= 134217728L);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isServerMetadataFormatCorrect(String metadata) {
|
public boolean isServerMetadataFormatCorrect(String metadata) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue