blob: 0a708fa919f1951113734f584325e51110da45a7 [file] [log] [blame]
Amye4ddc0d2019-06-13 19:21:24 -07001/*
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_V1_0_HDMICEC_H
18#define ANDROID_HARDWARE_TV_CEC_V1_0_HDMICEC_H
19
20#include <android/hardware/tv/cec/1.0/IHdmiCec.h>
21#include <hardware/hardware.h>
22#include <hardware/hdmi_cec.h>
23#include <hidl/MQDescriptor.h>
24#include <hidl/Status.h>
25#include <algorithm>
26#include <vector>
27
28using namespace std;
29
30namespace android {
31namespace hardware {
32namespace tv {
33namespace cec {
34namespace V1_0 {
35namespace implementation {
36
37using ::android::sp;
38using ::android::hardware::hidl_string;
39using ::android::hardware::hidl_vec;
40using ::android::hardware::Return;
41using ::android::hardware::Void;
42using ::android::hardware::tv::cec::V1_0::CecLogicalAddress;
43using ::android::hardware::tv::cec::V1_0::CecMessage;
44using ::android::hardware::tv::cec::V1_0::HdmiPortInfo;
45using ::android::hardware::tv::cec::V1_0::IHdmiCec;
46using ::android::hardware::tv::cec::V1_0::IHdmiCecCallback;
47using ::android::hardware::tv::cec::V1_0::MaxLength;
48using ::android::hardware::tv::cec::V1_0::OptionKey;
49using ::android::hardware::tv::cec::V1_0::Result;
50using ::android::hardware::tv::cec::V1_0::SendMessageResult;
51
Amy6490b2f2019-07-18 16:34:49 -070052#define CEC_MSG_IN_FIFO "/dev/cec_in_pipe"
53#define CEC_MSG_OUT_FIFO "/dev/cec_out_pipe"
54
Amye4ddc0d2019-06-13 19:21:24 -070055struct HdmiCecMock : public IHdmiCec, public hidl_death_recipient {
56 HdmiCecMock();
57 // Methods from ::android::hardware::tv::cec::V1_0::IHdmiCec follow.
58 Return<Result> addLogicalAddress(CecLogicalAddress addr) override;
59 Return<void> clearLogicalAddress() override;
60 Return<void> getPhysicalAddress(getPhysicalAddress_cb _hidl_cb) override;
61 Return<SendMessageResult> sendMessage(const CecMessage& message) override;
62 Return<void> setCallback(const sp<IHdmiCecCallback>& callback) override;
63 Return<int32_t> getCecVersion() override;
64 Return<uint32_t> getVendorId() override;
65 Return<void> getPortInfo(getPortInfo_cb _hidl_cb) override;
66 Return<void> setOption(OptionKey key, bool value) override;
67 Return<void> setLanguage(const hidl_string& language) override;
68 Return<void> enableAudioReturnChannel(int32_t portId, bool enable) override;
69 Return<bool> isConnected(int32_t portId) override;
70
71 virtual void serviceDied(uint64_t /*cookie*/,
72 const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
73 setCallback(nullptr);
74 }
75
76 void cec_set_option(int flag, int value);
Amy6490b2f2019-07-18 16:34:49 -070077 void printCecMsgBuf(const char* msg_buf, int len);
78
79 private:
80 static void* __threadLoop(void* data);
81 void threadLoop();
82 int readMessageFromFifo(unsigned char* buf, int msgCount);
83 int sendMessageToFifo(const CecMessage& message);
84 void handleHotplugMessage(unsigned char* msgBuf);
85 void handleCecMessage(unsigned char* msgBuf, int length);
Amye4ddc0d2019-06-13 19:21:24 -070086
87 private:
88 sp<IHdmiCecCallback> mCallback;
Amy6490b2f2019-07-18 16:34:49 -070089
Amye4ddc0d2019-06-13 19:21:24 -070090 // Variables for the virtual cec hal impl
91 uint16_t mPhysicalAddress = 0xFFFF;
92 vector<CecLogicalAddress> mLogicalAddresses;
93 int32_t mCecVersion = 0;
94 uint32_t mCecVendorId = 0;
Amy6490b2f2019-07-18 16:34:49 -070095
Amye4ddc0d2019-06-13 19:21:24 -070096 // Port configuration
Amy6490b2f2019-07-18 16:34:49 -070097 int mTotalPorts = 1;
98 hidl_vec<HdmiPortInfo> mPortInfo;
99 hidl_vec<bool> mPortConnectionStatus;
100
Amye4ddc0d2019-06-13 19:21:24 -0700101 // CEC Option value
102 int mOptionWakeUp = 0;
103 int mOptionEnableCec = 0;
104 int mOptionSystemCecControl = 0;
105 int mOptionLanguage = 0;
Amy6490b2f2019-07-18 16:34:49 -0700106
107 // Testing variables
108 // Input file descriptor
109 int mInputFile;
110 // Output file descriptor
111 int mOutputFile;
112 bool mCecThreadRun = true;
113 pthread_t mThreadId = 0;
Amye4ddc0d2019-06-13 19:21:24 -0700114};
115} // namespace implementation
116} // namespace V1_0
117} // namespace cec
118} // namespace tv
119} // namespace hardware
120} // namespace android
121
122#endif // ANDROID_HARDWARE_TV_CEC_V1_0_HDMICEC_H