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

Commit caf7f48a authored by Eric Laurent's avatar Eric Laurent
Browse files

AudioRecord: use audio attributes instead of audio source.

Added AudioRecord constructor with audio attributes.
Replaced AudioPolicymanager::getInput() by getInputForAttr().

No new functionality for now.

Also:

- Fixed warnings in AudioPolicyManager
- Allocate audio session ID before calling getOutputForAttr() in
AudioTrack.

Bug: 16006090.
Change-Id: I15df21e4411db688e3096dd801cf579d76d81711
parent 087eb332
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -152,6 +152,7 @@ public:
     * transferType:       How data is transferred from AudioRecord.
     * flags:              See comments on audio_input_flags_t in <system/audio.h>
     * threadCanCallJava:  Not present in parameter list, and so is fixed at false.
     * pAttributes:        if not NULL, supersedes inputSource for use case selection
     */

                        AudioRecord(audio_source_t inputSource,
@@ -164,7 +165,8 @@ public:
                                    uint32_t notificationFrames = 0,
                                    int sessionId = AUDIO_SESSION_ALLOCATE,
                                    transfer_type transferType = TRANSFER_DEFAULT,
                                    audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE);
                                    audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE,
                                    const audio_attributes_t* pAttributes = NULL);

    /* Terminates the AudioRecord and unregisters it from AudioFlinger.
     * Also destroys all resources associated with the AudioRecord.
@@ -198,7 +200,8 @@ public:
                            bool threadCanCallJava = false,
                            int sessionId = AUDIO_SESSION_ALLOCATE,
                            transfer_type transferType = TRANSFER_DEFAULT,
                            audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE);
                            audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE,
                            const audio_attributes_t* pAttributes = NULL);

    /* Result of constructing the AudioRecord. This must be checked for successful initialization
     * before using any AudioRecord API (except for set()), because using
@@ -219,7 +222,7 @@ public:
            uint32_t    channelCount() const    { return mChannelCount; }
            size_t      frameCount() const  { return mFrameCount; }
            size_t      frameSize() const   { return mFrameSize; }
            audio_source_t inputSource() const  { return mInputSource; }
            audio_source_t inputSource() const  { return mAttributes.source; }

    /* After it's created the track is not active. Call start() to
     * make it active. If set, the callback will start being called.
@@ -489,7 +492,6 @@ private:
    audio_format_t          mFormat;
    uint32_t                mChannelCount;
    size_t                  mFrameSize;         // app-level frame size == AudioFlinger frame size
    audio_source_t          mInputSource;
    uint32_t                mLatency;           // in ms
    audio_channel_mask_t    mChannelMask;
    audio_input_flags_t     mFlags;
@@ -529,6 +531,7 @@ private:

    sp<DeathNotifier>       mDeathNotifier;
    uint32_t                mSequence;              // incremented for each new IAudioRecord attempt
    audio_attributes_t      mAttributes;
};

}; // namespace android
+4 −3
Original line number Diff line number Diff line
@@ -236,12 +236,13 @@ public:

    // Client must successfully hand off the handle reference to AudioFlinger via openRecord(),
    // or release it with releaseInput().
    static audio_io_handle_t getInput(audio_source_t inputSource,
    static status_t getInputForAttr(const audio_attributes_t *attr,
                                    audio_io_handle_t *input,
                                    audio_session_t session,
                                    uint32_t samplingRate,
                                    audio_format_t format,
                                    audio_channel_mask_t channelMask,
                                    audio_session_t sessionId,
                                    audio_input_flags_t);
                                    audio_input_flags_t flags);

    static status_t startInput(audio_io_handle_t input,
                               audio_session_t session);
+7 −6
Original line number Diff line number Diff line
@@ -74,11 +74,12 @@ public:
    virtual void releaseOutput(audio_io_handle_t output,
                               audio_stream_type_t stream,
                               audio_session_t session) = 0;
    virtual audio_io_handle_t getInput(audio_source_t inputSource,
    virtual status_t  getInputForAttr(const audio_attributes_t *attr,
                                      audio_io_handle_t *input,
                                      audio_session_t session,
                                      uint32_t samplingRate,
                                      audio_format_t format,
                                      audio_channel_mask_t channelMask,
                                    audio_session_t audioSession,
                                      audio_input_flags_t flags) = 0;
    virtual status_t startInput(audio_io_handle_t input,
                                audio_session_t session) = 0;
+21 −8
Original line number Diff line number Diff line
@@ -82,14 +82,16 @@ AudioRecord::AudioRecord(
        uint32_t notificationFrames,
        int sessionId,
        transfer_type transferType,
        audio_input_flags_t flags)
        audio_input_flags_t flags,
        const audio_attributes_t* pAttributes)
    : mStatus(NO_INIT), mSessionId(AUDIO_SESSION_ALLOCATE),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
      mPreviousSchedulingGroup(SP_DEFAULT),
      mProxy(NULL)
{
    mStatus = set(inputSource, sampleRate, format, channelMask, frameCount, cbf, user,
            notificationFrames, false /*threadCanCallJava*/, sessionId, transferType, flags);
            notificationFrames, false /*threadCanCallJava*/, sessionId, transferType, flags,
            pAttributes);
}

