Merge changes from topics "fix-b-133526565-setters-getters", "fix-b-133526565-setters-getters-2"

* changes:
  audio: Add playback rate parameters to IStreamOut
  audio: Add Dual Mono Mode and Audio Description Mix Level to IStreamOut
This commit is contained in:
Andy Hung 2020-02-21 23:37:33 +00:00 committed by Android (Google) Code Review
commit 6f3fdba631
7 changed files with 325 additions and 15 deletions

View file

@ -276,4 +276,90 @@ interface IStreamOut extends IStream {
*/
selectPresentation(int32_t presentationId, int32_t programId)
generates (Result retval);
/**
* Returns the Dual Mono mode presentation setting.
*
* Optional method
*
* @return retval operation completion status.
* @return mode current setting of Dual Mono mode.
*/
getDualMonoMode() generates (Result retval, DualMonoMode mode);
/**
* Sets the Dual Mono mode presentation on the output device.
*
* The Dual Mono mode is generally applied to stereo audio streams
* where the left and right channels come from separate sources.
*
* Optional method
*
* @param mode selected Dual Mono mode.
* @return retval operation completion status.
*/
setDualMonoMode(DualMonoMode mode) generates (Result retval);
/**
* Returns the Audio Description Mix level in dB.
*
* The level is applied to streams incorporating a secondary Audio
* Description stream. It specifies the relative level of mixing for
* the Audio Description with a reference to the Main Audio.
*
* Optional method
*
* The value of the relative level is in the range from negative infinity
* to +48.
*
* @return retval operation completion status.
* @return leveldB the current Audio Description Mix Level in dB.
*/
getAudioDescriptionMixLevel() generates (Result retval, float leveldB);
/**
* Sets the Audio Description Mix level in dB.
*
* For streams incorporating a secondary Audio Description stream
* the relative level of mixing of the Audio Description to the Main Audio
* is controlled by this method.
*
* Optional method
*
* The value of the relative level must be in the range from negative
* infinity to +48.
*
* @param leveldB Audio Description Mix Level in dB
* @return retval operation completion status.
*/
setAudioDescriptionMixLevel(float leveldB) generates (Result retval);
/**
* Retrieves current playback rate parameters.
*
* Optional method
*
* @return retval operation completion status.
* @return playbackRate current playback parameters
*/
getPlaybackRateParameters()
generates (Result retval, PlaybackRate playbackRate);
/**
* Sets the playback rate parameters that control playback behavior.
* This is normally used when playing encoded content and decoding
* is performed in hardware. Otherwise, the framework can apply
* necessary transformations.
*
* Optional method
*
* If the HAL supports setting the playback rate, it is recommended
* to support speed and pitch values at least in the range
* from 0.5f to 2.0f, inclusive (see the definition of PlaybackRate struct).
*
* @param playbackRate playback parameters
* @return retval operation completion status.
*/
setPlaybackRateParameters(PlaybackRate playbackRate)
generates (Result retval);
};

View file

