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

Commit 2f8e63b5 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "Add AudioTrack and AudioRecord flag checks" into nyc-mr1-dev

parents 725c7852 05067787
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -491,6 +491,9 @@ public:
     */
            uint32_t    getInputFramesLost() const;

    /* Get the flags */
            audio_input_flags_t getFlags() const { AutoMutex _l(mLock); return mFlags; }

private:
    /* copying audio record objects is not allowed */
                        AudioRecord(const AudioRecord& other);
+2 −12
Original line number Diff line number Diff line
@@ -44,16 +44,6 @@ class IAudioFlinger : public IInterface
public:
    DECLARE_META_INTERFACE(AudioFlinger);

    // or-able bits shared by createTrack and openRecord, but not all combinations make sense
    enum {
        TRACK_DEFAULT = 0,  // client requests a default AudioTrack
        // FIXME: obsolete
        // TRACK_TIMED= 1,  // client requests a TimedAudioTrack
        TRACK_FAST    = 2,  // client requests a fast AudioTrack or AudioRecord
        TRACK_OFFLOAD = 4,  // client requests offload to hw codec
        TRACK_DIRECT = 8,   // client requests a direct output
    };
    typedef uint32_t track_flags_t;

    // invariant on exit for all APIs that return an sp<>:
    //   (return value != 0) == (*status == NO_ERROR)
@@ -67,7 +57,7 @@ public:
                                audio_format_t format,
                                audio_channel_mask_t channelMask,
                                size_t *pFrameCount,
                                track_flags_t *flags,
                                audio_output_flags_t *flags,
                                const sp<IMemory>& sharedBuffer,
                                // On successful return, AudioFlinger takes over the handle
                                // reference and will release it when the track is destroyed.
@@ -89,7 +79,7 @@ public:
                                audio_channel_mask_t channelMask,
                                const String16& callingPackage,
                                size_t *pFrameCount,
                                track_flags_t *flags,
                                audio_input_flags_t *flags,
                                pid_t pid,
                                pid_t tid,  // -1 means unused, otherwise must be valid non-0
                                int clientUid,
