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

Commit 61a8657a authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9682271 from 850d75e1 to tm-qpr3-release

Change-Id: I4ffdc2139691bd2ac9421ca20bc9265070c18751
parents 0461c936 850d75e1
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ namespace android::media {
// Convert data to string with level indentation.
// No need for a lock as the SimpleLog is thread-safe.
std::string VectorRecorder::toString(size_t indent) const {
    return mRecordLog.dumpToString(std::string(indent + 1, ' ').c_str(), mMaxLocalLogLine);
    return mRecordLog.dumpToString(std::string(indent, ' ').c_str(), mMaxLocalLogLine);
}

// Record into local log when it is time.
@@ -36,9 +36,9 @@ void VectorRecorder::record(const std::vector<float>& record) {
        sumToAverage_l();
        mRecordLog.log(
                "mean: %s, min: %s, max %s, calculated %zu samples in %0.4f second(s)",
                toString(mSum).c_str(),
                toString(mMin).c_str(),
                toString(mMax).c_str(),
                toString(mSum, mDelimiterIdx, mFormatString.c_str()).c_str(),
                toString(mMin, mDelimiterIdx, mFormatString.c_str()).c_str(),
                toString(mMax, mDelimiterIdx, mFormatString.c_str()).c_str(),
                mNumberOfSamples,
                mNumberOfSecondsSinceFirstSample.count());
        resetRecord_l();
+41 −4
Original line number Diff line number Diff line
@@ -34,9 +34,25 @@ namespace android::media {
 */
class VectorRecorder {
  public:
    /**
     * @param vectorSize is the size of the vector input.
     *        If the input does not match this size, it is ignored.
     * @param threshold is the time interval we bucket for averaging.
     * @param maxLogLine is the number of lines we log.  At this
     *        threshold, the oldest line will expire when the new line comes in.
     * @param delimiterIdx is an optional array of delimiter indices that
     *        replace the ',' with a ':'.  For example if delimiterIdx = { 3 } then
     *        the above example would format as [0.00, 0.00, 0.00 : -1.29, -0.50, 15.27].
     * @param formatString is the sprintf format string for the double converted data
     *        to use.
     */
    VectorRecorder(
        size_t vectorSize, std::chrono::duration<double> threshold, int maxLogLine)
        size_t vectorSize, std::chrono::duration<double> threshold, int maxLogLine,
            std::vector<size_t> delimiterIdx = {},
            const std::string_view formatString = {})
        : mVectorSize(vectorSize)
        , mDelimiterIdx(std::move(delimiterIdx))
        , mFormatString(formatString)
        , mRecordLog(maxLogLine)
        , mRecordThreshold(threshold)
    {
@@ -55,19 +71,38 @@ class VectorRecorder {

    /**
     * Format vector to a string, [0.00, 0.00, 0.00, -1.29, -0.50, 15.27].
     *
     * @param delimiterIdx is an optional array of delimiter indices that
     *        replace the ',' with a ':'.  For example if delimiterIdx = { 3 } then
     *        the above example would format as [0.00, 0.00, 0.00 : -1.29, -0.50, 15.27].
     * @param formatString is the sprintf format string for the double converted data
     *        to use.
     */
    template <typename T>
    static std::string toString(const std::vector<T>& record) {
    static std::string toString(const std::vector<T>& record,
            const std::vector<size_t>& delimiterIdx = {},
            const char * const formatString = nullptr) {
        if (record.size() == 0) {
            return "[]";
        }

        std::string ss = "[";
        auto nextDelimiter = delimiterIdx.begin();
        for (size_t i = 0; i < record.size(); ++i) {
            if (i > 0) {
                if (nextDelimiter != delimiterIdx.end()
                        && *nextDelimiter <= i) {
                     ss.append(" : ");
                     ++nextDelimiter;
                } else {
                    ss.append(", ");
                }
            base::StringAppendF(&ss, "%0.2lf", static_cast<double>(record[i]));
            }
            if (formatString != nullptr && *formatString) {
                base::StringAppendF(&ss, formatString, static_cast<double>(record[i]));
            } else {
                base::StringAppendF(&ss, "%5.2lf", static_cast<double>(record[i]));
            }
        }
        ss.append("]");
        return ss;
@@ -77,6 +112,8 @@ class VectorRecorder {
    static constexpr int mMaxLocalLogLine = 10;

    const size_t mVectorSize;
    const std::vector<size_t> mDelimiterIdx;
    const std::string mFormatString;

    // Local log for historical vector data.
    // Locked internally, so does not need mutex below.
+8 −3
Original line number Diff line number Diff line
@@ -273,10 +273,15 @@ DeviceVector Engine::getDevicesForStrategyInt(legacy_strategy strategy,
        break;

    case STRATEGY_PHONE: {
        devices = availableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_HEARING_AID);
        if (!devices.isEmpty()) break;
        // TODO(b/243670205): remove this logic that gives preference to last removable devices
        // once a UX decision has been made
        devices = availableOutputDevices.getFirstDevicesFromTypes(
                        getLastRemovableMediaDevices(GROUP_NONE, {AUDIO_DEVICE_OUT_BLE_HEADSET}));
                        getLastRemovableMediaDevices(GROUP_NONE, {
                            // excluding HEARING_AID and BLE_HEADSET because Dialer uses
                            // setCommunicationDevice to select them explicitly
                            AUDIO_DEVICE_OUT_HEARING_AID,
                            AUDIO_DEVICE_OUT_BLE_HEADSET
                            }));
        if (!devices.isEmpty()) break;
        devices = availableOutputDevices.getFirstDevicesFromTypes({
                AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET, AUDIO_DEVICE_OUT_EARPIECE});
+3 −3
Original line number Diff line number Diff line
@@ -1092,13 +1092,13 @@ std::string Spatializer::toString(unsigned level) const {
    if (mPoseController != nullptr) {
        ss.append(mPoseController->toString(level + 1))
            .append(prefixSpace)
            .append("Pose (active stage-to-head) [tx, ty, tz, pitch, roll, yaw]:\n")
            .append("Pose (active stage-to-head) [tx, ty, tz : pitch, roll, yaw]:\n")
            .append(prefixSpace)
            .append(" PerMinuteHistory:\n")
            .append(mPoseDurableRecorder.toString(level + 2))
            .append(mPoseDurableRecorder.toString(level + 3))
            .append(prefixSpace)
            .append(" PerSecondHistory:\n")
            .append(mPoseRecorder.toString(level + 2));
            .append(mPoseRecorder.toString(level + 3));
    } else {
        ss.append(prefixSpace).append("SpatializerPoseController not exist\n");
    }
+2 −2
Original line number Diff line number Diff line
@@ -404,10 +404,10 @@ private:
     */
    // Record one log line per second (up to mMaxLocalLogLine) to capture most recent sensor data.
    media::VectorRecorder mPoseRecorder GUARDED_BY(mLock) {
        6 /* vectorSize */, std::chrono::seconds(1), mMaxLocalLogLine };
        6 /* vectorSize */, std::chrono::seconds(1), mMaxLocalLogLine, { 3 } /* delimiterIdx */};
    // Record one log line per minute (up to mMaxLocalLogLine) to capture durable sensor data.
    media::VectorRecorder mPoseDurableRecorder  GUARDED_BY(mLock) {
        6 /* vectorSize */, std::chrono::minutes(1), mMaxLocalLogLine };
        6 /* vectorSize */, std::chrono::minutes(1), mMaxLocalLogLine, { 3 } /* delimiterIdx */};
};  // Spatializer

}; // namespace android
Loading