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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "TunerFrontend"
19
20 #include "TunerFrontend.h"
21
22 #include <aidl/android/hardware/tv/tuner/Result.h>
23
24 #include "TunerLnb.h"
25
26 using ::aidl::android::hardware::tv::tuner::Result;
27
28 namespace aidl {
29 namespace android {
30 namespace media {
31 namespace tv {
32 namespace tuner {
33
TunerFrontend(shared_ptr<IFrontend> frontend,int id)34 TunerFrontend::TunerFrontend(shared_ptr<IFrontend> frontend, int id) {
35 mFrontend = frontend;
36 mId = id;
37 }
38
~TunerFrontend()39 TunerFrontend::~TunerFrontend() {
40 close();
41 mFrontend = nullptr;
42 mId = -1;
43 }
44
setCallback(const shared_ptr<ITunerFrontendCallback> & tunerFrontendCallback)45 ::ndk::ScopedAStatus TunerFrontend::setCallback(
46 const shared_ptr<ITunerFrontendCallback>& tunerFrontendCallback) {
47 if (tunerFrontendCallback == nullptr) {
48 return ::ndk::ScopedAStatus::fromServiceSpecificError(
49 static_cast<int32_t>(Result::INVALID_ARGUMENT));
50 }
51
52 shared_ptr<IFrontendCallback> frontendCallback =
53 ::ndk::SharedRefBase::make<FrontendCallback>(tunerFrontendCallback);
54 return mFrontend->setCallback(frontendCallback);
55 }
56
tune(const FrontendSettings & settings)57 ::ndk::ScopedAStatus TunerFrontend::tune(const FrontendSettings& settings) {
58 return mFrontend->tune(settings);
59 }
60
stopTune()61 ::ndk::ScopedAStatus TunerFrontend::stopTune() {
62 return mFrontend->stopTune();
63 }
64
scan(const FrontendSettings & settings,FrontendScanType frontendScanType)65 ::ndk::ScopedAStatus TunerFrontend::scan(const FrontendSettings& settings,
66 FrontendScanType frontendScanType) {
67 return mFrontend->scan(settings, frontendScanType);
68 }
69
stopScan()70 ::ndk::ScopedAStatus TunerFrontend::stopScan() {
71 return mFrontend->stopScan();
72 }
73
setLnb(const shared_ptr<ITunerLnb> & lnb)74 ::ndk::ScopedAStatus TunerFrontend::setLnb(const shared_ptr<ITunerLnb>& lnb) {
75 if (lnb == nullptr) {
76 return ::ndk::ScopedAStatus::fromServiceSpecificError(
77 static_cast<int32_t>(Result::INVALID_ARGUMENT));
78 }
79
80 return mFrontend->setLnb(static_cast<TunerLnb*>(lnb.get())->getId());
81 }
82
linkCiCamToFrontend(int32_t ciCamId,int32_t * _aidl_return)83 ::ndk::ScopedAStatus TunerFrontend::linkCiCamToFrontend(int32_t ciCamId, int32_t* _aidl_return) {
84 return mFrontend->linkCiCam(ciCamId, _aidl_return);
85 }
86
unlinkCiCamToFrontend(int32_t ciCamId)87 ::ndk::ScopedAStatus TunerFrontend::unlinkCiCamToFrontend(int32_t ciCamId) {
88 return mFrontend->unlinkCiCam(ciCamId);
89 }
90
close()91 ::ndk::ScopedAStatus TunerFrontend::close() {
92 return mFrontend->close();
93 }
94
getStatus(const vector<FrontendStatusType> & in_statusTypes,vector<FrontendStatus> * _aidl_return)95 ::ndk::ScopedAStatus TunerFrontend::getStatus(const vector<FrontendStatusType>& in_statusTypes,
96 vector<FrontendStatus>* _aidl_return) {
97 return mFrontend->getStatus(in_statusTypes, _aidl_return);
98 }
99
getFrontendId(int32_t * _aidl_return)100 ::ndk::ScopedAStatus TunerFrontend::getFrontendId(int32_t* _aidl_return) {
101 *_aidl_return = mId;
102 return ::ndk::ScopedAStatus::ok();
103 }
104
getHardwareInfo(std::string * _aidl_return)105 ::ndk::ScopedAStatus TunerFrontend::getHardwareInfo(std::string* _aidl_return) {
106 return mFrontend->getHardwareInfo(_aidl_return);
107 }
108
removeOutputPid(int32_t in_pid)109 ::ndk::ScopedAStatus TunerFrontend::removeOutputPid(int32_t in_pid) {
110 return mFrontend->removeOutputPid(in_pid);
111 }
112
getFrontendStatusReadiness(const std::vector<FrontendStatusType> & in_statusTypes,std::vector<FrontendStatusReadiness> * _aidl_return)113 ::ndk::ScopedAStatus TunerFrontend::getFrontendStatusReadiness(
114 const std::vector<FrontendStatusType>& in_statusTypes,
115 std::vector<FrontendStatusReadiness>* _aidl_return) {
116 return mFrontend->getFrontendStatusReadiness(in_statusTypes, _aidl_return);
117 }
118
119 /////////////// FrontendCallback ///////////////////////
onEvent(FrontendEventType frontendEventType)120 ::ndk::ScopedAStatus TunerFrontend::FrontendCallback::onEvent(FrontendEventType frontendEventType) {
121 ALOGV("FrontendCallback::onEvent, type=%d", frontendEventType);
122 if (mTunerFrontendCallback != nullptr) {
123 mTunerFrontendCallback->onEvent(frontendEventType);
124 }
125 return ndk::ScopedAStatus::ok();
126 }
127
onScanMessage(FrontendScanMessageType type,const FrontendScanMessage & message)128 ::ndk::ScopedAStatus TunerFrontend::FrontendCallback::onScanMessage(
129 FrontendScanMessageType type, const FrontendScanMessage& message) {
130 ALOGV("FrontendCallback::onScanMessage, type=%d", type);
131 if (mTunerFrontendCallback != nullptr) {
132 mTunerFrontendCallback->onScanMessage(type, message);
133 }
134 return ndk::ScopedAStatus::ok();
135 }
136
137 } // namespace tuner
138 } // namespace tv
139 } // namespace media
140 } // namespace android
141 } // namespace aidl
142