blob: 2b3de17188683eacc5bc8ab5ad21c52acd2c2c3b [file] [log] [blame]
shubang23aa3ac2020-09-07 18:56:28 -07001/**
2 * Copyright (c) 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#define LOG_TAG "TunerService"
18
19#include <android/binder_manager.h>
20#include <utils/Log.h>
Amy Zhang0f04c452020-10-30 13:36:44 -070021#include "TunerFrontend.h"
shubang23aa3ac2020-09-07 18:56:28 -070022#include "TunerService.h"
23
Amy Zhang70de35a2020-10-12 20:13:16 -070024using ::aidl::android::media::tv::tuner::TunerFrontendAnalogCapabilities;
25using ::aidl::android::media::tv::tuner::TunerFrontendAtsc3Capabilities;
26using ::aidl::android::media::tv::tuner::TunerFrontendAtscCapabilities;
27using ::aidl::android::media::tv::tuner::TunerFrontendCableCapabilities;
28using ::aidl::android::media::tv::tuner::TunerFrontendCapabilities;
29using ::aidl::android::media::tv::tuner::TunerFrontendDvbsCapabilities;
30using ::aidl::android::media::tv::tuner::TunerFrontendDvbtCapabilities;
31using ::aidl::android::media::tv::tuner::TunerFrontendIsdbs3Capabilities;
32using ::aidl::android::media::tv::tuner::TunerFrontendIsdbsCapabilities;
33using ::aidl::android::media::tv::tuner::TunerFrontendIsdbtCapabilities;
shubang23aa3ac2020-09-07 18:56:28 -070034using ::android::hardware::hidl_vec;
35using ::android::hardware::tv::tuner::V1_0::FrontendId;
Amy Zhang70de35a2020-10-12 20:13:16 -070036using ::android::hardware::tv::tuner::V1_0::FrontendType;
shubang23aa3ac2020-09-07 18:56:28 -070037using ::android::hardware::tv::tuner::V1_0::Result;
38
39namespace android {
40
41sp<ITuner> TunerService::mTuner;
42
43TunerService::TunerService() {}
44TunerService::~TunerService() {}
45
46void TunerService::instantiate() {
47 std::shared_ptr<TunerService> service =
48 ::ndk::SharedRefBase::make<TunerService>();
49 AServiceManager_addService(service->asBinder().get(), getServiceName());
Amy Zhang0f04c452020-10-30 13:36:44 -070050 mTuner = ITuner::getService();
51 if (mTuner == nullptr) {
52 ALOGE("Failed to get ITuner service.");
53 }
shubang23aa3ac2020-09-07 18:56:28 -070054}
55
56Status TunerService::getFrontendIds(std::vector<int32_t>* ids, int32_t* /* _aidl_return */) {
57 if (mTuner == nullptr) {
Amy Zhang0f04c452020-10-30 13:36:44 -070058 ALOGE("ITuner service is not init.");
59 return ::ndk::ScopedAStatus::fromServiceSpecificError(
60 static_cast<int32_t>(Result::UNAVAILABLE));
shubang23aa3ac2020-09-07 18:56:28 -070061 }
62 hidl_vec<FrontendId> feIds;
63 Result res;
64 mTuner->getFrontendIds([&](Result r, const hidl_vec<FrontendId>& frontendIds) {
65 feIds = frontendIds;
66 res = r;
67 });
68 if (res != Result::SUCCESS) {
69 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
70 }
71 ids->resize(feIds.size());
72 std::copy(feIds.begin(), feIds.end(), ids->begin());
73
Amy Zhang0f04c452020-10-30 13:36:44 -070074 return Status::ok();
shubang23aa3ac2020-09-07 18:56:28 -070075}
76
Amy Zhang70de35a2020-10-12 20:13:16 -070077Status TunerService::getFrontendInfo(
78 int32_t frontendHandle, TunerServiceFrontendInfo* _aidl_return) {
79 if (mTuner == nullptr) {
Amy Zhang0f04c452020-10-30 13:36:44 -070080 ALOGE("ITuner service is not init.");
81 return ::ndk::ScopedAStatus::fromServiceSpecificError(
82 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhang70de35a2020-10-12 20:13:16 -070083 }
84
85 Result res;
86 FrontendInfo info;
87 int feId = getResourceIdFromHandle(frontendHandle);
88 mTuner->getFrontendInfo(feId, [&](Result r, const FrontendInfo& feInfo) {
89 info = feInfo;
90 res = r;
91 });
92 if (res != Result::SUCCESS) {
Amy Zhang0f04c452020-10-30 13:36:44 -070093 return Status::fromServiceSpecificError(static_cast<int32_t>(res));
Amy Zhang70de35a2020-10-12 20:13:16 -070094 }
95
96 TunerServiceFrontendInfo tunerInfo = convertToAidlFrontendInfo(feId, info);
97 *_aidl_return = tunerInfo;
Amy Zhang0f04c452020-10-30 13:36:44 -070098 return Status::ok();
99}
100
101Status TunerService::openFrontend(
102 int32_t frontendHandle, std::shared_ptr<ITunerFrontend>* _aidl_return) {
103 if (mTuner == nullptr) {
104 ALOGE("ITuner service is not init.");
105 return ::ndk::ScopedAStatus::fromServiceSpecificError(
106 static_cast<int32_t>(Result::UNAVAILABLE));
107 }
108
109 *_aidl_return = ::ndk::SharedRefBase::make<TunerFrontend>(mTuner, frontendHandle);
110 return Status::ok();
Amy Zhang70de35a2020-10-12 20:13:16 -0700111}
112
113TunerServiceFrontendInfo TunerService::convertToAidlFrontendInfo(int feId, FrontendInfo halInfo) {
114 TunerServiceFrontendInfo info{
115 .id = feId,
116 .type = (int)halInfo.type,
117 .minFrequency = (int)halInfo.minFrequency,
118 .maxFrequency = (int)halInfo.maxFrequency,
119 .minSymbolRate = (int)halInfo.minSymbolRate,
120 .maxSymbolRate = (int)halInfo.maxSymbolRate,
121 .acquireRange = (int)halInfo.acquireRange,
122 .exclusiveGroupId = (int)halInfo.exclusiveGroupId,
123 };
124 for (int i = 0; i < halInfo.statusCaps.size(); i++) {
125 info.statusCaps.push_back((int)halInfo.statusCaps[i]);
126 }
127
128 TunerFrontendCapabilities caps;
129 switch (halInfo.type) {
130 case FrontendType::ANALOG: {
131 TunerFrontendAnalogCapabilities analogCaps{
132 .typeCap = (int)halInfo.frontendCaps.analogCaps().typeCap,
133 .sifStandardCap = (int)halInfo.frontendCaps.analogCaps().sifStandardCap,
134 };
135 caps.set<TunerFrontendCapabilities::analogCaps>(analogCaps);
136 break;
137 }
138 case FrontendType::ATSC: {
139 TunerFrontendAtscCapabilities atscCaps{
140 .modulationCap = (int)halInfo.frontendCaps.atscCaps().modulationCap,
141 };
142 caps.set<TunerFrontendCapabilities::atscCaps>(atscCaps);
143 break;
144 }
145 case FrontendType::ATSC3: {
146 TunerFrontendAtsc3Capabilities atsc3Caps{
147 .bandwidthCap = (int)halInfo.frontendCaps.atsc3Caps().bandwidthCap,
148 .modulationCap = (int)halInfo.frontendCaps.atsc3Caps().modulationCap,
149 .timeInterleaveModeCap =
150 (int)halInfo.frontendCaps.atsc3Caps().timeInterleaveModeCap,
151 .codeRateCap = (int)halInfo.frontendCaps.atsc3Caps().codeRateCap,
152 .demodOutputFormatCap = (int)halInfo.frontendCaps.atsc3Caps().demodOutputFormatCap,
153 .fecCap = (int)halInfo.frontendCaps.atsc3Caps().fecCap,
154 };
155 caps.set<TunerFrontendCapabilities::atsc3Caps>(atsc3Caps);
156 break;
157 }
158 case FrontendType::DVBC: {
159 TunerFrontendCableCapabilities cableCaps{
160 .modulationCap = (int)halInfo.frontendCaps.dvbcCaps().modulationCap,
161 .codeRateCap = (int)halInfo.frontendCaps.dvbcCaps().fecCap,
162 .annexCap = (int)halInfo.frontendCaps.dvbcCaps().annexCap,
163 };
164 caps.set<TunerFrontendCapabilities::cableCaps>(cableCaps);
165 break;
166 }
167 case FrontendType::DVBS: {
168 TunerFrontendDvbsCapabilities dvbsCaps{
169 .modulationCap = (int)halInfo.frontendCaps.dvbsCaps().modulationCap,
170 .codeRateCap = (long)halInfo.frontendCaps.dvbsCaps().innerfecCap,
171 .standard = (int)halInfo.frontendCaps.dvbsCaps().standard,
172 };
173 caps.set<TunerFrontendCapabilities::dvbsCaps>(dvbsCaps);
174 break;
175 }
176 case FrontendType::DVBT: {
177 TunerFrontendDvbtCapabilities dvbtCaps{
178 .transmissionModeCap = (int)halInfo.frontendCaps.dvbtCaps().transmissionModeCap,
179 .bandwidthCap = (int)halInfo.frontendCaps.dvbtCaps().bandwidthCap,
180 .constellationCap = (int)halInfo.frontendCaps.dvbtCaps().constellationCap,
181 .codeRateCap = (int)halInfo.frontendCaps.dvbtCaps().coderateCap,
182 .hierarchyCap = (int)halInfo.frontendCaps.dvbtCaps().hierarchyCap,
183 .guardIntervalCap = (int)halInfo.frontendCaps.dvbtCaps().guardIntervalCap,
184 .isT2Supported = (bool)halInfo.frontendCaps.dvbtCaps().isT2Supported,
185 .isMisoSupported = (bool)halInfo.frontendCaps.dvbtCaps().isMisoSupported,
186 };
187 caps.set<TunerFrontendCapabilities::dvbtCaps>(dvbtCaps);
188 break;
189 }
190 case FrontendType::ISDBS: {
191 TunerFrontendIsdbsCapabilities isdbsCaps{
192 .modulationCap = (int)halInfo.frontendCaps.isdbsCaps().modulationCap,
193 .codeRateCap = (int)halInfo.frontendCaps.isdbsCaps().coderateCap,
194 };
195 caps.set<TunerFrontendCapabilities::isdbsCaps>(isdbsCaps);
196 break;
197 }
198 case FrontendType::ISDBS3: {
199 TunerFrontendIsdbs3Capabilities isdbs3Caps{
200 .modulationCap = (int)halInfo.frontendCaps.isdbs3Caps().modulationCap,
201 .codeRateCap = (int)halInfo.frontendCaps.isdbs3Caps().coderateCap,
202 };
203 caps.set<TunerFrontendCapabilities::isdbs3Caps>(isdbs3Caps);
204 break;
205 }
206 case FrontendType::ISDBT: {
207 TunerFrontendIsdbtCapabilities isdbtCaps{
208 .modeCap = (int)halInfo.frontendCaps.isdbtCaps().modeCap,
209 .bandwidthCap = (int)halInfo.frontendCaps.isdbtCaps().bandwidthCap,
210 .modulationCap = (int)halInfo.frontendCaps.isdbtCaps().modulationCap,
211 .codeRateCap = (int)halInfo.frontendCaps.isdbtCaps().coderateCap,
212 .guardIntervalCap = (int)halInfo.frontendCaps.isdbtCaps().guardIntervalCap,
213 };
214 caps.set<TunerFrontendCapabilities::isdbtCaps>(isdbtCaps);
215 break;
216 }
217 default:
218 break;
219 }
220
221 info.caps = caps;
222 return info;
223}
shubang23aa3ac2020-09-07 18:56:28 -0700224} // namespace android