1 /* 2 * Copyright 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media.tv.tuner.frontend; 18 19 import android.annotation.IntDef; 20 import android.annotation.IntRange; 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.annotation.Size; 24 import android.annotation.SystemApi; 25 import android.hardware.tv.tuner.FrontendIptvSettingsIgmp; 26 import android.hardware.tv.tuner.FrontendIptvSettingsProtocol; 27 28 import java.lang.annotation.Retention; 29 import java.lang.annotation.RetentionPolicy; 30 31 /** 32 * Frontend settings for IPTV. 33 * 34 * @hide 35 */ 36 @SystemApi 37 public final class IptvFrontendSettings extends FrontendSettings { 38 /** @hide */ 39 @IntDef(prefix = "PROTOCOL_", 40 value = {PROTOCOL_UNDEFINED, PROTOCOL_UDP, PROTOCOL_RTP}) 41 @Retention(RetentionPolicy.SOURCE) 42 public @interface Protocol {} 43 44 /** 45 * IP protocol type UNDEFINED. 46 */ 47 public static final int PROTOCOL_UNDEFINED = FrontendIptvSettingsProtocol.UNDEFINED; 48 49 /** 50 * IP protocol type UDP (User Datagram Protocol). 51 */ 52 public static final int PROTOCOL_UDP = FrontendIptvSettingsProtocol.UDP; 53 54 /** 55 * IP protocol type RTP (Real-time Transport Protocol). 56 */ 57 public static final int PROTOCOL_RTP = FrontendIptvSettingsProtocol.RTP; 58 59 /** @hide */ 60 @IntDef(prefix = "IGMP_", 61 value = {IGMP_UNDEFINED, IGMP_V1, IGMP_V2, IGMP_V3}) 62 @Retention(RetentionPolicy.SOURCE) 63 public @interface Igmp {} 64 65 /** 66 * IGMP (Internet Group Management Protocol) UNDEFINED. 67 */ 68 public static final int IGMP_UNDEFINED = FrontendIptvSettingsIgmp.UNDEFINED; 69 70 /** 71 * IGMP (Internet Group Management Protocol) V1. 72 */ 73 public static final int IGMP_V1 = FrontendIptvSettingsIgmp.V1; 74 75 /** 76 * IGMP (Internet Group Management Protocol) V2. 77 */ 78 public static final int IGMP_V2 = FrontendIptvSettingsIgmp.V2; 79 80 /** 81 * IGMP (Internet Group Management Protocol) V3. 82 */ 83 public static final int IGMP_V3 = FrontendIptvSettingsIgmp.V3; 84 85 private final byte[] mSrcIpAddress; 86 private final byte[] mDstIpAddress; 87 private final int mSrcPort; 88 private final int mDstPort; 89 private final IptvFrontendSettingsFec mFec; 90 private final int mProtocol; 91 private final int mIgmp; 92 private final long mBitrate; 93 private final String mContentUrl; 94 IptvFrontendSettings(@onNull byte[] srcIpAddress, @NonNull byte[] dstIpAddress, int srcPort, int dstPort, @NonNull IptvFrontendSettingsFec fec, int protocol, int igmp, long bitrate, @NonNull String contentUrl)95 private IptvFrontendSettings(@NonNull byte[] srcIpAddress, @NonNull byte[] dstIpAddress, 96 int srcPort, int dstPort, @NonNull IptvFrontendSettingsFec fec, int protocol, int igmp, 97 long bitrate, @NonNull String contentUrl) { 98 super(0); 99 mSrcIpAddress = srcIpAddress; 100 mDstIpAddress = dstIpAddress; 101 mSrcPort = srcPort; 102 mDstPort = dstPort; 103 mFec = fec; 104 mProtocol = protocol; 105 mIgmp = igmp; 106 mBitrate = bitrate; 107 mContentUrl = contentUrl; 108 } 109 110 /** 111 * Gets the source IP address. 112 */ 113 @Size(min = 4, max = 16) 114 @NonNull getSrcIpAddress()115 public byte[] getSrcIpAddress() { 116 return mSrcIpAddress; 117 } 118 119 /** 120 * Gets the destination IP address. 121 */ 122 @Size(min = 4, max = 16) 123 @NonNull getDstIpAddress()124 public byte[] getDstIpAddress() { 125 return mDstIpAddress; 126 } 127 128 /** 129 * Gets the source port. 130 */ getSrcPort()131 public int getSrcPort() { 132 return mSrcPort; 133 } 134 135 /** 136 * Gets the destination port. 137 */ getDstPort()138 public int getDstPort() { 139 return mDstPort; 140 } 141 142 /** 143 * Gets FEC (Forward Error Correction). 144 */ 145 @Nullable getFec()146 public IptvFrontendSettingsFec getFec() { 147 return mFec; 148 } 149 150 /** 151 * Gets the protocol. 152 */ 153 @Protocol getProtocol()154 public int getProtocol() { 155 return mProtocol; 156 } 157 158 /** 159 * Gets the IGMP (Internet Group Management Protocol). 160 */ 161 @Igmp getIgmp()162 public int getIgmp() { 163 return mIgmp; 164 } 165 166 /** 167 * Gets the bitrate. 168 */ 169 @IntRange(from = 0) getBitrate()170 public long getBitrate() { 171 return mBitrate; 172 } 173 174 /** 175 * Gets the contentUrl 176 * contentUrl is a source URL in the format protocol://ip:port containing data 177 */ 178 @NonNull getContentUrl()179 public String getContentUrl() { 180 return mContentUrl; 181 } 182 183 /** 184 * Builder for {@link IptvFrontendSettings}. 185 */ 186 public static final class Builder { 187 private byte[] mSrcIpAddress = {0, 0, 0, 0}; 188 private byte[] mDstIpAddress = {0, 0, 0, 0}; 189 private int mSrcPort = 0; 190 private int mDstPort = 0; 191 private IptvFrontendSettingsFec mFec = null; 192 private int mProtocol = FrontendIptvSettingsProtocol.UNDEFINED; 193 private int mIgmp = FrontendIptvSettingsIgmp.UNDEFINED; 194 private long mBitrate = 0; 195 private String mContentUrl = ""; 196 Builder()197 public Builder() { 198 } 199 200 /** 201 * Sets the source IP address. 202 * 203 * <p>Default value is 0.0.0.0, an invalid IP address. 204 */ 205 @NonNull setSrcIpAddress(@onNull byte[] srcIpAddress)206 public Builder setSrcIpAddress(@NonNull byte[] srcIpAddress) { 207 mSrcIpAddress = srcIpAddress; 208 return this; 209 } 210 211 /** 212 * Sets the destination IP address. 213 * 214 * <p>Default value is 0.0.0.0, an invalid IP address. 215 */ 216 @NonNull setDstIpAddress(@onNull byte[] dstIpAddress)217 public Builder setDstIpAddress(@NonNull byte[] dstIpAddress) { 218 mDstIpAddress = dstIpAddress; 219 return this; 220 } 221 222 /** 223 * Sets the source IP port. 224 * 225 * <p>Default value is 0. 226 */ 227 @NonNull setSrcPort(int srcPort)228 public Builder setSrcPort(int srcPort) { 229 mSrcPort = srcPort; 230 return this; 231 } 232 233 /** 234 * Sets the destination IP port. 235 * 236 * <p>Default value is 0. 237 */ 238 @NonNull setDstPort(int dstPort)239 public Builder setDstPort(int dstPort) { 240 mDstPort = dstPort; 241 return this; 242 } 243 244 /** 245 * Sets the FEC (Forward Error Correction). 246 * 247 * <p>Default value is {@code null}. 248 */ 249 @NonNull setFec(@ullable IptvFrontendSettingsFec fec)250 public Builder setFec(@Nullable IptvFrontendSettingsFec fec) { 251 mFec = fec; 252 return this; 253 } 254 255 /** 256 * Sets the protocol. 257 * 258 * <p>Default value is {@link #PROTOCOL_UNDEFINED}. 259 */ 260 @NonNull setProtocol(@rotocol int protocol)261 public Builder setProtocol(@Protocol int protocol) { 262 mProtocol = protocol; 263 return this; 264 } 265 266 /** 267 * Sets the IGMP (Internet Group Management Protocol). 268 * 269 * <p>Default value is {@link #IGMP_UNDEFINED}. 270 */ 271 @NonNull setIgmp(@gmp int igmp)272 public Builder setIgmp(@Igmp int igmp) { 273 mIgmp = igmp; 274 return this; 275 } 276 277 /** 278 * Sets the bitrate. 279 * 280 * <p>Default value is 0. 281 */ 282 @NonNull setBitrate(@ntRangefrom = 0) long bitrate)283 public Builder setBitrate(@IntRange(from = 0) long bitrate) { 284 mBitrate = bitrate; 285 return this; 286 } 287 288 /** 289 * Sets the contentUrl. 290 * 291 * <p>Default value is "". 292 */ 293 @NonNull setContentUrl(@onNull String contentUrl)294 public Builder setContentUrl(@NonNull String contentUrl) { 295 mContentUrl = contentUrl; 296 return this; 297 } 298 299 /** 300 * Builds a {@link IptvFrontendSettings} object. 301 */ 302 @NonNull build()303 public IptvFrontendSettings build() { 304 return new IptvFrontendSettings(mSrcIpAddress, mDstIpAddress, mSrcPort, mDstPort, 305 mFec, mProtocol, mIgmp, mBitrate, mContentUrl); 306 } 307 } 308 309 @Override getType()310 public int getType() { 311 return FrontendSettings.TYPE_IPTV; 312 } 313 } 314