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.Nullable;
22 import android.annotation.SystemApi;
23 import android.hardware.tv.tuner.V1_0.Constants;
24 
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 
28 /**
29  * Filter configuration for a ALP filter.
30  *
31  * @hide
32  */
33 @SystemApi
34 public final class AlpFilterConfiguration extends FilterConfiguration {
35     /**
36      * IPv4 packet type.
37      */
38     public static final int PACKET_TYPE_IPV4 = 0;
39     /**
40      * Compressed packet type.
41      */
42     public static final int PACKET_TYPE_COMPRESSED = 2;
43     /**
44      * Signaling packet type.
45      */
46     public static final int PACKET_TYPE_SIGNALING = 4;
47     /**
48      * Extension packet type.
49      */
50     public static final int PACKET_TYPE_EXTENSION = 6;
51     /**
52      * MPEG-2 TS packet type.
53      */
54     public static final int PACKET_TYPE_MPEG2_TS = 7;
55 
56     /** @hide */
57     @Retention(RetentionPolicy.SOURCE)
58     @IntDef(prefix = "LENGTH_TYPE_", value =
59             {LENGTH_TYPE_UNDEFINED, LENGTH_TYPE_WITHOUT_ADDITIONAL_HEADER,
60             LENGTH_TYPE_WITH_ADDITIONAL_HEADER})
61     public @interface LengthType {}
62 
63     /**
64      * Length type not defined.
65      */
66     public static final int LENGTH_TYPE_UNDEFINED = Constants.DemuxAlpLengthType.UNDEFINED;
67     /**
68      * Length does NOT include additional header.
69      */
70     public static final int LENGTH_TYPE_WITHOUT_ADDITIONAL_HEADER =
71             Constants.DemuxAlpLengthType.WITHOUT_ADDITIONAL_HEADER;
72     /**
73      * Length includes additional header.
74      */
75     public static final int LENGTH_TYPE_WITH_ADDITIONAL_HEADER =
76             Constants.DemuxAlpLengthType.WITH_ADDITIONAL_HEADER;
77 
78 
79     private final int mPacketType;
80     private final int mLengthType;
81 
AlpFilterConfiguration(Settings settings, int packetType, int lengthType)82     private AlpFilterConfiguration(Settings settings, int packetType, int lengthType) {
83         super(settings);
84         mPacketType = packetType;
85         mLengthType = lengthType;
86     }
87 
88     @Override
getType()89     public int getType() {
90         return Filter.TYPE_ALP;
91     }
92 
93     /**
94      * Gets packet type.
95      *
96      * <p>The meaning of each packet type value is shown in ATSC A/330:2019 table 5.2.
97      */
getPacketType()98     public int getPacketType() {
99         return mPacketType;
100     }
101     /**
102      * Gets length type.
103      */
104     @LengthType
getLengthType()105     public int getLengthType() {
106         return mLengthType;
107     }
108 
109     /**
110      * Creates a builder for {@link AlpFilterConfiguration}.
111      */
112     @NonNull
builder()113     public static Builder builder() {
114         return new Builder();
115     }
116 
117     /**
118      * Builder for {@link AlpFilterConfiguration}.
119      */
120     public static final class Builder {
121         private int mPacketType = PACKET_TYPE_IPV4;
122         private int mLengthType = LENGTH_TYPE_UNDEFINED;
123         private Settings mSettings;
124 
Builder()125         private Builder() {
126         }
127 
128         /**
129          * Sets packet type.
130          *
131          * <p>The meaning of each packet type value is shown in ATSC A/330:2019 table 5.2.
132          * <p>Default value is {@link #PACKET_TYPE_IPV4}.
133          */
134         @NonNull
setPacketType(int packetType)135         public Builder setPacketType(int packetType) {
136             mPacketType = packetType;
137             return this;
138         }
139         /**
140          * Sets length type.
141          *
142          * <p>Default value is {@link #LENGTH_TYPE_UNDEFINED}.
143          */
144         @NonNull
setLengthType(@engthType int lengthType)145         public Builder setLengthType(@LengthType int lengthType) {
146             mLengthType = lengthType;
147             return this;
148         }
149 
150         /**
151          * Sets filter settings.
152          */
153         @NonNull
setSettings(@ullable Settings settings)154         public Builder setSettings(@Nullable Settings settings) {
155             mSettings = settings;
156             return this;
157         }
158 
159         /**
160          * Builds a {@link AlpFilterConfiguration} object.
161          */
162         @NonNull
build()163         public AlpFilterConfiguration build() {
164             return new AlpFilterConfiguration(mSettings, mPacketType, mLengthType);
165         }
166     }
167 }
168