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

Commit 54368e63 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add metrics updated callback." into main

parents f8978deb 14016a57
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -785,6 +785,7 @@ enum {
    kWhatOutputBuffersChanged = 'outC',
    kWhatFirstTunnelFrameReady = 'ftfR',
    kWhatPollForRenderedBuffers = 'plrb',
    kWhatMetricsUpdated      = 'mtru',
};

class CryptoAsyncCallback : public CryptoAsync::CryptoAsyncCallback {
@@ -882,6 +883,7 @@ public:
    virtual void onOutputFramesRendered(const std::list<FrameRenderTracker::Info> &done) override;
    virtual void onOutputBuffersChanged() override;
    virtual void onFirstTunnelFrameReady() override;
    virtual void onMetricsUpdated(const sp<AMessage> &updatedMetrics) override;
private:
    const sp<AMessage> mNotify;
};
@@ -1008,6 +1010,13 @@ void CodecCallback::onFirstTunnelFrameReady() {
    notify->post();
}

void CodecCallback::onMetricsUpdated(const sp<AMessage> &updatedMetrics) {
    sp<AMessage> notify(mNotify->dup());
    notify->setInt32("what", kWhatMetricsUpdated);
    notify->setMessage("updated-metrics", updatedMetrics);
    notify->post();
}

static MediaResourceSubType toMediaResourceSubType(MediaCodec::Domain domain) {
    switch (domain) {
        case MediaCodec::DOMAIN_VIDEO: return MediaResourceSubType::kVideoCodec;
@@ -4381,6 +4390,49 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
                    break;
                }

                case kWhatMetricsUpdated:
                {
                    sp<AMessage> updatedMetrics;
                    CHECK(msg->findMessage("updated-metrics", &updatedMetrics));

                    size_t numEntries = updatedMetrics->countEntries();
                    AMessage::Type type;
                    for (size_t i = 0; i < numEntries; ++i) {
                        const char *name = updatedMetrics->getEntryNameAt(i, &type);
                        AMessage::ItemData itemData = updatedMetrics->getEntryAt(i);
                        switch (type) {
                            case AMessage::kTypeInt32: {
                                int32_t metricValue;
                                itemData.find(&metricValue);
                                mediametrics_setInt32(mMetricsHandle, name, metricValue);
                                break;
                            }
                            case AMessage::kTypeInt64: {
                                int64_t metricValue;
                                itemData.find(&metricValue);
                                mediametrics_setInt64(mMetricsHandle, name, metricValue);
                                break;
                            }
                            case AMessage::kTypeDouble: {
                                double metricValue;
                                itemData.find(&metricValue);
                                mediametrics_setDouble(mMetricsHandle, name, metricValue);
                                break;
                            }
                            case AMessage::kTypeString: {
                                AString metricValue;
                                itemData.find(&metricValue);
                                mediametrics_setCString(mMetricsHandle, name, metricValue.c_str());
                                break;
                            }
                            // ToDo: add support for other types
                            default:
                                ALOGW("Updated metrics type not supported.");
                        }
                    }
                    break;
                }

                case kWhatEOS:
                {
                    // We already notify the client of this by using the
+6 −0
Original line number Diff line number Diff line
@@ -182,6 +182,12 @@ struct CodecBase : public AHandler, /* static */ ColorUtils {
         * Notify MediaCodec that the first tunnel frame is ready.
         */
        virtual void onFirstTunnelFrameReady() = 0;
        /**
         * Notify MediaCodec that there are metrics to be updated.
         *
         * @param updatedMetrics metrics need to be updated.
         */
        virtual void onMetricsUpdated(const sp<AMessage> &updatedMetrics) = 0;
    };

    /**