1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _ANDROID_MEDIA_TV_TUNER_CLIENT_H_
#define _ANDROID_MEDIA_TV_TUNER_CLIENT_H_
#include <aidl/android/media/tv/tunerresourcemanager/ITunerResourceManager.h>
#include <aidl/android/media/tv/tuner/ITunerService.h>
#include <aidl/android/media/tv/tuner/TunerFrontendInfo.h>
#include <android/binder_parcel_utils.h>
#include <android/hardware/tv/tuner/1.1/ITuner.h>
#include <android/hardware/tv/tuner/1.1/types.h>
#include "DemuxClient.h"
#include "ClientHelper.h"
#include "FrontendClient.h"
#include "DescramblerClient.h"
#include "LnbClient.h"
using Status = ::ndk::ScopedAStatus;
using ::aidl::android::media::tv::tuner::TunerDemuxCapabilities;
using ::aidl::android::media::tv::tuner::ITunerService;
using ::aidl::android::media::tv::tuner::TunerFrontendInfo;
using ::aidl::android::media::tv::tunerresourcemanager::ITunerResourceManager;
using ::android::hardware::tv::tuner::V1_0::DemuxCapabilities;
using ::android::hardware::tv::tuner::V1_0::FrontendId;
using ::android::hardware::tv::tuner::V1_0::ITuner;
using ::android::hardware::tv::tuner::V1_0::LnbId;
using ::android::hardware::tv::tuner::V1_0::Result;
using ::android::hardware::tv::tuner::V1_1::FrontendDtmbCapabilities;
using namespace std;
namespace android {
const static int TUNER_HAL_VERSION_UNKNOWN = 0;
const static int TUNER_HAL_VERSION_1_0 = 1 << 16;
const static int TUNER_HAL_VERSION_1_1 = (1 << 16) | 1;
typedef enum {
FRONTEND,
LNB,
DEMUX,
DESCRAMBLER,
} TunerResourceType;
struct TunerClient : public RefBase {
public:
TunerClient();
~TunerClient();
/**
* Retrieve all the frontend ids.
*
* @return a list of the available frontend ids
*/
vector<FrontendId> getFrontendIds();
/**
* Open a new interface of FrontendClient given a frontendHandle.
*
* @param frontendHandle the handle of the frontend granted by TRM.
* @return a newly created FrontendClient interface.
*/
sp<FrontendClient> openFrontend(int frontendHandle);
/**
* Retrieve the granted frontend's information.
*
* @param id the id of the frontend granted by TRM.
* @return the information for the frontend.
*/
shared_ptr<FrontendInfo> getFrontendInfo(int id);
/**
* Retrieve the DTMB frontend's capabilities.
*
* @param id the id of the DTMB frontend.
* @return the capabilities of the frontend.
*/
shared_ptr<FrontendDtmbCapabilities> getFrontendDtmbCapabilities(int id);
/**
* Open a new interface of DemuxClient given a demuxHandle.
*
* @param demuxHandle the handle of the demux granted by TRM.
* @return a newly created DemuxClient interface.
*/
sp<DemuxClient> openDemux(int demuxHandle);
/**
* Retrieve the Demux capabilities.
*
* @return the demux’s capabilities.
*/
shared_ptr<DemuxCapabilities> getDemuxCaps();
/**
* Open a new interface of DescramblerClient given a descramblerHandle.
*
* @param descramblerHandle the handle of the descrambler granted by TRM.
* @return a newly created DescramblerClient interface.
*/
sp<DescramblerClient> openDescrambler(int descramblerHandle);
/**
* Open a new interface of LnbClient given an lnbHandle.
*
* @param lnbHandle the handle of the LNB granted by TRM.
* @return a newly created LnbClient interface.
*/
sp<LnbClient> openLnb(int lnbHandle);
/**
* Open a new interface of LnbClient given a LNB name.
*
* @param lnbName the name for an external LNB to be opened.
* @return a newly created LnbClient interface.
*/
sp<LnbClient> openLnbByName(string lnbName);
/**
* Get the current Tuner HAL version. The high 16 bits are the major version number
* while the low 16 bits are the minor version. Default value is unknown version 0.
*/
int getHalTunerVersion() { return mTunerVersion; }
private:
sp<ITuner> getHidlTuner();
sp<IFrontend> openHidlFrontendById(int id);
sp<IDemux> openHidlDemux(int& demuxId);
Result getHidlFrontendInfo(int id, FrontendInfo& info);
sp<ILnb> openHidlLnbById(int id);
sp<ILnb> openHidlLnbByName(string name, LnbId& lnbId);
sp<IDescrambler> openHidlDescrambler();
vector<int> getLnbHandles();
DemuxCapabilities getHidlDemuxCaps(TunerDemuxCapabilities& aidlCaps);
FrontendInfo frontendInfoAidlToHidl(TunerFrontendInfo aidlFrontendInfo);
void updateTunerResources();
void updateFrontendResources();
void updateLnbResources();
int getResourceIdFromHandle(int handle, int resourceType);
int getResourceHandleFromId(int id, int resourceType);
/**
* An AIDL Tuner Service Singleton assigned at the first time the Tuner Client
* connects with the Tuner Service. Default null when the service does not exist.
*/
static shared_ptr<ITunerService> mTunerService;
/**
* A Tuner 1.0 HAL interface that is ready before connecting to the TunerService
* This is a temprary connection before the Tuner Framework fully migrates to the TunerService.
* Default null.
*/
static sp<ITuner> mTuner;
/**
* A Tuner 1.1 HAL interface that is ready before connecting to the TunerService
* This is a temprary connection before the Tuner Framework fully migrates to the TunerService.
* Default null.
*/
static sp<::android::hardware::tv::tuner::V1_1::ITuner> mTuner_1_1;
// An integer that carries the Tuner version. The high 16 bits are the major version number
// while the low 16 bits are the minor version. Default value is unknown version 0.
static int mTunerVersion;
shared_ptr<ITunerResourceManager> mTunerResourceManager;
int mResourceRequestCount = 0;
};
} // namespace android
#endif // _ANDROID_MEDIA_TV_TUNER_CLIENT_H_
|