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