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.filter;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.media.tv.tuner.TunerUtils;
23 import android.media.tv.tuner.TunerVersionChecker;
24 
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 
28 /**
29  * Filter Settings for a Video and Audio.
30  *
31  * @hide
32  */
33 @SystemApi
34 public class AvSettings extends Settings {
35     /** @hide */
36     @IntDef(prefix = "VIDEO_STREAM_TYPE_",
37             value = {VIDEO_STREAM_TYPE_UNDEFINED, VIDEO_STREAM_TYPE_RESERVED,
38                     VIDEO_STREAM_TYPE_MPEG1, VIDEO_STREAM_TYPE_MPEG2,
39                     VIDEO_STREAM_TYPE_MPEG4P2, VIDEO_STREAM_TYPE_AVC, VIDEO_STREAM_TYPE_HEVC,
40                     VIDEO_STREAM_TYPE_VC1, VIDEO_STREAM_TYPE_VP8, VIDEO_STREAM_TYPE_VP9,
41                     VIDEO_STREAM_TYPE_AV1, VIDEO_STREAM_TYPE_AVS, VIDEO_STREAM_TYPE_AVS2,
42                     VIDEO_STREAM_TYPE_VVC})
43     @Retention(RetentionPolicy.SOURCE)
44     public @interface VideoStreamType {}
45 
46     /*
47      * Undefined Video stream type
48      */
49     public static final int VIDEO_STREAM_TYPE_UNDEFINED =
50             android.hardware.tv.tuner.VideoStreamType.UNDEFINED;
51     /*
52      * ITU-T | ISO/IEC Reserved
53      */
54     public static final int VIDEO_STREAM_TYPE_RESERVED =
55             android.hardware.tv.tuner.VideoStreamType.RESERVED;
56     /*
57      * ISO/IEC 11172
58      */
59     public static final int VIDEO_STREAM_TYPE_MPEG1 =
60             android.hardware.tv.tuner.VideoStreamType.MPEG1;
61     /*
62      * ITU-T Rec.H.262 and ISO/IEC 13818-2
63      */
64     public static final int VIDEO_STREAM_TYPE_MPEG2 =
65             android.hardware.tv.tuner.VideoStreamType.MPEG2;
66     /*
67      * ISO/IEC 14496-2 (MPEG-4 H.263 based video)
68      */
69     public static final int VIDEO_STREAM_TYPE_MPEG4P2 =
70             android.hardware.tv.tuner.VideoStreamType.MPEG4P2;
71     /*
72      * ITU-T Rec.H.264 and ISO/IEC 14496-10
73      */
74     public static final int VIDEO_STREAM_TYPE_AVC = android.hardware.tv.tuner.VideoStreamType.AVC;
75     /*
76      * ITU-T Rec. H.265 and ISO/IEC 23008-2
77      */
78     public static final int VIDEO_STREAM_TYPE_HEVC = android.hardware.tv.tuner.VideoStreamType.HEVC;
79     /*
80      * ITU-T Rec. H.266 and ISO/IEC 23090-3
81      */
82     public static final int VIDEO_STREAM_TYPE_VVC = android.hardware.tv.tuner.VideoStreamType.VVC;
83     /*
84      * Microsoft VC.1
85      */
86     public static final int VIDEO_STREAM_TYPE_VC1 = android.hardware.tv.tuner.VideoStreamType.VC1;
87     /*
88      * Google VP8
89      */
90     public static final int VIDEO_STREAM_TYPE_VP8 = android.hardware.tv.tuner.VideoStreamType.VP8;
91     /*
92      * Google VP9
93      */
94     public static final int VIDEO_STREAM_TYPE_VP9 = android.hardware.tv.tuner.VideoStreamType.VP9;
95     /*
96      * AOMedia Video 1
97      */
98     public static final int VIDEO_STREAM_TYPE_AV1 = android.hardware.tv.tuner.VideoStreamType.AV1;
99     /*
100      * Chinese Standard
101      */
102     public static final int VIDEO_STREAM_TYPE_AVS = android.hardware.tv.tuner.VideoStreamType.AVS;
103     /*
104      * New Chinese Standard
105      */
106     public static final int VIDEO_STREAM_TYPE_AVS2 = android.hardware.tv.tuner.VideoStreamType.AVS2;
107 
108     /** @hide */
109     @IntDef(prefix = "AUDIO_STREAM_TYPE_",
110             value = {AUDIO_STREAM_TYPE_UNDEFINED, AUDIO_STREAM_TYPE_PCM, AUDIO_STREAM_TYPE_MP3,
111                     AUDIO_STREAM_TYPE_MPEG1, AUDIO_STREAM_TYPE_MPEG2, AUDIO_STREAM_TYPE_MPEGH,
112                     AUDIO_STREAM_TYPE_AAC, AUDIO_STREAM_TYPE_AC3, AUDIO_STREAM_TYPE_EAC3,
113                     AUDIO_STREAM_TYPE_AC4, AUDIO_STREAM_TYPE_DTS, AUDIO_STREAM_TYPE_DTS_HD,
114                     AUDIO_STREAM_TYPE_WMA, AUDIO_STREAM_TYPE_OPUS, AUDIO_STREAM_TYPE_VORBIS,
115                     AUDIO_STREAM_TYPE_DRA, AUDIO_STREAM_TYPE_AAC_ADTS, AUDIO_STREAM_TYPE_AAC_LATM,
116                     AUDIO_STREAM_TYPE_AAC_HE_ADTS, AUDIO_STREAM_TYPE_AAC_HE_LATM})
117     @Retention(RetentionPolicy.SOURCE)
118     public @interface AudioStreamType {}
119 
120     /*
121      * Undefined Audio stream type
122      */
123     public static final int AUDIO_STREAM_TYPE_UNDEFINED =
124             android.hardware.tv.tuner.AudioStreamType.UNDEFINED;
125     /*
126      * Uncompressed Audio
127      */
128     public static final int AUDIO_STREAM_TYPE_PCM = android.hardware.tv.tuner.AudioStreamType.PCM;
129     /*
130      * MPEG Audio Layer III versions
131      */
132     public static final int AUDIO_STREAM_TYPE_MP3 = android.hardware.tv.tuner.AudioStreamType.MP3;
133     /*
134      * ISO/IEC 11172 Audio
135      */
136     public static final int AUDIO_STREAM_TYPE_MPEG1 =
137             android.hardware.tv.tuner.AudioStreamType.MPEG1;
138     /*
139      * ISO/IEC 13818-3
140      */
141     public static final int AUDIO_STREAM_TYPE_MPEG2 =
142             android.hardware.tv.tuner.AudioStreamType.MPEG2;
143     /*
144      * ISO/IEC 23008-3 (MPEG-H Part 3)
145      */
146     public static final int AUDIO_STREAM_TYPE_MPEGH =
147             android.hardware.tv.tuner.AudioStreamType.MPEGH;
148     /*
149      * ISO/IEC 14496-3
150      */
151     public static final int AUDIO_STREAM_TYPE_AAC = android.hardware.tv.tuner.AudioStreamType.AAC;
152     /*
153      * Dolby Digital
154      */
155     public static final int AUDIO_STREAM_TYPE_AC3 = android.hardware.tv.tuner.AudioStreamType.AC3;
156     /*
157      * Dolby Digital Plus
158      */
159     public static final int AUDIO_STREAM_TYPE_EAC3 = android.hardware.tv.tuner.AudioStreamType.EAC3;
160     /*
161      * Dolby AC-4
162      */
163     public static final int AUDIO_STREAM_TYPE_AC4 = android.hardware.tv.tuner.AudioStreamType.AC4;
164     /*
165      * Basic DTS
166      */
167     public static final int AUDIO_STREAM_TYPE_DTS = android.hardware.tv.tuner.AudioStreamType.DTS;
168     /*
169      * High Resolution DTS
170      */
171     public static final int AUDIO_STREAM_TYPE_DTS_HD =
172             android.hardware.tv.tuner.AudioStreamType.DTS_HD;
173     /*
174      * Windows Media Audio
175      */
176     public static final int AUDIO_STREAM_TYPE_WMA = android.hardware.tv.tuner.AudioStreamType.WMA;
177     /*
178      * Opus Interactive Audio Codec
179      */
180     public static final int AUDIO_STREAM_TYPE_OPUS = android.hardware.tv.tuner.AudioStreamType.OPUS;
181     /*
182      * VORBIS Interactive Audio Codec
183      */
184     public static final int AUDIO_STREAM_TYPE_VORBIS =
185             android.hardware.tv.tuner.AudioStreamType.VORBIS;
186     /*
187      * SJ/T 11368-2006
188      */
189     public static final int AUDIO_STREAM_TYPE_DRA = android.hardware.tv.tuner.AudioStreamType.DRA;
190 
191     /*
192      * AAC with ADTS (Audio Data Transport Format).
193      *
194      * This API is only supported by Tuner HAL 2.0 or higher. Use
195      * {@link TunerVersionChecker#getTunerVersion()} to check the version.
196      */
197     public static final int AUDIO_STREAM_TYPE_AAC_ADTS =
198             android.hardware.tv.tuner.AudioStreamType.AAC_ADTS;
199 
200     /*
201      * AAC with ADTS with LATM (Low-overhead MPEG-4 Audio Transport Multiplex).
202      *
203      * This API is only supported by Tuner HAL 2.0 or higher. Use
204      * {@link TunerVersionChecker#getTunerVersion()} to check the version.
205      */
206     public static final int AUDIO_STREAM_TYPE_AAC_LATM =
207             android.hardware.tv.tuner.AudioStreamType.AAC_LATM;
208 
209     /*
210      * High-Efficiency AAC (HE-AAC) with ADTS (Audio Data Transport Format).
211      *
212      * This API is only supported by Tuner HAL 2.0 or higher. Use
213      * {@link TunerVersionChecker#getTunerVersion()} to check the version.
214      */
215     public static final int AUDIO_STREAM_TYPE_AAC_HE_ADTS =
216             android.hardware.tv.tuner.AudioStreamType.AAC_HE_ADTS;
217 
218     /*
219      * High-Efficiency AAC (HE-AAC) with LATM (Low-overhead MPEG-4 Audio Transport Multiplex).
220      *
221      * This API is only supported by Tuner HAL 2.0 or higher. Use
222      * {@link TunerVersionChecker#getTunerVersion()} to check the version.
223      */
224     public static final int AUDIO_STREAM_TYPE_AAC_HE_LATM =
225             android.hardware.tv.tuner.AudioStreamType.AAC_HE_LATM;
226 
227     private final boolean mIsPassthrough;
228     private int mAudioStreamType = AUDIO_STREAM_TYPE_UNDEFINED;
229     private int mVideoStreamType = VIDEO_STREAM_TYPE_UNDEFINED;
230     private final boolean mUseSecureMemory;
231 
AvSettings(int mainType, boolean isAudio, boolean isPassthrough, int audioStreamType, int videoStreamType, boolean useSecureMemory)232     private AvSettings(int mainType, boolean isAudio, boolean isPassthrough, int audioStreamType,
233             int videoStreamType, boolean useSecureMemory) {
234         super(TunerUtils.getFilterSubtype(
235                 mainType,
236                 isAudio
237                         ? Filter.SUBTYPE_AUDIO
238                         : Filter.SUBTYPE_VIDEO));
239         mIsPassthrough = isPassthrough;
240         mAudioStreamType = audioStreamType;
241         mVideoStreamType = videoStreamType;
242         mUseSecureMemory = useSecureMemory;
243     }
244 
245     /**
246      * Checks whether it's passthrough.
247      */
isPassthrough()248     public boolean isPassthrough() {
249         return mIsPassthrough;
250     }
251 
252     /**
253      * Get the Audio Stream Type.
254      */
255     @AudioStreamType
getAudioStreamType()256     public int getAudioStreamType() {
257         return mAudioStreamType;
258     }
259 
260     /**
261      * Get the Video Stream Type.
262      */
263     @VideoStreamType
getVideoStreamType()264     public int getVideoStreamType() {
265         return mVideoStreamType;
266     }
267 
268     /**
269      * Checks whether secure memory is used.
270      *
271      * <p>This query is only supported by Tuner HAL 2.0 or higher. The return value on HAL 1.1 and
272      * lower is undefined. Use {@link TunerVersionChecker#getTunerVersion()} to check the version.
273      */
useSecureMemory()274     public boolean useSecureMemory() {
275         return mUseSecureMemory;
276     }
277 
278     /**
279      * Creates a builder for {@link AvSettings}.
280      *
281      * @param mainType the filter main type.
282      * @param isAudio {@code true} if it's audio settings; {@code false} if it's video settings.
283      */
284     @NonNull
builder(@ilter.Type int mainType, boolean isAudio)285     public static Builder builder(@Filter.Type int mainType, boolean isAudio) {
286         return new Builder(mainType, isAudio);
287     }
288 
289     /**
290      * Builder for {@link AvSettings}.
291      */
292     public static class Builder {
293         private final int mMainType;
294         private final boolean mIsAudio;
295         private boolean mIsPassthrough = false;
296         private int mAudioStreamType = AUDIO_STREAM_TYPE_UNDEFINED;
297         private int mVideoStreamType = VIDEO_STREAM_TYPE_UNDEFINED;
298         boolean mUseSecureMemory = false;
299 
Builder(int mainType, boolean isAudio)300         private Builder(int mainType, boolean isAudio) {
301             mMainType = mainType;
302             mIsAudio = isAudio;
303         }
304 
305         /**
306          * Sets whether it's passthrough.
307          *
308          * <p>Default value is {@code false}.
309          */
310         @NonNull
setPassthrough(boolean isPassthrough)311         public Builder setPassthrough(boolean isPassthrough) {
312             mIsPassthrough = isPassthrough;
313             return this;
314         }
315 
316         /**
317          * Sets the Audio Stream Type.
318          *
319          * <p>This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause
320          * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version.
321          *
322          * <p>Default is {@link #AUDIO_STREAM_TYPE_UNDEFINED}.
323          *
324          * @param audioStreamType the audio stream type to set.
325          */
326         @NonNull
setAudioStreamType(@udioStreamType int audioStreamType)327         public Builder setAudioStreamType(@AudioStreamType int audioStreamType) {
328             if (TunerVersionChecker.checkHigherOrEqualVersionTo(
329                     TunerVersionChecker.TUNER_VERSION_1_1, "setAudioStreamType") && mIsAudio) {
330                 mAudioStreamType = audioStreamType;
331                 mVideoStreamType = VIDEO_STREAM_TYPE_UNDEFINED;
332             }
333             return this;
334         }
335 
336         /**
337          * Sets the Video Stream Type.
338          *
339          * <p>This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause
340          * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version.
341          *
342          * <p>Default value is {@link #VIDEO_STREAM_TYPE_UNDEFINED}.
343          *
344          * @param videoStreamType the video stream type to set.
345          */
346         @NonNull
setVideoStreamType(@ideoStreamType int videoStreamType)347         public Builder setVideoStreamType(@VideoStreamType int videoStreamType) {
348             if (TunerVersionChecker.checkHigherOrEqualVersionTo(
349                     TunerVersionChecker.TUNER_VERSION_1_1, "setVideoStreamType") && !mIsAudio) {
350                 mVideoStreamType = videoStreamType;
351                 mAudioStreamType = AUDIO_STREAM_TYPE_UNDEFINED;
352             }
353             return this;
354         }
355 
356         /**
357          * Sets whether secure memory should be used.
358          *
359          * <p>This API is only supported by Tuner HAL 2.0 or higher. Unsupported version would cause
360          * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version.
361          *
362          * <p>Default value is {@code false}.
363          */
364         @NonNull
setUseSecureMemory(boolean useSecureMemory)365         public Builder setUseSecureMemory(boolean useSecureMemory) {
366             if (TunerVersionChecker.checkHigherOrEqualVersionTo(
367                         TunerVersionChecker.TUNER_VERSION_2_0, "setSecureMemory")) {
368                 mUseSecureMemory = useSecureMemory;
369             }
370             return this;
371         }
372 
373         /**
374          * Builds a {@link AvSettings} object.
375          */
376         @NonNull
build()377         public AvSettings build() {
378             return new AvSettings(mMainType, mIsAudio, mIsPassthrough, mAudioStreamType,
379                     mVideoStreamType, mUseSecureMemory);
380         }
381     }
382 }
383