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

Commit 0d255b2d authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Use channel mask instead of channel count for track creation

Record and playback objects (resp AudioRecord and AudioTrack)
are created using a channel mask, but this information is lost
in the mixer because only the channel count is known to
AudioFlinger. A channel count can always be derived from a
channel mask.

The change consists in:
- disambiguiting variable names for channel masks and counts
- passing the mask information from the client to AudioFlinger
 and the mixer.
- when using the DIRECT ouput, only verifying the format of
 the track is compatible with the output's for PCM.

Change-Id: I50d87bfb7d7afcabdf5f12d4ab75ef3a54132c0e
parent 65580f9a
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ public:
     * sampleRate:         Track sampling rate in Hz.
     * format:             Audio format (e.g AUDIO_FORMAT_PCM_16_BIT for signed
     *                     16 bits per sample).
     * channels:           Channel mask: see audio_channels_t.
     * channelMask:        Channel mask: see audio_channels_t.
     * frameCount:         Total size of track PCM buffer in frames. This defines the
     *                     latency of the track.
     * flags:              A bitmask of acoustic values from enum record_flags.  It enables
@@ -151,7 +151,7 @@ public:
                        AudioRecord(int inputSource,
                                    uint32_t sampleRate = 0,
                                    int format          = 0,
                                    uint32_t channels = AUDIO_CHANNEL_IN_MONO,
                                    uint32_t channelMask = AUDIO_CHANNEL_IN_MONO,
                                    int frameCount      = 0,
                                    uint32_t flags      = 0,
                                    callback_t cbf = 0,
@@ -177,7 +177,7 @@ public:
            status_t    set(int inputSource     = 0,
                            uint32_t sampleRate = 0,
                            int format          = 0,
                            uint32_t channels = AUDIO_CHANNEL_IN_MONO,
                            uint32_t channelMask = AUDIO_CHANNEL_IN_MONO,
                            int frameCount      = 0,
                            uint32_t flags      = 0,
                            callback_t cbf = 0,
@@ -348,8 +348,8 @@ private:

            bool processAudioBuffer(const sp<ClientRecordThread>& thread);
            status_t openRecord_l(uint32_t sampleRate,
                                int format,
                                int channelCount,
                                uint32_t format,
                                uint32_t channelMask,
                                int frameCount,
                                uint32_t flags,
                                audio_io_handle_t input);
@@ -364,10 +364,10 @@ private:
    uint32_t                mFrameCount;

    audio_track_cblk_t*     mCblk;
    uint8_t                 mFormat;
    uint32_t                mFormat;
    uint8_t                 mChannelCount;
    uint8_t                 mInputSource;
    uint8_t                 mReserved;
    uint8_t                 mReserved[2];
    status_t                mStatus;
    uint32_t                mLatency;

@@ -382,7 +382,7 @@ private:
    uint32_t                mNewPosition;
    uint32_t                mUpdatePeriod;
    uint32_t                mFlags;
    uint32_t                mChannels;
    uint32_t                mChannelMask;
    audio_io_handle_t       mInput;
    int                     mSessionId;
};
+10 −9
Original line number Diff line number Diff line
@@ -69,8 +69,8 @@ public:
            MUTE    = 0x00000001
        };
        uint32_t    flags;
        int         channelCount;
        int         format;
        int         channelCount; // will be removed in the future, do not use
        size_t      frameCount;
        size_t      size;
        union {
@@ -129,7 +129,7 @@ public:
     * sampleRate:         Track sampling rate in Hz.
     * format:             Audio format (e.g AUDIO_FORMAT_PCM_16_BIT for signed
     *                     16 bits per sample).
     * channels:           Channel mask: see audio_channels_t.
     * channelMask:        Channel mask: see audio_channels_t.
     * frameCount:         Total size of track PCM buffer in frames. This defines the
     *                     latency of the track.
     * flags:              Reserved for future use.
@@ -143,7 +143,7 @@ public:
                        AudioTrack( int streamType,
                                    uint32_t sampleRate  = 0,
                                    int format           = 0,
                                    int channels         = 0,
                                    int channelMask      = 0,
                                    int frameCount       = 0,
                                    uint32_t flags       = 0,
                                    callback_t cbf       = 0,
@@ -163,7 +163,7 @@ public:
                        AudioTrack( int streamType,
                                    uint32_t sampleRate = 0,
                                    int format          = 0,
                                    int channels        = 0,
                                    int channelMask     = 0,
                                    const sp<IMemory>& sharedBuffer = 0,
                                    uint32_t flags      = 0,
                                    callback_t cbf      = 0,
@@ -187,7 +187,7 @@ public:
            status_t    set(int streamType      =-1,
                            uint32_t sampleRate = 0,
                            int format          = 0,
                            int channels        = 0,
                            int channelMask     = 0,
                            int frameCount      = 0,
                            uint32_t flags      = 0,
                            callback_t cbf      = 0,
@@ -438,8 +438,8 @@ private:
            bool processAudioBuffer(const sp<AudioTrackThread>& thread);
            status_t createTrack_l(int streamType,
                                 uint32_t sampleRate,
                                 int format,
                                 int channelCount,
                                 uint32_t format,
                                 uint32_t channelMask,
                                 int frameCount,
                                 uint32_t flags,
                                 const sp<IMemory>& sharedBuffer,
@@ -459,11 +459,12 @@ private:
    uint32_t                mFrameCount;

    audio_track_cblk_t*     mCblk;
    uint32_t                mFormat;
    uint8_t                 mStreamType;
    uint8_t                 mFormat;
    uint8_t                 mChannelCount;
    uint8_t                 mMuted;
    uint32_t                mChannels;
    uint8_t                 mReserved;
    uint32_t                mChannelMask;
    status_t                mStatus;
    uint32_t                mLatency;

+5 −5
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@ public:
                                pid_t pid,
                                int streamType,
                                uint32_t sampleRate,
                                int format,
                                int channelCount,
                                uint32_t format,
                                uint32_t channelMask,
                                int frameCount,
                                uint32_t flags,
                                const sp<IMemory>& sharedBuffer,
@@ -61,8 +61,8 @@ public:
                                pid_t pid,
                                int input,
                                uint32_t sampleRate,
                                int format,
                                int channelCount,
                                uint32_t format,
                                uint32_t channelMask,
                                int frameCount,
                                uint32_t flags,
                                int *sessionId,
@@ -73,7 +73,7 @@ public:
     */
    virtual     uint32_t    sampleRate(int output) const = 0;
    virtual     int         channelCount(int output) const = 0;
    virtual     int         format(int output) const = 0;
    virtual     uint32_t    format(int output) const = 0;
    virtual     size_t      frameCount(int output) const = 0;
    virtual     uint32_t    latency(int output) const = 0;

+2 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ struct audio_track_cblk_t
                // 16 bit because data is converted to 16 bit before being stored in buffer

                uint8_t     frameSize;
                uint8_t     channelCount;
                uint8_t     pad1;
                uint16_t    bufferTimeoutMs; // Maximum cumulated timeout before restarting audioflinger

                uint16_t    waitTimeMs;      // Cumulated wait time
@@ -90,6 +90,7 @@ struct audio_track_cblk_t
    volatile    int32_t     flags;

                // Cache line boundary (32 bytes)

                            audio_track_cblk_t();
                uint32_t    stepUser(uint32_t frameCount);
                bool        stepServer(uint32_t frameCount);
+14 −14
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ AudioRecord::AudioRecord(
        int inputSource,
        uint32_t sampleRate,
        int format,
        uint32_t channels,
        uint32_t channelMask,
        int frameCount,
        uint32_t flags,
        callback_t cbf,
@@ -97,7 +97,7 @@ AudioRecord::AudioRecord(
        int sessionId)
    : mStatus(NO_INIT), mSessionId(0)
{
    mStatus = set(inputSource, sampleRate, format, channels,
    mStatus = set(inputSource, sampleRate, format, channelMask,
            frameCount, flags, cbf, user, notificationFrames, sessionId);
}

@@ -121,7 +121,7 @@ status_t AudioRecord::set(
        int inputSource,
        uint32_t sampleRate,
        int format,
        uint32_t channels,
        uint32_t channelMask,
        int frameCount,
        uint32_t flags,
        callback_t cbf,
@@ -131,7 +131,7 @@ status_t AudioRecord::set(
        int sessionId)
{

    LOGV("set(): sampleRate %d, channels %d, frameCount %d",sampleRate, channels, frameCount);
    LOGV("set(): sampleRate %d, channelMask %d, frameCount %d",sampleRate, channelMask, frameCount);

    AutoMutex lock(mLock);

@@ -156,14 +156,14 @@ status_t AudioRecord::set(
        return BAD_VALUE;
    }

    if (!audio_is_input_channel(channels)) {
    if (!audio_is_input_channel(channelMask)) {
        return BAD_VALUE;
    }

    int channelCount = popcount(channels);
    int channelCount = popcount(channelMask);

    audio_io_handle_t input = AudioSystem::getInput(inputSource,
                                    sampleRate, format, channels, (audio_in_acoustics_t)flags);
                                    sampleRate, format, channelMask, (audio_in_acoustics_t)flags);
    if (input == 0) {
        LOGE("Could not get audio input for record source %d", inputSource);
        return BAD_VALUE;
@@ -190,7 +190,7 @@ status_t AudioRecord::set(
    mSessionId = sessionId;

    // create the IAudioRecord
    status = openRecord_l(sampleRate, format, channelCount,
    status = openRecord_l(sampleRate, format, channelMask,
                        frameCount, flags, input);
    if (status != NO_ERROR) {
        return status;
@@ -209,7 +209,7 @@ status_t AudioRecord::set(
    // Update buffer size in case it has been limited by AudioFlinger during track creation
    mFrameCount = mCblk->frameCount;
    mChannelCount = (uint8_t)channelCount;
    mChannels = channels;
    mChannelMask = channelMask;
    mActive = 0;
    mCbf = cbf;
    mNotificationFrames = notificationFrames;
@@ -437,8 +437,8 @@ unsigned int AudioRecord::getInputFramesLost()
// must be called with mLock held
status_t AudioRecord::openRecord_l(
        uint32_t sampleRate,
        int format,
        int channelCount,
        uint32_t format,
        uint32_t channelMask,
        int frameCount,
        uint32_t flags,
        audio_io_handle_t input)
@@ -451,7 +451,7 @@ status_t AudioRecord::openRecord_l(

    sp<IAudioRecord> record = audioFlinger->openRecord(getpid(), input,
                                                       sampleRate, format,
                                                       channelCount,
                                                       channelMask,
                                                       frameCount,
                                                       ((uint16_t)flags) << 16,
                                                       &mSessionId,
@@ -589,7 +589,7 @@ audio_io_handle_t AudioRecord::getInput_l()
{
    mInput = AudioSystem::getInput(mInputSource,
                                mCblk->sampleRate,
                                mFormat, mChannels,
                                mFormat, mChannelMask,
                                (audio_in_acoustics_t)mFlags);
    return mInput;
}
@@ -756,7 +756,7 @@ status_t AudioRecord::restoreRecord_l(audio_track_cblk_t*& cblk)
        // if the new IAudioRecord is created, openRecord_l() will modify the
        // following member variables: mAudioRecord, mCblkMemory and mCblk.
        // It will also delete the strong references on previous IAudioRecord and IMemory
        result = openRecord_l(cblk->sampleRate, mFormat, mChannelCount,
        result = openRecord_l(cblk->sampleRate, mFormat, mChannelMask,
                mFrameCount, mFlags, getInput_l());
        if (result == NO_ERROR) {
            result = mAudioRecord->start();
Loading