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