1 /* 2 * Copyright (C) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BACKGROUND_EVENT_HANDLER_H 17 #define BACKGROUND_EVENT_HANDLER_H 18 19 #include <mutex> 20 #include <unordered_map> 21 #include <vector> 22 #include "instance_info.h" 23 #include "refbase.h" 24 25 namespace OHOS { 26 namespace MediaAVCodec { 27 using ObjectList = std::unordered_multimap<pid_t, InstanceId>; 28 29 class BackGroundEventHandler { 30 public: 31 static BackGroundEventHandler &GetInstance(); 32 void NotifyFreeze(InstanceId instanceId); 33 void NotifyFreeze(const std::vector<pid_t> &pidList); 34 void NotifyActive(InstanceId instanceId); 35 void NotifyActive(const std::vector<pid_t> &pidList); 36 void NotifyActiveAll(); 37 void ErasePid(pid_t pid); 38 void EraseInstance(InstanceId instanceId); 39 40 private: BackGroundEventHandler()41 BackGroundEventHandler() {}; 42 ~BackGroundEventHandler() = default; 43 44 std::recursive_mutex mutex_; 45 ObjectList memoryRecycleList_; 46 ObjectList suspendList_; 47 }; 48 } // namespace MediaAVCodec 49 } // namespace OHOS 50 #endif // BACKGROUND_EVENT_HANDLER_H