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 
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29 
30 /**
31  * Frontend settings for DVBS.
32  *
33  * @hide
34  */
35 @SystemApi
36 public class DvbsFrontendSettings extends FrontendSettings {
37     /** @hide */
38     @IntDef(flag = true,
39             prefix = "MODULATION_",
40             value = {MODULATION_UNDEFINED, MODULATION_AUTO, MODULATION_MOD_QPSK,
41                     MODULATION_MOD_8PSK, MODULATION_MOD_16QAM, MODULATION_MOD_16PSK,
42                     MODULATION_MOD_32PSK, MODULATION_MOD_ACM, MODULATION_MOD_8APSK,
43                     MODULATION_MOD_16APSK, MODULATION_MOD_32APSK, MODULATION_MOD_64APSK,
44                     MODULATION_MOD_128APSK, MODULATION_MOD_256APSK, MODULATION_MOD_RESERVED})
45     @Retention(RetentionPolicy.SOURCE)
46     public @interface Modulation {}
47 
48     /**
49      * Modulation undefined.
50      */
51     public static final int MODULATION_UNDEFINED = Constants.FrontendDvbsModulation.UNDEFINED;
52     /**
53      * Hardware is able to detect and set modulation automatically
54      */
55     public static final int MODULATION_AUTO = Constants.FrontendDvbsModulation.AUTO;
56     /**
57      * QPSK Modulation.
58      */
59     public static final int MODULATION_MOD_QPSK = Constants.FrontendDvbsModulation.MOD_QPSK;
60     /**
61      * 8PSK Modulation.
62      */
63     public static final int MODULATION_MOD_8PSK = Constants.FrontendDvbsModulation.MOD_8PSK;
64     /**
65      * 16QAM Modulation.
66      */
67     public static final int MODULATION_MOD_16QAM = Constants.FrontendDvbsModulation.MOD_16QAM;
68     /**
69      * 16PSK Modulation.
70      */
71     public static final int MODULATION_MOD_16PSK = Constants.FrontendDvbsModulation.MOD_16PSK;
72     /**
73      * 32PSK Modulation.
74      */
75     public static final int MODULATION_MOD_32PSK = Constants.FrontendDvbsModulation.MOD_32PSK;
76     /**
77      * ACM Modulation.
78      */
79     public static final int MODULATION_MOD_ACM = Constants.FrontendDvbsModulation.MOD_ACM;
80     /**
81      * 8APSK Modulation.
82      */
83     public static final int MODULATION_MOD_8APSK = Constants.FrontendDvbsModulation.MOD_8APSK;
84     /**
85      * 16APSK Modulation.
86      */
87     public static final int MODULATION_MOD_16APSK = Constants.FrontendDvbsModulation.MOD_16APSK;
88     /**
89      * 32APSK Modulation.
90      */
91     public static final int MODULATION_MOD_32APSK = Constants.FrontendDvbsModulation.MOD_32APSK;
92     /**
93      * 64APSK Modulation.
94      */
95     public static final int MODULATION_MOD_64APSK = Constants.FrontendDvbsModulation.MOD_64APSK;
96     /**
97      * 128APSK Modulation.
98      */
99     public static final int MODULATION_MOD_128APSK = Constants.FrontendDvbsModulation.MOD_128APSK;
100     /**
101      * 256APSK Modulation.
102      */
103     public static final int MODULATION_MOD_256APSK = Constants.FrontendDvbsModulation.MOD_256APSK;
104     /**
105      * Reversed Modulation.
106      */
107     public static final int MODULATION_MOD_RESERVED = Constants.FrontendDvbsModulation.MOD_RESERVED;
108 
109     /** @hide */
110     @Retention(RetentionPolicy.SOURCE)
111     @IntDef(prefix = "ROLLOFF_",
112             value = {ROLLOFF_UNDEFINED, ROLLOFF_0_35, ROLLOFF_0_25, ROLLOFF_0_20, ROLLOFF_0_15,
113                     ROLLOFF_0_10, ROLLOFF_0_5})
114     public @interface Rolloff {}
115 
116     /**
117      * Rolloff range undefined.
118      */
119     public static final int ROLLOFF_UNDEFINED = Constants.FrontendDvbsRolloff.UNDEFINED;
120     /**
121      * Rolloff range 0,35.
122      */
123     public static final int ROLLOFF_0_35 = Constants.FrontendDvbsRolloff.ROLLOFF_0_35;
124     /**
125      * Rolloff range 0,25.
126      */
127     public static final int ROLLOFF_0_25 = Constants.FrontendDvbsRolloff.ROLLOFF_0_25;
128     /**
129      * Rolloff range 0,20.
130      */
131     public static final int ROLLOFF_0_20 = Constants.FrontendDvbsRolloff.ROLLOFF_0_20;
132     /**
133      * Rolloff range 0,15.
134      */
135     public static final int ROLLOFF_0_15 = Constants.FrontendDvbsRolloff.ROLLOFF_0_15;
136     /**
137      * Rolloff range 0,10.
138      */
139     public static final int ROLLOFF_0_10 = Constants.FrontendDvbsRolloff.ROLLOFF_0_10;
140     /**
141      * Rolloff range 0,5.
142      */
143     public static final int ROLLOFF_0_5 = Constants.FrontendDvbsRolloff.ROLLOFF_0_5;
144 
145     /** @hide */
146     @Retention(RetentionPolicy.SOURCE)
147     @IntDef(prefix = "PILOT_",
148             value = {PILOT_UNDEFINED, PILOT_ON, PILOT_OFF, PILOT_AUTO})
149     public @interface Pilot {}
150 
151     /**
152      * Pilot mode undefined.
153      */
154     public static final int PILOT_UNDEFINED = Constants.FrontendDvbsPilot.UNDEFINED;
155     /**
156      * Pilot mode on.
157      */
158     public static final int PILOT_ON = Constants.FrontendDvbsPilot.ON;
159     /**
160      * Pilot mode off.
161      */
162     public static final int PILOT_OFF = Constants.FrontendDvbsPilot.OFF;
163     /**
164      * Pilot mode auto.
165      */
166     public static final int PILOT_AUTO = Constants.FrontendDvbsPilot.AUTO;
167 
168 
169     /** @hide */
170     @IntDef(flag = true,
171             prefix = "STANDARD_",
172             value = {STANDARD_AUTO, STANDARD_S, STANDARD_S2, STANDARD_S2X})
173     @Retention(RetentionPolicy.SOURCE)
174     public @interface Standard {}
175 
176     /**
177      * Standard undefined.
178      */
179     public static final int STANDARD_AUTO = Constants.FrontendDvbsStandard.AUTO;
180     /**
181      * Standard S.
182      */
183     public static final int STANDARD_S = Constants.FrontendDvbsStandard.S;
184     /**
185      * Standard S2.
186      */
187     public static final int STANDARD_S2 = Constants.FrontendDvbsStandard.S2;
188     /**
189      * Standard S2X.
190      */
191     public static final int STANDARD_S2X = Constants.FrontendDvbsStandard.S2X;
192 
193     /** @hide */
194     @IntDef(prefix = "VCM_MODE_",
195             value = {VCM_MODE_UNDEFINED, VCM_MODE_AUTO, VCM_MODE_MANUAL})
196     @Retention(RetentionPolicy.SOURCE)
197     public @interface VcmMode {}
198 
199     /**
200      * VCM mode undefined.
201      */
202     public static final int VCM_MODE_UNDEFINED = Constants.FrontendDvbsVcmMode.UNDEFINED;
203     /**
204      * Auto VCM mode.
205      */
206     public static final int VCM_MODE_AUTO = Constants.FrontendDvbsVcmMode.AUTO;
207     /**
208      * Manual VCM mode.
209      */
210     public static final int VCM_MODE_MANUAL = Constants.FrontendDvbsVcmMode.MANUAL;
211 
212 
213     private final int mModulation;
214     private final DvbsCodeRate mCodeRate;
215     private final int mSymbolRate;
216     private final int mRolloff;
217     private final int mPilot;
218     private final int mInputStreamId;
219     private final int mStandard;
220     private final int mVcmMode;
221 
DvbsFrontendSettings(int frequency, int modulation, DvbsCodeRate codeRate, int symbolRate, int rolloff, int pilot, int inputStreamId, int standard, int vcm)222     private DvbsFrontendSettings(int frequency, int modulation, DvbsCodeRate codeRate,
223             int symbolRate, int rolloff, int pilot, int inputStreamId, int standard, int vcm) {
224         super(frequency);
225         mModulation = modulation;
226         mCodeRate = codeRate;
227         mSymbolRate = symbolRate;
228         mRolloff = rolloff;
229         mPilot = pilot;
230         mInputStreamId = inputStreamId;
231         mStandard = standard;
232         mVcmMode = vcm;
233     }
234 
235     /**
236      * Gets Modulation.
237      */
238     @Modulation
getModulation()239     public int getModulation() {
240         return mModulation;
241     }
242     /**
243      * Gets Code rate.
244      */
245     @Nullable
getCodeRate()246     public DvbsCodeRate getCodeRate() {
247         return mCodeRate;
248     }
249     /**
250      * Gets Symbol Rate in symbols per second.
251      */
getSymbolRate()252     public int getSymbolRate() {
253         return mSymbolRate;
254     }
255     /**
256      * Gets Rolloff.
257      */
258     @Rolloff
getRolloff()259     public int getRolloff() {
260         return mRolloff;
261     }
262     /**
263      * Gets Pilot mode.
264      */
265     @Pilot
getPilot()266     public int getPilot() {
267         return mPilot;
268     }
269     /**
270      * Gets Input Stream ID.
271      */
getInputStreamId()272     public int getInputStreamId() {
273         return mInputStreamId;
274     }
275     /**
276      * Gets DVBS sub-standard.
277      */
278     @Standard
getStandard()279     public int getStandard() {
280         return mStandard;
281     }
282     /**
283      * Gets VCM mode.
284      */
285     @VcmMode
getVcmMode()286     public int getVcmMode() {
287         return mVcmMode;
288     }
289 
290     /**
291      * Creates a builder for {@link DvbsFrontendSettings}.
292      */
293     @NonNull
builder()294     public static Builder builder() {
295         return new Builder();
296     }
297 
298     /**
299      * Builder for {@link DvbsFrontendSettings}.
300      */
301     public static class Builder {
302         private int mFrequency = 0;
303         private int mModulation = MODULATION_UNDEFINED;
304         private DvbsCodeRate mCodeRate = null;
305         private int mSymbolRate = 0;
306         private int mRolloff = ROLLOFF_UNDEFINED;
307         private int mPilot = PILOT_UNDEFINED;
308         private int mInputStreamId = Tuner.INVALID_STREAM_ID;
309         private int mStandard = STANDARD_AUTO;
310         private int mVcmMode = VCM_MODE_UNDEFINED;
311 
Builder()312         private Builder() {
313         }
314 
315         /**
316          * Sets frequency in Hz.
317          *
318          * <p>Default value is 0.
319          */
320         @NonNull
321         @IntRange(from = 1)
setFrequency(int frequency)322         public Builder setFrequency(int frequency) {
323             mFrequency = frequency;
324             return this;
325         }
326 
327         /**
328          * Sets Modulation.
329          *
330          * <p>Default value is {@link #MODULATION_UNDEFINED}.
331          */
332         @NonNull
setModulation(@odulation int modulation)333         public Builder setModulation(@Modulation int modulation) {
334             mModulation = modulation;
335             return this;
336         }
337         /**
338          * Sets Code rate.
339          *
340          * <p>Default value is {@code null}.
341          */
342         @NonNull
setCodeRate(@ullable DvbsCodeRate codeRate)343         public Builder setCodeRate(@Nullable DvbsCodeRate codeRate) {
344             mCodeRate = codeRate;
345             return this;
346         }
347         /**
348          * Sets Symbol Rate.
349          *
350          * <p>Default value is 0.
351          */
352         @NonNull
setSymbolRate(int symbolRate)353         public Builder setSymbolRate(int symbolRate) {
354             mSymbolRate = symbolRate;
355             return this;
356         }
357         /**
358          * Sets Rolloff.
359          *
360          * <p>Default value is {@link #ROLLOFF_UNDEFINED}.
361          */
362         @NonNull
setRolloff(@olloff int rolloff)363         public Builder setRolloff(@Rolloff int rolloff) {
364             mRolloff = rolloff;
365             return this;
366         }
367         /**
368          * Sets Pilot mode.
369          *
370          * <p>Default value is {@link #PILOT_UNDEFINED}.
371          */
372         @NonNull
setPilot(@ilot int pilot)373         public Builder setPilot(@Pilot int pilot) {
374             mPilot = pilot;
375             return this;
376         }
377         /**
378          * Sets Input Stream ID.
379          *
380          * <p>Default value is {@link Tuner#INVALID_STREAM_ID}.
381          */
382         @NonNull
setInputStreamId(int inputStreamId)383         public Builder setInputStreamId(int inputStreamId) {
384             mInputStreamId = inputStreamId;
385             return this;
386         }
387         /**
388          * Sets Standard.
389          *
390          * <p>Default value is {@link #STANDARD_AUTO}.
391          */
392         @NonNull
setStandard(@tandard int standard)393         public Builder setStandard(@Standard int standard) {
394             mStandard = standard;
395             return this;
396         }
397         /**
398          * Sets VCM mode.
399          *
400          * <p>Default value is {@link #VCM_MODE_UNDEFINED}.
401          */
402         @NonNull
setVcmMode(@cmMode int vcm)403         public Builder setVcmMode(@VcmMode int vcm) {
404             mVcmMode = vcm;
405             return this;
406         }
407 
408         /**
409          * Builds a {@link DvbsFrontendSettings} object.
410          */
411         @NonNull
build()412         public DvbsFrontendSettings build() {
413             return new DvbsFrontendSettings(mFrequency, mModulation, mCodeRate, mSymbolRate,
414                     mRolloff, mPilot, mInputStreamId, mStandard, mVcmMode);
415         }
416     }
417 
418     @Override
getType()419     public int getType() {
420         return FrontendSettings.TYPE_DVBS;
421     }
422 }
423