• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.hardware.tv.tuner.V1_1.Constants;
23 import android.media.tv.tuner.TunerUtils;
24 import android.media.tv.tuner.TunerVersionChecker;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 
29 /**
30  * Filter Settings for a Video and Audio.
31  *
32  * @hide
33  */
34 @SystemApi
35 public class AvSettings extends Settings {
36     /** @hide */
37     @IntDef(prefix = "VIDEO_STREAM_TYPE_",
38             value = {VIDEO_STREAM_TYPE_UNDEFINED, VIDEO_STREAM_TYPE_RESERVED,
39                     VIDEO_STREAM_TYPE_MPEG1, VIDEO_STREAM_TYPE_MPEG2,
40                     VIDEO_STREAM_TYPE_MPEG4P2, VIDEO_STREAM_TYPE_AVC, VIDEO_STREAM_TYPE_HEVC,
41                     VIDEO_STREAM_TYPE_VC1, VIDEO_STREAM_TYPE_VP8, VIDEO_STREAM_TYPE_VP9,
42                     VIDEO_STREAM_TYPE_AV1, VIDEO_STREAM_TYPE_AVS, VIDEO_STREAM_TYPE_AVS2})
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 = Constants.VideoStreamType.UNDEFINED;
50     /*
51      * ITU-T | ISO/IEC Reserved
52      */
53     public static final int VIDEO_STREAM_TYPE_RESERVED = Constants.VideoStreamType.RESERVED;
54     /*
55      * ISO/IEC 11172
56      */
57     public static final int VIDEO_STREAM_TYPE_MPEG1 = Constants.VideoStreamType.MPEG1;
58     /*
59      * ITU-T Rec.H.262 and ISO/IEC 13818-2
60      */
61     public static final int VIDEO_STREAM_TYPE_MPEG2 = Constants.VideoStreamType.MPEG2;
62     /*
63      * ISO/IEC 14496-2 (MPEG-4 H.263 based video)
64      */
65     public static final int VIDEO_STREAM_TYPE_MPEG4P2 = Constants.VideoStreamType.MPEG4P2;
66     /*
67      * ITU-T Rec.H.264 and ISO/IEC 14496-10
68      */
69     public static final int VIDEO_STREAM_TYPE_AVC = Constants.VideoStreamType.AVC;
70     /*
71      * ITU-T Rec. H.265 and ISO/IEC 23008-2
72      */
73     public static final int VIDEO_STREAM_TYPE_HEVC = Constants.VideoStreamType.HEVC;
74     /*
75      * Microsoft VC.1
76      */
77     public static final int VIDEO_STREAM_TYPE_VC1 = Constants.VideoStreamType.VC1;
78     /*
79      * Google VP8
80      */
81     public static final int VIDEO_STREAM_TYPE_VP8 = Constants.VideoStreamType.VP8;
82     /*
83      * Google VP9
84      */
85     public static final int VIDEO_STREAM_TYPE_VP9 = Constants.VideoStreamType.VP9;
86     /*
87      * AOMedia Video 1
88      */
89     public static final int VIDEO_STREAM_TYPE_AV1 = Constants.VideoStreamType.AV1;
90     /*
91      * Chinese Standard
92      */
93     public static final int VIDEO_STREAM_TYPE_AVS = Constants.VideoStreamType.AVS;
94     /*
95      * New Chinese Standard
96      */
97     public static final int VIDEO_STREAM_TYPE_AVS2 = Constants.VideoStreamType.AVS2;
98 
99     /** @hide */
100     @IntDef(prefix = "AUDIO_STREAM_TYPE_",
101             value = {AUDIO_STREAM_TYPE_UNDEFINED, AUDIO_STREAM_TYPE_PCM, AUDIO_STREAM_TYPE_MP3,
102                     AUDIO_STREAM_TYPE_MPEG1, AUDIO_STREAM_TYPE_MPEG2, AUDIO_STREAM_TYPE_MPEGH,
103                     AUDIO_STREAM_TYPE_AAC, AUDIO_STREAM_TYPE_AC3, AUDIO_STREAM_TYPE_EAC3,
104                     AUDIO_STREAM_TYPE_AC4, AUDIO_STREAM_TYPE_DTS, AUDIO_STREAM_TYPE_DTS_HD,
105                     AUDIO_STREAM_TYPE_WMA, AUDIO_STREAM_TYPE_OPUS, AUDIO_STREAM_TYPE_VORBIS,
106                     AUDIO_STREAM_TYPE_DRA})
107     @Retention(RetentionPolicy.SOURCE)
108     public @interface AudioStreamType {}
109 
110     /*
111      * Undefined Audio stream type
112      */
113     public static final int AUDIO_STREAM_TYPE_UNDEFINED = Constants.AudioStreamType.UNDEFINED;
114     /*
115      * Uncompressed Audio
116      */
117     public static final int AUDIO_STREAM_TYPE_PCM = Constants.AudioStreamType.PCM;
118     /*
119      * MPEG Audio Layer III versions
120      */
121     public static final int AUDIO_STREAM_TYPE_MP3 = Constants.AudioStreamType.MP3;
122     /*
123      * ISO/IEC 11172 Audio
124      */
125     public static final int AUDIO_STREAM_TYPE_MPEG1 = Constants.AudioStreamType.MPEG1;
126     /*
127      * ISO/IEC 13818-3
128      */
129     public static final int AUDIO_STREAM_TYPE_MPEG2 = Constants.AudioStreamType.MPEG2;
130     /*
131      * ISO/IEC 23008-3 (MPEG-H Part 3)
132      */
133     public static final int AUDIO_STREAM_TYPE_MPEGH = Constants.AudioStreamType.MPEGH;
134     /*
135      * ISO/IEC 14496-3
136      */
137     public static final int AUDIO_STREAM_TYPE_AAC = Constants.AudioStreamType.AAC;
138     /*
139      * Dolby Digital
140      */
141     public static final int AUDIO_STREAM_TYPE_AC3 = Constants.AudioStreamType.AC3;
142     /*
143      * Dolby Digital Plus
144      */
145     public static final int AUDIO_STREAM_TYPE_EAC3 = Constants.AudioStreamType.EAC3;
146     /*
147      * Dolby AC-4
148      */
149     public static final int AUDIO_STREAM_TYPE_AC4 = Constants.AudioStreamType.AC4;
150     /*
151      * Basic DTS
152      */
153     public static final int AUDIO_STREAM_TYPE_DTS = Constants.AudioStreamType.DTS;
154     /*
155      * High Resolution DTS
156      */
157     public static final int AUDIO_STREAM_TYPE_DTS_HD = Constants.AudioStreamType.DTS_HD;
158     /*
159      * Windows Media Audio
160      */
161     public static final int AUDIO_STREAM_TYPE_WMA = Constants.AudioStreamType.WMA;
162     /*
163      * Opus Interactive Audio Codec
164      */
165     public static final int AUDIO_STREAM_TYPE_OPUS = Constants.AudioStreamType.OPUS;
166     /*
167      * VORBIS Interactive Audio Codec
168      */
169     public static final int AUDIO_STREAM_TYPE_VORBIS = Constants.AudioStreamType.VORBIS;
170     /*
171      * SJ/T 11368-2006
172      */
173     public static final int AUDIO_STREAM_TYPE_DRA = Constants.AudioStreamType.DRA;
174 
175 
176     private final boolean mIsPassthrough;
177     private int mAudioStreamType = AUDIO_STREAM_TYPE_UNDEFINED;
178     private int mVideoStreamType = VIDEO_STREAM_TYPE_UNDEFINED;
179 
AvSettings(int mainType, boolean isAudio, boolean isPassthrough, int audioStreamType, int videoStreamType)180     private AvSettings(int mainType, boolean isAudio, boolean isPassthrough,
181             int audioStreamType, int videoStreamType) {
182         super(TunerUtils.getFilterSubtype(
183                 mainType,
184                 isAudio
185                         ? Filter.SUBTYPE_AUDIO
186                         : Filter.SUBTYPE_VIDEO));
187         mIsPassthrough = isPassthrough;
188         mAudioStreamType = audioStreamType;
189         mVideoStreamType = videoStreamType;
190     }
191 
192     /**
193      * Checks whether it's passthrough.
194      */
isPassthrough()195     public boolean isPassthrough() {
196         return mIsPassthrough;
197     }
198 
199     /**
200      * Get the Audio Stream Type.
201      */
202     @AudioStreamType
getAudioStreamType()203     public int getAudioStreamType() {
204         return mAudioStreamType;
205     }
206 
207     /**
208      * Get the Video Stream Type.
209      */
210     @VideoStreamType
getVideoStreamType()211     public int getVideoStreamType() {
212         return mVideoStreamType;
213     }
214 
215     /**
216      * Creates a builder for {@link AvSettings}.
217      *
218      * @param mainType the filter main type.
219      * @param isAudio {@code true} if it's audio settings; {@code false} if it's video settings.
220      */
221     @NonNull
builder(@ilter.Type int mainType, boolean isAudio)222     public static Builder builder(@Filter.Type int mainType, boolean isAudio) {
223         return new Builder(mainType, isAudio);
224     }
225 
226     /**
227      * Builder for {@link AvSettings}.
228      */
229     public static class Builder {
230         private final int mMainType;
231         private final boolean mIsAudio;
232         private boolean mIsPassthrough;
233         private int mAudioStreamType = AUDIO_STREAM_TYPE_UNDEFINED;
234         private int mVideoStreamType = VIDEO_STREAM_TYPE_UNDEFINED;
235 
Builder(int mainType, boolean isAudio)236         private Builder(int mainType, boolean isAudio) {
237             mMainType = mainType;
238             mIsAudio = isAudio;
239         }
240 
241         /**
242          * Sets whether it's passthrough.
243          */
244         @NonNull
setPassthrough(boolean isPassthrough)245         public Builder setPassthrough(boolean isPassthrough) {
246             mIsPassthrough = isPassthrough;
247             return this;
248         }
249 
250         /**
251          * Sets the Audio Stream Type.
252          *
253          * <p>This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause
254          * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version.
255          *
256          * @param audioStreamType the audio stream type to set.
257          */
258         @NonNull
setAudioStreamType(@udioStreamType int audioStreamType)259         public Builder setAudioStreamType(@AudioStreamType int audioStreamType) {
260             if (TunerVersionChecker.checkHigherOrEqualVersionTo(
261                     TunerVersionChecker.TUNER_VERSION_1_1, "setAudioStreamType") && mIsAudio) {
262                 mAudioStreamType = audioStreamType;
263                 mVideoStreamType = VIDEO_STREAM_TYPE_UNDEFINED;
264             }
265             return this;
266         }
267 
268         /**
269          * Sets the Video Stream Type.
270          *
271          * <p>This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause
272          * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version.
273          *
274          * @param videoStreamType the video stream type to set.
275          */
276         @NonNull
setVideoStreamType(@ideoStreamType int videoStreamType)277         public Builder setVideoStreamType(@VideoStreamType int videoStreamType) {
278             if (TunerVersionChecker.checkHigherOrEqualVersionTo(
279                     TunerVersionChecker.TUNER_VERSION_1_1, "setVideoStreamType") && !mIsAudio) {
280                 mVideoStreamType = videoStreamType;
281                 mAudioStreamType = AUDIO_STREAM_TYPE_UNDEFINED;
282             }
283             return this;
284         }
285 
286         /**
287          * Builds a {@link AvSettings} object.
288          */
289         @NonNull
build()290         public AvSettings build() {
291             return new AvSettings(mMainType, mIsAudio, mIsPassthrough,
292                     mAudioStreamType, mVideoStreamType);
293         }
294     }
295 }
296