1 /* 2 * Copyright (C) 2024 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 IM_EFILTER_CACHE_NEGOTIATE_H 17 #define IM_EFILTER_CACHE_NEGOTIATE_H 18 19 #include "efilter_cache_config.h" 20 21 #include <memory> 22 23 namespace OHOS { 24 namespace Media { 25 namespace Effect { 26 class EFilterCacheNegotiate { 27 public: 28 EFilterCacheNegotiate() = default; 29 30 ~EFilterCacheNegotiate() = default; 31 NegotiateConfig(std::shared_ptr<EFilterCacheConfig> config)32 void NegotiateConfig(std::shared_ptr<EFilterCacheConfig> config) 33 { 34 if (config == nullptr) { 35 return; 36 } 37 if (config->GetStatus() == CacheStatus::NO_CACHE) { 38 return; 39 } 40 needCache_ = true; 41 if (config->GetStatus() == CacheStatus::CACHE_START) { 42 return; 43 } 44 if (config_ == nullptr) { 45 config_ = config; 46 config_->SetStatus(CacheStatus::CACHE_USED); 47 return; 48 } 49 if (config_->GetStatus() == CacheStatus::CACHE_ENABLED) { 50 config_->SetStatus(CacheStatus::CACHE_ENABLED); 51 config_ = config; 52 config_->SetStatus(CacheStatus::CACHE_USED); 53 } 54 } 55 UseCache()56 void UseCache() 57 { 58 hasUsedCache_ = true; 59 } 60 HasUseCache()61 bool HasUseCache() 62 { 63 return hasUsedCache_; 64 } 65 needCache()66 bool needCache() 67 { 68 return needCache_; 69 } 70 HasCached()71 bool HasCached() 72 { 73 return config_ != nullptr; 74 } 75 ClearConfig()76 void ClearConfig() 77 { 78 if (config_ != nullptr && config_->GetStatus() == CacheStatus::CACHE_USED) { 79 config_->SetStatus(CacheStatus::CACHE_ENABLED); 80 } 81 hasUsedCache_ = false; 82 needCache_ = false; 83 config_ = nullptr; 84 } 85 86 private: 87 std::shared_ptr<EFilterCacheConfig> config_ = nullptr; 88 bool hasUsedCache_ = false; 89 bool needCache_ = false; 90 }; 91 } // namespace Effect 92 } // namespace Media 93 } // namespace OHOS 94 #endif // IM_EFILTER_CACHE_NEGOTIATE_H 95