• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 #pragma once
18 #include <android/hardware/audio/6.0/IPrimaryDevice.h>
19 #include <atomic>
20 #include <unordered_map>
21 #include "talsa.h"
22 
23 namespace android {
24 namespace hardware {
25 namespace audio {
26 namespace V6_0 {
27 namespace implementation {
28 
29 using ::android::sp;
30 using ::android::hardware::hidl_bitfield;
31 using ::android::hardware::hidl_string;
32 using ::android::hardware::hidl_vec;
33 using ::android::hardware::Return;
34 
35 using namespace ::android::hardware::audio::common::V6_0;
36 using namespace ::android::hardware::audio::V6_0;
37 
38 struct PrimaryDevice : public IPrimaryDevice {
39     PrimaryDevice();
40 
41     Return<Result> initCheck() override;
42     Return<Result> setMasterVolume(float volume) override;
43     Return<void> getMasterVolume(getMasterVolume_cb _hidl_cb) override;
44     Return<Result> setMicMute(bool mute) override;
45     Return<void> getMicMute(getMicMute_cb _hidl_cb) override;
46     Return<Result> setMasterMute(bool mute) override;
47     Return<void> getMasterMute(getMasterMute_cb _hidl_cb) override;
48     Return<void> getInputBufferSize(const AudioConfig& config,
49                                     getInputBufferSize_cb _hidl_cb) override;
50     Return<void> openOutputStream(int32_t ioHandle,
51                                   const DeviceAddress& device,
52                                   const AudioConfig& config,
53                                   hidl_bitfield<AudioOutputFlag> flags,
54                                   const SourceMetadata& sourceMetadata,
55                                   openOutputStream_cb _hidl_cb) override;
56     Return<void> openInputStream(int32_t ioHandle,
57                                  const DeviceAddress& device,
58                                  const AudioConfig& config,
59                                  hidl_bitfield<AudioInputFlag> flags,
60                                  const SinkMetadata& sinkMetadata,
61                                  openInputStream_cb _hidl_cb) override;
62     Return<bool> supportsAudioPatches() override;
63     Return<void> createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
64                                   const hidl_vec<AudioPortConfig>& sinks,
65                                   createAudioPatch_cb _hidl_cb) override;
66     Return<void> updateAudioPatch(AudioPatchHandle previousPatch,
67                                   const hidl_vec<AudioPortConfig>& sources,
68                                   const hidl_vec<AudioPortConfig>& sinks,
69                                   updateAudioPatch_cb _hidl_cb) override;
70     Return<Result> releaseAudioPatch(AudioPatchHandle patch) override;
71     Return<void> getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) override;
72     Return<Result> setAudioPortConfig(const AudioPortConfig& config) override;
73     Return<Result> setScreenState(bool turnedOn) override;
74     Return<void> getHwAvSync(getHwAvSync_cb _hidl_cb) override;
75     Return<void> getParameters(const hidl_vec<ParameterValue>& context,
76                                const hidl_vec<hidl_string>& keys,
77                                getParameters_cb _hidl_cb) override;
78     Return<Result> setParameters(const hidl_vec<ParameterValue>& context,
79                                  const hidl_vec<ParameterValue>& parameters) override;
80     Return<void> getMicrophones(getMicrophones_cb _hidl_cb) override;
81     Return<Result> setConnectedState(const DeviceAddress& address, bool connected) override;
82     Return<Result> close() override;
83     Return<Result> addDeviceEffect(AudioPortHandle device, uint64_t effectId) override;
84     Return<Result> removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override;
85     Return<Result> setVoiceVolume(float volume) override;
86     Return<Result> setMode(AudioMode mode) override;
87     Return<Result> setBtScoHeadsetDebugName(const hidl_string& name) override;
88     Return<void> getBtScoNrecEnabled(getBtScoNrecEnabled_cb _hidl_cb) override;
89     Return<Result> setBtScoNrecEnabled(bool enabled) override;
90     Return<void> getBtScoWidebandEnabled(getBtScoWidebandEnabled_cb _hidl_cb) override;
91     Return<Result> setBtScoWidebandEnabled(bool enabled) override;
92     Return<void> getTtyMode(getTtyMode_cb _hidl_cb) override;
93     Return<Result> setTtyMode(IPrimaryDevice::TtyMode mode) override;
94     Return<void> getHacEnabled(getHacEnabled_cb _hidl_cb) override;
95     Return<Result> setHacEnabled(bool enabled) override;
96     Return<void> getBtHfpEnabled(getBtHfpEnabled_cb _hidl_cb) override;
97     Return<Result> setBtHfpEnabled(bool enabled) override;
98     Return<Result> setBtHfpSampleRate(uint32_t sampleRateHz) override;
99     Return<Result> setBtHfpVolume(float volume) override;
100     Return<Result> updateRotation(IPrimaryDevice::Rotation rotation) override;
101 
102 private:
103     static void unrefDevice(IDevice*);
104     void unrefDeviceImpl();
105 
106     talsa::MixerPtr     mMixer;
107     talsa::mixer_ctl_t  *mMixerMasterVolumeCtl = nullptr;
108     talsa::mixer_ctl_t  *mMixerCaptureVolumeCtl = nullptr;
109     talsa::mixer_ctl_t  *mMixerMasterPaybackSwitchCtl = nullptr;
110     talsa::mixer_ctl_t  *mMixerCaptureSwitchCtl = nullptr;
111     float               mMasterVolume = 1.0f;
112     std::atomic<int>    mNStreams = 0;
113 
114     struct AudioPatch {
115         AudioPortConfig source;
116         AudioPortConfig sink;
117     };
118 
119     AudioPatchHandle    mNextAudioPatchHandle = 0;
120     std::unordered_map<AudioPatchHandle, AudioPatch> mAudioPatches;
121 };
122 
123 }  // namespace implementation
124 }  // namespace V6_0
125 }  // namespace audio
126 }  // namespace hardware
127 }  // namespace android
128