Skip to content

Commit 2cd27e1

Browse files
authored
Add maxBitrate to Archive (#269)
1 parent cf4f236 commit 2cd27e1

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,14 @@ public String toString() {
113113
}
114114

115115
@JsonProperty private long createdAt;
116-
@JsonProperty private int duration = 0;
116+
@JsonProperty private int duration;
117117
@JsonProperty private String id;
118118
@JsonProperty private String name;
119119
@JsonProperty private int partnerId;
120120
@JsonProperty private String reason;
121121
@JsonProperty private String sessionId;
122-
@JsonProperty private long size = 0;
122+
@JsonProperty private long size;
123+
@JsonProperty private int maxBitrate;
123124
@JsonProperty private Status status;
124125
@JsonProperty private String url;
125126
@JsonProperty private boolean hasVideo = true;
@@ -202,6 +203,15 @@ public long getSize() {
202203
return size;
203204
}
204205

206+
/**
207+
* The maximum bitrate of the archive, in bits per second.
208+
*
209+
* @since 4.15.0
210+
*/
211+
public int getMaxBitrate() {
212+
return maxBitrate;
213+
}
214+
205215
/**
206216
* The status of the archive, as defined by the {@link com.opentok.Archive.Status} enum.
207217
*/

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

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class ArchiveProperties {
2828
private String multiArchiveTag;
2929
private boolean hasAudio;
3030
private boolean hasVideo;
31+
private Integer maxBitrate;
3132
private OutputMode outputMode;
3233
private StreamMode streamMode;
3334
private ArchiveLayout layout;
@@ -37,6 +38,7 @@ private ArchiveProperties(Builder builder) {
3738
this.resolution = builder.resolution;
3839
this.hasAudio = builder.hasAudio;
3940
this.hasVideo = builder.hasVideo;
41+
this.maxBitrate = builder.maxBitrate;
4042
this.outputMode = builder.outputMode;
4143
this.streamMode = builder.streamMode;
4244
this.layout = builder.layout;
@@ -54,6 +56,7 @@ public static class Builder {
5456
private String multiArchiveTag = null;
5557
private boolean hasAudio = true;
5658
private boolean hasVideo = true;
59+
private Integer maxBitrate;
5760
private OutputMode outputMode = OutputMode.COMPOSED;
5861
private StreamMode streamMode = StreamMode.AUTO;
5962
private ArchiveLayout layout = null;
@@ -112,6 +115,19 @@ public Builder hasVideo(boolean hasVideo) {
112115
return this;
113116
}
114117

118+
/**
119+
* Sets the maximum bitrate (bps) for the archive. Minimum is 100000, maximum is 6000000.
120+
*
121+
* @param maxBitrate The maximum bitrate (in bits per second) for the archiving.
122+
*
123+
* @return The ArchiveProperties.Builder object with the maxBitrate setting.
124+
* @since 4.15.0
125+
*/
126+
public Builder maxBitrate(int maxBitrate) {
127+
this.maxBitrate = maxBitrate;
128+
return this;
129+
}
130+
115131
/**
116132
* Sets the output mode for this archive.
117133
*
@@ -221,6 +237,16 @@ public boolean hasAudio() {
221237
return hasAudio;
222238
}
223239

240+
/**
241+
* Gets the maximum bitrate (bps) for the archive if specified.
242+
*
243+
* @return The maximum bitrate (in bits per second) for the archiving, or {@code null} if unspecified (the default).
244+
* @since 4.15.0
245+
*/
246+
public Integer maxBitrate() {
247+
return maxBitrate;
248+
}
249+
224250
/**
225251
* The output mode of the archive.
226252
*/
@@ -246,43 +272,49 @@ public ArchiveLayout layout() {
246272
public Map<String, Collection<String>> toMap() {
247273
Map<String, Collection<String>> params = new HashMap<>();
248274
if (name != null) {
249-
ArrayList<String> valueList = new ArrayList<>();
275+
ArrayList<String> valueList = new ArrayList<>(1);
250276
valueList.add(name);
251277
params.put("name", valueList);
252278
}
253279
if (resolution != null) {
254-
ArrayList<String> valueList = new ArrayList<>();
280+
ArrayList<String> valueList = new ArrayList<>(1);
255281
valueList.add(resolution);
256282
params.put("resolution", valueList);
257283
}
258-
ArrayList<String> valueList = new ArrayList<>();
284+
ArrayList<String> valueList = new ArrayList<>(1);
259285
valueList.add(Boolean.toString(hasAudio));
260286
params.put("hasAudio", valueList);
261287

262-
valueList = new ArrayList<>();
288+
valueList = new ArrayList<>(1);
263289
valueList.add(Boolean.toString(hasVideo));
264290
params.put("hasVideo", valueList);
265291

266-
valueList = new ArrayList<>();
292+
valueList = new ArrayList<>(1);
267293
valueList.add(outputMode.toString());
268294
params.put("outputMode", valueList);
269295

270-
valueList = new ArrayList<>();
296+
valueList = new ArrayList<>(1);
271297
valueList.add(streamMode.toString());
272298
params.put("streamMode", valueList);
273299

274300
if (layout != null) {
275-
valueList = new ArrayList<>();
301+
valueList = new ArrayList<>(1);
276302
valueList.add(layout.toString());
277303
params.put("layout", valueList);
278304
}
279305

280306
if (multiArchiveTag != null) {
281-
valueList = new ArrayList<>();
307+
valueList = new ArrayList<>(1);
282308
valueList.add(multiArchiveTag);
283309
params.put("multiArchiveTag", valueList);
284310
}
285311

312+
if (maxBitrate != null) {
313+
valueList = new ArrayList<>(1);
314+
valueList.add(maxBitrate.toString());
315+
params.put("maxBitrate", valueList);
316+
}
317+
286318
return params;
287319
}
288320

src/main/java/com/opentok/util/HttpClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ public String startArchive(String sessionId, ArchiveProperties properties) throw
211211
if (properties.resolution() != null) {
212212
requestJson.put("resolution", properties.resolution());
213213
}
214+
if (properties.maxBitrate() != null) {
215+
requestJson.put("maxBitrate", properties.maxBitrate());
216+
}
214217
if (properties.getMultiArchiveTag() != null) {
215218
requestJson.put("multiArchiveTag", properties.getMultiArchiveTag());
216219
}

src/test/java/com/opentok/OpenTokTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,11 @@ public void testStartArchive() throws OpenTokException {
10751075
.streamMode(Archive.StreamMode.AUTO)
10761076
.resolution("1920x1080")
10771077
.multiArchiveTag("MyArchiveTag")
1078+
.maxBitrate(3214560)
10781079
.build();
10791080

10801081
assertNotNull(properties.toMap());
1082+
assertEquals(Integer.valueOf(3214560), properties.maxBitrate());
10811083

10821084
Archive archive = sdk.startArchive(sessionId, properties);
10831085
assertNotNull(archive);
@@ -1566,6 +1568,7 @@ public void testGetExpiredArchive() throws OpenTokException {
15661568
" \"partnerId\" : 123456,\n" +
15671569
" \"reason\" : \"\",\n" +
15681570
" \"sessionId\" : \"SESSIONID\",\n" +
1571+
" \"maxBitrate\" : 2000000,\n" +
15691572
" \"size\" : 8347554,\n" +
15701573
" \"status\" : \"expired\",\n" +
15711574
" \"url\" : null\n" +
@@ -1574,6 +1577,7 @@ public void testGetExpiredArchive() throws OpenTokException {
15741577
Archive archive = sdk.getArchive(archiveId);
15751578
assertNotNull(archive);
15761579
assertEquals(Archive.Status.EXPIRED, archive.getStatus());
1580+
assertEquals(2000000, archive.getMaxBitrate());
15771581
}
15781582

15791583
// NOTE: this test is pretty sloppy

0 commit comments

Comments
 (0)