blob: f2e78c9acbd3e3e420a923f55f6523d94917e86b [file] [log] [blame]
Amy Zhangbf68a162020-11-23 17:42:40 -08001/*
2 * Copyright 2020 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_TV_TUNER_CLIENT_H_
18#define _ANDROID_MEDIA_TV_TUNER_CLIENT_H_
19
20#include <aidl/android/media/tv/tuner/ITunerService.h>
21#include <android/hardware/tv/tuner/1.1/ITuner.h>
22#include <android/hardware/tv/tuner/1.1/types.h>
23
24#include "FrontendClient.h"
25
26using ::aidl::android::media::tv::tuner::ITunerService;
27using ::aidl::android::media::tv::tuner::TunerServiceFrontendInfo;
28
29using ::android::hardware::tv::tuner::V1_0::DemuxCapabilities;
30using ::android::hardware::tv::tuner::V1_0::FrontendId;
31using ::android::hardware::tv::tuner::V1_0::ITuner;
32using ::android::hardware::tv::tuner::V1_0::Result;
33using ::android::hardware::tv::tuner::V1_1::FrontendDtmbCapabilities;
34
35using namespace std;
36
37namespace android {
38
39struct TunerClient : public RefBase {
40
41public:
42 TunerClient();
43 ~TunerClient();
44
45 /**
46 * Retrieve all the frontend ids.
47 *
48 * @return a list of the available frontend ids
49 */
50 vector<FrontendId> getFrontendIds();
51
52 /**
53 * Open a new interface of FrontendClient given a frontendHandle.
54 *
55 * @param frontendHandle the handle of the frontend granted by TRM.
56 * @return a newly created FrontendClient interface.
57 */
58 sp<FrontendClient> openFrontend(int frontendHandle);
59
60 /**
61 * Retrieve the granted frontend's information.
62 *
63 * @param id the id of the frontend granted by TRM.
64 * @return the information for the frontend.
65 */
66 shared_ptr<FrontendInfo> getFrontendInfo(int id);
67
68 /**
69 * Retrieve the DTMB frontend's capabilities.
70 *
71 * @param id the id of the DTMB frontend.
72 * @return the capabilities of the frontend.
73 */
74 shared_ptr<FrontendDtmbCapabilities> getFrontendDtmbCapabilities(int id);
75
76 /**
77 * Get the current Tuner HAL version. The high 16 bits are the major version number
78 * while the low 16 bits are the minor version. Default value is unknown version 0.
79 */
80 int getHalTunerVersion() { return mTunerVersion; }
81
82 static int getResourceIdFromHandle(int handle) {
83 return (handle & 0x00ff0000) >> 16;
84 }
85
86private:
87 /**
88 * An AIDL Tuner Service Singleton assigned at the first time the Tuner Client
89 * connects with the Tuner Service. Default null when the service does not exist.
90 */
91 static shared_ptr<ITunerService> mTunerService;
92
93 /**
94 * A Tuner 1.0 HAL interface that is ready before connecting to the TunerService
95 * This is a temprary connection before the Tuner Framework fully migrates to the TunerService.
96 * Default null.
97 */
98 static sp<ITuner> mTuner;
99
100 /**
101 * A Tuner 1.1 HAL interface that is ready before connecting to the TunerService
102 * This is a temprary connection before the Tuner Framework fully migrates to the TunerService.
103 * Default null.
104 */
105 static sp<::android::hardware::tv::tuner::V1_1::ITuner> mTuner_1_1;
106
107 // An integer that carries the Tuner version. The high 16 bits are the major version number
108 // while the low 16 bits are the minor version. Default value is unknown version 0.
109 static int mTunerVersion;
110
111 sp<ITuner> getHidlTuner();
112 sp<IFrontend> openHidlFrontendByHandle(int frontendHandle);
113 Result getHidlFrontendInfo(int id, FrontendInfo& info);
114 FrontendInfo FrontendInfoAidlToHidl(TunerServiceFrontendInfo aidlFrontendInfo);
115};
116} // namespace android
117
118#endif // _ANDROID_MEDIA_TV_TUNER_CLIENT_H_