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

Commit f7b279fb authored by Phil Burk's avatar Phil Burk Committed by Android (Google) Code Review
Browse files

Merge "AudioTrack: explain why FAST mixer denied" into oc-dr1-dev

parents ec89b2e2 adbb75af
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -507,6 +507,18 @@ audio_port_handle_t AudioRecord::getRoutedDeviceId() {
}

// -------------------------------------------------------------------------
// TODO Move this macro to a common header file for enum to string conversion in audio framework.
#define MEDIA_CASE_ENUM(name) case name: return #name
const char * AudioRecord::convertTransferToText(transfer_type transferType) {
    switch (transferType) {
        MEDIA_CASE_ENUM(TRANSFER_DEFAULT);
        MEDIA_CASE_ENUM(TRANSFER_CALLBACK);
        MEDIA_CASE_ENUM(TRANSFER_OBTAIN);
        MEDIA_CASE_ENUM(TRANSFER_SYNC);
        default:
            return "UNRECOGNIZED";
    }
}

// must be called with mLock held
status_t AudioRecord::openRecord_l(const Modulo<uint32_t> &epoch, const String16& opPackageName)
@@ -590,12 +602,20 @@ status_t AudioRecord::openRecord_l(const Modulo<uint32_t> &epoch, const String16
            (mTransfer == TRANSFER_SYNC) ||
            // use case 3: obtain/release mode
            (mTransfer == TRANSFER_OBTAIN);
        if (!useCaseAllowed) {
            ALOGW("AUDIO_INPUT_FLAG_FAST denied, incompatible transfer = %s",
                  convertTransferToText(mTransfer));
        }

        // sample rates must also match
        bool fastAllowed = useCaseAllowed && (mSampleRate == afSampleRate);
        bool sampleRateAllowed = mSampleRate == afSampleRate;
        if (!sampleRateAllowed) {
            ALOGW("AUDIO_INPUT_FLAG_FAST denied, rates do not match %u Hz, require %u Hz",
                  mSampleRate, afSampleRate);
        }

        bool fastAllowed = useCaseAllowed && sampleRateAllowed;
        if (!fastAllowed) {
            ALOGW("AUDIO_INPUT_FLAG_FAST denied by client; transfer %d, "
                "track %u Hz, input %u Hz",
                mTransfer, mSampleRate, afSampleRate);
            mFlags = (audio_input_flags_t) (mFlags & ~(AUDIO_INPUT_FLAG_FAST |
                    AUDIO_INPUT_FLAG_RAW));
            AudioSystem::releaseInput(input, mSessionId);
+32 −8
Original line number Diff line number Diff line
@@ -1268,6 +1268,20 @@ void AudioTrack::updateLatency_l()
    }
}

// TODO Move this macro to a common header file for enum to string conversion in audio framework.
#define MEDIA_CASE_ENUM(name) case name: return #name
const char * AudioTrack::convertTransferToText(transfer_type transferType) {
    switch (transferType) {
        MEDIA_CASE_ENUM(TRANSFER_DEFAULT);
        MEDIA_CASE_ENUM(TRANSFER_CALLBACK);
        MEDIA_CASE_ENUM(TRANSFER_OBTAIN);
        MEDIA_CASE_ENUM(TRANSFER_SYNC);
        MEDIA_CASE_ENUM(TRANSFER_SHARED);
        default:
            return "UNRECOGNIZED";
    }
}

status_t AudioTrack::createTrack_l()
{
    const sp<IAudioFlinger>& audioFlinger = AudioSystem::get_audio_flinger();
@@ -1343,22 +1357,32 @@ status_t AudioTrack::createTrack_l()

    // Client can only express a preference for FAST.  Server will perform additional tests.
    if (mFlags & AUDIO_OUTPUT_FLAG_FAST) {
        bool useCaseAllowed =
        // either of these use cases:
        // use case 1: shared buffer
            (mSharedBuffer != 0) ||
        bool sharedBuffer = mSharedBuffer != 0;
        bool transferAllowed =
            // use case 2: callback transfer mode
            (mTransfer == TRANSFER_CALLBACK) ||
            // use case 3: obtain/release mode
            (mTransfer == TRANSFER_OBTAIN) ||
            // use case 4: synchronous write
            ((mTransfer == TRANSFER_SYNC) && mThreadCanCallJava);

        bool useCaseAllowed = sharedBuffer || transferAllowed;
        if (!useCaseAllowed) {
            ALOGW("AUDIO_OUTPUT_FLAG_FAST denied, not shared buffer and transfer = %s",
                  convertTransferToText(mTransfer));
        }

        // sample rates must also match
        bool fastAllowed = useCaseAllowed && (mSampleRate == mAfSampleRate);
        bool sampleRateAllowed = mSampleRate == mAfSampleRate;
        if (!sampleRateAllowed) {
            ALOGW("AUDIO_OUTPUT_FLAG_FAST denied, rates do not match %u Hz, require %u Hz",
                  mSampleRate, mAfSampleRate);
        }

        bool fastAllowed = useCaseAllowed && sampleRateAllowed;
        if (!fastAllowed) {
            ALOGW("AUDIO_OUTPUT_FLAG_FAST denied by client; transfer %d, "
                "track %u Hz, output %u Hz",
                mTransfer, mSampleRate, mAfSampleRate);
            mFlags = (audio_output_flags_t) (mFlags & ~AUDIO_OUTPUT_FLAG_FAST);
        }
    }
+6 −0
Original line number Diff line number Diff line
@@ -334,6 +334,12 @@ public:
     */
            status_t getTimestamp(ExtendedTimestamp *timestamp);

    /**
     * @param transferType
     * @return text string that matches the enum name
     */
    static const char * convertTransferToText(transfer_type transferType);

    /* Returns a handle on the audio input used by this AudioRecord.
     *
     * Parameters:
+6 −0
Original line number Diff line number Diff line
@@ -564,6 +564,12 @@ public:
     */
            status_t    reload();

    /**
     * @param transferType
     * @return text string that matches the enum name
     */
            static const char * convertTransferToText(transfer_type transferType);

    /* Returns a handle on the audio output used by this AudioTrack.
     *
     * Parameters: