blob: 23118c8c150bef4b58a1542db3b0f3e10c2fe842 [file] [log] [blame]
Yixiao Luoaaa52302022-08-11 18:44:50 -07001/*
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 Zhao6bdbc5e2023-01-12 16:51:03 -080022#include <aidl/android/hardware/tv/input/TvMessageEventType.h>
23#include <fmq/AidlMessageQueue.h>
Yixiao Luoaaa52302022-08-11 18:44:50 -070024#include <map>
David Zhaoeb955ce2023-05-16 17:51:15 -070025#include <unordered_map>
Yixiao Luoaaa52302022-08-11 18:44:50 -070026#include "TvInputDeviceInfoWrapper.h"
27#include "TvStreamConfigWrapper.h"
28
29using namespace android;
30using namespace std;
31using ::aidl::android::hardware::common::NativeHandle;
David Zhao6bdbc5e2023-01-12 16:51:03 -080032using ::aidl::android::hardware::common::fmq::MQDescriptor;
33using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
34using ::android::AidlMessageQueue;
Yixiao Luoaaa52302022-08-11 18:44:50 -070035
36namespace aidl {
37namespace android {
38namespace hardware {
39namespace tv {
40namespace input {
41
David Zhaoeb955ce2023-05-16 17:51:15 -070042using TvMessageEnabledMap = std::unordered_map<
43 int32_t, std::unordered_map<int32_t, std::unordered_map<TvMessageEventType, bool>>>;
44
Yixiao Luoaaa52302022-08-11 18:44:50 -070045class TvInput : public BnTvInput {
46 public:
47 TvInput();
48
49 ::ndk::ScopedAStatus setCallback(const shared_ptr<ITvInputCallback>& in_callback) override;
David Zhao6bdbc5e2023-01-12 16:51:03 -080050 ::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 Luoaaa52302022-08-11 18:44:50 -070055 ::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;
60
61 void init();
62
63 private:
64 native_handle_t* createNativeHandle(int fd);
Yixiao Luoaaa52302022-08-11 18:44:50 -070065
66 shared_ptr<ITvInputCallback> mCallback;
67 map<int32_t, shared_ptr<TvInputDeviceInfoWrapper>> mDeviceInfos;
68 map<int32_t, map<int32_t, shared_ptr<TvStreamConfigWrapper>>> mStreamConfigs;
David Zhaoeb955ce2023-05-16 17:51:15 -070069 TvMessageEnabledMap mTvMessageEventEnabled;
Yixiao Luoaaa52302022-08-11 18:44:50 -070070};
71
72} // namespace input
73} // namespace tv
74} // namespace hardware
75} // namespace android
76} // namespace aidl