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

Commit 011aa652 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

AudioFlinger uses media.log service for logging

Change-Id: Ia0f8204334f6b233f644d897762a18c95d936b4b
parent 0be9fe58
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@
#include <common_time/cc_helper.h>
//#include <common_time/local_clock.h>

#include <media/IMediaLogService.h>

// ----------------------------------------------------------------------------

// Note: the following macro is used for extremely verbose logging message.  In
@@ -127,6 +129,11 @@ AudioFlinger::AudioFlinger()
      mMode(AUDIO_MODE_INVALID),
      mBtNrecIsOff(false)
{
    char value[PROPERTY_VALUE_MAX];
    bool doLog = (property_get("ro.test_harness", value, "0") > 0) && (atoi(value) == 1);
    if (doLog) {
        mLogMemoryDealer = new MemoryDealer(kLogMemorySize, "LogWriters");
    }
}

void AudioFlinger::onFirstRef()
@@ -323,6 +330,17 @@ status_t AudioFlinger::dump(int fd, const Vector<String16>& args)
        if (locked) {
            mLock.unlock();
        }

        // append a copy of media.log here by forwarding fd to it, but don't attempt
        // to lookup the service if it's not running, as it will block for a second
        if (mLogMemoryDealer != 0) {
            sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log"));
            if (binder != 0) {
                fdprintf(fd, "\nmedia.log:\n");
                Vector<String16> args;
                binder->dump(fd, args);
            }
        }
    }
    return NO_ERROR;
}
@@ -340,6 +358,35 @@ sp<AudioFlinger::Client> AudioFlinger::registerPid_l(pid_t pid)
    return client;
}

sp<NBLog::Writer> AudioFlinger::newWriter_l(size_t size, const char *name)
{
    if (mLogMemoryDealer == 0) {
        return new NBLog::Writer();
    }
    sp<IMemory> shared = mLogMemoryDealer->allocate(NBLog::Timeline::sharedSize(size));
    sp<NBLog::Writer> writer = new NBLog::Writer(size, shared);
    sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log"));
    if (binder != 0) {
        interface_cast<IMediaLogService>(binder)->registerWriter(shared, size, name);
    }
    return writer;
}

void AudioFlinger::unregisterWriter(const sp<NBLog::Writer>& writer)
{
    sp<IMemory> iMemory(writer->getIMemory());
    if (iMemory == 0) {
        return;
    }
    sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log"));
    if (binder != 0) {
        interface_cast<IMediaLogService>(binder)->unregisterWriter(iMemory);
        // Now the media.log remote reference to IMemory is gone.
        // When our last local reference to IMemory also drops to zero,
        // the IMemory destructor will deallocate the region from mMemoryDealer.
    }
}

// IAudioFlinger interface


+9 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@

#include <powermanager/IPowerManager.h>

#include <media/nbaio/NBLog.h>

namespace android {

class audio_track_cblk_t;
@@ -222,6 +224,13 @@ public:

    // end of IAudioFlinger interface

    sp<NBLog::Writer>   newWriter_l(size_t size, const char *name);
    void                unregisterWriter(const sp<NBLog::Writer>& writer);
private:
    static const size_t kLogMemorySize = 10 * 1024;
    sp<MemoryDealer>    mLogMemoryDealer;   // == 0 when NBLog is disabled
public:

    class SyncEvent;

    typedef void (*sync_event_callback_t)(const wp<SyncEvent>& event) ;
+17 −0
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ bool FastMixer::threadLoop()
    struct timespec measuredWarmupTs = {0, 0};  // how long did it take for warmup to complete
    uint32_t warmupCycles = 0;  // counter of number of loop cycles required to warmup
    NBAIO_Sink* teeSink = NULL; // if non-NULL, then duplicate write() to this non-blocking sink
    NBLog::Writer dummyLogWriter, *logWriter = &dummyLogWriter;

