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