Skip to content

Commit caa2c29

Browse files
Mofizur Rahmanpardeljeffswartz
authored
[DEVX-5709] add selective stream for archive and broadcast (#206)
* add selective stream for archive and broadcast * update patch to reflect api docs * Docs edits * Docs typo corrections * StreamMode docs edits * update license year * remove patchproperties Co-authored-by: Paul Ardeleanu <paul.ardeleanu@vonage.com> Co-authored-by: Jeff Swartz <jeff.swartz@vonage.com>
1 parent 523a2f7 commit caa2c29

38 files changed

+439
-94
lines changed

src/main/java/com/opentok/Archive.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* OpenTok Java SDK
3-
* Copyright (C) 2021 Vonage.
3+
* Copyright (C) 2022 Vonage.
44
* http://www.tokbox.com
55
*
66
* Licensed under The MIT License (MIT). See LICENSE file for more information.
@@ -88,6 +88,26 @@ public enum OutputMode {
8888
}
8989
}
9090

91+
/**
92+
* Defines values used in the
93+
* {@link ArchiveProperties.Builder#streamMode(com.opentok.Archive.StreamMode)} method
94+
* and returned by the {@link Archive#getStreamMode()} method.
95+
*/
96+
public enum StreamMode {
97+
/**
98+
* Streams will be automatically included in the archive.
99+
*/
100+
AUTO,
101+
/**
102+
* Streams will be included in the archive based on calls to the
103+
* {@link OpenTok#addArchiveStream(String, String, boolean, boolean)} and
104+
* {@link OpenTok#removeArchiveStream(String, String)} methods.
105+
*/
106+
MANUAL;
107+
108+
@JsonValue public String toString() { return super.toString().toLowerCase(); }
109+
}
110+
91111
@JsonProperty private long createdAt;
92112
@JsonProperty private int duration = 0;
93113
@JsonProperty private String id;
@@ -101,6 +121,7 @@ public enum OutputMode {
101121
@JsonProperty private boolean hasVideo = true;
102122
@JsonProperty private boolean hasAudio = true;
103123
@JsonProperty private OutputMode outputMode = OutputMode.COMPOSED;
124+
@JsonProperty private StreamMode streamMode = StreamMode.AUTO;
104125
@JsonProperty private String password;
105126
@JsonProperty private String resolution;
106127

@@ -215,6 +236,14 @@ public boolean hasAudio() {
215236
public OutputMode getOutputMode() {
216237
return outputMode;
217238
}
239+
240+
/**
241+
* The stream mode to used for selecting streams to be included in this archive:
242+
* <code>StreamMode.AUTO</code> or <code>StreamMode.MANUAL</code>.
243+
*/
244+
public StreamMode getStreamMode() {
245+
return streamMode;
246+
}
218247

219248
/**
220249
* The encrypted password if an archive storage was configured to use an encryption key

src/main/java/com/opentok/ArchiveLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* OpenTok Java SDK
3-
* Copyright (C) 2021 Vonage.
3+
* Copyright (C) 2022 Vonage.
44
* http://www.tokbox.com
55
*
66
* Licensed under The MIT License (MIT). See LICENSE file for more information.

src/main/java/com/opentok/ArchiveList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* OpenTok Java SDK
3-
* Copyright (C) 2021 Vonage.
3+
* Copyright (C) 2022 Vonage.
44
* http://www.tokbox.com
55
*
66
* Licensed under The MIT License (MIT). See LICENSE file for more information.

src/main/java/com/opentok/ArchiveMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* OpenTok Java SDK
3-
* Copyright (C) 2021 Vonage.
3+
* Copyright (C) 2022 Vonage.
44
* http://www.tokbox.com
55
*
66
* Licensed under The MIT License (MIT). See LICENSE file for more information.

src/main/java/com/opentok/ArchiveProperties.java

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/**
22
* OpenTok Java SDK
3-
* Copyright (C) 2021 Vonage.
3+
* Copyright (C) 2022 Vonage.
44
* http://www.tokbox.com
55
*
66
* Licensed under The MIT License (MIT). See LICENSE file for more information.
77
*/
88
package com.opentok;
99

1010
import com.opentok.Archive.OutputMode;
11+
import com.opentok.Archive.StreamMode;
1112

1213
import java.util.ArrayList;
1314
import java.util.Collection;
@@ -17,7 +18,7 @@
1718

1819
/**
1920
* Defines values for the <code>properties</code> parameter of the
20-
* {@link OpenTok#createSession(SessionProperties)} method.
21+
* {@link OpenTok#startArchive(String sessionId, ArchiveProperties properties)} method.
2122
*
2223
* @see OpenTok#createSession(com.opentok.SessionProperties properties)
2324
*/
@@ -29,6 +30,7 @@ public class ArchiveProperties {
2930
private boolean hasAudio;
3031
private boolean hasVideo;
3132
private OutputMode outputMode;
33+
private StreamMode streamMode;
3234
private ArchiveLayout layout;
3335

3436
private ArchiveProperties(Builder builder) {
@@ -37,11 +39,12 @@ private ArchiveProperties(Builder builder) {
3739
this.hasAudio = builder.hasAudio;
3840
this.hasVideo = builder.hasVideo;
3941
this.outputMode = builder.outputMode;
42+
this.streamMode = builder.streamMode;
4043
this.layout = builder.layout;
4144
}
4245

4346
/**
44-
* Use this class to create a ArchiveProperties object.
47+
* Used to create an ArchiveProperties object.
4548
*
4649
* @see ArchiveProperties
4750
*/
@@ -51,11 +54,11 @@ public static class Builder {
5154
private boolean hasAudio = true;
5255
private boolean hasVideo = true;
5356
private OutputMode outputMode = OutputMode.COMPOSED;
57+
private StreamMode streamMode = StreamMode.AUTO;
5458
private ArchiveLayout layout = null;
55-
5659

5760
/**
58-
* Call this method to set a name to the archive.
61+
* Sets a name for the archive.
5962
*
6063
* @param name The name of the archive. You can use this name to identify the archive. It is a property
6164
* of the Archive object, and it is a property of archive-related events in the OpenTok JavaScript SDK.
@@ -68,7 +71,7 @@ public Builder name(String name) {
6871
}
6972

7073
/**
71-
* Call this method to set the resolution of the archive.
74+
* Sets the resolution of the archive.
7275
*
7376
* @param resolution The resolution of the archive, either "640x480" (SD, the default) or
7477
* "1280x720" (HD). This property only applies to composed archives. If you set this
@@ -83,7 +86,8 @@ public Builder resolution(String resolution) {
8386
}
8487

8588
/**
86-
* Call this method to include an audio track (<code>true</code>) or not <code>false</code>).
89+
* Call this method to include an audio track (<code>true</code>, the default)
90+
* or not <code>false</code>).
8791
*
8892
* @param hasAudio Whether the archive will include an audio track.
8993
*
@@ -93,21 +97,22 @@ public Builder hasAudio(boolean hasAudio) {
9397
this.hasAudio = hasAudio;
9498
return this;
9599
}
96-
100+
97101
/**
98-
* Call this method to include an video track (<code>true</code>) or not <code>false</code>).
102+
* Call this method to include an video track (<code>true</code>, the default)
103+
* or not <code>false</code>).
99104
*
100-
* @param hasVideo Whether the archive will include an video track.
105+
* @param hasVideo Whether the archive will include a video track.
101106
*
102107
* @return The ArchiveProperties.Builder object with the hasVideo setting.
103108
*/
104109
public Builder hasVideo(boolean hasVideo) {
105110
this.hasVideo = hasVideo;
106111
return this;
107-
}
112+
}
108113

109114
/**
110-
* Call this method to choose the output mode to be generated for this archive.
115+
* Sets the output mode for this archive.
111116
*
112117
* @param outputMode Set to a value defined in the {@link Archive.OutputMode} enum.
113118
*
@@ -119,13 +124,36 @@ public Builder outputMode(OutputMode outputMode) {
119124
}
120125

121126
/**
122-
* Call this method to customize the layout for a composed archive
127+
* Sets the stream mode for this archive.
128+
*
129+
* When streams are selected automatically (<code>StreamMode.AUTO</code>, the default), all
130+
* streams in the session can be included in the archive. When streams are selected manually
131+
* (<code>StreamMode.MANUAL</code>), you specify streams to be included based on calls
132+
* to the {@link OpenTok#addArchiveStream(String, String, boolean, boolean)} and
133+
* {@link OpenTok#removeArchiveStream(String, String)} methods. With
134+
* <code>StreamMode.MANUAL</code>, you can specify whether a stream's audio, video, or both
135+
* are included in the archive. Un both automatic and manual modes, the archive composer
136+
* includes streams based on
137+
* <a href="https://tokbox.com/developer/guides/archive-broadcast-layout/#stream-prioritization-rules">stream
138+
* prioritization rules</a>.
139+
*
140+
* @param streamMode Set to a value defined in the {@link Archive.StreamMode} enum.
141+
*
142+
* @return The ArchiveProperties.Builder object with the stream mode setting.
143+
*/
144+
public Builder streamMode(StreamMode streamMode) {
145+
this.streamMode = streamMode;
146+
return this;
147+
}
148+
149+
/**
150+
* Sets the layout for a composed archive.
123151
*
124152
* @param layout An object of type {@link ArchiveLayout} .
125153
*
126154
* @return The ArchiveProperties.Builder object with the output mode setting.
127155
*/
128-
public Builder layout(ArchiveLayout layout){
156+
public Builder layout(ArchiveLayout layout) {
129157
this.layout = layout;
130158
return this;
131159
}
@@ -139,18 +167,21 @@ public ArchiveProperties build() {
139167
return new ArchiveProperties(this);
140168
}
141169
}
170+
142171
/**
143-
* Returns the name of the archive, which you can use to identify the archive
172+
* Returns the name of the archive, which you can use to identify the archive.
144173
*/
145174
public String name() {
146175
return name;
147176
}
177+
148178
/**
149-
* Returns the resolution of the archive
179+
* Returns the resolution of the archive.
150180
*/
151181
public String resolution() {
152182
return resolution;
153183
}
184+
154185
/**
155186
* Whether the archive has a video track (<code>true</code>) or not (<code>false</code>).
156187
*/
@@ -164,7 +195,7 @@ public boolean hasVideo() {
164195
public boolean hasAudio() {
165196
return hasAudio;
166197
}
167-
198+
168199
/**
169200
* The output mode of the archive.
170201
*/
@@ -173,7 +204,12 @@ public OutputMode outputMode() {
173204
}
174205

175206
/**
176-
* Optionally set a custom layout (composed archives only)
207+
* The stream mode of the archive.
208+
*/
209+
public StreamMode streamMode() { return streamMode; }
210+
211+
/**
212+
* Returns the custom layout of the archive (composed archives only).
177213
*/
178214
public ArchiveLayout layout() {
179215
return layout;
@@ -197,15 +233,19 @@ public Map<String, Collection<String>> toMap() {
197233
ArrayList<String> valueList = new ArrayList<String>();
198234
valueList.add(Boolean.toString(hasAudio));
199235
params.put("hasAudio", valueList);
200-
236+
201237
valueList = new ArrayList<String>();
202238
valueList.add(Boolean.toString(hasVideo));
203239
params.put("hasVideo", valueList);
204-
240+
205241
valueList = new ArrayList<String>();
206242
valueList.add(outputMode.toString());
207243
params.put("outputMode", valueList);
208244

245+
valueList = new ArrayList<String>();
246+
valueList.add(streamMode.toString());
247+
params.put("streamMode", valueList);
248+
209249
if (layout != null) {
210250
valueList = new ArrayList<String>();
211251
valueList.add(layout.toString());

src/main/java/com/opentok/Broadcast.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* OpenTok Java SDK
3-
* Copyright (C) 2021 Vonage.
3+
* Copyright (C) 2022 Vonage.
44
* http://www.tokbox.com
55
*
66
* Licensed under The MIT License (MIT). See LICENSE file for more information.
@@ -10,6 +10,7 @@
1010
import com.fasterxml.jackson.annotation.JsonCreator;
1111
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
1212
import com.fasterxml.jackson.annotation.JsonProperty;
13+
import com.fasterxml.jackson.annotation.JsonValue;
1314
import com.fasterxml.jackson.databind.ObjectMapper;
1415

1516
import java.util.ArrayList;
@@ -21,6 +22,26 @@
2122
*/
2223
@JsonIgnoreProperties(ignoreUnknown=true)
2324
public class Broadcast {
25+
/**
26+
* Defines values used in the
27+
* {@link BroadcastProperties.Builder#streamMode(com.opentok.Broadcast.StreamMode)} method
28+
* and returned by the {@link Broadcast#getStreamMode()} method.
29+
*/
30+
public enum StreamMode {
31+
/**
32+
* Streams will be automatically included in the broadcast.
33+
*/
34+
AUTO,
35+
/**
36+
* Strams will be included in the archive based on calls to the
37+
* {@link OpenTok#addBroadcastStream(String, String, boolean, boolean)} and
38+
* {@link OpenTok#removeBroadcastStream(String, String)} methods.
39+
*/
40+
MANUAL;
41+
42+
@JsonValue
43+
public String toString() { return super.toString().toLowerCase(); }
44+
}
2445

2546
@JsonProperty private String id;
2647
@JsonProperty private String sessionId;
@@ -29,6 +50,7 @@ public class Broadcast {
2950
@JsonProperty private long updatedAt;
3051
@JsonProperty private String resolution;
3152
@JsonProperty private String status;
53+
@JsonProperty private StreamMode streamMode = StreamMode.AUTO;
3254
private List<Rtmp> rtmpList = new ArrayList<>();
3355
private String hls;
3456

@@ -137,4 +159,12 @@ public String toString() {
137159
}
138160
}
139161

162+
/**
163+
* The stream mode to used for selecting streams to be included in this archive:
164+
* <code>StreamMode.AUTO</code> or <code>StreamMode.MANUAL</code>.
165+
*/
166+
public StreamMode getStreamMode() {
167+
return streamMode;
168+
}
169+
140170
}

src/main/java/com/opentok/BroadcastLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* OpenTok Java SDK
3-
* Copyright (C) 2021 Vonage.
3+
* Copyright (C) 2022 Vonage.
44
* http://www.tokbox.com
55
*
66
* Licensed under The MIT License (MIT). See LICENSE file for more information.

0 commit comments

Comments
 (0)