    for (;;) {

@@ -119,9 +120,12 @@ bool FastMixer::threadLoop()
        FastMixerState::Command command = next->mCommand;
        if (next != current) {

            logWriter->log("next != current");

            // As soon as possible of learning of a new dump area, start using it
            dumpState = next->mDumpState != NULL ? next->mDumpState : &dummyDumpState;
            teeSink = next->mTeeSink;
            logWriter = next->mNBLogWriter != NULL ? next->mNBLogWriter : &dummyLogWriter;

            // We want to always have a valid reference to the previous (non-idle) state.
            // However, the state queue only guarantees access to current and previous states.
@@ -163,6 +167,7 @@ bool FastMixer::threadLoop()
                ALOG_ASSERT(coldFutexAddr != NULL);
                int32_t old = android_atomic_dec(coldFutexAddr);
                if (old <= 0) {
                    logWriter->log("wait");
                    __futex_syscall4(coldFutexAddr, FUTEX_WAIT_PRIVATE, old - 1, NULL);
                }
                // This may be overly conservative; there could be times that the normal mixer
@@ -181,6 +186,7 @@ bool FastMixer::threadLoop()
            }
            continue;
        case FastMixerState::EXIT:
            logWriter->log("exit");
            delete mixer;
            delete[] mixBuffer;
            return false;
@@ -258,11 +264,15 @@ bool FastMixer::threadLoop()
            unsigned currentTrackMask = current->mTrackMask;
            dumpState->mTrackMask = currentTrackMask;
            if (current->mFastTracksGen != fastTracksGen) {
                logWriter->logf("gen %d", current->mFastTracksGen);
                ALOG_ASSERT(mixBuffer != NULL);
                int name;

                // process removed tracks first to avoid running out of track names
                unsigned removedTracks = previousTrackMask & ~currentTrackMask;
                if (removedTracks) {
                    logWriter->logf("removed %#x", removedTracks);
                }
                while (removedTracks != 0) {
                    i = __builtin_ctz(removedTracks);
                    removedTracks &= ~(1 << i);
@@ -282,6 +292,9 @@ bool FastMixer::threadLoop()

                // now process added tracks
                unsigned addedTracks = currentTrackMask & ~previousTrackMask;
                if (addedTracks) {
                    logWriter->logf("added %#x", addedTracks);
                }
                while (addedTracks != 0) {
                    i = __builtin_ctz(addedTracks);
                    addedTracks &= ~(1 << i);
@@ -312,6 +325,9 @@ bool FastMixer::threadLoop()
                // finally process modified tracks; these use the same slot
                // but may have a different buffer provider or volume provider
                unsigned modifiedTracks = currentTrackMask & previousTrackMask;
                if (modifiedTracks) {
                    logWriter->logf("modified %#x", modifiedTracks);
                }
                while (modifiedTracks != 0) {
                    i = __builtin_ctz(modifiedTracks);
                    modifiedTracks &= ~(1 << i);
@@ -455,6 +471,7 @@ bool FastMixer::threadLoop()
        struct timespec newTs;
        int rc = clock_gettime(CLOCK_MONOTONIC, &newTs);
        if (rc == 0) {
            logWriter->logTimestamp(newTs);
            if (oldTsValid) {
                time_t sec = newTs.tv_sec - oldTs.tv_sec;
                long nsec = newTs.tv_nsec - oldTs.tv_nsec;
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ FastTrack::~FastTrack()
FastMixerState::FastMixerState() :
    mFastTracksGen(0), mTrackMask(0), mOutputSink(NULL), mOutputSinkGen(0),
    mFrameCount(0), mCommand(INITIAL), mColdFutexAddr(NULL), mColdGen(0),
    mDumpState(NULL), mTeeSink(NULL)
    mDumpState(NULL), mTeeSink(NULL), mNBLogWriter(NULL)
{
}

+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <system/audio.h>
#include <media/ExtendedAudioBufferProvider.h>
#include <media/nbaio/NBAIO.h>
#include <media/nbaio/NBLog.h>

namespace android {

@@ -77,6 +78,7 @@ struct FastMixerState {
    // This might be a one-time configuration rather than per-state
    FastMixerDumpState* mDumpState; // if non-NULL, then update dump state periodically
    NBAIO_Sink* mTeeSink;       // if non-NULL, then duplicate write()s to this non-blocking sink
    NBLog::Writer* mNBLogWriter; // non-blocking logger
};  // struct FastMixerState

}   // namespace android
Loading