blob: 8a1181a38fe25c476fa258261a19d80fc696410e [file] [log] [blame]
Amy Zhangbf68a162020-11-23 17:42:40 -08001/*
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
Amy Zhang39a3fa42020-12-21 16:56:03 -080020#include <aidl/android/media/tv/tunerresourcemanager/ITunerResourceManager.h>
Amy Zhangbf68a162020-11-23 17:42:40 -080021#include <aidl/android/media/tv/tuner/ITunerService.h>
Amy Zhangd1fd5ac2021-01-13 16:30:24 -080022#include <aidl/android/media/tv/tuner/TunerFrontendInfo.h>
Amy Zhangbf68a162020-11-23 17:42:40 -080023#include <android/hardware/tv/tuner/1.1/ITuner.h>
24#include <android/hardware/tv/tuner/1.1/types.h>
25
26#include "FrontendClient.h"
Amy Zhang6bfeaa02020-11-30 15:16:39 -080027#include "DemuxClient.h"
Amy Zhangb0f63ab2021-01-06 17:19:27 -080028#include "DescramblerClient.h"
29#include "LnbClient.h"
Amy Zhangbf68a162020-11-23 17:42:40 -080030
31using ::aidl::android::media::tv::tuner::ITunerService;
Amy Zhangd1fd5ac2021-01-13 16:30:24 -080032using ::aidl::android::media::tv::tuner::TunerFrontendInfo;
Amy Zhang39a3fa42020-12-21 16:56:03 -080033using ::aidl::android::media::tv::tunerresourcemanager::ITunerResourceManager;
Amy Zhangbf68a162020-11-23 17:42:40 -080034
35using ::android::hardware::tv::tuner::V1_0::DemuxCapabilities;
36using ::android::hardware::tv::tuner::V1_0::FrontendId;
37using ::android::hardware::tv::tuner::V1_0::ITuner;
Amy Zhang39a3fa42020-12-21 16:56:03 -080038using ::android::hardware::tv::tuner::V1_0::LnbId;
Amy Zhangbf68a162020-11-23 17:42:40 -080039using ::android::hardware::tv::tuner::V1_0::Result;
40using ::android::hardware::tv::tuner::V1_1::FrontendDtmbCapabilities;
41
42using namespace std;
43
44namespace android {
45
Amy Zhang210c26a2021-01-12 11:25:27 -080046typedef enum {
47 FRONTEND,
48 LNB,
49 DEMUX,
50 DESCRAMBLER,
51} TunerResourceType;
52
Amy Zhangbf68a162020-11-23 17:42:40 -080053struct TunerClient : public RefBase {
54
55public:
56 TunerClient();
57 ~TunerClient();
58
59 /**
60 * Retrieve all the frontend ids.
61 *
62 * @return a list of the available frontend ids
63 */
64 vector<FrontendId> getFrontendIds();
65
66 /**
67 * Open a new interface of FrontendClient given a frontendHandle.
68 *
69 * @param frontendHandle the handle of the frontend granted by TRM.
70 * @return a newly created FrontendClient interface.
71 */
72 sp<FrontendClient> openFrontend(int frontendHandle);
73
74 /**
75 * Retrieve the granted frontend's information.
76 *
77 * @param id the id of the frontend granted by TRM.
78 * @return the information for the frontend.
79 */
80 shared_ptr<FrontendInfo> getFrontendInfo(int id);
81
82 /**
83 * Retrieve the DTMB frontend's capabilities.
84 *
85 * @param id the id of the DTMB frontend.
86 * @return the capabilities of the frontend.
87 */
88 shared_ptr<FrontendDtmbCapabilities> getFrontendDtmbCapabilities(int id);
89
90 /**
Amy Zhang6bfeaa02020-11-30 15:16:39 -080091 * Open a new interface of DemuxClient given a demuxHandle.
92 *
93 * @param demuxHandle the handle of the demux granted by TRM.
94 * @return a newly created DemuxClient interface.
95 */
96 sp<DemuxClient> openDemux(int demuxHandle);
97
98 /**
99 * Retrieve the Demux capabilities.
100 *
101 * @return the demux’s capabilities.
102 */
Amy Zhang90a50b42021-01-11 16:58:59 -0800103 shared_ptr<DemuxCapabilities> getDemuxCaps();
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800104
105 /**
106 * Open a new interface of DescramblerClient given a descramblerHandle.
107 *
108 * @param descramblerHandle the handle of the descrambler granted by TRM.
109 * @return a newly created DescramblerClient interface.
110 */
111 sp<DescramblerClient> openDescrambler(int descramblerHandle);
112
113 /**
114 * Open a new interface of LnbClient given an lnbHandle.
115 *
116 * @param lnbHandle the handle of the LNB granted by TRM.
117 * @return a newly created LnbClient interface.
118 */
119 sp<LnbClient> openLnb(int lnbHandle);
120
121 /**
122 * Open a new interface of LnbClient given a LNB name.
123 *
124 * @param lnbName the name for an external LNB to be opened.
125 * @return a newly created LnbClient interface.
126 */
127 sp<LnbClient> openLnbByName(string lnbName);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800128
129 /**
Amy Zhangbf68a162020-11-23 17:42:40 -0800130 * Get the current Tuner HAL version. The high 16 bits are the major version number
131 * while the low 16 bits are the minor version. Default value is unknown version 0.
132 */
133 int getHalTunerVersion() { return mTunerVersion; }
134
Amy Zhang210c26a2021-01-12 11:25:27 -0800135private:
136 sp<ITuner> getHidlTuner();
137 sp<IFrontend> openHidlFrontendById(int id);
Amy Zhang921fd432021-01-07 13:18:27 -0800138 sp<IDemux> openHidlDemux(int& demuxId);
Amy Zhang210c26a2021-01-12 11:25:27 -0800139 Result getHidlFrontendInfo(int id, FrontendInfo& info);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800140 sp<ILnb> openHidlLnbById(int id);
141 sp<ILnb> openHidlLnbByName(string name, LnbId& lnbId);
Amy Zhang921fd432021-01-07 13:18:27 -0800142 sp<IDescrambler> openHidlDescrambler();
Amy Zhang39a3fa42020-12-21 16:56:03 -0800143 vector<int> getLnbHandles();
Amy Zhangd1fd5ac2021-01-13 16:30:24 -0800144 FrontendInfo FrontendInfoAidlToHidl(TunerFrontendInfo aidlFrontendInfo);
Amy Zhang39a3fa42020-12-21 16:56:03 -0800145 void updateTunerResources();
146 void updateFrontendResources();
147 void updateLnbResources();
Amy Zhang210c26a2021-01-12 11:25:27 -0800148
149 int getResourceIdFromHandle(int handle, int resourceType);
150
151 int getResourceHandleFromId(int id, int resourceType);
Amy Zhangbf68a162020-11-23 17:42:40 -0800152
Amy Zhangbf68a162020-11-23 17:42:40 -0800153 /**
154 * An AIDL Tuner Service Singleton assigned at the first time the Tuner Client
155 * connects with the Tuner Service. Default null when the service does not exist.
156 */
157 static shared_ptr<ITunerService> mTunerService;
158
159 /**
160 * A Tuner 1.0 HAL interface that is ready before connecting to the TunerService
161 * This is a temprary connection before the Tuner Framework fully migrates to the TunerService.
162 * Default null.
163 */
164 static sp<ITuner> mTuner;
165
166 /**
167 * A Tuner 1.1 HAL interface that is ready before connecting to the TunerService
168 * This is a temprary connection before the Tuner Framework fully migrates to the TunerService.
169 * Default null.
170 */
171 static sp<::android::hardware::tv::tuner::V1_1::ITuner> mTuner_1_1;
172
173 // An integer that carries the Tuner version. The high 16 bits are the major version number
174 // while the low 16 bits are the minor version. Default value is unknown version 0.
175 static int mTunerVersion;
176
Amy Zhang39a3fa42020-12-21 16:56:03 -0800177 shared_ptr<ITunerResourceManager> mTunerResourceManager;
178
Amy Zhang210c26a2021-01-12 11:25:27 -0800179 int mResourceRequestCount = 0;
Amy Zhangbf68a162020-11-23 17:42:40 -0800180};
181} // namespace android
182
183#endif // _ANDROID_MEDIA_TV_TUNER_CLIENT_H_