Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c721e71f authored by Ronghua Wu's avatar Ronghua Wu
Browse files

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

Bug: 20559813
Change-Id: If231cb44337ca7dc74c39fc3cd73e2b6f3cb85b8
(cherry picked from commit d4c1f6b4)
parent 5e955592
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ namespace android {

extern const char kResourceSecureCodec[];
extern const char kResourceNonSecureCodec[];
extern const char kResourceAudioCodec[];
extern const char kResourceVideoCodec[];
extern const char kResourceGraphicMemory[];

class MediaResource {
+1 −1
Original line number Diff line number Diff line
@@ -351,7 +351,7 @@ private:
    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.
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ namespace android {

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) {}
+16 −7
Original line number Diff line number Diff line
@@ -434,7 +434,8 @@ status_t MediaCodec::init(const AString &name, bool nameIsType, bool encoder) {
    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 @@ status_t MediaCodec::configure(
    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 @@ uint64_t MediaCodec::getGraphicBufferSize() {
    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 @@ status_t MediaCodec::start() {
    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 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
                        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 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
                            // 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);