• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.SystemApi;
23 import android.hardware.tv.tuner.FrontendCableTimeInterleaveMode;
24 import android.hardware.tv.tuner.FrontendDvbcAnnex;
25 import android.hardware.tv.tuner.FrontendDvbcBandwidth;
26 import android.hardware.tv.tuner.FrontendDvbcModulation;
27 import android.hardware.tv.tuner.FrontendDvbcOuterFec;
28 import android.media.tv.tuner.TunerVersionChecker;
29 import android.media.tv.tuner.frontend.FrontendSettings.FrontendSpectralInversion;
30 
31 import java.lang.annotation.Retention;
32 import java.lang.annotation.RetentionPolicy;
33 
34 /**
35  * Frontend settings for DVBC.
36  *
37  * @hide
38  */
39 @SystemApi
40 public class DvbcFrontendSettings extends FrontendSettings {
41 
42     /** @hide */
43     @IntDef(prefix = "MODULATION_",
44             value = {MODULATION_UNDEFINED, MODULATION_AUTO, MODULATION_MOD_16QAM,
45                     MODULATION_MOD_32QAM, MODULATION_MOD_64QAM, MODULATION_MOD_128QAM,
46                     MODULATION_MOD_256QAM})
47     @Retention(RetentionPolicy.SOURCE)
48     public @interface Modulation {}
49 
50     /**
51      * Modulation undefined.
52      */
53     public static final int MODULATION_UNDEFINED = FrontendDvbcModulation.UNDEFINED;
54     /**
55      * Hardware is able to detect and set modulation automatically
56      */
57     public static final int MODULATION_AUTO = FrontendDvbcModulation.AUTO;
58     /**
59      * 16QAM Modulation.
60      */
61     public static final int MODULATION_MOD_16QAM = FrontendDvbcModulation.MOD_16QAM;
62     /**
63      * 32QAM Modulation.
64      */
65     public static final int MODULATION_MOD_32QAM = FrontendDvbcModulation.MOD_32QAM;
66     /**
67      * 64QAM Modulation.
68      */
69     public static final int MODULATION_MOD_64QAM = FrontendDvbcModulation.MOD_64QAM;
70     /**
71      * 128QAM Modulation.
72      */
73     public static final int MODULATION_MOD_128QAM = FrontendDvbcModulation.MOD_128QAM;
74     /**
75      * 256QAM Modulation.
76      */
77     public static final int MODULATION_MOD_256QAM = FrontendDvbcModulation.MOD_256QAM;
78 
79     /** @hide */
80     @Retention(RetentionPolicy.SOURCE)
81     @IntDef(prefix = "OUTER_FEC_",
82             value = {OUTER_FEC_UNDEFINED, OUTER_FEC_OUTER_FEC_NONE, OUTER_FEC_OUTER_FEC_RS})
83     public @interface OuterFec {}
84 
85     /**
86      * Outer Forward Error Correction (FEC) Type undefined.
87      */
88     public static final int OUTER_FEC_UNDEFINED = FrontendDvbcOuterFec.UNDEFINED;
89     /**
90      * None Outer Forward Error Correction (FEC) Type.
91      */
92     public static final int OUTER_FEC_OUTER_FEC_NONE = FrontendDvbcOuterFec.OUTER_FEC_NONE;
93     /**
94      * RS Outer Forward Error Correction (FEC) Type.
95      */
96     public static final int OUTER_FEC_OUTER_FEC_RS = FrontendDvbcOuterFec.OUTER_FEC_RS;
97 
98 
99     /** @hide */
100     @IntDef(prefix = "ANNEX_",
101             value = {ANNEX_UNDEFINED, ANNEX_A, ANNEX_B, ANNEX_C})
102     @Retention(RetentionPolicy.SOURCE)
103     public @interface Annex {}
104 
105     /**
106      * Annex Type undefined.
107      */
108     public static final int ANNEX_UNDEFINED = FrontendDvbcAnnex.UNDEFINED;
109     /**
110      * Annex Type A.
111      */
112     public static final int ANNEX_A = FrontendDvbcAnnex.A;
113     /**
114      * Annex Type B.
115      */
116     public static final int ANNEX_B = FrontendDvbcAnnex.B;
117     /**
118      * Annex Type C.
119      */
120     public static final int ANNEX_C = FrontendDvbcAnnex.C;
121 
122 
123     /**
124      * @deprecated Use the {@code FrontendSpectralInversion} instead.
125      * @hide
126      */
127     @Deprecated
128     @IntDef(prefix = "SPECTRAL_INVERSION_",
129             value = {SPECTRAL_INVERSION_UNDEFINED, SPECTRAL_INVERSION_NORMAL,
130                     SPECTRAL_INVERSION_INVERTED})
131     @Retention(RetentionPolicy.SOURCE)
132     public @interface SpectralInversion {}
133 
134     /**
135      * Spectral Inversion Type undefined.
136      *
137      * @deprecated Use the {@link FrontendSettings#FRONTEND_SPECTRAL_INVERSION_UNDEFINED} instead.
138      */
139     @Deprecated
140     public static final int SPECTRAL_INVERSION_UNDEFINED =
141             android.hardware.tv.tuner.FrontendSpectralInversion.UNDEFINED;
142     /**
143      * Normal Spectral Inversion.
144      *
145      * @deprecated Use the {@link FrontendSettings#FRONTEND_SPECTRAL_INVERSION_NORMAL} instead.
146      */
147     @Deprecated
148     public static final int SPECTRAL_INVERSION_NORMAL =
149              android.hardware.tv.tuner.FrontendSpectralInversion.NORMAL;
150     /**
151      * Inverted Spectral Inversion.
152      *
153      * @deprecated Use the {@link FrontendSettings#FRONTEND_SPECTRAL_INVERSION_INVERTED} instead.
154      */
155     @Deprecated
156     public static final int SPECTRAL_INVERSION_INVERTED =
157             android.hardware.tv.tuner.FrontendSpectralInversion.INVERTED;
158 
159     /** @hide */
160     @IntDef(prefix = "TIME_INTERLEAVE_MODE_",
161             value = {TIME_INTERLEAVE_MODE_UNDEFINED, TIME_INTERLEAVE_MODE_AUTO,
162                     TIME_INTERLEAVE_MODE_128_1_0, TIME_INTERLEAVE_MODE_128_1_1,
163                     TIME_INTERLEAVE_MODE_64_2, TIME_INTERLEAVE_MODE_32_4,
164                     TIME_INTERLEAVE_MODE_16_8, TIME_INTERLEAVE_MODE_8_16,
165                     TIME_INTERLEAVE_MODE_128_2, TIME_INTERLEAVE_MODE_128_3,
166                     TIME_INTERLEAVE_MODE_128_4})
167     @Retention(RetentionPolicy.SOURCE)
168     public @interface TimeInterleaveMode {}
169 
170     /**
171      * Time interleave mode undefined.
172      */
173     public static final int TIME_INTERLEAVE_MODE_UNDEFINED =
174             FrontendCableTimeInterleaveMode.UNDEFINED;
175     /**
176      * Hardware is able to detect and set Time Interleave Mode automatically.
177      */
178     public static final int TIME_INTERLEAVE_MODE_AUTO = FrontendCableTimeInterleaveMode.AUTO;
179     /**
180      * 128/1/0 Time Interleave Mode.
181      */
182     public static final int TIME_INTERLEAVE_MODE_128_1_0 =
183             FrontendCableTimeInterleaveMode.INTERLEAVING_128_1_0;
184     /**
185      * 128/1/1 Time Interleave Mode.
186      */
187     public static final int TIME_INTERLEAVE_MODE_128_1_1 =
188             FrontendCableTimeInterleaveMode.INTERLEAVING_128_1_1;
189     /**
190      * 64/2 Time Interleave Mode.
191      */
192     public static final int TIME_INTERLEAVE_MODE_64_2 =
193             FrontendCableTimeInterleaveMode.INTERLEAVING_64_2;
194     /**
195      * 32/4 Time Interleave Mode.
196      */
197     public static final int TIME_INTERLEAVE_MODE_32_4 =
198             FrontendCableTimeInterleaveMode.INTERLEAVING_32_4;
199     /**
200      * 16/8 Time Interleave Mode.
201      */
202     public static final int TIME_INTERLEAVE_MODE_16_8 =
203             FrontendCableTimeInterleaveMode.INTERLEAVING_16_8;
204     /**
205      * 8/16 Time Interleave Mode.
206      */
207     public static final int TIME_INTERLEAVE_MODE_8_16 =
208             FrontendCableTimeInterleaveMode.INTERLEAVING_8_16;
209     /**
210      * 128/2 Time Interleave Mode.
211      */
212     public static final int TIME_INTERLEAVE_MODE_128_2 =
213             FrontendCableTimeInterleaveMode.INTERLEAVING_128_2;
214     /**
215      * 128/3 Time Interleave Mode.
216      */
217     public static final int TIME_INTERLEAVE_MODE_128_3 =
218             FrontendCableTimeInterleaveMode.INTERLEAVING_128_3;
219     /**
220      * 128/4 Time Interleave Mode.
221      */
222     public static final int TIME_INTERLEAVE_MODE_128_4 =
223             FrontendCableTimeInterleaveMode.INTERLEAVING_128_4;
224 
225     /** @hide */
226     @IntDef(prefix = "BANDWIDTH_",
227             value = {BANDWIDTH_UNDEFINED, BANDWIDTH_5MHZ, BANDWIDTH_6MHZ, BANDWIDTH_7MHZ,
228                     BANDWIDTH_8MHZ})
229     @Retention(RetentionPolicy.SOURCE)
230     public @interface Bandwidth {}
231 
232     /**
233      * Bandwidth undefined.
234      */
235     public static final int BANDWIDTH_UNDEFINED = FrontendDvbcBandwidth.UNDEFINED;
236     /**
237      * 5 MHz bandwidth.
238      */
239     public static final int BANDWIDTH_5MHZ = FrontendDvbcBandwidth.BANDWIDTH_5MHZ;
240     /**
241      * 6 MHz bandwidth.
242      */
243     public static final int BANDWIDTH_6MHZ = FrontendDvbcBandwidth.BANDWIDTH_6MHZ;
244     /**
245      * 7 MHz bandwidth.
246      */
247     public static final int BANDWIDTH_7MHZ = FrontendDvbcBandwidth.BANDWIDTH_7MHZ;
248     /**
249      * 8 MHz bandwidth.
250      */
251     public static final int BANDWIDTH_8MHZ = FrontendDvbcBandwidth.BANDWIDTH_8MHZ;
252 
253 
254     private final int mModulation;
255     private final long mInnerFec;
256     private final int mSymbolRate;
257     private final int mOuterFec;
258     private final int mAnnex;
259     private final int mSpectralInversion;
260     // Dvbc time interleave mode is only supported in Tuner 1.1 or higher.
261     private final int mInterleaveMode;
262     // Dvbc bandwidth is only supported in Tuner 1.1 or higher.
263     private final int mBandwidth;
264 
DvbcFrontendSettings(long frequency, int modulation, long innerFec, int symbolRate, int outerFec, int annex, int spectralInversion, int interleaveMode, int bandwidth)265     private DvbcFrontendSettings(long frequency, int modulation, long innerFec, int symbolRate,
266             int outerFec, int annex, int spectralInversion, int interleaveMode, int bandwidth) {
267         super(frequency);
268         mModulation = modulation;
269         mInnerFec = innerFec;
270         mSymbolRate = symbolRate;
271         mOuterFec = outerFec;
272         mAnnex = annex;
273         mSpectralInversion = spectralInversion;
274         mInterleaveMode = interleaveMode;
275         mBandwidth = bandwidth;
276     }
277 
278     /**
279      * Gets Modulation.
280      */
281     @Modulation
getModulation()282     public int getModulation() {
283         return mModulation;
284     }
285     /**
286      * Gets Inner Forward Error Correction.
287      */
288     @InnerFec
getInnerFec()289     public long getInnerFec() {
290         return mInnerFec;
291     }
292     /**
293      * Gets Symbol Rate in symbols per second.
294      */
getSymbolRate()295     public int getSymbolRate() {
296         return mSymbolRate;
297     }
298     /**
299      * Gets Outer Forward Error Correction.
300      */
301     @OuterFec
getOuterFec()302     public int getOuterFec() {
303         return mOuterFec;
304     }
305     /**
306      * Gets Annex.
307      */
308     @Annex
getAnnex()309     public int getAnnex() {
310         return mAnnex;
311     }
312     /**
313      * Gets Spectral Inversion.
314      */
315     @FrontendSpectralInversion
getSpectralInversion()316     public int getSpectralInversion() {
317         return mSpectralInversion;
318     }
319     /**
320      * Gets Time Interleave Mode.
321      */
322     @TimeInterleaveMode
getTimeInterleaveMode()323     public int getTimeInterleaveMode() {
324         return mInterleaveMode;
325     }
326     /**
327      * Gets Bandwidth.
328      */
329     @Bandwidth
getBandwidth()330     public int getBandwidth() {
331         return mBandwidth;
332     }
333 
334     /**
335      * Creates a builder for {@link DvbcFrontendSettings}.
336      */
337     @NonNull
builder()338     public static Builder builder() {
339         return new Builder();
340     }
341 
342     /**
343      * Builder for {@link DvbcFrontendSettings}.
344      */
345     public static class Builder {
346         private long mFrequency = 0;
347         private int mModulation = MODULATION_UNDEFINED;
348         private long mInnerFec = FEC_UNDEFINED;
349         private int mSymbolRate = 0;
350         private int mOuterFec = OUTER_FEC_UNDEFINED;
351         private int mAnnex = ANNEX_UNDEFINED;
352         private int mSpectralInversion = FrontendSettings.FRONTEND_SPECTRAL_INVERSION_UNDEFINED;
353         private int mInterleaveMode = TIME_INTERLEAVE_MODE_UNDEFINED;
354         private int mBandwidth = BANDWIDTH_UNDEFINED;
355 
Builder()356         private Builder() {
357         }
358 
359         /**
360          * Sets frequency in Hz.
361          *
362          * <p>Default value is 0.
363          * @deprecated Use {@link #setFrequencyLong(long)}
364          */
365         @NonNull
366         @IntRange(from = 1)
367         @Deprecated
setFrequency(int frequency)368         public Builder setFrequency(int frequency) {
369             return setFrequencyLong((long) frequency);
370         }
371 
372         /**
373          * Sets frequency in Hz.
374          *
375          * <p>Default value is 0.
376          */
377         @NonNull
378         @IntRange(from = 1)
setFrequencyLong(long frequency)379         public Builder setFrequencyLong(long frequency) {
380             mFrequency = frequency;
381             return this;
382         }
383 
384         /**
385          * Sets Modulation.
386          *
387          * <p>Default value is {@link #MODULATION_UNDEFINED}.
388          */
389         @NonNull
setModulation(@odulation int modulation)390         public Builder setModulation(@Modulation int modulation) {
391             mModulation = modulation;
392             return this;
393         }
394         /**
395          * Sets Inner Forward Error Correction.
396          *
397          * <p>Default value is {@link #FEC_UNDEFINED}.
398          */
399         @NonNull
setInnerFec(@nnerFec long fec)400         public Builder setInnerFec(@InnerFec long fec) {
401             mInnerFec = fec;
402             return this;
403         }
404         /**
405          * Sets Symbol Rate in symbols per second.
406          *
407          * <p>Default value is 0.
408          */
409         @NonNull
setSymbolRate(int symbolRate)410         public Builder setSymbolRate(int symbolRate) {
411             mSymbolRate = symbolRate;
412             return this;
413         }
414         /**
415          * Sets Outer Forward Error Correction.
416          *
417          * <p>Default value is {@link #OUTER_FEC_UNDEFINED}.
418          */
419         @NonNull
setOuterFec(@uterFec int outerFec)420         public Builder setOuterFec(@OuterFec int outerFec) {
421             mOuterFec = outerFec;
422             return this;
423         }
424         /**
425          * Sets Annex.
426          *
427          * <p>Default value is {@link #ANNEX_UNDEFINED}.
428          */
429         @NonNull
setAnnex(@nnex int annex)430         public Builder setAnnex(@Annex int annex) {
431             mAnnex = annex;
432             return this;
433         }
434         /**
435          * Sets Spectral Inversion.
436          *
437          * <p>Default value is {@link FrontendSettings#FRONTEND_SPECTRAL_INVERSION_UNDEFINED}.
438          */
439         @NonNull
setSpectralInversion(@rontendSpectralInversion int spectralInversion)440         public Builder setSpectralInversion(@FrontendSpectralInversion int spectralInversion) {
441             mSpectralInversion = spectralInversion;
442             return this;
443         }
444         /**
445          * Set the time interleave mode.
446          *
447          * <p>This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause
448          * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version.
449          *
450          * @param interleaveMode the value to set as the time interleave mode. Default value is
451          * {@link #TIME_INTERLEAVE_MODE_UNDEFINED}.
452          */
453         @NonNull
setTimeInterleaveMode(@imeInterleaveMode int interleaveMode)454         public Builder setTimeInterleaveMode(@TimeInterleaveMode int interleaveMode) {
455             if (TunerVersionChecker.checkHigherOrEqualVersionTo(
456                         TunerVersionChecker.TUNER_VERSION_1_1, "setTimeInterleaveMode")) {
457                 mInterleaveMode = interleaveMode;
458             }
459             return this;
460         }
461         /**
462          * Set the Bandwidth.
463          *
464          * <p>This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause
465          * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version.
466          *
467          * @param bandwidth the value to set as the bandwidth. Default value is
468          * {@link #BANDWIDTH_UNDEFINED}.
469          */
470         @NonNull
setBandwidth(@andwidth int bandwidth)471         public Builder setBandwidth(@Bandwidth int bandwidth) {
472             if (TunerVersionChecker.checkHigherOrEqualVersionTo(
473                         TunerVersionChecker.TUNER_VERSION_1_1, "setBandwidth")) {
474                 mBandwidth = bandwidth;
475             }
476             return this;
477         }
478 
479         /**
480          * Builds a {@link DvbcFrontendSettings} object.
481          */
482         @NonNull
build()483         public DvbcFrontendSettings build() {
484             return new DvbcFrontendSettings(mFrequency, mModulation, mInnerFec, mSymbolRate,
485                 mOuterFec, mAnnex, mSpectralInversion, mInterleaveMode, mBandwidth);
486         }
487     }
488 
489     @Override
getType()490     public int getType() {
491         return FrontendSettings.TYPE_DVBC;
492     }
493 }
494