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