Venkatarama Avadhani | 820b548 | 2022-05-18 15:19:04 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | |
Venkatarama Avadhani | 601d299 | 2022-12-12 22:29:30 +0530 | [diff] [blame] | 17 | #include <aidl/android/hardware/tv/hdmi/cec/BnHdmiCec.h> |
Venkatarama Avadhani | 820b548 | 2022-05-18 15:19:04 +0530 | [diff] [blame] | 18 | #include <algorithm> |
| 19 | #include <vector> |
| 20 | |
| 21 | using namespace std; |
| 22 | |
| 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace tv { |
Venkatarama Avadhani | 601d299 | 2022-12-12 22:29:30 +0530 | [diff] [blame] | 26 | namespace hdmi { |
Venkatarama Avadhani | 820b548 | 2022-05-18 15:19:04 +0530 | [diff] [blame] | 27 | namespace cec { |
| 28 | namespace implementation { |
| 29 | |
Venkatarama Avadhani | 601d299 | 2022-12-12 22:29:30 +0530 | [diff] [blame] | 30 | using ::aidl::android::hardware::tv::hdmi::cec::BnHdmiCec; |
| 31 | using ::aidl::android::hardware::tv::hdmi::cec::CecLogicalAddress; |
| 32 | using ::aidl::android::hardware::tv::hdmi::cec::CecMessage; |
| 33 | using ::aidl::android::hardware::tv::hdmi::cec::IHdmiCec; |
| 34 | using ::aidl::android::hardware::tv::hdmi::cec::IHdmiCecCallback; |
| 35 | using ::aidl::android::hardware::tv::hdmi::cec::Result; |
| 36 | using ::aidl::android::hardware::tv::hdmi::cec::SendMessageResult; |
Venkatarama Avadhani | 820b548 | 2022-05-18 15:19:04 +0530 | [diff] [blame] | 37 | |
| 38 | #define CEC_MSG_IN_FIFO "/dev/cec_aidl_in_pipe" |
| 39 | #define CEC_MSG_OUT_FIFO "/dev/cec_aidl_out_pipe" |
| 40 | |
| 41 | struct HdmiCecMock : public BnHdmiCec { |
| 42 | HdmiCecMock(); |
| 43 | ::ndk::ScopedAStatus addLogicalAddress(CecLogicalAddress addr, Result* _aidl_return) override; |
| 44 | ::ndk::ScopedAStatus clearLogicalAddress() override; |
| 45 | ::ndk::ScopedAStatus enableAudioReturnChannel(int32_t portId, bool enable) override; |
| 46 | ::ndk::ScopedAStatus getCecVersion(int32_t* _aidl_return) override; |
| 47 | ::ndk::ScopedAStatus getPhysicalAddress(int32_t* _aidl_return) override; |
| 48 | ::ndk::ScopedAStatus getVendorId(int32_t* _aidl_return) override; |
| 49 | ::ndk::ScopedAStatus sendMessage(const CecMessage& message, |
| 50 | SendMessageResult* _aidl_return) override; |
| 51 | ::ndk::ScopedAStatus setCallback(const std::shared_ptr<IHdmiCecCallback>& callback) override; |
| 52 | ::ndk::ScopedAStatus setLanguage(const std::string& language) override; |
| 53 | ::ndk::ScopedAStatus enableWakeupByOtp(bool value) override; |
| 54 | ::ndk::ScopedAStatus enableCec(bool value) override; |
| 55 | ::ndk::ScopedAStatus enableSystemCecControl(bool value) override; |
| 56 | void printCecMsgBuf(const char* msg_buf, int len); |
| 57 | |
| 58 | private: |
| 59 | static void* __threadLoop(void* data); |
| 60 | void threadLoop(); |
| 61 | int readMessageFromFifo(unsigned char* buf, int msgCount); |
| 62 | int sendMessageToFifo(const CecMessage& message); |
| 63 | void handleCecMessage(unsigned char* msgBuf, int length); |
| 64 | |
| 65 | private: |
| 66 | static void serviceDied(void* cookie); |
| 67 | std::shared_ptr<IHdmiCecCallback> mCallback; |
| 68 | |
| 69 | // Variables for the virtual cec hal impl |
| 70 | uint16_t mPhysicalAddress = 0xFFFF; |
| 71 | vector<CecLogicalAddress> mLogicalAddresses; |
| 72 | int32_t mCecVersion = 0x06; |
| 73 | uint32_t mCecVendorId = 0x01; |
| 74 | |
| 75 | // CEC Option value |
| 76 | bool mOptionWakeUp = 0; |
| 77 | bool mOptionEnableCec = 0; |
| 78 | bool mOptionSystemCecControl = 0; |
| 79 | int mOptionLanguage; |
| 80 | |
| 81 | // Testing variables |
| 82 | // Input file descriptor |
| 83 | int mInputFile; |
| 84 | // Output file descriptor |
| 85 | int mOutputFile; |
| 86 | bool mCecThreadRun = true; |
| 87 | pthread_t mThreadId = 0; |
| 88 | |
| 89 | ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient; |
| 90 | }; |
| 91 | } // namespace implementation |
| 92 | } // namespace cec |
Venkatarama Avadhani | 601d299 | 2022-12-12 22:29:30 +0530 | [diff] [blame] | 93 | } // namespace hdmi |
Venkatarama Avadhani | 820b548 | 2022-05-18 15:19:04 +0530 | [diff] [blame] | 94 | } // namespace tv |
| 95 | } // namespace hardware |
| 96 | } // namespace android |