diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-06-21 07:37:10 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-06-21 07:37:10 +0000 |
commit | 1837373f6fd1ab4e7a2f086e489726c769e8f489 (patch) | |
tree | 099b54ae7b829dee4f7f2eee858fc9aa4ea2b81e | |
parent | 769026f4edfaefa7a30471eeb6ccb6f2814c09aa (diff) | |
parent | 94109e23217e03656071699cd9fd983ec61cd3cd (diff) | |
download | fugu-1837373f6fd1ab4e7a2f086e489726c769e8f489.tar.gz |
release-request-d1418208-3b0b-4ef9-a2f0-a8f8ac6c24e8-for-git_oc-mr1-release-4120176 snap-temp-L55000000076156472
Change-Id: I7d4c0bb3f83c2e7845770515ac4e65dcbcb2e067
-rw-r--r-- | device.mk | 2 | ||||
-rw-r--r-- | libaudio/AudioHardwareInput.cpp | 2 | ||||
-rw-r--r-- | libaudio/AudioStreamIn.cpp | 33 | ||||
-rw-r--r-- | libaudio/AudioStreamIn.h | 3 |
4 files changed, 37 insertions, 3 deletions
@@ -152,7 +152,7 @@ PRODUCT_COPY_FILES += \ device/asus/fugu/wrs_omxil_components.list:system/etc/wrs_omxil_components.list \ frameworks/av/media/libstagefright/data/media_codecs_google_audio.xml:system/etc/media_codecs_google_audio.xml \ frameworks/av/media/libstagefright/data/media_codecs_google_tv.xml:system/etc/media_codecs_google_tv.xml \ - frameworks/av/media/libstagefright/data/media_codecs_google_video.xml:system/etc/media_codecs_google_video.xml \ + frameworks/av/media/libstagefright/data/media_codecs_google_video_le.xml:system/etc/media_codecs_google_video_le.xml \ device/asus/fugu/media_codecs.xml:system/etc/media_codecs.xml \ device/asus/fugu/media_codecs_performance.xml:system/etc/media_codecs_performance.xml \ device/asus/fugu/mfx_omxil_core.conf:system/etc/mfx_omxil_core.conf \ diff --git a/libaudio/AudioHardwareInput.cpp b/libaudio/AudioHardwareInput.cpp index 6a7a9f4..eef0e89 100644 --- a/libaudio/AudioHardwareInput.cpp +++ b/libaudio/AudioHardwareInput.cpp @@ -76,7 +76,7 @@ status_t AudioHardwareInput::getMicMute(bool* mute) } // milliseconds per ALSA period -const uint32_t AudioHardwareInput::kPeriodMsec = 10; +const uint32_t AudioHardwareInput::kPeriodMsec = 20; size_t AudioHardwareInput::calculateInputBufferSize(uint32_t outputSampleRate, audio_format_t format, diff --git a/libaudio/AudioStreamIn.cpp b/libaudio/AudioStreamIn.cpp index 89df69a..36156aa 100644 --- a/libaudio/AudioStreamIn.cpp +++ b/libaudio/AudioStreamIn.cpp @@ -43,7 +43,7 @@ const audio_format_t AudioStreamIn::kAudioFormat = AUDIO_FORMAT_PCM_16_BIT; const uint32_t AudioStreamIn::kChannelMask = AUDIO_CHANNEL_IN_MONO; // number of periods in the ALSA buffer -const int AudioStreamIn::kPeriodCount = 4; +const int AudioStreamIn::kPeriodCount = 32; AudioStreamIn::AudioStreamIn(AudioHardwareInput& owner) : mOwnerHAL(owner) @@ -58,6 +58,9 @@ AudioStreamIn::AudioStreamIn(AudioHardwareInput& owner) , mInputSource(AUDIO_SOURCE_DEFAULT) , mReadStatus(0) , mFramesIn(0) + , mLastReadFinishedNs(-1) + , mLastBytesRead(0) + , mMinAllowedReadTimeNs(0) { struct resampler_buffer_provider& provider = mResamplerProviderWrapper.provider; @@ -282,12 +285,37 @@ ssize_t AudioStreamIn::read(void* buffer, size_t bytes) // if we have never returned any data from an actual device and need // to synth on the first call to read) usleep(bytes * 1000000 / getFrameSize() / mRequestedSampleRate); + mLastReadFinishedNs = -1; } else { bool mute; mOwnerHAL.getMicMute(&mute); if (mute) { memset(buffer, 0, bytes); } + + nsecs_t now = systemTime(); + + if (mLastReadFinishedNs != -1) { + const nsecs_t kMinsleeptimeNs = 1000000; // don't sleep less than 1ms + const nsecs_t deltaNs = now - mLastReadFinishedNs; + + if (bytes != mLastBytesRead) { + mMinAllowedReadTimeNs = + (((nsecs_t)bytes * 1000000000) / getFrameSize()) / mRequestedSampleRate / 2; + mLastBytesRead = bytes; + } + + // Make sure total read time is at least the duration corresponding to half the amount + // of data requested. + // Note: deltaNs is always > 0 here + if (mMinAllowedReadTimeNs > deltaNs + kMinsleeptimeNs) { + usleep((mMinAllowedReadTimeNs - deltaNs) / 1000); + // Throttle must be attributed to the previous read time to allow + // back-to-back throttling. + now = systemTime(); + } + } + mLastReadFinishedNs = now; } return bytes; @@ -375,6 +403,9 @@ status_t AudioStreamIn::startInputStream_l() } mBuffer = new int16_t[mBufferSize / sizeof(uint16_t)]; + mLastReadFinishedNs = -1; + mLastBytesRead = 0; + if (mResampler) { release_resampler(mResampler); mResampler = NULL; diff --git a/libaudio/AudioStreamIn.h b/libaudio/AudioStreamIn.h index 8c2d444..1fe4410 100644 --- a/libaudio/AudioStreamIn.h +++ b/libaudio/AudioStreamIn.h @@ -115,6 +115,9 @@ class AudioStreamIn { int mInputSource; int mReadStatus; unsigned int mFramesIn; + nsecs_t mLastReadFinishedNs; + size_t mLastBytesRead; + nsecs_t mMinAllowedReadTimeNs; }; }; // namespace android |