From 2cd27e1e19de7aa9306495e37f54862ac8df37e1 Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Wed, 13 Nov 2024 17:50:22 +0000 Subject: [PATCH] Add maxBitrate to Archive (#269) --- src/main/java/com/opentok/Archive.java | 14 +++++- .../java/com/opentok/ArchiveProperties.java | 48 +++++++++++++++---- .../java/com/opentok/util/HttpClient.java | 3 ++ src/test/java/com/opentok/OpenTokTest.java | 4 ++ 4 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/opentok/Archive.java b/src/main/java/com/opentok/Archive.java index 1213c9e..8c1964e 100644 --- a/src/main/java/com/opentok/Archive.java +++ b/src/main/java/com/opentok/Archive.java @@ -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; @@ -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. */ diff --git a/src/main/java/com/opentok/ArchiveProperties.java b/src/main/java/com/opentok/ArchiveProperties.java index b5a6712..2496d94 100644 --- a/src/main/java/com/opentok/ArchiveProperties.java +++ b/src/main/java/com/opentok/ArchiveProperties.java @@ -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; @@ -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; @@ -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; @@ -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. * @@ -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. */ @@ -246,43 +272,49 @@ public ArchiveLayout layout() { public Map> toMap() { Map> params = new HashMap<>(); if (name != null) { - ArrayList valueList = new ArrayList<>(); + ArrayList valueList = new ArrayList<>(1); valueList.add(name); params.put("name", valueList); } if (resolution != null) { - ArrayList valueList = new ArrayList<>(); + ArrayList valueList = new ArrayList<>(1); valueList.add(resolution); params.put("resolution", valueList); } - ArrayList valueList = new ArrayList<>(); + ArrayList 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; } diff --git a/src/main/java/com/opentok/util/HttpClient.java b/src/main/java/com/opentok/util/HttpClient.java index 3d074df..dd441d9 100644 --- a/src/main/java/com/opentok/util/HttpClient.java +++ b/src/main/java/com/opentok/util/HttpClient.java @@ -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()); } diff --git a/src/test/java/com/opentok/OpenTokTest.java b/src/test/java/com/opentok/OpenTokTest.java index 741b234..94be334 100644 --- a/src/test/java/com/opentok/OpenTokTest.java +++ b/src/test/java/com/opentok/OpenTokTest.java @@ -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); @@ -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" + @@ -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