@ -247,3 +247,111 @@ enum MicrophoneDirection : int32_t {
*/
EXTERNAL = 3,
};
/* Dual Mono handling is used when a stereo audio stream
* contains separate audio content on the left and right channels.
* Such information about the content of the stream may be found, for example,
* in ITU T-REC-J.94-201610 A.6.2.3 Component descriptor.
*/
@export(name="audio_dual_mono_mode_t", value_prefix="AUDIO_DUAL_MONO_MODE_")
enum DualMonoMode : int32_t {
// Need to be in sync with DUAL_MONO_MODE* constants in
// frameworks/base/media/java/android/media/AudioTrack.java
/**
* Disable any Dual Mono presentation effect.
*
*/
OFF = 0,
/**
* This mode indicates that a stereo stream should be presented
* with the left and right audio channels blended together
* and delivered to both channels.
*
* Behavior for non-stereo streams is implementation defined.
* A suggested guideline is that the left-right stereo symmetric
* channels are pairwise blended, the other channels such as center
* are left alone.
*/
LR = 1,
/**
* This mode indicates that a stereo stream should be presented
* with the left audio channel replicated into the right audio channel.
*
* Behavior for non-stereo streams is implementation defined.
* A suggested guideline is that all channels with left-right
* stereo symmetry will have the left channel position replicated
* into the right channel position. The center channels (with no
* left/right symmetry) or unbalanced channels are left alone.
*/
LL = 2,
/**
* This mode indicates that a stereo stream should be presented
* with the right audio channel replicated into the left audio channel.
*
* Behavior for non-stereo streams is implementation defined.
* A suggested guideline is that all channels with left-right
* stereo symmetry will have the right channel position replicated
* into the left channel position. The center channels (with no
* left/right symmetry) or unbalanced channels are left alone.
*/
RR = 3,
};
/**
* Algorithms used for timestretching (preserving pitch while playing audio
* content at different speed).
*/
@export(name="audio_timestretch_stretch_mode_t", value_prefix="AUDIO_TIMESTRETCH_STRETCH_")
enum TimestretchMode : int32_t {
// Need to be in sync with AUDIO_STRETCH_MODE_* constants in
// frameworks/base/media/java/android/media/PlaybackParams.java
DEFAULT = 0,
/** Selects timestretch algorithm best suitable for voice (speech) content. */
VOICE = 1,
};
/**
* Behavior when the values for speed and / or pitch are out
* of applicable range.
*/
@export(name="audio_timestretch_fallback_mode_t", value_prefix="AUDIO_TIMESTRETCH_FALLBACK_")
enum TimestretchFallbackMode : int32_t {
// Need to be in sync with AUDIO_FALLBACK_MODE_* constants in
// frameworks/base/media/java/android/media/PlaybackParams.java
/** Play silence for parameter values that are out of range. */
MUTE = 1,
/** Return an error while trying to set the parameters. */
FAIL = 2,
};
/**
* Parameters determining playback behavior. They are used to speed up or
* slow down playback and / or change the tonal frequency of the audio content
* (pitch).
*/
struct PlaybackRate {
/**
* Speed factor (multiplier). Normal speed has the value of 1.0f.
* Values less than 1.0f slow down playback, value greater than 1.0f
* speed it up.
*/
float speed;
/**
* Pitch factor (multiplier). Setting pitch value to 1.0f together
* with changing playback speed preserves the pitch, this is often
* called "timestretching." Setting the pitch value equal to speed produces
* the same effect as playing audio content at different sampling rate.
*/
float pitch;
/**
* Selects the algorithm used for timestretching (preserving pitch while
* playing audio at different speed).
*/
TimestretchMode timestretchMode;
/**
* Selects the behavior when the specified values for speed and / or pitch
* are out of applicable range.
*/
TimestretchFallbackMode fallbackMode;
};

View file

@ -582,6 +582,38 @@ Return<Result> StreamOut::selectPresentation(int32_t /*presentationId*/, int32_t
}
#endif
#if MAJOR_VERSION >= 6
Return<void> StreamOut::getDualMonoMode(getDualMonoMode_cb _hidl_cb) {
_hidl_cb(Result::NOT_SUPPORTED, DualMonoMode::OFF);
return Void();
}
Return<Result> StreamOut::setDualMonoMode(DualMonoMode /*mode*/) {
return Result::NOT_SUPPORTED;
}
Return<void> StreamOut::getAudioDescriptionMixLevel(getAudioDescriptionMixLevel_cb _hidl_cb) {
_hidl_cb(Result::NOT_SUPPORTED, -std::numeric_limits<float>::infinity());
return Void();
}
Return<Result> StreamOut::setAudioDescriptionMixLevel(float /*leveldB*/) {
return Result::NOT_SUPPORTED;
}
Return<void> StreamOut::getPlaybackRateParameters(getPlaybackRateParameters_cb _hidl_cb) {
_hidl_cb(Result::NOT_SUPPORTED,
// Same as AUDIO_PLAYBACK_RATE_INITIALIZER
PlaybackRate{1.0f, 1.0f, TimestretchMode::DEFAULT, TimestretchFallbackMode::FAIL});
return Void();
}
Return<Result> StreamOut::setPlaybackRateParameters(const PlaybackRate& /*playbackRate*/) {
return Result::NOT_SUPPORTED;
}
#endif
} // namespace implementation
} // namespace CPP_VERSION
} // namespace audio

View file

