blob: 30ac3359b9dc0be682a0b50c15b9b76a76aead3e
1 | /* |
2 | * Copyright (C) 2011 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 | * @author Tellen Yu |
16 | * @version 1.0 |
17 | * @date 2018/1/12 |
18 | * @par function description: |
19 | * - 1 tv_input hal to tvserver interface |
20 | */ |
21 | |
22 | #define LOG_TAG "TvInputIntf" |
23 | |
24 | #include <utils/Log.h> |
25 | #include <string.h> |
26 | #include "TvInputIntf.h" |
27 | #include "tvcmd.h" |
28 | #include <math.h> |
29 | |
30 | using namespace android; |
31 | |
32 | TvInputIntf::TvInputIntf() : mpObserver(nullptr) { |
33 | mTvSession = TvServerHidlClient::connect(CONNECT_TYPE_HAL); |
34 | mTvSession->setListener(this); |
35 | |
36 | int hdmiPorts = getHdmiPorts(); |
37 | int count = 0; |
38 | while (hdmiPorts !=0) { |
39 | if (count > HDMI_MAX_SUPPORT_NUM - 1) { |
40 | ALOGE("max support num:%d, but now count:%d", HDMI_MAX_SUPPORT_NUM, count); |
41 | break; |
42 | } |
43 | |
44 | mHdmiPorts[count++] = (hdmiPorts%10); |
45 | hdmiPorts = hdmiPorts/10; |
46 | } |
47 | |
48 | ALOGI("get hdmi ports:%d, port count:%d", hdmiPorts, count); |
49 | } |
50 | |
51 | TvInputIntf::~TvInputIntf() |
52 | { |
53 | mTvSession.clear(); |
54 | } |
55 | |
56 | int TvInputIntf::setTvObserver ( TvPlayObserver *ob ) |
57 | { |
58 | //ALOGI("setTvObserver:%p", ob); |
59 | mpObserver = ob; |
60 | return 0; |
61 | } |
62 | |
63 | void TvInputIntf::notify(const tv_parcel_t &parcel) |
64 | { |
65 | source_connect_t srcConnect; |
66 | srcConnect.msgType = parcel.msgType; |
67 | srcConnect.source = parcel.bodyInt[0]; |
68 | srcConnect.state = parcel.bodyInt[1]; |
69 | |
70 | //ALOGI("notify type:%d, %p", srcConnect.msgType, mpObserver); |
71 | if (mpObserver != NULL) |
72 | mpObserver->onTvEvent(srcConnect); |
73 | } |
74 | |
75 | int TvInputIntf::startTv() |
76 | { |
77 | return mTvSession->startTv(); |
78 | } |
79 | |
80 | int TvInputIntf::stopTv() |
81 | { |
82 | return mTvSession->stopTv(); |
83 | } |
84 | |
85 | int TvInputIntf::switchSourceInput(tv_source_input_t source_input) |
86 | { |
87 | return mTvSession->switchInputSrc(source_input); |
88 | } |
89 | |
90 | int TvInputIntf::getSourceConnectStatus(tv_source_input_t source_input) |
91 | { |
92 | return mTvSession->getInputSrcConnectStatus(source_input); |
93 | } |
94 | |
95 | int TvInputIntf::getCurrentSourceInput() |
96 | { |
97 | return mTvSession->getCurrentInputSrc(); |
98 | } |
99 | |
100 | int TvInputIntf::getHdmiAvHotplugDetectOnoff() |
101 | { |
102 | return mTvSession->getHdmiAvHotplugStatus(); |
103 | } |
104 | |
105 | int TvInputIntf::getSupportInputDevices(int *devices, int *count) |
106 | { |
107 | std::string serverDevices = mTvSession->getSupportInputDevices(); |
108 | const char *input_list = serverDevices.c_str(); |
109 | ALOGD("getAllTvDevices input list = %s", input_list); |
110 | |
111 | int len = 0; |
112 | const char *seg = ","; |
113 | char *pT = strtok((char*)input_list, seg); |
114 | while (pT) { |
115 | len ++; |
116 | *devices = atoi(pT); |
117 | ALOGD("devices: %d: %d", len , *devices); |
118 | devices ++; |
119 | pT = strtok(NULL, seg); |
120 | } |
121 | *count = len; |
122 | return 0; |
123 | |
124 | } |
125 | |
126 | int TvInputIntf::getHdmiPorts() |
127 | { |
128 | return mTvSession->getHdmiPorts(); |
129 | } |
130 | |
131 | int TvInputIntf::getHdmiPort(tv_source_input_t source_input) { |
132 | if (source_input > SOURCE_HDMI4) { |
133 | ALOGE("input source:%d > max hdmi source4: %d", (int)source_input , SOURCE_HDMI4); |
134 | return -1; |
135 | } |
136 | return mHdmiPorts[source_input - SOURCE_HDMI1]; |
137 | } |
138 | |
139 |