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.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 
23 /**
24  * Filter configuration for a TLV filter.
25  *
26  * @hide
27  */
28 @SystemApi
29 public final class TlvFilterConfiguration extends FilterConfiguration {
30     /**
31      * IPv4 packet type.
32      */
33     public static final int PACKET_TYPE_IPV4 = 0x01;
34     /**
35      * IPv6 packet type.
36      */
37     public static final int PACKET_TYPE_IPV6 = 0x02;
38     /**
39      * Compressed packet type.
40      */
41     public static final int PACKET_TYPE_COMPRESSED = 0x03;
42     /**
43      * Signaling packet type.
44      */
45     public static final int PACKET_TYPE_SIGNALING = 0xFE;
46     /**
47      * NULL packet type.
48      */
49     public static final int PACKET_TYPE_NULL = 0xFF;
50 
51     private final int mPacketType;
52     private final boolean mIsCompressedIpPacket;
53     private final boolean mPassthrough;
54 
TlvFilterConfiguration(Settings settings, int packetType, boolean isCompressed, boolean passthrough)55     private TlvFilterConfiguration(Settings settings, int packetType, boolean isCompressed,
56             boolean passthrough) {
57         super(settings);
58         mPacketType = packetType;
59         mIsCompressedIpPacket = isCompressed;
60         mPassthrough = passthrough;
61     }
62 
63     @Override
getType()64     public int getType() {
65         return Filter.TYPE_TLV;
66     }
67 
68     /**
69      * Gets packet type.
70      *
71      * <p>The description of each packet type value is shown in ITU-R BT.1869 table 2.
72      */
getPacketType()73     public int getPacketType() {
74         return mPacketType;
75     }
76     /**
77      * Checks whether the data is compressed IP packet.
78      *
79      * @return {@code true} if the filtered data is compressed IP packet; {@code false} otherwise.
80      */
isCompressedIpPacket()81     public boolean isCompressedIpPacket() {
82         return mIsCompressedIpPacket;
83     }
84     /**
85      * Checks whether it's passthrough.
86      *
87      * @return {@code true} if the data from TLV subtype go to next filter directly;
88      *         {@code false} otherwise.
89      */
isPassthrough()90     public boolean isPassthrough() {
91         return mPassthrough;
92     }
93 
94     /**
95      * Creates a builder for {@link TlvFilterConfiguration}.
96      */
97     @NonNull
builder()98     public static Builder builder() {
99         return new Builder();
100     }
101 
102     /**
103      * Builder for {@link TlvFilterConfiguration}.
104      */
105     public static final class Builder {
106         private int mPacketType = PACKET_TYPE_NULL;
107         private boolean mIsCompressedIpPacket = false;
108         private boolean mPassthrough = false;
109         private Settings mSettings;
110 
Builder()111         private Builder() {
112         }
113 
114         /**
115          * Sets packet type.
116          *
117          * <p>The description of each packet type value is shown in ITU-R BT.1869 table 2.
118          * <p>Default value is {@link #PACKET_TYPE_NULL}.
119          */
120         @NonNull
setPacketType(int packetType)121         public Builder setPacketType(int packetType) {
122             mPacketType = packetType;
123             return this;
124         }
125         /**
126          * Sets whether the data is compressed IP packet.
127          *
128          * <p>Default value is {@code false}.
129          */
130         @NonNull
setCompressedIpPacket(boolean isCompressedIpPacket)131         public Builder setCompressedIpPacket(boolean isCompressedIpPacket) {
132             mIsCompressedIpPacket = isCompressedIpPacket;
133             return this;
134         }
135         /**
136          * Sets whether it's passthrough.
137          *
138          * <p>Default value is {@code false}.
139          */
140         @NonNull
setPassthrough(boolean passthrough)141         public Builder setPassthrough(boolean passthrough) {
142             mPassthrough = passthrough;
143             return this;
144         }
145 
146         /**
147          * Sets filter settings.
148          */
149         @NonNull
setSettings(@ullable Settings settings)150         public Builder setSettings(@Nullable Settings settings) {
151             mSettings = settings;
152             return this;
153         }
154 
155         /**
156          * Builds a {@link TlvFilterConfiguration} object.
157          */
158         @NonNull
build()159         public TlvFilterConfiguration build() {
160             return new TlvFilterConfiguration(
161                     mSettings, mPacketType, mIsCompressedIpPacket, mPassthrough);
162         }
163     }
164 }
165