1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_AUDIOCONTROL_H 17 #define ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_AUDIOCONTROL_H 18 19 #include <aidl/android/hardware/automotive/audiocontrol/AudioFocusChange.h> 20 #include <aidl/android/hardware/automotive/audiocontrol/AudioGainConfigInfo.h> 21 #include <aidl/android/hardware/automotive/audiocontrol/BnAudioControl.h> 22 #include <aidl/android/hardware/automotive/audiocontrol/DuckingInfo.h> 23 #include <aidl/android/hardware/automotive/audiocontrol/IAudioGainCallback.h> 24 #include <aidl/android/hardware/automotive/audiocontrol/IModuleChangeCallback.h> 25 #include <aidl/android/hardware/automotive/audiocontrol/MutingInfo.h> 26 #include <aidl/android/hardware/automotive/audiocontrol/Reasons.h> 27 #include <aidl/android/hardware/audio/common/PlaybackTrackMetadata.h> 28 29 #include <aidl/android/media/audio/common/AudioChannelLayout.h> 30 #include <aidl/android/media/audio/common/AudioDeviceType.h> 31 #include <aidl/android/media/audio/common/AudioFormatDescription.h> 32 #include <aidl/android/media/audio/common/AudioFormatType.h> 33 #include <aidl/android/media/audio/common/AudioGainMode.h> 34 #include <aidl/android/media/audio/common/AudioIoFlags.h> 35 #include <aidl/android/media/audio/common/AudioOutputFlags.h> 36 37 namespace android::hardware::audiocontrol::internal { 38 class CarAudioConfigurationXmlConverter; 39 } 40 41 namespace aidl { 42 namespace android { 43 namespace hardware { 44 namespace automotive { 45 namespace audiocontrol { 46 47 namespace audiohalcommon = ::aidl::android::hardware::audio::common; 48 namespace audiomediacommon = ::aidl::android::media::audio::common; 49 50 class AudioControl : public BnAudioControl { 51 public: 52 AudioControl(); 53 AudioControl(const std::string& carAudioConfig, const std::string& audioFadeConfig); 54 ndk::ScopedAStatus onAudioFocusChange(const std::string& in_usage, int32_t in_zoneId, 55 AudioFocusChange in_focusChange) override; 56 ndk::ScopedAStatus onDevicesToDuckChange( 57 const std::vector<DuckingInfo>& in_duckingInfos) override; 58 ndk::ScopedAStatus onDevicesToMuteChange( 59 const std::vector<MutingInfo>& in_mutingInfos) override; 60 ndk::ScopedAStatus registerFocusListener( 61 const std::shared_ptr<IFocusListener>& in_listener) override; 62 ndk::ScopedAStatus setBalanceTowardRight(float in_value) override; 63 ndk::ScopedAStatus setFadeTowardFront(float in_value) override; 64 ndk::ScopedAStatus onAudioFocusChangeWithMetaData( 65 const audiohalcommon::PlaybackTrackMetadata &in_playbackMetaData, int32_t in_zoneId, 66 AudioFocusChange in_focusChange) override; 67 ndk::ScopedAStatus setAudioDeviceGainsChanged( 68 const std::vector <Reasons> &in_reasons, 69 const std::vector <AudioGainConfigInfo> &in_gains) override; 70 ndk::ScopedAStatus registerGainCallback( 71 const std::shared_ptr <IAudioGainCallback> &in_callback) override; 72 ndk::ScopedAStatus setModuleChangeCallback( 73 const std::shared_ptr<IModuleChangeCallback>& in_callback) override; 74 ndk::ScopedAStatus clearModuleChangeCallback() override; 75 ndk::ScopedAStatus getAudioDeviceConfiguration( 76 AudioDeviceConfiguration* audioDeviceConfig) override; 77 ndk::ScopedAStatus getOutputMirroringDevices( 78 std::vector<::aidl::android::media::audio::common::AudioPort>* mirrorDevices) override; 79 ndk::ScopedAStatus getCarAudioZones(std::vector<AudioZone>* audioZones) override; 80 81 binder_status_t dump(int fd, const char** args, uint32_t numArgs) override; 82 83 void setAudioEnabled(bool isEnabled); 84 85 private: 86 // This focus listener will only be used by this HAL instance to communicate with 87 // a single instance of CarAudioService. As such, it doesn't have explicit serialization. 88 // If a different AudioControl implementation were to have multiple threads leveraging this 89 // listener, then it should also include mutexes or make the listener atomic. 90 std::shared_ptr<IFocusListener> mFocusListener; 91 92 /** 93 * @brief mAudioGainCallback will be used by this HAL instance to communicate e.g. with a single 94 * instance of CarAudioService to report unexpected gain changed. 95 */ 96 std::shared_ptr<IAudioGainCallback> mAudioGainCallback = nullptr; 97 std::shared_ptr<IModuleChangeCallback> mModuleChangeCallback = nullptr; 98 99 std::shared_ptr<::android::hardware::audiocontrol::internal::CarAudioConfigurationXmlConverter> 100 mCarAudioConfigurationConverter = nullptr; 101 102 binder_status_t cmdHelp(int fd) const; 103 binder_status_t cmdRequestFocus(int fd, const char** args, uint32_t numArgs); 104 binder_status_t cmdAbandonFocus(int fd, const char** args, uint32_t numArgs); 105 binder_status_t cmdRequestFocusWithMetaData(int fd, const char **args, uint32_t numArgs); 106 binder_status_t cmdAbandonFocusWithMetaData(int fd, const char **args, uint32_t numArgs); 107 binder_status_t cmdOnAudioDeviceGainsChanged(int fd, const char **args, uint32_t numArgs); 108 binder_status_t parseMetaData(int fd, const std::string &metadataLiteral, 109 audiohalcommon::PlaybackTrackMetadata &trackMetadata); 110 binder_status_t cmdOnAudioPortsChanged(int fd, const char** args, uint32_t numArgs); 111 112 binder_status_t parseAudioGains( 113 int fd, const std::string& stringGain, 114 std::vector<::aidl::android::media::audio::common::AudioGain>& gains); 115 binder_status_t parseSampleRates(int fd, const std::string& sampleRates, 116 std::vector<int32_t>& vecSampleRates); 117 118 binder_status_t dumpsys(int fd); 119 }; 120 121 } // namespace audiocontrol 122 } // namespace automotive 123 } // namespace hardware 124 } // namespace android 125 } // namespace aidl 126 127 #endif // ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_AUDIOCONTROL_H 128