• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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/tunerresourcemanager/ITunerResourceManager.h>
21 #include <aidl/android/media/tv/tuner/ITunerService.h>
22 #include <aidl/android/media/tv/tuner/TunerFrontendInfo.h>
23 #include <android/binder_parcel_utils.h>
24 #include <android/hardware/tv/tuner/1.1/ITuner.h>
25 #include <android/hardware/tv/tuner/1.1/types.h>
26 
27 #include "DemuxClient.h"
28 #include "ClientHelper.h"
29 #include "FrontendClient.h"
30 #include "DescramblerClient.h"
31 #include "LnbClient.h"
32 
33 using Status = ::ndk::ScopedAStatus;
34 
35 using ::aidl::android::media::tv::tuner::TunerDemuxCapabilities;
36 using ::aidl::android::media::tv::tuner::ITunerService;
37 using ::aidl::android::media::tv::tuner::TunerFrontendInfo;
38 using ::aidl::android::media::tv::tunerresourcemanager::ITunerResourceManager;
39 
40 using ::android::hardware::tv::tuner::V1_0::DemuxCapabilities;
41 using ::android::hardware::tv::tuner::V1_0::FrontendId;
42 using ::android::hardware::tv::tuner::V1_0::ITuner;
43 using ::android::hardware::tv::tuner::V1_0::LnbId;
44 using ::android::hardware::tv::tuner::V1_0::Result;
45 using ::android::hardware::tv::tuner::V1_1::FrontendDtmbCapabilities;
46 
47 using namespace std;
48 
49 namespace android {
50 
51 const static int TUNER_HAL_VERSION_UNKNOWN = 0;
52 const static int TUNER_HAL_VERSION_1_0 = 1 << 16;
53 const static int TUNER_HAL_VERSION_1_1 = (1 << 16) | 1;
54 
55 typedef enum {
56     FRONTEND,
57     LNB,
58     DEMUX,
59     DESCRAMBLER,
60 } TunerResourceType;
61 
62 struct TunerClient : public RefBase {
63 
64 public:
65     TunerClient();
66     ~TunerClient();
67 
68     /**
69      * Retrieve all the frontend ids.
70      *
71      * @return a list of the available frontend ids
72      */
73     vector<FrontendId> getFrontendIds();
74 
75     /**
76      * Open a new interface of FrontendClient given a frontendHandle.
77      *
78      * @param frontendHandle the handle of the frontend granted by TRM.
79      * @return a newly created FrontendClient interface.
80      */
81     sp<FrontendClient> openFrontend(int frontendHandle);
82 
83     /**
84      * Retrieve the granted frontend's information.
85      *
86      * @param id the id of the frontend granted by TRM.
87      * @return the information for the frontend.
88      */
89     shared_ptr<FrontendInfo> getFrontendInfo(int id);
90 
91     /**
92      * Retrieve the DTMB frontend's capabilities.
93      *
94      * @param id the id of the DTMB frontend.
95      * @return the capabilities of the frontend.
96      */
97     shared_ptr<FrontendDtmbCapabilities> getFrontendDtmbCapabilities(int id);
98 
99     /**
100      * Open a new interface of DemuxClient given a demuxHandle.
101      *
102      * @param demuxHandle the handle of the demux granted by TRM.
103      * @return a newly created DemuxClient interface.
104      */
105     sp<DemuxClient> openDemux(int demuxHandle);
106 
107     /**
108      * Retrieve the Demux capabilities.
109      *
110      * @return the demux’s capabilities.
111      */
112     shared_ptr<DemuxCapabilities> getDemuxCaps();
113 
114     /**
115      * Open a new interface of DescramblerClient given a descramblerHandle.
116      *
117      * @param descramblerHandle the handle of the descrambler granted by TRM.
118      * @return a newly created DescramblerClient interface.
119      */
120     sp<DescramblerClient> openDescrambler(int descramblerHandle);
121 
122     /**
123      * Open a new interface of LnbClient given an lnbHandle.
124      *
125      * @param lnbHandle the handle of the LNB granted by TRM.
126      * @return a newly created LnbClient interface.
127      */
128     sp<LnbClient> openLnb(int lnbHandle);
129 
130     /**
131      * Open a new interface of LnbClient given a LNB name.
132      *
133      * @param lnbName the name for an external LNB to be opened.
134      * @return a newly created LnbClient interface.
135      */
136     sp<LnbClient> openLnbByName(string lnbName);
137 
138     /**
139      * Get the current Tuner HAL version. The high 16 bits are the major version number
140      * while the low 16 bits are the minor version. Default value is unknown version 0.
141      */
getHalTunerVersionTunerClient142     int getHalTunerVersion() { return mTunerVersion; }
143 
144 private:
145     sp<ITuner> getHidlTuner();
146     sp<IFrontend> openHidlFrontendById(int id);
147     sp<IDemux> openHidlDemux(int& demuxId);
148     Result getHidlFrontendInfo(int id, FrontendInfo& info);
149     sp<ILnb> openHidlLnbById(int id);
150     sp<ILnb> openHidlLnbByName(string name, LnbId& lnbId);
151     sp<IDescrambler> openHidlDescrambler();
152     vector<int> getLnbHandles();
153     DemuxCapabilities getHidlDemuxCaps(TunerDemuxCapabilities& aidlCaps);
154     FrontendInfo frontendInfoAidlToHidl(TunerFrontendInfo aidlFrontendInfo);
155     void updateTunerResources();
156     void updateFrontendResources();
157     void updateLnbResources();
158 
159     int getResourceIdFromHandle(int handle, int resourceType);
160 
161     int getResourceHandleFromId(int id, int resourceType);
162 
163     /**
164      * An AIDL Tuner Service Singleton assigned at the first time the Tuner Client
165      * connects with the Tuner Service. Default null when the service does not exist.
166      */
167     static shared_ptr<ITunerService> mTunerService;
168 
169     /**
170      * A Tuner 1.0 HAL interface that is ready before connecting to the TunerService
171      * This is a temprary connection before the Tuner Framework fully migrates to the TunerService.
172      * Default null.
173      */
174     static sp<ITuner> mTuner;
175 
176     /**
177      * A Tuner 1.1 HAL interface that is ready before connecting to the TunerService
178      * This is a temprary connection before the Tuner Framework fully migrates to the TunerService.
179      * Default null.
180      */
181     static sp<::android::hardware::tv::tuner::V1_1::ITuner> mTuner_1_1;
182 
183     // An integer that carries the Tuner version. The high 16 bits are the major version number
184     // while the low 16 bits are the minor version. Default value is unknown version 0.
185     static int mTunerVersion;
186 
187     shared_ptr<ITunerResourceManager> mTunerResourceManager;
188 
189     int mResourceRequestCount = 0;
190 };
191 }  // namespace android
192 
193 #endif  // _ANDROID_MEDIA_TV_TUNER_CLIENT_H_
194