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

Commit ecda7fe5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "codec metrics for resource reclaim" am: 75657297 am: 3e1d0a33 am:...

Merge "codec metrics for resource reclaim" am: 75657297 am: 3e1d0a33 am: 372a252c am: a7e55fe8

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/2451485



Change-Id: I5ccd1bfa86df8fea47446eb2f342090780abc148
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents e3892129 a7e55fe8
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
namespace android {

using aidl::android::media::MediaResourceParcel;
using aidl::android::media::ClientInfoParcel;

namespace {
void ResourceManagerServiceDied(void* cookie) {
@@ -137,7 +138,10 @@ void DrmSessionManager::addSession(int pid,

    static int64_t clientId = 0;
    mSessionMap[toStdVec(sessionId)] = (SessionInfo){pid, uid, clientId};
    mService->addResource(pid, uid, clientId++, drm, toResourceVec(sessionId, INT64_MAX));
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(pid),
                                .uid = static_cast<int32_t>(uid),
                                .id = clientId++};
    mService->addResource(clientInfo, drm, toResourceVec(sessionId, INT64_MAX));
}

void DrmSessionManager::useSession(const Vector<uint8_t> &sessionId) {
@@ -150,7 +154,10 @@ void DrmSessionManager::useSession(const Vector<uint8_t> &sessionId) {
    }

    auto info = it->second;
    mService->addResource(info.pid, info.uid, info.clientId, NULL, toResourceVec(sessionId, -1));
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(info.pid),
                                .uid = static_cast<int32_t>(info.uid),
                                .id = info.clientId};
    mService->addResource(clientInfo, NULL, toResourceVec(sessionId, -1));
}

void DrmSessionManager::removeSession(const Vector<uint8_t> &sessionId) {
@@ -164,7 +171,10 @@ void DrmSessionManager::removeSession(const Vector<uint8_t> &sessionId) {

    auto info = it->second;
    // removeClient instead of removeSession because each client has only one session
    mService->removeClient(info.pid, info.clientId);
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(info.pid),
                                .uid = static_cast<int32_t>(info.uid),
                                .id = info.clientId};
    mService->removeClient(clientInfo);
    mSessionMap.erase(it);
}

@@ -182,9 +192,13 @@ bool DrmSessionManager::reclaimSession(int callingPid) {

    // cannot update mSessionMap because we do not know which sessionId is reclaimed;
    // we rely on IResourceManagerClient to removeSession in reclaimResource
    Vector<uint8_t> dummy;
    Vector<uint8_t> placeHolder;
    bool success;
    ScopedAStatus status = service->reclaimResource(callingPid, toResourceVec(dummy, INT64_MAX), &success);
    uid_t uid = AIBinder_getCallingUid();
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(callingPid),
                                .uid = static_cast<int32_t>(uid)};
    ScopedAStatus status = service->reclaimResource(
        clientInfo, toResourceVec(placeHolder, INT64_MAX), &success);
    return status.isOk() && success;
}

+46 −9
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ using Status = ::ndk::ScopedAStatus;
using aidl::android::media::BnResourceManagerClient;
using aidl::android::media::IResourceManagerClient;
using aidl::android::media::IResourceManagerService;
using aidl::android::media::ClientInfoParcel;

