DO NOT MERGE libmedia: add sub resource type audio-codec and video-codec.

Bug: 20559813
Change-Id: If231cb44337ca7dc74c39fc3cd73e2b6f3cb85b8
(cherry picked from commit d4c1f6b4ecfef7323422359fc38bd1edb1abf205)
diff --git a/include/media/MediaResource.h b/include/media/MediaResource.h
index 0b57c84..20f2cad 100644
--- a/include/media/MediaResource.h
+++ b/include/media/MediaResource.h
@@ -25,6 +25,8 @@
 
 extern const char kResourceSecureCodec[];
 extern const char kResourceNonSecureCodec[];
+extern const char kResourceAudioCodec[];
+extern const char kResourceVideoCodec[];
 extern const char kResourceGraphicMemory[];
 
 class MediaResource {
diff --git a/include/media/stagefright/MediaCodec.h b/include/media/stagefright/MediaCodec.h
index f2b21c9..d89e4c7 100644
--- a/include/media/stagefright/MediaCodec.h
+++ b/include/media/stagefright/MediaCodec.h
@@ -351,7 +351,7 @@
     bool isExecuting() const;
 
     uint64_t getGraphicBufferSize();
-    void addResource(const char *type, uint64_t value);
+    void addResource(const String8 &type, const String8 &subtype, uint64_t value);
 
     /* called to get the last codec error when the sticky flag is set.
      * if no such codec error is found, returns UNKNOWN_ERROR.
diff --git a/media/libmedia/MediaResource.cpp b/media/libmedia/MediaResource.cpp
index eea2c43..40ec0cb 100644
--- a/media/libmedia/MediaResource.cpp
+++ b/media/libmedia/MediaResource.cpp
@@ -23,6 +23,8 @@
 
 const char kResourceSecureCodec[] = "secure-codec";
 const char kResourceNonSecureCodec[] = "non-secure-codec";
+const char kResourceAudioCodec[] = "audio-codec";
+const char kResourceVideoCodec[] = "video-codec";
 const char kResourceGraphicMemory[] = "graphic-memory";
 
 MediaResource::MediaResource() : mValue(0) {}
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index 7065a6e..aa0d2e6 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -434,7 +434,8 @@
     status_t err;
     Vector<MediaResource> resources;
     const char *type = secureCodec ? kResourceSecureCodec : kResourceNonSecureCodec;
-    resources.push_back(MediaResource(String8(type), 1));
+    const char *subtype = mIsVideo ? kResourceVideoCodec : kResourceAudioCodec;
+    resources.push_back(MediaResource(String8(type), String8(subtype), 1));
     for (int i = 0; i <= kMaxRetry; ++i) {
         if (i > 0) {
             // Don't try to reclaim resource for the first time.
@@ -492,7 +493,8 @@
     Vector<MediaResource> resources;
     const char *type = (mFlags & kFlagIsSecure) ?
             kResourceSecureCodec : kResourceNonSecureCodec;
-    resources.push_back(MediaResource(String8(type), 1));
+    const char *subtype = mIsVideo ? kResourceVideoCodec : kResourceAudioCodec;
+    resources.push_back(MediaResource(String8(type), String8(subtype), 1));
     // Don't know the buffer size at this point, but it's fine to use 1 because
     // the reclaimResource call doesn't consider the requester's buffer size for now.
     resources.push_back(MediaResource(String8(kResourceGraphicMemory), 1));
@@ -557,9 +559,9 @@
     return size;
 }
 
-void MediaCodec::addResource(const char *type, uint64_t value) {
+void MediaCodec::addResource(const String8 &type, const String8 &subtype, uint64_t value) {
     Vector<MediaResource> resources;
-    resources.push_back(MediaResource(String8(type), value));
+    resources.push_back(MediaResource(type, subtype, value));
     mResourceManagerService->addResource(
             getCallingPid(), getId(mResourceManagerClient), mResourceManagerClient, resources);
 }
@@ -571,7 +573,8 @@
     Vector<MediaResource> resources;
     const char *type = (mFlags & kFlagIsSecure) ?
             kResourceSecureCodec : kResourceNonSecureCodec;
-    resources.push_back(MediaResource(String8(type), 1));
+    const char *subtype = mIsVideo ? kResourceVideoCodec : kResourceAudioCodec;
+    resources.push_back(MediaResource(String8(type), String8(subtype), 1));
     // Don't know the buffer size at this point, but it's fine to use 1 because
     // the reclaimResource call doesn't consider the requester's buffer size for now.
     resources.push_back(MediaResource(String8(kResourceGraphicMemory), 1));
@@ -1183,7 +1186,9 @@
                         mFlags &= ~kFlagIsSecure;
                         resourceType = String8(kResourceNonSecureCodec);
                     }
-                    addResource(resourceType, 1);
+
+                    const char *subtype = mIsVideo ? kResourceVideoCodec : kResourceAudioCodec;
+                    addResource(resourceType, String8(subtype), 1);
 
                     (new AMessage)->postReply(mReplyID);
                     break;
@@ -1297,7 +1302,11 @@
                             // allocating input buffers, so this is a good
                             // indication that now all buffers are allocated.
                             if (mIsVideo) {
-                                addResource(kResourceGraphicMemory, getGraphicBufferSize());
+                                String8 subtype;
+                                addResource(
+                                        String8(kResourceGraphicMemory),
+                                        subtype,
+                                        getGraphicBufferSize());
                             }
                             setState(STARTED);
                             (new AMessage)->postReply(mReplyID);