1 /*
2  * Copyright (C) 2021 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;
18 
19 import android.annotation.NonNull;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 /**
24  * A request for PES from broadcast signal.
25  */
26 public final class PesRequest extends BroadcastInfoRequest implements Parcelable {
27     private static final @TvInputManager.BroadcastInfoType int REQUEST_TYPE =
28             TvInputManager.BROADCAST_INFO_TYPE_PES;
29 
30     public static final @NonNull Parcelable.Creator<PesRequest> CREATOR =
31             new Parcelable.Creator<PesRequest>() {
32                 @Override
33                 public PesRequest createFromParcel(Parcel source) {
34                     source.readInt();
35                     return createFromParcelBody(source);
36                 }
37 
38                 @Override
39                 public PesRequest[] newArray(int size) {
40                     return new PesRequest[size];
41                 }
42             };
43 
44     private final int mTsPid;
45     private final int mStreamId;
46 
createFromParcelBody(Parcel in)47     static PesRequest createFromParcelBody(Parcel in) {
48         return new PesRequest(in);
49     }
50 
PesRequest(int requestId, @RequestOption int option, int tsPid, int streamId)51     public PesRequest(int requestId, @RequestOption int option, int tsPid, int streamId) {
52         super(REQUEST_TYPE, requestId, option);
53         mTsPid = tsPid;
54         mStreamId = streamId;
55     }
56 
PesRequest(Parcel source)57     PesRequest(Parcel source) {
58         super(REQUEST_TYPE, source);
59         mTsPid = source.readInt();
60         mStreamId = source.readInt();
61     }
62 
63     /**
64      * Gets the packet identifier (PID) of the TS (transport stream).
65      */
getTsPid()66     public int getTsPid() {
67         return mTsPid;
68     }
69 
70     /**
71      * Gets the StreamID of requested PES.
72      */
getStreamId()73     public int getStreamId() {
74         return mStreamId;
75     }
76 
77     @Override
describeContents()78     public int describeContents() {
79         return 0;
80     }
81 
82     @Override
writeToParcel(@onNull Parcel dest, int flags)83     public void writeToParcel(@NonNull Parcel dest, int flags) {
84         super.writeToParcel(dest, flags);
85         dest.writeInt(mTsPid);
86         dest.writeInt(mStreamId);
87     }
88 }
89