/* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ANDROID_HARDWARE_AUDIO_DEVICE_H #define ANDROID_HARDWARE_AUDIO_DEVICE_H #include PATH(android/hardware/audio/FILE_VERSION/IDevice.h) #include "ParametersUtil.h" #include #include #include #include #include #include #include namespace android { namespace hardware { namespace audio { namespace CPP_VERSION { namespace implementation { using ::android::sp; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::CoreUtils; using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::ParametersUtil; using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION; using namespace ::android::hardware::audio::CPP_VERSION; using AudioInputFlags = CoreUtils::AudioInputFlags; using AudioOutputFlags = CoreUtils::AudioOutputFlags; struct Device : public IDevice, public ParametersUtil { explicit Device(audio_hw_device_t* device); // Methods from ::android::hardware::audio::CPP_VERSION::IDevice follow. Return initCheck() override; Return setMasterVolume(float volume) override; Return getMasterVolume(getMasterVolume_cb _hidl_cb) override; Return setMicMute(bool mute) override; Return getMicMute(getMicMute_cb _hidl_cb) override; Return setMasterMute(bool mute) override; Return getMasterMute(getMasterMute_cb _hidl_cb) override; Return getInputBufferSize(const AudioConfig& config, getInputBufferSize_cb _hidl_cb) override; std::tuple> openOutputStreamCore(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, const AudioOutputFlags& flags, AudioConfig* suggestedConfig); std::tuple> openInputStreamCore( int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, const AudioInputFlags& flags, AudioSource source, AudioConfig* suggestedConfig); #if MAJOR_VERSION >= 4 std::tuple, AudioConfig> openOutputStreamImpl( int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, const SourceMetadata& sourceMetadata, #if MAJOR_VERSION <= 6 AudioOutputFlags flags); #else const AudioOutputFlags& flags); #endif std::tuple, AudioConfig> openInputStreamImpl( int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, #if MAJOR_VERSION <= 6 AudioInputFlags flags, #else const AudioInputFlags& flags, #endif const SinkMetadata& sinkMetadata); #endif // MAJOR_VERSION >= 4 Return openOutputStream(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, #if MAJOR_VERSION <= 6 AudioOutputFlags flags, #else const AudioOutputFlags& flags, #endif #if MAJOR_VERSION >= 4 const SourceMetadata& sourceMetadata, #endif openOutputStream_cb _hidl_cb) override; Return openInputStream(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, #if MAJOR_VERSION <= 6 AudioInputFlags flags, #else const AudioInputFlags& flags, #endif #if MAJOR_VERSION == 2 AudioSource source, #elif MAJOR_VERSION >= 4 const SinkMetadata& sinkMetadata, #endif openInputStream_cb _hidl_cb) override; #if MAJOR_VERSION == 7 && MINOR_VERSION == 1 Return openOutputStream_7_1(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, const AudioOutputFlags& flags, const SourceMetadata& sourceMetadata, openOutputStream_7_1_cb _hidl_cb) override; #endif Return supportsAudioPatches() override; Return createAudioPatch(const hidl_vec& sources, const hidl_vec& sinks, createAudioPatch_cb _hidl_cb) override; Return releaseAudioPatch(int32_t patch) override; Return getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) override; Return setAudioPortConfig(const AudioPortConfig& config) override; Return setScreenState(bool turnedOn) override; #if MAJOR_VERSION == 2 Return getHwAvSync() override; Return getParameters(const hidl_vec& keys, getParameters_cb _hidl_cb) override; Return setParameters(const hidl_vec& parameters) override; Return debugDump(const hidl_handle& fd) override; #elif MAJOR_VERSION >= 4 Return getHwAvSync(getHwAvSync_cb _hidl_cb) override; Return getParameters(const hidl_vec& context, const hidl_vec& keys, getParameters_cb _hidl_cb) override; Return setParameters(const hidl_vec& context, const hidl_vec& parameters) override; Return getMicrophones(getMicrophones_cb _hidl_cb) override; Return setConnectedState(const DeviceAddress& address, bool connected) override; #endif #if MAJOR_VERSION >= 6 Return close() override; Return addDeviceEffect(AudioPortHandle device, uint64_t effectId) override; Return removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override; Return updateAudioPatch(int32_t previousPatch, const hidl_vec& sources, const hidl_vec& sinks, createAudioPatch_cb _hidl_cb) override; #endif #if MAJOR_VERSION == 7 && MINOR_VERSION == 1 Return setConnectedState_7_1(const AudioPort& devicePort, bool connected) override; #endif Return debug(const hidl_handle& fd, const hidl_vec& options) override; // Utility methods for extending interfaces. Result analyzeStatus(const char* funcName, int status, const std::vector& ignoreErrors = {}); void closeInputStream(audio_stream_in_t* stream); void closeOutputStream(audio_stream_out_t* stream); audio_hw_device_t* device() const { return mDevice; } uint32_t version() const { return mDevice->common.version; } private: bool mIsClosed; audio_hw_device_t* mDevice; int mOpenedStreamsCount = 0; virtual ~Device(); Result doClose(); std::tuple createOrUpdateAudioPatch( AudioPatchHandle patch, const hidl_vec& sources, const hidl_vec& sinks); template Return getAudioPortImpl(const AudioPort& port, getAudioPort_cb _hidl_cb, int (*halGetter)(audio_hw_device_t*, HalPort*), const char* halGetterName); // Methods from ParametersUtil. char* halGetParameters(const char* keys) override; int halSetParameters(const char* keysAndValues) override; }; } // namespace implementation } // namespace CPP_VERSION } // namespace audio } // namespace hardware } // namespace android #endif // ANDROID_HARDWARE_AUDIO_DEVICE_H