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

Commit ff555d55 authored by Songyue Han's avatar Songyue Han
Browse files

Add metrics updated callback.

This is used for sending metrics from CCodec to MediaCodec.

Bug: 270518245
Test: manual

Change-Id: If716eccc12e8f203bca657a2be3d94c7384c2ea9
parent 3c7d77fc
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<RenderedFrameInfo> &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;
@@ -4380,6 +4389,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;
    };

    /**