1 /*
2  * Copyright (C) 2019 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_HARDWARE_TV_TUNER_V1_0_TUNER_H_
18 #define ANDROID_HARDWARE_TV_TUNER_V1_0_TUNER_H_
19 
20 #include <android/hardware/tv/tuner/1.0/ITuner.h>
21 #include <map>
22 #include "Demux.h"
23 #include "Frontend.h"
24 #include "Lnb.h"
25 
26 using namespace std;
27 
28 namespace android {
29 namespace hardware {
30 namespace tv {
31 namespace tuner {
32 namespace V1_0 {
33 namespace implementation {
34 
35 class Frontend;
36 class Demux;
37 
38 class Tuner : public ITuner {
39   public:
40     Tuner();
41     virtual Return<void> getFrontendIds(getFrontendIds_cb _hidl_cb) override;
42 
43     virtual Return<void> openFrontendById(uint32_t frontendId,
44                                           openFrontendById_cb _hidl_cb) override;
45 
46     virtual Return<void> openDemux(openDemux_cb _hidl_cb) override;
47 
48     virtual Return<void> getDemuxCaps(getDemuxCaps_cb _hidl_cb) override;
49 
50     virtual Return<void> openDescrambler(openDescrambler_cb _hidl_cb) override;
51 
52     virtual Return<void> getFrontendInfo(FrontendId frontendId,
53                                          getFrontendInfo_cb _hidl_cb) override;
54 
55     virtual Return<void> getLnbIds(getLnbIds_cb _hidl_cb) override;
56 
57     virtual Return<void> openLnbById(LnbId lnbId, openLnbById_cb _hidl_cb) override;
58 
59     virtual Return<void> openLnbByName(const hidl_string& lnbName,
60                                        openLnbByName_cb _hidl_cb) override;
61 
62     sp<Frontend> getFrontendById(uint32_t frontendId);
63 
64     void setFrontendAsDemuxSource(uint32_t frontendId, uint32_t demuxId);
65 
66     void frontendStartTune(uint32_t frontendId);
67     void frontendStopTune(uint32_t frontendId);
68 
69   private:
70     virtual ~Tuner();
71     // Static mFrontends array to maintain local frontends information
72     vector<sp<Frontend>> mFrontends;
73     vector<FrontendInfo::FrontendCapabilities> mFrontendCaps;
74     std::map<uint32_t, uint32_t> mFrontendToDemux;
75     std::map<uint32_t, sp<Demux>> mDemuxes;
76     // To maintain how many Frontends we have
77     int mFrontendSize;
78     // The last used demux id. Initial value is -1.
79     // First used id will be 0.
80     int mLastUsedId = -1;
81     vector<sp<Lnb>> mLnbs;
82 };
83 
84 }  // namespace implementation
85 }  // namespace V1_0
86 }  // namespace tuner
87 }  // namespace tv
88 }  // namespace hardware
89 }  // namespace android
90 
91 #endif  // ANDROID_HARDWARE_TV_TUNER_V1_0_TUNER_H_
92