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_0.Constants; 23 import android.media.tv.tuner.TunerUtils; 24 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 28 /** 29 * The Settings for the record in DVR. 30 * 31 * @hide 32 */ 33 @SystemApi 34 public class RecordSettings extends Settings { 35 /** 36 * Indexes can be tagged through TS (Transport Stream) header. 37 * 38 * @hide 39 */ 40 @IntDef(flag = true, 41 value = {TS_INDEX_INVALID, TS_INDEX_FIRST_PACKET, TS_INDEX_PAYLOAD_UNIT_START_INDICATOR, 42 TS_INDEX_CHANGE_TO_NOT_SCRAMBLED, TS_INDEX_CHANGE_TO_EVEN_SCRAMBLED, 43 TS_INDEX_CHANGE_TO_ODD_SCRAMBLED, TS_INDEX_DISCONTINUITY_INDICATOR, 44 TS_INDEX_RANDOM_ACCESS_INDICATOR, TS_INDEX_PRIORITY_INDICATOR, 45 TS_INDEX_PCR_FLAG, TS_INDEX_OPCR_FLAG, TS_INDEX_SPLICING_POINT_FLAG, 46 TS_INDEX_PRIVATE_DATA, TS_INDEX_ADAPTATION_EXTENSION_FLAG, 47 MPT_INDEX_MPT, MPT_INDEX_VIDEO, MPT_INDEX_AUDIO, 48 MPT_INDEX_TIMESTAMP_TARGET_VIDEO, 49 MPT_INDEX_TIMESTAMP_TARGET_AUDIO}) 50 @Retention(RetentionPolicy.SOURCE) 51 public @interface TsIndexMask {} 52 53 /** 54 * Invalid Transport Stream (TS) index. 55 */ 56 public static final int TS_INDEX_INVALID = 0; 57 /** 58 * TS index FIRST_PACKET. 59 */ 60 public static final int TS_INDEX_FIRST_PACKET = Constants.DemuxTsIndex.FIRST_PACKET; 61 /** 62 * TS index PAYLOAD_UNIT_START_INDICATOR. 63 */ 64 public static final int TS_INDEX_PAYLOAD_UNIT_START_INDICATOR = 65 Constants.DemuxTsIndex.PAYLOAD_UNIT_START_INDICATOR; 66 /** 67 * TS index CHANGE_TO_NOT_SCRAMBLED. 68 */ 69 public static final int TS_INDEX_CHANGE_TO_NOT_SCRAMBLED = 70 Constants.DemuxTsIndex.CHANGE_TO_NOT_SCRAMBLED; 71 /** 72 * TS index CHANGE_TO_EVEN_SCRAMBLED. 73 */ 74 public static final int TS_INDEX_CHANGE_TO_EVEN_SCRAMBLED = 75 Constants.DemuxTsIndex.CHANGE_TO_EVEN_SCRAMBLED; 76 /** 77 * TS index CHANGE_TO_ODD_SCRAMBLED. 78 */ 79 public static final int TS_INDEX_CHANGE_TO_ODD_SCRAMBLED = 80 Constants.DemuxTsIndex.CHANGE_TO_ODD_SCRAMBLED; 81 /** 82 * TS index DISCONTINUITY_INDICATOR. 83 */ 84 public static final int TS_INDEX_DISCONTINUITY_INDICATOR = 85 Constants.DemuxTsIndex.DISCONTINUITY_INDICATOR; 86 /** 87 * TS index RANDOM_ACCESS_INDICATOR. 88 */ 89 public static final int TS_INDEX_RANDOM_ACCESS_INDICATOR = 90 Constants.DemuxTsIndex.RANDOM_ACCESS_INDICATOR; 91 /** 92 * TS index PRIORITY_INDICATOR. 93 */ 94 public static final int TS_INDEX_PRIORITY_INDICATOR = Constants.DemuxTsIndex.PRIORITY_INDICATOR; 95 /** 96 * TS index PCR_FLAG. 97 */ 98 public static final int TS_INDEX_PCR_FLAG = Constants.DemuxTsIndex.PCR_FLAG; 99 /** 100 * TS index OPCR_FLAG. 101 */ 102 public static final int TS_INDEX_OPCR_FLAG = Constants.DemuxTsIndex.OPCR_FLAG; 103 /** 104 * TS index SPLICING_POINT_FLAG. 105 */ 106 public static final int TS_INDEX_SPLICING_POINT_FLAG = 107 Constants.DemuxTsIndex.SPLICING_POINT_FLAG; 108 /** 109 * TS index PRIVATE_DATA. 110 */ 111 public static final int TS_INDEX_PRIVATE_DATA = Constants.DemuxTsIndex.PRIVATE_DATA; 112 /** 113 * TS index ADAPTATION_EXTENSION_FLAG. 114 */ 115 public static final int TS_INDEX_ADAPTATION_EXTENSION_FLAG = 116 Constants.DemuxTsIndex.ADAPTATION_EXTENSION_FLAG; 117 /** 118 * Index the address of MPEG Media Transport Packet Table(MPT). 119 */ 120 public static final int MPT_INDEX_MPT = 121 android.hardware.tv.tuner.V1_1.Constants.DemuxTsIndex.MPT_INDEX_MPT; 122 /** 123 * Index the address of Video. 124 */ 125 public static final int MPT_INDEX_VIDEO = 126 android.hardware.tv.tuner.V1_1.Constants.DemuxTsIndex.MPT_INDEX_VIDEO; 127 /** 128 * Index the address of Audio. 129 */ 130 public static final int MPT_INDEX_AUDIO = 131 android.hardware.tv.tuner.V1_1.Constants.DemuxTsIndex.MPT_INDEX_AUDIO; 132 /** 133 * Index to indicate this is a target of timestamp extraction for video. 134 */ 135 public static final int MPT_INDEX_TIMESTAMP_TARGET_VIDEO = 136 android.hardware.tv.tuner.V1_1.Constants.DemuxTsIndex.MPT_INDEX_TIMESTAMP_TARGET_VIDEO; 137 /** 138 * Index to indicate this is a target of timestamp extraction for audio. 139 */ 140 public static final int MPT_INDEX_TIMESTAMP_TARGET_AUDIO = 141 android.hardware.tv.tuner.V1_1.Constants.DemuxTsIndex.MPT_INDEX_TIMESTAMP_TARGET_AUDIO; 142 143 144 /** @hide */ 145 @Retention(RetentionPolicy.SOURCE) 146 @IntDef(prefix = "INDEX_TYPE_", value = 147 {INDEX_TYPE_NONE, INDEX_TYPE_SC, INDEX_TYPE_SC_HEVC}) 148 public @interface ScIndexType {} 149 150 /** 151 * Start Code Index is not used. 152 */ 153 public static final int INDEX_TYPE_NONE = Constants.DemuxRecordScIndexType.NONE; 154 /** 155 * Start Code index. 156 */ 157 public static final int INDEX_TYPE_SC = Constants.DemuxRecordScIndexType.SC; 158 /** 159 * Start Code index for HEVC. 160 */ 161 public static final int INDEX_TYPE_SC_HEVC = Constants.DemuxRecordScIndexType.SC_HEVC; 162 163 /** 164 * Indexes can be tagged by Start Code in PES (Packetized Elementary Stream) 165 * according to ISO/IEC 13818-1. 166 * @hide 167 */ 168 @IntDef(prefix = "SC_INDEX_", 169 flag = true, 170 value = {SC_INDEX_I_FRAME, SC_INDEX_P_FRAME, SC_INDEX_B_FRAME, 171 SC_INDEX_SEQUENCE, SC_INDEX_I_SLICE, SC_INDEX_P_SLICE, 172 SC_INDEX_B_SLICE, SC_INDEX_SI_SLICE, SC_INDEX_SP_SLICE}) 173 @Retention(RetentionPolicy.SOURCE) 174 public @interface ScIndex {} 175 176 /** 177 * SC index for a new I-frame. 178 */ 179 public static final int SC_INDEX_I_FRAME = Constants.DemuxScIndex.I_FRAME; 180 /** 181 * SC index for a new P-frame. 182 */ 183 public static final int SC_INDEX_P_FRAME = Constants.DemuxScIndex.P_FRAME; 184 /** 185 * SC index for a new B-frame. 186 */ 187 public static final int SC_INDEX_B_FRAME = Constants.DemuxScIndex.B_FRAME; 188 /** 189 * SC index for a new sequence. 190 */ 191 public static final int SC_INDEX_SEQUENCE = Constants.DemuxScIndex.SEQUENCE; 192 /** 193 * All blocks are coded as I blocks. 194 */ 195 public static final int SC_INDEX_I_SLICE = 196 android.hardware.tv.tuner.V1_1.Constants.DemuxScIndex.I_SLICE; 197 /** 198 * Blocks are coded as I or P blocks. 199 */ 200 public static final int SC_INDEX_P_SLICE = 201 android.hardware.tv.tuner.V1_1.Constants.DemuxScIndex.P_SLICE; 202 /** 203 * Blocks are coded as I, P or B blocks. 204 */ 205 public static final int SC_INDEX_B_SLICE = 206 android.hardware.tv.tuner.V1_1.Constants.DemuxScIndex.B_SLICE; 207 /** 208 * A so-called switching I slice that is coded. 209 */ 210 public static final int SC_INDEX_SI_SLICE = 211 android.hardware.tv.tuner.V1_1.Constants.DemuxScIndex.SI_SLICE; 212 /** 213 * A so-called switching P slice that is coded. 214 */ 215 public static final int SC_INDEX_SP_SLICE = 216 android.hardware.tv.tuner.V1_1.Constants.DemuxScIndex.SP_SLICE; 217 218 /** 219 * Indexes can be tagged by NAL unit group in HEVC according to ISO/IEC 23008-2. 220 * 221 * @hide 222 */ 223 @IntDef(flag = true, 224 value = {SC_HEVC_INDEX_SPS, SC_HEVC_INDEX_AUD, SC_HEVC_INDEX_SLICE_CE_BLA_W_LP, 225 SC_HEVC_INDEX_SLICE_BLA_W_RADL, SC_HEVC_INDEX_SLICE_BLA_N_LP, 226 SC_HEVC_INDEX_SLICE_IDR_W_RADL, SC_HEVC_INDEX_SLICE_IDR_N_LP, 227 SC_HEVC_INDEX_SLICE_TRAIL_CRA}) 228 @Retention(RetentionPolicy.SOURCE) 229 public @interface ScHevcIndex {} 230 231 /** 232 * SC HEVC index SPS. 233 */ 234 public static final int SC_HEVC_INDEX_SPS = Constants.DemuxScHevcIndex.SPS; 235 /** 236 * SC HEVC index AUD. 237 */ 238 public static final int SC_HEVC_INDEX_AUD = Constants.DemuxScHevcIndex.AUD; 239 /** 240 * SC HEVC index SLICE_CE_BLA_W_LP. 241 */ 242 public static final int SC_HEVC_INDEX_SLICE_CE_BLA_W_LP = 243 Constants.DemuxScHevcIndex.SLICE_CE_BLA_W_LP; 244 /** 245 * SC HEVC index SLICE_BLA_W_RADL. 246 */ 247 public static final int SC_HEVC_INDEX_SLICE_BLA_W_RADL = 248 Constants.DemuxScHevcIndex.SLICE_BLA_W_RADL; 249 /** 250 * SC HEVC index SLICE_BLA_N_LP. 251 */ 252 public static final int SC_HEVC_INDEX_SLICE_BLA_N_LP = 253 Constants.DemuxScHevcIndex.SLICE_BLA_N_LP; 254 /** 255 * SC HEVC index SLICE_IDR_W_RADL. 256 */ 257 public static final int SC_HEVC_INDEX_SLICE_IDR_W_RADL = 258 Constants.DemuxScHevcIndex.SLICE_IDR_W_RADL; 259 /** 260 * SC HEVC index SLICE_IDR_N_LP. 261 */ 262 public static final int SC_HEVC_INDEX_SLICE_IDR_N_LP = 263 Constants.DemuxScHevcIndex.SLICE_IDR_N_LP; 264 /** 265 * SC HEVC index SLICE_TRAIL_CRA. 266 */ 267 public static final int SC_HEVC_INDEX_SLICE_TRAIL_CRA = 268 Constants.DemuxScHevcIndex.SLICE_TRAIL_CRA; 269 270 /** 271 * @hide 272 */ 273 @IntDef(flag = true, 274 prefix = "SC_", 275 value = { 276 SC_INDEX_I_FRAME, 277 SC_INDEX_P_FRAME, 278 SC_INDEX_B_FRAME, 279 SC_INDEX_SEQUENCE, 280 SC_HEVC_INDEX_SPS, 281 SC_HEVC_INDEX_AUD, 282 SC_HEVC_INDEX_SLICE_CE_BLA_W_LP, 283 SC_HEVC_INDEX_SLICE_BLA_W_RADL, 284 SC_HEVC_INDEX_SLICE_BLA_N_LP, 285 SC_HEVC_INDEX_SLICE_IDR_W_RADL, 286 SC_HEVC_INDEX_SLICE_IDR_N_LP, 287 SC_HEVC_INDEX_SLICE_TRAIL_CRA, 288 }) 289 @Retention(RetentionPolicy.SOURCE) 290 public @interface ScIndexMask {} 291 292 293 294 private final int mTsIndexMask; 295 private final int mScIndexType; 296 private final int mScIndexMask; 297 RecordSettings(int mainType, int tsIndexType, int scIndexType, int scIndexMask)298 private RecordSettings(int mainType, int tsIndexType, int scIndexType, int scIndexMask) { 299 super(TunerUtils.getFilterSubtype(mainType, Filter.SUBTYPE_RECORD)); 300 mTsIndexMask = tsIndexType; 301 mScIndexType = scIndexType; 302 mScIndexMask = scIndexMask; 303 } 304 305 /** 306 * Gets TS index mask. 307 */ 308 @TsIndexMask getTsIndexMask()309 public int getTsIndexMask() { 310 return mTsIndexMask; 311 } 312 /** 313 * Gets Start Code index type. 314 */ 315 @ScIndexType getScIndexType()316 public int getScIndexType() { 317 return mScIndexType; 318 } 319 /** 320 * Gets Start Code index mask. 321 */ 322 @ScIndexMask getScIndexMask()323 public int getScIndexMask() { 324 return mScIndexMask; 325 } 326 327 /** 328 * Creates a builder for {@link RecordSettings}. 329 * 330 * @param mainType the filter main type. 331 */ 332 @NonNull builder(@ilter.Type int mainType)333 public static Builder builder(@Filter.Type int mainType) { 334 return new Builder(mainType); 335 } 336 337 /** 338 * Builder for {@link RecordSettings}. 339 */ 340 public static class Builder { 341 private final int mMainType; 342 private int mTsIndexMask; 343 private int mScIndexType; 344 private int mScIndexMask; 345 Builder(int mainType)346 private Builder(int mainType) { 347 mMainType = mainType; 348 } 349 350 /** 351 * Sets TS index mask. 352 */ 353 @NonNull setTsIndexMask(@sIndexMask int indexMask)354 public Builder setTsIndexMask(@TsIndexMask int indexMask) { 355 mTsIndexMask = indexMask; 356 return this; 357 } 358 /** 359 * Sets index type. 360 */ 361 @NonNull setScIndexType(@cIndexType int indexType)362 public Builder setScIndexType(@ScIndexType int indexType) { 363 mScIndexType = indexType; 364 return this; 365 } 366 /** 367 * Sets Start Code index mask. 368 */ 369 @NonNull setScIndexMask(@cIndexMask int indexMask)370 public Builder setScIndexMask(@ScIndexMask int indexMask) { 371 mScIndexMask = indexMask; 372 return this; 373 } 374 375 /** 376 * Builds a {@link RecordSettings} object. 377 */ 378 @NonNull build()379 public RecordSettings build() { 380 return new RecordSettings(mMainType, mTsIndexMask, mScIndexType, mScIndexMask); 381 } 382 } 383 384 } 385