summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2017-06-21 07:31:19 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2017-06-21 07:31:19 +0000
commit6bf7a64d6b32eb662f6bb85c21161e8bf1f1d57a (patch)
tree66027cbca7e81fd92394301bbb1558f553bf3ef6
parent2905d5715ca9adaf540f6a4117153b9f972ab87a (diff)
parentd45ac2692b42a37dab0b4fce8a1c1df1d3a43ac2 (diff)
release-request-6ca2e77a-0d0f-44cc-a74b-b35c7c145346-for-git_oc-dr1-release-4120184 snap-temp-L36000000076156573
Change-Id: Ib373f9ae34e1a1718f263f6c884416f6177bec75
-rw-r--r--device.mk2
-rw-r--r--libaudio/AudioHardwareInput.cpp2
-rw-r--r--libaudio/AudioStreamIn.cpp33
-rw-r--r--libaudio/AudioStreamIn.h3
4 files changed, 37 insertions, 3 deletions
diff --git a/device.mk b/device.mk
index 0ab6910..a8d96a8 100644
--- a/device.mk
+++ b/device.mk
@@ -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