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