blob: 94fdf274ef166cf7a80600b2aabd3b2e34a39368 [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
20#include <aidl/android/media/tv/tuner/ITunerService.h>
21#include <android/hardware/tv/tuner/1.1/ITuner.h>
22#include <android/hardware/tv/tuner/1.1/types.h>
23
24#include "FrontendClient.h"
Amy Zhang6bfeaa02020-11-30 15:16:39 -080025#include "DemuxClient.h"
Amy Zhangb0f63ab2021-01-06 17:19:27 -080026#include "DescramblerClient.h"
27#include "LnbClient.h"
Amy Zhangbf68a162020-11-23 17:42:40 -080028
29using ::aidl::android::media::tv::tuner::ITunerService;
30using ::aidl::android::media::tv::tuner::TunerServiceFrontendInfo;
31
32using ::android::hardware::tv::tuner::V1_0::DemuxCapabilities;
33using ::android::hardware::tv::tuner::V1_0::FrontendId;
34using ::android::hardware::tv::tuner::V1_0::ITuner;
35using ::android::hardware::tv::tuner::V1_0::Result;
36using ::android::hardware::tv::tuner::V1_1::FrontendDtmbCapabilities;
37
38using namespace std;
39
40namespace android {
41
Amy Zhang210c26a2021-01-12 11:25:27 -080042typedef enum {
43 FRONTEND,
44 LNB,
45 DEMUX,
46 DESCRAMBLER,
47} TunerResourceType;
48
Amy Zhangbf68a162020-11-23 17:42:40 -080049struct TunerClient : public RefBase {
50
51public:
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<FrontendId> 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(int 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(int id);
77
78 /**
79 * Retrieve the DTMB frontend's capabilities.
80 *
81 * @param id the id of the DTMB frontend.
82 * @return the capabilities of the frontend.
83 */
84 shared_ptr<FrontendDtmbCapabilities> getFrontendDtmbCapabilities(int id);
85
86 /**
Amy Zhang6bfeaa02020-11-30 15:16:39 -080087 * Open a new interface of DemuxClient given a demuxHandle.
88 *
89 * @param demuxHandle the handle of the demux granted by TRM.
90 * @return a newly created DemuxClient interface.
91 */
92 sp<DemuxClient> openDemux(int demuxHandle);
93
94 /**
95 * Retrieve the Demux capabilities.
96 *
97 * @return the demux’s capabilities.
98 */
Amy Zhang90a50b42021-01-11 16:58:59 -080099 shared_ptr<DemuxCapabilities> getDemuxCaps();
Amy Zhangb0f63ab2021-01-06 17:19:27 -0800100
101 /**
102 * Open a new interface of DescramblerClient given a descramblerHandle.
103 *
104 * @param descramblerHandle the handle of the descrambler granted by TRM.
105 * @return a newly created DescramblerClient interface.
106 */
107 sp<DescramblerClient> openDescrambler(int descramblerHandle);
108
109 /**
110 * Open a new interface of LnbClient given an lnbHandle.
111 *
112 * @param lnbHandle the handle of the LNB granted by TRM.
113 * @return a newly created LnbClient interface.
114 */
115 sp<LnbClient> openLnb(int lnbHandle);
116
117 /**
118 * Open a new interface of LnbClient given a LNB name.
119 *
120 * @param lnbName the name for an external LNB to be opened.
121 * @return a newly created LnbClient interface.
122 */
123 sp<LnbClient> openLnbByName(string lnbName);
Amy Zhang6bfeaa02020-11-30 15:16:39 -0800124
125 /**
Amy Zhangbf68a162020-11-23 17:42:40 -0800126 * Get the current Tuner HAL version. The high 16 bits are the major version number
127 * while the low 16 bits are the minor version. Default value is unknown version 0.
128 */
129 int getHalTunerVersion() { return mTunerVersion; }
130
Amy Zhang210c26a2021-01-12 11:25:27 -0800131private:
132 sp<ITuner> getHidlTuner();
133 sp<IFrontend> openHidlFrontendById(int id);
Amy Zhang921fd432021-01-07 13:18:27 -0800134 sp<IDemux> openHidlDemux(int& demuxId);
Amy Zhang210c26a2021-01-12 11:25:27 -0800135 Result getHidlFrontendInfo(int id, FrontendInfo& info);
Amy Zhangd3d57b42021-01-07 11:14:43 -0800136 sp<ILnb> openHidlLnbById(int id);
137 sp<ILnb> openHidlLnbByName(string name, LnbId& lnbId);
Amy Zhang921fd432021-01-07 13:18:27 -0800138 sp<IDescrambler> openHidlDescrambler();
Amy Zhang210c26a2021-01-12 11:25:27 -0800139 FrontendInfo FrontendInfoAidlToHidl(TunerServiceFrontendInfo aidlFrontendInfo);
140
141 int getResourceIdFromHandle(int handle, int resourceType);
142
143 int getResourceHandleFromId(int id, int resourceType);
Amy Zhangbf68a162020-11-23 17:42:40 -0800144
145private:
146 /**
147 * An AIDL Tuner Service Singleton assigned at the first time the Tuner Client
148 * connects with the Tuner Service. Default null when the service does not exist.
149 */
150 static shared_ptr<ITunerService> mTunerService;
151
152 /**
153 * A Tuner 1.0 HAL interface that is ready before connecting to the TunerService
154 * This is a temprary connection before the Tuner Framework fully migrates to the TunerService.
155 * Default null.
156 */
157 static sp<ITuner> mTuner;
158
159 /**
160 * A Tuner 1.1 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<::android::hardware::tv::tuner::V1_1::ITuner> mTuner_1_1;
165
166 // An integer that carries the Tuner version. The high 16 bits are the major version number
167 // while the low 16 bits are the minor version. Default value is unknown version 0.
168 static int mTunerVersion;
169
Amy Zhang210c26a2021-01-12 11:25:27 -0800170 int mResourceRequestCount = 0;
Amy Zhangbf68a162020-11-23 17:42:40 -0800171};
172} // namespace android
173
174#endif // _ANDROID_MEDIA_TV_TUNER_CLIENT_H_