@ -121,6 +121,14 @@ struct StreamOut : public IStreamOut {
Return<void> updateSourceMetadata(const SourceMetadata& sourceMetadata) override;
Return<Result> selectPresentation(int32_t presentationId, int32_t programId) override;
#endif
#if MAJOR_VERSION >= 6
Return<void> getDualMonoMode(getDualMonoMode_cb _hidl_cb) override;
Return<Result> setDualMonoMode(DualMonoMode mode) override;
Return<void> getAudioDescriptionMixLevel(getAudioDescriptionMixLevel_cb _hidl_cb) override;
Return<Result> setAudioDescriptionMixLevel(float leveldB) override;
Return<void> getPlaybackRateParameters(getPlaybackRateParameters_cb _hidl_cb) override;
Return<Result> setPlaybackRateParameters(const PlaybackRate& playbackRate) override;
#endif
static Result getPresentationPositionImpl(audio_stream_out_t* stream, uint64_t* frames,
TimeSpec* timeStamp);

View file

@ -190,3 +190,64 @@ TEST_P(AudioPatchHidlTest, UpdatePatchInvalidHandle) {
hidl_vec<AudioPortConfig>(), hidl_vec<AudioPortConfig>(), returnIn(res, ignored)));
ASSERT_RESULT(Result::INVALID_ARGUMENTS, res);
}
using DualMonoModeAccessorHidlTest = AccessorHidlTest<DualMonoMode, OutputStreamTest>;
TEST_P(DualMonoModeAccessorHidlTest, DualMonoModeTest) {
doc::test("Check that dual mono mode can be set and retrieved");
testAccessors<OPTIONAL>(&OutputStreamTest::getStream, "dual mono mode",
Initial{DualMonoMode::OFF},
{DualMonoMode::LR, DualMonoMode::LL, DualMonoMode::RR},
&IStreamOut::setDualMonoMode, &IStreamOut::getDualMonoMode);
}
INSTANTIATE_TEST_CASE_P(DualMonoModeHidl, DualMonoModeAccessorHidlTest,
::testing::ValuesIn(getOutputDeviceConfigParameters()),
&DeviceConfigParameterToString);
using AudioDescriptionMixLevelHidlTest = AccessorHidlTest<float, OutputStreamTest>;
TEST_P(AudioDescriptionMixLevelHidlTest, AudioDescriptionMixLevelTest) {
doc::test("Check that audio description mix level can be set and retrieved");
testAccessors<OPTIONAL>(
&OutputStreamTest::getStream, "audio description mix level",
Initial{-std::numeric_limits<float>::infinity()}, {-48.0f, -1.0f, 0.0f, 1.0f, 48.0f},
&IStreamOut::setAudioDescriptionMixLevel, &IStreamOut::getAudioDescriptionMixLevel,
{48.5f, 1000.0f, std::numeric_limits<float>::infinity()});
}
INSTANTIATE_TEST_CASE_P(AudioDescriptionMixLevelHidl, AudioDescriptionMixLevelHidlTest,
::testing::ValuesIn(getOutputDeviceConfigParameters()),
&DeviceConfigParameterToString);
using PlaybackRateParametersHidlTest = AccessorHidlTest<PlaybackRate, OutputStreamTest>;
TEST_P(PlaybackRateParametersHidlTest, PlaybackRateParametersTest) {
doc::test("Check that playback rate parameters can be set and retrieved");
testAccessors<OPTIONAL>(
&OutputStreamTest::getStream, "playback rate parameters",
Initial{PlaybackRate{1.0f, 1.0f, TimestretchMode::DEFAULT,
TimestretchFallbackMode::FAIL}},
{// Speed and pitch values in the range from 0.5f to 2.0f must be supported
// (see the definition of IStreamOut::setPlaybackRateParameters).
PlaybackRate{1.0f, 1.0f, TimestretchMode::DEFAULT, TimestretchFallbackMode::MUTE},
PlaybackRate{2.0f, 2.0f, TimestretchMode::DEFAULT, TimestretchFallbackMode::MUTE},
PlaybackRate{0.5f, 0.5f, TimestretchMode::DEFAULT, TimestretchFallbackMode::MUTE},
// Gross speed / pitch values must not be rejected if the fallback mode is "mute"
PlaybackRate{1000.0f, 1000.0f, TimestretchMode::DEFAULT,
TimestretchFallbackMode::MUTE},
// Default speed / pitch values must not be rejected in "fail" fallback mode
PlaybackRate{1.0f, 1.0f, TimestretchMode::DEFAULT, TimestretchFallbackMode::FAIL},
// Same for "voice" mode
PlaybackRate{1.0f, 1.0f, TimestretchMode::VOICE, TimestretchFallbackMode::MUTE},
PlaybackRate{2.0f, 2.0f, TimestretchMode::VOICE, TimestretchFallbackMode::MUTE},
PlaybackRate{0.5f, 0.5f, TimestretchMode::VOICE, TimestretchFallbackMode::MUTE},
PlaybackRate{1000.0f, 1000.0f, TimestretchMode::VOICE, TimestretchFallbackMode::MUTE},
PlaybackRate{1.0f, 1.0f, TimestretchMode::VOICE, TimestretchFallbackMode::FAIL}},
&IStreamOut::setPlaybackRateParameters, &IStreamOut::getPlaybackRateParameters,
{PlaybackRate{1000.0f, 1000.0f, TimestretchMode::DEFAULT,
TimestretchFallbackMode::FAIL},
PlaybackRate{1000.0f, 1000.0f, TimestretchMode::VOICE,
TimestretchFallbackMode::FAIL}});
}
INSTANTIATE_TEST_CASE_P(PlaybackRateParametersHidl, PlaybackRateParametersHidlTest,
::testing::ValuesIn(getOutputDeviceConfigParameters()),
&DeviceConfigParameterToString);

