• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 #include <aidl/android/hardware/tv/input/TvMessageEventType.h>
23 #include <fmq/AidlMessageQueue.h>
24 #include <map>
25 #include <unordered_map>
26 #include "TvInputDeviceInfoWrapper.h"
27 #include "TvStreamConfigWrapper.h"
28 
29 using namespace android;
30 using namespace std;
31 using ::aidl::android::hardware::common::NativeHandle;
32 using ::aidl::android::hardware::common::fmq::MQDescriptor;
33 using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
34 using ::android::AidlMessageQueue;
35 
36 namespace aidl {
37 namespace android {
38 namespace hardware {
39 namespace tv {
40 namespace input {
41 
42 using TvMessageEnabledMap = std::unordered_map<
43         int32_t, std::unordered_map<int32_t, std::unordered_map<TvMessageEventType, bool>>>;
44 
45 class TvInput : public BnTvInput {
46   public:
47     TvInput();
48 
49     ::ndk::ScopedAStatus setCallback(const shared_ptr<ITvInputCallback>& in_callback) override;
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;
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;
60     void init();
61 
62   private:
63     native_handle_t* createNativeHandle(int fd);
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;
68     TvMessageEnabledMap mTvMessageEventEnabled;
69     shared_ptr<AidlMessageQueue<int8_t, SynchronizedReadWrite>> mQueue;
70 };
71 
72 }  // namespace input
73 }  // namespace tv
74 }  // namespace hardware
75 }  // namespace android
76 }  // namespace aidl
77