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

Commit 6a734006 authored by Girish Shetty's avatar Girish Shetty Committed by Automerger Merge Worker
Browse files

Merge changes from topic "codec_importance" into main am: 6c2c6392 am: 5664378e

parents 45bce99c 5664378e
Loading
Loading
Loading
Loading
+83 −72
Original line number Diff line number Diff line
@@ -396,6 +396,10 @@ struct MediaCodec::ResourceManagerServiceProxy :
        mCodecName = name;
    }

    inline void setImportance(int importance) {
        mImportance = importance;
    }

private:
    // To get the binder interface to ResourceManagerService.
    void getService() {
@@ -435,12 +439,30 @@ private:
        mGetServiceFuture = std::async(std::launch::async, [this] { getService(); });
    }

    /**
     * Get the ClientInfo to communicate with the ResourceManager.
     *
     * ClientInfo includes:
     *   - {pid, uid} of the process
     *   - identifier for the client
     *   - name of the client/codec
     *   - importance associated with the client
     */
    inline ClientInfoParcel getClientInfo() const {
        ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                    .uid = static_cast<int32_t>(mUid),
                                    .id = getId(mClient),
                                    .name = mCodecName,
                                    .importance = mImportance};
        return std::move(clientInfo);
    }

private:
    std::mutex  mLock;
    bool        mBinderDied = false;
    pid_t       mPid;
    uid_t       mUid;
    bool mBinderDied = false;
    int         mImportance = 0;
    std::string mCodecName;
    /**
     * Reconnecting with the ResourceManagerService, after its binder interface dies,
@@ -548,11 +570,7 @@ void MediaCodec::ResourceManagerServiceProxy::reRegisterAllResources_l() {
    std::vector<MediaResourceParcel> resources;
    std::copy(mMediaResourceParcel.begin(), mMediaResourceParcel.end(),
              std::back_inserter(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);
    mService->addResource(getClientInfo(), mClient, resources);
}

void MediaCodec::ResourceManagerServiceProxy::BinderDiedCallback(void* cookie) {
@@ -585,11 +603,7 @@ void MediaCodec::ResourceManagerServiceProxy::addResource(
    }
    std::vector<MediaResourceParcel> resources;
    resources.push_back(resource);
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                .uid = static_cast<int32_t>(mUid),
                                .id = getId(mClient),
                                .name = mCodecName};
    service->addResource(clientInfo, mClient, resources);
    service->addResource(getClientInfo(), mClient, resources);
    mMediaResourceParcel.emplace(resource);
}

@@ -603,11 +617,7 @@ void MediaCodec::ResourceManagerServiceProxy::removeResource(
    }
    std::vector<MediaResourceParcel> resources;
    resources.push_back(resource);
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                .uid = static_cast<int32_t>(mUid),
                                .id = getId(mClient),
                                .name = mCodecName};
    service->removeResource(clientInfo, resources);
    service->removeResource(getClientInfo(), resources);
    mMediaResourceParcel.erase(resource);
}

@@ -618,11 +628,7 @@ void MediaCodec::ResourceManagerServiceProxy::removeClient() {
        ALOGW("Service isn't available");
        return;
    }
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                .uid = static_cast<int32_t>(mUid),
                                .id = getId(mClient),
                                .name = mCodecName};
    service->removeClient(clientInfo);
    service->removeClient(getClientInfo());
    mMediaResourceParcel.clear();
}

@@ -633,11 +639,7 @@ void MediaCodec::ResourceManagerServiceProxy::markClientForPendingRemoval() {
        ALOGW("Service isn't available");
        return;
    }
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                .uid = static_cast<int32_t>(mUid),
                                .id = getId(mClient),
                                .name = mCodecName};
    service->markClientForPendingRemoval(clientInfo);
    service->markClientForPendingRemoval(getClientInfo());
    mMediaResourceParcel.clear();
}

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

@@ -665,11 +663,7 @@ void MediaCodec::ResourceManagerServiceProxy::notifyClientCreated() {
        ALOGW("Service isn't available");
        return;
    }
    ClientInfoParcel clientInfo{.pid = static_cast<int32_t>(mPid),
                                .uid = static_cast<int32_t>(mUid),
                                .id = getId(mClient),
                                .name = mCodecName};
    service->notifyClientCreated(clientInfo);
    service->notifyClientCreated(getClientInfo());
}

void MediaCodec::ResourceManagerServiceProxy::notifyClientStarted(
@@ -680,10 +674,7 @@ void MediaCodec::ResourceManagerServiceProxy::notifyClientStarted(
        ALOGW("Service isn't available");
        return;
    }
    clientConfig.clientInfo.pid = static_cast<int32_t>(mPid);
    clientConfig.clientInfo.uid = static_cast<int32_t>(mUid);
    clientConfig.clientInfo.id = getId(mClient);
    clientConfig.clientInfo.name = mCodecName;
    clientConfig.clientInfo = getClientInfo();
    service->notifyClientStarted(clientConfig);
}

@@ -695,10 +686,7 @@ void MediaCodec::ResourceManagerServiceProxy::notifyClientStopped(
        ALOGW("Service isn't available");
        return;
    }
    clientConfig.clientInfo.pid = static_cast<int32_t>(mPid);
    clientConfig.clientInfo.uid = static_cast<int32_t>(mUid);
    clientConfig.clientInfo.id = getId(mClient);
    clientConfig.clientInfo.name = mCodecName;
    clientConfig.clientInfo = getClientInfo();
    service->notifyClientStopped(clientConfig);
}

@@ -710,10 +698,7 @@ void MediaCodec::ResourceManagerServiceProxy::notifyClientConfigChanged(
        ALOGW("Service isn't available");
        return;
    }
    clientConfig.clientInfo.pid = static_cast<int32_t>(mPid);
    clientConfig.clientInfo.uid = static_cast<int32_t>(mUid);
    clientConfig.clientInfo.id = getId(mClient);
    clientConfig.clientInfo.name = mCodecName;
    clientConfig.clientInfo = getClientInfo();
    service->notifyClientConfigChanged(clientConfig);
}

@@ -1714,6 +1699,21 @@ void MediaCodec::updateLowLatency(const sp<AMessage> &msg) {
    }
}

void MediaCodec::updateCodecImportance(const sp<AMessage>& msg) {
    // Update the codec importance.
    int32_t importance = 0;
    if (msg->findInt32(KEY_IMPORTANCE, &importance)) {
        // Ignoring the negative importance.
        if (importance >= 0) {
            // Notify RM about the change in the importance.
            mResourceManagerProxy->setImportance(importance);
            ClientConfigParcel clientConfig;
            initClientConfigParcel(clientConfig);
            mResourceManagerProxy->notifyClientConfigChanged(clientConfig);
        }
    }
}

constexpr const char *MediaCodec::asString(TunnelPeekState state, const char *default_string){
    switch(state) {
        case TunnelPeekState::kLegacyMode:
@@ -2222,23 +2222,9 @@ static const char enableMediaFormatShapingProperty[] = "debug.stagefright.enable
static void mapFormat(AString componentName, const sp<AMessage> &format, const char *kind,
                      bool reverse);

status_t MediaCodec::configure(
        const sp<AMessage> &format,
        const sp<Surface> &nativeWindow,
        const sp<ICrypto> &crypto,
        uint32_t flags) {
    return configure(format, nativeWindow, crypto, NULL, flags);
}

status_t MediaCodec::configure(
        const sp<AMessage> &format,
        const sp<Surface> &surface,
        const sp<ICrypto> &crypto,
        const sp<IDescrambler> &descrambler,
        uint32_t flags) {

    sp<AMessage> msg = new AMessage(kWhatConfigure, this);
mediametrics_handle_t MediaCodec::createMediaMetrics(const sp<AMessage>& format, uint32_t flags) {
    mediametrics_handle_t nextMetricsHandle = mediametrics_create(kCodecKeyName);
    bool isEncoder = (flags & CONFIGURE_FLAG_ENCODE);

    // TODO: validity check log-session-id: it should be a 32-hex-digit.
    format->findString("log-session-id", &mLogSessionId);
@@ -2253,8 +2239,7 @@ status_t MediaCodec::configure(
        if (format->findInt32("level", &level)) {
            mediametrics_setInt32(nextMetricsHandle, kCodecLevel, level);
        }
        mediametrics_setInt32(nextMetricsHandle, kCodecEncoder,
                              (flags & CONFIGURE_FLAG_ENCODE) ? 1 : 0);
        mediametrics_setInt32(nextMetricsHandle, kCodecEncoder, isEncoder);

        if (!mLogSessionId.empty()) {
            mediametrics_setCString(nextMetricsHandle, kCodecLogSessionId, mLogSessionId.c_str());
@@ -2333,7 +2318,7 @@ status_t MediaCodec::configure(
        }
    }

    if (flags & CONFIGURE_FLAG_ENCODE) {
    if (isEncoder) {
        int8_t enableShaping = property_get_bool(enableMediaFormatShapingProperty,
                                                 enableMediaFormatShapingDefault);
        if (!enableShaping) {
@@ -2378,6 +2363,31 @@ status_t MediaCodec::configure(

    updateLowLatency(format);

    return nextMetricsHandle;
}

status_t MediaCodec::configure(
        const sp<AMessage> &format,
        const sp<Surface> &nativeWindow,
        const sp<ICrypto> &crypto,
        uint32_t flags) {
    return configure(format, nativeWindow, crypto, NULL, flags);
}

status_t MediaCodec::configure(
        const sp<AMessage> &format,
        const sp<Surface> &surface,
        const sp<ICrypto> &crypto,
        const sp<IDescrambler> &descrambler,
        uint32_t flags) {

    // Update the codec importance.
    updateCodecImportance(format);

    // Create and set up metrics for this codec.
    mediametrics_handle_t nextMetricsHandle = createMediaMetrics(format, flags);

    sp<AMessage> msg = new AMessage(kWhatConfigure, this);
    msg->setMessage("format", format);
    msg->setInt32("flags", flags);
    msg->setObject("surface", surface);
@@ -6589,6 +6599,7 @@ status_t MediaCodec::onSetParameters(const sp<AMessage> &params) {
        return NO_INIT;
    }
    updateLowLatency(params);
    updateCodecImportance(params);
    mapFormat(mComponentName, params, nullptr, false);
    updateTunnelPeek(params);
    mCodec->signalSetParameters(params);
+4 −0
Original line number Diff line number Diff line
@@ -320,6 +320,9 @@ private:
    status_t reclaim(bool force = false);
    friend struct ResourceManagerClient;

    // to create the metrics associated with this codec.
    mediametrics_handle_t createMediaMetrics(const sp<AMessage>& format, uint32_t flags);

private:
    enum State {
        UNINITIALIZED,
@@ -462,6 +465,7 @@ private:
    void resetMetricsFields();
    void updateEphemeralMediametrics(mediametrics_handle_t item);
    void updateLowLatency(const sp<AMessage> &msg);
    void updateCodecImportance(const sp<AMessage>& msg);
    void onGetMetrics(const sp<AMessage>& msg);
    constexpr const char *asString(TunnelPeekState state, const char *default_string="?");
    void updateTunnelPeek(const sp<AMessage> &msg);
+1 −0
Original line number Diff line number Diff line
@@ -794,6 +794,7 @@ inline constexpr char KEY_HDR_STATIC_INFO[] = "hdr-static-info";
inline constexpr char KEY_HDR10_PLUS_INFO[] = "hdr10-plus-info";
inline constexpr char KEY_HEIGHT[] = "height";
inline constexpr char KEY_I_FRAME_INTERVAL[] = "i-frame-interval";
inline constexpr char KEY_IMPORTANCE[] = "importance";
inline constexpr char KEY_INTRA_REFRESH_PERIOD[] = "intra-refresh-period";
inline constexpr char KEY_IS_ADTS[] = "is-adts";
inline constexpr char KEY_IS_AUTOSELECT[] = "is-autoselect";
+1 −0
Original line number Diff line number Diff line
@@ -428,6 +428,7 @@ EXPORT const char* AMEDIAFORMAT_KEY_HDR_STATIC_INFO = "hdr-static-info";
EXPORT const char* AMEDIAFORMAT_KEY_HDR10_PLUS_INFO = "hdr10-plus-info";
EXPORT const char* AMEDIAFORMAT_KEY_HEIGHT = "height";
EXPORT const char* AMEDIAFORMAT_KEY_ICC_PROFILE = "icc-profile";
EXPORT const char* AMEDIAFORMAT_KEY_IMPORTANCE = "importance";
EXPORT const char* AMEDIAFORMAT_KEY_INTRA_REFRESH_PERIOD = "intra-refresh-period";
EXPORT const char* AMEDIAFORMAT_KEY_IS_ADTS = "is-adts";
EXPORT const char* AMEDIAFORMAT_KEY_IS_AUTOSELECT = "is-autoselect";
+1 −0
Original line number Diff line number Diff line
@@ -168,6 +168,7 @@ extern const char* AMEDIAFORMAT_KEY_GRID_COLUMNS __INTRODUCED_IN(28);
extern const char* AMEDIAFORMAT_KEY_GRID_ROWS __INTRODUCED_IN(28);
extern const char* AMEDIAFORMAT_KEY_HDR_STATIC_INFO __INTRODUCED_IN(28);
extern const char* AMEDIAFORMAT_KEY_HEIGHT __INTRODUCED_IN(21);
extern const char* AMEDIAFORMAT_KEY_IMPORTANCE __INTRODUCED_IN(35);
extern const char* AMEDIAFORMAT_KEY_INTRA_REFRESH_PERIOD __INTRODUCED_IN(28);
extern const char* AMEDIAFORMAT_KEY_IS_ADTS __INTRODUCED_IN(21);
extern const char* AMEDIAFORMAT_KEY_IS_AUTOSELECT __INTRODUCED_IN(21);
Loading