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 prefix = "TS_INDEX_", 42 value = {TS_INDEX_FIRST_PACKET, TS_INDEX_PAYLOAD_UNIT_START_INDICATOR, 43 TS_INDEX_CHANGE_TO_NOT_SCRAMBLED, TS_INDEX_CHANGE_TO_EVEN_SCRAMBLED, 44 TS_INDEX_CHANGE_TO_ODD_SCRAMBLED, TS_INDEX_DISCONTINUITY_INDICATOR, 45 TS_INDEX_RANDOM_ACCESS_INDICATOR, TS_INDEX_PRIORITY_INDICATOR, 46 TS_INDEX_PCR_FLAG, TS_INDEX_OPCR_FLAG, TS_INDEX_SPLICING_POINT_FLAG, 47 TS_INDEX_PRIVATE_DATA, TS_INDEX_ADAPTATION_EXTENSION_FLAG}) 48 @Retention(RetentionPolicy.SOURCE) 49 public @interface TsIndexMask {} 50 51 /** 52 * TS index FIRST_PACKET. 53 */ 54 public static final int TS_INDEX_FIRST_PACKET = Constants.DemuxTsIndex.FIRST_PACKET; 55 /** 56 * TS index PAYLOAD_UNIT_START_INDICATOR. 57 */ 58 public static final int TS_INDEX_PAYLOAD_UNIT_START_INDICATOR = 59 Constants.DemuxTsIndex.PAYLOAD_UNIT_START_INDICATOR; 60 /** 61 * TS index CHANGE_TO_NOT_SCRAMBLED. 62 */ 63 public static final int TS_INDEX_CHANGE_TO_NOT_SCRAMBLED = 64 Constants.DemuxTsIndex.CHANGE_TO_NOT_SCRAMBLED; 65 /** 66 * TS index CHANGE_TO_EVEN_SCRAMBLED. 67 */ 68 public static final int TS_INDEX_CHANGE_TO_EVEN_SCRAMBLED = 69 Constants.DemuxTsIndex.CHANGE_TO_EVEN_SCRAMBLED; 70 /** 71 * TS index CHANGE_TO_ODD_SCRAMBLED. 72 */ 73 public static final int TS_INDEX_CHANGE_TO_ODD_SCRAMBLED = 74 Constants.DemuxTsIndex.CHANGE_TO_ODD_SCRAMBLED; 75 /** 76 * TS index DISCONTINUITY_INDICATOR. 77 */ 78 public static final int TS_INDEX_DISCONTINUITY_INDICATOR = 79 Constants.DemuxTsIndex.DISCONTINUITY_INDICATOR; 80 /** 81 * TS index RANDOM_ACCESS_INDICATOR. 82 */ 83 public static final int TS_INDEX_RANDOM_ACCESS_INDICATOR = 84 Constants.DemuxTsIndex.RANDOM_ACCESS_INDICATOR; 85 /** 86 * TS index PRIORITY_INDICATOR. 87 */ 88 public static final int TS_INDEX_PRIORITY_INDICATOR = Constants.DemuxTsIndex.PRIORITY_INDICATOR; 89 /** 90 * TS index PCR_FLAG. 91 */ 92 public static final int TS_INDEX_PCR_FLAG = Constants.DemuxTsIndex.PCR_FLAG; 93 /** 94 * TS index OPCR_FLAG. 95 */ 96 public static final int TS_INDEX_OPCR_FLAG = Constants.DemuxTsIndex.OPCR_FLAG; 97 /** 98 * TS index SPLICING_POINT_FLAG. 99 */ 100 public static final int TS_INDEX_SPLICING_POINT_FLAG = 101 Constants.DemuxTsIndex.SPLICING_POINT_FLAG; 102 /** 103 * TS index PRIVATE_DATA. 104 */ 105 public static final int TS_INDEX_PRIVATE_DATA = Constants.DemuxTsIndex.PRIVATE_DATA; 106 /** 107 * TS index ADAPTATION_EXTENSION_FLAG. 108 */ 109 public static final int TS_INDEX_ADAPTATION_EXTENSION_FLAG = 110 Constants.DemuxTsIndex.ADAPTATION_EXTENSION_FLAG; 111 112 /** @hide */ 113 @Retention(RetentionPolicy.SOURCE) 114 @IntDef(prefix = "INDEX_TYPE_", value = 115 {INDEX_TYPE_NONE, INDEX_TYPE_SC, INDEX_TYPE_SC_HEVC}) 116 public @interface ScIndexType {} 117 118 /** 119 * Start Code Index is not used. 120 */ 121 public static final int INDEX_TYPE_NONE = Constants.DemuxRecordScIndexType.NONE; 122 /** 123 * Start Code index. 124 */ 125 public static final int INDEX_TYPE_SC = Constants.DemuxRecordScIndexType.SC; 126 /** 127 * Start Code index for HEVC. 128 */ 129 public static final int INDEX_TYPE_SC_HEVC = Constants.DemuxRecordScIndexType.SC_HEVC; 130 131 /** 132 * Indexes can be tagged by Start Code in PES (Packetized Elementary Stream) 133 * according to ISO/IEC 13818-1. 134 * @hide 135 */ 136 @IntDef(flag = true, value = {SC_INDEX_I_FRAME, SC_INDEX_P_FRAME, SC_INDEX_B_FRAME, 137 SC_INDEX_SEQUENCE}) 138 @Retention(RetentionPolicy.SOURCE) 139 public @interface ScIndex {} 140 141 /** 142 * SC index for a new I-frame. 143 */ 144 public static final int SC_INDEX_I_FRAME = Constants.DemuxScIndex.I_FRAME; 145 /** 146 * SC index for a new P-frame. 147 */ 148 public static final int SC_INDEX_P_FRAME = Constants.DemuxScIndex.P_FRAME; 149 /** 150 * SC index for a new B-frame. 151 */ 152 public static final int SC_INDEX_B_FRAME = Constants.DemuxScIndex.B_FRAME; 153 /** 154 * SC index for a new sequence. 155 */ 156 public static final int SC_INDEX_SEQUENCE = Constants.DemuxScIndex.SEQUENCE; 157 158 159 /** 160 * Indexes can be tagged by NAL unit group in HEVC according to ISO/IEC 23008-2. 161 * 162 * @hide 163 */ 164 @IntDef(flag = true, 165 value = {SC_HEVC_INDEX_SPS, SC_HEVC_INDEX_AUD, SC_HEVC_INDEX_SLICE_CE_BLA_W_LP, 166 SC_HEVC_INDEX_SLICE_BLA_W_RADL, SC_HEVC_INDEX_SLICE_BLA_N_LP, 167 SC_HEVC_INDEX_SLICE_IDR_W_RADL, SC_HEVC_INDEX_SLICE_IDR_N_LP, 168 SC_HEVC_INDEX_SLICE_TRAIL_CRA}) 169 @Retention(RetentionPolicy.SOURCE) 170 public @interface ScHevcIndex {} 171 172 /** 173 * SC HEVC index SPS. 174 */ 175 public static final int SC_HEVC_INDEX_SPS = Constants.DemuxScHevcIndex.SPS; 176 /** 177 * SC HEVC index AUD. 178 */ 179 public static final int SC_HEVC_INDEX_AUD = Constants.DemuxScHevcIndex.AUD; 180 /** 181 * SC HEVC index SLICE_CE_BLA_W_LP. 182 */ 183 public static final int SC_HEVC_INDEX_SLICE_CE_BLA_W_LP = 184 Constants.DemuxScHevcIndex.SLICE_CE_BLA_W_LP; 185 /** 186 * SC HEVC index SLICE_BLA_W_RADL. 187 */ 188 public static final int SC_HEVC_INDEX_SLICE_BLA_W_RADL = 189 Constants.DemuxScHevcIndex.SLICE_BLA_W_RADL; 190 /** 191 * SC HEVC index SLICE_BLA_N_LP. 192 */ 193 public static final int SC_HEVC_INDEX_SLICE_BLA_N_LP = 194 Constants.DemuxScHevcIndex.SLICE_BLA_N_LP; 195 /** 196 * SC HEVC index SLICE_IDR_W_RADL. 197 */ 198 public static final int SC_HEVC_INDEX_SLICE_IDR_W_RADL = 199 Constants.DemuxScHevcIndex.SLICE_IDR_W_RADL; 200 /** 201 * SC HEVC index SLICE_IDR_N_LP. 202 */ 203 public static final int SC_HEVC_INDEX_SLICE_IDR_N_LP = 204 Constants.DemuxScHevcIndex.SLICE_IDR_N_LP; 205 /** 206 * SC HEVC index SLICE_TRAIL_CRA. 207 */ 208 public static final int SC_HEVC_INDEX_SLICE_TRAIL_CRA = 209 Constants.DemuxScHevcIndex.SLICE_TRAIL_CRA; 210 211 /** 212 * @hide 213 */ 214 @IntDef(flag = true, 215 prefix = "SC_", 216 value = { 217 SC_INDEX_I_FRAME, 218 SC_INDEX_P_FRAME, 219 SC_INDEX_B_FRAME, 220 SC_INDEX_SEQUENCE, 221 SC_HEVC_INDEX_SPS, 222 SC_HEVC_INDEX_AUD, 223 SC_HEVC_INDEX_SLICE_CE_BLA_W_LP, 224 SC_HEVC_INDEX_SLICE_BLA_W_RADL, 225 SC_HEVC_INDEX_SLICE_BLA_N_LP, 226 SC_HEVC_INDEX_SLICE_IDR_W_RADL, 227 SC_HEVC_INDEX_SLICE_IDR_N_LP, 228 SC_HEVC_INDEX_SLICE_TRAIL_CRA, 229 }) 230 @Retention(RetentionPolicy.SOURCE) 231 public @interface ScIndexMask {} 232 233 234 235 private final int mTsIndexMask; 236 private final int mScIndexType; 237 private final int mScIndexMask; 238 RecordSettings(int mainType, int tsIndexType, int scIndexType, int scIndexMask)239 private RecordSettings(int mainType, int tsIndexType, int scIndexType, int scIndexMask) { 240 super(TunerUtils.getFilterSubtype(mainType, Filter.SUBTYPE_RECORD)); 241 mTsIndexMask = tsIndexType; 242 mScIndexType = scIndexType; 243 mScIndexMask = scIndexMask; 244 } 245 246 /** 247 * Gets TS index mask. 248 */ 249 @TsIndexMask getTsIndexMask()250 public int getTsIndexMask() { 251 return mTsIndexMask; 252 } 253 /** 254 * Gets Start Code index type. 255 */ 256 @ScIndexType getScIndexType()257 public int getScIndexType() { 258 return mScIndexType; 259 } 260 /** 261 * Gets Start Code index mask. 262 */ 263 @ScIndexMask getScIndexMask()264 public int getScIndexMask() { 265 return mScIndexMask; 266 } 267 268 /** 269 * Creates a builder for {@link RecordSettings}. 270 * 271 * @param mainType the filter main type. 272 */ 273 @NonNull builder(@ilter.Type int mainType)274 public static Builder builder(@Filter.Type int mainType) { 275 return new Builder(mainType); 276 } 277 278 /** 279 * Builder for {@link RecordSettings}. 280 */ 281 public static class Builder { 282 private final int mMainType; 283 private int mTsIndexMask; 284 private int mScIndexType; 285 private int mScIndexMask; 286 Builder(int mainType)287 private Builder(int mainType) { 288 mMainType = mainType; 289 } 290 291 /** 292 * Sets TS index mask. 293 */ 294 @NonNull setTsIndexMask(@sIndexMask int indexMask)295 public Builder setTsIndexMask(@TsIndexMask int indexMask) { 296 mTsIndexMask = indexMask; 297 return this; 298 } 299 /** 300 * Sets index type. 301 */ 302 @NonNull setScIndexType(@cIndexType int indexType)303 public Builder setScIndexType(@ScIndexType int indexType) { 304 mScIndexType = indexType; 305 return this; 306 } 307 /** 308 * Sets Start Code index mask. 309 */ 310 @NonNull setScIndexMask(@cIndexMask int indexMask)311 public Builder setScIndexMask(@ScIndexMask int indexMask) { 312 mScIndexMask = indexMask; 313 return this; 314 } 315 316 /** 317 * Builds a {@link RecordSettings} object. 318 */ 319 @NonNull build()320 public RecordSettings build() { 321 return new RecordSettings(mMainType, mTsIndexMask, mScIndexType, mScIndexMask); 322 } 323 } 324 325 } 326