diff options
| author | Ronghua Wu <ronghuawu@google.com> | 2015-03-13 10:47:08 -0700 | 
|---|---|---|
| committer | Ronghua Wu <ronghuawu@google.com> | 2015-04-14 14:16:12 -0700 | 
| commit | 67e7f543c7f1c4fe4ee1989ceb0aebe44a63b49e (patch) | |
| tree | 7de894fc9626b36de6eed70812962380ca217f22 /services/mediaresourcemanager | |
| parent | 9e6955a19bf77ebf27b770e910efbe1ebf1ceac0 (diff) | |
| download | frameworks_av-67e7f543c7f1c4fe4ee1989ceb0aebe44a63b49e.zip frameworks_av-67e7f543c7f1c4fe4ee1989ceb0aebe44a63b49e.tar.gz frameworks_av-67e7f543c7f1c4fe4ee1989ceb0aebe44a63b49e.tar.bz2  | |
media: use ResourceManagerService with MediaCodec
Bug: 19620911
Change-Id: I235a97e5195b28645b7834dda0dd77307d93f4a8
Diffstat (limited to 'services/mediaresourcemanager')
| -rw-r--r-- | services/mediaresourcemanager/ResourceManagerService.cpp | 44 | ||||
| -rw-r--r-- | services/mediaresourcemanager/test/ResourceManagerService_test.cpp | 68 | 
2 files changed, 106 insertions, 6 deletions
diff --git a/services/mediaresourcemanager/ResourceManagerService.cpp b/services/mediaresourcemanager/ResourceManagerService.cpp index 7296d47..75a69ed 100644 --- a/services/mediaresourcemanager/ResourceManagerService.cpp +++ b/services/mediaresourcemanager/ResourceManagerService.cpp @@ -126,6 +126,7 @@ void ResourceManagerService::addResource(      Mutex::Autolock lock(mLock);      ResourceInfos& infos = getResourceInfosForEdit(pid, mMap);      ResourceInfo& info = getResourceInfoForEdit(clientId, client, infos); +    // TODO: do the merge instead of append.      info.resources.appendVector(resources);  } @@ -197,19 +198,58 @@ bool ResourceManagerService::reclaimResource(                  }              }          } + +        if (clients.size() == 0) { +            // if we are here, run the third pass to free one codec with the same type. +            for (size_t i = 0; i < resources.size(); ++i) { +                String8 type = resources[i].mType; +                if (type == kResourceSecureCodec || type == kResourceNonSecureCodec) { +                    sp<IResourceManagerClient> client; +                    if (!getLowestPriorityBiggestClient_l(callingPid, type, &client)) { +                        return false; +                    } +                    clients.push_back(client); +                } +            } +        }      }      if (clients.size() == 0) {          return false;      } +    sp<IResourceManagerClient> failedClient;      for (size_t i = 0; i < clients.size(); ++i) {          ALOGV("reclaimResource from client %p", clients[i].get());          if (!clients[i]->reclaimResource()) { -            return false; +            failedClient = clients[i]; +            break;          }      } -    return true; + +    { +        Mutex::Autolock lock(mLock); +        bool found = false; +        for (size_t i = 0; i < mMap.size(); ++i) { +            ResourceInfos &infos = mMap.editValueAt(i); +            for (size_t j = 0; j < infos.size();) { +                if (infos[j].client == failedClient) { +                    j = infos.removeAt(j); +                    found = true; +                } else { +                    ++j; +                } +            } +            if (found) { +                break; +            } +        } +        if (!found) { +            ALOGV("didn't find failed client"); +        } +    } + +    return (failedClient == NULL);  }  bool ResourceManagerService::getAllClients_l( diff --git a/services/mediaresourcemanager/test/ResourceManagerService_test.cpp b/services/mediaresourcemanager/test/ResourceManagerService_test.cpp index b73e1bc..48d1395 100644 --- a/services/mediaresourcemanager/test/ResourceManagerService_test.cpp +++ b/services/mediaresourcemanager/test/ResourceManagerService_test.cpp @@ -1,5 +1,5 @@  /* - * Copyright (C) 2015 The Android Open Source Project + * Copyright 2015 The Android Open Source Project   *   * Licensed under the Apache License, Version 2.0 (the "License");   * you may not use this file except in compliance with the License. @@ -118,6 +118,20 @@ protected:          client3->reset();      } +    // test set up +    // --------------------------------------------------------------------------------- +    //   pid                priority         client           type               number +    // --------------------------------------------------------------------------------- +    //   kTestPid1(30)      30               mTestClient1     secure codec       1 +    //                                                        graphic memory     200 +    //                                                        graphic memory     200 +    // --------------------------------------------------------------------------------- +    //   kTestPid2(20)      20               mTestClient2     non-secure codec   1 +    //                                                        graphic memory     300 +    //                                       ------------------------------------------- +    //                                       mTestClient3     secure codec       1 +    //                                                        graphic memory     100 +    // ---------------------------------------------------------------------------------      void addResource() {          // kTestPid1 mTestClient1          Vector<MediaResource> resources1; @@ -202,10 +216,12 @@ protected:          int lowPriorityPid = 100;          EXPECT_FALSE(mService->getAllClients_l(lowPriorityPid, type, &clients));          int midPriorityPid = 25; -        EXPECT_FALSE(mService->getAllClients_l(lowPriorityPid, type, &clients)); +        // some higher priority process (e.g. kTestPid2) owns the resource, so getAllClients_l +        // will fail. +        EXPECT_FALSE(mService->getAllClients_l(midPriorityPid, type, &clients));          int highPriorityPid = 10; -        EXPECT_TRUE(mService->getAllClients_l(10, unknowType, &clients)); -        EXPECT_TRUE(mService->getAllClients_l(10, type, &clients)); +        EXPECT_TRUE(mService->getAllClients_l(highPriorityPid, unknowType, &clients)); +        EXPECT_TRUE(mService->getAllClients_l(highPriorityPid, type, &clients));          EXPECT_EQ(2u, clients.size());          EXPECT_EQ(mTestClient3, clients[0]); @@ -308,6 +324,30 @@ protected:              // nothing left              EXPECT_FALSE(mService->reclaimResource(10, resources));          } + +        // ### secure codecs can coexist and secure codec can coexist with non-secure codec ### +        { +            addResource(); +            mService->mSupportsMultipleSecureCodecs = true; +            mService->mSupportsSecureWithNonSecureCodec = true; + +            Vector<MediaResource> resources; +            resources.push_back(MediaResource(String8(kResourceSecureCodec), 1)); + +            EXPECT_TRUE(mService->reclaimResource(10, resources)); +            // secure codec from lowest process got reclaimed +            verifyClients(true, false, false); + +            // call again should reclaim another secure codec from lowest process +            EXPECT_TRUE(mService->reclaimResource(10, resources)); +            verifyClients(false, false, true); + +            // nothing left +            EXPECT_FALSE(mService->reclaimResource(10, resources)); + +            // clean up client 2 which still has non secure codec left +            mService->removeResource((int64_t) mTestClient2.get()); +        }      }      void testReclaimResourceNonSecure() { @@ -360,6 +400,26 @@ protected:              // nothing left              EXPECT_FALSE(mService->reclaimResource(10, resources));          } + +        // ### secure codec can coexist with non-secure codec ### +        { +            addResource(); +            mService->mSupportsSecureWithNonSecureCodec = true; + +            Vector<MediaResource> resources; +            resources.push_back(MediaResource(String8(kResourceNonSecureCodec), 1)); + +            EXPECT_TRUE(mService->reclaimResource(10, resources)); +            // one non secure codec from lowest process got reclaimed +            verifyClients(false, true, false); + +            // nothing left +            EXPECT_FALSE(mService->reclaimResource(10, resources)); + +            // clean up client 1 and 3 which still have secure codec left +            mService->removeResource((int64_t) mTestClient1.get()); +            mService->removeResource((int64_t) mTestClient3.get()); +        }      }      void testGetLowestPriorityBiggestClient() {  | 
