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.LongDef; 22 import android.annotation.SystemApi; 23 import android.hardware.tv.tuner.FrontendInnerFec; 24 import android.hardware.tv.tuner.FrontendType; 25 import android.media.tv.tuner.Tuner; 26 import android.media.tv.tuner.TunerVersionChecker; 27 28 import java.lang.annotation.Retention; 29 import java.lang.annotation.RetentionPolicy; 30 31 /** 32 * Frontend settings for tune and scan operations. 33 * 34 * @hide 35 */ 36 @SystemApi 37 public abstract class FrontendSettings { 38 /** @hide */ 39 @IntDef(prefix = "TYPE_", 40 value = {TYPE_UNDEFINED, TYPE_ANALOG, TYPE_ATSC, TYPE_ATSC3, TYPE_DVBC, TYPE_DVBS, 41 TYPE_DVBT, TYPE_ISDBS, TYPE_ISDBS3, TYPE_ISDBT, TYPE_DTMB}) 42 @Retention(RetentionPolicy.SOURCE) 43 public @interface Type {} 44 45 /** 46 * Undefined frontend type. 47 */ 48 public static final int TYPE_UNDEFINED = FrontendType.UNDEFINED; 49 /** 50 * Analog frontend type. 51 */ 52 public static final int TYPE_ANALOG = FrontendType.ANALOG; 53 /** 54 * Advanced Television Systems Committee (ATSC) frontend type. 55 */ 56 public static final int TYPE_ATSC = FrontendType.ATSC; 57 /** 58 * Advanced Television Systems Committee 3.0 (ATSC-3) frontend type. 59 */ 60 public static final int TYPE_ATSC3 = FrontendType.ATSC3; 61 /** 62 * Digital Video Broadcasting-Cable (DVB-C) frontend type. 63 */ 64 public static final int TYPE_DVBC = FrontendType.DVBC; 65 /** 66 * Digital Video Broadcasting-Satellite (DVB-S) frontend type. 67 */ 68 public static final int TYPE_DVBS = FrontendType.DVBS; 69 /** 70 * Digital Video Broadcasting-Terrestrial (DVB-T) frontend type. 71 */ 72 public static final int TYPE_DVBT = FrontendType.DVBT; 73 /** 74 * Integrated Services Digital Broadcasting-Satellite (ISDB-S) frontend type. 75 */ 76 public static final int TYPE_ISDBS = FrontendType.ISDBS; 77 /** 78 * Integrated Services Digital Broadcasting-Satellite 3 (ISDB-S3) frontend type. 79 */ 80 public static final int TYPE_ISDBS3 = FrontendType.ISDBS3; 81 /** 82 * Integrated Services Digital Broadcasting-Terrestrial (ISDB-T) frontend type. 83 */ 84 public static final int TYPE_ISDBT = FrontendType.ISDBT; 85 /** 86 * Digital Terrestrial Multimedia Broadcast standard (DTMB) frontend type. 87 */ 88 public static final int TYPE_DTMB = FrontendType.DTMB; 89 90 91 /** @hide */ 92 @LongDef(prefix = "FEC_", 93 value = {FEC_UNDEFINED, FEC_AUTO, FEC_1_2, FEC_1_3, FEC_1_4, FEC_1_5, FEC_2_3, FEC_2_5, 94 FEC_2_9, FEC_3_4, FEC_3_5, FEC_4_5, FEC_4_15, FEC_5_6, FEC_5_9, FEC_6_7, FEC_7_8, 95 FEC_7_9, FEC_7_15, FEC_8_9, FEC_8_15, FEC_9_10, FEC_9_20, FEC_11_15, FEC_11_20, 96 FEC_11_45, FEC_13_18, FEC_13_45, FEC_14_45, FEC_23_36, FEC_25_36, FEC_26_45, FEC_28_45, 97 FEC_29_45, FEC_31_45, FEC_32_45, FEC_77_90}) 98 @Retention(RetentionPolicy.SOURCE) 99 public @interface InnerFec {} 100 101 /** 102 * FEC not defined. 103 */ 104 public static final long FEC_UNDEFINED = FrontendInnerFec.FEC_UNDEFINED; 105 /** 106 * hardware is able to detect and set FEC automatically. 107 */ 108 public static final long FEC_AUTO = FrontendInnerFec.AUTO; 109 /** 110 * 1/2 conv. code rate. 111 */ 112 public static final long FEC_1_2 = FrontendInnerFec.FEC_1_2; 113 /** 114 * 1/3 conv. code rate. 115 */ 116 public static final long FEC_1_3 = FrontendInnerFec.FEC_1_3; 117 /** 118 * 1/4 conv. code rate. 119 */ 120 public static final long FEC_1_4 = FrontendInnerFec.FEC_1_4; 121 /** 122 * 1/5 conv. code rate. 123 */ 124 public static final long FEC_1_5 = FrontendInnerFec.FEC_1_5; 125 /** 126 * 2/3 conv. code rate. 127 */ 128 public static final long FEC_2_3 = FrontendInnerFec.FEC_2_3; 129 /** 130 * 2/5 conv. code rate. 131 */ 132 public static final long FEC_2_5 = FrontendInnerFec.FEC_2_5; 133 /** 134 * 2/9 conv. code rate. 135 */ 136 public static final long FEC_2_9 = FrontendInnerFec.FEC_2_9; 137 /** 138 * 3/4 conv. code rate. 139 */ 140 public static final long FEC_3_4 = FrontendInnerFec.FEC_3_4; 141 /** 142 * 3/5 conv. code rate. 143 */ 144 public static final long FEC_3_5 = FrontendInnerFec.FEC_3_5; 145 /** 146 * 4/5 conv. code rate. 147 */ 148 public static final long FEC_4_5 = FrontendInnerFec.FEC_4_5; 149 /** 150 * 4/15 conv. code rate. 151 */ 152 public static final long FEC_4_15 = FrontendInnerFec.FEC_4_15; 153 /** 154 * 5/6 conv. code rate. 155 */ 156 public static final long FEC_5_6 = FrontendInnerFec.FEC_5_6; 157 /** 158 * 5/9 conv. code rate. 159 */ 160 public static final long FEC_5_9 = FrontendInnerFec.FEC_5_9; 161 /** 162 * 6/7 conv. code rate. 163 */ 164 public static final long FEC_6_7 = FrontendInnerFec.FEC_6_7; 165 /** 166 * 7/8 conv. code rate. 167 */ 168 public static final long FEC_7_8 = FrontendInnerFec.FEC_7_8; 169 /** 170 * 7/9 conv. code rate. 171 */ 172 public static final long FEC_7_9 = FrontendInnerFec.FEC_7_9; 173 /** 174 * 7/15 conv. code rate. 175 */ 176 public static final long FEC_7_15 = FrontendInnerFec.FEC_7_15; 177 /** 178 * 8/9 conv. code rate. 179 */ 180 public static final long FEC_8_9 = FrontendInnerFec.FEC_8_9; 181 /** 182 * 8/15 conv. code rate. 183 */ 184 public static final long FEC_8_15 = FrontendInnerFec.FEC_8_15; 185 /** 186 * 9/10 conv. code rate. 187 */ 188 public static final long FEC_9_10 = FrontendInnerFec.FEC_9_10; 189 /** 190 * 9/20 conv. code rate. 191 */ 192 public static final long FEC_9_20 = FrontendInnerFec.FEC_9_20; 193 /** 194 * 11/15 conv. code rate. 195 */ 196 public static final long FEC_11_15 = FrontendInnerFec.FEC_11_15; 197 /** 198 * 11/20 conv. code rate. 199 */ 200 public static final long FEC_11_20 = FrontendInnerFec.FEC_11_20; 201 /** 202 * 11/45 conv. code rate. 203 */ 204 public static final long FEC_11_45 = FrontendInnerFec.FEC_11_45; 205 /** 206 * 13/18 conv. code rate. 207 */ 208 public static final long FEC_13_18 = FrontendInnerFec.FEC_13_18; 209 /** 210 * 13/45 conv. code rate. 211 */ 212 public static final long FEC_13_45 = FrontendInnerFec.FEC_13_45; 213 /** 214 * 14/45 conv. code rate. 215 */ 216 public static final long FEC_14_45 = FrontendInnerFec.FEC_14_45; 217 /** 218 * 23/36 conv. code rate. 219 */ 220 public static final long FEC_23_36 = FrontendInnerFec.FEC_23_36; 221 /** 222 * 25/36 conv. code rate. 223 */ 224 public static final long FEC_25_36 = FrontendInnerFec.FEC_25_36; 225 /** 226 * 26/45 conv. code rate. 227 */ 228 public static final long FEC_26_45 = FrontendInnerFec.FEC_26_45; 229 /** 230 * 28/45 conv. code rate. 231 */ 232 public static final long FEC_28_45 = FrontendInnerFec.FEC_28_45; 233 /** 234 * 29/45 conv. code rate. 235 */ 236 public static final long FEC_29_45 = FrontendInnerFec.FEC_29_45; 237 /** 238 * 31/45 conv. code rate. 239 */ 240 public static final long FEC_31_45 = FrontendInnerFec.FEC_31_45; 241 /** 242 * 32/45 conv. code rate. 243 */ 244 public static final long FEC_32_45 = FrontendInnerFec.FEC_32_45; 245 /** 246 * 77/90 conv. code rate. 247 */ 248 public static final long FEC_77_90 = FrontendInnerFec.FEC_77_90; 249 250 /** @hide */ 251 @IntDef(prefix = "FRONTEND_SPECTRAL_INVERSION_", 252 value = {FRONTEND_SPECTRAL_INVERSION_UNDEFINED, FRONTEND_SPECTRAL_INVERSION_NORMAL, 253 FRONTEND_SPECTRAL_INVERSION_INVERTED}) 254 @Retention(RetentionPolicy.SOURCE) 255 public @interface FrontendSpectralInversion {} 256 257 /** 258 * Spectral Inversion Type undefined. 259 */ 260 public static final int FRONTEND_SPECTRAL_INVERSION_UNDEFINED = 261 android.hardware.tv.tuner.FrontendSpectralInversion.UNDEFINED; 262 /** 263 * Normal Spectral Inversion. 264 */ 265 public static final int FRONTEND_SPECTRAL_INVERSION_NORMAL = 266 android.hardware.tv.tuner.FrontendSpectralInversion.NORMAL; 267 /** 268 * Inverted Spectral Inversion. 269 */ 270 public static final int FRONTEND_SPECTRAL_INVERSION_INVERTED = 271 android.hardware.tv.tuner.FrontendSpectralInversion.INVERTED; 272 273 private final long mFrequency; 274 // End frequency is only supported in Tuner 1.1 or higher. 275 private long mEndFrequency = Tuner.INVALID_FRONTEND_SETTING_FREQUENCY; 276 // General spectral inversion is only supported in Tuner 1.1 or higher. 277 private int mSpectralInversion = FRONTEND_SPECTRAL_INVERSION_UNDEFINED; 278 FrontendSettings(long frequency)279 FrontendSettings(long frequency) { mFrequency = frequency; } 280 281 /** 282 * Returns the frontend type. 283 */ 284 @Type getType()285 public abstract int getType(); 286 287 /** 288 * Gets the frequency. 289 * 290 * @return the frequency in Hz. 291 * @deprecated Use {@link #getFrequencyLong()} 292 */ 293 @Deprecated getFrequency()294 public int getFrequency() { 295 return (int) getFrequencyLong(); 296 } 297 298 /** 299 * Gets the frequency. 300 * 301 * @return the frequency in Hz. 302 */ getFrequencyLong()303 public long getFrequencyLong() { 304 return mFrequency; 305 } 306 307 /** 308 * Get the end frequency. 309 * 310 * @return the end frequency in Hz. 311 * @deprecated Use {@link #getEndFrequencyLong()} 312 */ 313 @Deprecated 314 @IntRange(from = 1) getEndFrequency()315 public int getEndFrequency() { 316 return (int) getEndFrequencyLong(); 317 } 318 319 /** 320 * Get the end frequency. 321 * 322 * @return the end frequency in Hz. 323 */ 324 @IntRange(from = 1) getEndFrequencyLong()325 public long getEndFrequencyLong() { 326 return mEndFrequency; 327 } 328 329 /** 330 * Get the spectral inversion. 331 * 332 * @return the value of the spectral inversion. 333 */ 334 @FrontendSpectralInversion getFrontendSpectralInversion()335 public int getFrontendSpectralInversion() { 336 return mSpectralInversion; 337 } 338 339 /** 340 * Set Spectral Inversion. 341 * 342 * <p>This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause 343 * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version. 344 * 345 * @param inversion the value to set as the spectral inversion. Default value is {@link 346 * #FRONTEND_SPECTRAL_INVERSION_UNDEFINED}. 347 */ setSpectralInversion(@rontendSpectralInversion int inversion)348 public void setSpectralInversion(@FrontendSpectralInversion int inversion) { 349 if (TunerVersionChecker.checkHigherOrEqualVersionTo( 350 TunerVersionChecker.TUNER_VERSION_1_1, "setSpectralInversion")) { 351 mSpectralInversion = inversion; 352 } 353 } 354 355 /** 356 * Set End Frequency. This API is only supported with Tuner HAL 1.1 or higher. Otherwise it 357 * would be no-op. 358 * 359 * <p>This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause 360 * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version. 361 * 362 * @param endFrequency the end frequency used during blind scan. The default value is 363 * {@link android.media.tv.tuner.Tuner#INVALID_FRONTEND_SETTING_FREQUENCY}. 364 * @throws IllegalArgumentException if the {@code endFrequency} is not greater than 0. 365 * @deprecated Use {@link #setFrequencyLong(long)} 366 */ 367 @IntRange(from = 1) 368 @Deprecated setEndFrequency(int frequency)369 public void setEndFrequency(int frequency) { 370 setEndFrequencyLong((long) frequency); 371 } 372 373 /** 374 * Set End Frequency. This API is only supported with Tuner HAL 1.1 or higher. Otherwise it 375 * would be no-op. 376 * 377 * <p>This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause 378 * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version. 379 * 380 * @param endFrequency the end frequency used during blind scan. The default value is 381 * {@link android.media.tv.tuner.Tuner#INVALID_FRONTEND_SETTING_FREQUENCY}. 382 * @throws IllegalArgumentException if the {@code endFrequency} is not greater than 0. 383 */ 384 @IntRange(from = 1) setEndFrequencyLong(long endFrequency)385 public void setEndFrequencyLong(long endFrequency) { 386 if (TunerVersionChecker.checkHigherOrEqualVersionTo( 387 TunerVersionChecker.TUNER_VERSION_1_1, "setEndFrequency")) { 388 if (endFrequency < 1) { 389 throw new IllegalArgumentException("endFrequency must be greater than 0"); 390 } 391 mEndFrequency = endFrequency; 392 } 393 } 394 } 395