1 /* 2 * Copyright 2020 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.SuppressLint; 23 import android.annotation.SystemApi; 24 import android.hardware.tv.tuner.FrontendDtmbBandwidth; 25 import android.hardware.tv.tuner.FrontendDtmbCodeRate; 26 import android.hardware.tv.tuner.FrontendDtmbGuardInterval; 27 import android.hardware.tv.tuner.FrontendDtmbModulation; 28 import android.hardware.tv.tuner.FrontendDtmbTimeInterleaveMode; 29 import android.hardware.tv.tuner.FrontendDtmbTransmissionMode; 30 31 import java.lang.annotation.Retention; 32 import java.lang.annotation.RetentionPolicy; 33 34 /** 35 * Frontend settings for DTMB. 36 * 37 * <p>DTMB Frontend is only supported in Tuner HAL 1.1 or higher. Use {@link 38 * android.media.tv.tuner.TunerVersionChecker#getTunerVersion()} to get the version information. 39 * 40 * @hide 41 */ 42 @SystemApi 43 public final class DtmbFrontendSettings extends FrontendSettings { 44 45 /** @hide */ 46 @IntDef(prefix = "BANDWIDTH_", 47 value = {BANDWIDTH_UNDEFINED, BANDWIDTH_AUTO, BANDWIDTH_6MHZ, BANDWIDTH_8MHZ}) 48 @Retention(RetentionPolicy.SOURCE) 49 public @interface Bandwidth {} 50 51 /** 52 * Bandwidth not defined. 53 */ 54 public static final int BANDWIDTH_UNDEFINED = FrontendDtmbBandwidth.UNDEFINED; 55 /** 56 * Hardware is able to detect and set bandwidth automatically 57 */ 58 public static final int BANDWIDTH_AUTO = FrontendDtmbBandwidth.AUTO; 59 /** 60 * 6 MHz bandwidth. 61 */ 62 public static final int BANDWIDTH_6MHZ = FrontendDtmbBandwidth.BANDWIDTH_6MHZ; 63 /** 64 * 8 MHz bandwidth. 65 */ 66 public static final int BANDWIDTH_8MHZ = FrontendDtmbBandwidth.BANDWIDTH_8MHZ; 67 68 69 /** @hide */ 70 @IntDef(prefix = "TIME_INTERLEAVE_MODE_", 71 value = {TIME_INTERLEAVE_MODE_UNDEFINED, TIME_INTERLEAVE_MODE_AUTO, 72 TIME_INTERLEAVE_MODE_TIMER_INT_240, TIME_INTERLEAVE_MODE_TIMER_INT_720}) 73 @Retention(RetentionPolicy.SOURCE) 74 public @interface TimeInterleaveMode {} 75 76 /** 77 * Time Interleave Mode undefined. 78 */ 79 public static final int TIME_INTERLEAVE_MODE_UNDEFINED = 80 FrontendDtmbTimeInterleaveMode.UNDEFINED; 81 /** 82 * Hardware is able to detect and set time interleave mode automatically 83 */ 84 public static final int TIME_INTERLEAVE_MODE_AUTO = FrontendDtmbTimeInterleaveMode.AUTO; 85 /** 86 * Time Interleave Mode timer int 240. 87 */ 88 public static final int TIME_INTERLEAVE_MODE_TIMER_INT_240 = 89 FrontendDtmbTimeInterleaveMode.TIMER_INT_240; 90 /** 91 * Time Interleave Mode timer int 720. 92 */ 93 public static final int TIME_INTERLEAVE_MODE_TIMER_INT_720 = 94 FrontendDtmbTimeInterleaveMode.TIMER_INT_720; 95 96 97 /** @hide */ 98 @IntDef(prefix = "GUARD_INTERVAL_", 99 value = {GUARD_INTERVAL_UNDEFINED, GUARD_INTERVAL_AUTO, 100 GUARD_INTERVAL_PN_420_VARIOUS, GUARD_INTERVAL_PN_595_CONST, 101 GUARD_INTERVAL_PN_945_VARIOUS, GUARD_INTERVAL_PN_420_CONST, 102 GUARD_INTERVAL_PN_945_CONST, GUARD_INTERVAL_PN_RESERVED}) 103 @Retention(RetentionPolicy.SOURCE) 104 public @interface GuardInterval {} 105 106 /** 107 * Guard Interval undefined. 108 */ 109 public static final int GUARD_INTERVAL_UNDEFINED = FrontendDtmbGuardInterval.UNDEFINED; 110 /** 111 * Hardware is able to detect and set Guard Interval automatically. 112 */ 113 public static final int GUARD_INTERVAL_AUTO = FrontendDtmbGuardInterval.AUTO; 114 /** 115 * PN_420_VARIOUS Guard Interval. 116 */ 117 public static final int GUARD_INTERVAL_PN_420_VARIOUS = 118 FrontendDtmbGuardInterval.PN_420_VARIOUS; 119 /** 120 * PN_595_CONST Guard Interval. 121 */ 122 public static final int GUARD_INTERVAL_PN_595_CONST = FrontendDtmbGuardInterval.PN_595_CONST; 123 /** 124 * PN_945_VARIOUS Guard Interval. 125 */ 126 public static final int GUARD_INTERVAL_PN_945_VARIOUS = 127 FrontendDtmbGuardInterval.PN_945_VARIOUS; 128 /** 129 * PN_420_CONST Guard Interval. 130 */ 131 public static final int GUARD_INTERVAL_PN_420_CONST = FrontendDtmbGuardInterval.PN_420_CONST; 132 /** 133 * PN_945_CONST Guard Interval. 134 */ 135 public static final int GUARD_INTERVAL_PN_945_CONST = FrontendDtmbGuardInterval.PN_945_CONST; 136 /** 137 * PN_RESERVED Guard Interval. 138 */ 139 public static final int GUARD_INTERVAL_PN_RESERVED = FrontendDtmbGuardInterval.PN_RESERVED; 140 141 142 /** @hide */ 143 @IntDef(prefix = "MODULATION_", 144 value = {MODULATION_CONSTELLATION_UNDEFINED, MODULATION_CONSTELLATION_AUTO, 145 MODULATION_CONSTELLATION_4QAM, MODULATION_CONSTELLATION_4QAM_NR, 146 MODULATION_CONSTELLATION_16QAM, MODULATION_CONSTELLATION_32QAM, 147 MODULATION_CONSTELLATION_64QAM}) 148 @Retention(RetentionPolicy.SOURCE) 149 public @interface Modulation {} 150 151 /** 152 * Constellation not defined. 153 */ 154 public static final int MODULATION_CONSTELLATION_UNDEFINED = FrontendDtmbModulation.UNDEFINED; 155 /** 156 * Hardware is able to detect and set Constellation automatically. 157 */ 158 public static final int MODULATION_CONSTELLATION_AUTO = FrontendDtmbModulation.AUTO; 159 /** 160 * 4QAM Constellation. 161 */ 162 public static final int MODULATION_CONSTELLATION_4QAM = 163 FrontendDtmbModulation.CONSTELLATION_4QAM; 164 /** 165 * 4QAM_NR Constellation. 166 */ 167 public static final int MODULATION_CONSTELLATION_4QAM_NR = 168 FrontendDtmbModulation.CONSTELLATION_4QAM_NR; 169 /** 170 * 16QAM Constellation. 171 */ 172 public static final int MODULATION_CONSTELLATION_16QAM = 173 FrontendDtmbModulation.CONSTELLATION_16QAM; 174 /** 175 * 32QAM Constellation. 176 */ 177 public static final int MODULATION_CONSTELLATION_32QAM = 178 FrontendDtmbModulation.CONSTELLATION_32QAM; 179 /** 180 * 64QAM Constellation. 181 */ 182 public static final int MODULATION_CONSTELLATION_64QAM = 183 FrontendDtmbModulation.CONSTELLATION_64QAM; 184 185 /** @hide */ 186 @IntDef(prefix = "CODERATE_", 187 value = {CODERATE_UNDEFINED, CODERATE_AUTO, CODERATE_2_5, CODERATE_3_5, CODERATE_4_5}) 188 @Retention(RetentionPolicy.SOURCE) 189 public @interface CodeRate {} 190 191 /** 192 * Code rate undefined. 193 */ 194 public static final int CODERATE_UNDEFINED = FrontendDtmbCodeRate.UNDEFINED; 195 /** 196 * Hardware is able to detect and set code rate automatically. 197 */ 198 public static final int CODERATE_AUTO = FrontendDtmbCodeRate.AUTO; 199 /** 200 * 2/5 code rate. 201 */ 202 public static final int CODERATE_2_5 = FrontendDtmbCodeRate.CODERATE_2_5; 203 /** 204 * 3/5 code rate. 205 */ 206 public static final int CODERATE_3_5 = FrontendDtmbCodeRate.CODERATE_3_5; 207 /** 208 * 4/5 code rate. 209 */ 210 public static final int CODERATE_4_5 = FrontendDtmbCodeRate.CODERATE_4_5; 211 212 /** @hide */ 213 @IntDef(prefix = "TRANSMISSION_MODE_", 214 value = {TRANSMISSION_MODE_UNDEFINED, TRANSMISSION_MODE_AUTO, 215 TRANSMISSION_MODE_C1, TRANSMISSION_MODE_C3780}) 216 @Retention(RetentionPolicy.SOURCE) 217 public @interface TransmissionMode {} 218 219 /** 220 * Transmission Mode undefined. 221 */ 222 public static final int TRANSMISSION_MODE_UNDEFINED = FrontendDtmbTransmissionMode.UNDEFINED; 223 /** 224 * Hardware is able to detect and set Transmission Mode automatically 225 */ 226 public static final int TRANSMISSION_MODE_AUTO = FrontendDtmbTransmissionMode.AUTO; 227 /** 228 * C1 Transmission Mode. 229 */ 230 public static final int TRANSMISSION_MODE_C1 = FrontendDtmbTransmissionMode.C1; 231 /** 232 * C3780 Transmission Mode. 233 */ 234 public static final int TRANSMISSION_MODE_C3780 = FrontendDtmbTransmissionMode.C3780; 235 236 237 private final int mModulation; 238 private final int mCodeRate; 239 private final int mTransmissionMode; 240 private final int mBandwidth; 241 private final int mGuardInterval; 242 private final int mTimeInterleaveMode; 243 DtmbFrontendSettings(long frequency, int modulation, int codeRate, int transmissionMode, int guardInterval, int timeInterleaveMode, int bandwidth)244 private DtmbFrontendSettings(long frequency, int modulation, int codeRate, int transmissionMode, 245 int guardInterval, int timeInterleaveMode, int bandwidth) { 246 super(frequency); 247 mModulation = modulation; 248 mCodeRate = codeRate; 249 mTransmissionMode = transmissionMode; 250 mGuardInterval = guardInterval; 251 mTimeInterleaveMode = timeInterleaveMode; 252 mBandwidth = bandwidth; 253 } 254 255 /** 256 * Gets Modulation. 257 */ 258 @Modulation getModulation()259 public int getModulation() { 260 return mModulation; 261 } 262 263 /** 264 * Gets Code Rate. 265 */ 266 @CodeRate getCodeRate()267 public int getCodeRate() { 268 return mCodeRate; 269 } 270 271 /** 272 * Gets Transmission Mode. 273 */ 274 @TransmissionMode getTransmissionMode()275 public int getTransmissionMode() { 276 return mTransmissionMode; 277 } 278 279 /** 280 * Gets Bandwidth. 281 */ 282 @Bandwidth getBandwidth()283 public int getBandwidth() { 284 return mBandwidth; 285 } 286 287 /** 288 * Gets Time Interleave Mode. 289 */ 290 @TimeInterleaveMode getTimeInterleaveMode()291 public int getTimeInterleaveMode() { 292 return mTimeInterleaveMode; 293 } 294 295 /** 296 * Gets Guard Interval. 297 */ 298 @GuardInterval getGuardInterval()299 public int getGuardInterval() { 300 return mGuardInterval; 301 } 302 303 /** 304 * Creates a builder for {@link AtscFrontendSettings}. 305 */ 306 @NonNull builder()307 public static Builder builder() { 308 return new Builder(); 309 } 310 311 /** 312 * Builder for {@link AtscFrontendSettings}. 313 */ 314 public static final class Builder { 315 private long mFrequency = 0; 316 private int mModulation = MODULATION_CONSTELLATION_UNDEFINED; 317 private int mCodeRate = CODERATE_UNDEFINED; 318 private int mTransmissionMode = TRANSMISSION_MODE_UNDEFINED; 319 private int mBandwidth = BANDWIDTH_UNDEFINED; 320 private int mTimeInterleaveMode = TIME_INTERLEAVE_MODE_UNDEFINED; 321 private int mGuardInterval = GUARD_INTERVAL_UNDEFINED; 322 Builder()323 private Builder() { 324 } 325 326 /** 327 * Sets frequency in Hz. 328 * 329 * <p>Default value is 0. 330 * @deprecated Use {@link #setFrequencyLong(long)} 331 */ 332 @NonNull 333 @IntRange(from = 1) 334 @Deprecated setFrequency(int frequency)335 public Builder setFrequency(int frequency) { 336 return setFrequencyLong((long) frequency); 337 } 338 339 /** 340 * Sets frequency in Hz. 341 * 342 * <p>Default value is 0. 343 */ 344 @NonNull 345 @IntRange(from = 1) 346 @SuppressLint("MissingGetterMatchingBuilder") setFrequencyLong(long frequency)347 public Builder setFrequencyLong(long frequency) { 348 mFrequency = frequency; 349 return this; 350 } 351 352 /** 353 * Sets Modulation. 354 * 355 * <p>Default value is {@link #MODULATION_CONSTELLATION_UNDEFINED}. 356 */ 357 @NonNull setModulation(@odulation int modulation)358 public Builder setModulation(@Modulation int modulation) { 359 mModulation = modulation; 360 return this; 361 } 362 363 /** 364 * Sets Code Rate. 365 * 366 * <p>Default value is {@link #CODERATE_UNDEFINED}. 367 */ 368 @NonNull setCodeRate(@odeRate int codeRate)369 public Builder setCodeRate(@CodeRate int codeRate) { 370 mCodeRate = codeRate; 371 return this; 372 } 373 374 /** 375 * Sets Bandwidth. 376 * 377 * <p>Default value is {@link #BANDWIDTH_UNDEFINED}. 378 */ 379 @NonNull setBandwidth(@andwidth int bandwidth)380 public Builder setBandwidth(@Bandwidth int bandwidth) { 381 mBandwidth = bandwidth; 382 return this; 383 } 384 385 /** 386 * Sets Time Interleave Mode. 387 * 388 * <p>Default value is {@link #TIME_INTERLEAVE_MODE_UNDEFINED}. 389 */ 390 @NonNull setTimeInterleaveMode(@imeInterleaveMode int timeInterleaveMode)391 public Builder setTimeInterleaveMode(@TimeInterleaveMode int timeInterleaveMode) { 392 mTimeInterleaveMode = timeInterleaveMode; 393 return this; 394 } 395 396 /** 397 * Sets Guard Interval. 398 * 399 * <p>Default value is {@link #GUARD_INTERVAL_UNDEFINED}. 400 */ 401 @NonNull setGuardInterval(@uardInterval int guardInterval)402 public Builder setGuardInterval(@GuardInterval int guardInterval) { 403 mGuardInterval = guardInterval; 404 return this; 405 } 406 /** 407 * Sets Transmission Mode. 408 * 409 * <p>Default value is {@link #TRANSMISSION_MODE_UNDEFINED}. 410 */ 411 @NonNull setTransmissionMode(@ransmissionMode int transmissionMode)412 public Builder setTransmissionMode(@TransmissionMode int transmissionMode) { 413 mTransmissionMode = transmissionMode; 414 return this; 415 } 416 417 /** 418 * Builds a {@link DtmbFrontendSettings} object. 419 */ 420 @NonNull build()421 public DtmbFrontendSettings build() { 422 return new DtmbFrontendSettings(mFrequency, mModulation, mCodeRate, 423 mTransmissionMode, mGuardInterval, mTimeInterleaveMode, mBandwidth); 424 } 425 } 426 427 @Override getType()428 public int getType() { 429 return FrontendSettings.TYPE_DTMB; 430 } 431 } 432