// key for media statistics
static const char *kCodecKeyName = "codec";
@@ -210,8 +211,8 @@ static const C2MemoryUsage kDefaultReadWriteUsage{
////////////////////////////////////////////////////////////////////////////////

struct ResourceManagerClient : public BnResourceManagerClient {
    explicit ResourceManagerClient(MediaCodec* codec, int32_t pid) :
            mMediaCodec(codec), mPid(pid) {}
    explicit ResourceManagerClient(MediaCodec* codec, int32_t pid, int32_t uid) :
            mMediaCodec(codec), mPid(pid), mUid(uid) {}

    Status reclaimResource(bool* _aidl_return) override {
        sp<MediaCodec> codec = mMediaCodec.promote();
@@ -223,7 +224,10 @@ struct ResourceManagerClient : public BnResourceManagerClient {
            if (service == nullptr) {
                ALOGW("MediaCodec::ResourceManagerClient unable to find ResourceManagerService");
            }
            service->removeClient(mPid, getId(this));
            ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                .uid = static_cast<int32_t>(mUid),
                                .id = getId(this)};
            service->removeClient(clientInfo);
            *_aidl_return = true;
            return Status::ok();
        }
@@ -261,6 +265,7 @@ struct ResourceManagerClient : public BnResourceManagerClient {
private:
    wp<MediaCodec> mMediaCodec;
    int32_t mPid;
    int32_t mUid;

    DISALLOW_EVIL_CONSTRUCTORS(ResourceManagerClient);
};
@@ -286,10 +291,15 @@ struct MediaCodec::ResourceManagerServiceProxy : public RefBase {
    void markClientForPendingRemoval();
    bool reclaimResource(const std::vector<MediaResourceParcel> &resources);

    inline void setCodecName(const char* name) {
        mCodecName = name;
    }

private:
    Mutex mLock;
    pid_t mPid;
    uid_t mUid;
    std::string mCodecName;
    std::shared_ptr<IResourceManagerService> mService;
    std::shared_ptr<IResourceManagerClient> mClient;
    ::ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
@@ -396,7 +406,11 @@ void MediaCodec::ResourceManagerServiceProxy::addResource(
    if (mService == nullptr) {
        return;
    }
    mService->addResource(mPid, mUid, getId(mClient), mClient, resources);
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                .uid = static_cast<int32_t>(mUid),
                                .id = getId(mClient),
                                .name = mCodecName};
    mService->addResource(clientInfo, mClient, resources);
}

void MediaCodec::ResourceManagerServiceProxy::removeResource(
@@ -408,7 +422,11 @@ void MediaCodec::ResourceManagerServiceProxy::removeResource(
    if (mService == nullptr) {
        return;
    }
    mService->removeResource(mPid, getId(mClient), resources);
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                .uid = static_cast<int32_t>(mUid),
                                .id = getId(mClient),
                                .name = mCodecName};
    mService->removeResource(clientInfo, resources);
}

void MediaCodec::ResourceManagerServiceProxy::removeClient() {
@@ -416,7 +434,11 @@ void MediaCodec::ResourceManagerServiceProxy::removeClient() {
    if (mService == nullptr) {
        return;
    }
    mService->removeClient(mPid, getId(mClient));
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                .uid = static_cast<int32_t>(mUid),
                                .id = getId(mClient),
                                .name = mCodecName};
    mService->removeClient(clientInfo);
}

void MediaCodec::ResourceManagerServiceProxy::markClientForPendingRemoval() {
@@ -424,7 +446,11 @@ void MediaCodec::ResourceManagerServiceProxy::markClientForPendingRemoval() {
    if (mService == nullptr) {
        return;
    }
    mService->markClientForPendingRemoval(mPid, getId(mClient));
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                .uid = static_cast<int32_t>(mUid),
                                .id = getId(mClient),
                                .name = mCodecName};
    mService->markClientForPendingRemoval(clientInfo);
}

bool MediaCodec::ResourceManagerServiceProxy::reclaimResource(
@@ -434,7 +460,11 @@ bool MediaCodec::ResourceManagerServiceProxy::reclaimResource(
        return false;
    }
    bool success;
    Status status = mService->reclaimResource(mPid, resources, &success);
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                .uid = static_cast<int32_t>(mUid),
                                .id = getId(mClient),
                                .name = mCodecName};
    Status status = mService->reclaimResource(clientInfo, resources, &success);
    return status.isOk() && success;
}

@@ -872,7 +902,7 @@ MediaCodec::MediaCodec(
      mGetCodecBase(getCodecBase),
      mGetCodecInfo(getCodecInfo) {
    mResourceManagerProxy = new ResourceManagerServiceProxy(pid, uid,
            ::ndk::SharedRefBase::make<ResourceManagerClient>(this, pid));
            ::ndk::SharedRefBase::make<ResourceManagerClient>(this, pid, uid));
    if (!mGetCodecBase) {
        mGetCodecBase = [](const AString &name, const char *owner) {
            return GetCodecBase(name, owner);
@@ -1743,6 +1773,11 @@ status_t MediaCodec::init(const AString &name) {

    std::vector<MediaResourceParcel> resources;
    resources.push_back(MediaResource::CodecResource(secureCodec, toMediaResourceSubType(mDomain)));

    // If the ComponentName is not set yet, use the name passed by the user.
    if (mComponentName.empty()) {
        mResourceManagerProxy->setCodecName(name.c_str());
    }
    for (int i = 0; i <= kMaxRetry; ++i) {
        if (i > 0) {
            // Don't try to reclaim resource for the first time.
@@ -3528,6 +3563,8 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
                    if (mComponentName.c_str()) {
                        mediametrics_setCString(mMetricsHandle, kCodecCodec,
                                                mComponentName.c_str());
                        // Update the codec name.
                        mResourceManagerProxy->setCodecName(mComponentName.c_str());
                    }

                    const char *owner = mCodecInfo ? mCodecInfo->getOwnerName() : "";
+1 −1
Original line number Diff line number Diff line
@@ -40,11 +40,11 @@ bool ProcessInfo::getPriority(int pid, int* priority) {
    int32_t state;
    int32_t score = INVALID_ADJ;
    status_t err = service->getProcessStatesAndOomScoresFromPids(length, &pid, &state, &score);
    ALOGV("%s: pid:%d state:%d score:%d err:%d", __FUNCTION__, pid, state, score, err);
    if (err != OK) {
        ALOGE("getProcessStatesAndOomScoresFromPids failed");
        return false;
    }
    ALOGV("pid %d state %d score %d", pid, state, score);
    if (score <= NATIVE_ADJ) {
        std::scoped_lock lock{mOverrideLock};

+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ filegroup {
        "aidl/android/media/MediaResourceSubType.aidl",
        "aidl/android/media/MediaResourceParcel.aidl",
        "aidl/android/media/MediaResourcePolicyParcel.aidl",
        "aidl/android/media/ClientInfoParcel.aidl",
    ],
    path: "aidl",
}
@@ -87,10 +88,15 @@ cc_library {
        "libbinder_ndk",
        "libutils",
        "liblog",
        "libstats_media_metrics",
        "libstatspull",
        "libstatssocket",
        "libprotobuf-cpp-lite",
    ],

    static_libs: [
        "resourceobserver_aidl_interface-V1-ndk",
        "libplatformprotos",
    ],

    include_dirs: ["frameworks/av/include"],
@@ -101,4 +107,10 @@ cc_library {
    ],

    export_include_dirs: ["."],

    export_shared_lib_headers: [
        "libstats_media_metrics",
        "libstatspull",
        "libstatssocket",
    ],
}
+207 −40

File changed.

Preview size limit exceeded, changes collapsed.

Loading