Yixiao Luo | aaa5230 | 2022-08-11 18:44:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <aidl/android/hardware/tv/input/BnTvInput.h> |
| 20 | #include <utils/KeyedVector.h> |
| 21 | |
David Zhao | 6bdbc5e | 2023-01-12 16:51:03 -0800 | [diff] [blame] | 22 | #include <aidl/android/hardware/tv/input/TvMessageEventType.h> |
| 23 | #include <fmq/AidlMessageQueue.h> |
Yixiao Luo | aaa5230 | 2022-08-11 18:44:50 -0700 | [diff] [blame] | 24 | #include <map> |
David Zhao | eb955ce | 2023-05-16 17:51:15 -0700 | [diff] [blame] | 25 | #include <unordered_map> |
Yixiao Luo | aaa5230 | 2022-08-11 18:44:50 -0700 | [diff] [blame] | 26 | #include "TvInputDeviceInfoWrapper.h" |
| 27 | #include "TvStreamConfigWrapper.h" |
| 28 | |
| 29 | using namespace android; |
| 30 | using namespace std; |
| 31 | using ::aidl::android::hardware::common::NativeHandle; |
David Zhao | 6bdbc5e | 2023-01-12 16:51:03 -0800 | [diff] [blame] | 32 | using ::aidl::android::hardware::common::fmq::MQDescriptor; |
| 33 | using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite; |
| 34 | using ::android::AidlMessageQueue; |
Yixiao Luo | aaa5230 | 2022-08-11 18:44:50 -0700 | [diff] [blame] | 35 | |
| 36 | namespace aidl { |
| 37 | namespace android { |
| 38 | namespace hardware { |
| 39 | namespace tv { |
| 40 | namespace input { |
| 41 | |
David Zhao | eb955ce | 2023-05-16 17:51:15 -0700 | [diff] [blame] | 42 | using TvMessageEnabledMap = std::unordered_map< |
| 43 | int32_t, std::unordered_map<int32_t, std::unordered_map<TvMessageEventType, bool>>>; |
| 44 | |
Yixiao Luo | aaa5230 | 2022-08-11 18:44:50 -0700 | [diff] [blame] | 45 | class TvInput : public BnTvInput { |
| 46 | public: |
| 47 | TvInput(); |
| 48 | |
| 49 | ::ndk::ScopedAStatus setCallback(const shared_ptr<ITvInputCallback>& in_callback) override; |
David Zhao | 6bdbc5e | 2023-01-12 16:51:03 -0800 | [diff] [blame] | 50 | ::ndk::ScopedAStatus setTvMessageEnabled(int32_t deviceId, int32_t streamId, |
| 51 | TvMessageEventType in_type, bool enabled) override; |
| 52 | ::ndk::ScopedAStatus getTvMessageQueueDesc( |
| 53 | MQDescriptor<int8_t, SynchronizedReadWrite>* out_queue, int32_t in_deviceId, |
| 54 | int32_t in_streamId) override; |
Yixiao Luo | aaa5230 | 2022-08-11 18:44:50 -0700 | [diff] [blame] | 55 | ::ndk::ScopedAStatus getStreamConfigurations(int32_t in_deviceId, |
| 56 | vector<TvStreamConfig>* _aidl_return) override; |
| 57 | ::ndk::ScopedAStatus openStream(int32_t in_deviceId, int32_t in_streamId, |
| 58 | NativeHandle* _aidl_return) override; |
| 59 | ::ndk::ScopedAStatus closeStream(int32_t in_deviceId, int32_t in_streamId) override; |
Yixiao Luo | aaa5230 | 2022-08-11 18:44:50 -0700 | [diff] [blame] | 60 | void init(); |
| 61 | |
| 62 | private: |
| 63 | native_handle_t* createNativeHandle(int fd); |
Yixiao Luo | aaa5230 | 2022-08-11 18:44:50 -0700 | [diff] [blame] | 64 | |
| 65 | shared_ptr<ITvInputCallback> mCallback; |
| 66 | map<int32_t, shared_ptr<TvInputDeviceInfoWrapper>> mDeviceInfos; |
| 67 | map<int32_t, map<int32_t, shared_ptr<TvStreamConfigWrapper>>> mStreamConfigs; |
David Zhao | eb955ce | 2023-05-16 17:51:15 -0700 | [diff] [blame] | 68 | TvMessageEnabledMap mTvMessageEventEnabled; |
David Zhao | 0dc2bc6 | 2023-10-17 11:56:52 -0700 | [diff] [blame] | 69 | shared_ptr<AidlMessageQueue<int8_t, SynchronizedReadWrite>> mQueue; |
Yixiao Luo | aaa5230 | 2022-08-11 18:44:50 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | } // namespace input |
| 73 | } // namespace tv |
| 74 | } // namespace hardware |
| 75 | } // namespace android |
| 76 | } // namespace aidl |