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

Commit c47acf27 authored by jiabin's avatar jiabin
Browse files

Add log and dump for external vibration and HapticGenerator.

Adding more log and dump for external vibration and HapticGenerator is
useful for debugging.

Bug: 225287868
Test: make, dumpsys media.audio_flinger
Change-Id: If9befd3d3b4a4ba005069435f96d84cb02764527
parent 20310c3e
Loading
Loading
Loading
Loading
+43 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@

#include <algorithm>
#include <memory>
#include <sstream>
#include <string>
#include <utility>

@@ -94,6 +95,33 @@ float getFloatProperty(const std::string& key, float defaultValue) {
    return defaultValue;
}

std::string hapticParamToString(const struct HapticGeneratorParam& param) {
    std::stringstream ss;
    ss << "\t\tHapticGenerator Parameters:\n";
    ss << "\t\t- resonant frequency: " << param.resonantFrequency << '\n';
    ss << "\t\t- bpf Q: " << param.bpfQ << '\n';
    ss << "\t\t- slow env normalization power: " << param.slowEnvNormalizationPower << '\n';
    ss << "\t\t- bsf zero Q: " << param.bsfZeroQ << '\n';
    ss << "\t\t- bsf pole Q: " << param.bsfPoleQ << '\n';
    ss << "\t\t- distortion corner frequency: " << param.distortionCornerFrequency << '\n';
    ss << "\t\t- distortion input gain: " << param.distortionInputGain << '\n';
    ss << "\t\t- distortion cube threshold: " << param.distortionCubeThreshold << '\n';
    ss << "\t\t- distortion output gain: " << param.distortionOutputGain << '\n';
    return ss.str();
}

std::string hapticSettingToString(const struct HapticGeneratorParam& param) {
    std::stringstream ss;
    ss << "\t\tHaptic setting:\n";
    ss << "\t\t- tracks intensity map:\n";
    for (const auto&[id, intensity] : param.id2Intensity) {
        ss << "\t\t\t- id=" << id << ", intensity=" << (int) intensity;
    }
    ss << "\t\t- max intensity: " << (int) param.maxHapticIntensity << '\n';
    ss << "\t\t- max haptic amplitude: " << param.maxHapticAmplitude << '\n';
    return ss.str();
}

int HapticGenerator_Init(struct HapticGeneratorContext *context) {
    context->itfe = &gHapticGeneratorInterface;

@@ -129,7 +157,7 @@ int HapticGenerator_Init(struct HapticGeneratorContext *context) {
    context->param.distortionCubeThreshold = 0.1f;
    context->param.distortionOutputGain = getFloatProperty(
            "vendor.audio.hapticgenerator.distortion.output.gain", DEFAULT_DISTORTION_OUTPUT_GAIN);
    ALOGD("Using distortion output gain as %f", context->param.distortionOutputGain);
    ALOGD("%s\n%s", __func__, hapticParamToString(context->param).c_str());

    context->state = HAPTICGENERATOR_STATE_INITIALIZED;
    return 0;
@@ -289,6 +317,7 @@ int HapticGenerator_SetParameter(struct HapticGeneratorContext *context,
        }
        int id = *(int *) value;
        os::HapticScale hapticIntensity = static_cast<os::HapticScale>(*((int *) value + 1));
        ALOGD("Setting haptic intensity as %d", hapticIntensity);
        if (hapticIntensity == os::HapticScale::MUTE) {
            context->param.id2Intensity.erase(id);
        } else {
@@ -313,6 +342,10 @@ int HapticGenerator_SetParameter(struct HapticGeneratorContext *context,
        context->param.bsfZeroQ = isnan(qFactor) ? DEFAULT_BSF_POLE_Q : qFactor;
        context->param.bsfPoleQ = context->param.bsfZeroQ / 2.0f;
        context->param.maxHapticAmplitude = maxAmplitude;
        ALOGD("Updating vibrator info, resonantFrequency=%f, bsfZeroQ=%f, bsfPoleQ=%f, "
              "maxHapticAmplitude=%f",
              context->param.resonantFrequency, context->param.bsfZeroQ, context->param.bsfPoleQ,
              context->param.maxHapticAmplitude);

        if (context->processorsRecord.bpf != nullptr) {
            context->processorsRecord.bpf->setCoefficients(
@@ -358,6 +391,11 @@ float* HapticGenerator_runProcessingChain(
    return in;
}

void HapticGenerator_Dump(int32_t fd, const struct HapticGeneratorParam& param) {
    dprintf(fd, "%s", hapticParamToString(param).c_str());
    dprintf(fd, "%s", hapticSettingToString(param).c_str());
}

} // namespace (anonymous)

//-----------------------------------------------------------------------------
@@ -562,6 +600,10 @@ int32_t HapticGenerator_Command(effect_handle_t self, uint32_t cmdCode, uint32_t
        case EFFECT_CMD_SET_AUDIO_MODE:
            break;

        case EFFECT_CMD_DUMP:
            HapticGenerator_Dump(*(reinterpret_cast<int32_t*>(cmdData)), context->param);
            break;

        default:
            ALOGW("HapticGenerator_Command invalid command %u", cmdCode);
            return -EINVAL;
+6 −0
Original line number Diff line number Diff line
@@ -654,6 +654,7 @@ int AudioFlinger::onExternalVibrationStart(const sp<os::ExternalVibration>& exte
void AudioFlinger::onExternalVibrationStop(const sp<os::ExternalVibration>& externalVibration) {
    sp<os::IExternalVibratorService> evs = getExternalVibratorService();
    if (evs != 0) {
        ALOGD("%s, stopping external vibration", __func__);
        evs->onExternalVibrationStop(*externalVibration);
    }
}
@@ -765,6 +766,11 @@ void AudioFlinger::dumpInternals(int fd, const Vector<String16>& args __unused)
                            (uint32_t)(mStandbyTimeInNsecs / 1000000));
    result.append(buffer);
    write(fd, result.string(), result.size());

    dprintf(fd, "Vibrator infos(size=%zu):\n", mAudioVibratorInfos.size());
    for (const auto& vibratorInfo : mAudioVibratorInfos) {
        dprintf(fd, "  - %s\n", vibratorInfo.toString().c_str());
    }
}

void AudioFlinger::dumpPermissionDenial(int fd, const Vector<String16>& args __unused)
+2 −0
Original line number Diff line number Diff line
@@ -1906,6 +1906,7 @@ binder::Status AudioFlinger::PlaybackThread::Track::AudioVibrationController::mu
        PlaybackThread *playbackThread = (PlaybackThread *)thread.get();
        if ((mTrack->channelMask() & AUDIO_CHANNEL_HAPTIC_ALL) != AUDIO_CHANNEL_NONE
                && playbackThread->mHapticChannelCount > 0) {
            ALOGD("%s, haptic playback was muted for track %d", __func__, mTrack->id());
            mTrack->setHapticPlaybackEnabled(false);
            *ret = true;
        }
@@ -1923,6 +1924,7 @@ binder::Status AudioFlinger::PlaybackThread::Track::AudioVibrationController::un
        PlaybackThread *playbackThread = (PlaybackThread *)thread.get();
        if ((mTrack->channelMask() & AUDIO_CHANNEL_HAPTIC_ALL) != AUDIO_CHANNEL_NONE
                && playbackThread->mHapticChannelCount > 0) {
            ALOGD("%s, haptic playback was unmuted for track %d", __func__, mTrack->id());
            mTrack->setHapticPlaybackEnabled(true);
            *ret = true;
        }