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.IntRange; 20 import android.annotation.NonNull; 21 import android.annotation.SystemApi; 22 import android.media.tv.tuner.TunerUtils; 23 24 /** 25 * Filter Settings for Section data according to ISO/IEC 13818-1 and ISO/IEC 23008-1. 26 * 27 * @hide 28 */ 29 @SystemApi 30 public abstract class SectionSettings extends Settings { 31 final boolean mCrcEnabled; 32 final boolean mIsRepeat; 33 final boolean mIsRaw; 34 final int mBitWidthOfLengthField; 35 SectionSettings(int mainType, boolean crcEnabled, boolean isRepeat, boolean isRaw, int bitWidthOfLengthField)36 SectionSettings(int mainType, boolean crcEnabled, boolean isRepeat, boolean isRaw, 37 int bitWidthOfLengthField) { 38 super(TunerUtils.getFilterSubtype(mainType, Filter.SUBTYPE_SECTION)); 39 mCrcEnabled = crcEnabled; 40 mIsRepeat = isRepeat; 41 mIsRaw = isRaw; 42 mBitWidthOfLengthField = bitWidthOfLengthField; 43 } 44 45 /** 46 * Returns whether the filter enables CRC (Cyclic redundancy check) and discards data which 47 * doesn't pass the check. 48 */ isCrcEnabled()49 public boolean isCrcEnabled() { 50 return mCrcEnabled; 51 } 52 53 /** 54 * Returns whether the filter repeats the data. 55 * 56 * If {@code false}, for {@link SectionSettingsWithTableInfo}, HAL filters out all sections 57 * based on {@link SectionSettingsWithTableInfo} TableId and Version, and stops filtering data. 58 * For {@link SectionSettingsWithSectionBits}, HAL filters out the first section which matches 59 * the {@link SectionSettingsWithSectionBits} configuration, and stops filtering data. 60 * 61 * If {@code true}, for {@link SectionSettingsWithTableInfo}, HAL filters out all sections based 62 * on {@link SectionSettingsWithTableInfo} TableId and Version, and repeats. For 63 * {@link SectionSettingsWithSectionBits}, HAL filters out sections which match the 64 * {@link SectionSettingsWithSectionBits} configuration, and repeats. 65 */ isRepeat()66 public boolean isRepeat() { 67 return mIsRepeat; 68 } 69 70 /** 71 * Returns whether the filter sends {@link FilterCallback#onFilterStatusChanged} instead of 72 * {@link FilterCallback#onFilterEvent}. 73 */ isRaw()74 public boolean isRaw() { 75 return mIsRaw; 76 } 77 78 /** 79 * Returns the bit width of the MMTP (MPEG Media Transport Protocol) section message's length 80 * field according to ISO/IEC 23008-1. 81 * 82 * The section filter uses this for CRC (Cyclic redundancy check) checking when 83 * {@link #isCrcEnabled()} is {@code true}. 84 */ getLengthFieldBitWidth()85 public int getLengthFieldBitWidth() { 86 return mBitWidthOfLengthField; 87 } 88 89 /** 90 * Builder for {@link SectionSettings}. 91 * 92 * @param <T> The subclass to be built. 93 */ 94 public abstract static class Builder<T extends Builder<T>> { 95 final int mMainType; 96 boolean mCrcEnabled; 97 boolean mIsRepeat; 98 boolean mIsRaw; 99 int mBitWidthOfLengthField; 100 Builder(int mainType)101 Builder(int mainType) { 102 mMainType = mainType; 103 } 104 105 /** 106 * Sets whether the filter enables CRC (Cyclic redundancy check) and discards data which 107 * doesn't pass the check. 108 */ 109 @NonNull setCrcEnabled(boolean crcEnabled)110 public T setCrcEnabled(boolean crcEnabled) { 111 mCrcEnabled = crcEnabled; 112 return self(); 113 } 114 115 /** 116 * Sets whether the filter repeats the data. 117 * 118 * If {@code false}, for {@link SectionSettingsWithTableInfo}, HAL filters out all sections 119 * based on {@link SectionSettingsWithTableInfo} TableId and Version, and stops filtering 120 * data. For {@link SectionSettingsWithSectionBits}, HAL filters out the first section which 121 * matches the {@link SectionSettingsWithSectionBits} configuration, and stops filtering 122 * data. 123 * 124 * If {@code true}, for {@link SectionSettingsWithTableInfo}, HAL filters out all sections 125 * based on {@link SectionSettingsWithTableInfo} TableId and Version, and repeats. For 126 * {@link SectionSettingsWithSectionBits}, HAL filters out sections which match the 127 * {@link SectionSettingsWithSectionBits} configuration, and repeats. 128 */ 129 @NonNull setRepeat(boolean isRepeat)130 public T setRepeat(boolean isRepeat) { 131 mIsRepeat = isRepeat; 132 return self(); 133 } 134 135 /** 136 * Sets whether the filter send onFilterStatus instead of 137 * {@link FilterCallback#onFilterEvent}. 138 */ 139 @NonNull setRaw(boolean isRaw)140 public T setRaw(boolean isRaw) { 141 mIsRaw = isRaw; 142 return self(); 143 } 144 145 /** 146 * Sets the bit width for the MMTP(MPEG Media Transport Protocol) section message's length 147 * field according to ISO/IEC 23008-1. 148 * 149 * The section filter uses this for CRC (Cyclic redundancy check) checking when 150 * {@link #isCrcEnabled()} is {@code true}. 151 * 152 * <p>This field is only supported in Tuner 2.0 or higher version. Unsupported version will 153 * cause no-op. Use {@link android.media.tv.tuner.TunerVersionChecker#getTunerVersion()} 154 * to get the version information. 155 */ 156 @NonNull setBitWidthOfLengthField(@ntRangefrom = 0) int bitWidthOfLengthField)157 public T setBitWidthOfLengthField(@IntRange(from = 0) int bitWidthOfLengthField) { 158 mBitWidthOfLengthField = bitWidthOfLengthField; 159 return self(); 160 } 161 self()162 /* package */ abstract T self(); 163 } 164 } 165