mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Legacy wrapper: Use arbitrary limit on buffer size
The legacy HAL wrapper prepareForWrite and prepareForRead used to return INVALID_ARGUMENTS if the computed buffer size just under SIZE_MAX. This meant that the limitation depended on the architecture (32 vs 64 bit size_t). This caused VTS test failure on 64 bits. Instead of dynamically calculating an arbitrary max size, choose a fixed one. This max buffer size has been chosen at 1GiB. It should be enough for the foreseeable future and not too close from the 4GiB max on 32 bit. Test: vts-tradefed run commandAndExit vts --module VtsHalAudioV2_0Target Bug: 67030516 Change-Id: I4cc3efda9bb66e6dae8b4e6785f52d9e51440aee Signed-off-by: Kevin Rocard <krocard@google.com>
This commit is contained in:
committed by
Mikhail Naganov
parent
3021f1fafb
commit
46cba442d2
@@ -49,6 +49,13 @@ using ::android::sp;
|
||||
struct Stream : public IStream, public ParametersUtil {
|
||||
explicit Stream(audio_stream_t* stream);
|
||||
|
||||
/** 1GiB is the maximum buffer size the HAL client is allowed to request.
|
||||
* This value has been chosen to be under SIZE_MAX and still big enough
|
||||
* for all audio use case.
|
||||
* Keep private for 2.0, put in .hal in 2.1
|
||||
*/
|
||||
static constexpr uint32_t MAX_BUFFER_SIZE = 2 << 30 /* == 1GiB */;
|
||||
|
||||
// Methods from ::android::hardware::audio::V2_0::IStream follow.
|
||||
Return<uint64_t> getFrameSize() override;
|
||||
Return<uint64_t> getFrameCount() override;
|
||||
|
||||
@@ -347,14 +347,10 @@ Return<void> StreamIn::prepareForReading(uint32_t frameSize,
|
||||
sendError(Result::INVALID_ARGUMENTS);
|
||||
return Void();
|
||||
}
|
||||
// A message queue asserts if it can not handle the requested buffer,
|
||||
// thus the client has to guess the maximum size it can handle
|
||||
// Choose an arbitrary margin for the overhead of a message queue
|
||||
size_t metadataOverhead = 100000;
|
||||
if (frameSize >
|
||||
(std::numeric_limits<size_t>::max() - metadataOverhead) / framesCount) {
|
||||
ALOGE("Buffer too big: %u*%u bytes can not fit in a message queue",
|
||||
frameSize, framesCount);
|
||||
|
||||
if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) {
|
||||
ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount,
|
||||
Stream::MAX_BUFFER_SIZE);
|
||||
sendError(Result::INVALID_ARGUMENTS);
|
||||
return Void();
|
||||
}
|
||||
|
||||
@@ -323,14 +323,9 @@ Return<void> StreamOut::prepareForWriting(uint32_t frameSize,
|
||||
sendError(Result::INVALID_ARGUMENTS);
|
||||
return Void();
|
||||
}
|
||||
// A message queue asserts if it can not handle the requested buffer,
|
||||
// thus the client has to guess the maximum size it can handle
|
||||
size_t metadataOverhead =
|
||||
100000; // Arbitrary margin for the overhead of a message queue
|
||||
if (frameSize >
|
||||
(std::numeric_limits<size_t>::max() - metadataOverhead) / framesCount) {
|
||||
ALOGE("Buffer too big: %u*%u bytes can not fit in a message queue",
|
||||
frameSize, framesCount);
|
||||
if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) {
|
||||
ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount,
|
||||
Stream::MAX_BUFFER_SIZE);
|
||||
sendError(Result::INVALID_ARGUMENTS);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user