1 /* 2 * Copyright 2019 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.SystemApi; 23 import android.hardware.tv.tuner.FrontendAtsc3Bandwidth; 24 import android.hardware.tv.tuner.FrontendAtsc3CodeRate; 25 import android.hardware.tv.tuner.FrontendAtsc3DemodOutputFormat; 26 import android.hardware.tv.tuner.FrontendAtsc3Fec; 27 import android.hardware.tv.tuner.FrontendAtsc3Modulation; 28 import android.hardware.tv.tuner.FrontendAtsc3TimeInterleaveMode; 29 30 import java.lang.annotation.Retention; 31 import java.lang.annotation.RetentionPolicy; 32 33 /** 34 * Frontend settings for ATSC-3. 35 * 36 * @hide 37 */ 38 @SystemApi 39 public class Atsc3FrontendSettings extends FrontendSettings { 40 41 /** @hide */ 42 @IntDef(prefix = "BANDWIDTH_", 43 value = {BANDWIDTH_UNDEFINED, BANDWIDTH_AUTO, BANDWIDTH_BANDWIDTH_6MHZ, 44 BANDWIDTH_BANDWIDTH_7MHZ, BANDWIDTH_BANDWIDTH_8MHZ}) 45 @Retention(RetentionPolicy.SOURCE) 46 public @interface Bandwidth {} 47 48 /** 49 * Bandwidth not defined. 50 */ 51 public static final int BANDWIDTH_UNDEFINED = FrontendAtsc3Bandwidth.UNDEFINED; 52 /** 53 * Hardware is able to detect and set bandwidth automatically 54 */ 55 public static final int BANDWIDTH_AUTO = FrontendAtsc3Bandwidth.AUTO; 56 /** 57 * 6 MHz bandwidth. 58 */ 59 public static final int BANDWIDTH_BANDWIDTH_6MHZ = FrontendAtsc3Bandwidth.BANDWIDTH_6MHZ; 60 /** 61 * 7 MHz bandwidth. 62 */ 63 public static final int BANDWIDTH_BANDWIDTH_7MHZ = FrontendAtsc3Bandwidth.BANDWIDTH_7MHZ; 64 /** 65 * 8 MHz bandwidth. 66 */ 67 public static final int BANDWIDTH_BANDWIDTH_8MHZ = FrontendAtsc3Bandwidth.BANDWIDTH_8MHZ; 68 69 70 /** @hide */ 71 @IntDef(prefix = "MODULATION_", 72 value = {MODULATION_UNDEFINED, MODULATION_AUTO, 73 MODULATION_MOD_QPSK, MODULATION_MOD_16QAM, 74 MODULATION_MOD_64QAM, MODULATION_MOD_256QAM, 75 MODULATION_MOD_1024QAM, MODULATION_MOD_4096QAM}) 76 @Retention(RetentionPolicy.SOURCE) 77 public @interface Modulation {} 78 79 /** 80 * Modulation undefined. 81 */ 82 public static final int MODULATION_UNDEFINED = FrontendAtsc3Modulation.UNDEFINED; 83 /** 84 * Hardware is able to detect and set modulation automatically. 85 */ 86 public static final int MODULATION_AUTO = FrontendAtsc3Modulation.AUTO; 87 /** 88 * QPSK modulation. 89 */ 90 public static final int MODULATION_MOD_QPSK = FrontendAtsc3Modulation.MOD_QPSK; 91 /** 92 * 16QAM modulation. 93 */ 94 public static final int MODULATION_MOD_16QAM = FrontendAtsc3Modulation.MOD_16QAM; 95 /** 96 * 64QAM modulation. 97 */ 98 public static final int MODULATION_MOD_64QAM = FrontendAtsc3Modulation.MOD_64QAM; 99 /** 100 * 256QAM modulation. 101 */ 102 public static final int MODULATION_MOD_256QAM = FrontendAtsc3Modulation.MOD_256QAM; 103 /** 104 * 1024QAM modulation. 105 */ 106 public static final int MODULATION_MOD_1024QAM = FrontendAtsc3Modulation.MOD_1024QAM; 107 /** 108 * 4096QAM modulation. 109 */ 110 public static final int MODULATION_MOD_4096QAM = FrontendAtsc3Modulation.MOD_4096QAM; 111 112 113 /** @hide */ 114 @IntDef(prefix = "TIME_INTERLEAVE_MODE_", 115 value = {TIME_INTERLEAVE_MODE_UNDEFINED, TIME_INTERLEAVE_MODE_AUTO, 116 TIME_INTERLEAVE_MODE_CTI, TIME_INTERLEAVE_MODE_HTI}) 117 @Retention(RetentionPolicy.SOURCE) 118 public @interface TimeInterleaveMode {} 119 120 /** 121 * Time interleave mode undefined. 122 */ 123 public static final int TIME_INTERLEAVE_MODE_UNDEFINED = 124 FrontendAtsc3TimeInterleaveMode.UNDEFINED; 125 /** 126 * Hardware is able to detect and set Time Interleave Mode automatically. 127 */ 128 public static final int TIME_INTERLEAVE_MODE_AUTO = FrontendAtsc3TimeInterleaveMode.AUTO; 129 /** 130 * CTI Time Interleave Mode. 131 */ 132 public static final int TIME_INTERLEAVE_MODE_CTI = FrontendAtsc3TimeInterleaveMode.CTI; 133 /** 134 * HTI Time Interleave Mode. 135 */ 136 public static final int TIME_INTERLEAVE_MODE_HTI = FrontendAtsc3TimeInterleaveMode.HTI; 137 138 139 /** @hide */ 140 @IntDef(prefix = "CODERATE_", 141 value = {CODERATE_UNDEFINED, CODERATE_AUTO, CODERATE_2_15, CODERATE_3_15, CODERATE_4_15, 142 CODERATE_5_15, CODERATE_6_15, CODERATE_7_15, CODERATE_8_15, CODERATE_9_15, 143 CODERATE_10_15, CODERATE_11_15, CODERATE_12_15, CODERATE_13_15}) 144 @Retention(RetentionPolicy.SOURCE) 145 public @interface CodeRate {} 146 147 /** 148 * Code rate undefined. 149 */ 150 public static final int CODERATE_UNDEFINED = FrontendAtsc3CodeRate.UNDEFINED; 151 /** 152 * Hardware is able to detect and set code rate automatically 153 */ 154 public static final int CODERATE_AUTO = FrontendAtsc3CodeRate.AUTO; 155 /** 156 * 2/15 code rate. 157 */ 158 public static final int CODERATE_2_15 = FrontendAtsc3CodeRate.CODERATE_2_15; 159 /** 160 * 3/15 code rate. 161 */ 162 public static final int CODERATE_3_15 = FrontendAtsc3CodeRate.CODERATE_3_15; 163 /** 164 * 4/15 code rate. 165 */ 166 public static final int CODERATE_4_15 = FrontendAtsc3CodeRate.CODERATE_4_15; 167 /** 168 * 5/15 code rate. 169 */ 170 public static final int CODERATE_5_15 = FrontendAtsc3CodeRate.CODERATE_5_15; 171 /** 172 * 6/15 code rate. 173 */ 174 public static final int CODERATE_6_15 = FrontendAtsc3CodeRate.CODERATE_6_15; 175 /** 176 * 7/15 code rate. 177 */ 178 public static final int CODERATE_7_15 = FrontendAtsc3CodeRate.CODERATE_7_15; 179 /** 180 * 8/15 code rate. 181 */ 182 public static final int CODERATE_8_15 = FrontendAtsc3CodeRate.CODERATE_8_15; 183 /** 184 * 9/15 code rate. 185 */ 186 public static final int CODERATE_9_15 = FrontendAtsc3CodeRate.CODERATE_9_15; 187 /** 188 * 10/15 code rate. 189 */ 190 public static final int CODERATE_10_15 = FrontendAtsc3CodeRate.CODERATE_10_15; 191 /** 192 * 11/15 code rate. 193 */ 194 public static final int CODERATE_11_15 = FrontendAtsc3CodeRate.CODERATE_11_15; 195 /** 196 * 12/15 code rate. 197 */ 198 public static final int CODERATE_12_15 = FrontendAtsc3CodeRate.CODERATE_12_15; 199 /** 200 * 13/15 code rate. 201 */ 202 public static final int CODERATE_13_15 = FrontendAtsc3CodeRate.CODERATE_13_15; 203 204 205 /** @hide */ 206 @IntDef(prefix = "FEC_", 207 value = {FEC_UNDEFINED, FEC_AUTO, FEC_BCH_LDPC_16K, FEC_BCH_LDPC_64K, FEC_CRC_LDPC_16K, 208 FEC_CRC_LDPC_64K, FEC_LDPC_16K, FEC_LDPC_64K}) 209 @Retention(RetentionPolicy.SOURCE) 210 public @interface Fec {} 211 212 /** 213 * Forward Error Correction undefined. 214 */ 215 public static final int FEC_UNDEFINED = FrontendAtsc3Fec.UNDEFINED; 216 /** 217 * Hardware is able to detect and set FEC automatically 218 */ 219 public static final int FEC_AUTO = FrontendAtsc3Fec.AUTO; 220 /** 221 * BCH LDPC 16K Forward Error Correction 222 */ 223 public static final int FEC_BCH_LDPC_16K = FrontendAtsc3Fec.BCH_LDPC_16K; 224 /** 225 * BCH LDPC 64K Forward Error Correction 226 */ 227 public static final int FEC_BCH_LDPC_64K = FrontendAtsc3Fec.BCH_LDPC_64K; 228 /** 229 * CRC LDPC 16K Forward Error Correction 230 */ 231 public static final int FEC_CRC_LDPC_16K = FrontendAtsc3Fec.CRC_LDPC_16K; 232 /** 233 * CRC LDPC 64K Forward Error Correction 234 */ 235 public static final int FEC_CRC_LDPC_64K = FrontendAtsc3Fec.CRC_LDPC_64K; 236 /** 237 * LDPC 16K Forward Error Correction 238 */ 239 public static final int FEC_LDPC_16K = FrontendAtsc3Fec.LDPC_16K; 240 /** 241 * LDPC 64K Forward Error Correction 242 */ 243 public static final int FEC_LDPC_64K = FrontendAtsc3Fec.LDPC_64K; 244 245 246 /** @hide */ 247 @IntDef(prefix = "DEMOD_OUTPUT_FORMAT_", 248 value = {DEMOD_OUTPUT_FORMAT_UNDEFINED, DEMOD_OUTPUT_FORMAT_ATSC3_LINKLAYER_PACKET, 249 DEMOD_OUTPUT_FORMAT_BASEBAND_PACKET}) 250 @Retention(RetentionPolicy.SOURCE) 251 public @interface DemodOutputFormat {} 252 253 /** 254 * Demod output format undefined. 255 */ 256 public static final int DEMOD_OUTPUT_FORMAT_UNDEFINED = 257 FrontendAtsc3DemodOutputFormat.UNDEFINED; 258 /** 259 * ALP format. Typically used in US region. 260 */ 261 public static final int DEMOD_OUTPUT_FORMAT_ATSC3_LINKLAYER_PACKET = 262 FrontendAtsc3DemodOutputFormat.ATSC3_LINKLAYER_PACKET; 263 /** 264 * BaseBand packet format. Typically used in Korea region. 265 */ 266 public static final int DEMOD_OUTPUT_FORMAT_BASEBAND_PACKET = 267 FrontendAtsc3DemodOutputFormat.BASEBAND_PACKET; 268 269 private final int mBandwidth; 270 private final int mDemodOutputFormat; 271 private final Atsc3PlpSettings[] mPlpSettings; 272 Atsc3FrontendSettings( long frequency, int bandwidth, int demodOutputFormat, Atsc3PlpSettings[] plpSettings)273 private Atsc3FrontendSettings( 274 long frequency, int bandwidth, int demodOutputFormat, Atsc3PlpSettings[] plpSettings) { 275 super(frequency); 276 mBandwidth = bandwidth; 277 mDemodOutputFormat = demodOutputFormat; 278 mPlpSettings = plpSettings; 279 } 280 281 /** 282 * Gets bandwidth. 283 */ 284 @Bandwidth getBandwidth()285 public int getBandwidth() { 286 return mBandwidth; 287 } 288 /** 289 * Gets Demod Output Format. 290 */ 291 @DemodOutputFormat getDemodOutputFormat()292 public int getDemodOutputFormat() { 293 return mDemodOutputFormat; 294 } 295 /** 296 * Gets PLP Settings. 297 */ 298 @NonNull getPlpSettings()299 public Atsc3PlpSettings[] getPlpSettings() { 300 return mPlpSettings; 301 } 302 303 /** 304 * Creates a builder for {@link Atsc3FrontendSettings}. 305 * 306 */ 307 @NonNull builder()308 public static Builder builder() { 309 return new Builder(); 310 } 311 312 /** 313 * Builder for {@link Atsc3FrontendSettings}. 314 */ 315 public static class Builder { 316 private long mFrequency = 0; 317 private int mBandwidth = BANDWIDTH_UNDEFINED; 318 private int mDemodOutputFormat = DEMOD_OUTPUT_FORMAT_UNDEFINED; 319 private Atsc3PlpSettings[] mPlpSettings = {}; 320 Builder()321 private Builder() { 322 } 323 324 /** 325 * Sets frequency in Hz. 326 * 327 * <p>Default value is 0. 328 * @deprecated Use {@link #setFrequencyLong(long)} 329 */ 330 @NonNull 331 @IntRange(from = 1) 332 @Deprecated setFrequency(int frequency)333 public Builder setFrequency(int frequency) { 334 return setFrequencyLong((long) frequency); 335 } 336 337 /** 338 * Sets frequency in Hz. 339 * 340 * <p>Default value is 0. 341 */ 342 @NonNull 343 @IntRange(from = 1) setFrequencyLong(long frequency)344 public Builder setFrequencyLong(long frequency) { 345 mFrequency = frequency; 346 return this; 347 } 348 349 /** 350 * Sets bandwidth. 351 * 352 * <p>Default value is {@link #BANDWIDTH_UNDEFINED}. 353 */ 354 @NonNull setBandwidth(int bandwidth)355 public Builder setBandwidth(int bandwidth) { 356 mBandwidth = bandwidth; 357 return this; 358 } 359 /** 360 * Sets Demod Output Format. 361 * 362 * <p>Default value is {@link #DEMOD_OUTPUT_FORMAT_UNDEFINED}. 363 */ 364 @NonNull setDemodOutputFormat(@emodOutputFormat int demodOutputFormat)365 public Builder setDemodOutputFormat(@DemodOutputFormat int demodOutputFormat) { 366 mDemodOutputFormat = demodOutputFormat; 367 return this; 368 } 369 /** 370 * Sets PLP Settings. 371 * 372 * <p>Default value an empty array. 373 */ 374 @NonNull setPlpSettings(@onNull Atsc3PlpSettings[] plpSettings)375 public Builder setPlpSettings(@NonNull Atsc3PlpSettings[] plpSettings) { 376 mPlpSettings = plpSettings; 377 return this; 378 } 379 380 /** 381 * Builds a {@link Atsc3FrontendSettings} object. 382 */ 383 @NonNull build()384 public Atsc3FrontendSettings build() { 385 return new Atsc3FrontendSettings(mFrequency, mBandwidth, mDemodOutputFormat, 386 mPlpSettings); 387 } 388 } 389 390 @Override getType()391 public int getType() { 392 return FrontendSettings.TYPE_ATSC3; 393 } 394 } 395