AudioRecord::~AudioRecord()
@@ -126,7 +128,8 @@ status_t AudioRecord::set(
        bool threadCanCallJava,
        int sessionId,
        transfer_type transferType,
        audio_input_flags_t flags)
        audio_input_flags_t flags,
        const audio_attributes_t* pAttributes)
{
    ALOGV("set(): inputSource %d, sampleRate %u, format %#x, channelMask %#x, frameCount %zu, "
          "notificationFrames %u, sessionId %d, transferType %d, flags %#x",
@@ -168,7 +171,15 @@ status_t AudioRecord::set(
    if (inputSource == AUDIO_SOURCE_DEFAULT) {
        inputSource = AUDIO_SOURCE_MIC;
    }
    mInputSource = inputSource;
    if (pAttributes == NULL) {
        memset(&mAttributes, 0, sizeof(audio_attributes_t));
        mAttributes.source = inputSource;
    } else {
        // stream type shouldn't be looked at, this track has audio attributes
        memcpy(&mAttributes, pAttributes, sizeof(audio_attributes_t));
        ALOGV("Building AudioRecord with attributes: source=%d flags=0x%x tags=[%s]",
              mAttributes.source, mAttributes.flags, mAttributes.tags);
    }

    if (sampleRate == 0) {
        ALOGE("Invalid sample rate %u", sampleRate);
@@ -444,12 +455,14 @@ status_t AudioRecord::openRecord_l(size_t epoch)
        }
    }

    audio_io_handle_t input = AudioSystem::getInput(mInputSource, mSampleRate, mFormat,
            mChannelMask, (audio_session_t)mSessionId, mFlags);
    if (input == AUDIO_IO_HANDLE_NONE) {
    audio_io_handle_t input;
    status = AudioSystem::getInputForAttr(&mAttributes, &input, (audio_session_t)mSessionId,
                                        mSampleRate, mFormat, mChannelMask, mFlags);

    if (status != NO_ERROR) {
        ALOGE("Could not get audio input for record source %d, sample rate %u, format %#x, "
              "channel mask %#x, session %d, flags %#x",
              mInputSource, mSampleRate, mFormat, mChannelMask, mSessionId, mFlags);
              mAttributes.source, mSampleRate, mFormat, mChannelMask, mSessionId, mFlags);
        return BAD_VALUE;
    }
    {
+9 −8
Original line number Diff line number Diff line
@@ -693,16 +693,17 @@ void AudioSystem::releaseOutput(audio_io_handle_t output,
    aps->releaseOutput(output, stream, session);
}

audio_io_handle_t AudioSystem::getInput(audio_source_t inputSource,
status_t AudioSystem::getInputForAttr(const audio_attributes_t *attr,
                                audio_io_handle_t *input,
                                audio_session_t session,
                                uint32_t samplingRate,
                                audio_format_t format,
                                audio_channel_mask_t channelMask,
                                    audio_session_t sessionId,
                                audio_input_flags_t flags)
{
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return 0;
    return aps->getInput(inputSource, samplingRate, format, channelMask, sessionId, flags);
    if (aps == 0) return NO_INIT;
    return aps->getInputForAttr(attr, input, session, samplingRate, format, channelMask, flags);
}

status_t AudioSystem::startInput(audio_io_handle_t input,
Loading