1 /* 2 * Copyright (C) 2020 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_TRANSCODING_RESOURCE_POLICY_H 18 #define ANDROID_MEDIA_TRANSCODING_RESOURCE_POLICY_H 19 20 #include <android/binder_auto_utils.h> 21 #include <media/ResourcePolicyInterface.h> 22 #include <utils/Condition.h> 23 24 #include <mutex> 25 namespace aidl { 26 namespace android { 27 namespace media { 28 class IResourceObserverService; 29 } 30 } // namespace android 31 } // namespace aidl 32 33 namespace android { 34 35 using ::aidl::android::media::IResourceObserverService; 36 37 class TranscodingResourcePolicy : public ResourcePolicyInterface { 38 public: 39 explicit TranscodingResourcePolicy(); 40 ~TranscodingResourcePolicy(); 41 42 void setCallback(const std::shared_ptr<ResourcePolicyCallbackInterface>& cb) override; 43 void setPidResourceLost(pid_t pid) override; 44 45 private: 46 struct ResourceObserver; 47 mutable std::mutex mRegisteredLock; 48 bool mRegistered GUARDED_BY(mRegisteredLock); 49 std::shared_ptr<IResourceObserverService> mService GUARDED_BY(mRegisteredLock); 50 std::shared_ptr<ResourceObserver> mObserver; 51 52 mutable std::mutex mCallbackLock; 53 std::weak_ptr<ResourcePolicyCallbackInterface> mResourcePolicyCallback 54 GUARDED_BY(mCallbackLock); 55 pid_t mResourceLostPid GUARDED_BY(mCallbackLock); 56 57 ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient; 58 59 static void BinderDiedCallback(void* cookie); 60 61 void registerSelf(); 62 void unregisterSelf(); 63 void onResourceAvailable(pid_t pid); 64 }; // class TranscodingUidPolicy 65 66 } // namespace android 67 #endif // ANDROID_MEDIA_TRANSCODING_RESOURCE_POLICY_H 68