1 /*
2  * Copyright (C) 2016 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 #ifndef ANDROID_HARDWARE_AUDIO_V2_0_PRIMARYDEVICE_H
18 #define ANDROID_HARDWARE_AUDIO_V2_0_PRIMARYDEVICE_H
19 
20 #include <android/hardware/audio/2.0/IPrimaryDevice.h>
21 #include <hidl/Status.h>
22 
23 #include <hidl/MQDescriptor.h>
24 
25 #include "Device.h"
26 
27 namespace android {
28 namespace hardware {
29 namespace audio {
30 namespace V2_0 {
31 namespace implementation {
32 
33 using ::android::hardware::audio::common::V2_0::AudioConfig;
34 using ::android::hardware::audio::common::V2_0::AudioInputFlag;
35 using ::android::hardware::audio::common::V2_0::AudioMode;
36 using ::android::hardware::audio::common::V2_0::AudioOutputFlag;
37 using ::android::hardware::audio::common::V2_0::AudioPort;
38 using ::android::hardware::audio::common::V2_0::AudioPortConfig;
39 using ::android::hardware::audio::common::V2_0::AudioSource;
40 using ::android::hardware::audio::V2_0::DeviceAddress;
41 using ::android::hardware::audio::V2_0::IDevice;
42 using ::android::hardware::audio::V2_0::IPrimaryDevice;
43 using ::android::hardware::audio::V2_0::IStreamIn;
44 using ::android::hardware::audio::V2_0::IStreamOut;
45 using ::android::hardware::audio::V2_0::ParameterValue;
46 using ::android::hardware::audio::V2_0::Result;
47 using ::android::hardware::Return;
48 using ::android::hardware::Void;
49 using ::android::hardware::hidl_vec;
50 using ::android::hardware::hidl_string;
51 using ::android::sp;
52 
53 struct PrimaryDevice : public IPrimaryDevice {
54     explicit PrimaryDevice(audio_hw_device_t* device);
55 
56     // Methods from ::android::hardware::audio::V2_0::IDevice follow.
57     Return<Result> initCheck()  override;
58     Return<Result> setMasterVolume(float volume)  override;
59     Return<void> getMasterVolume(getMasterVolume_cb _hidl_cb)  override;
60     Return<Result> setMicMute(bool mute)  override;
61     Return<void> getMicMute(getMicMute_cb _hidl_cb)  override;
62     Return<Result> setMasterMute(bool mute)  override;
63     Return<void> getMasterMute(getMasterMute_cb _hidl_cb)  override;
64     Return<void> getInputBufferSize(
65             const AudioConfig& config, getInputBufferSize_cb _hidl_cb)  override;
66     Return<void> openOutputStream(
67             int32_t ioHandle,
68             const DeviceAddress& device,
69             const AudioConfig& config,
70             AudioOutputFlag flags,
71             openOutputStream_cb _hidl_cb)  override;
72     Return<void> openInputStream(
73             int32_t ioHandle,
74             const DeviceAddress& device,
75             const AudioConfig& config,
76             AudioInputFlag flags,
77             AudioSource source,
78             openInputStream_cb _hidl_cb)  override;
79     Return<bool> supportsAudioPatches()  override;
80     Return<void> createAudioPatch(
81             const hidl_vec<AudioPortConfig>& sources,
82             const hidl_vec<AudioPortConfig>& sinks,
83             createAudioPatch_cb _hidl_cb)  override;
84     Return<Result> releaseAudioPatch(int32_t patch)  override;
85     Return<void> getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb)  override;
86     Return<Result> setAudioPortConfig(const AudioPortConfig& config)  override;
87     Return<AudioHwSync> getHwAvSync()  override;
88     Return<Result> setScreenState(bool turnedOn)  override;
89     Return<void> getParameters(
90             const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb)  override;
91     Return<Result> setParameters(const hidl_vec<ParameterValue>& parameters)  override;
92     Return<void> debugDump(const hidl_handle& fd)  override;
93 
94     // Methods from ::android::hardware::audio::V2_0::IPrimaryDevice follow.
95     Return<Result> setVoiceVolume(float volume)  override;
96     Return<Result> setMode(AudioMode mode)  override;
97     Return<void> getBtScoNrecEnabled(getBtScoNrecEnabled_cb _hidl_cb)  override;
98     Return<Result> setBtScoNrecEnabled(bool enabled)  override;
99     Return<void> getBtScoWidebandEnabled(getBtScoWidebandEnabled_cb _hidl_cb)  override;
100     Return<Result> setBtScoWidebandEnabled(bool enabled)  override;
101     Return<void> getTtyMode(getTtyMode_cb _hidl_cb)  override;
102     Return<Result> setTtyMode(IPrimaryDevice::TtyMode mode)  override;
103     Return<void> getHacEnabled(getHacEnabled_cb _hidl_cb)  override;
104     Return<Result> setHacEnabled(bool enabled)  override;
105 
106   private:
107     sp<Device> mDevice;
108 
109     virtual ~PrimaryDevice();
110 };
111 
112 }  // namespace implementation
113 }  // namespace V2_0
114 }  // namespace audio
115 }  // namespace hardware
116 }  // namespace android
117 
118 #endif  // ANDROID_HARDWARE_AUDIO_V2_0_PRIMARYDEVICE_H
119