1*ec779b8eSAndroid Build Coastguard Worker /* 2*ec779b8eSAndroid Build Coastguard Worker ** 3*ec779b8eSAndroid Build Coastguard Worker ** Copyright 2023, The Android Open Source Project 4*ec779b8eSAndroid Build Coastguard Worker ** 5*ec779b8eSAndroid Build Coastguard Worker ** Licensed under the Apache License, Version 2.0 (the "License"); 6*ec779b8eSAndroid Build Coastguard Worker ** you may not use this file except in compliance with the License. 7*ec779b8eSAndroid Build Coastguard Worker ** You may obtain a copy of the License at 8*ec779b8eSAndroid Build Coastguard Worker ** 9*ec779b8eSAndroid Build Coastguard Worker ** http://www.apache.org/licenses/LICENSE-2.0 10*ec779b8eSAndroid Build Coastguard Worker ** 11*ec779b8eSAndroid Build Coastguard Worker ** Unless required by applicable law or agreed to in writing, software 12*ec779b8eSAndroid Build Coastguard Worker ** distributed under the License is distributed on an "AS IS" BASIS, 13*ec779b8eSAndroid Build Coastguard Worker ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*ec779b8eSAndroid Build Coastguard Worker ** See the License for the specific language governing permissions and 15*ec779b8eSAndroid Build Coastguard Worker ** limitations under the License. 16*ec779b8eSAndroid Build Coastguard Worker */ 17*ec779b8eSAndroid Build Coastguard Worker 18*ec779b8eSAndroid Build Coastguard Worker #ifndef ANDROID_MEDIA_CLIENTIMPORTANCERECLAIMPOLICY_H_ 19*ec779b8eSAndroid Build Coastguard Worker #define ANDROID_MEDIA_CLIENTIMPORTANCERECLAIMPOLICY_H_ 20*ec779b8eSAndroid Build Coastguard Worker 21*ec779b8eSAndroid Build Coastguard Worker #include <media/MediaResource.h> 22*ec779b8eSAndroid Build Coastguard Worker #include "IReclaimPolicy.h" 23*ec779b8eSAndroid Build Coastguard Worker 24*ec779b8eSAndroid Build Coastguard Worker namespace android { 25*ec779b8eSAndroid Build Coastguard Worker 26*ec779b8eSAndroid Build Coastguard Worker class ResourceTracker; 27*ec779b8eSAndroid Build Coastguard Worker struct ClientInfo; 28*ec779b8eSAndroid Build Coastguard Worker 29*ec779b8eSAndroid Build Coastguard Worker /* 30*ec779b8eSAndroid Build Coastguard Worker * Implementation of Reclaim Policy based on the client's importance. 31*ec779b8eSAndroid Build Coastguard Worker * 32*ec779b8eSAndroid Build Coastguard Worker * Find the least important (other than that of requesting client) client from the 33*ec779b8eSAndroid Build Coastguard Worker * same process (that is requesting for the resource). 34*ec779b8eSAndroid Build Coastguard Worker * If there are multiple clients with least importance, then pick the biggest 35*ec779b8eSAndroid Build Coastguard Worker * client among them. 36*ec779b8eSAndroid Build Coastguard Worker * 37*ec779b8eSAndroid Build Coastguard Worker */ 38*ec779b8eSAndroid Build Coastguard Worker class ClientImportanceReclaimPolicy : public IReclaimPolicy { 39*ec779b8eSAndroid Build Coastguard Worker public: 40*ec779b8eSAndroid Build Coastguard Worker explicit ClientImportanceReclaimPolicy(const std::shared_ptr<ResourceTracker>& resourceTracker); 41*ec779b8eSAndroid Build Coastguard Worker 42*ec779b8eSAndroid Build Coastguard Worker virtual ~ClientImportanceReclaimPolicy(); 43*ec779b8eSAndroid Build Coastguard Worker 44*ec779b8eSAndroid Build Coastguard Worker /* 45*ec779b8eSAndroid Build Coastguard Worker * Based on the client importance, identify and return the least important client of 46*ec779b8eSAndroid Build Coastguard Worker * the requesting process from the list of given clients that satisfy the resource requested. 47*ec779b8eSAndroid Build Coastguard Worker * 48*ec779b8eSAndroid Build Coastguard Worker * @param[in] reclaimRequestInfo Information about the resource request 49*ec779b8eSAndroid Build Coastguard Worker * @param[in] client List of clients to select from. 50*ec779b8eSAndroid Build Coastguard Worker * @param[out] targetClients Upon success, this will have the list of identified client(s). 51*ec779b8eSAndroid Build Coastguard Worker * 52*ec779b8eSAndroid Build Coastguard Worker * @return true on success, false otherwise 53*ec779b8eSAndroid Build Coastguard Worker */ 54*ec779b8eSAndroid Build Coastguard Worker bool getClients(const ReclaimRequestInfo& reclaimRequestInfo, 55*ec779b8eSAndroid Build Coastguard Worker const std::vector<ClientInfo>& clients, 56*ec779b8eSAndroid Build Coastguard Worker std::vector<ClientInfo>& targetClients) override; 57*ec779b8eSAndroid Build Coastguard Worker 58*ec779b8eSAndroid Build Coastguard Worker private: 59*ec779b8eSAndroid Build Coastguard Worker std::shared_ptr<ResourceTracker> mResourceTracker; 60*ec779b8eSAndroid Build Coastguard Worker }; 61*ec779b8eSAndroid Build Coastguard Worker 62*ec779b8eSAndroid Build Coastguard Worker } // namespace android 63*ec779b8eSAndroid Build Coastguard Worker 64*ec779b8eSAndroid Build Coastguard Worker #endif // ANDROID_MEDIA_CLIENTIMPORTANCERECLAIMPOLICY_H_ 65