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

Commit edd72459 authored by Scott Mertz's avatar Scott Mertz
Browse files

stagefright: Move to 64 available tracks

Many games use numerous tracks.  If the system
runs out of tracks, new tracks won't be able
to be created.  This has been causing notifications
not to play if many apps are holding open tracks.

Issue: BACON-6

Change-Id: I9cea51b9bd678feba31a88e17dd22083b01d81de
parent 26c53e60
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -95,10 +95,9 @@ bool AudioMixer::isMultichannelCapable = false;
effect_descriptor_t AudioMixer::dwnmFxDesc;

// Ensure mConfiguredNames bitmask is initialized properly on all architectures.
// The value of 1 << x is undefined in C when x >= 32.

AudioMixer::AudioMixer(size_t frameCount, uint32_t sampleRate, uint32_t maxNumTracks)
    :   mTrackNames(0), mConfiguredNames((maxNumTracks >= 32 ? 0 : 1 << maxNumTracks) - 1),
    :   mTrackNames(0), mConfiguredNames((maxNumTracks >= 64 ? 0ULL : 1ULL << maxNumTracks) - 1),
        mSampleRate(sampleRate)
{
    // AudioMixer is not yet capable of multi-channel beyond stereo
@@ -107,12 +106,11 @@ AudioMixer::AudioMixer(size_t frameCount, uint32_t sampleRate, uint32_t maxNumTr
    ALOG_ASSERT(maxNumTracks <= MAX_NUM_TRACKS, "maxNumTracks %u > MAX_NUM_TRACKS %u",
            maxNumTracks, MAX_NUM_TRACKS);

    // AudioMixer is not yet capable of more than 32 active track inputs
    ALOG_ASSERT(32 >= MAX_NUM_TRACKS, "bad MAX_NUM_TRACKS %d", MAX_NUM_TRACKS);
    // AudioMixer is not yet capable of more than 64 active track inputs
    ALOG_ASSERT(64 >= MAX_NUM_TRACKS, "bad MAX_NUM_TRACKS %d", MAX_NUM_TRACKS);

    // AudioMixer is not yet capable of multi-channel output beyond stereo
    ALOG_ASSERT(2 == MAX_NUM_CHANNELS, "bad MAX_NUM_CHANNELS %d", MAX_NUM_CHANNELS);

    LocalClock lc;

    pthread_once(&sOnceControl, &sInitRoutine);
@@ -178,11 +176,11 @@ void AudioMixer::setLog(NBLog::Writer *log)

int AudioMixer::getTrackName(audio_channel_mask_t channelMask, int sessionId)
{
    uint32_t names = (~mTrackNames) & mConfiguredNames;
    uint64_t names = (~mTrackNames) & mConfiguredNames;
    if (names != 0) {
        int n = __builtin_ctz(names);
        int n = __builtin_ctzll(names);
        ALOGV("add track (%d)", n);
        mTrackNames |= 1 << n;
        mTrackNames |= 1ULL << n;
        // assume default parameters for the track, except where noted below
        track_t* t = &mState.tracks[n];
        t->needs = 0;
@@ -386,7 +384,7 @@ void AudioMixer::deleteTrackName(int name)
    // delete the downmixer
    unprepareTrackForDownmix(&mState.tracks[name], name);

    mTrackNames &= ~(1<<name);
    mTrackNames &= ~(1ULL<<name);
}

void AudioMixer::enable(int name)
+6 −6
Original line number Diff line number Diff line
@@ -43,9 +43,9 @@ public:
    /*virtual*/             ~AudioMixer();  // non-virtual saves a v-table, restore if sub-classed


    // This mixer has a hard-coded upper limit of 32 active track inputs.
    // Adding support for > 32 tracks would require more than simply changing this value.
    static const uint32_t MAX_NUM_TRACKS = 32;
    // This mixer has a hard-coded upper limit of 64 active track inputs.
    // Adding support for > 64 tracks would require more than simply changing this value.
    static const uint32_t MAX_NUM_TRACKS = 64;
    // maximum number of channels supported by the mixer

    // This mixer has a hard-coded upper limit of 2 channels for output.
@@ -113,7 +113,7 @@ public:
    void        setBufferProvider(int name, AudioBufferProvider* bufferProvider);
    void        process(int64_t pts);

    uint32_t    trackNames() const { return mTrackNames; }
    uint64_t    trackNames() const { return mTrackNames; }

    size_t      getUnreleasedFrames(int name) const;

@@ -241,11 +241,11 @@ private:
    };

    // bitmask of allocated track names, where bit 0 corresponds to TRACK0 etc.
    uint32_t        mTrackNames;
    uint64_t        mTrackNames;

    // bitmask of configured track names; ~0 if maxNumTracks == MAX_NUM_TRACKS,
    // but will have fewer bits set if maxNumTracks < MAX_NUM_TRACKS
    const uint32_t  mConfiguredNames;
    const uint64_t  mConfiguredNames;

    const uint32_t  mSampleRate;

+1 −1
Original line number Diff line number Diff line
@@ -3643,7 +3643,7 @@ void AudioFlinger::MixerThread::dumpInternals(int fd, const Vector<String16>& ar

    PlaybackThread::dumpInternals(fd, args);

    snprintf(buffer, SIZE, "AudioMixer tracks: %08x\n", mAudioMixer->trackNames());
    snprintf(buffer, SIZE, "AudioMixer tracks: %016llx\n", mAudioMixer->trackNames());
    result.append(buffer);
    write(fd, result.string(), result.size());