• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 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 #ifndef ANDROID_MEDIA_TUNERHIDLSERVICE_H
18 #define ANDROID_MEDIA_TUNERHIDLSERVICE_H
19 
20 #include <aidl/android/hardware/tv/tuner/DemuxFilterEvent.h>
21 #include <aidl/android/hardware/tv/tuner/DemuxFilterStatus.h>
22 #include <aidl/android/media/tv/tuner/BnTunerService.h>
23 #include <aidl/android/media/tv/tunerresourcemanager/TunerFrontendInfo.h>
24 #include <android/hardware/tv/tuner/1.1/ITuner.h>
25 #include <utils/Mutex.h>
26 
27 #include <unordered_set>
28 
29 #include "TunerHelper.h"
30 #include "TunerHidlFilter.h"
31 #include "TunerHidlFrontend.h"
32 
33 using ::aidl::android::hardware::tv::tuner::DemuxCapabilities;
34 using ::aidl::android::hardware::tv::tuner::DemuxFilterEvent;
35 using ::aidl::android::hardware::tv::tuner::DemuxFilterStatus;
36 using ::aidl::android::hardware::tv::tuner::FrontendInfo;
37 using ::aidl::android::hardware::tv::tuner::FrontendType;
38 using ::aidl::android::media::tv::tuner::ITunerDemux;
39 using ::aidl::android::media::tv::tuner::ITunerDescrambler;
40 using ::aidl::android::media::tv::tuner::ITunerFrontend;
41 using ::aidl::android::media::tv::tuner::ITunerLnb;
42 using ::aidl::android::media::tv::tunerresourcemanager::TunerFrontendInfo;
43 using ::android::Mutex;
44 using ::android::sp;
45 using ::android::hardware::hidl_vec;
46 using ::android::hardware::Return;
47 using ::android::hardware::Void;
48 using ::std::shared_ptr;
49 using ::std::string;
50 using ::std::vector;
51 
52 using HidlFrontendDtmbCapabilities = ::android::hardware::tv::tuner::V1_1::FrontendDtmbCapabilities;
53 using HidlDemuxFilterEvent = ::android::hardware::tv::tuner::V1_0::DemuxFilterEvent;
54 using HidlDemuxFilterStatus = ::android::hardware::tv::tuner::V1_0::DemuxFilterStatus;
55 using HidlDemuxCapabilities = ::android::hardware::tv::tuner::V1_0::DemuxCapabilities;
56 using HidlFrontendInfo = ::android::hardware::tv::tuner::V1_0::FrontendInfo;
57 using HidlITuner = ::android::hardware::tv::tuner::V1_0::ITuner;
58 using HidlResult = ::android::hardware::tv::tuner::V1_0::Result;
59 using HidlFrontendId = ::android::hardware::tv::tuner::V1_0::FrontendId;
60 
61 namespace aidl {
62 namespace android {
63 namespace media {
64 namespace tv {
65 namespace tuner {
66 
67 class TunerHidlService : public BnTunerService {
68 public:
getServiceName()69     static char const* getServiceName() { return "media.tuner"; }
70     static binder_status_t instantiate();
71     TunerHidlService();
72     virtual ~TunerHidlService();
73 
74     ::ndk::ScopedAStatus getFrontendIds(vector<int32_t>* out_ids) override;
75     ::ndk::ScopedAStatus getFrontendInfo(int32_t in_frontendHandle,
76                                          FrontendInfo* _aidl_return) override;
77     ::ndk::ScopedAStatus openFrontend(int32_t in_frontendHandle,
78                                       shared_ptr<ITunerFrontend>* _aidl_return) override;
79     ::ndk::ScopedAStatus openLnb(int32_t in_lnbHandle,
80                                  shared_ptr<ITunerLnb>* _aidl_return) override;
81     ::ndk::ScopedAStatus openLnbByName(const std::string& in_lnbName,
82                                        shared_ptr<ITunerLnb>* _aidl_return) override;
83     ::ndk::ScopedAStatus openDemux(int32_t in_demuxHandle,
84                                    shared_ptr<ITunerDemux>* _aidl_return) override;
85     ::ndk::ScopedAStatus getDemuxCaps(DemuxCapabilities* _aidl_return) override;
86     ::ndk::ScopedAStatus openDescrambler(int32_t in_descramblerHandle,
87                                          shared_ptr<ITunerDescrambler>* _aidl_return) override;
88     ::ndk::ScopedAStatus getTunerHalVersion(int32_t* _aidl_return) override;
89     ::ndk::ScopedAStatus openSharedFilter(const string& in_filterToken,
90                                           const shared_ptr<ITunerFilterCallback>& in_cb,
91                                           shared_ptr<ITunerFilter>* _aidl_return) override;
92     ::ndk::ScopedAStatus setLna(bool in_bEnable) override;
93     ::ndk::ScopedAStatus setMaxNumberOfFrontends(FrontendType in_frontendType,
94                                                  int32_t in_maxNumber) override;
95     ::ndk::ScopedAStatus getMaxNumberOfFrontends(FrontendType in_frontendType,
96                                                  int32_t* _aidl_return) override;
97 
98     string addFilterToShared(const shared_ptr<TunerHidlFilter>& sharedFilter);
99     void removeSharedFilter(const shared_ptr<TunerHidlFilter>& sharedFilter);
100     void removeFrontend(const shared_ptr<TunerHidlFrontend>& frontend);
101 
102     static shared_ptr<TunerHidlService> getTunerService();
103 
104 private:
105     bool hasITuner();
106     bool hasITuner_1_1();
107     void updateTunerResources();
108     vector<TunerFrontendInfo> getTRMFrontendInfos();
109     vector<int32_t> getTRMLnbHandles();
110     HidlResult getHidlFrontendIds(hidl_vec<HidlFrontendId>& ids);
111     HidlResult getHidlFrontendInfo(const int id, HidlFrontendInfo& info);
112     DemuxCapabilities getAidlDemuxCaps(const HidlDemuxCapabilities& caps);
113     FrontendInfo getAidlFrontendInfo(const HidlFrontendInfo& halInfo,
114                                      const HidlFrontendDtmbCapabilities& dtmbCaps);
115 
116     sp<HidlITuner> mTuner;
117     sp<::android::hardware::tv::tuner::V1_1::ITuner> mTuner_1_1;
118     int mTunerVersion = TUNER_HAL_VERSION_UNKNOWN;
119     Mutex mSharedFiltersLock;
120     map<string, shared_ptr<TunerHidlFilter>> mSharedFilters;
121     Mutex mOpenedFrontendsLock;
122     unordered_set<shared_ptr<TunerHidlFrontend>> mOpenedFrontends;
123     int mLnaStatus = -1;
124 
125     static shared_ptr<TunerHidlService> sTunerService;
126 };
127 
128 }  // namespace tuner
129 }  // namespace tv
130 }  // namespace media
131 }  // namespace android
132 }  // namespace aidl
133 
134 #endif  // ANDROID_MEDIA_TUNERHIDLSERVICE_H
135