001/*
002 *   Copyright 2024 Vonage
003 *
004 *   Licensed under the Apache License, Version 2.0 (the "License");
005 *   you may not use this file except in compliance with the License.
006 *   You may obtain a copy of the License at
007 *
008 *        http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *   Unless required by applicable law or agreed to in writing, software
011 *   distributed under the License is distributed on an "AS IS" BASIS,
012 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *   See the License for the specific language governing permissions and
014 *   limitations under the License.
015 */
016package com.vonage.client.video;
017
018import com.fasterxml.jackson.annotation.JsonProperty;
019import com.vonage.client.JsonableBaseObject;
020
021/**
022 * Represents HTTP Live Streaming (HLS) options for a {@link Broadcast}.
023 */
024public class Hls extends JsonableBaseObject {
025        private Boolean dvr, lowLatency;
026
027        protected Hls() {
028        }
029
030        protected Hls(Builder builder) {
031                // Non-short-circuiting for setter
032                if (((dvr = builder.dvr) != null && dvr) & ((lowLatency = builder.lowLatency) != null && lowLatency)) {
033                        throw new IllegalArgumentException("Cannot set both dvr and lowLatency on HLS");
034                }
035        }
036
037        /**
038         * Whether DVR functionality — rewinding, pausing, and resuming — is enabled in players that support it.
039         *
040         * @return {@code true} if DVR functionality is enabled, or {@code null} if unknown / unset.
041         */
042        @JsonProperty("dvr")
043        public Boolean dvr() {
044                return dvr;
045        }
046
047        /**
048         * Whether low-latency mode is enabled for the HLS stream. Some HLS players do not support low-latency mode.
049         *
050         * @return {@code true} if low latency mode is enabled, or {@code null} if unknown / unset.
051         */
052        @JsonProperty("lowLatency")
053        public Boolean lowLatency() {
054                return lowLatency;
055        }
056
057        /**
058         * Entrypoint for constructing an instance of this class.
059         *
060         * @return A new Builder.
061         */
062        public static Builder builder() {
063                return new Builder();
064        }
065
066        /**
067         * Used to create the Hls object.
068         */
069        public static class Builder {
070                private Boolean dvr, lowLatency;
071
072                Builder() {}
073
074                /**
075                 * Whether to enable DVR functionality — rewinding, pausing, and resuming — in players that support it
076                 * (true), or not (false, the default). With DVR enabled, the HLS URL will include a {@code ?DVR} query
077                 * string appended to the end.
078                 *
079                 * @param dvr DVR toggle.
080                 *
081                 * @return This builder.
082                 */
083                public Builder dvr(boolean dvr) {
084                        this.dvr = dvr;
085                        return this;
086                }
087
088                /**
089                 * Whether to enable low-latency mode for the HLS stream. Some HLS players do not support low-latency mode.
090                 * This feature is incompatible with DVR mode HLS broadcasts.
091                 *
092                 * @param lowLatency Low latency toggle.
093                 *
094                 * @return This builder.
095                 */
096                public Builder lowLatency(boolean lowLatency) {
097                        this.lowLatency = lowLatency;
098                        return this;
099                }
100
101                /**
102                 * Builds the HLS object with the selected settings.
103                 *
104                 * @return A new HLS instance.
105                 */
106                public Hls build() {
107                        return new Hls(this);
108                }
109        }
110}