openvidu-java-client: individual stream recording

pull/203/head
pabloFuente 2019-01-18 12:07:57 +01:00
parent c0248068b6
commit 95b8207f58
3 changed files with 133 additions and 21 deletions

View File

@ -194,8 +194,16 @@ public class OpenVidu {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("session", sessionId); json.put("session", sessionId);
json.put("name", properties.name()); json.put("name", properties.name());
json.put("recordingLayout", (properties.recordingLayout() != null) ? properties.recordingLayout().name() : ""); json.put("outputMode", properties.outputMode());
json.put("customLayout", (properties.customLayout() != null) ? properties.customLayout() : "");
if (Recording.OutputMode.COMPOSED.equals(properties.outputMode())) {
json.put("recordingLayout",
(properties.recordingLayout() != null) ? properties.recordingLayout().name() : "");
if (RecordingLayout.CUSTOM.equals(properties.recordingLayout())) {
json.put("customLayout", (properties.customLayout() != null) ? properties.customLayout() : "");
}
}
StringEntity params = null; StringEntity params = null;
try { try {
params = new StringEntity(json.toString()); params = new StringEntity(json.toString());

View File

@ -59,6 +59,22 @@ public class Recording {
failed; failed;
} }
/**
* See {@link io.openvidu.java.client.Recording#getOutputMode()}
*/
public enum OutputMode {
/**
* Recording all streams in a grid layout in a single archive
*/
COMPOSED,
/**
* Record each stream individually
*/
INDIVIDUAL;
}
private Recording.Status status; private Recording.Status status;
private String id; private String id;
@ -67,8 +83,6 @@ public class Recording {
private long size; // bytes private long size; // bytes
private double duration; // seconds private double duration; // seconds
private String url; private String url;
private boolean hasAudio = true;
private boolean hasVideo = true;
private RecordingProperties recordingProperties; private RecordingProperties recordingProperties;
protected Recording(JSONObject json) { protected Recording(JSONObject json) {
@ -78,11 +92,20 @@ public class Recording {
this.size = (long) json.get("size"); this.size = (long) json.get("size");
this.duration = (double) json.get("duration"); this.duration = (double) json.get("duration");
this.url = (String) json.get("url"); this.url = (String) json.get("url");
this.hasAudio = (boolean) json.get("hasAudio");
this.hasVideo = (boolean) json.get("hasVideo");
this.status = Recording.Status.valueOf((String) json.get("status")); this.status = Recording.Status.valueOf((String) json.get("status"));
this.recordingProperties = new RecordingProperties.Builder().name((String) json.get("name"))
.recordingLayout(RecordingLayout.valueOf((String) json.get("recordingLayout"))).build(); OutputMode outputMode = OutputMode.valueOf((String) json.get("outputMode"));
RecordingProperties.Builder builder = new RecordingProperties.Builder().name((String) json.get("name"))
.outputMode(outputMode).hasAudio((boolean) json.get("hasAudio"))
.hasVideo((boolean) json.get("hasVideo"));
if (OutputMode.COMPOSED.equals(outputMode)) {
builder.recordingLayout(RecordingLayout.valueOf((String) json.get("recordingLayout")));
String customLayout = (String) json.get("customLayout");
if (customLayout != null) {
builder.customLayout(customLayout);
}
}
this.recordingProperties = builder.build();
} }
/** /**
@ -109,12 +132,30 @@ public class Recording {
} }
/** /**
* The layout used in this recording * Mode of recording: COMPOSED for a single archive in a grid layout or
* INDIVIDUAL for one archive for each stream
*/
public OutputMode getOutputMode() {
return this.recordingProperties.outputMode();
}
/**
* The layout used in this recording. Only defined if OutputMode is COMPOSED
*/ */
public RecordingLayout getRecordingLayout() { public RecordingLayout getRecordingLayout() {
return this.recordingProperties.recordingLayout(); return this.recordingProperties.recordingLayout();
} }
/**
* The custom layout used in this recording. Only defined if if OutputMode is
* COMPOSED and
* {@link io.openvidu.java.client.RecordingProperties.Builder#customLayout(String)}
* has been called
*/
public RecordingLayout getCustomLayout() {
return this.recordingProperties.recordingLayout();
}
/** /**
* Session associated to the recording * Session associated to the recording
*/ */
@ -159,7 +200,7 @@ public class Recording {
* otherwise (currently fixed to true) * otherwise (currently fixed to true)
*/ */
public boolean hasAudio() { public boolean hasAudio() {
return hasAudio; return this.recordingProperties.hasAudio();
} }
/** /**
@ -167,7 +208,7 @@ public class Recording {
* otherwise (currently fixed to true) * otherwise (currently fixed to true)
*/ */
public boolean hasVideo() { public boolean hasVideo() {
return hasVideo; return this.recordingProperties.hasVideo();
} }
} }

View File

@ -24,8 +24,11 @@ package io.openvidu.java.client;
public class RecordingProperties { public class RecordingProperties {
private String name; private String name;
private Recording.OutputMode outputMode;
private RecordingLayout recordingLayout; private RecordingLayout recordingLayout;
private String customLayout; private String customLayout;
private boolean hasAudio;
private boolean hasVideo;
/** /**
* Builder for {@link io.openvidu.java.client.RecordingProperties} * Builder for {@link io.openvidu.java.client.RecordingProperties}
@ -33,22 +36,24 @@ public class RecordingProperties {
public static class Builder { public static class Builder {
private String name = ""; private String name = "";
private Recording.OutputMode outputMode = Recording.OutputMode.COMPOSED;
private RecordingLayout recordingLayout; private RecordingLayout recordingLayout;
private String customLayout = ""; private String customLayout = "";
private boolean hasAudio = true;
private boolean hasVideo = true;
/** /**
* Builder for {@link io.openvidu.java.client.RecordingProperties} * Builder for {@link io.openvidu.java.client.RecordingProperties}
*/ */
public RecordingProperties build() { public RecordingProperties build() {
return new RecordingProperties(this.name, this.recordingLayout, this.customLayout); return new RecordingProperties(this.name, this.outputMode, this.recordingLayout, this.customLayout,
this.hasAudio, this.hasVideo);
} }
/** /**
* Call this method to set the name of the video file. You can access this same * Call this method to set the name of the video file. You can access this same
* value in your clients on recording events (<code>recordingStarted</code>, * value in your clients on recording events (<code>recordingStarted</code>,
* <code>recordingStopped</code>). <strong>WARNING: this parameter follows an * <code>recordingStopped</code>)
* overwriting policy.</strong> If you name two recordings the same, the newest
* MP4 file will overwrite the oldest one
*/ */
public RecordingProperties.Builder name(String name) { public RecordingProperties.Builder name(String name) {
this.name = name; this.name = name;
@ -56,7 +61,20 @@ public class RecordingProperties {
} }
/** /**
* Call this method to set the layout to be used in the recording * Call this method to set the mode of recording: COMPOSED for a single archive
* in a grid layout or INDIVIDUAL for one archive for each stream
*/
public RecordingProperties.Builder outputMode(Recording.OutputMode outputMode) {
this.outputMode = outputMode;
return this;
}
/**
* Call this method to set the layout to be used in the recording. Will only
* have effect if
* {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode)}
* has been called with value
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED}
*/ */
public RecordingProperties.Builder recordingLayout(RecordingLayout layout) { public RecordingProperties.Builder recordingLayout(RecordingLayout layout) {
this.recordingLayout = layout; this.recordingLayout = layout;
@ -68,7 +86,12 @@ public class RecordingProperties {
* {@link io.openvidu.java.client.RecordingProperties.Builder#recordingLayout(RecordingLayout)} * {@link io.openvidu.java.client.RecordingProperties.Builder#recordingLayout(RecordingLayout)}
* to {@link io.openvidu.java.client.RecordingLayout#CUSTOM} you can call this * to {@link io.openvidu.java.client.RecordingLayout#CUSTOM} you can call this
* method to set the relative path to the specific custom layout you want to * method to set the relative path to the specific custom layout you want to
* use. See <a href= * use.<br>
* Will only have effect if
* {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode)}
* has been called with value
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED}.<br>
* See <a href=
* "https://openvidu.io/docs/advanced-features/recording#custom-recording-layouts" * "https://openvidu.io/docs/advanced-features/recording#custom-recording-layouts"
* target="_blank">Custom recording layouts</a> to learn more * target="_blank">Custom recording layouts</a> to learn more
*/ */
@ -77,25 +100,51 @@ public class RecordingProperties {
return this; return this;
} }
/**
* Call this method to specify whether or not to record the audio track
*/
public RecordingProperties.Builder hasAudio(boolean hasAudio) {
this.hasAudio = true;
return this;
}
/**
* Call this method to specify whether or not to record the video track
*/
public RecordingProperties.Builder hasVideo(boolean hasVideo) {
this.hasVideo = true;
return this;
}
} }
protected RecordingProperties(String name, RecordingLayout layout, String customLayout) { protected RecordingProperties(String name, Recording.OutputMode outputMode, RecordingLayout layout,
String customLayout, boolean hasAudio, boolean hasVideo) {
this.name = name; this.name = name;
this.outputMode = outputMode;
this.recordingLayout = layout; this.recordingLayout = layout;
this.customLayout = customLayout; this.customLayout = customLayout;
this.hasAudio = hasAudio;
this.hasVideo = hasVideo;
} }
/** /**
* Defines the name you want to give to the video file. You can access this same * Defines the name you want to give to the video file. You can access this same
* value in your clients on recording events (<code>recordingStarted</code>, * value in your clients on recording events (<code>recordingStarted</code>,
* <code>recordingStopped</code>). <strong>WARNING: this parameter follows an * <code>recordingStopped</code>)
* overwriting policy.</strong> If you name two recordings the same, the newest
* MP4 file will overwrite the oldest one
*/ */
public String name() { public String name() {
return this.name; return this.name;
} }
/**
* Defines the mode of recording: COMPOSED for a single archive in a grid layout
* or INDIVIDUAL for one archive for each stream
*/
public Recording.OutputMode outputMode() {
return this.outputMode;
}
/** /**
* Defines the layout to be used in the recording * Defines the layout to be used in the recording
*/ */
@ -115,4 +164,18 @@ public class RecordingProperties {
return this.customLayout; return this.customLayout;
} }
/**
* Defines if the recording has an audio track or not
*/
public boolean hasAudio() {
return this.hasAudio;
}
/**
* Defines if the recording has a video track or not
*/
public boolean hasVideo() {
return this.hasVideo;
}
} }