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

Commit 17a6de9c authored by Sharad Sangle's avatar Sharad Sangle Committed by Linux Build Service Account
Browse files

audio: calculate the max buffer size runtime

  Currently kMaxBufferSize is predefined as 30720,
  but this is valid only for camcorder use-case and
  not for other use-case, but as this is predefined
  calculations for other than camera use-case go
  wrong, such as frameCount and record latency, which
  leads to issues such as data drop at the begining
  due to high record latency.

  So instead predefining the MaxBufferSize calculate
  it only for camcorder use-case and use standard AOSP
  value otherwise

Change-Id: Ie7d43ddfdcb2b13a8a5eaa12cc8a233ac0d9470d
parent 72edeed6
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -61,8 +61,7 @@ protected:
    virtual ~AudioSource();

    enum {
        //calculated for max duration 80 msec with 48K sampling rate.
        kMaxBufferSize = 30720,
        kMaxBufferSize = 2048,

        // After the initial mute, we raise the volume linearly
        // over kAutoRampDurationUs.
@@ -91,7 +90,7 @@ protected:
    int64_t mInitialReadTimeUs;
    int64_t mNumFramesReceived;
    int64_t mNumClientOwnedBuffers;

    size_t mMaxBufferSize;
    List<MediaBuffer * > mBuffersReceived;

    void trackMaxAmplitude(int16_t *data, int nSamples);
+6 −5
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ AudioSource::AudioSource(
    CHECK(sampleRate > 0);

    size_t minFrameCount;
    mMaxBufferSize = kMaxBufferSize;
    status_t status = AudioRecord::getMinFrameCount(&minFrameCount,
                                           sampleRate,
                                           AUDIO_FORMAT_PCM_16_BIT,
@@ -77,7 +78,7 @@ AudioSource::AudioSource(
    if (status == OK) {
        // make sure that the AudioRecord callback never returns more than the maximum
        // buffer size
        uint32_t frameCount = kMaxBufferSize / sizeof(int16_t) / channelCount;
        uint32_t frameCount = mMaxBufferSize / sizeof(int16_t) / channelCount;

        // make sure that the AudioRecord total buffer size is large enough
        size_t bufCount = 2;
@@ -193,7 +194,7 @@ sp<MetaData> AudioSource::getFormat() {
    meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_RAW);
    meta->setInt32(kKeySampleRate, mSampleRate);
    meta->setInt32(kKeyChannelCount, mRecord->channelCount());
    meta->setInt32(kKeyMaxInputSize, kMaxBufferSize);
    meta->setInt32(kKeyMaxInputSize, mMaxBufferSize);
    meta->setInt32(kKeyPcmEncoding, kAudioEncodingPcm16bit);

    return meta;
@@ -350,9 +351,9 @@ status_t AudioSource::dataCallback(const AudioRecord::Buffer& audioBuffer) {

    while (numLostBytes > 0) {
        size_t bufferSize = numLostBytes;
        if (numLostBytes > kMaxBufferSize) {
            numLostBytes -= kMaxBufferSize;
            bufferSize = kMaxBufferSize;
        if (numLostBytes > mMaxBufferSize) {
            numLostBytes -= mMaxBufferSize;
            bufferSize = mMaxBufferSize;
        } else {
            numLostBytes = 0;
        }