1 /** 2 * Copyright 2021, 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_MEDIA_TUNERFILTER_H 18 #define ANDROID_MEDIA_TUNERFILTER_H 19 20 #include <aidl/android/hardware/tv/tuner/AvStreamType.h> 21 #include <aidl/android/hardware/tv/tuner/BnFilterCallback.h> 22 #include <aidl/android/hardware/tv/tuner/DemuxFilterEvent.h> 23 #include <aidl/android/hardware/tv/tuner/DemuxFilterSettings.h> 24 #include <aidl/android/hardware/tv/tuner/DemuxFilterStatus.h> 25 #include <aidl/android/hardware/tv/tuner/DemuxFilterType.h> 26 #include <aidl/android/hardware/tv/tuner/FilterDelayHint.h> 27 #include <aidl/android/hardware/tv/tuner/IFilter.h> 28 #include <aidl/android/media/tv/tuner/BnTunerFilter.h> 29 #include <aidl/android/media/tv/tuner/ITunerFilterCallback.h> 30 #include <utils/Mutex.h> 31 32 using ::aidl::android::hardware::common::NativeHandle; 33 using ::aidl::android::hardware::common::fmq::MQDescriptor; 34 using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite; 35 using ::aidl::android::hardware::tv::tuner::AvStreamType; 36 using ::aidl::android::hardware::tv::tuner::BnFilterCallback; 37 using ::aidl::android::hardware::tv::tuner::DemuxFilterEvent; 38 using ::aidl::android::hardware::tv::tuner::DemuxFilterSettings; 39 using ::aidl::android::hardware::tv::tuner::DemuxFilterStatus; 40 using ::aidl::android::hardware::tv::tuner::DemuxFilterType; 41 using ::aidl::android::hardware::tv::tuner::FilterDelayHint; 42 using ::aidl::android::hardware::tv::tuner::IFilter; 43 using ::aidl::android::media::tv::tuner::BnTunerFilter; 44 using ::android::Mutex; 45 46 using namespace std; 47 48 namespace aidl { 49 namespace android { 50 namespace media { 51 namespace tv { 52 namespace tuner { 53 54 using AidlMQDesc = MQDescriptor<int8_t, SynchronizedReadWrite>; 55 56 class TunerFilter : public BnTunerFilter { 57 58 public: 59 class FilterCallback : public BnFilterCallback { 60 public: FilterCallback(const shared_ptr<ITunerFilterCallback> & tunerFilterCallback)61 FilterCallback(const shared_ptr<ITunerFilterCallback>& tunerFilterCallback) 62 : mTunerFilterCallback(tunerFilterCallback), mOriginalCallback(nullptr){}; 63 64 ::ndk::ScopedAStatus onFilterEvent(const vector<DemuxFilterEvent>& events) override; 65 ::ndk::ScopedAStatus onFilterStatus(DemuxFilterStatus status) override; 66 67 void sendSharedFilterStatus(int32_t status); 68 void attachSharedFilterCallback(const shared_ptr<ITunerFilterCallback>& in_cb); 69 void detachSharedFilterCallback(); 70 void detachCallbacks(); 71 72 private: 73 shared_ptr<ITunerFilterCallback> mTunerFilterCallback; 74 shared_ptr<ITunerFilterCallback> mOriginalCallback; 75 Mutex mCallbackLock; 76 }; 77 78 TunerFilter(shared_ptr<IFilter> filter, shared_ptr<FilterCallback> cb, DemuxFilterType type); 79 virtual ~TunerFilter(); 80 81 ::ndk::ScopedAStatus getId(int32_t* _aidl_return) override; 82 ::ndk::ScopedAStatus getId64Bit(int64_t* _aidl_return) override; 83 ::ndk::ScopedAStatus getQueueDesc(AidlMQDesc* _aidl_return) override; 84 ::ndk::ScopedAStatus configure(const DemuxFilterSettings& in_settings) override; 85 ::ndk::ScopedAStatus configureMonitorEvent(int32_t in_monitorEventTypes) override; 86 ::ndk::ScopedAStatus configureIpFilterContextId(int32_t in_cid) override; 87 ::ndk::ScopedAStatus configureAvStreamType(const AvStreamType& in_avStreamType) override; 88 ::ndk::ScopedAStatus getAvSharedHandle(NativeHandle* out_avMemory, 89 int64_t* _aidl_return) override; 90 ::ndk::ScopedAStatus releaseAvHandle(const NativeHandle& in_handle, 91 int64_t in_avDataId) override; 92 ::ndk::ScopedAStatus setDataSource(const shared_ptr<ITunerFilter>& in_filter) override; 93 ::ndk::ScopedAStatus start() override; 94 ::ndk::ScopedAStatus stop() override; 95 ::ndk::ScopedAStatus flush() override; 96 ::ndk::ScopedAStatus close() override; 97 ::ndk::ScopedAStatus acquireSharedFilterToken(string* _aidl_return) override; 98 ::ndk::ScopedAStatus freeSharedFilterToken(const string& in_filterToken) override; 99 ::ndk::ScopedAStatus getFilterType(DemuxFilterType* _aidl_return) override; 100 ::ndk::ScopedAStatus setDelayHint(const FilterDelayHint& in_hint) override; 101 102 bool isSharedFilterAllowed(int32_t pid); 103 void attachSharedFilterCallback(const shared_ptr<ITunerFilterCallback>& in_cb); 104 shared_ptr<IFilter> getHalFilter(); 105 106 private: 107 shared_ptr<IFilter> mFilter; 108 int32_t mId; 109 int64_t mId64Bit; 110 DemuxFilterType mType; 111 bool mStarted; 112 bool mShared; 113 int32_t mClientPid; 114 shared_ptr<FilterCallback> mFilterCallback; 115 Mutex mLock; 116 }; 117 118 } // namespace tuner 119 } // namespace tv 120 } // namespace media 121 } // namespace android 122 } // namespace aidl 123 124 #endif // ANDROID_MEDIA_TUNERFILTER_H 125