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.Nullable; 23 import android.annotation.SystemApi; 24 import android.hardware.tv.tuner.FrontendDvbsModulation; 25 import android.hardware.tv.tuner.FrontendDvbsPilot; 26 import android.hardware.tv.tuner.FrontendDvbsRolloff; 27 import android.hardware.tv.tuner.FrontendDvbsScanType; 28 import android.hardware.tv.tuner.FrontendDvbsStandard; 29 import android.hardware.tv.tuner.FrontendDvbsVcmMode; 30 import android.media.tv.tuner.Tuner; 31 import android.media.tv.tuner.TunerVersionChecker; 32 33 34 import java.lang.annotation.Retention; 35 import java.lang.annotation.RetentionPolicy; 36 37 /** 38 * Frontend settings for DVBS. 39 * 40 * @hide 41 */ 42 @SystemApi 43 public class DvbsFrontendSettings extends FrontendSettings { 44 /** @hide */ 45 @IntDef(prefix = "SCAN_TYPE_", 46 value = {SCAN_TYPE_UNDEFINED, SCAN_TYPE_DIRECT, SCAN_TYPE_DISEQC, 47 SCAN_TYPE_UNICABLE, SCAN_TYPE_JESS}) 48 @Retention(RetentionPolicy.SOURCE) 49 public @interface ScanType {} 50 51 /** 52 * Dvbs scan type undefined. 53 */ 54 public static final int SCAN_TYPE_UNDEFINED = FrontendDvbsScanType.UNDEFINED; 55 56 /** 57 * Dvbs scan type DIRECT. 58 */ 59 public static final int SCAN_TYPE_DIRECT = FrontendDvbsScanType.DIRECT; 60 61 /** 62 * Dvbs scan type DISEQC. 63 */ 64 public static final int SCAN_TYPE_DISEQC = FrontendDvbsScanType.DISEQC; 65 66 /** 67 * Dvbs scan type UNICABLE. 68 */ 69 public static final int SCAN_TYPE_UNICABLE = FrontendDvbsScanType.UNICABLE; 70 71 /** 72 * Dvbs scan type JESS. 73 */ 74 public static final int SCAN_TYPE_JESS = FrontendDvbsScanType.JESS; 75 76 /** @hide */ 77 @IntDef(prefix = "MODULATION_", 78 value = {MODULATION_UNDEFINED, MODULATION_AUTO, MODULATION_MOD_QPSK, 79 MODULATION_MOD_8PSK, MODULATION_MOD_16QAM, MODULATION_MOD_16PSK, 80 MODULATION_MOD_32PSK, MODULATION_MOD_ACM, MODULATION_MOD_8APSK, 81 MODULATION_MOD_16APSK, MODULATION_MOD_32APSK, MODULATION_MOD_64APSK, 82 MODULATION_MOD_128APSK, MODULATION_MOD_256APSK, MODULATION_MOD_RESERVED}) 83 @Retention(RetentionPolicy.SOURCE) 84 public @interface Modulation {} 85 86 /** 87 * Modulation undefined. 88 */ 89 public static final int MODULATION_UNDEFINED = FrontendDvbsModulation.UNDEFINED; 90 /** 91 * Hardware is able to detect and set modulation automatically 92 */ 93 public static final int MODULATION_AUTO = FrontendDvbsModulation.AUTO; 94 /** 95 * QPSK Modulation. 96 */ 97 public static final int MODULATION_MOD_QPSK = FrontendDvbsModulation.MOD_QPSK; 98 /** 99 * 8PSK Modulation. 100 */ 101 public static final int MODULATION_MOD_8PSK = FrontendDvbsModulation.MOD_8PSK; 102 /** 103 * 16QAM Modulation. 104 */ 105 public static final int MODULATION_MOD_16QAM = FrontendDvbsModulation.MOD_16QAM; 106 /** 107 * 16PSK Modulation. 108 */ 109 public static final int MODULATION_MOD_16PSK = FrontendDvbsModulation.MOD_16PSK; 110 /** 111 * 32PSK Modulation. 112 */ 113 public static final int MODULATION_MOD_32PSK = FrontendDvbsModulation.MOD_32PSK; 114 /** 115 * ACM Modulation. 116 */ 117 public static final int MODULATION_MOD_ACM = FrontendDvbsModulation.MOD_ACM; 118 /** 119 * 8APSK Modulation. 120 */ 121 public static final int MODULATION_MOD_8APSK = FrontendDvbsModulation.MOD_8APSK; 122 /** 123 * 16APSK Modulation. 124 */ 125 public static final int MODULATION_MOD_16APSK = FrontendDvbsModulation.MOD_16APSK; 126 /** 127 * 32APSK Modulation. 128 */ 129 public static final int MODULATION_MOD_32APSK = FrontendDvbsModulation.MOD_32APSK; 130 /** 131 * 64APSK Modulation. 132 */ 133 public static final int MODULATION_MOD_64APSK = FrontendDvbsModulation.MOD_64APSK; 134 /** 135 * 128APSK Modulation. 136 */ 137 public static final int MODULATION_MOD_128APSK = FrontendDvbsModulation.MOD_128APSK; 138 /** 139 * 256APSK Modulation. 140 */ 141 public static final int MODULATION_MOD_256APSK = FrontendDvbsModulation.MOD_256APSK; 142 /** 143 * Reversed Modulation. 144 */ 145 public static final int MODULATION_MOD_RESERVED = FrontendDvbsModulation.MOD_RESERVED; 146 147 /** @hide */ 148 @Retention(RetentionPolicy.SOURCE) 149 @IntDef(prefix = "ROLLOFF_", 150 value = {ROLLOFF_UNDEFINED, ROLLOFF_0_35, ROLLOFF_0_25, ROLLOFF_0_20, ROLLOFF_0_15, 151 ROLLOFF_0_10, ROLLOFF_0_5}) 152 public @interface Rolloff {} 153 154 /** 155 * Rolloff range undefined. 156 */ 157 public static final int ROLLOFF_UNDEFINED = FrontendDvbsRolloff.UNDEFINED; 158 /** 159 * Rolloff range 0,35. 160 */ 161 public static final int ROLLOFF_0_35 = FrontendDvbsRolloff.ROLLOFF_0_35; 162 /** 163 * Rolloff range 0,25. 164 */ 165 public static final int ROLLOFF_0_25 = FrontendDvbsRolloff.ROLLOFF_0_25; 166 /** 167 * Rolloff range 0,20. 168 */ 169 public static final int ROLLOFF_0_20 = FrontendDvbsRolloff.ROLLOFF_0_20; 170 /** 171 * Rolloff range 0,15. 172 */ 173 public static final int ROLLOFF_0_15 = FrontendDvbsRolloff.ROLLOFF_0_15; 174 /** 175 * Rolloff range 0,10. 176 */ 177 public static final int ROLLOFF_0_10 = FrontendDvbsRolloff.ROLLOFF_0_10; 178 /** 179 * Rolloff range 0,5. 180 */ 181 public static final int ROLLOFF_0_5 = FrontendDvbsRolloff.ROLLOFF_0_5; 182 183 /** @hide */ 184 @Retention(RetentionPolicy.SOURCE) 185 @IntDef(prefix = "PILOT_", 186 value = {PILOT_UNDEFINED, PILOT_ON, PILOT_OFF, PILOT_AUTO}) 187 public @interface Pilot {} 188 189 /** 190 * Pilot mode undefined. 191 */ 192 public static final int PILOT_UNDEFINED = FrontendDvbsPilot.UNDEFINED; 193 /** 194 * Pilot mode on. 195 */ 196 public static final int PILOT_ON = FrontendDvbsPilot.ON; 197 /** 198 * Pilot mode off. 199 */ 200 public static final int PILOT_OFF = FrontendDvbsPilot.OFF; 201 /** 202 * Pilot mode auto. 203 */ 204 public static final int PILOT_AUTO = FrontendDvbsPilot.AUTO; 205 206 207 /** @hide */ 208 @IntDef(prefix = "STANDARD_", 209 value = {STANDARD_AUTO, STANDARD_S, STANDARD_S2, STANDARD_S2X}) 210 @Retention(RetentionPolicy.SOURCE) 211 public @interface Standard {} 212 213 /** 214 * Standard undefined. 215 */ 216 public static final int STANDARD_AUTO = FrontendDvbsStandard.AUTO; 217 /** 218 * Standard S. 219 */ 220 public static final int STANDARD_S = FrontendDvbsStandard.S; 221 /** 222 * Standard S2. 223 */ 224 public static final int STANDARD_S2 = FrontendDvbsStandard.S2; 225 /** 226 * Standard S2X. 227 */ 228 public static final int STANDARD_S2X = FrontendDvbsStandard.S2X; 229 230 /** @hide */ 231 @IntDef(prefix = "VCM_MODE_", 232 value = {VCM_MODE_UNDEFINED, VCM_MODE_AUTO, VCM_MODE_MANUAL}) 233 @Retention(RetentionPolicy.SOURCE) 234 public @interface VcmMode {} 235 236 /** 237 * VCM mode undefined. 238 */ 239 public static final int VCM_MODE_UNDEFINED = FrontendDvbsVcmMode.UNDEFINED; 240 /** 241 * Auto VCM mode. 242 */ 243 public static final int VCM_MODE_AUTO = FrontendDvbsVcmMode.AUTO; 244 /** 245 * Manual VCM mode. 246 */ 247 public static final int VCM_MODE_MANUAL = FrontendDvbsVcmMode.MANUAL; 248 249 250 private final int mModulation; 251 private final DvbsCodeRate mCodeRate; 252 private final int mSymbolRate; 253 private final int mRolloff; 254 private final int mPilot; 255 private final int mInputStreamId; 256 private final int mStandard; 257 private final int mVcmMode; 258 // Dvbs scan type is only supported in Tuner 1.1 or higher. 259 private final int mScanType; 260 // isDiseqcRxMessage is only supported in Tuner 1.1 or higher. 261 private final boolean mIsDiseqcRxMessage; 262 DvbsFrontendSettings(long frequency, int modulation, DvbsCodeRate codeRate, int symbolRate, int rolloff, int pilot, int inputStreamId, int standard, int vcm, int scanType, boolean isDiseqcRxMessage)263 private DvbsFrontendSettings(long frequency, int modulation, DvbsCodeRate codeRate, 264 int symbolRate, int rolloff, int pilot, int inputStreamId, int standard, int vcm, 265 int scanType, boolean isDiseqcRxMessage) { 266 super(frequency); 267 mModulation = modulation; 268 mCodeRate = codeRate; 269 mSymbolRate = symbolRate; 270 mRolloff = rolloff; 271 mPilot = pilot; 272 mInputStreamId = inputStreamId; 273 mStandard = standard; 274 mVcmMode = vcm; 275 mScanType = scanType; 276 mIsDiseqcRxMessage = isDiseqcRxMessage; 277 } 278 279 /** 280 * Gets Modulation. 281 */ 282 @Modulation getModulation()283 public int getModulation() { 284 return mModulation; 285 } 286 /** 287 * Gets Code rate. 288 */ 289 @Nullable getCodeRate()290 public DvbsCodeRate getCodeRate() { 291 return mCodeRate; 292 } 293 /** 294 * Gets Symbol Rate in symbols per second. 295 */ getSymbolRate()296 public int getSymbolRate() { 297 return mSymbolRate; 298 } 299 /** 300 * Gets Rolloff. 301 */ 302 @Rolloff getRolloff()303 public int getRolloff() { 304 return mRolloff; 305 } 306 /** 307 * Gets Pilot mode. 308 */ 309 @Pilot getPilot()310 public int getPilot() { 311 return mPilot; 312 } 313 /** 314 * Gets Input Stream ID. 315 */ getInputStreamId()316 public int getInputStreamId() { 317 return mInputStreamId; 318 } 319 /** 320 * Gets DVBS sub-standard. 321 */ 322 @Standard getStandard()323 public int getStandard() { 324 return mStandard; 325 } 326 /** 327 * Gets VCM mode. 328 */ 329 @VcmMode getVcmMode()330 public int getVcmMode() { 331 return mVcmMode; 332 } 333 /** 334 * Get scan type. 335 */ 336 @ScanType getScanType()337 public int getScanType() { 338 return mScanType; 339 } 340 /** 341 * Get if the client can handle the Diseqc Rx Message or not. Default value is false. 342 * 343 * The setter {@link Builder#setCanHandleDiseqcRxMessage(boolean)} is only supported with 344 * Tuner HAL 1.1 or higher. Use {@link TunerVersionChecker#getTunerVersion()} to check the 345 * version. 346 */ canHandleDiseqcRxMessage()347 public boolean canHandleDiseqcRxMessage() { 348 return mIsDiseqcRxMessage; 349 } 350 351 /** 352 * Creates a builder for {@link DvbsFrontendSettings}. 353 */ 354 @NonNull builder()355 public static Builder builder() { 356 return new Builder(); 357 } 358 359 /** 360 * Builder for {@link DvbsFrontendSettings}. 361 */ 362 public static class Builder { 363 private long mFrequency = 0; 364 private int mModulation = MODULATION_UNDEFINED; 365 private DvbsCodeRate mCodeRate = null; 366 private int mSymbolRate = 0; 367 private int mRolloff = ROLLOFF_UNDEFINED; 368 private int mPilot = PILOT_UNDEFINED; 369 private int mInputStreamId = Tuner.INVALID_STREAM_ID; 370 private int mStandard = STANDARD_AUTO; 371 private int mVcmMode = VCM_MODE_UNDEFINED; 372 private int mScanType = SCAN_TYPE_UNDEFINED; 373 private boolean mIsDiseqcRxMessage = false; 374 Builder()375 private Builder() { 376 } 377 378 /** 379 * Sets frequency in Hz. 380 * 381 * <p>Default value is 0. 382 * @deprecated Use {@link #setFrequencyLong(long)} 383 */ 384 @NonNull 385 @IntRange(from = 1) 386 @Deprecated setFrequency(int frequency)387 public Builder setFrequency(int frequency) { 388 return setFrequencyLong((long) frequency); 389 } 390 391 /** 392 * Sets frequency in Hz. 393 * 394 * <p>Default value is 0. 395 */ 396 @NonNull 397 @IntRange(from = 1) setFrequencyLong(long frequency)398 public Builder setFrequencyLong(long frequency) { 399 mFrequency = frequency; 400 return this; 401 } 402 403 /** 404 * Set the scan type. 405 * 406 * <p>This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause 407 * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version. 408 * 409 * @param scanType the value to set as the scan type. Default value is 410 * {@link android.media.tv.tuner.frontend.DvbsFrontendSettings#DVBS_SCAN_TYPE_UNDEFINED}. 411 */ 412 @NonNull setScanType(@canType int scanType)413 public Builder setScanType(@ScanType int scanType) { 414 if (TunerVersionChecker.checkHigherOrEqualVersionTo( 415 TunerVersionChecker.TUNER_VERSION_1_1, "setScanType")) { 416 mScanType = scanType; 417 } 418 return this; 419 } 420 421 /** 422 * Set true to indicate the client can handle the Diseqc Messages. Note that it's still 423 * possible that the client won't receive the messages when HAL is not able to setup Rx 424 * channel in the hardware layer. 425 * 426 * <p>This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause 427 * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version. 428 */ 429 @NonNull setCanHandleDiseqcRxMessage(boolean canHandleDiseqcMessage)430 public Builder setCanHandleDiseqcRxMessage(boolean canHandleDiseqcMessage) { 431 if (TunerVersionChecker.checkHigherOrEqualVersionTo( 432 TunerVersionChecker.TUNER_VERSION_1_1, "setCanHandleDiseqcRxMessage")) { 433 mIsDiseqcRxMessage = canHandleDiseqcMessage; 434 } 435 return this; 436 } 437 438 /** 439 * Sets Modulation. 440 * 441 * <p>Default value is {@link #MODULATION_UNDEFINED}. 442 */ 443 @NonNull setModulation(@odulation int modulation)444 public Builder setModulation(@Modulation int modulation) { 445 mModulation = modulation; 446 return this; 447 } 448 /** 449 * Sets Code rate. 450 * 451 * <p>Default value is {@code null}. 452 */ 453 @NonNull setCodeRate(@ullable DvbsCodeRate codeRate)454 public Builder setCodeRate(@Nullable DvbsCodeRate codeRate) { 455 mCodeRate = codeRate; 456 return this; 457 } 458 /** 459 * Sets Symbol Rate. 460 * 461 * <p>Default value is 0. 462 */ 463 @NonNull setSymbolRate(int symbolRate)464 public Builder setSymbolRate(int symbolRate) { 465 mSymbolRate = symbolRate; 466 return this; 467 } 468 /** 469 * Sets Rolloff. 470 * 471 * <p>Default value is {@link #ROLLOFF_UNDEFINED}. 472 */ 473 @NonNull setRolloff(@olloff int rolloff)474 public Builder setRolloff(@Rolloff int rolloff) { 475 mRolloff = rolloff; 476 return this; 477 } 478 /** 479 * Sets Pilot mode. 480 * 481 * <p>Default value is {@link #PILOT_UNDEFINED}. 482 */ 483 @NonNull setPilot(@ilot int pilot)484 public Builder setPilot(@Pilot int pilot) { 485 mPilot = pilot; 486 return this; 487 } 488 /** 489 * Sets Input Stream ID. 490 * 491 * <p>Default value is {@link Tuner#INVALID_STREAM_ID}. 492 */ 493 @NonNull setInputStreamId(int inputStreamId)494 public Builder setInputStreamId(int inputStreamId) { 495 mInputStreamId = inputStreamId; 496 return this; 497 } 498 /** 499 * Sets Standard. 500 * 501 * <p>Default value is {@link #STANDARD_AUTO}. 502 */ 503 @NonNull setStandard(@tandard int standard)504 public Builder setStandard(@Standard int standard) { 505 mStandard = standard; 506 return this; 507 } 508 /** 509 * Sets VCM mode. 510 * 511 * <p>Default value is {@link #VCM_MODE_UNDEFINED}. 512 */ 513 @NonNull setVcmMode(@cmMode int vcm)514 public Builder setVcmMode(@VcmMode int vcm) { 515 mVcmMode = vcm; 516 return this; 517 } 518 519 /** 520 * Builds a {@link DvbsFrontendSettings} object. 521 */ 522 @NonNull build()523 public DvbsFrontendSettings build() { 524 return new DvbsFrontendSettings(mFrequency, mModulation, mCodeRate, mSymbolRate, 525 mRolloff, mPilot, mInputStreamId, mStandard, mVcmMode, mScanType, 526 mIsDiseqcRxMessage); 527 } 528 } 529 530 @Override getType()531 public int getType() { 532 return FrontendSettings.TYPE_DVBS; 533 } 534 } 535