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