1 /*
2  * Copyright 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 #ifndef _ANDROID_MEDIA_TV_TUNER_CLIENT_H_
18 #define _ANDROID_MEDIA_TV_TUNER_CLIENT_H_
19 
20 #include <aidl/android/media/tv/tuner/ITunerService.h>
21 #include <android/binder_parcel_utils.h>
22 
23 #include "ClientHelper.h"
24 #include "DemuxClient.h"
25 #include "DescramblerClient.h"
26 #include "FilterClient.h"
27 #include "FilterClientCallback.h"
28 #include "FrontendClient.h"
29 #include "LnbClient.h"
30 
31 using Status = ::ndk::ScopedAStatus;
32 
33 using ::aidl::android::hardware::tv::tuner::DemuxCapabilities;
34 using ::aidl::android::hardware::tv::tuner::DemuxInfo;
35 using ::aidl::android::hardware::tv::tuner::FrontendInfo;
36 using ::aidl::android::hardware::tv::tuner::FrontendType;
37 using ::aidl::android::hardware::tv::tuner::Result;
38 using ::aidl::android::media::tv::tuner::ITunerService;
39 
40 using namespace std;
41 
42 namespace android {
43 
44 const static int32_t TUNER_HAL_VERSION_UNKNOWN = 0;
45 const static int32_t TUNER_HAL_VERSION_1_0 = 1 << 16;
46 const static int32_t TUNER_HAL_VERSION_1_1 = (1 << 16) | 1;
47 const static int32_t TUNER_HAL_VERSION_2_0 = 2 << 16;
48 
49 struct TunerClient : public RefBase {
50 
51 public:
52     TunerClient();
53     ~TunerClient();
54 
55     /**
56      * Retrieve all the frontend ids.
57      *
58      * @return a list of the available frontend ids
59      */
60     vector<int32_t> getFrontendIds();
61 
62     /**
63      * Open a new interface of FrontendClient given a frontendHandle.
64      *
65      * @param frontendHandle the handle of the frontend granted by TRM.
66      * @return a newly created FrontendClient interface.
67      */
68     sp<FrontendClient> openFrontend(int32_t frontendHandle);
69 
70     /**
71      * Retrieve the granted frontend's information.
72      *
73      * @param id the id of the frontend granted by TRM.
74      * @return the information for the frontend.
75      */
76     shared_ptr<FrontendInfo> getFrontendInfo(int32_t id);
77 
78     /**
79      * Open a new interface of DemuxClient given a demuxHandle.
80      *
81      * @param demuxHandle the handle of the demux granted by TRM.
82      * @return a newly created DemuxClient interface.
83      */
84     sp<DemuxClient> openDemux(int32_t demuxHandle);
85 
86     /**
87      * Retrieve the DemuxInfo of a specific demux
88      *
89      * @param demuxHandle the handle of the demux to query demux info for
90      * @return the demux info
91      */
92     shared_ptr<DemuxInfo> getDemuxInfo(int32_t demuxHandle);
93 
94     /**
95      * Retrieve a list of demux info
96      *
97      * @return a list of DemuxInfo
98      */
99     void getDemuxInfoList(vector<DemuxInfo>* demuxInfoList);
100 
101     /**
102      * Retrieve the Demux capabilities.
103      *
104      * @return the demux’s capabilities.
105      */
106     shared_ptr<DemuxCapabilities> getDemuxCaps();
107 
108     /**
109      * Open a new interface of DescramblerClient given a descramblerHandle.
110      *
111      * @param descramblerHandle the handle of the descrambler granted by TRM.
112      * @return a newly created DescramblerClient interface.
113      */
114     sp<DescramblerClient> openDescrambler(int32_t descramblerHandle);
115 
116     /**
117      * Open a new interface of LnbClient given an lnbHandle.
118      *
119      * @param lnbHandle the handle of the LNB granted by TRM.
120      * @return a newly created LnbClient interface.
121      */
122     sp<LnbClient> openLnb(int32_t lnbHandle);
123 
124     /**
125      * Open a new interface of LnbClient given a LNB name.
126      *
127      * @param lnbName the name for an external LNB to be opened.
128      * @return a newly created LnbClient interface.
129      */
130     sp<LnbClient> openLnbByName(string lnbName);
131 
132     /**
133      * Get the current Tuner HAL version. The high 16 bits are the major version number
134      * while the low 16 bits are the minor version. Default value is unknown version 0.
135      */
getHalTunerVersionTunerClient136     int32_t getHalTunerVersion() { return mTunerVersion; }
137 
138     /**
139      * Open a new shared filter client.
140      *
141      * @param filterToken the shared filter token created by FilterClient.
142      * @param cb the FilterClientCallback to receive filter events.
143      * @return a newly created TunerFilter interface.
144      */
145     sp<FilterClient> openSharedFilter(const string& filterToken, sp<FilterClientCallback> cb);
146 
147     /**
148      * Enable or Disable Low Noise Amplifier (LNA).
149      */
150     Result setLna(bool bEnable);
151 
152     /**
153      * Set the maximum frontend number of a given frontend type.
154      *
155      * @param frontendType the frontend type which maximum number will be set.
156      * @param maxNumber the new maximum number.
157      */
158     Result setMaxNumberOfFrontends(FrontendType frontendType, int32_t maxNumber);
159 
160     /**
161      * Get the maximum frontend number of a given frontend type.
162      *
163      * @param frontendType the frontend type which maximum number will be queried.
164      */
165     int getMaxNumberOfFrontends(FrontendType frontendType);
166 
167     /**
168      * Is Low Noise Amplifier (LNA) supported.
169      */
170     bool isLnaSupported();
171 
172 private:
173     /**
174      * An AIDL Tuner Service assigned at the first time the Tuner Client connects with
175      * the Tuner Service. null when the service does not exist. The tuner client in JNI
176      * will be singleton, so this Tuner Service client will be singleton too.
177      */
178     shared_ptr<ITunerService> mTunerService;
179 
180     // An integer that carries the Tuner version. The high 16 bits are the major version number
181     // while the low 16 bits are the minor version. Default value is unknown version 0.
182     static int32_t mTunerVersion;
183 };
184 }  // namespace android
185 
186 #endif  // _ANDROID_MEDIA_TV_TUNER_CLIENT_H_
187