Merge "audio: Make I/O operations in default stub more realistic" am: b862e6e20b
am: 7c0a635b6d
am: b91c536372
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2473366 Change-Id: Id9488d2642f7303211cf2fa108ac694a7c393b6d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
a2145b3994
4 changed files with 26 additions and 8 deletions
|
@ -13,6 +13,7 @@ cc_defaults {
|
|||
shared_libs: [
|
||||
"libalsautilsv2",
|
||||
"libaudioaidlcommon",
|
||||
"libaudioutils",
|
||||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"libcutils",
|
||||
|
|
|
@ -14,8 +14,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#define LOG_TAG "AHAL_Stream"
|
||||
#include <android-base/logging.h>
|
||||
#include <audio_utils/clock.h>
|
||||
|
||||
#include "core-impl/Module.h"
|
||||
#include "core-impl/StreamStub.h"
|
||||
|
@ -29,31 +32,42 @@ using aidl::android::media::audio::common::MicrophoneInfo;
|
|||
namespace aidl::android::hardware::audio::core {
|
||||
|
||||
DriverStub::DriverStub(const StreamContext& context, bool isInput)
|
||||
: mFrameSizeBytes(context.getFrameSize()), mIsInput(isInput) {}
|
||||
: mFrameSizeBytes(context.getFrameSize()),
|
||||
mSampleRate(context.getSampleRate()),
|
||||
mIsAsynchronous(!!context.getAsyncCallback()),
|
||||
mIsInput(isInput) {}
|
||||
|
||||
::android::status_t DriverStub::init() {
|
||||
usleep(1000);
|
||||
usleep(500);
|
||||
return ::android::OK;
|
||||
}
|
||||
|
||||
::android::status_t DriverStub::drain(StreamDescriptor::DrainMode) {
|
||||
usleep(1000);
|
||||
usleep(500);
|
||||
return ::android::OK;
|
||||
}
|
||||
|
||||
::android::status_t DriverStub::flush() {
|
||||
usleep(1000);
|
||||
usleep(500);
|
||||
return ::android::OK;
|
||||
}
|
||||
|
||||
::android::status_t DriverStub::pause() {
|
||||
usleep(1000);
|
||||
usleep(500);
|
||||
return ::android::OK;
|
||||
}
|
||||
|
||||
::android::status_t DriverStub::transfer(void* buffer, size_t frameCount, size_t* actualFrameCount,
|
||||
int32_t* latencyMs) {
|
||||
usleep(3000);
|
||||
static constexpr float kMicrosPerSecond = MICROS_PER_SECOND;
|
||||
static constexpr float kScaleFactor = .8f;
|
||||
if (mIsAsynchronous) {
|
||||
usleep(500);
|
||||
} else {
|
||||
const size_t delayUs = static_cast<size_t>(
|
||||
std::roundf(kScaleFactor * frameCount * kMicrosPerSecond / mSampleRate));
|
||||
usleep(delayUs);
|
||||
}
|
||||
if (mIsInput) {
|
||||
uint8_t* byteBuffer = static_cast<uint8_t*>(buffer);
|
||||
for (size_t i = 0; i < frameCount * mFrameSizeBytes; ++i) {
|
||||
|
@ -66,12 +80,13 @@ DriverStub::DriverStub(const StreamContext& context, bool isInput)
|
|||
}
|
||||
|
||||
::android::status_t DriverStub::standby() {
|
||||
usleep(1000);
|
||||
usleep(500);
|
||||
return ::android::OK;
|
||||
}
|
||||
|
||||
::android::status_t DriverStub::setConnectedDevices(
|
||||
const std::vector<AudioDevice>& connectedDevices __unused) {
|
||||
usleep(500);
|
||||
return ::android::OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ class Module : public BnModule {
|
|||
bool isMmapSupported();
|
||||
|
||||
// This value is used for all AudioPatches.
|
||||
static constexpr int32_t kMinimumStreamBufferSizeFrames = 16;
|
||||
static constexpr int32_t kMinimumStreamBufferSizeFrames = 256;
|
||||
// The maximum stream buffer size is 1 GiB = 2 ** 30 bytes;
|
||||
static constexpr int32_t kMaximumStreamBufferSizeBytes = 1 << 30;
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ class DriverStub : public DriverInterface {
|
|||
|
||||
private:
|
||||
const size_t mFrameSizeBytes;
|
||||
const int mSampleRate;
|
||||
const bool mIsAsynchronous;
|
||||
const bool mIsInput;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue