Audio HAL: A volume/gain outside of [0,1] is an error
Hals are supposed to received normalized volumes, between 0 and 1.
Previously volumes outside [0,1] were clamp to this range.
This clamping has the capability to hide bugs thus return an error if
such volume is received.
Test: vts-tradefed run vts --module VtsHalAudioV2_0Target
Test: call/play music/record/video...
Bug: 36311550
Change-Id: Ia4880bdff6111cbcdae6a4ebee921eddae141ee4
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/audio/2.0/default/StreamOut.cpp b/audio/2.0/default/StreamOut.cpp
index eb53259..e48497f 100644
--- a/audio/2.0/default/StreamOut.cpp
+++ b/audio/2.0/default/StreamOut.cpp
@@ -25,6 +25,7 @@
#include <utils/Trace.h>
#include "StreamOut.h"
+#include "Util.h"
namespace android {
namespace hardware {
@@ -282,12 +283,16 @@
}
Return<Result> StreamOut::setVolume(float left, float right) {
- Result retval(Result::NOT_SUPPORTED);
- if (mStream->set_volume != NULL) {
- retval = Stream::analyzeStatus(
- "set_volume", mStream->set_volume(mStream, left, right));
+ if (mStream->set_volume == NULL) {
+ return Result::NOT_SUPPORTED;
}
- return retval;
+ if (!isGainNormalized(left)) {
+ ALOGW("Can not set a stream output volume {%f, %f} outside [0,1]", left,
+ right);
+ return Result::INVALID_ARGUMENTS;
+ }
+ return Stream::analyzeStatus("set_volume",
+ mStream->set_volume(mStream, left, right));
}
Return<void> StreamOut::prepareForWriting(uint32_t frameSize,