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     void removeDemux(uint32_t demuxId);
69     void removeFrontend(uint32_t frontendId);
70 
71   private:
72     virtual ~Tuner();
73     // Static mFrontends array to maintain local frontends information
74     map<uint32_t, sp<Frontend>> mFrontends;
75     map<uint32_t, FrontendInfo::FrontendCapabilities> mFrontendCaps;
76     map<uint32_t, uint32_t> mFrontendToDemux;
77     map<uint32_t, sp<Demux>> mDemuxes;
78     // To maintain how many Frontends we have
79     int mFrontendSize;
80     // The last used demux id. Initial value is -1.
81     // First used id will be 0.
82     int mLastUsedId = -1;
83     vector<sp<Lnb>> mLnbs;
84 };
85 
86 }  // namespace implementation
87 }  // namespace V1_0
88 }  // namespace tuner
89 }  // namespace tv
90 }  // namespace hardware
91 }  // namespace android
92 
93 #endif  // ANDROID_HARDWARE_TV_TUNER_V1_0_TUNER_H_
94