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

Commit a0129612 authored by jiabin's avatar jiabin
Browse files

Add channel mask in SoundPool sample.

There may be channel mask information after extracting from files. For
instance, haptic-audio coupled ogg file. In that case, it is preferred
using that channel mask directly to create AudioTrack instead of using
channel count to calculate a channel mask.

Test: manully test with playing with SoundPool.
Bug: 111454766
Change-Id: I0483365cbc1b93587d1c4738b0ed25b2d800718d
parent 01fb624e
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -513,7 +513,8 @@ Sample::~Sample()

static status_t decode(int fd, int64_t offset, int64_t length,
        uint32_t *rate, int *numChannels, audio_format_t *audioFormat,
        sp<MemoryHeapBase> heap, size_t *memsize) {
        audio_channel_mask_t *channelMask, sp<MemoryHeapBase> heap,
        size_t *memsize) {

    ALOGV("fd %d, offset %" PRId64 ", size %" PRId64, fd, offset, length);
    AMediaExtractor *ex = AMediaExtractor_new();
@@ -650,6 +651,10 @@ static status_t decode(int fd, int64_t offset, int64_t length,
                (void)AMediaFormat_delete(format);
                return UNKNOWN_ERROR;
            }
            if (!AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_CHANNEL_MASK,
                    (int32_t*) channelMask)) {
                *channelMask = AUDIO_CHANNEL_NONE;
            }
            (void)AMediaFormat_delete(format);
            *memsize = written;
            return OK;
@@ -665,12 +670,13 @@ status_t Sample::doLoad()
    uint32_t sampleRate;
    int numChannels;
    audio_format_t format;
    audio_channel_mask_t channelMask;
    status_t status;
    mHeap = new MemoryHeapBase(kDefaultHeapSize);

    ALOGV("Start decode");
    status = decode(mFd, mOffset, mLength, &sampleRate, &numChannels, &format,
                                 mHeap, &mSize);
                    &channelMask, mHeap, &mSize);
    ALOGV("close(%d)", mFd);
    ::close(mFd);
    mFd = -1;
@@ -697,6 +703,7 @@ status_t Sample::doLoad()
    mSampleRate = sampleRate;
    mNumChannels = numChannels;
    mFormat = format;
    mChannelMask = channelMask;
    mState = READY;
    return NO_ERROR;

@@ -781,7 +788,11 @@ void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftV
            // wrong audio audio buffer size  (mAudioBufferSize)
            unsigned long toggle = mToggle ^ 1;
            void *userData = (void *)((unsigned long)this | toggle);
            audio_channel_mask_t channelMask = audio_channel_out_mask_from_count(numChannels);
            audio_channel_mask_t sampleChannelMask = sample->channelMask();
            // When sample contains a not none channel mask, use it as is.
            // Otherwise, use channel count to calculate channel mask.
            audio_channel_mask_t channelMask = sampleChannelMask != AUDIO_CHANNEL_NONE
                    ? sampleChannelMask : audio_channel_out_mask_from_count(numChannels);

            // do not create a new audio track if current track is compatible with sample parameters
    #ifdef USE_SHARED_MEM_BUFFER
+14 −12
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ public:
    int numChannels() { return mNumChannels; }
    int sampleRate() { return mSampleRate; }
    audio_format_t format() { return mFormat; }
    audio_channel_mask_t channelMask() { return mChannelMask; }
    size_t size() { return mSize; }
    int state() { return mState; }
    uint8_t* data() { return static_cast<uint8_t*>(mData->pointer()); }
@@ -75,6 +76,7 @@ private:
    uint8_t              mState;
    uint8_t              mNumChannels;
    audio_format_t       mFormat;
    audio_channel_mask_t mChannelMask;
    int                  mFd;
    int64_t              mOffset;
    int64_t              mLength;