作用
管理资源(Resource), 应用添加和移除资源时通知到 Service.
资源紧张时, 将根据优先级释放资源.
释放资源通过 IResourceManagerClient.reclaimResource 通知应用进行释放
启动时机
在 mediaserver 初始化时启动,并且被添加到 Service Manager 中
1.0 在 meida server 的 main 函数中实例化对象
| 
					 1 2 3 4 5 6 7  | 
						// frameworks/av/media/mediaserver/main_mediaserver.cpp int main(int argc __unused, char **argv __unused) {     ...     ResourceManagerService::instantiate();// 见 2.0     ... }  | 
					
2.0 ResourceManagerService::instantiate
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  | 
						// frameworks/av/services/mediaresourcemanager/ResourceManagerService.cpp void ResourceManagerService::instantiate() {     // 调用空构造参数的构造函数  见 3.0     std::shared_ptr<ResourceManagerService> service =             ::ndk::SharedRefBase::make<ResourceManagerService>();     // 添加到系统 service manager     binder_status_t status =             AServiceManager_addService(service->asBinder().get(), getServiceName());// getServiceName 返回 media.resource_manager     if (status != STATUS_OK) {         return;     }     // TODO: mediaserver main() is already starting the thread pool,     // move this to mediaserver main() when other services in mediaserver     // are converted to ndk-platform aidl.     //ABinderProcess_startThreadPool(); }  | 
					
3.0 ResourceManagerService::ResourceManagerService
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  | 
						// frameworks/av/services/mediaresourcemanager/ResourceManagerService.cpp ResourceManagerService::ResourceManagerService()     : ResourceManagerService(new ProcessInfo(), new SystemCallbackImpl()) {} ResourceManagerService::ResourceManagerService(         const sp<ProcessInfoInterface> &processInfo,         const sp<SystemCallbackInterface> &systemResource)     : mProcessInfo(processInfo),       mSystemCB(systemResource),       mServiceLog(new ServiceLog()),       mSupportsMultipleSecureCodecs(true),       mSupportsSecureWithNonSecureCodec(true),       mCpuBoostCount(0),       mDeathRecipient(AIBinder_DeathRecipient_new(DeathNotifier::BinderDiedCallback)) {     mSystemCB->noteResetVideo(); }  | 
					
提供的接口
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81  | 
						// frameworks/av/media/libmedia/aidl/android/media/IResourceManagerService.aidl interface IResourceManagerService {     /**      * Configure the ResourceManagerService to adopted particular policies when      * managing the resources.      *      * @param policies an array of policies to be adopted.      */     void config(in MediaResourcePolicyParcel[] policies);     /**      * Add a client to a process with a list of resources.      *      * @param pid pid of the client.      * @param uid uid of the client.      * @param clientId an identifier that uniquely identifies the client within the pid.      * @param client interface for the ResourceManagerService to call the client.      * @param resources an array of resources to be added.      */     void addResource(             int pid,             int uid,             long clientId,             IResourceManagerClient client,             in MediaResourceParcel[] resources);     /**      * Remove the listed resources from a client.      *      * @param pid pid from which the list of resources will be removed.      * @param clientId clientId within the pid from which the list of resources will be removed.      * @param resources an array of resources to be removed from the client.      */     void removeResource(int pid, long clientId, in MediaResourceParcel[] resources);     /**      * Remove all resources from a client.      *      * @param pid pid from which the client's resources will be removed.      * @param clientId clientId within the pid that will be removed.      */     void removeClient(int pid, long clientId);     /**      * Tries to reclaim resource from processes with lower priority than the      * calling process according to the requested resources.      *      * @param callingPid pid of the calling process.      * @param resources an array of resources to be reclaimed.      *      * @return true if the reclaim was successful and false otherwise.      */     boolean reclaimResource(int callingPid, in MediaResourceParcel[] resources);     /**      * Override the pid of original calling process with the pid of the process      * who actually use the requested resources.      *      * @param originalPid pid of the original calling process.      * @param newPid pid of the actual process who use the resources.      *        remove existing override on originalPid if newPid is -1.      */     void overridePid(int originalPid, int newPid);     /**      * Mark a client for pending removal      *      * @param pid pid from which the client's resources will be removed.      * @param clientId clientId within the pid that will be removed.      */     void markClientForPendingRemoval(int pid, long clientId);     /**      * Reclaim resources from clients pending removal, if any.      *      * @param pid pid from which resources will be reclaimed.      */     void reclaimResourcesFromClientsPendingRemoval(int pid); }  | 
					
0 Comments