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.V1_0.Constants;
24 
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 
28 /**
29  * Frontend settings for ATSC-3.
30  *
31  * @hide
32  */
33 @SystemApi
34 public class Atsc3FrontendSettings extends FrontendSettings {
35 
36     /** @hide */
37     @IntDef(flag = true,
38             prefix = "BANDWIDTH_",
39             value = {BANDWIDTH_UNDEFINED, BANDWIDTH_AUTO, BANDWIDTH_BANDWIDTH_6MHZ,
40                     BANDWIDTH_BANDWIDTH_7MHZ, BANDWIDTH_BANDWIDTH_8MHZ})
41     @Retention(RetentionPolicy.SOURCE)
42     public @interface Bandwidth {}
43 
44     /**
45      * Bandwidth not defined.
46      */
47     public static final int BANDWIDTH_UNDEFINED =
48             Constants.FrontendAtsc3Bandwidth.UNDEFINED;
49     /**
50      * Hardware is able to detect and set bandwidth automatically
51      */
52     public static final int BANDWIDTH_AUTO = Constants.FrontendAtsc3Bandwidth.AUTO;
53     /**
54      * 6 MHz bandwidth.
55      */
56     public static final int BANDWIDTH_BANDWIDTH_6MHZ =
57             Constants.FrontendAtsc3Bandwidth.BANDWIDTH_6MHZ;
58     /**
59      * 7 MHz bandwidth.
60      */
61     public static final int BANDWIDTH_BANDWIDTH_7MHZ =
62             Constants.FrontendAtsc3Bandwidth.BANDWIDTH_7MHZ;
63     /**
64      * 8 MHz bandwidth.
65      */
66     public static final int BANDWIDTH_BANDWIDTH_8MHZ =
67             Constants.FrontendAtsc3Bandwidth.BANDWIDTH_8MHZ;
68 
69 
70     /** @hide */
71     @IntDef(flag = true,
72             prefix = "MODULATION_",
73             value = {MODULATION_UNDEFINED, MODULATION_AUTO,
74                     MODULATION_MOD_QPSK, MODULATION_MOD_16QAM,
75                     MODULATION_MOD_64QAM, MODULATION_MOD_256QAM,
76                     MODULATION_MOD_1024QAM, MODULATION_MOD_4096QAM})
77     @Retention(RetentionPolicy.SOURCE)
78     public @interface Modulation {}
79 
80     /**
81      * Modulation undefined.
82      */
83     public static final int MODULATION_UNDEFINED = Constants.FrontendAtsc3Modulation.UNDEFINED;
84     /**
85      * Hardware is able to detect and set modulation automatically.
86      */
87     public static final int MODULATION_AUTO = Constants.FrontendAtsc3Modulation.AUTO;
88     /**
89      * QPSK modulation.
90      */
91     public static final int MODULATION_MOD_QPSK = Constants.FrontendAtsc3Modulation.MOD_QPSK;
92     /**
93      * 16QAM modulation.
94      */
95     public static final int MODULATION_MOD_16QAM = Constants.FrontendAtsc3Modulation.MOD_16QAM;
96     /**
97      * 64QAM modulation.
98      */
99     public static final int MODULATION_MOD_64QAM = Constants.FrontendAtsc3Modulation.MOD_64QAM;
100     /**
101      * 256QAM modulation.
102      */
103     public static final int MODULATION_MOD_256QAM = Constants.FrontendAtsc3Modulation.MOD_256QAM;
104     /**
105      * 1024QAM modulation.
106      */
107     public static final int MODULATION_MOD_1024QAM = Constants.FrontendAtsc3Modulation.MOD_1024QAM;
108     /**
109      * 4096QAM modulation.
110      */
111     public static final int MODULATION_MOD_4096QAM = Constants.FrontendAtsc3Modulation.MOD_4096QAM;
112 
113 
114     /** @hide */
115     @IntDef(flag = true,
116             prefix = "TIME_INTERLEAVE_MODE_",
117             value = {TIME_INTERLEAVE_MODE_UNDEFINED, TIME_INTERLEAVE_MODE_AUTO,
118                     TIME_INTERLEAVE_MODE_CTI, TIME_INTERLEAVE_MODE_HTI})
119     @Retention(RetentionPolicy.SOURCE)
120     public @interface TimeInterleaveMode {}
121 
122     /**
123      * Time interleave mode undefined.
124      */
125     public static final int TIME_INTERLEAVE_MODE_UNDEFINED =
126             Constants.FrontendAtsc3TimeInterleaveMode.UNDEFINED;
127     /**
128      * Hardware is able to detect and set Time Interleave Mode automatically.
129      */
130     public static final int TIME_INTERLEAVE_MODE_AUTO =
131             Constants.FrontendAtsc3TimeInterleaveMode.AUTO;
132     /**
133      * CTI Time Interleave Mode.
134      */
135     public static final int TIME_INTERLEAVE_MODE_CTI =
136             Constants.FrontendAtsc3TimeInterleaveMode.CTI;
137     /**
138      * HTI Time Interleave Mode.
139      */
140     public static final int TIME_INTERLEAVE_MODE_HTI =
141             Constants.FrontendAtsc3TimeInterleaveMode.HTI;
142 
143 
144     /** @hide */
145     @IntDef(flag = true,
146             prefix = "CODERATE_",
147             value = {CODERATE_UNDEFINED, CODERATE_AUTO, CODERATE_2_15, CODERATE_3_15, CODERATE_4_15,
148                     CODERATE_5_15, CODERATE_6_15, CODERATE_7_15, CODERATE_8_15, CODERATE_9_15,
149                     CODERATE_10_15, CODERATE_11_15, CODERATE_12_15, CODERATE_13_15})
150     @Retention(RetentionPolicy.SOURCE)
151     public @interface CodeRate {}
152 
153     /**
154      * Code rate undefined.
155      */
156     public static final int CODERATE_UNDEFINED = Constants.FrontendAtsc3CodeRate.UNDEFINED;
157     /**
158      * Hardware is able to detect and set code rate automatically
159      */
160     public static final int CODERATE_AUTO = Constants.FrontendAtsc3CodeRate.AUTO;
161     /**
162      * 2/15 code rate.
163      */
164     public static final int CODERATE_2_15 = Constants.FrontendAtsc3CodeRate.CODERATE_2_15;
165     /**
166      * 3/15 code rate.
167      */
168     public static final int CODERATE_3_15 = Constants.FrontendAtsc3CodeRate.CODERATE_3_15;
169     /**
170      * 4/15 code rate.
171      */
172     public static final int CODERATE_4_15 = Constants.FrontendAtsc3CodeRate.CODERATE_4_15;
173     /**
174      * 5/15 code rate.
175      */
176     public static final int CODERATE_5_15 = Constants.FrontendAtsc3CodeRate.CODERATE_5_15;
177     /**
178      * 6/15 code rate.
179      */
180     public static final int CODERATE_6_15 = Constants.FrontendAtsc3CodeRate.CODERATE_6_15;
181     /**
182      * 7/15 code rate.
183      */
184     public static final int CODERATE_7_15 = Constants.FrontendAtsc3CodeRate.CODERATE_7_15;
185     /**
186      * 8/15 code rate.
187      */
188     public static final int CODERATE_8_15 = Constants.FrontendAtsc3CodeRate.CODERATE_8_15;
189     /**
190      * 9/15 code rate.
191      */
192     public static final int CODERATE_9_15 = Constants.FrontendAtsc3CodeRate.CODERATE_9_15;
193     /**
194      * 10/15 code rate.
195      */
196     public static final int CODERATE_10_15 = Constants.FrontendAtsc3CodeRate.CODERATE_10_15;
197     /**
198      * 11/15 code rate.
199      */
200     public static final int CODERATE_11_15 = Constants.FrontendAtsc3CodeRate.CODERATE_11_15;
201     /**
202      * 12/15 code rate.
203      */
204     public static final int CODERATE_12_15 = Constants.FrontendAtsc3CodeRate.CODERATE_12_15;
205     /**
206      * 13/15 code rate.
207      */
208     public static final int CODERATE_13_15 = Constants.FrontendAtsc3CodeRate.CODERATE_13_15;
209 
210 
211     /** @hide */
212     @IntDef(flag = true,
213             prefix = "FEC_",
214             value = {FEC_UNDEFINED, FEC_AUTO, FEC_BCH_LDPC_16K, FEC_BCH_LDPC_64K, FEC_CRC_LDPC_16K,
215                     FEC_CRC_LDPC_64K, FEC_LDPC_16K, FEC_LDPC_64K})
216     @Retention(RetentionPolicy.SOURCE)
217     public @interface Fec {}
218 
219     /**
220      * Forward Error Correction undefined.
221      */
222     public static final int FEC_UNDEFINED = Constants.FrontendAtsc3Fec.UNDEFINED;
223     /**
224      * Hardware is able to detect and set FEC automatically
225      */
226     public static final int FEC_AUTO = Constants.FrontendAtsc3Fec.AUTO;
227     /**
228      * BCH LDPC 16K Forward Error Correction
229      */
230     public static final int FEC_BCH_LDPC_16K = Constants.FrontendAtsc3Fec.BCH_LDPC_16K;
231     /**
232      * BCH LDPC 64K Forward Error Correction
233      */
234     public static final int FEC_BCH_LDPC_64K = Constants.FrontendAtsc3Fec.BCH_LDPC_64K;
235     /**
236      * CRC LDPC 16K Forward Error Correction
237      */
238     public static final int FEC_CRC_LDPC_16K = Constants.FrontendAtsc3Fec.CRC_LDPC_16K;
239     /**
240      * CRC LDPC 64K Forward Error Correction
241      */
242     public static final int FEC_CRC_LDPC_64K = Constants.FrontendAtsc3Fec.CRC_LDPC_64K;
243     /**
244      * LDPC 16K Forward Error Correction
245      */
246     public static final int FEC_LDPC_16K = Constants.FrontendAtsc3Fec.LDPC_16K;
247     /**
248      * LDPC 64K Forward Error Correction
249      */
250     public static final int FEC_LDPC_64K = Constants.FrontendAtsc3Fec.LDPC_64K;
251 
252 
253     /** @hide */
254     @IntDef(flag = true,
255             prefix = "DEMOD_OUTPUT_FORMAT_",
256             value = {DEMOD_OUTPUT_FORMAT_UNDEFINED, DEMOD_OUTPUT_FORMAT_ATSC3_LINKLAYER_PACKET,
257                     DEMOD_OUTPUT_FORMAT_BASEBAND_PACKET})
258     @Retention(RetentionPolicy.SOURCE)
259     public @interface DemodOutputFormat {}
260 
261     /**
262      * Demod output format undefined.
263      */
264     public static final int DEMOD_OUTPUT_FORMAT_UNDEFINED =
265             Constants.FrontendAtsc3DemodOutputFormat.UNDEFINED;
266     /**
267      * ALP format. Typically used in US region.
268      */
269     public static final int DEMOD_OUTPUT_FORMAT_ATSC3_LINKLAYER_PACKET =
270             Constants.FrontendAtsc3DemodOutputFormat.ATSC3_LINKLAYER_PACKET;
271     /**
272      * BaseBand packet format. Typically used in Korea region.
273      */
274     public static final int DEMOD_OUTPUT_FORMAT_BASEBAND_PACKET =
275             Constants.FrontendAtsc3DemodOutputFormat.BASEBAND_PACKET;
276 
277     private final int mBandwidth;
278     private final int mDemodOutputFormat;
279     private final Atsc3PlpSettings[] mPlpSettings;
280 
Atsc3FrontendSettings(int frequency, int bandwidth, int demodOutputFormat, Atsc3PlpSettings[] plpSettings)281     private Atsc3FrontendSettings(int frequency, int bandwidth, int demodOutputFormat,
282             Atsc3PlpSettings[] plpSettings) {
283         super(frequency);
284         mBandwidth = bandwidth;
285         mDemodOutputFormat = demodOutputFormat;
286         mPlpSettings = plpSettings;
287     }
288 
289     /**
290      * Gets bandwidth.
291      */
292     @Bandwidth
getBandwidth()293     public int getBandwidth() {
294         return mBandwidth;
295     }
296     /**
297      * Gets Demod Output Format.
298      */
299     @DemodOutputFormat
getDemodOutputFormat()300     public int getDemodOutputFormat() {
301         return mDemodOutputFormat;
302     }
303     /**
304      * Gets PLP Settings.
305      */
306     @NonNull
getPlpSettings()307     public Atsc3PlpSettings[] getPlpSettings() {
308         return mPlpSettings;
309     }
310 
311     /**
312      * Creates a builder for {@link Atsc3FrontendSettings}.
313      *
314      */
315     @NonNull
builder()316     public static Builder builder() {
317         return new Builder();
318     }
319 
320     /**
321      * Builder for {@link Atsc3FrontendSettings}.
322      */
323     public static class Builder {
324         private int mFrequency = 0;
325         private int mBandwidth = BANDWIDTH_UNDEFINED;
326         private int mDemodOutputFormat = DEMOD_OUTPUT_FORMAT_UNDEFINED;
327         private Atsc3PlpSettings[] mPlpSettings = {};
328 
Builder()329         private Builder() {
330         }
331 
332         /**
333          * Sets frequency in Hz.
334          *
335          * <p>Default value is 0.
336          */
337         @NonNull
338         @IntRange(from = 1)
setFrequency(int frequency)339         public Builder setFrequency(int frequency) {
340             mFrequency = frequency;
341             return this;
342         }
343 
344         /**
345          * Sets bandwidth.
346          *
347          * <p>Default value is {@link #BANDWIDTH_UNDEFINED}.
348          */
349         @NonNull
setBandwidth(int bandwidth)350         public Builder setBandwidth(int bandwidth) {
351             mBandwidth = bandwidth;
352             return this;
353         }
354         /**
355          * Sets Demod Output Format.
356          *
357          * <p>Default value is {@link #DEMOD_OUTPUT_FORMAT_UNDEFINED}.
358          */
359         @NonNull
setDemodOutputFormat(@emodOutputFormat int demodOutputFormat)360         public Builder setDemodOutputFormat(@DemodOutputFormat int demodOutputFormat) {
361             mDemodOutputFormat = demodOutputFormat;
362             return this;
363         }
364         /**
365          * Sets PLP Settings.
366          *
367          * <p>Default value an empty array.
368          */
369         @NonNull
setPlpSettings(@onNull Atsc3PlpSettings[] plpSettings)370         public Builder setPlpSettings(@NonNull Atsc3PlpSettings[] plpSettings) {
371             mPlpSettings = plpSettings;
372             return this;
373         }
374 
375         /**
376          * Builds a {@link Atsc3FrontendSettings} object.
377          */
378         @NonNull
build()379         public Atsc3FrontendSettings build() {
380             return new Atsc3FrontendSettings(
381                 mFrequency, mBandwidth, mDemodOutputFormat, mPlpSettings);
382         }
383     }
384 
385     @Override
getType()386     public int getType() {
387         return FrontendSettings.TYPE_ATSC3;
388     }
389 }
390