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

Commit eb9487e1 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Fix capture overruns at non-primary sample rate

and small buffer size.  Also:
Pull out the magic number "12 ms" to a named constant.
Remove obsolete AudioFlinger::mPrimaryOutputSampleRate.

Bug: 22662814
Change-Id: I261f75a222c4505a84aad2493d251bd2dea59f68
parent 8f0547a9
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -181,7 +181,6 @@ AudioFlinger::AudioFlinger()
      mIsLowRamDevice(true),
      mIsDeviceTypeKnown(false),
      mGlobalEffectEnableTime(0),
      mPrimaryOutputSampleRate(0),
      mSystemReady(false)
{
    getpid_cached = getpid();
@@ -1869,8 +1868,6 @@ status_t AudioFlinger::openOutput(audio_module_handle_t module,
            mHardwareStatus = AUDIO_HW_SET_MODE;
            mPrimaryHardwareDev->hwDevice()->set_mode(mPrimaryHardwareDev->hwDevice(), mMode);
            mHardwareStatus = AUDIO_HW_IDLE;

            mPrimaryOutputSampleRate = config->sample_rate;
        }
        return NO_ERROR;
    }
+1 −3
Original line number Diff line number Diff line
@@ -763,8 +763,6 @@ private:

    sp<PatchPanel> mPatchPanel;

    uint32_t    mPrimaryOutputSampleRate;   // sample rate of the primary output, or zero if none
                                            // protected by mHardwareLock
    bool        mSystemReady;
};

+6 −14
Original line number Diff line number Diff line
@@ -125,10 +125,15 @@ static const uint32_t kMinThreadSleepTimeUs = 5000;
static const uint32_t kMaxThreadSleepTimeShift = 2;

// minimum normal sink buffer size, expressed in milliseconds rather than frames
// FIXME This should be based on experimentally observed scheduling jitter
static const uint32_t kMinNormalSinkBufferSizeMs = 20;
// maximum normal sink buffer size
static const uint32_t kMaxNormalSinkBufferSizeMs = 24;

// minimum capture buffer size in milliseconds to _not_ need a fast capture thread
// FIXME This should be based on experimentally observed scheduling jitter
static const uint32_t kMinNormalCaptureBufferSizeMs = 12;

// Offloaded output thread standby delay: allows track transition without going to standby
static const nsecs_t kOffloadStandbyDelayNs = seconds(1);

@@ -5490,20 +5495,7 @@ AudioFlinger::RecordThread::RecordThread(const sp<AudioFlinger>& audioFlinger,
        initFastCapture = true;
        break;
    case FastCapture_Static:
        uint32_t primaryOutputSampleRate;
        {
            AutoMutex _l(audioFlinger->mHardwareLock);
            primaryOutputSampleRate = audioFlinger->mPrimaryOutputSampleRate;
        }
        initFastCapture =
                // either capture sample rate is same as (a reasonable) primary output sample rate
                ((isMusicRate(primaryOutputSampleRate) &&
                    (mSampleRate == primaryOutputSampleRate)) ||
                // or primary output sample rate is unknown, and capture sample rate is reasonable
                ((primaryOutputSampleRate == 0) &&
                        isMusicRate(mSampleRate))) &&
                // and the buffer size is < 12 ms
                (mFrameCount * 1000) / mSampleRate < 12;
        initFastCapture = (mFrameCount * 1000) / mSampleRate < kMinNormalCaptureBufferSizeMs;
        break;
    // case FastCapture_Dynamic:
    }