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_PROCESSPRIORITYRECLAIMPOLICY_H_ 19*ec779b8eSAndroid Build Coastguard Worker #define ANDROID_MEDIA_PROCESSPRIORITYRECLAIMPOLICY_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 the Reclaim Policy based on the process priority. 31*ec779b8eSAndroid Build Coastguard Worker * 32*ec779b8eSAndroid Build Coastguard Worker * Find the lowest priority process (lower than the calling/requesting process’s priority) 33*ec779b8eSAndroid Build Coastguard Worker * that has the required resources. 34*ec779b8eSAndroid Build Coastguard Worker * From that process, find the biggest client and return the same for reclaiming. 35*ec779b8eSAndroid Build Coastguard Worker * If there is a codec co-existence policy, that is addressed as below: 36*ec779b8eSAndroid Build Coastguard Worker * - if these are any conflicting codecs, reclaim all those conflicting clients. 37*ec779b8eSAndroid Build Coastguard Worker * If no conflicting codecs, the reclaim policy will select a client in the order of: 38*ec779b8eSAndroid Build Coastguard Worker * - Find the biggest client from the lowest priority process that 39*ec779b8eSAndroid Build Coastguard Worker * has the other resources and with the given primary type. 40*ec779b8eSAndroid Build Coastguard Worker * - select the biggest client from the lower priority process that 41*ec779b8eSAndroid Build Coastguard Worker * has the primary type. 42*ec779b8eSAndroid Build Coastguard Worker * - If it's a codec reclaim request, then: 43*ec779b8eSAndroid Build Coastguard Worker * - select the biggest client from the lower priority process that 44*ec779b8eSAndroid Build Coastguard Worker * has the othe type (for example secure for a non-secure and vice versa). 45*ec779b8eSAndroid Build Coastguard Worker */ 46*ec779b8eSAndroid Build Coastguard Worker class ProcessPriorityReclaimPolicy : public IReclaimPolicy { 47*ec779b8eSAndroid Build Coastguard Worker public: 48*ec779b8eSAndroid Build Coastguard Worker ProcessPriorityReclaimPolicy(const std::shared_ptr<ResourceTracker>& resourceTracker); 49*ec779b8eSAndroid Build Coastguard Worker 50*ec779b8eSAndroid Build Coastguard Worker virtual ~ProcessPriorityReclaimPolicy(); 51*ec779b8eSAndroid Build Coastguard Worker 52*ec779b8eSAndroid Build Coastguard Worker /* 53*ec779b8eSAndroid Build Coastguard Worker * Based on the process priority, identify and return a client from the list 54*ec779b8eSAndroid Build Coastguard Worker * of given clients that satisfy the resource requested. 55*ec779b8eSAndroid Build Coastguard Worker * 56*ec779b8eSAndroid Build Coastguard Worker * @param[in] reclaimRequestInfo Information about the resource request 57*ec779b8eSAndroid Build Coastguard Worker * @param[in] client List of clients to select from. 58*ec779b8eSAndroid Build Coastguard Worker * @param[out] targetClients Upon success, this will have the list of identified client(s). 59*ec779b8eSAndroid Build Coastguard Worker * 60*ec779b8eSAndroid Build Coastguard Worker * @return true on success, false otherwise 61*ec779b8eSAndroid Build Coastguard Worker */ 62*ec779b8eSAndroid Build Coastguard Worker bool getClients(const ReclaimRequestInfo& reclaimRequestInfo, 63*ec779b8eSAndroid Build Coastguard Worker const std::vector<ClientInfo>& clients, 64*ec779b8eSAndroid Build Coastguard Worker std::vector<ClientInfo>& targetClients) override; 65*ec779b8eSAndroid Build Coastguard Worker 66*ec779b8eSAndroid Build Coastguard Worker private: 67*ec779b8eSAndroid Build Coastguard Worker 68*ec779b8eSAndroid Build Coastguard Worker // Get the biggest client with the given resources from the given list of clients. 69*ec779b8eSAndroid Build Coastguard Worker // The client should belong to lowest possible priority than that of the 70*ec779b8eSAndroid Build Coastguard Worker // calling/requesting process. 71*ec779b8eSAndroid Build Coastguard Worker // returns true on success, false otherwise 72*ec779b8eSAndroid Build Coastguard Worker // 73*ec779b8eSAndroid Build Coastguard Worker bool getBiggestClientFromLowestPriority( 74*ec779b8eSAndroid Build Coastguard Worker pid_t callingPid, 75*ec779b8eSAndroid Build Coastguard Worker int callingPriority, 76*ec779b8eSAndroid Build Coastguard Worker MediaResource::Type type, 77*ec779b8eSAndroid Build Coastguard Worker MediaResource::SubType subType, 78*ec779b8eSAndroid Build Coastguard Worker MediaResource::SubType primarySubType, 79*ec779b8eSAndroid Build Coastguard Worker const std::vector<ClientInfo>& clients, 80*ec779b8eSAndroid Build Coastguard Worker ClientInfo& targetClient, 81*ec779b8eSAndroid Build Coastguard Worker int& lowestPriority); 82*ec779b8eSAndroid Build Coastguard Worker 83*ec779b8eSAndroid Build Coastguard Worker private: 84*ec779b8eSAndroid Build Coastguard Worker std::shared_ptr<ResourceTracker> mResourceTracker; 85*ec779b8eSAndroid Build Coastguard Worker }; 86*ec779b8eSAndroid Build Coastguard Worker 87*ec779b8eSAndroid Build Coastguard Worker } // namespace android 88*ec779b8eSAndroid Build Coastguard Worker 89*ec779b8eSAndroid Build Coastguard Worker #endif // ANDROID_MEDIA_PROCESSPRIORITYRECLAIMPOLICY_H_ 90