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