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.FrontendIsdbsCoderate;
24 import android.hardware.tv.tuner.FrontendIsdbsModulation;
25 import android.hardware.tv.tuner.FrontendIsdbsRolloff;
26 import android.hardware.tv.tuner.FrontendIsdbsStreamIdType;
27 import android.media.tv.tuner.Tuner;
28 
29 import java.lang.annotation.Retention;
30 import java.lang.annotation.RetentionPolicy;
31 
32 /**
33  * Frontend settings for ISDBS.
34  *
35  * @hide
36  */
37 @SystemApi
38 public class IsdbsFrontendSettings extends FrontendSettings {
39     /** @hide */
40     @Retention(RetentionPolicy.SOURCE)
41     @IntDef(prefix = "STREAM_ID_TYPE_",
42             value = {STREAM_ID_TYPE_ID, STREAM_ID_TYPE_RELATIVE_NUMBER})
43     public @interface StreamIdType {}
44 
45     /**
46      * Uses stream ID.
47      */
48     public static final int STREAM_ID_TYPE_ID = FrontendIsdbsStreamIdType.STREAM_ID;
49     /**
50      * Uses relative number.
51      */
52     public static final int STREAM_ID_TYPE_RELATIVE_NUMBER =
53             FrontendIsdbsStreamIdType.RELATIVE_STREAM_NUMBER;
54 
55 
56     /** @hide */
57     @IntDef(prefix = "MODULATION_",
58             value = {MODULATION_UNDEFINED, MODULATION_AUTO, MODULATION_MOD_BPSK,
59                     MODULATION_MOD_QPSK, MODULATION_MOD_TC8PSK})
60     @Retention(RetentionPolicy.SOURCE)
61     public @interface Modulation {}
62 
63     /**
64      * Modulation undefined.
65      */
66     public static final int MODULATION_UNDEFINED = FrontendIsdbsModulation.UNDEFINED;
67     /**
68      * Hardware is able to detect and set modulation automatically
69      */
70     public static final int MODULATION_AUTO = FrontendIsdbsModulation.AUTO;
71     /**
72      * BPSK Modulation.
73      */
74     public static final int MODULATION_MOD_BPSK = FrontendIsdbsModulation.MOD_BPSK;
75     /**
76      * QPSK Modulation.
77      */
78     public static final int MODULATION_MOD_QPSK = FrontendIsdbsModulation.MOD_QPSK;
79     /**
80      * TC8PSK Modulation.
81      */
82     public static final int MODULATION_MOD_TC8PSK = FrontendIsdbsModulation.MOD_TC8PSK;
83 
84 
85     /** @hide */
86     @IntDef(prefix = "CODERATE_",
87             value = {CODERATE_UNDEFINED, CODERATE_AUTO, CODERATE_1_2, CODERATE_2_3, CODERATE_3_4,
88                     CODERATE_5_6, CODERATE_7_8})
89     @Retention(RetentionPolicy.SOURCE)
90     public @interface CodeRate {}
91 
92     /**
93      * Code rate undefined.
94      */
95     public static final int CODERATE_UNDEFINED = FrontendIsdbsCoderate.UNDEFINED;
96     /**
97      * Hardware is able to detect and set code rate automatically.
98      */
99     public static final int CODERATE_AUTO = FrontendIsdbsCoderate.AUTO;
100     /**
101      * 1/2 code rate.
102      */
103     public static final int CODERATE_1_2 = FrontendIsdbsCoderate.CODERATE_1_2;
104     /**
105      * 2/3 code rate.
106      */
107     public static final int CODERATE_2_3 = FrontendIsdbsCoderate.CODERATE_2_3;
108     /**
109      * 3/4 code rate.
110      */
111     public static final int CODERATE_3_4 = FrontendIsdbsCoderate.CODERATE_3_4;
112     /**
113      * 5/6 code rate.
114      */
115     public static final int CODERATE_5_6 = FrontendIsdbsCoderate.CODERATE_5_6;
116     /**
117      * 7/8 code rate.
118      */
119     public static final int CODERATE_7_8 = FrontendIsdbsCoderate.CODERATE_7_8;
120 
121     /** @hide */
122     @Retention(RetentionPolicy.SOURCE)
123     @IntDef(prefix = "ROLLOFF_",
124             value = {ROLLOFF_UNDEFINED, ROLLOFF_0_35})
125     public @interface Rolloff {}
126 
127     /**
128      * Rolloff type undefined.
129      */
130     public static final int ROLLOFF_UNDEFINED = FrontendIsdbsRolloff.UNDEFINED;
131     /**
132      * 0,35 rolloff.
133      */
134     public static final int ROLLOFF_0_35 = FrontendIsdbsRolloff.ROLLOFF_0_35;
135 
136 
137     private final int mStreamId;
138     private final int mStreamIdType;
139     private final int mModulation;
140     private final int mCodeRate;
141     private final int mSymbolRate;
142     private final int mRolloff;
143 
IsdbsFrontendSettings(long frequency, int streamId, int streamIdType, int modulation, int codeRate, int symbolRate, int rolloff)144     private IsdbsFrontendSettings(long frequency, int streamId, int streamIdType, int modulation,
145             int codeRate, int symbolRate, int rolloff) {
146         super(frequency);
147         mStreamId = streamId;
148         mStreamIdType = streamIdType;
149         mModulation = modulation;
150         mCodeRate = codeRate;
151         mSymbolRate = symbolRate;
152         mRolloff = rolloff;
153     }
154 
155     /**
156      * Gets Stream ID.
157      */
getStreamId()158     public int getStreamId() {
159         return mStreamId;
160     }
161     /**
162      * Gets Stream ID Type.
163      */
164     @StreamIdType
getStreamIdType()165     public int getStreamIdType() {
166         return mStreamIdType;
167     }
168     /**
169      * Gets Modulation.
170      */
171     @Modulation
getModulation()172     public int getModulation() {
173         return mModulation;
174     }
175     /**
176      * Gets Code rate.
177      */
178     @CodeRate
getCodeRate()179     public int getCodeRate() {
180         return mCodeRate;
181     }
182     /**
183      * Gets Symbol Rate in symbols per second.
184      */
getSymbolRate()185     public int getSymbolRate() {
186         return mSymbolRate;
187     }
188     /**
189      * Gets Roll off type.
190      */
191     @Rolloff
getRolloff()192     public int getRolloff() {
193         return mRolloff;
194     }
195 
196     /**
197      * Creates a builder for {@link IsdbsFrontendSettings}.
198      */
199     @NonNull
builder()200     public static Builder builder() {
201         return new Builder();
202     }
203 
204     /**
205      * Builder for {@link IsdbsFrontendSettings}.
206      */
207     public static class Builder {
208         private long mFrequency = 0;
209         private int mStreamId = Tuner.INVALID_STREAM_ID;
210         private int mStreamIdType = STREAM_ID_TYPE_ID;
211         private int mModulation = MODULATION_UNDEFINED;
212         private int mCodeRate = CODERATE_UNDEFINED;
213         private int mSymbolRate = 0;
214         private int mRolloff = ROLLOFF_UNDEFINED;
215 
Builder()216         private Builder() {
217         }
218 
219         /**
220          * Sets frequency in Hz.
221          *
222          * <p>Default value is 0.
223          * @deprecated Use {@link #setFrequencyLong(long)}
224          */
225         @NonNull
226         @IntRange(from = 1)
227         @Deprecated
setFrequency(int frequency)228         public Builder setFrequency(int frequency) {
229             return setFrequencyLong((long) frequency);
230         }
231 
232         /**
233          * Sets frequency in Hz.
234          *
235          * <p>Default value is 0.
236          */
237         @NonNull
238         @IntRange(from = 1)
setFrequencyLong(long frequency)239         public Builder setFrequencyLong(long frequency) {
240             mFrequency = frequency;
241             return this;
242         }
243 
244         /**
245          * Sets Stream ID.
246          *
247          * <p>Default value is {@link Tuner#INVALID_STREAM_ID}.
248          */
249         @NonNull
setStreamId(int streamId)250         public Builder setStreamId(int streamId) {
251             mStreamId = streamId;
252             return this;
253         }
254         /**
255          * Sets StreamIdType.
256          *
257          * <p>Default value is {@link #STREAM_ID_TYPE_ID}.
258          */
259         @NonNull
setStreamIdType(@treamIdType int streamIdType)260         public Builder setStreamIdType(@StreamIdType int streamIdType) {
261             mStreamIdType = streamIdType;
262             return this;
263         }
264         /**
265          * Sets Modulation.
266          *
267          * <p>Default value is {@link #MODULATION_UNDEFINED}.
268          */
269         @NonNull
setModulation(@odulation int modulation)270         public Builder setModulation(@Modulation int modulation) {
271             mModulation = modulation;
272             return this;
273         }
274         /**
275          * Sets Code rate.
276          *
277          * <p>Default value is {@link #CODERATE_UNDEFINED}.
278          */
279         @NonNull
setCodeRate(@odeRate int codeRate)280         public Builder setCodeRate(@CodeRate int codeRate) {
281             mCodeRate = codeRate;
282             return this;
283         }
284         /**
285          * Sets Symbol Rate in symbols per second.
286          *
287          * <p>Default value is 0.
288          */
289         @NonNull
setSymbolRate(int symbolRate)290         public Builder setSymbolRate(int symbolRate) {
291             mSymbolRate = symbolRate;
292             return this;
293         }
294         /**
295          * Sets Roll off type.
296          *
297          * <p>Default value is {@link #ROLLOFF_UNDEFINED}.
298          */
299         @NonNull
setRolloff(@olloff int rolloff)300         public Builder setRolloff(@Rolloff int rolloff) {
301             mRolloff = rolloff;
302             return this;
303         }
304 
305         /**
306          * Builds a {@link IsdbsFrontendSettings} object.
307          */
308         @NonNull
build()309         public IsdbsFrontendSettings build() {
310             return new IsdbsFrontendSettings(mFrequency, mStreamId, mStreamIdType, mModulation,
311                     mCodeRate, mSymbolRate, mRolloff);
312         }
313     }
314 
315     @Override
getType()316     public int getType() {
317         return FrontendSettings.TYPE_ISDBS;
318     }
319 }
320