blob: 16b80e890c7714f98c787c2f07dad4aad59819db [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 Gaffie8a693082022-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 Gaffie8a693082022-02-08 17:40:14 +010023#include <aidl/android/hardware/automotive/audiocontrol/IAudioGainCallback.h>
Oscar Azucenab8e5cd02020-12-16 13:53:14 -080024#include <aidl/android/hardware/automotive/audiocontrol/MutingInfo.h>
Francois Gaffie8a693082022-02-08 17:40:14 +010025#include <aidl/android/hardware/automotive/audiocontrol/Reasons.h>
26
27#include <aidl/android/hardware/audio/common/PlaybackTrackMetadata.h>
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070028
29namespace aidl::android::hardware::automotive::audiocontrol {
30
Francois Gaffie8a693082022-02-08 17:40:14 +010031namespace audiohalcommon = ::aidl::android::hardware::audio::common;
32namespace audiomediacommon = ::aidl::android::media::audio::common;
33
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070034class AudioControl : public BnAudioControl {
35 public:
36 ndk::ScopedAStatus onAudioFocusChange(const std::string& in_usage, int32_t in_zoneId,
37 AudioFocusChange in_focusChange) override;
Hayden Gomesad816702020-12-14 15:29:29 -080038 ndk::ScopedAStatus onDevicesToDuckChange(
39 const std::vector<DuckingInfo>& in_duckingInfos) override;
Oscar Azucenab8e5cd02020-12-16 13:53:14 -080040 ndk::ScopedAStatus onDevicesToMuteChange(
41 const std::vector<MutingInfo>& in_mutingInfos) override;
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070042 ndk::ScopedAStatus registerFocusListener(
Hayden Gomes6333eed2021-03-25 11:27:59 -070043 const std::shared_ptr<IFocusListener>& in_listener) override;
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070044 ndk::ScopedAStatus setBalanceTowardRight(float in_value) override;
45 ndk::ScopedAStatus setFadeTowardFront(float in_value) override;
Francois Gaffie8a693082022-02-08 17:40:14 +010046 ndk::ScopedAStatus onAudioFocusChangeWithMetaData(
47 const audiohalcommon::PlaybackTrackMetadata& in_playbackMetaData, int32_t in_zoneId,
48 AudioFocusChange in_focusChange) override;
49 ndk::ScopedAStatus setAudioDeviceGainsChanged(
50 const std::vector<Reasons>& in_reasons,
51 const std::vector<AudioGainConfigInfo>& in_gains) override;
52 ndk::ScopedAStatus registerGainCallback(
53 const std::shared_ptr<IAudioGainCallback>& in_callback) override;
54
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070055 binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
56
57 private:
58 // This focus listener will only be used by this HAL instance to communicate with
59 // a single instance of CarAudioService. As such, it doesn't have explicit serialization.
60 // If a different AudioControl implementation were to have multiple threads leveraging this
61 // listener, then it should also include mutexes or make the listener atomic.
Hayden Gomes6333eed2021-03-25 11:27:59 -070062 std::shared_ptr<IFocusListener> mFocusListener;
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070063
Francois Gaffie8a693082022-02-08 17:40:14 +010064 /**
65 * @brief mAudioGainCallback will be used by this HAL instance to communicate e.g. with a single
66 * instance of CarAudioService to report unexpected gain changed.
67 */
68 std::shared_ptr<IAudioGainCallback> mAudioGainCallback = nullptr;
69
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070070 binder_status_t cmdHelp(int fd) const;
71 binder_status_t cmdRequestFocus(int fd, const char** args, uint32_t numArgs);
72 binder_status_t cmdAbandonFocus(int fd, const char** args, uint32_t numArgs);
Francois Gaffie8a693082022-02-08 17:40:14 +010073 binder_status_t cmdRequestFocusWithMetaData(int fd, const char** args, uint32_t numArgs);
74 binder_status_t cmdAbandonFocusWithMetaData(int fd, const char** args, uint32_t numArgs);
75 binder_status_t cmdOnAudioDeviceGainsChanged(int fd, const char** args, uint32_t numArgs);
76
77 binder_status_t parseMetaData(int fd, const std::string& metadataLiteral,
78 audiohalcommon::PlaybackTrackMetadata& trackMetadata);
79
Hayden Gomesaeeb9b02020-10-27 13:08:34 -070080 binder_status_t dumpsys(int fd);
81};
82
83} // namespace aidl::android::hardware::automotive::audiocontrol
84
85#endif // ANDROID_HARDWARE_AUTOMOTIVE_AUDIOCONTROL_AUDIOCONTROL_H