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

Commit 198e8f74 authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Gerrit Code Review
Browse files

Merge "audio: Improve logging in remote submix module" into main

parents b87fae42 9eb3314a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ class ModuleRemoteSubmix : public Module {
    ndk::ScopedAStatus onMasterVolumeChanged(float volume) override;
    int32_t getNominalLatencyMs(
            const ::aidl::android::media::audio::common::AudioPortConfig& portConfig) override;
    // TODO(b/307586684): Report proper minimum stream buffer size by overriding 'setAudioPatch'.
    binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
};

}  // namespace aidl::android::hardware::audio::core
+1 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ class StreamRemoteSubmix : public StreamCommonImpl {
    int64_t mStartTimeNs = 0;
    long mFramesSinceStart = 0;
    int mReadErrorCount = 0;
    int mReadFailureCount = 0;
};

class StreamInRemoteSubmix final : public StreamIn, public StreamSwitcher {
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#define LOG_TAG "AHAL_ModuleRemoteSubmix"

#include <stdio.h>
#include <vector>

#include <android-base/logging.h>
@@ -174,4 +175,9 @@ int32_t ModuleRemoteSubmix::getNominalLatencyMs(const AudioPortConfig&) {
    return kMinLatencyMs;
}

binder_status_t ModuleRemoteSubmix::dump(int fd, const char** /*args*/, uint32_t /*numArgs*/) {
    dprintf(fd, "\nSubmixRoutes:\n%s\n", r_submix::SubmixRoute::dumpRoutes().c_str());
    return STATUS_OK;
}

}  // namespace aidl::android::hardware::audio::core
+7 −1
Original line number Diff line number Diff line
@@ -267,6 +267,7 @@ size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
        }
        return ::android::OK;
    }
    mReadErrorCount = 0;

    LOG(VERBOSE) << __func__ << ": " << mDeviceAddress.toString() << ", " << frameCount
                 << " frames";
@@ -294,7 +295,12 @@ size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
        }
    }
    if (actuallyRead < frameCount) {
        LOG(WARNING) << __func__ << ": read " << actuallyRead << " vs. requested " << frameCount;
        if (++mReadFailureCount < kMaxReadFailureAttempts) {
            LOG(WARNING) << __func__ << ": read " << actuallyRead << " vs. requested " << frameCount
                         << " (not all errors will be logged)";
        }
    } else {
        mReadFailureCount = 0;
    }
    mCurrentRoute->updateReadCounterFrames(*actualFrameCount);
    return ::android::OK;
+39 −2
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
 * limitations under the License.
 */

#include <mutex>

#define LOG_TAG "AHAL_SubmixRoute"
#include <android-base/logging.h>
#include <media/AidlConversionCppNdk.h>
@@ -28,10 +30,11 @@ using aidl::android::media::audio::common::AudioDeviceAddress;
namespace aidl::android::hardware::audio::core::r_submix {

// static
SubmixRoute::RoutesMonitor SubmixRoute::getRoutes() {
SubmixRoute::RoutesMonitor SubmixRoute::getRoutes(bool tryLock) {
    static std::mutex submixRoutesLock;
    static RoutesMap submixRoutes;
    return RoutesMonitor(submixRoutesLock, submixRoutes);
    return !tryLock ? RoutesMonitor(submixRoutesLock, submixRoutes)
                    : RoutesMonitor(submixRoutesLock, submixRoutes, tryLock);
}

// static
@@ -66,6 +69,21 @@ void SubmixRoute::removeRoute(const AudioDeviceAddress& deviceAddress) {
    getRoutes()->erase(deviceAddress);
}

// static
std::string SubmixRoute::dumpRoutes() {
    auto routes = getRoutes(true /*tryLock*/);
    std::string result;
    if (routes->empty()) result.append(" <Empty>");
    for (const auto& r : *(routes.operator->())) {
        result.append(" - ")
                .append(r.first.toString())
                .append(": ")
                .append(r.second->dump())
                .append("\n");
    }
    return result;
}

// Verify a submix input or output stream can be opened.
bool SubmixRoute::isStreamConfigValid(bool isInput, const AudioConfig& streamConfig) {
    // If the stream is already open, don't open it again.
@@ -258,4 +276,23 @@ void SubmixRoute::exitStandby(bool isInput) {
    }
}

std::string SubmixRoute::dump() NO_THREAD_SAFETY_ANALYSIS {
    const bool isLocked = mLock.try_lock();
    std::string result = std::string(isLocked ? "" : "! ")
                                 .append("Input ")
                                 .append(mStreamInOpen ? "open" : "closed")
                                 .append(mStreamInStandby ? ", standby" : ", active")
                                 .append(", refcount: ")
                                 .append(std::to_string(mInputRefCount))
                                 .append(", framesRead: ")
                                 .append(mSource ? std::to_string(mSource->framesRead()) : "<null>")
                                 .append("; Output ")
                                 .append(mStreamOutOpen ? "open" : "closed")
                                 .append(mStreamOutStandby ? ", standby" : ", active")
                                 .append(", framesWritten: ")
                                 .append(mSink ? std::to_string(mSink->framesWritten()) : "<null>");
    if (isLocked) mLock.unlock();
    return result;
}

}  // namespace aidl::android::hardware::audio::core::r_submix
Loading