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_TUNERSERVICE_H 18 #define ANDROID_MEDIA_TUNERSERVICE_H 19 20 #include <aidl/android/hardware/tv/tuner/DemuxFilterEvent.h> 21 #include <aidl/android/hardware/tv/tuner/DemuxFilterStatus.h> 22 #include <aidl/android/hardware/tv/tuner/ITuner.h> 23 #include <aidl/android/media/tv/tuner/BnTunerService.h> 24 #include <aidl/android/media/tv/tunerresourcemanager/TunerFrontendInfo.h> 25 #include <utils/Mutex.h> 26 27 #include <map> 28 29 #include "TunerFilter.h" 30 #include "TunerHelper.h" 31 32 using ::aidl::android::hardware::tv::tuner::DemuxCapabilities; 33 using ::aidl::android::hardware::tv::tuner::DemuxFilterEvent; 34 using ::aidl::android::hardware::tv::tuner::DemuxFilterStatus; 35 using ::aidl::android::hardware::tv::tuner::DemuxInfo; 36 using ::aidl::android::hardware::tv::tuner::FrontendInfo; 37 using ::aidl::android::hardware::tv::tuner::FrontendType; 38 using ::aidl::android::hardware::tv::tuner::ITuner; 39 using ::aidl::android::media::tv::tuner::BnTunerService; 40 using ::aidl::android::media::tv::tuner::ITunerDemux; 41 using ::aidl::android::media::tv::tuner::ITunerFilter; 42 using ::aidl::android::media::tv::tuner::ITunerFilterCallback; 43 using ::aidl::android::media::tv::tuner::ITunerFrontend; 44 using ::aidl::android::media::tv::tuner::ITunerLnb; 45 using ::aidl::android::media::tv::tunerresourcemanager::TunerFrontendInfo; 46 using ::android::Mutex; 47 48 using namespace std; 49 50 namespace aidl { 51 namespace android { 52 namespace media { 53 namespace tv { 54 namespace tuner { 55 56 class TunerService : public BnTunerService { 57 public: getServiceName()58 static char const *getServiceName() { return "media.tuner"; } 59 static binder_status_t instantiate(); 60 TunerService(); 61 virtual ~TunerService(); 62 63 ::ndk::ScopedAStatus getFrontendIds(vector<int32_t>* out_ids) override; 64 ::ndk::ScopedAStatus getFrontendInfo(int32_t in_frontendHandle, 65 FrontendInfo* _aidl_return) override; 66 ::ndk::ScopedAStatus openFrontend(int32_t in_frontendHandle, 67 shared_ptr<ITunerFrontend>* _aidl_return) override; 68 ::ndk::ScopedAStatus openLnb(int32_t in_lnbHandle, 69 shared_ptr<ITunerLnb>* _aidl_return) override; 70 ::ndk::ScopedAStatus openLnbByName(const string& in_lnbName, 71 shared_ptr<ITunerLnb>* _aidl_return) override; 72 ::ndk::ScopedAStatus openDemux(int32_t in_demuxHandle, 73 shared_ptr<ITunerDemux>* _aidl_return) override; 74 ::ndk::ScopedAStatus getDemuxCaps(DemuxCapabilities* _aidl_return) override; 75 ::ndk::ScopedAStatus getDemuxInfo(int32_t in_demuxHandle, DemuxInfo* _aidl_return) override; 76 ::ndk::ScopedAStatus getDemuxInfoList(vector<DemuxInfo>* _aidl_return) override; 77 ::ndk::ScopedAStatus openDescrambler(int32_t in_descramblerHandle, 78 shared_ptr<ITunerDescrambler>* _aidl_return) override; 79 ::ndk::ScopedAStatus getTunerHalVersion(int32_t* _aidl_return) override; 80 ::ndk::ScopedAStatus openSharedFilter(const string& in_filterToken, 81 const shared_ptr<ITunerFilterCallback>& in_cb, 82 shared_ptr<ITunerFilter>* _aidl_return) override; 83 ::ndk::ScopedAStatus isLnaSupported(bool* _aidl_return) override; 84 ::ndk::ScopedAStatus setLna(bool in_bEnable) override; 85 ::ndk::ScopedAStatus setMaxNumberOfFrontends(FrontendType in_frontendType, 86 int32_t in_maxNumber) override; 87 ::ndk::ScopedAStatus getMaxNumberOfFrontends(FrontendType in_frontendType, 88 int32_t* _aidl_return) override; 89 90 string addFilterToShared(const shared_ptr<TunerFilter>& sharedFilter); 91 void removeSharedFilter(const shared_ptr<TunerFilter>& sharedFilter); 92 93 private: 94 void updateTunerResources(); 95 vector<TunerFrontendInfo> getTRMFrontendInfos(); 96 vector<TunerDemuxInfo> getTRMDemuxInfos(); 97 vector<int32_t> getTRMLnbHandles(); 98 99 shared_ptr<ITuner> mTuner; 100 int mTunerVersion = TUNER_HAL_VERSION_UNKNOWN; 101 Mutex mSharedFiltersLock; 102 map<string, shared_ptr<TunerFilter>> mSharedFilters; 103 }; 104 105 } // namespace tuner 106 } // namespace tv 107 } // namespace media 108 } // namespace android 109 } // namespace aidl 110 111 #endif // ANDROID_MEDIA_TUNERSERVICE_H 112