+4 −4
Original line number Diff line number Diff line
@@ -593,11 +593,10 @@ status_t AudioRecord::openRecord_l(const Modulo<uint32_t> &epoch, const String16
    size_t notificationFrames = mNotificationFramesReq;
    size_t frameCount = mReqFrameCount;

    IAudioFlinger::track_flags_t trackFlags = IAudioFlinger::TRACK_DEFAULT;
    audio_input_flags_t flags = mFlags;

    pid_t tid = -1;
    if (mFlags & AUDIO_INPUT_FLAG_FAST) {
        trackFlags |= IAudioFlinger::TRACK_FAST;
        if (mAudioRecordThread != 0) {
            tid = mAudioRecordThread->getTid();
        }
@@ -615,7 +614,7 @@ status_t AudioRecord::openRecord_l(const Modulo<uint32_t> &epoch, const String16
                                                       mChannelMask,
                                                       opPackageName,
                                                       &temp,
                                                       &trackFlags,
                                                       &flags,
                                                       mClientPid,
                                                       tid,
                                                       mClientUid,
@@ -638,7 +637,7 @@ status_t AudioRecord::openRecord_l(const Modulo<uint32_t> &epoch, const String16

    mAwaitBoost = false;
    if (mFlags & AUDIO_INPUT_FLAG_FAST) {
        if (trackFlags & IAudioFlinger::TRACK_FAST) {
        if (flags & AUDIO_INPUT_FLAG_FAST) {
            ALOGI("AUDIO_INPUT_FLAG_FAST successful; frameCount %zu", frameCount);
            mAwaitBoost = true;
        } else {
@@ -648,6 +647,7 @@ status_t AudioRecord::openRecord_l(const Modulo<uint32_t> &epoch, const String16
            continue;   // retry
        }
    }
    mFlags = flags;

    if (iMem == 0) {
        ALOGE("Could not get control block");
+5 −14
Original line number Diff line number Diff line
@@ -1372,24 +1372,15 @@ status_t AudioTrack::createTrack_l()
        }
    }

    IAudioFlinger::track_flags_t trackFlags = IAudioFlinger::TRACK_DEFAULT;
    audio_output_flags_t flags = mFlags;

    pid_t tid = -1;
    if (mFlags & AUDIO_OUTPUT_FLAG_FAST) {
        trackFlags |= IAudioFlinger::TRACK_FAST;
        if (mAudioTrackThread != 0 && !mThreadCanCallJava) {
            tid = mAudioTrackThread->getTid();
        }
    }

    if (mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
        trackFlags |= IAudioFlinger::TRACK_OFFLOAD;
    }

    if (mFlags & AUDIO_OUTPUT_FLAG_DIRECT) {
        trackFlags |= IAudioFlinger::TRACK_DIRECT;
    }

    size_t temp = frameCount;   // temp may be replaced by a revised value of frameCount,
                                // but we will still need the original value also
    audio_session_t originalSessionId = mSessionId;
@@ -1398,7 +1389,7 @@ status_t AudioTrack::createTrack_l()
                                                      mFormat,
                                                      mChannelMask,
                                                      &temp,
                                                      &trackFlags,
                                                      &flags,
                                                      mSharedBuffer,
                                                      output,
                                                      mClientPid,
@@ -1451,23 +1442,23 @@ status_t AudioTrack::createTrack_l()

    mAwaitBoost = false;
    if (mFlags & AUDIO_OUTPUT_FLAG_FAST) {
        if (trackFlags & IAudioFlinger::TRACK_FAST) {
        if (flags & AUDIO_OUTPUT_FLAG_FAST) {
            ALOGV("AUDIO_OUTPUT_FLAG_FAST successful; frameCount %zu", frameCount);
            if (!mThreadCanCallJava) {
                mAwaitBoost = true;
            }
        } else {
            ALOGW("AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount %zu", frameCount);
            mFlags = (audio_output_flags_t) (mFlags & ~AUDIO_OUTPUT_FLAG_FAST);
        }
    }
    mFlags = flags;

    // Make sure that application is notified with sufficient margin before underrun.
    // The client can divide the AudioTrack buffer into sub-buffers,
    // and expresses its desire to server as the notification frame count.
    if (mSharedBuffer == 0 && audio_is_linear_pcm(mFormat)) {
        size_t maxNotificationFrames;
        if (trackFlags & IAudioFlinger::TRACK_FAST) {
        if (mFlags & AUDIO_OUTPUT_FLAG_FAST) {
            // notify every HAL buffer, regardless of the size of the track buffer
            maxNotificationFrames = afFrameCountHAL;
        } else {
+8 −8
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ public:
                                audio_format_t format,
                                audio_channel_mask_t channelMask,
                                size_t *pFrameCount,
                                track_flags_t *flags,
                                audio_output_flags_t *flags,
                                const sp<IMemory>& sharedBuffer,
                                audio_io_handle_t output,
                                pid_t pid,
@@ -119,7 +119,7 @@ public:
        data.writeInt32(channelMask);
        size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
        data.writeInt64(frameCount);
        track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
        audio_output_flags_t lFlags = flags != NULL ? *flags : AUDIO_OUTPUT_FLAG_NONE;
        data.writeInt32(lFlags);
        // haveSharedBuffer
        if (sharedBuffer != 0) {
@@ -145,7 +145,7 @@ public:
            if (pFrameCount != NULL) {
                *pFrameCount = frameCount;
            }
            lFlags = reply.readInt32();
            lFlags = (audio_output_flags_t)reply.readInt32();
            if (flags != NULL) {
                *flags = lFlags;
            }
@@ -180,7 +180,7 @@ public:
                                audio_channel_mask_t channelMask,
                                const String16& opPackageName,
                                size_t *pFrameCount,
                                track_flags_t *flags,
                                audio_input_flags_t *flags,
                                pid_t pid,
                                pid_t tid,
                                int clientUid,
@@ -200,7 +200,7 @@ public:
        data.writeString16(opPackageName);
        size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
        data.writeInt64(frameCount);
        track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
        audio_input_flags_t lFlags = flags != NULL ? *flags : AUDIO_INPUT_FLAG_NONE;
        data.writeInt32(lFlags);
        data.writeInt32((int32_t) pid);
        data.writeInt32((int32_t) tid);
@@ -221,7 +221,7 @@ public:
            if (pFrameCount != NULL) {
                *pFrameCount = frameCount;
            }
            lFlags = reply.readInt32();
            lFlags = (audio_input_flags_t)reply.readInt32();
            if (flags != NULL) {
                *flags = lFlags;
            }
@@ -947,7 +947,7 @@ status_t BnAudioFlinger::onTransact(
            audio_format_t format = (audio_format_t) data.readInt32();
            audio_channel_mask_t channelMask = data.readInt32();
            size_t frameCount = data.readInt64();
            track_flags_t flags = (track_flags_t) data.readInt32();
            audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
            bool haveSharedBuffer = data.readInt32() != 0;
            sp<IMemory> buffer;
            if (haveSharedBuffer) {
@@ -986,7 +986,7 @@ status_t BnAudioFlinger::onTransact(
            audio_channel_mask_t channelMask = data.readInt32();
            const String16& opPackageName = data.readString16();
            size_t frameCount = data.readInt64();
            track_flags_t flags = (track_flags_t) data.readInt32();
            audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
            pid_t pid = (pid_t) data.readInt32();
            pid_t tid = (pid_t) data.readInt32();
            int clientUid = data.readInt32();
Loading