diff options
| author | 2020-01-16 20:29:03 +0000 | |
|---|---|---|
| committer | 2020-01-16 20:29:03 +0000 | |
| commit | 3c01d0cdfe6464191a4cb0350c7e4bf2181d63b4 (patch) | |
| tree | 8f68e26b07e7f11298d8e1dfa14de58d731d64f1 | |
| parent | 25e6dd3ed13346a0fe7056d02ad9faf1328367e2 (diff) | |
| parent | 4eda97f10e542d52c96c91162bb05e8858014d7c (diff) | |
Merge "Complete FilterConfiguration getters and builders"
13 files changed, 1022 insertions, 152 deletions
diff --git a/media/java/android/media/tv/tuner/TunerConstants.java b/media/java/android/media/tv/tuner/TunerConstants.java index 19cfa32eccd6..fa8f550867b8 100644 --- a/media/java/android/media/tv/tuner/TunerConstants.java +++ b/media/java/android/media/tv/tuner/TunerConstants.java @@ -129,93 +129,29 @@ public final class TunerConstants { */ public static final int FILTER_STATUS_OVERFLOW = Constants.DemuxFilterStatus.OVERFLOW; - /** - * Indexes can be tagged through TS (Transport Stream) header. - * - * @hide - */ - @IntDef(flag = true, value = {TS_INDEX_FIRST_PACKET, TS_INDEX_PAYLOAD_UNIT_START_INDICATOR, - TS_INDEX_CHANGE_TO_NOT_SCRAMBLED, TS_INDEX_CHANGE_TO_EVEN_SCRAMBLED, - TS_INDEX_CHANGE_TO_ODD_SCRAMBLED, TS_INDEX_DISCONTINUITY_INDICATOR, - TS_INDEX_RANDOM_ACCESS_INDICATOR, TS_INDEX_PRIORITY_INDICATOR, TS_INDEX_PCR_FLAG, - TS_INDEX_OPCR_FLAG, TS_INDEX_SPLICING_POINT_FLAG, TS_INDEX_PRIVATE_DATA, - TS_INDEX_ADAPTATION_EXTENSION_FLAG}) + + /** @hide */ @Retention(RetentionPolicy.SOURCE) - public @interface TsIndex {} + @IntDef(prefix = "INDEX_TYPE_", value = + {INDEX_TYPE_NONE, INDEX_TYPE_SC, INDEX_TYPE_SC_HEVC}) + public @interface ScIndexType {} /** - * TS index FIRST_PACKET. + * Start Code Index is not used. * @hide */ - public static final int TS_INDEX_FIRST_PACKET = Constants.DemuxTsIndex.FIRST_PACKET; + public static final int INDEX_TYPE_NONE = Constants.DemuxRecordScIndexType.NONE; /** - * TS index PAYLOAD_UNIT_START_INDICATOR. + * Start Code index. * @hide */ - public static final int TS_INDEX_PAYLOAD_UNIT_START_INDICATOR = - Constants.DemuxTsIndex.PAYLOAD_UNIT_START_INDICATOR; + public static final int INDEX_TYPE_SC = Constants.DemuxRecordScIndexType.SC; /** - * TS index CHANGE_TO_NOT_SCRAMBLED. + * Start Code index for HEVC. * @hide */ - public static final int TS_INDEX_CHANGE_TO_NOT_SCRAMBLED = - Constants.DemuxTsIndex.CHANGE_TO_NOT_SCRAMBLED; - /** - * TS index CHANGE_TO_EVEN_SCRAMBLED. - * @hide - */ - public static final int TS_INDEX_CHANGE_TO_EVEN_SCRAMBLED = - Constants.DemuxTsIndex.CHANGE_TO_EVEN_SCRAMBLED; - /** - * TS index CHANGE_TO_ODD_SCRAMBLED. - * @hide - */ - public static final int TS_INDEX_CHANGE_TO_ODD_SCRAMBLED = - Constants.DemuxTsIndex.CHANGE_TO_ODD_SCRAMBLED; - /** - * TS index DISCONTINUITY_INDICATOR. - * @hide - */ - public static final int TS_INDEX_DISCONTINUITY_INDICATOR = - Constants.DemuxTsIndex.DISCONTINUITY_INDICATOR; - /** - * TS index RANDOM_ACCESS_INDICATOR. - * @hide - */ - public static final int TS_INDEX_RANDOM_ACCESS_INDICATOR = - Constants.DemuxTsIndex.RANDOM_ACCESS_INDICATOR; - /** - * TS index PRIORITY_INDICATOR. - * @hide - */ - public static final int TS_INDEX_PRIORITY_INDICATOR = Constants.DemuxTsIndex.PRIORITY_INDICATOR; - /** - * TS index PCR_FLAG. - * @hide - */ - public static final int TS_INDEX_PCR_FLAG = Constants.DemuxTsIndex.PCR_FLAG; - /** - * TS index OPCR_FLAG. - * @hide - */ - public static final int TS_INDEX_OPCR_FLAG = Constants.DemuxTsIndex.OPCR_FLAG; - /** - * TS index SPLICING_POINT_FLAG. - * @hide - */ - public static final int TS_INDEX_SPLICING_POINT_FLAG = - Constants.DemuxTsIndex.SPLICING_POINT_FLAG; - /** - * TS index PRIVATE_DATA. - * @hide - */ - public static final int TS_INDEX_PRIVATE_DATA = Constants.DemuxTsIndex.PRIVATE_DATA; - /** - * TS index ADAPTATION_EXTENSION_FLAG. - * @hide - */ - public static final int TS_INDEX_ADAPTATION_EXTENSION_FLAG = - Constants.DemuxTsIndex.ADAPTATION_EXTENSION_FLAG; + public static final int INDEX_TYPE_SC_HEVC = Constants.DemuxRecordScIndexType.SC_HEVC; + /** * Indexes can be tagged by Start Code in PES (Packetized Elementary Stream) diff --git a/media/java/android/media/tv/tuner/filter/AlpFilterConfiguration.java b/media/java/android/media/tv/tuner/filter/AlpFilterConfiguration.java index f0fe533093ba..fcca6a1615c3 100644 --- a/media/java/android/media/tv/tuner/filter/AlpFilterConfiguration.java +++ b/media/java/android/media/tv/tuner/filter/AlpFilterConfiguration.java @@ -16,20 +16,123 @@ package android.media.tv.tuner.filter; +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.RequiresPermission; +import android.content.Context; +import android.hardware.tv.tuner.V1_0.Constants; +import android.media.tv.tuner.TunerUtils; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * Filter configuration for a ALP filter. * @hide */ public class AlpFilterConfiguration extends FilterConfiguration { - private int mPacketType; - private int mLengthType; + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(prefix = "LENGTH_TYPE_", value = + {LENGTH_TYPE_UNDEFINED, LENGTH_TYPE_WITHOUT_ADDITIONAL_HEADER, + LENGTH_TYPE_WITH_ADDITIONAL_HEADER}) + public @interface LengthType {} + + /** + * Length type not defined. + */ + public static final int LENGTH_TYPE_UNDEFINED = Constants.DemuxAlpLengthType.UNDEFINED; + /** + * Length does NOT include additional header. + */ + public static final int LENGTH_TYPE_WITHOUT_ADDITIONAL_HEADER = + Constants.DemuxAlpLengthType.WITHOUT_ADDITIONAL_HEADER; + /** + * Length includes additional header. + */ + public static final int LENGTH_TYPE_WITH_ADDITIONAL_HEADER = + Constants.DemuxAlpLengthType.WITH_ADDITIONAL_HEADER; + - public AlpFilterConfiguration(Settings settings) { + private final int mPacketType; + private final int mLengthType; + + public AlpFilterConfiguration(Settings settings, int packetType, int lengthType) { super(settings); + mPacketType = packetType; + mLengthType = lengthType; } @Override public int getType() { return FilterConfiguration.FILTER_TYPE_ALP; } + + /** + * Gets packet type. + */ + @FilterConfiguration.PacketType + public int getPacketType() { + return mPacketType; + } + /** + * Gets length type. + */ + @LengthType + public int getLengthType() { + return mLengthType; + } + + /** + * Creates a builder for {@link AlpFilterConfiguration}. + * + * @param context the context of the caller. + */ + @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) + @NonNull + public static Builder builder(@NonNull Context context) { + TunerUtils.checkTunerPermission(context); + return new Builder(); + } + + /** + * Builder for {@link AlpFilterConfiguration}. + */ + public static class Builder extends FilterConfiguration.Builder<Builder> { + private int mPacketType; + private int mLengthType; + + private Builder() { + } + + /** + * Sets packet type. + */ + @NonNull + public Builder setPacketType(@FilterConfiguration.PacketType int packetType) { + mPacketType = packetType; + return this; + } + /** + * Sets length type. + */ + @NonNull + public Builder setLengthType(@LengthType int lengthType) { + mLengthType = lengthType; + return this; + } + + /** + * Builds a {@link AlpFilterConfiguration} object. + */ + @NonNull + public AlpFilterConfiguration build() { + return new AlpFilterConfiguration(mSettings, mPacketType, mLengthType); + } + + @Override + Builder self() { + return this; + } + } } diff --git a/media/java/android/media/tv/tuner/filter/AvSettings.java b/media/java/android/media/tv/tuner/filter/AvSettings.java index a7c49d5585f8..940b5ae44a74 100644 --- a/media/java/android/media/tv/tuner/filter/AvSettings.java +++ b/media/java/android/media/tv/tuner/filter/AvSettings.java @@ -16,21 +16,84 @@ package android.media.tv.tuner.filter; +import android.annotation.NonNull; +import android.annotation.RequiresPermission; +import android.content.Context; import android.media.tv.tuner.TunerConstants; import android.media.tv.tuner.TunerUtils; +import android.media.tv.tuner.filter.FilterConfiguration.FilterType; /** * Filter Settings for a Video and Audio. + * * @hide */ public class AvSettings extends Settings { - private boolean mIsPassthrough; + private final boolean mIsPassthrough; - private AvSettings(int mainType, boolean isAudio) { + private AvSettings(int mainType, boolean isAudio, boolean isPassthrough) { super(TunerUtils.getFilterSubtype( mainType, isAudio ? TunerConstants.FILTER_SUBTYPE_AUDIO : TunerConstants.FILTER_SUBTYPE_VIDEO)); + mIsPassthrough = isPassthrough; + } + + /** + * Checks whether it's passthrough. + */ + public boolean isPassthrough() { + return mIsPassthrough; + } + + /** + * Creates a builder for {@link AvSettings}. + * + * @param context the context of the caller. + * @param mainType the filter main type. + * @param isAudio {@code true} if it's audio settings; {@code false} if it's video settings. + */ + @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) + @NonNull + public static Builder builder( + @NonNull Context context, @FilterType int mainType, boolean isAudio) { + TunerUtils.checkTunerPermission(context); + return new Builder(mainType, isAudio); + } + + /** + * Builder for {@link AvSettings}. + */ + public static class Builder extends Settings.Builder<Builder> { + private final boolean mIsAudio; + private boolean mIsPassthrough; + + private Builder(int mainType, boolean isAudio) { + super(mainType); + mIsAudio = isAudio; + } + + /** + * Sets whether it's passthrough. + */ + @NonNull + public Builder setPassthrough(boolean isPassthrough) { + mIsPassthrough = isPassthrough; + return this; + } + + /** + * Builds a {@link AvSettings} object. + */ + @NonNull + public AvSettings build() { + return new AvSettings(mMainType, mIsAudio, mIsPassthrough); + } + + @Override + Builder self() { + return this; + } } } diff --git a/media/java/android/media/tv/tuner/filter/DownloadSettings.java b/media/java/android/media/tv/tuner/filter/DownloadSettings.java index 0742b1166ede..e3e1df064238 100644 --- a/media/java/android/media/tv/tuner/filter/DownloadSettings.java +++ b/media/java/android/media/tv/tuner/filter/DownloadSettings.java @@ -16,17 +16,75 @@ package android.media.tv.tuner.filter; +import android.annotation.NonNull; +import android.annotation.RequiresPermission; +import android.content.Context; import android.media.tv.tuner.TunerConstants; import android.media.tv.tuner.TunerUtils; +import android.media.tv.tuner.filter.FilterConfiguration.FilterType; /** * Filter Settings for a Download. * @hide */ public class DownloadSettings extends Settings { - private int mDownloadId; + private final int mDownloadId; - public DownloadSettings(int mainType) { + private DownloadSettings(int mainType, int downloadId) { super(TunerUtils.getFilterSubtype(mainType, TunerConstants.FILTER_SUBTYPE_DOWNLOAD)); + mDownloadId = downloadId; + } + + /** + * Gets download ID. + */ + public int getDownloadId() { + return mDownloadId; + } + + /** + * Creates a builder for {@link DownloadSettings}. + * + * @param context the context of the caller. + * @param mainType the filter main type. + */ + @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) + @NonNull + public static Builder builder(@NonNull Context context, @FilterType int mainType) { + TunerUtils.checkTunerPermission(context); + return new Builder(mainType); + } + + /** + * Builder for {@link DownloadSettings}. + */ + public static class Builder extends Settings.Builder<Builder> { + private int mDownloadId; + + private Builder(int mainType) { + super(mainType); + } + + /** + * Sets download ID. + */ + @NonNull + public Builder setDownloadId(int downloadId) { + mDownloadId = downloadId; + return this; + } + + /** + * Builds a {@link DownloadSettings} object. + */ + @NonNull + public DownloadSettings build() { + return new DownloadSettings(mMainType, mDownloadId); + } + + @Override + Builder self() { + return this; + } } } diff --git a/media/java/android/media/tv/tuner/filter/FilterConfiguration.java b/media/java/android/media/tv/tuner/filter/FilterConfiguration.java index 6496627cd1d4..68c722f244d4 100644 --- a/media/java/android/media/tv/tuner/filter/FilterConfiguration.java +++ b/media/java/android/media/tv/tuner/filter/FilterConfiguration.java @@ -33,7 +33,8 @@ import java.lang.annotation.RetentionPolicy; public abstract class FilterConfiguration { /** @hide */ - @IntDef({FILTER_TYPE_TS, FILTER_TYPE_MMTP, FILTER_TYPE_IP, FILTER_TYPE_TLV, FILTER_TYPE_ALP}) + @IntDef(prefix = "FILTER_TYPE_", value = + {FILTER_TYPE_TS, FILTER_TYPE_MMTP, FILTER_TYPE_IP, FILTER_TYPE_TLV, FILTER_TYPE_ALP}) @Retention(RetentionPolicy.SOURCE) public @interface FilterType {} @@ -58,6 +59,30 @@ public abstract class FilterConfiguration { */ public static final int FILTER_TYPE_ALP = Constants.DemuxFilterMainType.ALP; + + /** @hide */ + @IntDef(prefix = "PACKET_TYPE_", value = + {PACKET_TYPE_IPV4, PACKET_TYPE_COMPRESSED, PACKET_TYPE_SIGNALING}) + @Retention(RetentionPolicy.SOURCE) + public @interface PacketType {} + + /** + * IP v4 packet type. + * @hide + */ + public static final int PACKET_TYPE_IPV4 = 0; + /** + * Compressed packet type. + * @hide + */ + public static final int PACKET_TYPE_COMPRESSED = 2; + /** + * Signaling packet type. + * @hide + */ + public static final int PACKET_TYPE_SIGNALING = 4; + + @Nullable /* package */ final Settings mSettings; @@ -77,4 +102,27 @@ public abstract class FilterConfiguration { public Settings getSettings() { return mSettings; } + + /** + * Builder for {@link FilterConfiguration}. + * + * @param <T> The subclass to be built. + * @hide + */ + public abstract static class Builder<T extends Builder<T>> { + /* package */ Settings mSettings; + + /* package */ Builder() { + } + + /** + * Sets filter settings. + */ + @Nullable + public T setFrequency(Settings settings) { + mSettings = settings; + return self(); + } + /* package */ abstract T self(); + } } diff --git a/media/java/android/media/tv/tuner/filter/IpFilterConfiguration.java b/media/java/android/media/tv/tuner/filter/IpFilterConfiguration.java index c89636887628..98edf1035df3 100644 --- a/media/java/android/media/tv/tuner/filter/IpFilterConfiguration.java +++ b/media/java/android/media/tv/tuner/filter/IpFilterConfiguration.java @@ -16,23 +16,152 @@ package android.media.tv.tuner.filter; +import android.annotation.NonNull; +import android.annotation.RequiresPermission; +import android.annotation.Size; +import android.content.Context; +import android.media.tv.tuner.TunerUtils; + /** * Filter configuration for a IP filter. * @hide */ public class IpFilterConfiguration extends FilterConfiguration { - private byte[] mSrcIpAddress; - private byte[] mDstIpAddress; - private int mSrcPort; - private int mDstPort; - private boolean mPassthrough; + private final byte[] mSrcIpAddress; + private final byte[] mDstIpAddress; + private final int mSrcPort; + private final int mDstPort; + private final boolean mPassthrough; - public IpFilterConfiguration(Settings settings) { + public IpFilterConfiguration(Settings settings, byte[] srcAddr, byte[] dstAddr, int srcPort, + int dstPort, boolean passthrough) { super(settings); + mSrcIpAddress = srcAddr; + mDstIpAddress = dstAddr; + mSrcPort = srcPort; + mDstPort = dstPort; + mPassthrough = passthrough; } @Override public int getType() { return FilterConfiguration.FILTER_TYPE_IP; } + + /** + * Gets source IP address. + */ + @Size(min = 4, max = 16) + public byte[] getSrcIpAddress() { + return mSrcIpAddress; + } + /** + * Gets destination IP address. + */ + @Size(min = 4, max = 16) + public byte[] getDstIpAddress() { + return mDstIpAddress; + } + /** + * Gets source port. + */ + public int getSrcPort() { + return mSrcPort; + } + /** + * Gets destination port. + */ + public int getDstPort() { + return mDstPort; + } + /** + * Checks whether the filter is passthrough. + * + * @return {@code true} if the data from IP subtype go to next filter directly; + * {@code false} otherwise. + */ + public boolean isPassthrough() { + return mPassthrough; + } + + /** + * Creates a builder for {@link IpFilterConfiguration}. + * + * @param context the context of the caller. + */ + @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) + @NonNull + public static Builder builder(@NonNull Context context) { + TunerUtils.checkTunerPermission(context); + return new Builder(); + } + + /** + * Builder for {@link IpFilterConfiguration}. + */ + public static class Builder extends FilterConfiguration.Builder<Builder> { + private byte[] mSrcIpAddress; + private byte[] mDstIpAddress; + private int mSrcPort; + private int mDstPort; + private boolean mPassthrough; + + private Builder() { + } + + /** + * Sets source IP address. + */ + @NonNull + public Builder setSrcIpAddress(byte[] srcIpAddress) { + mSrcIpAddress = srcIpAddress; + return this; + } + /** + * Sets destination IP address. + */ + @NonNull + public Builder setDstIpAddress(byte[] dstIpAddress) { + mDstIpAddress = dstIpAddress; + return this; + } + /** + * Sets source port. + */ + @NonNull + public Builder setSrcPort(int srcPort) { + mSrcPort = srcPort; + return this; + } + /** + * Sets destination port. + */ + @NonNull + public Builder setDstPort(int dstPort) { + mDstPort = dstPort; + return this; + } + /** + * Sets passthrough. + */ + @NonNull + public Builder setPassthrough(boolean passthrough) { + mPassthrough = passthrough; + return this; + } + + /** + * Builds a {@link IpFilterConfiguration} object. + */ + @NonNull + public IpFilterConfiguration build() { + return new IpFilterConfiguration( + mSettings, mSrcIpAddress, mDstIpAddress, mSrcPort, mDstPort, mPassthrough); + } + + @Override + Builder self() { + return this; + } + } } diff --git a/media/java/android/media/tv/tuner/filter/MmtpFilterConfiguration.java b/media/java/android/media/tv/tuner/filter/MmtpFilterConfiguration.java index 9045ce67a61f..83246e51c8b6 100644 --- a/media/java/android/media/tv/tuner/filter/MmtpFilterConfiguration.java +++ b/media/java/android/media/tv/tuner/filter/MmtpFilterConfiguration.java @@ -16,19 +16,78 @@ package android.media.tv.tuner.filter; +import android.annotation.NonNull; +import android.annotation.RequiresPermission; +import android.content.Context; +import android.media.tv.tuner.TunerUtils; + /** * Filter configuration for a MMTP filter. * @hide */ public class MmtpFilterConfiguration extends FilterConfiguration { - private int mMmtpPid; + private final int mMmtpPid; - public MmtpFilterConfiguration(Settings settings) { + public MmtpFilterConfiguration(Settings settings, int mmtpPid) { super(settings); + mMmtpPid = mmtpPid; } @Override public int getType() { return FilterConfiguration.FILTER_TYPE_MMTP; } + + /** + * Gets MMPT PID. + * + * <p>Packet ID is used to specify packets in MMTP. + */ + public int getMmtpPid() { + return mMmtpPid; + } + + /** + * Creates a builder for {@link IpFilterConfiguration}. + * + * @param context the context of the caller. + */ + @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) + @NonNull + public static Builder builder(@NonNull Context context) { + TunerUtils.checkTunerPermission(context); + return new Builder(); + } + + /** + * Builder for {@link IpFilterConfiguration}. + */ + public static class Builder extends FilterConfiguration.Builder<Builder> { + private int mMmtpPid; + + private Builder() { + } + + /** + * Sets MMPT PID. + */ + @NonNull + public Builder setMmtpPid(int mmtpPid) { + mMmtpPid = mmtpPid; + return this; + } + + /** + * Builds a {@link IpFilterConfiguration} object. + */ + @NonNull + public MmtpFilterConfiguration build() { + return new MmtpFilterConfiguration(mSettings, mMmtpPid); + } + + @Override + Builder self() { + return this; + } + } } diff --git a/media/java/android/media/tv/tuner/filter/RecordSettings.java b/media/java/android/media/tv/tuner/filter/RecordSettings.java index 701868afc789..483370935352 100644 --- a/media/java/android/media/tv/tuner/filter/RecordSettings.java +++ b/media/java/android/media/tv/tuner/filter/RecordSettings.java @@ -16,18 +16,231 @@ package android.media.tv.tuner.filter; +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.RequiresPermission; +import android.content.Context; +import android.hardware.tv.tuner.V1_0.Constants; import android.media.tv.tuner.TunerConstants; +import android.media.tv.tuner.TunerConstants.ScIndexType; import android.media.tv.tuner.TunerUtils; +import android.media.tv.tuner.filter.FilterConfiguration.FilterType; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; /** * The Settings for the record in DVR. * @hide */ public class RecordSettings extends Settings { - private int mIndexType; - private int mIndexMask; + /** + * Indexes can be tagged through TS (Transport Stream) header. + * + * @hide + */ + @IntDef(flag = true, + prefix = "TS_INDEX_", + value = {TS_INDEX_FIRST_PACKET, TS_INDEX_PAYLOAD_UNIT_START_INDICATOR, + TS_INDEX_CHANGE_TO_NOT_SCRAMBLED, TS_INDEX_CHANGE_TO_EVEN_SCRAMBLED, + TS_INDEX_CHANGE_TO_ODD_SCRAMBLED, TS_INDEX_DISCONTINUITY_INDICATOR, + TS_INDEX_RANDOM_ACCESS_INDICATOR, TS_INDEX_PRIORITY_INDICATOR, + TS_INDEX_PCR_FLAG, TS_INDEX_OPCR_FLAG, TS_INDEX_SPLICING_POINT_FLAG, + TS_INDEX_PRIVATE_DATA, TS_INDEX_ADAPTATION_EXTENSION_FLAG}) + @Retention(RetentionPolicy.SOURCE) + public @interface TsIndexMask {} + + /** + * TS index FIRST_PACKET. + * @hide + */ + public static final int TS_INDEX_FIRST_PACKET = Constants.DemuxTsIndex.FIRST_PACKET; + /** + * TS index PAYLOAD_UNIT_START_INDICATOR. + * @hide + */ + public static final int TS_INDEX_PAYLOAD_UNIT_START_INDICATOR = + Constants.DemuxTsIndex.PAYLOAD_UNIT_START_INDICATOR; + /** + * TS index CHANGE_TO_NOT_SCRAMBLED. + * @hide + */ + public static final int TS_INDEX_CHANGE_TO_NOT_SCRAMBLED = + Constants.DemuxTsIndex.CHANGE_TO_NOT_SCRAMBLED; + /** + * TS index CHANGE_TO_EVEN_SCRAMBLED. + * @hide + */ + public static final int TS_INDEX_CHANGE_TO_EVEN_SCRAMBLED = + Constants.DemuxTsIndex.CHANGE_TO_EVEN_SCRAMBLED; + /** + * TS index CHANGE_TO_ODD_SCRAMBLED. + * @hide + */ + public static final int TS_INDEX_CHANGE_TO_ODD_SCRAMBLED = + Constants.DemuxTsIndex.CHANGE_TO_ODD_SCRAMBLED; + /** + * TS index DISCONTINUITY_INDICATOR. + * @hide + */ + public static final int TS_INDEX_DISCONTINUITY_INDICATOR = + Constants.DemuxTsIndex.DISCONTINUITY_INDICATOR; + /** + * TS index RANDOM_ACCESS_INDICATOR. + * @hide + */ + public static final int TS_INDEX_RANDOM_ACCESS_INDICATOR = + Constants.DemuxTsIndex.RANDOM_ACCESS_INDICATOR; + /** + * TS index PRIORITY_INDICATOR. + * @hide + */ + public static final int TS_INDEX_PRIORITY_INDICATOR = Constants.DemuxTsIndex.PRIORITY_INDICATOR; + /** + * TS index PCR_FLAG. + * @hide + */ + public static final int TS_INDEX_PCR_FLAG = Constants.DemuxTsIndex.PCR_FLAG; + /** + * TS index OPCR_FLAG. + * @hide + */ + public static final int TS_INDEX_OPCR_FLAG = Constants.DemuxTsIndex.OPCR_FLAG; + /** + * TS index SPLICING_POINT_FLAG. + * @hide + */ + public static final int TS_INDEX_SPLICING_POINT_FLAG = + Constants.DemuxTsIndex.SPLICING_POINT_FLAG; + /** + * TS index PRIVATE_DATA. + * @hide + */ + public static final int TS_INDEX_PRIVATE_DATA = Constants.DemuxTsIndex.PRIVATE_DATA; + /** + * TS index ADAPTATION_EXTENSION_FLAG. + * @hide + */ + public static final int TS_INDEX_ADAPTATION_EXTENSION_FLAG = + Constants.DemuxTsIndex.ADAPTATION_EXTENSION_FLAG; + /** + * @hide + */ + @IntDef(flag = true, + prefix = "SC_", + value = { + TunerConstants.SC_INDEX_I_FRAME, + TunerConstants.SC_INDEX_P_FRAME, + TunerConstants.SC_INDEX_B_FRAME, + TunerConstants.SC_INDEX_SEQUENCE, + TunerConstants.SC_HEVC_INDEX_SPS, + TunerConstants.SC_HEVC_INDEX_AUD, + TunerConstants.SC_HEVC_INDEX_SLICE_CE_BLA_W_LP, + TunerConstants.SC_HEVC_INDEX_SLICE_BLA_W_RADL, + TunerConstants.SC_HEVC_INDEX_SLICE_BLA_N_LP, + TunerConstants.SC_HEVC_INDEX_SLICE_IDR_W_RADL, + TunerConstants.SC_HEVC_INDEX_SLICE_IDR_N_LP, + TunerConstants.SC_HEVC_INDEX_SLICE_TRAIL_CRA, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ScIndexMask {} + - public RecordSettings(int mainType) { + private final int mTsIndexMask; + private final int mScIndexType; + private final int mScIndexMask; + + private RecordSettings(int mainType, int tsIndexType, int scIndexType, int scIndexMask) { super(TunerUtils.getFilterSubtype(mainType, TunerConstants.FILTER_SUBTYPE_RECORD)); + mTsIndexMask = tsIndexType; + mScIndexType = scIndexType; + mScIndexMask = scIndexMask; } + + /** + * Gets TS index mask. + */ + @TsIndexMask + public int getTsIndexMask() { + return mTsIndexMask; + } + /** + * Gets Start Code index type. + */ + @ScIndexType + public int getScIndexType() { + return mScIndexType; + } + /** + * Gets Start Code index mask. + */ + @ScIndexMask + public int getScIndexMask() { + return mScIndexMask; + } + + /** + * Creates a builder for {@link RecordSettings}. + * + * @param context the context of the caller. + * @param mainType the filter main type. + */ + @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) + @NonNull + public static Builder builder(@NonNull Context context, @FilterType int mainType) { + TunerUtils.checkTunerPermission(context); + return new Builder(mainType); + } + + /** + * Builder for {@link RecordSettings}. + */ + public static class Builder extends Settings.Builder<Builder> { + private int mTsIndexMask; + private int mScIndexType; + private int mScIndexMask; + + private Builder(int mainType) { + super(mainType); + } + + /** + * Sets TS index mask. + */ + @NonNull + public Builder setTsIndexMask(@TsIndexMask int indexMask) { + mTsIndexMask = indexMask; + return this; + } + /** + * Sets index type. + */ + @NonNull + public Builder setScIndexType(@ScIndexType int indexType) { + mScIndexType = indexType; + return this; + } + /** + * Sets Start Code index mask. + */ + @NonNull + public Builder setScIndexMask(@ScIndexMask int indexMask) { + mScIndexMask = indexMask; + return this; + } + + /** + * Builds a {@link RecordSettings} object. + */ + @NonNull + public RecordSettings build() { + return new RecordSettings(mMainType, mTsIndexMask, mScIndexType, mScIndexMask); + } + + @Override + Builder self() { + return this; + } + } + } diff --git a/media/java/android/media/tv/tuner/filter/SectionSettingsWithSectionBits.java b/media/java/android/media/tv/tuner/filter/SectionSettingsWithSectionBits.java index 414ea6790bf5..0fa982e3dd01 100644 --- a/media/java/android/media/tv/tuner/filter/SectionSettingsWithSectionBits.java +++ b/media/java/android/media/tv/tuner/filter/SectionSettingsWithSectionBits.java @@ -16,18 +16,116 @@ package android.media.tv.tuner.filter; -import java.util.List; +import android.annotation.NonNull; +import android.annotation.RequiresPermission; +import android.content.Context; +import android.media.tv.tuner.TunerUtils; +import android.media.tv.tuner.filter.FilterConfiguration.FilterType; /** - * Bits Settings for Section Filter. + * Bits Settings for Section Filters. * @hide */ public class SectionSettingsWithSectionBits extends SectionSettings { - private List<Byte> mFilter; - private List<Byte> mMask; - private List<Byte> mMode; + private final byte[] mFilter; + private final byte[] mMask; + private final byte[] mMode; - private SectionSettingsWithSectionBits(int mainType) { + + private SectionSettingsWithSectionBits(int mainType, byte[] filter, byte[] mask, byte[] mode) { super(mainType); + mFilter = filter; + mMask = mask; + mMode = mode; + } + + /** + * Gets the bytes configured for Section Filter + */ + public byte[] getFilterBytes() { + return mFilter; + } + /** + * Gets bit mask. + * + * <p>The bits in the bytes are used for filtering. + */ + public byte[] getMask() { + return mMask; + } + /** + * Gets mode. + * + * <p>Do positive match at the bit position of the configured bytes when the bit at same + * position of the mode is 0. + * <p>Do negative match at the bit position of the configured bytes when the bit at same + * position of the mode is 1. + */ + public byte[] getMode() { + return mMode; + } + + /** + * Creates a builder for {@link SectionSettingsWithSectionBits}. + * + * @param context the context of the caller. + * @param mainType the filter main type. + */ + @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) + @NonNull + public static Builder builder(@NonNull Context context, @FilterType int mainType) { + TunerUtils.checkTunerPermission(context); + return new Builder(mainType); + } + + /** + * Builder for {@link SectionSettingsWithSectionBits}. + */ + public static class Builder extends Settings.Builder<Builder> { + private byte[] mFilter; + private byte[] mMask; + private byte[] mMode; + + private Builder(int mainType) { + super(mainType); + } + + /** + * Sets filter bytes. + */ + @NonNull + public Builder setFilter(byte[] filter) { + mFilter = filter; + return this; + } + /** + * Sets bit mask. + */ + @NonNull + public Builder setMask(byte[] mask) { + mMask = mask; + return this; + } + /** + * Sets mode. + */ + @NonNull + public Builder setMode(byte[] mode) { + mMode = mode; + return this; + } + + /** + * Builds a {@link SectionSettingsWithSectionBits} object. + */ + @NonNull + public SectionSettingsWithSectionBits build() { + return new SectionSettingsWithSectionBits(mMainType, mFilter, mMask, mMode); + } + + @Override + Builder self() { + return this; + } } } diff --git a/media/java/android/media/tv/tuner/filter/SectionSettingsWithTableInfo.java b/media/java/android/media/tv/tuner/filter/SectionSettingsWithTableInfo.java index 0df1d7308e60..6542b89478b2 100644 --- a/media/java/android/media/tv/tuner/filter/SectionSettingsWithTableInfo.java +++ b/media/java/android/media/tv/tuner/filter/SectionSettingsWithTableInfo.java @@ -16,15 +16,92 @@ package android.media.tv.tuner.filter; +import android.annotation.NonNull; +import android.annotation.RequiresPermission; +import android.content.Context; +import android.media.tv.tuner.TunerUtils; +import android.media.tv.tuner.filter.FilterConfiguration.FilterType; + /** * Table information for Section Filter. * @hide */ public class SectionSettingsWithTableInfo extends SectionSettings { - private int mTableId; - private int mVersion; + private final int mTableId; + private final int mVersion; - private SectionSettingsWithTableInfo(int mainType) { + private SectionSettingsWithTableInfo(int mainType, int tableId, int version) { super(mainType); + mTableId = tableId; + mVersion = version; + } + + /** + * Gets table ID. + */ + public int getTableId() { + return mTableId; + } + /** + * Gets version. + */ + public int getVersion() { + return mVersion; } + + /** + * Creates a builder for {@link SectionSettingsWithTableInfo}. + * + * @param context the context of the caller. + * @param mainType the filter main type. + */ + @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) + @NonNull + public static Builder builder(@NonNull Context context, @FilterType int mainType) { + TunerUtils.checkTunerPermission(context); + return new Builder(mainType); + } + + /** + * Builder for {@link SectionSettingsWithTableInfo}. + */ + public static class Builder extends Settings.Builder<Builder> { + private int mTableId; + private int mVersion; + + private Builder(int mainType) { + super(mainType); + } + + /** + * Sets table ID. + */ + @NonNull + public Builder setTableId(int tableId) { + mTableId = tableId; + return this; + } + /** + * Sets version. + */ + @NonNull + public Builder setVersion(int version) { + mVersion = version; + return this; + } + + /** + * Builds a {@link SectionSettingsWithTableInfo} object. + */ + @NonNull + public SectionSettingsWithTableInfo build() { + return new SectionSettingsWithTableInfo(mMainType, mTableId, mVersion); + } + + @Override + Builder self() { + return this; + } + } + } diff --git a/media/java/android/media/tv/tuner/filter/Settings.java b/media/java/android/media/tv/tuner/filter/Settings.java index 91559260031c..d697280a4106 100644 --- a/media/java/android/media/tv/tuner/filter/Settings.java +++ b/media/java/android/media/tv/tuner/filter/Settings.java @@ -39,4 +39,20 @@ public abstract class Settings { public int getType() { return mType; } + + + /** + * Builder for {@link Settings}. + * + * @param <T> The subclass to be built. + * @hide + */ + public abstract static class Builder<T extends Builder<T>> { + /* package */ final int mMainType; + + /* package */ Builder(int mainType) { + mMainType = mainType; + } + /* package */ abstract T self(); + } } diff --git a/media/java/android/media/tv/tuner/filter/TlvFilterConfiguration.java b/media/java/android/media/tv/tuner/filter/TlvFilterConfiguration.java index de8ee754a28c..eb97fc04362c 100644 --- a/media/java/android/media/tv/tuner/filter/TlvFilterConfiguration.java +++ b/media/java/android/media/tv/tuner/filter/TlvFilterConfiguration.java @@ -16,21 +16,118 @@ package android.media.tv.tuner.filter; +import android.annotation.NonNull; +import android.annotation.RequiresPermission; +import android.content.Context; +import android.media.tv.tuner.TunerUtils; + /** * Filter configuration for a TLV filter. * @hide */ public class TlvFilterConfiguration extends FilterConfiguration { - private int mPacketType; - private boolean mIsCompressedIpPacket; - private boolean mPassthrough; + private final int mPacketType; + private final boolean mIsCompressedIpPacket; + private final boolean mPassthrough; - public TlvFilterConfiguration(Settings settings) { + public TlvFilterConfiguration(Settings settings, int packetType, boolean isCompressed, + boolean passthrough) { super(settings); + mPacketType = packetType; + mIsCompressedIpPacket = isCompressed; + mPassthrough = passthrough; } @Override public int getType() { return FilterConfiguration.FILTER_TYPE_TLV; } + + /** + * Gets packet type. + */ + @FilterConfiguration.PacketType + public int getPacketType() { + return mPacketType; + } + /** + * Checks whether the data is compressed IP packet. + * + * @return {@code true} if the filtered data is compressed IP packet; {@code false} otherwise. + */ + public boolean isCompressedIpPacket() { + return mIsCompressedIpPacket; + } + /** + * Checks whether it's passthrough. + * + * @return {@code true} if the data from TLV subtype go to next filter directly; + * {@code false} otherwise. + */ + public boolean isPassthrough() { + return mPassthrough; + } + + /** + * Creates a builder for {@link TlvFilterConfiguration}. + * + * @param context the context of the caller. + */ + @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) + @NonNull + public static Builder builder(@NonNull Context context) { + TunerUtils.checkTunerPermission(context); + return new Builder(); + } + + /** + * Builder for {@link TlvFilterConfiguration}. + */ + public static class Builder extends FilterConfiguration.Builder<Builder> { + private int mPacketType; + private boolean mIsCompressedIpPacket; + private boolean mPassthrough; + + private Builder() { + } + + /** + * Sets packet type. + */ + @NonNull + public Builder setPacketType(@FilterConfiguration.PacketType int packetType) { + mPacketType = packetType; + return this; + } + /** + * Sets whether the data is compressed IP packet. + */ + @NonNull + public Builder setIsCompressedIpPacket(boolean isCompressedIpPacket) { + mIsCompressedIpPacket = isCompressedIpPacket; + return this; + } + /** + * Sets whether it's passthrough. + */ + @NonNull + public Builder setPassthrough(boolean passthrough) { + mPassthrough = passthrough; + return this; + } + + /** + * Builds a {@link TlvFilterConfiguration} object. + */ + @NonNull + public TlvFilterConfiguration build() { + return new TlvFilterConfiguration( + mSettings, mPacketType, mIsCompressedIpPacket, mPassthrough); + } + + @Override + Builder self() { + return this; + } + } } diff --git a/media/java/android/media/tv/tuner/filter/TsRecordEvent.java b/media/java/android/media/tv/tuner/filter/TsRecordEvent.java index fa4dd72e3eda..1b8485e22dcf 100644 --- a/media/java/android/media/tv/tuner/filter/TsRecordEvent.java +++ b/media/java/android/media/tv/tuner/filter/TsRecordEvent.java @@ -16,12 +16,8 @@ package android.media.tv.tuner.filter; -import android.annotation.IntDef; import android.media.tv.tuner.Tuner.Filter; -import android.media.tv.tuner.TunerConstants; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; /** * Filter event sent from {@link Filter} objects for TS record data. @@ -29,47 +25,17 @@ import java.lang.annotation.RetentionPolicy; * @hide */ public class TsRecordEvent extends FilterEvent { - /** - * @hide - */ - @IntDef(flag = true, value = { - TunerConstants.TS_INDEX_FIRST_PACKET, - TunerConstants.TS_INDEX_PAYLOAD_UNIT_START_INDICATOR, - TunerConstants.TS_INDEX_CHANGE_TO_NOT_SCRAMBLED, - TunerConstants.TS_INDEX_CHANGE_TO_EVEN_SCRAMBLED, - TunerConstants.TS_INDEX_CHANGE_TO_ODD_SCRAMBLED, - TunerConstants.TS_INDEX_DISCONTINUITY_INDICATOR, - TunerConstants.TS_INDEX_RANDOM_ACCESS_INDICATOR, - TunerConstants.TS_INDEX_PRIORITY_INDICATOR, - TunerConstants.TS_INDEX_PCR_FLAG, - TunerConstants.TS_INDEX_OPCR_FLAG, - TunerConstants.TS_INDEX_SPLICING_POINT_FLAG, - TunerConstants.TS_INDEX_PRIVATE_DATA, - TunerConstants.TS_INDEX_ADAPTATION_EXTENSION_FLAG, - TunerConstants.SC_INDEX_I_FRAME, - TunerConstants.SC_INDEX_P_FRAME, - TunerConstants.SC_INDEX_B_FRAME, - TunerConstants.SC_INDEX_SEQUENCE, - TunerConstants.SC_HEVC_INDEX_SPS, - TunerConstants.SC_HEVC_INDEX_AUD, - TunerConstants.SC_HEVC_INDEX_SLICE_CE_BLA_W_LP, - TunerConstants.SC_HEVC_INDEX_SLICE_BLA_W_RADL, - TunerConstants.SC_HEVC_INDEX_SLICE_BLA_N_LP, - TunerConstants.SC_HEVC_INDEX_SLICE_IDR_W_RADL, - TunerConstants.SC_HEVC_INDEX_SLICE_IDR_N_LP, - TunerConstants.SC_HEVC_INDEX_SLICE_TRAIL_CRA, - }) - @Retention(RetentionPolicy.SOURCE) - public @interface IndexMask {} private final int mPid; - private final int mIndexMask; + private final int mTsIndexMask; + private final int mScIndexMask; private final long mByteNumber; // This constructor is used by JNI code only - private TsRecordEvent(int pid, int indexMask, long byteNumber) { + private TsRecordEvent(int pid, int tsIndexMask, int scIndexMask, long byteNumber) { mPid = pid; - mIndexMask = indexMask; + mTsIndexMask = tsIndexMask; + mScIndexMask = scIndexMask; mByteNumber = byteNumber; } @@ -81,13 +47,20 @@ public class TsRecordEvent extends FilterEvent { } /** - * Gets index mask. + * Gets TS index mask. + */ + @RecordSettings.TsIndexMask + public int getTsIndexMask() { + return mTsIndexMask; + } + /** + * Gets SC index mask. * - * <p>The index type is one of TS, SC, and SC-HEVC, and is set when configuring the filter. + * <p>The index type is SC or SC-HEVC, and is set when configuring the filter. */ - @IndexMask - public int getIndexMask() { - return mIndexMask; + @RecordSettings.ScIndexMask + public int getScIndexMask() { + return mScIndexMask; } /** |