Skip to content

Commit

Permalink
Add maxBitrate to Archive (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani authored Nov 13, 2024
1 parent cf4f236 commit 2cd27e1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 10 deletions.
14 changes: 12 additions & 2 deletions src/main/java/com/opentok/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ public String toString() {
}

@JsonProperty private long createdAt;
@JsonProperty private int duration = 0;
@JsonProperty private int duration;
@JsonProperty private String id;
@JsonProperty private String name;
@JsonProperty private int partnerId;
@JsonProperty private String reason;
@JsonProperty private String sessionId;
@JsonProperty private long size = 0;
@JsonProperty private long size;
@JsonProperty private int maxBitrate;
@JsonProperty private Status status;
@JsonProperty private String url;
@JsonProperty private boolean hasVideo = true;
Expand Down Expand Up @@ -202,6 +203,15 @@ public long getSize() {
return size;
}

/**
* The maximum bitrate of the archive, in bits per second.
*
* @since 4.15.0
*/
public int getMaxBitrate() {
return maxBitrate;
}

/**
* The status of the archive, as defined by the {@link com.opentok.Archive.Status} enum.
*/
Expand Down
48 changes: 40 additions & 8 deletions src/main/java/com/opentok/ArchiveProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ArchiveProperties {
private String multiArchiveTag;
private boolean hasAudio;
private boolean hasVideo;
private Integer maxBitrate;
private OutputMode outputMode;
private StreamMode streamMode;
private ArchiveLayout layout;
Expand All @@ -37,6 +38,7 @@ private ArchiveProperties(Builder builder) {
this.resolution = builder.resolution;
this.hasAudio = builder.hasAudio;
this.hasVideo = builder.hasVideo;
this.maxBitrate = builder.maxBitrate;
this.outputMode = builder.outputMode;
this.streamMode = builder.streamMode;
this.layout = builder.layout;
Expand All @@ -54,6 +56,7 @@ public static class Builder {
private String multiArchiveTag = null;
private boolean hasAudio = true;
private boolean hasVideo = true;
private Integer maxBitrate;
private OutputMode outputMode = OutputMode.COMPOSED;
private StreamMode streamMode = StreamMode.AUTO;
private ArchiveLayout layout = null;
Expand Down Expand Up @@ -112,6 +115,19 @@ public Builder hasVideo(boolean hasVideo) {
return this;
}

/**
* Sets the maximum bitrate (bps) for the archive. Minimum is 100000, maximum is 6000000.
*
* @param maxBitrate The maximum bitrate (in bits per second) for the archiving.
*
* @return The ArchiveProperties.Builder object with the maxBitrate setting.
* @since 4.15.0
*/
public Builder maxBitrate(int maxBitrate) {
this.maxBitrate = maxBitrate;
return this;
}

/**
* Sets the output mode for this archive.
*
Expand Down Expand Up @@ -221,6 +237,16 @@ public boolean hasAudio() {
return hasAudio;
}

/**
* Gets the maximum bitrate (bps) for the archive if specified.
*
* @return The maximum bitrate (in bits per second) for the archiving, or {@code null} if unspecified (the default).
* @since 4.15.0
*/
public Integer maxBitrate() {
return maxBitrate;
}

/**
* The output mode of the archive.
*/
Expand All @@ -246,43 +272,49 @@ public ArchiveLayout layout() {
public Map<String, Collection<String>> toMap() {
Map<String, Collection<String>> params = new HashMap<>();
if (name != null) {
ArrayList<String> valueList = new ArrayList<>();
ArrayList<String> valueList = new ArrayList<>(1);
valueList.add(name);
params.put("name", valueList);
}
if (resolution != null) {
ArrayList<String> valueList = new ArrayList<>();
ArrayList<String> valueList = new ArrayList<>(1);
valueList.add(resolution);
params.put("resolution", valueList);
}
ArrayList<String> valueList = new ArrayList<>();
ArrayList<String> valueList = new ArrayList<>(1);
valueList.add(Boolean.toString(hasAudio));
params.put("hasAudio", valueList);

valueList = new ArrayList<>();
valueList = new ArrayList<>(1);
valueList.add(Boolean.toString(hasVideo));
params.put("hasVideo", valueList);

valueList = new ArrayList<>();
valueList = new ArrayList<>(1);
valueList.add(outputMode.toString());
params.put("outputMode", valueList);

valueList = new ArrayList<>();
valueList = new ArrayList<>(1);
valueList.add(streamMode.toString());
params.put("streamMode", valueList);

if (layout != null) {
valueList = new ArrayList<>();
valueList = new ArrayList<>(1);
valueList.add(layout.toString());
params.put("layout", valueList);
}

if (multiArchiveTag != null) {
valueList = new ArrayList<>();
valueList = new ArrayList<>(1);
valueList.add(multiArchiveTag);
params.put("multiArchiveTag", valueList);
}

if (maxBitrate != null) {
valueList = new ArrayList<>(1);
valueList.add(maxBitrate.toString());
params.put("maxBitrate", valueList);
}

return params;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/opentok/util/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ public String startArchive(String sessionId, ArchiveProperties properties) throw
if (properties.resolution() != null) {
requestJson.put("resolution", properties.resolution());
}
if (properties.maxBitrate() != null) {
requestJson.put("maxBitrate", properties.maxBitrate());
}
if (properties.getMultiArchiveTag() != null) {
requestJson.put("multiArchiveTag", properties.getMultiArchiveTag());
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/com/opentok/OpenTokTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,11 @@ public void testStartArchive() throws OpenTokException {
.streamMode(Archive.StreamMode.AUTO)
.resolution("1920x1080")
.multiArchiveTag("MyArchiveTag")
.maxBitrate(3214560)
.build();

assertNotNull(properties.toMap());
assertEquals(Integer.valueOf(3214560), properties.maxBitrate());

Archive archive = sdk.startArchive(sessionId, properties);
assertNotNull(archive);
Expand Down Expand Up @@ -1566,6 +1568,7 @@ public void testGetExpiredArchive() throws OpenTokException {
" \"partnerId\" : 123456,\n" +
" \"reason\" : \"\",\n" +
" \"sessionId\" : \"SESSIONID\",\n" +
" \"maxBitrate\" : 2000000,\n" +
" \"size\" : 8347554,\n" +
" \"status\" : \"expired\",\n" +
" \"url\" : null\n" +
Expand All @@ -1574,6 +1577,7 @@ public void testGetExpiredArchive() throws OpenTokException {
Archive archive = sdk.getArchive(archiveId);
assertNotNull(archive);
assertEquals(Archive.Status.EXPIRED, archive.getStatus());
assertEquals(2000000, archive.getMaxBitrate());
}

// NOTE: this test is pretty sloppy
Expand Down

0 comments on commit 2cd27e1

Please sign in to comment.