View file

@ -140,6 +140,11 @@ using HidlTestBase = ::testing::Test;
class HidlTest : public HidlTestBase {
public:
virtual ~HidlTest() = default;
// public access to avoid annoyances when using this method in template classes
// derived from test classes
sp<IDevice> getDevice() const {
return DeviceManager::getInstance().get(getFactoryName(), getDeviceName());
}
protected:
// Factory and device name getters to be overridden in subclasses.
@ -149,9 +154,6 @@ class HidlTest : public HidlTestBase {
sp<IDevicesFactory> getDevicesFactory() const {
return DevicesFactoryManager::getInstance().get(getFactoryName());
}
sp<IDevice> getDevice() const {
return DeviceManager::getInstance().get(getFactoryName(), getDeviceName());
}
bool resetDevice() const {
return DeviceManager::getInstance().reset(getFactoryName(), getDeviceName());
}
@ -419,7 +421,8 @@ class AudioPrimaryHidlTest : public AudioHidlDeviceTest {
ASSERT_TRUE(getDevice() != nullptr);
}
protected:
// public access to avoid annoyances when using this method in template classes
// derived from test classes
sp<IPrimaryDevice> getDevice() const {
return DeviceManager::getInstance().getPrimary(getFactoryName());
}
@ -450,15 +453,15 @@ class AccessorHidlTest : public BaseTestClass {
/** Test a property getter and setter.
* The getter and/or the setter may return NOT_SUPPORTED if optionality == OPTIONAL.
*/
template <Optionality optionality = REQUIRED, class Getter, class Setter>
void testAccessors(const string& propertyName, const Initial expectedInitial,
list<Property> valuesToTest, Setter setter, Getter getter,
const vector<Property>& invalidValues = {}) {
template <Optionality optionality = REQUIRED, class IUTGetter, class Getter, class Setter>
void testAccessors(IUTGetter iutGetter, const string& propertyName,
const Initial expectedInitial, list<Property> valuesToTest, Setter setter,
Getter getter, const vector<Property>& invalidValues = {}) {
const auto expectedResults = {Result::OK,
optionality == OPTIONAL ? Result::NOT_SUPPORTED : Result::OK};
Property initialValue = expectedInitial.value;
ASSERT_OK((BaseTestClass::getDevice().get()->*getter)(returnIn(res, initialValue)));
ASSERT_OK(((this->*iutGetter)().get()->*getter)(returnIn(res, initialValue)));
ASSERT_RESULT(expectedResults, res);
if (res == Result::OK && expectedInitial.check == REQUIRED) {
EXPECT_EQ(expectedInitial.value, initialValue);
@ -469,7 +472,7 @@ class AccessorHidlTest : public BaseTestClass {
for (Property setValue : valuesToTest) {
SCOPED_TRACE("Test " + propertyName + " getter and setter for " +
testing::PrintToString(setValue));
auto ret = (BaseTestClass::getDevice().get()->*setter)(setValue);
auto ret = ((this->*iutGetter)().get()->*setter)(setValue);
ASSERT_RESULT(expectedResults, ret);
if (ret == Result::NOT_SUPPORTED) {
doc::partialTest(propertyName + " setter is not supported");
@ -477,7 +480,7 @@ class AccessorHidlTest : public BaseTestClass {
}
Property getValue;
// Make sure the getter returns the same value just set
ASSERT_OK((BaseTestClass::getDevice().get()->*getter)(returnIn(res, getValue)));
ASSERT_OK(((this->*iutGetter)().get()->*getter)(returnIn(res, getValue)));
ASSERT_RESULT(expectedResults, res);
if (res == Result::NOT_SUPPORTED) {
doc::partialTest(propertyName + " getter is not supported");
@ -490,11 +493,18 @@ class AccessorHidlTest : public BaseTestClass {
SCOPED_TRACE("Try to set " + propertyName + " with the invalid value " +
testing::PrintToString(invalidValue));
EXPECT_RESULT(invalidArgsOrNotSupported,
(BaseTestClass::getDevice().get()->*setter)(invalidValue));
((this->*iutGetter)().get()->*setter)(invalidValue));
}
// Restore initial value
EXPECT_RESULT(expectedResults, (BaseTestClass::getDevice().get()->*setter)(initialValue));
EXPECT_RESULT(expectedResults, ((this->*iutGetter)().get()->*setter)(initialValue));
}
template <Optionality optionality = REQUIRED, class Getter, class Setter>
void testAccessors(const string& propertyName, const Initial expectedInitial,
list<Property> valuesToTest, Setter setter, Getter getter,
const vector<Property>& invalidValues = {}) {
testAccessors<optionality>(&BaseTestClass::getDevice, propertyName, expectedInitial,
valuesToTest, setter, getter, invalidValues);
}
};
@ -872,6 +882,11 @@ class StreamHelper {
template <class Stream>
class OpenStreamTest : public AudioHidlTestWithDeviceConfigParameter {
public:
// public access to avoid annoyances when using this method in template classes
// derived from test classes
sp<Stream> getStream() const { return stream; }
protected:
OpenStreamTest() : AudioHidlTestWithDeviceConfigParameter(), helper(stream) {}
template <class Open>

View file

@ -605,13 +605,13 @@ ff5dd821c2c7a9c78607159c4d788960b725487263c49d956ca5fa3d37008b45 android.hardwar
5751f230e86a36111e7c5b995577cbf89d8df76c8e6c7641199198f3db3a93f7 android.hardware.wifi@1.3::IWifiStaIface
# HALs released in Android R
e966a3437d6a98d9d9e14e9d672088771716031900c0deb55a0946c751a03a44 android.hardware.audio@6.0::types
822369cf4dc16a6f6b9622bcf86cbdc0b692dc82193fc15e967767175cbfdd8f android.hardware.audio@6.0::types
7241bd4596a927cd46d4b82f5e29e2cbe57f194aa1b25555f1d1d352e8b15c61 android.hardware.audio@6.0::IDevice
2402876cbc23c0de3690a665eca84fd3857d1808dba5cad25ce272f81ecef8c9 android.hardware.audio@6.0::IDevicesFactory
bca5379d5065e2e08b6ad7308ffc8a71a972fc0698bec678ea32eea786d01cb5 android.hardware.audio@6.0::IPrimaryDevice
fd1f1b29f26b42e886220f04a08086c00e5ade9d7b53f095438e578ab9d42a93 android.hardware.audio@6.0::IStream
2df5d5866b37776f25079c0e54b54350a2abe4e025a59c9e02a7d3abe8ca00e8 android.hardware.audio@6.0::IStreamIn
78e4138cc8307c11fc777c3bd376e581ba4ba48196b05ca1d7cdfa515c87b48a android.hardware.audio@6.0::IStreamOut
e6cd2b7c1a86b6ca683c0224ffde3b73aa14f6487de9f46833e539d26d1b3b5c android.hardware.audio@6.0::IStreamOut
997fdaad7a9d17ee7e01feb7031a753e2365e72ad30b11d950e9183fabdf3844 android.hardware.audio@6.0::IStreamOutCallback
167ed5cfb7d91db2e2bf20f1320c1a9004eeb768e26f535e0f7db94a21867d21 android.hardware.audio.common@6.0::types
817930d58412d662cb45e641c50cb62c727e4a3e3ffe7029a53cad9677b97d58 android.hardware.audio.effect@6.0::types