blob: 7eca446f126094c6b3dfebc47b901914c8a70766 [file] [log] [blame]
Hayden Gomesaeeb9b02020-10-27 13:08:34 -07001/*
2 * Copyright (C) 2020 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>
Francois Gaffie625a8982022-02-08 17:40:14 +010020#include <aidl/android/hardware/automotive/audiocontrol/AudioGainConfigInfo.h>
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070021#include <aidl/android/hardware/automotive/audiocontrol/BnAudioControl.h>
Hayden Gomesad816702020-12-14 15:29:29 -080022#include <aidl/android/hardware/automotive/audiocontrol/DuckingInfo.h>
Francois Gaffie625a8982022-02-08 17:40:14 +010023#include <aidl/android/hardware/automotive/audiocontrol/IAudioGainCallback.h>
Raj Goparaju27a02e12023-01-30 16:17:14 -080024#include <aidl/android/hardware/automotive/audiocontrol/IModuleChangeCallback.h>
Oscar Azucenab8e5cd02020-12-16 13:53:14 -080025#include <aidl/android/hardware/automotive/audiocontrol/MutingInfo.h>
Francois Gaffie625a8982022-02-08 17:40:14 +010026#include <aidl/android/hardware/automotive/audiocontrol/Reasons.h>
27
28#include <aidl/android/hardware/audio/common/PlaybackTrackMetadata.h>
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070029
Raj Goparaju27a02e12023-01-30 16:17:14 -080030#include <aidl/android/media/audio/common/AudioChannelLayout.h>
31#include <aidl/android/media/audio/common/AudioDeviceType.h>
32#include <aidl/android/media/audio/common/AudioFormatDescription.h>
33#include <aidl/android/media/audio/common/AudioFormatType.h>
34#include <aidl/android/media/audio/common/AudioGainMode.h>
35#include <aidl/android/media/audio/common/AudioIoFlags.h>
36#include <aidl/android/media/audio/common/AudioOutputFlags.h>
37
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070038namespace aidl::android::hardware::automotive::audiocontrol {
39
Francois Gaffie625a8982022-02-08 17:40:14 +010040namespace audiohalcommon = ::aidl::android::hardware::audio::common;
41namespace audiomediacommon = ::aidl::android::media::audio::common;
42
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070043class AudioControl : public BnAudioControl {
44 public:
45 ndk::ScopedAStatus onAudioFocusChange(const std::string& in_usage, int32_t in_zoneId,
46 AudioFocusChange in_focusChange) override;
Hayden Gomesad816702020-12-14 15:29:29 -080047 ndk::ScopedAStatus onDevicesToDuckChange(
48 const std::vector<DuckingInfo>& in_duckingInfos) override;
Oscar Azucenab8e5cd02020-12-16 13:53:14 -080049 ndk::ScopedAStatus onDevicesToMuteChange(
50 const std::vector<MutingInfo>& in_mutingInfos) override;
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070051 ndk::ScopedAStatus registerFocusListener(
Hayden Gomes6333eed2021-03-25 11:27:59 -070052 const std::shared_ptr<IFocusListener>& in_listener) override;
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070053 ndk::ScopedAStatus setBalanceTowardRight(float in_value) override;
54 ndk::ScopedAStatus setFadeTowardFront(float in_value) override;
Francois Gaffie625a8982022-02-08 17:40:14 +010055 ndk::ScopedAStatus onAudioFocusChangeWithMetaData(
56 const audiohalcommon::PlaybackTrackMetadata& in_playbackMetaData, int32_t in_zoneId,
57 AudioFocusChange in_focusChange) override;
58 ndk::ScopedAStatus setAudioDeviceGainsChanged(
59 const std::vector<Reasons>& in_reasons,
60 const std::vector<AudioGainConfigInfo>& in_gains) override;
61 ndk::ScopedAStatus registerGainCallback(
62 const std::shared_ptr<IAudioGainCallback>& in_callback) override;
Raj Goparaju27a02e12023-01-30 16:17:14 -080063 ndk::ScopedAStatus setModuleChangeCallback(
64 const std::shared_ptr<IModuleChangeCallback>& in_callback) override;
65 ndk::ScopedAStatus clearModuleChangeCallback() override;
Francois Gaffie625a8982022-02-08 17:40:14 +010066
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070067 binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
68
69 private:
70 // This focus listener will only be used by this HAL instance to communicate with
71 // a single instance of CarAudioService. As such, it doesn't have explicit serialization.
72 // If a different AudioControl implementation were to have multiple threads leveraging this
73 // listener, then it should also include mutexes or make the listener atomic.
Hayden Gomes6333eed2021-03-25 11:27:59 -070074 std::shared_ptr<IFocusListener> mFocusListener;
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070075
Francois Gaffie625a8982022-02-08 17:40:14 +010076 /**
77 * @brief mAudioGainCallback will be used by this HAL instance to communicate e.g. with a single
78 * instance of CarAudioService to report unexpected gain changed.
79 */
80 std::shared_ptr<IAudioGainCallback> mAudioGainCallback = nullptr;
81
Raj Goparaju27a02e12023-01-30 16:17:14 -080082 std::shared_ptr<IModuleChangeCallback> mModuleChangeCallback = nullptr;
83
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070084 binder_status_t cmdHelp(int fd) const;
85 binder_status_t cmdRequestFocus(int fd, const char** args, uint32_t numArgs);
86 binder_status_t cmdAbandonFocus(int fd, const char** args, uint32_t numArgs);
Francois Gaffie625a8982022-02-08 17:40:14 +010087 binder_status_t cmdRequestFocusWithMetaData(int fd, const char** args, uint32_t numArgs);
88 binder_status_t cmdAbandonFocusWithMetaData(int fd, const char** args, uint32_t numArgs);
89 binder_status_t cmdOnAudioDeviceGainsChanged(int fd, const char** args, uint32_t numArgs);
Raj Goparaju27a02e12023-01-30 16:17:14 -080090 binder_status_t cmdOnAudioPortsChanged(int fd, const char** args, uint32_t numArgs);
Francois Gaffie625a8982022-02-08 17:40:14 +010091
92 binder_status_t parseMetaData(int fd, const std::string& metadataLiteral,
93 audiohalcommon::PlaybackTrackMetadata& trackMetadata);
Raj Goparaju27a02e12023-01-30 16:17:14 -080094 binder_status_t parseAudioGains(
95 int fd, const std::string& stringGain,
96 std::vector<::aidl::android::media::audio::common::AudioGain>& gains);
97 binder_status_t parseSampleRates(int fd, const std::string& sampleRates,
98 std::vector<int32_t>& vecSampleRates);
Francois Gaffie625a8982022-02-08 17:40:14 +010099
Hayden Gomesaeeb9b02020-10-27 13:08:34 -0700100 binder_status_t dumpsys(int fd);
101};
102
103} // namespace aidl::android::hardware::automotive::audiocontrol
104
105#endif // ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_AUDIOCONTROL_H