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

Commit 8aa43c0b authored by Andy Hung's avatar Andy Hung
Browse files

Spatializer: Send metrics when not created

For best result normalization, we should also send metrics
when the Spatializer is not created.

This is an empty spatializer create metric which results
in an empty spatializer capabilities atom delivered to statsd.

Test: adb shell dumpsys media.metrics
Bug: 246662756
Change-Id: Ib122c90b1d95c7633913c75b0784d7e7a5f5d4b0
parent 1c7fb942
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -272,6 +272,11 @@ void AudioPolicyService::onFirstRef()
        if (hasSpatializer) {
            mSpatializer = Spatializer::create(this);
        }
        if (mSpatializer == nullptr) {
            // No spatializer created, signal the reason: NO_INIT a failure, OK means intended.
            const status_t createStatus = hasSpatializer ? NO_INIT : OK;
            Spatializer::sendEmptyCreateSpatializerMetricWithStatus(createStatus);
        }
    }
    AudioSystem::audioPolicyReady();
}
+12 −0
Original line number Diff line number Diff line
@@ -387,6 +387,18 @@ status_t Spatializer::loadEngineConfiguration(sp<EffectHalInterface> effect) {
    return NO_ERROR;
}

/* static */
void Spatializer::sendEmptyCreateSpatializerMetricWithStatus(status_t status) {
    mediametrics::LogItem(kDefaultMetricsId)
        .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_CREATE)
        .set(AMEDIAMETRICS_PROP_CHANNELMASKS, "")
        .set(AMEDIAMETRICS_PROP_LEVELS, "")
        .set(AMEDIAMETRICS_PROP_MODES, "")
        .set(AMEDIAMETRICS_PROP_HEADTRACKINGMODES, "")
        .set(AMEDIAMETRICS_PROP_STATUS, (int32_t)status)
        .record();
}

/** Gets the channel mask, sampling rate and format set for the spatializer input. */
audio_config_base_t Spatializer::getAudioInConfig() const {
    std::lock_guard lock(mLock);
+8 −1
Original line number Diff line number Diff line
@@ -198,6 +198,11 @@ class Spatializer : public media::BnSpatializer,
        return ss;
    };

    // If the Spatializer is not created, we send the status for metrics purposes.
    // OK:      Spatializer not expected to be created.
    // NO_INIT: Spatializer creation failed.
    static void sendEmptyCreateSpatializerMetricWithStatus(status_t status);

private:
    Spatializer(effect_descriptor_t engineDescriptor,
                     SpatializerPolicyCallback *callback);
@@ -351,7 +356,9 @@ private:
    SpatializerPolicyCallback* const mPolicyCallback;

    /** Currently there is only one version of the spatializer running */
    const std::string mMetricsId = AMEDIAMETRICS_KEY_PREFIX_AUDIO_SPATIALIZER "0";
    static constexpr const char* kDefaultMetricsId =
            AMEDIAMETRICS_KEY_PREFIX_AUDIO_SPATIALIZER "0";
    const std::string mMetricsId = kDefaultMetricsId;

    /** Mutex protecting internal state */
    mutable std::mutex mLock;