diff options
author | Sorin Basca <sorinbasca@google.com> | 2021-08-25 14:15:58 +0000 |
---|---|---|
committer | Sorin Basca <sorinbasca@google.com> | 2021-08-25 14:15:58 +0000 |
commit | c8b26fbb92e813ad7d986a58e8ce3ffe44a48428 (patch) | |
tree | 40ca482a8b0a9a72ebd71ed30d6b25f2831514e4 /audio | |
parent | 476010820e788ee87d66c088f93a55ab6a97a755 (diff) | |
download | device_generic_goldfish-c8b26fbb92e813ad7d986a58e8ce3ffe44a48428.tar.gz device_generic_goldfish-c8b26fbb92e813ad7d986a58e8ce3ffe44a48428.tar.bz2 device_generic_goldfish-c8b26fbb92e813ad7d986a58e8ce3ffe44a48428.zip |
Revert "Update the audio HAL to @7"
Revert "Upgrade audio and audio.effect HALs"
Revert submission 1804916-emulator-audio7
Reason for revert: Broken test (http://b/197715978)
Reverted Changes:
I92675c2ec:Update the audio HAL to @7
If878215f7:Upgrade audio and audio.effect HALs
Change-Id: I856ca03bdf86efd993b077186a05e924fd5e70b0
Diffstat (limited to 'audio')
31 files changed, 382 insertions, 419 deletions
diff --git a/audio/Android.bp b/audio/Android.bp index cdbf7e8a..e7c8f764 100644 --- a/audio/Android.bp +++ b/audio/Android.bp @@ -31,16 +31,16 @@ license { } cc_library_shared { - name: "android.hardware.audio.legacy@7.0-impl.ranchu", - defaults: ["android.hardware.audio@7.0-impl_default"], + name: "android.hardware.audio.legacy@6.0-impl.ranchu", + defaults: ["android.hardware.audio@6.0-impl_default"], relative_install_path: "hw", vendor: true, } cc_library_shared { - name: "android.hardware.audio@7.0-impl.ranchu", + name: "android.hardware.audio@6.0-impl.ranchu", vendor: true, - vintf_fragments: ["android.hardware.audio@7.0-impl.ranchu.xml"], + vintf_fragments: ["android.hardware.audio@6.0-impl.ranchu.xml"], relative_install_path: "hw", defaults: ["hidl_defaults"], srcs: [ @@ -59,10 +59,9 @@ cc_library_shared { "util.cpp", ], shared_libs: [ - "android.hardware.audio@7.0", - "android.hardware.audio.common@7.0", - "android.hardware.audio.common@7.0-enums", - "android.hardware.audio.common@7.0-util", + "android.hardware.audio@6.0", + "android.hardware.audio.common@6.0", + "android.hardware.audio.common@6.0-util", "libaudioutils", "libbase", "libcutils", @@ -77,13 +76,13 @@ cc_library_shared { "libaudio_system_headers", ], cflags: [ - "-DLOG_TAG=\"android.hardware.audio@7.0-impl.ranchu\"", + "-DLOG_TAG=\"android.hardware.audio@6.0-impl.ranchu\"", ], - // a.h.audio@X.0-impl.ranchu (see above) loads a.h.audio.legacy@X.0-impl + // a.h.audio@6.0-impl.ranchu (see above) loads a.h.audio.legacy@6.0-impl // which loads audio.r_submix.default which provides the r_submix device, // see b/161485545. Should be retired once a better r_submix is available. required: [ - "android.hardware.audio.legacy@7.0-impl.ranchu", + "android.hardware.audio.legacy@6.0-impl.ranchu", "audio.r_submix.default", ], } diff --git a/audio/android.hardware.audio@7.0-impl.ranchu.xml b/audio/android.hardware.audio@6.0-impl.ranchu.xml index 8e224b1e..b0a2aaaa 100644 --- a/audio/android.hardware.audio@7.0-impl.ranchu.xml +++ b/audio/android.hardware.audio@6.0-impl.ranchu.xml @@ -2,7 +2,7 @@ <hal format="hidl"> <name>android.hardware.audio</name> <transport>hwbinder</transport> - <version>7.0</version> + <version>6.0</version> <interface> <name>IDevicesFactory</name> <instance>default</instance> diff --git a/audio/audio_ops.cpp b/audio/audio_ops.cpp index cdbd2d03..088c9349 100644 --- a/audio/audio_ops.cpp +++ b/audio/audio_ops.cpp @@ -21,7 +21,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { namespace aops { @@ -73,7 +73,7 @@ l1: STEP; } // namespace aops } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/audio_ops.h b/audio/audio_ops.h index eeb5b6ee..3822a139 100644 --- a/audio/audio_ops.h +++ b/audio/audio_ops.h @@ -20,7 +20,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { namespace aops { @@ -28,7 +28,7 @@ void multiplyByVolume(float volume, int16_t *a, size_t n); } // namespace aops } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/device_factory.cpp b/audio/device_factory.cpp index c1355fb7..d399b5ba 100644 --- a/audio/device_factory.cpp +++ b/audio/device_factory.cpp @@ -23,7 +23,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { using ::android::hardware::Void; @@ -36,7 +36,7 @@ using ::android::hardware::Void; DevicesFactory::DevicesFactory() { mLegacyLib.reset(dlopen( - LIB_PATH_PREFIX "android.hardware.audio.legacy@7.0-impl.ranchu.so", RTLD_NOW)); + LIB_PATH_PREFIX "android.hardware.audio.legacy@6.0-impl.ranchu.so", RTLD_NOW)); LOG_ALWAYS_FATAL_IF(!mLegacyLib); typedef IDevicesFactory *(*Func)(const char *); @@ -65,7 +65,7 @@ Return<void> DevicesFactory::openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) { } } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/device_factory.h b/audio/device_factory.h index d1b8009b..cc33be5a 100644 --- a/audio/device_factory.h +++ b/audio/device_factory.h @@ -16,19 +16,19 @@ #pragma once #include <memory> -#include <android/hardware/audio/7.0/IDevicesFactory.h> +#include <android/hardware/audio/6.0/IDevicesFactory.h> #include <dlfcn.h> namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { using ::android::sp; using ::android::hardware::hidl_string; using ::android::hardware::Return; -using namespace ::android::hardware::audio::V7_0; +using namespace ::android::hardware::audio::V6_0; struct DevicesFactory : public IDevicesFactory { DevicesFactory(); @@ -48,7 +48,7 @@ private: }; } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/device_port_sink.cpp b/audio/device_port_sink.cpp index 7139ae76..3c4de41c 100644 --- a/audio/device_port_sink.cpp +++ b/audio/device_port_sink.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include <android_audio_policy_configuration_V7_0-enums.h> #include <chrono> #include <thread> #include <log/log.h> @@ -27,14 +26,10 @@ #include "util.h" #include "debug.h" -namespace xsd { -using namespace ::android::audio::policy::configuration::V7_0; -} - namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { namespace { @@ -46,15 +41,15 @@ struct TinyalsaSink : public DevicePortSink { const AudioConfig &cfg, uint64_t &frames) : mStartNs(systemTime(SYSTEM_TIME_MONOTONIC)) - , mSampleRateHz(cfg.base.sampleRateHz) - , mFrameSize(util::countChannels(cfg.base.channelMask) * sizeof(int16_t)) + , mSampleRateHz(cfg.sampleRateHz) + , mFrameSize(util::countChannels(cfg.channelMask) * sizeof(int16_t)) , mWriteSizeFrames(cfg.frameCount) , mFrames(frames) , mRingBuffer(mFrameSize * cfg.frameCount * 3) , mMixer(pcmCard) , mPcm(talsa::pcmOpen(pcmCard, pcmDevice, - util::countChannels(cfg.base.channelMask), - cfg.base.sampleRateHz, + util::countChannels(cfg.channelMask), + cfg.sampleRateHz, cfg.frameCount, true /* isOut */)) { mConsumeThread = std::thread(&TinyalsaSink::consumeThread, this); @@ -217,8 +212,8 @@ private: struct NullSink : public DevicePortSink { NullSink(const AudioConfig &cfg, uint64_t &frames) : mFrames(frames) - , mSampleRateHz(cfg.base.sampleRateHz) - , mNChannels(util::countChannels(cfg.base.channelMask)) + , mSampleRateHz(cfg.sampleRateHz) + , mNChannels(util::countChannels(cfg.channelMask)) , mTimestamp(systemTime(SYSTEM_TIME_MONOTONIC)) {} Result getPresentationPosition(uint64_t &frames, TimeSpec &ts) override { @@ -281,18 +276,17 @@ std::unique_ptr<DevicePortSink> DevicePortSink::create(size_t readerBufferSizeHint, const DeviceAddress &address, const AudioConfig &cfg, - const hidl_vec<AudioInOutFlag> &flags, + const hidl_bitfield<AudioOutputFlag> &flags, uint64_t &frames) { (void)flags; - if (xsd::stringToAudioFormat(cfg.base.format) != xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT) { - ALOGE("%s:%d, unexpected format: %s", __func__, __LINE__, cfg.base.format.c_str()); + if (cfg.format != AudioFormat::PCM_16_BIT) { + ALOGE("%s:%d Only PCM_16_BIT is supported", __func__, __LINE__); return FAILURE(nullptr); } - switch (xsd::stringToAudioDevice(address.deviceType)) { - case xsd::AudioDevice::AUDIO_DEVICE_OUT_DEFAULT: - case xsd::AudioDevice::AUDIO_DEVICE_OUT_SPEAKER: + switch (address.device) { + case AudioDevice::OUT_SPEAKER: { auto sinkptr = TinyalsaSink::create(talsa::kPcmCard, talsa::kPcmDevice, cfg, readerBufferSizeHint, frames); if (sinkptr == nullptr) { @@ -303,32 +297,17 @@ DevicePortSink::create(size_t readerBufferSizeHint, } } - case xsd::AudioDevice::AUDIO_DEVICE_OUT_TELEPHONY_TX: + case AudioDevice::OUT_TELEPHONY_TX: return NullSink::create(cfg, readerBufferSizeHint, frames); default: - ALOGW("%s:%d unsupported device: %s", __func__, __LINE__, address.deviceType.c_str()); + ALOGW("%s:%d unsupported device: %x created nullsink", __func__, __LINE__, address.device); return NullSink::create(cfg, readerBufferSizeHint, frames); } } -bool DevicePortSink::validateDeviceAddress(const DeviceAddress& address) { - switch (xsd::stringToAudioDevice(address.deviceType)) { - default: - ALOGW("%s:%d unsupported device: %s", __func__, __LINE__, address.deviceType.c_str()); - return FAILURE(false); - - case xsd::AudioDevice::AUDIO_DEVICE_OUT_DEFAULT: - case xsd::AudioDevice::AUDIO_DEVICE_OUT_SPEAKER: - case xsd::AudioDevice::AUDIO_DEVICE_OUT_TELEPHONY_TX: - break; - } - - return true; -} - } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/device_port_sink.h b/audio/device_port_sink.h index c8451954..5159b509 100644 --- a/audio/device_port_sink.h +++ b/audio/device_port_sink.h @@ -16,18 +16,18 @@ #pragma once #include <memory> -#include <android/hardware/audio/common/7.0/types.h> -#include <android/hardware/audio/7.0/types.h> +#include <android/hardware/audio/common/6.0/types.h> +#include <android/hardware/audio/6.0/types.h> #include "ireader.h" namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { -using namespace ::android::hardware::audio::common::V7_0; -using namespace ::android::hardware::audio::V7_0; +using namespace ::android::hardware::audio::common::V6_0; +using namespace ::android::hardware::audio::V6_0; struct DevicePortSink { virtual ~DevicePortSink() {} @@ -37,14 +37,12 @@ struct DevicePortSink { static std::unique_ptr<DevicePortSink> create(size_t readerBufferSizeHint, const DeviceAddress &, const AudioConfig &, - const hidl_vec<AudioInOutFlag> &, + const hidl_bitfield<AudioOutputFlag> &, uint64_t &frames); - - static bool validateDeviceAddress(const DeviceAddress &); }; } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/device_port_source.cpp b/audio/device_port_source.cpp index cf7f0bb9..3bdb766a 100644 --- a/audio/device_port_source.cpp +++ b/audio/device_port_source.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include <android_audio_policy_configuration_V7_0-enums.h> #include <cmath> #include <chrono> #include <thread> @@ -31,14 +30,10 @@ #include "util.h" #include "debug.h" -namespace xsd { -using namespace ::android::audio::policy::configuration::V7_0; -} - namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { namespace { @@ -49,15 +44,15 @@ struct TinyalsaSource : public DevicePortSource { TinyalsaSource(unsigned pcmCard, unsigned pcmDevice, const AudioConfig &cfg, uint64_t &frames) : mStartNs(systemTime(SYSTEM_TIME_MONOTONIC)) - , mSampleRateHz(cfg.base.sampleRateHz) - , mFrameSize(util::countChannels(cfg.base.channelMask) * sizeof(int16_t)) + , mSampleRateHz(cfg.sampleRateHz) + , mFrameSize(util::countChannels(cfg.channelMask) * sizeof(int16_t)) , mReadSizeFrames(cfg.frameCount) , mFrames(frames) , mRingBuffer(mFrameSize * cfg.frameCount * 3) , mMixer(pcmCard) , mPcm(talsa::pcmOpen(pcmCard, pcmDevice, - util::countChannels(cfg.base.channelMask), - cfg.base.sampleRateHz, + util::countChannels(cfg.channelMask), + cfg.sampleRateHz, cfg.frameCount, false /* isOut */)) { mProduceThread = std::thread(&TinyalsaSource::producerThread, this); @@ -223,8 +218,8 @@ template <class G> struct GeneratedSource : public DevicePortSource { : mWriteBuffer(writerBufferSizeHint / sizeof(int16_t)) , mFrames(frames) , mStartNs(systemTime(SYSTEM_TIME_MONOTONIC)) - , mSampleRateHz(cfg.base.sampleRateHz) - , mNChannels(util::countChannels(cfg.base.channelMask)) + , mSampleRateHz(cfg.sampleRateHz) + , mNChannels(util::countChannels(cfg.channelMask)) , mGenerator(std::move(generator)) {} Result getCapturePosition(uint64_t &frames, uint64_t &time) override { @@ -403,55 +398,37 @@ std::unique_ptr<DevicePortSource> DevicePortSource::create(size_t writerBufferSizeHint, const DeviceAddress &address, const AudioConfig &cfg, - const hidl_vec<AudioInOutFlag> &flags, + const hidl_bitfield<AudioOutputFlag> &flags, uint64_t &frames) { (void)flags; - if (xsd::stringToAudioFormat(cfg.base.format) != xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT) { - ALOGE("%s:%d, unexpected format: %s", __func__, __LINE__, cfg.base.format.c_str()); + if (cfg.format != AudioFormat::PCM_16_BIT) { + ALOGE("%s:%d Only PCM_16_BIT is supported", __func__, __LINE__); return FAILURE(nullptr); } - switch (xsd::stringToAudioDevice(address.deviceType)) { - case xsd::AudioDevice::AUDIO_DEVICE_IN_DEFAULT: - case xsd::AudioDevice::AUDIO_DEVICE_IN_BUILTIN_MIC: + switch (address.device) { + case AudioDevice::IN_BUILTIN_MIC: return TinyalsaSource::create(talsa::kPcmCard, talsa::kPcmDevice, cfg, writerBufferSizeHint, frames); - case xsd::AudioDevice::AUDIO_DEVICE_IN_TELEPHONY_RX: + case AudioDevice::IN_TELEPHONY_RX: return createGeneratedSource(cfg, writerBufferSizeHint, frames, - BusySignalGenerator(cfg.base.sampleRateHz)); + BusySignalGenerator(cfg.sampleRateHz)); - case xsd::AudioDevice::AUDIO_DEVICE_IN_FM_TUNER: + case AudioDevice::IN_FM_TUNER: return createGeneratedSource( cfg, writerBufferSizeHint, frames, - RepeatGenerator(generateSinePattern(cfg.base.sampleRateHz, 440.0, 1.0))); + RepeatGenerator(generateSinePattern(cfg.sampleRateHz, 440.0, 1.0))); default: - ALOGW("%s:%d unsupported device: %s", __func__, __LINE__, address.deviceType.c_str()); + ALOGE("%s:%d unsupported device: %x", __func__, __LINE__, address.device); return FAILURE(nullptr); } } - -bool DevicePortSource::validateDeviceAddress(const DeviceAddress& address) { - switch (xsd::stringToAudioDevice(address.deviceType)) { - default: - ALOGW("%s:%d unsupported device: %s", __func__, __LINE__, address.deviceType.c_str()); - return FAILURE(false); - - case xsd::AudioDevice::AUDIO_DEVICE_IN_DEFAULT: - case xsd::AudioDevice::AUDIO_DEVICE_IN_BUILTIN_MIC: - case xsd::AudioDevice::AUDIO_DEVICE_IN_TELEPHONY_RX: - case xsd::AudioDevice::AUDIO_DEVICE_IN_FM_TUNER: - break; - } - - return true; -} - } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/device_port_source.h b/audio/device_port_source.h index 7f61757b..16b5d27c 100644 --- a/audio/device_port_source.h +++ b/audio/device_port_source.h @@ -16,18 +16,18 @@ #pragma once #include <memory> -#include <android/hardware/audio/common/7.0/types.h> -#include <android/hardware/audio/7.0/types.h> +#include <android/hardware/audio/common/6.0/types.h> +#include <android/hardware/audio/6.0/types.h> #include "iwriter.h" namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { -using namespace ::android::hardware::audio::common::V7_0; -using namespace ::android::hardware::audio::V7_0; +using namespace ::android::hardware::audio::common::V6_0; +using namespace ::android::hardware::audio::V6_0; struct DevicePortSource { virtual ~DevicePortSource() {} @@ -37,14 +37,12 @@ struct DevicePortSource { static std::unique_ptr<DevicePortSource> create(size_t writerBufferSizeHint, const DeviceAddress &, const AudioConfig &, - const hidl_vec<AudioInOutFlag> &, + const hidl_bitfield<AudioOutputFlag> &, uint64_t &frames); - - static bool validateDeviceAddress(const DeviceAddress &); }; } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/entry.cpp b/audio/entry.cpp index b5f58658..1d48f432 100644 --- a/audio/entry.cpp +++ b/audio/entry.cpp @@ -16,8 +16,8 @@ #include "device_factory.h" -using android::hardware::audio::V7_0::IDevicesFactory; -using android::hardware::audio::V7_0::implementation::DevicesFactory; +using android::hardware::audio::V6_0::IDevicesFactory; +using android::hardware::audio::V6_0::implementation::DevicesFactory; extern "C" IDevicesFactory* HIDL_FETCH_IDevicesFactory(const char* name) { (void)name; diff --git a/audio/io_thread.cpp b/audio/io_thread.cpp index 55e0d24c..b87c5e4c 100644 --- a/audio/io_thread.cpp +++ b/audio/io_thread.cpp @@ -20,7 +20,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { bool IOThread::notify(const uint32_t mask) { @@ -45,7 +45,7 @@ void IOThread::requestExit() { } } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/io_thread.h b/audio/io_thread.h index e0b09724..698df499 100644 --- a/audio/io_thread.h +++ b/audio/io_thread.h @@ -20,7 +20,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { struct IOThread { @@ -35,7 +35,7 @@ struct IOThread { }; } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/ireader.h b/audio/ireader.h index c30fbcd2..cb20e2b6 100644 --- a/audio/ireader.h +++ b/audio/ireader.h @@ -20,7 +20,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { struct IReader { @@ -29,7 +29,7 @@ struct IReader { }; } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/iwriter.h b/audio/iwriter.h index b03846e1..d204ab1e 100644 --- a/audio/iwriter.h +++ b/audio/iwriter.h @@ -20,7 +20,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { struct IWriter { @@ -29,7 +29,7 @@ struct IWriter { }; } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/policy/audio_policy_configuration.xml b/audio/policy/audio_policy_configuration.xml index 50c0c2f6..34e8aff5 100644 --- a/audio/policy/audio_policy_configuration.xml +++ b/audio/policy/audio_policy_configuration.xml @@ -14,7 +14,7 @@ limitations under the License. --> -<audioPolicyConfiguration version="7.0" xmlns:xi="http://www.w3.org/2001/XInclude"> +<audioPolicyConfiguration version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude"> <!-- version section contains a “version” tag in the form “major.minor” e.g version=”1.0” --> <!-- Global configuration Decalaration --> diff --git a/audio/policy/primary_audio_policy_configuration.xml b/audio/policy/primary_audio_policy_configuration.xml index ac4b2448..33a47d7f 100644 --- a/audio/policy/primary_audio_policy_configuration.xml +++ b/audio/policy/primary_audio_policy_configuration.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- Default Primary Audio HAL Module Audio Policy Configuration include file --> -<module name="primary" halVersion="3.0"> +<module name="primary" halVersion="2.0"> <attachedDevices> <item>Speaker</item> <item>Built-In Mic</item> @@ -21,16 +21,16 @@ <mixPort name="telephony_tx" role="source"> <profile name="" format="AUDIO_FORMAT_PCM_16_BIT" - samplingRates="44100" channelMasks="AUDIO_CHANNEL_OUT_MONO AUDIO_CHANNEL_OUT_STEREO"/> + samplingRates="44100" channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO"/> </mixPort> <mixPort name="telephony_rx" role="sink"> <profile name="" format="AUDIO_FORMAT_PCM_16_BIT" - samplingRates="44100" channelMasks="AUDIO_CHANNEL_IN_MONO AUDIO_CHANNEL_IN_STEREO"/> + samplingRates="44100" channelMasks="AUDIO_CHANNEL_IN_MONO,AUDIO_CHANNEL_IN_STEREO"/> </mixPort> <mixPort name="fm_tuner" role="sink"> <profile name="" format="AUDIO_FORMAT_PCM_16_BIT" - samplingRates="44100" channelMasks="AUDIO_CHANNEL_IN_MONO AUDIO_CHANNEL_IN_STEREO"/> + samplingRates="44100" channelMasks="AUDIO_CHANNEL_IN_MONO,AUDIO_CHANNEL_IN_STEREO"/> </mixPort> </mixPorts> <devicePorts> diff --git a/audio/primary_device.cpp b/audio/primary_device.cpp index a3fd6897..3ba4bf8f 100644 --- a/audio/primary_device.cpp +++ b/audio/primary_device.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include <android_audio_policy_configuration_V7_0-enums.h> #include <log/log.h> #include <system/audio.h> #include "primary_device.h" @@ -23,14 +22,10 @@ #include "util.h" #include "debug.h" -namespace xsd { -using namespace ::android::audio::policy::configuration::V7_0; -} - namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { constexpr size_t kInBufferDurationMs = 15; @@ -87,11 +82,12 @@ Return<void> PrimaryDevice::getInputBufferSize(const AudioConfig& config, if (util::checkAudioConfig(false, kInBufferDurationMs, config, suggestedConfig)) { const size_t sz = suggestedConfig.frameCount - * util::countChannels(suggestedConfig.base.channelMask) - * util::getBytesPerSample(suggestedConfig.base.format); + * util::countChannels(suggestedConfig.channelMask) + * util::getBytesPerSample(suggestedConfig.format); _hidl_cb(Result::OK, sz); } else { + ALOGE("PrimaryDevice::%s:%d failed", __func__, __LINE__); _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), 0); } @@ -101,22 +97,9 @@ Return<void> PrimaryDevice::getInputBufferSize(const AudioConfig& config, Return<void> PrimaryDevice::openOutputStream(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, - const hidl_vec<AudioInOutFlag>& flags, + hidl_bitfield<AudioOutputFlag> flags, const SourceMetadata& sourceMetadata, openOutputStream_cb _hidl_cb) { - if (!StreamOut::validateDeviceAddress(device)) { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}); - return Void(); - } - if (!StreamOut::validateFlags(flags)) { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}); - return Void(); - } - if (!StreamOut::validateSourceMetadata(sourceMetadata)) { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}); - return Void(); - } - AudioConfig suggestedConfig; if (util::checkAudioConfig(true, kOutBufferDurationMs, config, suggestedConfig)) { auto stream = std::make_unique<StreamOut>( @@ -129,9 +112,10 @@ Return<void> PrimaryDevice::openOutputStream(int32_t ioHandle, LOG_ALWAYS_FATAL_IF(!mOutputStreams.insert(stream.get()).second); } - _hidl_cb(Result::OK, stream.release(), suggestedConfig); + _hidl_cb(Result::OK, stream.release(), config); } else { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, suggestedConfig); + ALOGE("PrimaryDevice::%s:%d failed", __func__, __LINE__); + _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), nullptr, suggestedConfig); } return Void(); @@ -140,22 +124,9 @@ Return<void> PrimaryDevice::openOutputStream(int32_t ioHandle, Return<void> PrimaryDevice::openInputStream(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, - const hidl_vec<AudioInOutFlag>& flags, + hidl_bitfield<AudioInputFlag> flags, const SinkMetadata& sinkMetadata, openInputStream_cb _hidl_cb) { - if (!StreamIn::validateDeviceAddress(device)) { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}); - return Void(); - } - if (!StreamIn::validateFlags(flags)) { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}); - return Void(); - } - if (!StreamIn::validateSinkMetadata(sinkMetadata)) { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}); - return Void(); - } - AudioConfig suggestedConfig; if (util::checkAudioConfig(false, kInBufferDurationMs, config, suggestedConfig)) { auto stream = std::make_unique<StreamIn>( @@ -168,9 +139,10 @@ Return<void> PrimaryDevice::openInputStream(int32_t ioHandle, LOG_ALWAYS_FATAL_IF(!mInputStreams.insert(stream.get()).second); } - _hidl_cb(Result::OK, stream.release(), suggestedConfig); + _hidl_cb(Result::OK, stream.release(), config); } else { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, suggestedConfig); + ALOGE("PrimaryDevice::%s:%d failed", __func__, __LINE__); + _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), nullptr, suggestedConfig); } return Void(); @@ -413,7 +385,7 @@ void PrimaryDevice::updateInputStreamMicMute(bool micMute) const { } } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/primary_device.h b/audio/primary_device.h index 6af6a86a..2a956806 100644 --- a/audio/primary_device.h +++ b/audio/primary_device.h @@ -15,7 +15,7 @@ */ #pragma once -#include <android/hardware/audio/7.0/IPrimaryDevice.h> +#include <android/hardware/audio/6.0/IPrimaryDevice.h> #include <mutex> #include <unordered_map> #include <unordered_set> @@ -23,7 +23,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { using ::android::sp; @@ -32,8 +32,8 @@ using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; -using namespace ::android::hardware::audio::common::V7_0; -using namespace ::android::hardware::audio::V7_0; +using namespace ::android::hardware::audio::common::V6_0; +using namespace ::android::hardware::audio::V6_0; struct StreamIn; struct StreamOut; @@ -53,13 +53,13 @@ struct PrimaryDevice : public IPrimaryDevice { Return<void> openOutputStream(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, - const hidl_vec<AudioInOutFlag>& flags, + hidl_bitfield<AudioOutputFlag> flags, const SourceMetadata& sourceMetadata, openOutputStream_cb _hidl_cb) override; Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, - const hidl_vec<AudioInOutFlag>& flags, + hidl_bitfield<AudioInputFlag> flags, const SinkMetadata& sinkMetadata, openInputStream_cb _hidl_cb) override; Return<bool> supportsAudioPatches() override; @@ -129,7 +129,7 @@ private: }; } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/ring_buffer.cpp b/audio/ring_buffer.cpp index 8fb04043..b2cc8c4f 100644 --- a/audio/ring_buffer.cpp +++ b/audio/ring_buffer.cpp @@ -20,7 +20,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { RingBuffer::RingBuffer(size_t capacity) @@ -149,7 +149,7 @@ size_t RingBuffer::consume(const ContiniousLockedChunk &lock, size_t size) { } } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/ring_buffer.h b/audio/ring_buffer.h index 3c7d9953..41916779 100644 --- a/audio/ring_buffer.h +++ b/audio/ring_buffer.h @@ -25,7 +25,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { // A one-producer-one-consumer ring buffer. @@ -96,7 +96,7 @@ private: }; } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/stream_common.cpp b/audio/stream_common.cpp index 76c35997..6235f9a8 100644 --- a/audio/stream_common.cpp +++ b/audio/stream_common.cpp @@ -22,7 +22,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { using ::android::hardware::Void; @@ -30,16 +30,16 @@ using ::android::hardware::Void; StreamCommon::StreamCommon(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, - hidl_vec<AudioInOutFlag> flags) + hidl_bitfield<AudioInputFlag> flags) : m_ioHandle(ioHandle) , m_device(device) , m_config(config) - , m_flags(std::move(flags)) + , m_flags(flags) {} uint64_t StreamCommon::getFrameSize() const { - return util::countChannels(m_config.base.channelMask) - * util::getBytesPerSample(m_config.base.format); + return util::countChannels(m_config.channelMask) + * util::getBytesPerSample(m_config.format); } uint64_t StreamCommon::getFrameCount() const { @@ -51,21 +51,47 @@ uint64_t StreamCommon::getBufferSize() const { } uint32_t StreamCommon::getSampleRate() const { - return m_config.base.sampleRateHz; + return m_config.sampleRateHz; } -void StreamCommon::getSupportedProfiles(const IStream::getSupportedProfiles_cb &_hidl_cb) const { - AudioProfile profile; +void StreamCommon::getSupportedSampleRates(AudioFormat format, + IStream::getSupportedSampleRates_cb _hidl_cb) const { + if (m_config.format == format) { + _hidl_cb(Result::OK, {m_config.sampleRateHz}); + } else { + _hidl_cb(Result::OK, {}); + } +} + +Result StreamCommon::setSampleRate(uint32_t sampleRateHz) const { + (void)sampleRateHz; + return FAILURE(Result::NOT_SUPPORTED); +} + +hidl_bitfield<AudioChannelMask> StreamCommon::getChannelMask() const { + return m_config.channelMask; +} - profile.format = m_config.base.format; - profile.sampleRates = { m_config.base.sampleRateHz }; - profile.channelMasks = { m_config.base.channelMask }; +void StreamCommon::getSupportedChannelMasks(AudioFormat format, + IStream::getSupportedChannelMasks_cb _hidl_cb) const { + if (m_config.format == format) { + _hidl_cb(Result::OK, {m_config.channelMask}); + } else { + _hidl_cb(Result::OK, {}); + } +} - _hidl_cb(Result::OK, {profile}); +Result StreamCommon::setChannelMask(hidl_bitfield<AudioChannelMask> mask) const { + (void)mask; + return FAILURE(Result::NOT_SUPPORTED); } AudioFormat StreamCommon::getFormat() const { - return m_config.base.format; + return m_config.format; +} + +void StreamCommon::getSupportedFormats(IStream::getSupportedFormats_cb _hidl_cb) const { + _hidl_cb(Result::OK, {m_config.format}); } Result StreamCommon::setFormat(AudioFormat format) const { @@ -73,11 +99,11 @@ Result StreamCommon::setFormat(AudioFormat format) const { return FAILURE(Result::NOT_SUPPORTED); } -void StreamCommon::getAudioProperties(const IStream::getAudioProperties_cb &_hidl_cb) const { - _hidl_cb(Result::OK, m_config.base); +void StreamCommon::getAudioProperties(IStream::getAudioProperties_cb _hidl_cb) const { + _hidl_cb(m_config.sampleRateHz, m_config.channelMask, m_config.format); } -void StreamCommon::getDevices(const IStream::getDevices_cb &_hidl_cb) const { +void StreamCommon::getDevices(IStream::getDevices_cb _hidl_cb) const { _hidl_cb(Result::OK, {m_device}); } @@ -87,7 +113,7 @@ Result StreamCommon::setDevices(const hidl_vec<DeviceAddress>& devices) const { } } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/stream_common.h b/audio/stream_common.h index 2129e19b..ecacee13 100644 --- a/audio/stream_common.h +++ b/audio/stream_common.h @@ -15,46 +15,54 @@ */ #pragma once -#include <android/hardware/audio/7.0/IStream.h> +#include <android/hardware/audio/6.0/IStream.h> namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { using ::android::sp; +using ::android::hardware::hidl_bitfield; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; -using namespace ::android::hardware::audio::common::V7_0; -using namespace ::android::hardware::audio::V7_0; +using namespace ::android::hardware::audio::common::V6_0; +using namespace ::android::hardware::audio::V6_0; struct StreamCommon { StreamCommon(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, - hidl_vec<AudioInOutFlag> flags); + hidl_bitfield<AudioInputFlag> flags); uint64_t getFrameSize() const; uint64_t getFrameCount() const; uint64_t getBufferSize() const; uint32_t getSampleRate() const; - void getSupportedProfiles(const IStream::getSupportedProfiles_cb &_hidl_cb) const; + void getSupportedSampleRates(AudioFormat format, + IStream::getSupportedSampleRates_cb _hidl_cb) const; + Result setSampleRate(uint32_t sampleRateHz) const; + hidl_bitfield<AudioChannelMask> getChannelMask() const; + void getSupportedChannelMasks(AudioFormat format, + IStream::getSupportedChannelMasks_cb _hidl_cb) const; + Result setChannelMask(hidl_bitfield<AudioChannelMask> mask) const; AudioFormat getFormat() const; + void getSupportedFormats(IStream::getSupportedFormats_cb _hidl_cb) const; Result setFormat(AudioFormat format) const; - void getAudioProperties(const IStream::getAudioProperties_cb &_hidl_cb) const; - void getDevices(const IStream::getDevices_cb &_hidl_cb) const; + void getAudioProperties(IStream::getAudioProperties_cb _hidl_cb) const; + void getDevices(IStream::getDevices_cb _hidl_cb) const; Result setDevices(const hidl_vec<DeviceAddress>& devices) const; const int32_t m_ioHandle; const DeviceAddress m_device; const AudioConfig m_config; - const hidl_vec<AudioInOutFlag> m_flags; + const hidl_bitfield<AudioOutputFlag> m_flags; }; } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/stream_in.cpp b/audio/stream_in.cpp index 9afebbea..ee7bcfcd 100644 --- a/audio/stream_in.cpp +++ b/audio/stream_in.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include <android_audio_policy_configuration_V7_0-enums.h> #include <log/log.h> #include <fmq/EventFlag.h> #include <fmq/MessageQueue.h> @@ -30,14 +29,10 @@ #include "util.h" #include "debug.h" -namespace xsd { -using namespace ::android::audio::policy::configuration::V7_0; -} - namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { using ::android::hardware::Void; @@ -225,10 +220,10 @@ StreamIn::StreamIn(sp<PrimaryDevice> dev, int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, - hidl_vec<AudioInOutFlag> flags, + hidl_bitfield<AudioInputFlag> flags, const SinkMetadata& sinkMetadata) : mDev(std::move(dev)) - , mCommon(ioHandle, device, config, std::move(flags)) + , mCommon(ioHandle, device, config, flags) , mSinkMetadata(sinkMetadata) { } @@ -248,19 +243,50 @@ Return<uint64_t> StreamIn::getBufferSize() { return mCommon.getBufferSize(); } -Return<void> StreamIn::getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) { - mCommon.getSupportedProfiles(_hidl_cb); +Return<uint32_t> StreamIn::getSampleRate() { + return mCommon.getSampleRate(); +} + +Return<void> StreamIn::getSupportedSampleRates(AudioFormat format, + getSupportedSampleRates_cb _hidl_cb) { + mCommon.getSupportedSampleRates(format, _hidl_cb); return Void(); } -Return<void> StreamIn::getAudioProperties(getAudioProperties_cb _hidl_cb) { - mCommon.getAudioProperties(_hidl_cb); +Return<Result> StreamIn::setSampleRate(uint32_t sampleRateHz) { + return mCommon.setSampleRate(sampleRateHz); +} + +Return<hidl_bitfield<AudioChannelMask>> StreamIn::getChannelMask() { + return mCommon.getChannelMask(); +} + +Return<void> StreamIn::getSupportedChannelMasks(AudioFormat format, + IStream::getSupportedChannelMasks_cb _hidl_cb) { + mCommon.getSupportedChannelMasks(format, _hidl_cb); return Void(); } -Return<Result> StreamIn::setAudioProperties(const AudioConfigBaseOptional& config) { - (void)config; - return FAILURE(Result::NOT_SUPPORTED); +Return<Result> StreamIn::setChannelMask(hidl_bitfield<AudioChannelMask> mask) { + return mCommon.setChannelMask(mask); +} + +Return<AudioFormat> StreamIn::getFormat() { + return mCommon.getFormat(); +} + +Return<void> StreamIn::getSupportedFormats(getSupportedFormats_cb _hidl_cb) { + mCommon.getSupportedFormats(_hidl_cb); + return Void(); +} + +Return<Result> StreamIn::setFormat(AudioFormat format) { + return mCommon.setFormat(format); +} + +Return<void> StreamIn::getAudioProperties(getAudioProperties_cb _hidl_cb) { + mCommon.getAudioProperties(_hidl_cb); + return Void(); } Return<Result> StreamIn::addEffect(uint64_t effectId) { @@ -359,21 +385,21 @@ Return<Result> StreamIn::setGain(float gain) { return FAILURE(Result::NOT_SUPPORTED); } -Return<Result> StreamIn::updateSinkMetadata(const SinkMetadata& sinkMetadata) { +Return<void> StreamIn::updateSinkMetadata(const SinkMetadata& sinkMetadata) { (void)sinkMetadata; - return FAILURE(Result::NOT_SUPPORTED); + return Void(); } Return<void> StreamIn::prepareForReading(uint32_t frameSize, uint32_t framesCount, prepareForReading_cb _hidl_cb) { if (!frameSize || !framesCount || frameSize > 256 || framesCount > (1u << 20)) { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}, {}, -1); + _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}, {}, {}); return Void(); } if (mReadThread) { // INVALID_STATE if the method was already called. - _hidl_cb(FAILURE(Result::INVALID_STATE), {}, {}, {}, -1); + _hidl_cb(FAILURE(Result::INVALID_STATE), {}, {}, {}, {}); return Void(); } @@ -384,11 +410,11 @@ Return<void> StreamIn::prepareForReading(uint32_t frameSize, *(t->mCommandMQ.getDesc()), *(t->mDataMQ.getDesc()), *(t->mStatusMQ.getDesc()), - t->getTid().get()); + {.pid = getpid(), .tid = t->getTid().get()}); mReadThread = std::move(t); } else { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}, {}, -1); + _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}, {}, {}); } return Void(); @@ -420,28 +446,12 @@ Return<Result> StreamIn::setMicrophoneFieldDimension(float zoom) { void StreamIn::setMicMute(bool mute) { mEffectiveVolume = - (mute && (xsd::stringToAudioDevice(getDeviceAddress().deviceType) == - xsd::AudioDevice::AUDIO_DEVICE_IN_BUILTIN_MIC)) + (mute && (getDeviceAddress().device & AudioDevice::IN_BUILTIN_MIC)) ? 0.0f : 1.0f; } -bool StreamIn::validateDeviceAddress(const DeviceAddress& device) { - return DevicePortSource::validateDeviceAddress(device); -} - -bool StreamIn::validateFlags(const hidl_vec<AudioInOutFlag>& flags) { - return std::all_of(flags.begin(), flags.end(), [](const AudioInOutFlag& flag){ - return xsd::stringToAudioInOutFlag(flag) != xsd::AudioInOutFlag::UNKNOWN; - }); -} - -bool StreamIn::validateSinkMetadata(const SinkMetadata& sinkMetadata) { - (void)sinkMetadata; - return true; -} - } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/stream_in.h b/audio/stream_in.h index f7af5ac0..dfc38a65 100644 --- a/audio/stream_in.h +++ b/audio/stream_in.h @@ -15,8 +15,8 @@ */ #pragma once -#include <android/hardware/audio/7.0/IStreamIn.h> -#include <android/hardware/audio/7.0/IDevice.h> +#include <android/hardware/audio/6.0/IStreamIn.h> +#include <android/hardware/audio/6.0/IDevice.h> #include "stream_common.h" #include "io_thread.h" #include "primary_device.h" @@ -24,7 +24,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { using ::android::sp; @@ -32,15 +32,15 @@ using ::android::hardware::hidl_bitfield; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; -using namespace ::android::hardware::audio::common::V7_0; -using namespace ::android::hardware::audio::V7_0; +using namespace ::android::hardware::audio::common::V6_0; +using namespace ::android::hardware::audio::V6_0; struct StreamIn : public IStreamIn { StreamIn(sp<PrimaryDevice> dev, int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, - hidl_vec<AudioInOutFlag> flags, + hidl_bitfield<AudioInputFlag> flags, const SinkMetadata& sinkMetadata); ~StreamIn(); @@ -48,9 +48,16 @@ struct StreamIn : public IStreamIn { Return<uint64_t> getFrameSize() override; Return<uint64_t> getFrameCount() override; Return<uint64_t> getBufferSize() override; - Return<void> getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) override; + Return<uint32_t> getSampleRate() override; + Return<void> getSupportedSampleRates(AudioFormat format, getSupportedSampleRates_cb _hidl_cb) override; + Return<Result> setSampleRate(uint32_t sampleRateHz) override; + Return<hidl_bitfield<AudioChannelMask>> getChannelMask() override; + Return<void> getSupportedChannelMasks(AudioFormat format, getSupportedChannelMasks_cb _hidl_cb) override; + Return<Result> setChannelMask(hidl_bitfield<AudioChannelMask> mask) override; + Return<AudioFormat> getFormat() override; + Return<void> getSupportedFormats(getSupportedFormats_cb _hidl_cb) override; + Return<Result> setFormat(AudioFormat format) override; Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override; - Return<Result> setAudioProperties(const AudioConfigBaseOptional& config) override; Return<Result> addEffect(uint64_t effectId) override; Return<Result> removeEffect(uint64_t effectId) override; Return<Result> standby() override; @@ -71,7 +78,7 @@ struct StreamIn : public IStreamIn { // IStreamIn Return<void> getAudioSource(getAudioSource_cb _hidl_cb) override; Return<Result> setGain(float gain) override; - Return<Result> updateSinkMetadata(const SinkMetadata& sinkMetadata) override; + Return<void> updateSinkMetadata(const SinkMetadata& sinkMetadata) override; Return<void> prepareForReading(uint32_t frameSize, uint32_t framesCount, prepareForReading_cb _hidl_cb) override; Return<uint32_t> getInputFramesLost() override; @@ -82,17 +89,13 @@ struct StreamIn : public IStreamIn { const DeviceAddress &getDeviceAddress() const { return mCommon.m_device; } const AudioConfig &getAudioConfig() const { return mCommon.m_config; } - const hidl_vec<AudioInOutFlag> &getAudioOutputFlags() const { return mCommon.m_flags; } + const hidl_bitfield<AudioOutputFlag> &getAudioOutputFlags() const { return mCommon.m_flags; } uint64_t &getFrameCounter() { return mFrames; } void setMicMute(bool mute); void addInputFramesLost(size_t n) { mInputFramesLost += n; } float getEffectiveVolume() const { return mEffectiveVolume; } - static bool validateDeviceAddress(const DeviceAddress& device); - static bool validateFlags(const hidl_vec<AudioInOutFlag>& flags); - static bool validateSinkMetadata(const SinkMetadata& sinkMetadata); - private: Result closeImpl(bool fromDctor); @@ -109,7 +112,7 @@ private: }; } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/stream_out.cpp b/audio/stream_out.cpp index 6d198ab7..a34c2c6e 100644 --- a/audio/stream_out.cpp +++ b/audio/stream_out.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include <android_audio_policy_configuration_V7_0-enums.h> #include <log/log.h> #include <fmq/EventFlag.h> #include <fmq/MessageQueue.h> @@ -30,19 +29,15 @@ #include "util.h" #include "debug.h" -namespace xsd { -using namespace ::android::audio::policy::configuration::V7_0; -} - namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { using ::android::hardware::Void; -using namespace ::android::hardware::audio::common::V7_0; -using namespace ::android::hardware::audio::V7_0; +using namespace ::android::hardware::audio::common::V6_0; +using namespace ::android::hardware::audio::V6_0; namespace { @@ -233,10 +228,10 @@ StreamOut::StreamOut(sp<PrimaryDevice> dev, int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, - hidl_vec<AudioInOutFlag> flags, + hidl_bitfield<AudioOutputFlag> flags, const SourceMetadata& sourceMetadata) : mDev(std::move(dev)) - , mCommon(ioHandle, device, config, std::move(flags)) + , mCommon(ioHandle, device, config, flags) , mSourceMetadata(sourceMetadata) {} StreamOut::~StreamOut() { @@ -255,19 +250,50 @@ Return<uint64_t> StreamOut::getBufferSize() { return mCommon.getBufferSize(); } -Return<void> StreamOut::getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) { - mCommon.getSupportedProfiles(_hidl_cb); +Return<uint32_t> StreamOut::getSampleRate() { + return mCommon.getSampleRate(); +} + +Return<void> StreamOut::getSupportedSampleRates(AudioFormat format, + getSupportedSampleRates_cb _hidl_cb) { + mCommon.getSupportedSampleRates(format, _hidl_cb); return Void(); } -Return<void> StreamOut::getAudioProperties(getAudioProperties_cb _hidl_cb) { - mCommon.getAudioProperties(_hidl_cb); +Return<Result> StreamOut::setSampleRate(uint32_t sampleRateHz) { + return mCommon.setSampleRate(sampleRateHz); +} + +Return<hidl_bitfield<AudioChannelMask>> StreamOut::getChannelMask() { + return mCommon.getChannelMask(); +} + +Return<void> StreamOut::getSupportedChannelMasks(AudioFormat format, + IStream::getSupportedChannelMasks_cb _hidl_cb) { + mCommon.getSupportedChannelMasks(format, _hidl_cb); return Void(); } -Return<Result> StreamOut::setAudioProperties(const AudioConfigBaseOptional& config) { - (void)config; - return FAILURE(Result::NOT_SUPPORTED); +Return<Result> StreamOut::setChannelMask(hidl_bitfield<AudioChannelMask> mask) { + return mCommon.setChannelMask(mask); +} + +Return<AudioFormat> StreamOut::getFormat() { + return mCommon.getFormat(); +} + +Return<void> StreamOut::getSupportedFormats(getSupportedFormats_cb _hidl_cb) { + mCommon.getSupportedFormats(_hidl_cb); + return Void(); +} + +Return<Result> StreamOut::setFormat(AudioFormat format) { + return mCommon.setFormat(format); +} + +Return<void> StreamOut::getAudioProperties(getAudioProperties_cb _hidl_cb) { + mCommon.getAudioProperties(_hidl_cb); + return Void(); } Return<Result> StreamOut::addEffect(uint64_t effectId) { @@ -372,21 +398,21 @@ Return<Result> StreamOut::setVolume(float left, float right) { return Result::OK; } -Return<Result> StreamOut::updateSourceMetadata(const SourceMetadata& sourceMetadata) { +Return<void> StreamOut::updateSourceMetadata(const SourceMetadata& sourceMetadata) { (void)sourceMetadata; - return FAILURE(Result::NOT_SUPPORTED); + return Void(); } Return<void> StreamOut::prepareForWriting(uint32_t frameSize, uint32_t framesCount, prepareForWriting_cb _hidl_cb) { if (!frameSize || !framesCount || frameSize > 256 || framesCount > (1u << 20)) { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}, {}, -1); + _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}, {}, {}); return Void(); } if (mWriteThread) { // INVALID_STATE if the method was already called. - _hidl_cb(FAILURE(Result::INVALID_STATE), {}, {}, {}, -1); + _hidl_cb(FAILURE(Result::INVALID_STATE), {}, {}, {}, {}); return Void(); } @@ -397,11 +423,11 @@ Return<void> StreamOut::prepareForWriting(uint32_t frameSize, *(t->mCommandMQ.getDesc()), *(t->mDataMQ.getDesc()), *(t->mStatusMQ.getDesc()), - t->getTid().get()); + {.pid = getpid(), .tid = t->getTid().get()}); mWriteThread = std::move(t); } else { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}, {}, -1); + _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}, {}, {}); } return Void(); @@ -458,22 +484,7 @@ Return<Result> StreamOut::flush() { } Return<void> StreamOut::getPresentationPosition(getPresentationPosition_cb _hidl_cb) { - const auto w = static_cast<WriteThread*>(mWriteThread.get()); - if (!w) { - _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), {}, {}); - return Void(); - } - - const auto s = w->mSink.get(); - if (!s) { - _hidl_cb(Result::OK, mFrames, util::nsecs2TimeSpec(systemTime(SYSTEM_TIME_MONOTONIC))); - } else { - uint64_t frames; - TimeSpec ts; - const Result r = s->getPresentationPosition(frames, ts); - _hidl_cb(r, frames, ts); - } - + _hidl_cb(FAILURE(Result::NOT_SUPPORTED), {}, {}); // see WriteThread::doGetPresentationPosition return Void(); } @@ -524,23 +535,8 @@ void StreamOut::updateEffectiveVolumeLocked() { mEffectiveVolume = mMasterVolume * mStreamVolume; } -bool StreamOut::validateDeviceAddress(const DeviceAddress& device) { - return DevicePortSink::validateDeviceAddress(device); -} - -bool StreamOut::validateFlags(const hidl_vec<AudioInOutFlag>& flags) { - return std::all_of(flags.begin(), flags.end(), [](const AudioInOutFlag& flag){ - return xsd::stringToAudioInOutFlag(flag) != xsd::AudioInOutFlag::UNKNOWN; - }); -} - -bool StreamOut::validateSourceMetadata(const SourceMetadata& sourceMetadata) { - (void)sourceMetadata; - return true; -} - } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/stream_out.h b/audio/stream_out.h index d5b65fa0..20e42286 100644 --- a/audio/stream_out.h +++ b/audio/stream_out.h @@ -16,8 +16,8 @@ #pragma once #include <atomic> -#include <android/hardware/audio/7.0/IStreamOut.h> -#include <android/hardware/audio/7.0/IDevice.h> +#include <android/hardware/audio/6.0/IStreamOut.h> +#include <android/hardware/audio/6.0/IDevice.h> #include "stream_common.h" #include "io_thread.h" #include "primary_device.h" @@ -25,7 +25,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { using ::android::sp; @@ -33,15 +33,15 @@ using ::android::hardware::hidl_bitfield; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; -using namespace ::android::hardware::audio::common::V7_0; -using namespace ::android::hardware::audio::V7_0; +using namespace ::android::hardware::audio::common::V6_0; +using namespace ::android::hardware::audio::V6_0; struct StreamOut : public IStreamOut { StreamOut(sp<PrimaryDevice> dev, int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, - hidl_vec<AudioInOutFlag> flags, + hidl_bitfield<AudioOutputFlag> flags, const SourceMetadata& sourceMetadata); ~StreamOut(); @@ -49,9 +49,16 @@ struct StreamOut : public IStreamOut { Return<uint64_t> getFrameSize() override; Return<uint64_t> getFrameCount() override; Return<uint64_t> getBufferSize() override; - Return<void> getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) override; + Return<uint32_t> getSampleRate() override; + Return<void> getSupportedSampleRates(AudioFormat format, getSupportedSampleRates_cb _hidl_cb) override; + Return<Result> setSampleRate(uint32_t sampleRateHz) override; + Return<hidl_bitfield<AudioChannelMask>> getChannelMask() override; + Return<void> getSupportedChannelMasks(AudioFormat format, getSupportedChannelMasks_cb _hidl_cb) override; + Return<Result> setChannelMask(hidl_bitfield<AudioChannelMask> mask) override; + Return<AudioFormat> getFormat() override; + Return<void> getSupportedFormats(getSupportedFormats_cb _hidl_cb) override; + Return<Result> setFormat(AudioFormat format) override; Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override; - Return<Result> setAudioProperties(const AudioConfigBaseOptional& config) override; Return<Result> addEffect(uint64_t effectId) override; Return<Result> removeEffect(uint64_t effectId) override; Return<Result> standby() override; @@ -72,7 +79,7 @@ struct StreamOut : public IStreamOut { // IStreamOut Return<uint32_t> getLatency() override; Return<Result> setVolume(float left, float right) override; - Return<Result> updateSourceMetadata(const SourceMetadata& sourceMetadata) override; + Return<void> updateSourceMetadata(const SourceMetadata& sourceMetadata) override; Return<void> prepareForWriting(uint32_t frameSize, uint32_t framesCount, prepareForWriting_cb _hidl_cb) override; Return<void> getRenderPosition(getRenderPosition_cb _hidl_cb) override; @@ -99,14 +106,10 @@ struct StreamOut : public IStreamOut { float getEffectiveVolume() const { return mEffectiveVolume; } const DeviceAddress &getDeviceAddress() const { return mCommon.m_device; } const AudioConfig &getAudioConfig() const { return mCommon.m_config; } - const hidl_vec<AudioInOutFlag> &getAudioOutputFlags() const { return mCommon.m_flags; } + const hidl_bitfield<AudioOutputFlag> &getAudioOutputFlags() const { return mCommon.m_flags; } uint64_t &getFrameCounter() { return mFrames; } - static bool validateDeviceAddress(const DeviceAddress& device); - static bool validateFlags(const hidl_vec<AudioInOutFlag>& flags); - static bool validateSourceMetadata(const SourceMetadata& sourceMetadata); - private: Result closeImpl(bool fromDctor); void updateEffectiveVolumeLocked(); @@ -126,7 +129,7 @@ private: }; } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/talsa.cpp b/audio/talsa.cpp index d1e0597f..5afb8156 100644 --- a/audio/talsa.cpp +++ b/audio/talsa.cpp @@ -22,7 +22,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { namespace talsa { @@ -143,7 +143,7 @@ Mixer::~Mixer() { } // namespace talsa } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/talsa.h b/audio/talsa.h index 5fb1fadd..b461d63c 100644 --- a/audio/talsa.h +++ b/audio/talsa.h @@ -21,7 +21,7 @@ namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { namespace talsa { @@ -51,7 +51,7 @@ private: } // namespace talsa } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/util.cpp b/audio/util.cpp index 5a67dd80..00678d59 100644 --- a/audio/util.cpp +++ b/audio/util.cpp @@ -14,9 +14,8 @@ * limitations under the License. */ -#include <android_audio_policy_configuration_V7_0-enums.h> #include <log/log.h> -//#include <cutils/bitops.h> +#include <cutils/bitops.h> #include <cutils/sched_policy.h> #include <system/audio.h> #include <sys/resource.h> @@ -24,14 +23,10 @@ #include "util.h" #include "debug.h" -namespace xsd { -using namespace ::android::audio::policy::configuration::V7_0; -} - namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { namespace util { @@ -41,49 +36,36 @@ const std::array<uint32_t, 8> kSupportedRatesHz = { 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000 }; -bool checkSampleRateHz(uint32_t value, uint32_t &suggested) { +const std::array<hidl_bitfield<AudioChannelMask>, 4> kSupportedInChannelMask = { + AudioChannelMask::IN_LEFT | 0, + AudioChannelMask::IN_RIGHT | 0, + AudioChannelMask::IN_FRONT | 0, + AudioChannelMask::IN_STEREO | 0, +}; + +const std::array<hidl_bitfield<AudioChannelMask>, 4> kSupportedOutChannelMask = { + AudioChannelMask::OUT_FRONT_LEFT | 0, + AudioChannelMask::OUT_FRONT_RIGHT | 0, + AudioChannelMask::OUT_FRONT_CENTER | 0, + AudioChannelMask::OUT_STEREO | 0, +}; + +const std::array<AudioFormat, 1> kSupportedAudioFormats = { + AudioFormat::PCM_16_BIT, +}; + +bool checkSampleRateHz(uint32_t value, uint32_t &suggest) { for (const uint32_t supported : kSupportedRatesHz) { if (value <= supported) { - suggested = supported; - return value == supported; + suggest = supported; + return (value == supported); } } - suggested = kSupportedRatesHz.back(); + suggest = kSupportedRatesHz.back(); return FAILURE(false); } -bool checkChannelMask(const bool isOut, - const AudioChannelMask &value, - AudioChannelMask &suggested) { - switch (xsd::stringToAudioChannelMask(value)) { - case xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_MONO: - case xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO: - case xsd::AudioChannelMask::AUDIO_CHANNEL_IN_MONO: - case xsd::AudioChannelMask::AUDIO_CHANNEL_IN_STEREO: - suggested = value; - return true; - - default: - suggested = toString(isOut ? - xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO : - xsd::AudioChannelMask::AUDIO_CHANNEL_IN_MONO); - return FAILURE(false); - } -} - -bool checkFormat(const AudioFormat &value, AudioFormat &suggested) { - switch (xsd::stringToAudioFormat(value)) { - case xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT: - suggested = value; - return true; - - default: - suggested = toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT); - return FAILURE(false); - } -} - size_t align(size_t v, size_t a) { return (v + a - 1) / a * a; } @@ -115,43 +97,56 @@ MicrophoneInfo getMicrophoneInfo() { return mic; } -size_t countChannels(const AudioChannelMask &mask) { - return xsd::getChannelCount(mask); +size_t countChannels(hidl_bitfield<AudioChannelMask> mask) { + return popcount(mask); } -size_t getBytesPerSample(const AudioFormat &format) { - if (format == "AUDIO_FORMAT_PCM_16_BIT") { - return 2; - } else { - ALOGE("util::%s:%d unknown format, '%s'", __func__, __LINE__, format.c_str()); - return 0; - } +size_t getBytesPerSample(AudioFormat format) { + return audio_bytes_per_sample(static_cast<audio_format_t>(format)); } -bool checkAudioConfig(const bool isOut, +bool checkAudioConfig(bool isOut, size_t duration_ms, - const AudioConfig &src, + const AudioConfig &cfg, AudioConfig &suggested) { - bool result = true; - suggested = src; - - if (!checkSampleRateHz(src.base.sampleRateHz, suggested.base.sampleRateHz)) { - result = false; + bool valid = checkSampleRateHz(cfg.sampleRateHz, suggested.sampleRateHz); + + if (isOut) { + if (std::find(kSupportedOutChannelMask.begin(), + kSupportedOutChannelMask.end(), + cfg.channelMask) == kSupportedOutChannelMask.end()) { + suggested.channelMask = AudioChannelMask::OUT_STEREO | 0; + valid = FAILURE(false); + } else { + suggested.channelMask = cfg.channelMask; + } + } else { + if (std::find(kSupportedInChannelMask.begin(), + kSupportedInChannelMask.end(), + cfg.channelMask) == kSupportedInChannelMask.end()) { + suggested.channelMask = AudioChannelMask::IN_STEREO | 0; + valid = FAILURE(false); + } else { + suggested.channelMask = cfg.channelMask; + } } - if (!checkChannelMask(isOut, src.base.channelMask, suggested.base.channelMask)) { - result = false; + if (std::find(kSupportedAudioFormats.begin(), + kSupportedAudioFormats.end(), + cfg.format) == kSupportedAudioFormats.end()) { + suggested.format = AudioFormat::PCM_16_BIT; + valid = FAILURE(false); + } else { + suggested.format = cfg.format; } - if (!checkFormat(src.base.format, suggested.base.format)) { - result = false; - } + suggested.offloadInfo = cfg.offloadInfo; // don't care - if (src.frameCount == 0) { - suggested.frameCount = getBufferSizeFrames(duration_ms, src.base.sampleRateHz); - } + suggested.frameCount = (cfg.frameCount == 0) + ? getBufferSizeFrames(duration_ms, suggested.sampleRateHz) + : cfg.frameCount; - return result; + return valid; } TimeSpec nsecs2TimeSpec(nsecs_t ns) { @@ -168,7 +163,7 @@ void setThreadPriority(int prio) { } // namespace util } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android diff --git a/audio/util.h b/audio/util.h index f0caa6dc..5337c7b6 100644 --- a/audio/util.h +++ b/audio/util.h @@ -16,28 +16,27 @@ #pragma once #include <array> -#include <android/hardware/audio/common/7.0/types.h> -#include <android/hardware/audio/7.0/types.h> +#include <android/hardware/audio/common/6.0/types.h> +#include <android/hardware/audio/6.0/types.h> #include <utils/Timers.h> namespace android { namespace hardware { namespace audio { -namespace V7_0 { +namespace V6_0 { namespace implementation { namespace util { using ::android::hardware::hidl_bitfield; -using ::android::hardware::hidl_string; -using ::android::hardware::audio::common::V7_0::AudioFormat; -using ::android::hardware::audio::common::V7_0::AudioChannelMask; -using ::android::hardware::audio::common::V7_0::AudioConfig; -using ::android::hardware::audio::V7_0::MicrophoneInfo; +using ::android::hardware::audio::common::V6_0::AudioFormat; +using ::android::hardware::audio::common::V6_0::AudioChannelMask; +using ::android::hardware::audio::common::V6_0::AudioConfig; +using ::android::hardware::audio::V6_0::MicrophoneInfo; MicrophoneInfo getMicrophoneInfo(); -size_t countChannels(const AudioChannelMask &mask); -size_t getBytesPerSample(const AudioFormat &format); +size_t countChannels(hidl_bitfield<AudioChannelMask>); +size_t getBytesPerSample(AudioFormat); bool checkAudioConfig(bool isOut, size_t duration_ms, @@ -50,7 +49,7 @@ void setThreadPriority(int prio); } // namespace util } // namespace implementation -} // namespace V7_0 +} // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android |