blob: ab5477089fb68cac69eee2fb50e70bdd742578cd [file] [log] [blame]
Henry Fang2bb37162019-01-14 16:18:33 -08001/*
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_CEC_V2_0_HDMICEC_H
18#define ANDROID_HARDWARE_TV_CEC_V2_0_HDMICEC_H
19
20#include <algorithm>
21
22#include <android/hardware/tv/cec/2.0/IHdmiCec.h>
23#include <hardware/hardware.h>
24#include <hardware/hdmi_cec.h>
25#include <hidl/Status.h>
26
27#include <hidl/MQDescriptor.h>
28namespace android {
29namespace hardware {
30namespace tv {
31namespace cec {
32namespace V2_0 {
33namespace implementation {
34
35using ::android::sp;
36using ::android::hardware::hidl_string;
37using ::android::hardware::hidl_vec;
38using ::android::hardware::Return;
39using ::android::hardware::Void;
40using ::android::hardware::tv::cec::V2_0::CecLogicalAddress;
41using ::android::hardware::tv::cec::V2_0::CecMessage;
42using ::android::hardware::tv::cec::V2_0::CecPhysicalAddress;
43using ::android::hardware::tv::cec::V2_0::HdmiPortId;
44using ::android::hardware::tv::cec::V2_0::HdmiPortInfo;
45using ::android::hardware::tv::cec::V2_0::IHdmiCec;
46using ::android::hardware::tv::cec::V2_0::IHdmiCecCallback;
47using ::android::hardware::tv::cec::V2_0::MaxLength;
48using ::android::hardware::tv::cec::V2_0::OptionKey;
49using ::android::hardware::tv::cec::V2_0::Result;
50using ::android::hardware::tv::cec::V2_0::SendMessageResult;
51
52struct HdmiCec : public IHdmiCec, public hidl_death_recipient {
53 HdmiCec(hdmi_cec_device_t* device);
54 // Methods from ::android::hardware::tv::cec::V2_0::IHdmiCec follow.
55 Return<Result> addDeviceType(CecDeviceType deviceType) override;
56 Return<void> clearDeviceTypes() override;
57 Return<void> setAllDeviceTypes(CecAllDeviceTypes allDeviceTypes) override;
58 Return<void> setDeviceFeatures(CecDeviceType deviceType,
59 CecDeviceFeatures /* deviceFeatures */) override;
60 Return<void> setRcProfile(CecDeviceType deviceType,
61 const CecRcProfile& /* rcProfile */) override;
62 Return<void> readDeviceInfo(CecLogicalAddress logicalAddress,
63 CecPhysicalAddress physicalAddress,
64 const readDeviceInfo_cb _hidl_cb) override;
65 Return<SendMessageResult> sendMessage(const CecMessage& message) override;
66 Return<void> setCallback(const sp<IHdmiCecCallback>& callback) override;
67 Return<void> getPortInfo(getPortInfo_cb _hidl_cb) override;
68 Return<void> setOption(OptionKey key, bool value) override;
69 Return<void> setLanguage(const hidl_string& language) override;
70 Return<void> enableAudioReturnChannel(HdmiPortId portId, bool enable) override;
71 Return<bool> isConnected(HdmiPortId portId) override;
72
73 static void eventCallback(const hdmi_event_t* event, void* /* arg */) {
74 if (mCallback != nullptr && event != nullptr) {
75 if (event->type == HDMI_EVENT_CEC_MESSAGE) {
76 size_t length =
77 std::min(event->cec.length, static_cast<size_t>(MaxLength::MESSAGE_BODY));
78 CecMessage cecMessage{
79 .initiator = static_cast<CecLogicalAddress>(event->cec.initiator),
80 .destination = static_cast<CecLogicalAddress>(event->cec.destination),
81 };
82 cecMessage.body.resize(length);
83 for (size_t i = 0; i < length; ++i) {
84 cecMessage.body[i] = static_cast<uint8_t>(event->cec.body[i]);
85 }
86 mCallback->onCecMessage(cecMessage);
87 } else if (event->type == HDMI_EVENT_HOT_PLUG) {
88 HotplugEvent hotplugEvent{
89 .connected = event->hotplug.connected > 0,
90 .portId = static_cast<HdmiPortId>(event->hotplug.port_id)};
91 mCallback->onHotplugEvent(hotplugEvent);
92 }
93 }
94 }
95
96 virtual void serviceDied(uint64_t /*cookie*/,
97 const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
98 setCallback(nullptr);
99 }
100
101 private:
102 static sp<IHdmiCecCallback> mCallback;
103 const hdmi_cec_device_t* mDevice;
104};
105
106extern "C" IHdmiCec* HIDL_FETCH_IHdmiCec(const char* name);
107
108} // namespace implementation
109} // namespace V2_0
110} // namespace cec
111} // namespace tv
112} // namespace hardware
113} // namespace android
114
115#endif // ANDROID_HARDWARE_TV_CEC_V2_0_HDMICEC_H